Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VBE support for PositionWeightedModuleCollection #2647

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion torchrec/modules/feature_processor_.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#!/usr/bin/env python3

import abc
from typing import Dict, Optional
from typing import Dict, List, Optional

import torch

Expand Down Expand Up @@ -150,6 +150,13 @@ def get_weights_list(
return torch.cat(weights_list) if weights_list else features.weights_or_none()


@torch.fx.wrap
def get_stride_per_key_per_rank(kjt: KeyedJaggedTensor) -> Optional[List[List[int]]]:
if not kjt.variable_stride_per_key():
return None
return kjt.stride_per_key_per_rank()


class PositionWeightedModuleCollection(FeatureProcessorsCollection, CopyMixIn):
def __init__(
self, max_feature_lengths: Dict[str, int], device: Optional[torch.device] = None
Expand Down Expand Up @@ -193,6 +200,7 @@ def forward(self, features: KeyedJaggedTensor) -> KeyedJaggedTensor:
offsets=features.offsets(),
stride=features.stride(),
length_per_key=features.length_per_key(),
stride_per_key_per_rank=get_stride_per_key_per_rank(features),
)

def copy(self, device: torch.device) -> nn.Module:
Expand Down
Loading