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

Update batched_embedding_kernel #2702

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
50 changes: 44 additions & 6 deletions torchrec/distributed/batched_embedding_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,13 @@ def __init__(
self._feature_table_map: List[int] = []
self.table_name_to_count: Dict[str, int] = {}
self._param_per_table: Dict[str, TableBatchedEmbeddingSlice] = {}
self._fused_params: Dict[str, Any] = config.fused_params or {}
self._embedding_table_index_type: torch.dtype = self._fused_params.get(
"embedding_table_index_type", torch.int64
)
self._embedding_table_offset_type: torch.dtype = self._fused_params.get(
"embedding_table_offset_type", torch.int64
)

# pyre-fixme[9]: config has type `GroupedEmbeddingConfig`; used as
# `ShardedEmbeddingTable`.
Expand Down Expand Up @@ -800,8 +807,16 @@ def init_parameters(self) -> None:

def forward(self, features: KeyedJaggedTensor) -> torch.Tensor:
return self.emb_module(
indices=features.values().long(),
offsets=features.offsets().long(),
indices=(
features.values()
if self._embedding_table_index_type == torch.int32
else features.values().long()
),
offsets=(
features.offsets().type(dtype=features.values().dtype)
if self._embedding_table_offset_type == torch.int32
else features.offsets().long()
),
)

# pyre-fixme[14]: `state_dict` overrides method defined in `Module` inconsistently.
Expand Down Expand Up @@ -1213,6 +1228,13 @@ def __init__(
self._lengths_per_emb: List[int] = []
self.table_name_to_count: Dict[str, int] = {}
self._param_per_table: Dict[str, TableBatchedEmbeddingSlice] = {}
self._fused_params: Dict[str, Any] = config.fused_params or {}
self._embedding_table_index_type: torch.dtype = self._fused_params.get(
"embedding_table_index_type", torch.int64
)
self._embedding_table_offset_type: torch.dtype = self._fused_params.get(
"embedding_table_offset_type", torch.int64
)

# pyre-fixme[9]: config has type `GroupedEmbeddingConfig`; used as
# `ShardedEmbeddingTable`.
Expand Down Expand Up @@ -1265,15 +1287,31 @@ def forward(self, features: KeyedJaggedTensor) -> torch.Tensor:
),
):
return self.emb_module(
indices=features.values().long(),
offsets=features.offsets().long(),
indices=(
features.values()
if self._embedding_table_index_type == torch.int32
else features.values().long()
),
offsets=(
features.offsets().type(dtype=features.values().dtype)
if self._embedding_table_offset_type == torch.int32
else features.offsets().long()
),
per_sample_weights=weights,
batch_size_per_feature_per_rank=features.stride_per_key_per_rank(),
)
else:
return self.emb_module(
indices=features.values().long(),
offsets=features.offsets().long(),
indices=(
features.values()
if self._embedding_table_index_type == torch.int32
else features.values().long()
),
offsets=(
features.offsets().type(dtype=features.values().dtype)
if self._embedding_table_offset_type == torch.int32
else features.offsets().long()
),
per_sample_weights=weights,
)

Expand Down
Loading