|
42 | 42 | triton_tbe_backward_long_run_fused_weighted, |
43 | 43 | ) |
44 | 44 | from torchrec.distributed.triton_tbe.triton_tbe_backward_utils import ( |
| 45 | + _CLC_FIXED_GRID, |
45 | 46 | _expand_long_runs, |
| 47 | + _FIXED_GRID, |
46 | 48 | _LONG_RUN_THRESHOLD, |
47 | 49 | _stochastic_rounding_store, |
48 | 50 | get_grid_size, |
@@ -1774,7 +1776,10 @@ def backward(ctx, dout) -> Tuple[None, ...]: |
1774 | 1776 | stochastic_rounding_seed=stochastic_rounding_seed, |
1775 | 1777 | vbe=vbe, |
1776 | 1778 | ) |
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: |
1778 | 1783 | # CLC path: fused long-run grad accumulation + optimizer apply |
1779 | 1784 | # CLC Path is exclusive to CUDA B200+. |
1780 | 1785 | grad_accum_counter = programs_per_long_run.clone() |
@@ -1818,12 +1823,17 @@ def backward(ctx, dout) -> Tuple[None, ...]: |
1818 | 1823 | else: |
1819 | 1824 | # Non-CLC path: separate grad accumulation + apply kernels |
1820 | 1825 | # 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 | + ) |
1821 | 1831 | bwd_long_accum_w = ( |
1822 | 1832 | _amd_bwd_long_accum_weighted |
1823 | 1833 | if _use_amd |
1824 | 1834 | else triton_tbe_backward_long_run_grad_accum_weighted |
1825 | 1835 | ) |
1826 | | - bwd_long_accum_w[(long_accum_or_fused_grid_size,)]( |
| 1836 | + bwd_long_accum_w[(long_accum_grid_size,)]( |
1827 | 1837 | dout, |
1828 | 1838 | infos_sorted, |
1829 | 1839 | long_run_program_seg_starts, |
@@ -1912,7 +1922,10 @@ def backward(ctx, dout) -> Tuple[None, ...]: |
1912 | 1922 | stochastic_rounding_seed=stochastic_rounding_seed, |
1913 | 1923 | vbe=vbe, |
1914 | 1924 | ) |
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: |
1916 | 1929 | # CLC path: fused long-run grad accumulation + optimizer apply |
1917 | 1930 | # CLC Path is exclusive to CUDA B200+. |
1918 | 1931 | grad_accum_counter = programs_per_long_run.clone() |
@@ -1955,12 +1968,17 @@ def backward(ctx, dout) -> Tuple[None, ...]: |
1955 | 1968 | else: |
1956 | 1969 | # Non-CLC path: separate grad accumulation + apply kernels |
1957 | 1970 | # 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 | + ) |
1958 | 1976 | bwd_long_accum_uw = ( |
1959 | 1977 | _amd_bwd_long_accum_unweighted |
1960 | 1978 | if _use_amd |
1961 | 1979 | else triton_tbe_backward_long_run_grad_accum_unweighted |
1962 | 1980 | ) |
1963 | | - bwd_long_accum_uw[(long_accum_or_fused_grid_size,)]( |
| 1981 | + bwd_long_accum_uw[(long_accum_grid_size,)]( |
1964 | 1982 | dout, |
1965 | 1983 | infos_sorted, |
1966 | 1984 | long_run_program_seg_starts, |
|
0 commit comments