Skip to content

Commit

Permalink
tag KJT related part to sc.INPUT_DIST (#2678)
Browse files Browse the repository at this point in the history
Summary:

tag KJT output to sc.INPUT_DIST to enforce placement on CPU

Differential Revision: D67313214
  • Loading branch information
Jiyuan Zhang authored and facebook-github-bot committed Feb 16, 2025
1 parent 1d9541b commit 30de365
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions torchrec/quant/embedding_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ def _fx_trec_unwrap_kjt(
return indices.int(), offsets.int()


@torch.fx.wrap
def _fx_trec_unwrap_jt(
jt: JaggedTensor,
) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Forced conversions to support TBE
CPU - int32 or int64, offsets dtype must match
GPU - int32 only, offsets dtype must match
"""
indices = jt.values()
offsets = jt.offsets()
if jt.device().type == "cpu":
return indices, offsets.type(dtype=indices.dtype)
else:
return indices.int(), offsets.int()


class EmbeddingBagCollection(EmbeddingBagCollectionInterface, ModuleNoCopyMixin):
"""
This class represents a reimplemented version of the EmbeddingBagCollection
Expand Down

0 comments on commit 30de365

Please sign in to comment.