Skip to content

static config for sharded_modules #1766

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions torchrec/distributed/quant_embedding_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,21 @@ def _quantize_weight(
@torch.fx.wrap
def _unwrap_kjt(
features: KeyedJaggedTensor,
use_gpu: bool,
weighted: bool,
) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]:
if features.device().type == "cuda":
if use_gpu:
return (
features.values().int(),
features.offsets().int(),
features.weights_or_none(),
features.weights_or_none() if weighted else None,
)
else:
return features.values(), features.offsets(), features.weights_or_none()
return (
features.values(),
features.offsets(),
features.weights_or_none() if weighted else None,
)


class QuantBatchedEmbeddingBag(
Expand Down Expand Up @@ -210,7 +216,9 @@ def get_tbes_to_register(
return {self._emb_module: self._config}

def forward(self, features: KeyedJaggedTensor) -> torch.Tensor:
indices, offsets, per_sample_weights = _unwrap_kjt(features)
indices, offsets, per_sample_weights = _unwrap_kjt(
features, self.emb_module.row_alignment == 16, self._config.is_weighted
)
# Conditional call of .forward function for FX:
# emb_module() can go through FX only if emb_module is registered in named_modules (FX node call_module)
# emb_module.forward() does not require registering emb_module in named_modules (FX node call_function)
Expand Down Expand Up @@ -372,7 +380,9 @@ def split_embedding_weights(
]

def forward(self, features: KeyedJaggedTensor) -> torch.Tensor:
values, offsets, _ = _unwrap_kjt(features)
values, offsets, _ = _unwrap_kjt(
features, self.emb_module.row_alignment == 16, False
)
if self._emb_module_registered:
return self.emb_module(
indices=values,
Expand Down