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 bounds check for indices in unique_indices to prevent out-of-bounds errors #2728

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
15 changes: 15 additions & 0 deletions torchrec/distributed/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
ShardedTensor,
ShardingEnv,
ShardMetadata,
BoundsCheckMode,
)
from torchrec.distributed.utils import (
add_params_from_parameter_sharding,
Expand Down Expand Up @@ -1090,6 +1091,20 @@ def _dedup_indices(
for i, input_feature in enumerate(input_feature_splits):
hash_size_cumsum = self.get_buffer(f"_hash_size_cumsum_tensor_{i}")
hash_size_offset = self.get_buffer(f"_hash_size_offset_tensor_{i}")

lookup = self._lookups[i]
for emb_module in lookup._emb_modules:
emb_module = emb_module._emb_module
if emb_module.bounds_check_mode_int != BoundsCheckMode.NONE.value:
torch.ops.fbgemm.bounds_check_indices(
emb_module.rows_per_table,
input_feature.values().long(),
input_feature.offsets().long(),
emb_module.bounds_check_mode_int,
emb_module.bounds_check_warning,
None,
)

(
lengths,
offsets,
Expand Down