Skip to content

Commit 7d8e189

Browse files
stashuk-olekfacebook-github-bot
authored andcommitted
Select CUDA v2 bounds checking for Triton TBE (meta-pytorch#4484)
Summary: Cuda wasn't using bounds check, but triton did. Match the both to make it fair comparison Reviewed By: axeisghost, TroyGarden Differential Revision: D114279989
1 parent 85dbbae commit 7d8e189

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

torchrec/distributed/triton_tbe/triton_table_batched_embeddings.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,10 +1891,16 @@ def __init__(
18911891
rows_per_feature, dtype=torch.int64, device=device
18921892
)
18931893
self.bounds_check_warning = torch.tensor([0], device=device, dtype=torch.int64)
1894-
# Use WARNING mode by default. We don't support environment variable override
1895-
# because TritonTBE only uses bounds check v1 kernel, while the env var
1896-
# (FBGEMM_TBE_BOUNDS_CHECK_MODE) can also set v2 modes (V2_IGNORE, V2_WARNING, V2_FATAL).
1897-
self.bounds_check_mode: BoundsCheckMode = BoundsCheckMode.WARNING
1894+
self.bounds_check_mode: BoundsCheckMode = BoundsCheckMode.V2_WARNING
1895+
1896+
def _bounds_check_config(self) -> Tuple[BoundsCheckMode, int]:
1897+
is_v2 = self.bounds_check_mode.name.startswith("V2_")
1898+
mode = (
1899+
BoundsCheckMode[self.bounds_check_mode.name[3:]]
1900+
if is_v2
1901+
else self.bounds_check_mode
1902+
)
1903+
return mode, 1 + int(is_v2)
18981904

18991905
def prepare_inputs(
19001906
self,
@@ -1929,14 +1935,16 @@ def prepare_inputs(
19291935
):
19301936
per_sample_weights = per_sample_weights.float()
19311937

1932-
if self.bounds_check_mode != BoundsCheckMode.NONE:
1938+
bounds_check_mode, bounds_check_version = self._bounds_check_config()
1939+
if bounds_check_mode != BoundsCheckMode.NONE:
19331940
torch.ops.fbgemm.bounds_check_indices(
19341941
self.rows_per_table,
19351942
indices,
19361943
offsets,
1937-
self.bounds_check_mode,
1944+
bounds_check_mode,
19381945
self.bounds_check_warning,
19391946
per_sample_weights,
1947+
bounds_check_version=bounds_check_version,
19401948
)
19411949

19421950
return indices, offsets, per_sample_weights
@@ -2023,19 +2031,21 @@ def forward(
20232031
)
20242032

20252033
# Bounds check (VBE-aware)
2026-
if self.bounds_check_mode != BoundsCheckMode.NONE:
2034+
bounds_check_mode, bounds_check_version = self._bounds_check_config()
2035+
if bounds_check_mode != BoundsCheckMode.NONE:
20272036
torch.ops.fbgemm.bounds_check_indices(
20282037
self.rows_per_table,
20292038
indices,
20302039
offsets,
2031-
self.bounds_check_mode,
2040+
bounds_check_mode,
20322041
self.bounds_check_warning,
20332042
per_sample_weights,
20342043
B_offsets=vbe_metadata.B_offsets if vbe_metadata is not None else None,
20352044
max_B=max_B if max_B > 0 else -1,
20362045
b_t_map=b_t_map,
20372046
info_B_num_bits=info_B_num_bits if info_B_num_bits > 0 else -1,
20382047
info_B_mask=info_B_mask if info_B_mask > 0 else -1,
2048+
bounds_check_version=bounds_check_version,
20392049
)
20402050

20412051
return TritonTBE.apply(

0 commit comments

Comments
 (0)