Skip to content

Commit 2a08ccc

Browse files
stashuk-olekfacebook-github-bot
authored andcommitted
Reduce Triton TBE backward reduction pressure (meta-pytorch#4487)
Summary: Tweaking a bit to hide more from critical path. Reviewed By: axeisghost Differential Revision: D114273026
1 parent 003290b commit 2a08ccc

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

torchrec/distributed/triton_tbe/triton_table_batched_embeddings.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
triton_tbe_backward_long_run_fused_weighted,
4343
)
4444
from torchrec.distributed.triton_tbe.triton_tbe_backward_utils import (
45+
_CLC_FIXED_GRID,
4546
_expand_long_runs,
47+
_FIXED_GRID,
4648
_LONG_RUN_THRESHOLD,
4749
_stochastic_rounding_store,
4850
get_grid_size,
@@ -1774,7 +1776,10 @@ def backward(ctx, dout) -> Tuple[None, ...]:
17741776
stochastic_rounding_seed=stochastic_rounding_seed,
17751777
vbe=vbe,
17761778
)
1777-
if use_clc:
1779+
use_fused_clc_long_run = (
1780+
use_clc and max_num_runs > _CLC_FIXED_GRID * _LONG_RUN_THRESHOLD
1781+
)
1782+
if use_fused_clc_long_run:
17781783
# CLC path: fused long-run grad accumulation + optimizer apply
17791784
# CLC Path is exclusive to CUDA B200+.
17801785
grad_accum_counter = programs_per_long_run.clone()
@@ -1818,12 +1823,17 @@ def backward(ctx, dout) -> Tuple[None, ...]:
18181823
else:
18191824
# Non-CLC path: separate grad accumulation + apply kernels
18201825
# Kernel 2: long-run grad accumulation (weighted)
1826+
long_accum_grid_size = (
1827+
min(_FIXED_GRID, max_long_run_programs)
1828+
if use_clc
1829+
else long_accum_or_fused_grid_size
1830+
)
18211831
bwd_long_accum_w = (
18221832
_amd_bwd_long_accum_weighted
18231833
if _use_amd
18241834
else triton_tbe_backward_long_run_grad_accum_weighted
18251835
)
1826-
bwd_long_accum_w[(long_accum_or_fused_grid_size,)](
1836+
bwd_long_accum_w[(long_accum_grid_size,)](
18271837
dout,
18281838
infos_sorted,
18291839
long_run_program_seg_starts,
@@ -1912,7 +1922,10 @@ def backward(ctx, dout) -> Tuple[None, ...]:
19121922
stochastic_rounding_seed=stochastic_rounding_seed,
19131923
vbe=vbe,
19141924
)
1915-
if use_clc:
1925+
use_fused_clc_long_run = (
1926+
use_clc and max_num_runs > _CLC_FIXED_GRID * _LONG_RUN_THRESHOLD
1927+
)
1928+
if use_fused_clc_long_run:
19161929
# CLC path: fused long-run grad accumulation + optimizer apply
19171930
# CLC Path is exclusive to CUDA B200+.
19181931
grad_accum_counter = programs_per_long_run.clone()
@@ -1955,12 +1968,17 @@ def backward(ctx, dout) -> Tuple[None, ...]:
19551968
else:
19561969
# Non-CLC path: separate grad accumulation + apply kernels
19571970
# Kernel 2: long-run grad accumulation
1971+
long_accum_grid_size = (
1972+
min(_FIXED_GRID, max_long_run_programs)
1973+
if use_clc
1974+
else long_accum_or_fused_grid_size
1975+
)
19581976
bwd_long_accum_uw = (
19591977
_amd_bwd_long_accum_unweighted
19601978
if _use_amd
19611979
else triton_tbe_backward_long_run_grad_accum_unweighted
19621980
)
1963-
bwd_long_accum_uw[(long_accum_or_fused_grid_size,)](
1981+
bwd_long_accum_uw[(long_accum_grid_size,)](
19641982
dout,
19651983
infos_sorted,
19661984
long_run_program_seg_starts,

0 commit comments

Comments
 (0)