Skip to content

feat(cake_moe_grouped_gemm): fuse the fp32 weight-gradient accumulate into main_grad on sm_100a, sm_103a and sm_107a - #8602

Merged
yyihuang merged 8 commits into
flashinfer-ai:mainfrom
yyihuang:moe-grouped-gemm-wgrad-accumulate
Nov 4, 2026
Merged

yyihuang merged 8 commits into
flashinfer-ai:mainfrom
yyihuang:moe-grouped-gemm-wgrad-accumulate

Conversation

@yyihuang

@yyihuang yyihuang commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

The Cake ragged BF16 grouped GEMM for MoE expert training has two variants: deterministic flashinfer.experimental.cake_moe_grouped_det_gemm and non-deterministic flashinfer.experimental.cake.cake_moe_grouped_gemm (selected with deterministic=False). Both use FP32 accumulation. Each has forward (Y = X W^T), data-gradient (dX = G W) and weight-gradient (dW = G^T X, BF16 or FP32 output) programs. The facade flashinfer.experimental.cake.grouped_mm reaches the kernel, and its default stays deterministic.

This PR adds weight-gradient accumulation into an existing buffer, out[e] += G_e^T X_e. It is opt-in and applies to the non-deterministic variant only. These are the semantics of Megatron's gradient_accumulation_fusion and Transformer Engine's fuse_wgrad_accumulation. The public surface is grouped_gemm_wgrad(..., out=out, accumulate=True), prepare_grouped_gemm_wgrad(..., accumulate=True) and cake_grouped_mm(x, w, offs, deterministic=False, fuse_wgrad_accumulation=True). The last one adds into w.main_grad in the backward and supports Megatron's grad_added_to_main_grad. accumulate and fuse_wgrad_accumulation both default to off. With the defaults, the routes, programs, plans and bits are unchanged. For an fp32 out or main_grad, the add is fused into the epilogue of the k512 half-release weight-gradient programs. On sm_100a and sm_103a these are forms main_halves and main_wave_halves; on sm_107a they are main_halves and main_halves_k256t. This adds six fp32 accumulate builds that need CUDA toolkit 13.4 or newer. Every other case runs composed (the dW, then one add): a bf16 main_grad, the 256-wide k tile, other forms, a misaligned out, or an accumulate library that cannot load. plan["accumulate"] reports "fused" or "composed". As before for this variant, the summation order of a split tail tile can differ between runs. Against an fp32 dW followed by main_grad.add_, the fused route with grad_added_to_main_grad saves 2 * S bytes of peak memory (S = E * N * K elements).

Results (point estimates, new non-deterministic Cake against each baseline):

  • wgrad accumulate: At or above 1.0 against deterministic Cake on every row: GB300 1.033-1.255x, B200 1.022-1.241x, R200 1.024-1.318x. Against non-Cake SOTA the range is 0.931-1.060x on GB300, 0.945-1.058x on B200 and 0.961-1.036x on R200. The standalone call is slower than non-Cake SOTA on 9 of 20 rows on GB300 (lowest 0.931x), 8 of 20 on B200 (lowest 0.945x) and 11 of 20 on R200 (lowest 0.961x). On those rows the fastest baseline is mostly TE GroupedLinear. It takes host-side m_splits, so it needs the group sizes on the host. This kernel reads device offsets with no host sync. Closing the standalone wgrad accumulate gap to TE is follow-up work.
  • full backward: Against deterministic Cake the range is 0.989-1.174x on GB300 (3 rows below 1.0, each with a CI that includes 1) and 0.912-1.142x on B200 (9 rows below 1.0; one has a CI entirely below 1). On R200 it is 1.022-1.220x. Against non-Cake SOTA the range is 0.965-1.052x on GB300 (6 rows below 1.0), 0.910-1.046x on B200 (13 rows below 1.0) and 1.002-1.089x on R200.
  • checkpointed 2×fwd + bwd: At or above 1.0 on every row against both baselines. Against deterministic Cake: GB300 1.007-1.071x, B200 1.006-1.071x, R200 1.005-1.075x. Against non-Cake SOTA: GB300 1.010-1.054x, B200 1.000-1.044x, R200 1.010-1.069x.

Baselines and measurement. Speedup = baseline latency / new latency, so a value above 1 means the new kernel is faster. Brackets are bootstrap 95% CIs of the paired per-group median ratio.

  • "new non-deterministic Cake" is this PR's fused route.
  • "deterministic Cake" is the deterministic variant's fp32 dW followed by main_grad.add_. In full backward and checkpointed 2×fwd + bwd, it is the deterministic autograd plus the add.
  • "non-Cake SOTA" is the fastest fp32-accumulate non-Cake implementation measured for each row. The table names it in parentheses. This choice favors the baseline. The candidates are:
    • "TE GroupedLinear": Transformer Engine 2.20.2 GroupedLinear(fuse_wgrad_accumulation=True) on the legacy per-expert cuBLAS path with host m_splits.
    • "TE grouped tensor": the TE grouped-tensor path with device m_splits (cuBLASLt grouped GEMM).
    • "cuBLAS per expert": per-expert cublasGemmEx with beta=1 into main_grad.
    • "cuBLASLt grouped": cuBLASLt grouped matmul with beta=1 (wgrad accumulate only).
    • "DeepGEMM": DeepGEMM 2.8.2 k-grouped BF16 GEMM with C accumulation (wgrad accumulate only). It does not run on sm_107a, so it is absent on R200.
    • "per-op best composite" (full backward and checkpointed 2×fwd + bwd only): the fastest deterministic-matching forward and data-gradient (per-expert cuBLAS, torch, cuDNN or FlashInfer mm), plus the fastest fp32 accumulate weight-gradient.
  • torch._grouped_mm with fp32 output is unsupported in torch 2.14.1.
  • Operations:
    • "wgrad accumulate main_grad += dW" is the accumulate call alone (CUPTI cold-L2 span, 12 groups).
    • "full backward" is data-gradient + wgrad accumulate, with the forward untimed (cold-L2 CUDA events, 16 groups × 4 sequences).
    • "checkpointed 2×fwd + bwd" is one checkpointed micro-step (CUPTI cold-L2 span).
    • All runs use eager execution and cold L2.
  • Shapes are gate_up and down projections. E is the number of experts and M is the total token count. balanced, one_empty, skewed and short16 are group-size patterns. Inputs are bf16 and main_grad is fp32.
  • Environments:
    • GB300 sm_103a: 152 SMs, driver 580.159.03, power limit 1400 W.
    • B200 sm_100a: 148 SMs, driver 580.82.07, power limit 1000 W.
    • R200 sm_107a: 208 SMs, driver 615.71.10, power limit 2300 W, measured on one timing-admitted board (n=1, not decision-grade).
    • On all three, kernels were built with CUDA 13.4 (nvcc 13.4), with torch 2.14.1+cu130 and cuBLAS 13.8.0.4.
    • Non-Cake arms ran on one GPU per row. On GB300 and B200, the Cake arms also ran on replica GPUs for some rows.

GB300 sm_103a

GPU / architecture workload / shape operation deterministic Cake latency non-Cake SOTA latency new non-deterministic Cake latency speedup vs deterministic Cake speedup vs non-Cake SOTA
GB300 sm_103a (152 SM) down E4 M112576 balanced wgrad accumulate main_grad += dW 1.6389 ms 1.6491 ms (TE grouped tensor) 1.5728 ms 1.045x [1.038, 1.051] 1.049x [1.045, 1.051]
GB300 sm_103a (152 SM) down E4 M112576 one_empty wgrad accumulate main_grad += dW 1.6914 ms 1.6894 ms (cuBLAS per expert) 1.6052 ms 1.055x [1.050, 1.056] 1.054x [1.049, 1.058]
GB300 sm_103a (152 SM) down E4 M112576 skewed wgrad accumulate main_grad += dW 1.6861 ms 1.6103 ms (TE GroupedLinear) 1.5887 ms 1.060x [1.053, 1.063] 1.013x [1.006, 1.016]
GB300 sm_103a (152 SM) down E4 M136064 balanced wgrad accumulate main_grad += dW 1.9733 ms 1.9722 ms (TE grouped tensor) 1.8975 ms 1.040x [1.038, 1.042] 1.040x [1.038, 1.041]
GB300 sm_103a (152 SM) down E4 M136064 one_empty wgrad accumulate main_grad += dW 1.9789 ms 2.0247 ms (cuBLAS per expert) 1.9103 ms 1.036x [1.032, 1.043] 1.060x [1.055, 1.063]
GB300 sm_103a (152 SM) down E4 M136064 skewed wgrad accumulate main_grad += dW 2.0450 ms 2.0267 ms (TE GroupedLinear) 1.9498 ms 1.051x [1.048, 1.052] 1.040x [1.039, 1.042]
GB300 sm_103a (152 SM) down E8 M131072 balanced wgrad accumulate main_grad += dW 2.0212 ms 1.9375 ms (TE grouped tensor) 1.9009 ms 1.063x [1.062, 1.065] 1.018x [1.016, 1.023]
GB300 sm_103a (152 SM) down E16 M131072 balanced wgrad accumulate main_grad += dW 2.2128 ms 1.9216 ms (TE GroupedLinear) 1.9592 ms 1.130x [1.128, 1.132] 0.980x [0.978, 0.985]
GB300 sm_103a (152 SM) down E32 M131072 balanced wgrad accumulate main_grad += dW 2.5686 ms 1.8904 ms (TE GroupedLinear) 2.0443 ms 1.255x [1.253, 1.257] 0.931x [0.929, 0.935]
GB300 sm_103a (152 SM) gate_up E4 M112576 balanced wgrad accumulate main_grad += dW 3.3569 ms 3.2355 ms (TE GroupedLinear) 3.2029 ms 1.048x [1.043, 1.051] 1.009x [1.005, 1.012]
GB300 sm_103a (152 SM) gate_up E4 M112576 one_empty wgrad accumulate main_grad += dW 3.4344 ms 3.1361 ms (TE GroupedLinear) 3.2797 ms 1.047x [1.042, 1.051] 0.955x [0.952, 0.961]
GB300 sm_103a (152 SM) gate_up E4 M112576 skewed wgrad accumulate main_grad += dW 3.4480 ms 3.1633 ms (TE GroupedLinear) 3.2928 ms 1.047x [1.045, 1.048] 0.960x [0.955, 0.964]
GB300 sm_103a (152 SM) gate_up E4 M136064 balanced wgrad accumulate main_grad += dW 3.9888 ms 3.9083 ms (TE GroupedLinear) 3.8536 ms 1.035x [1.019, 1.038] 1.012x [1.000, 1.016]
GB300 sm_103a (152 SM) gate_up E4 M136064 one_empty wgrad accumulate main_grad += dW 4.2358 ms 3.8517 ms (TE GroupedLinear) 4.0473 ms 1.046x [1.043, 1.047] 0.953x [0.948, 0.959]
GB300 sm_103a (152 SM) gate_up E4 M136064 skewed wgrad accumulate main_grad += dW 4.0582 ms 3.7887 ms (TE GroupedLinear) 3.9216 ms 1.033x [1.030, 1.036] 0.966x [0.964, 0.968]
GB300 sm_103a (152 SM) gate_up E8 M131072 balanced wgrad accumulate main_grad += dW 3.9685 ms 3.6718 ms (TE GroupedLinear) 3.7572 ms 1.056x [1.054, 1.058] 0.978x [0.975, 0.980]
GB300 sm_103a (152 SM) gate_up E16 M131072 balanced wgrad accumulate main_grad += dW 4.3427 ms 3.9607 ms (DeepGEMM) 3.8390 ms 1.132x [1.122, 1.144] 1.032x [1.022, 1.047]
GB300 sm_103a (152 SM) gate_up E32 M131072 balanced wgrad accumulate main_grad += dW 5.0919 ms 4.1051 ms (DeepGEMM) 4.1117 ms 1.238x [1.237, 1.239] 0.983x [0.979, 0.989]
GB300 sm_103a (152 SM) down E32 M131072 short16 wgrad accumulate main_grad += dW 2.6493 ms 2.0776 ms (TE GroupedLinear) 2.1414 ms 1.242x [1.237, 1.247] 0.989x [0.987, 0.994]
GB300 sm_103a (152 SM) gate_up E32 M131072 short16 wgrad accumulate main_grad += dW 5.1682 ms 4.5610 ms (TE grouped tensor) 4.2464 ms 1.211x [1.209, 1.213] 1.059x [1.058, 1.063]
GB300 sm_103a (152 SM) down E4 M112576 balanced full backward 3.0042 ms 3.0559 ms (per-op best composite) 2.9583 ms 1.021x [1.002, 1.029] 1.035x [1.014, 1.058]
GB300 sm_103a (152 SM) down E4 M112576 one_empty full backward 3.0710 ms 3.1447 ms (TE grouped tensor) 3.0468 ms 1.010x [0.994, 1.025] 1.033x [1.017, 1.047]
GB300 sm_103a (152 SM) down E4 M112576 skewed full backward 3.0592 ms 3.0178 ms (TE GroupedLinear) 2.9420 ms 1.036x [1.031, 1.040] 1.025x [1.016, 1.030]
GB300 sm_103a (152 SM) down E4 M136064 balanced full backward 3.5565 ms 3.6170 ms (per-op best composite) 3.5392 ms 1.001x [0.981, 1.024] 1.022x [0.988, 1.043]
GB300 sm_103a (152 SM) down E4 M136064 one_empty full backward 3.6959 ms 3.7488 ms (cuBLAS per expert) 3.6018 ms 1.024x [1.001, 1.035] 1.046x [1.021, 1.067]
GB300 sm_103a (152 SM) down E4 M136064 skewed full backward 3.7618 ms 3.7591 ms (TE GroupedLinear) 3.6316 ms 1.031x [1.000, 1.036] 1.036x [0.997, 1.045]
GB300 sm_103a (152 SM) down E8 M131072 balanced full backward 3.6445 ms 3.6692 ms (TE grouped tensor) 3.4877 ms 1.047x [1.034, 1.049] 1.052x [1.039, 1.064]
GB300 sm_103a (152 SM) down E16 M131072 balanced full backward 3.8664 ms 3.6355 ms (per-op best composite) 3.5479 ms 1.090x [1.077, 1.099] 1.024x [1.016, 1.032]
GB300 sm_103a (152 SM) down E32 M131072 balanced full backward 4.2318 ms 3.5793 ms (per-op best composite) 3.5938 ms 1.174x [1.169, 1.179] 1.005x [0.996, 1.011]
GB300 sm_103a (152 SM) gate_up E4 M112576 balanced full backward 6.2178 ms 6.1988 ms (per-op best composite) 6.2174 ms 0.994x [0.960, 1.027] 0.995x [0.953, 1.029]
GB300 sm_103a (152 SM) gate_up E4 M112576 one_empty full backward 6.3704 ms 6.0531 ms (TE GroupedLinear) 6.2621 ms 1.014x [0.965, 1.034] 0.968x [0.939, 0.991]
GB300 sm_103a (152 SM) gate_up E4 M112576 skewed full backward 6.3277 ms 6.0529 ms (per-op best composite) 6.2003 ms 1.022x [1.005, 1.037] 0.983x [0.932, 0.992]
GB300 sm_103a (152 SM) gate_up E4 M136064 balanced full backward 7.5262 ms 7.7142 ms (per-op best composite) 7.5746 ms 0.989x [0.956, 1.013] 1.027x [0.937, 1.053]
GB300 sm_103a (152 SM) gate_up E4 M136064 one_empty full backward 7.7965 ms 7.5533 ms (TE GroupedLinear) 7.7933 ms 0.993x [0.981, 1.010] 0.968x [0.955, 0.978]
GB300 sm_103a (152 SM) gate_up E4 M136064 skewed full backward 7.6207 ms 7.3380 ms (per-op best composite) 7.5604 ms 1.008x [0.986, 1.018] 0.965x [0.940, 0.992]
GB300 sm_103a (152 SM) gate_up E8 M131072 balanced full backward 7.4193 ms 7.2661 ms (TE GroupedLinear) 7.3445 ms 1.017x [0.998, 1.036] 1.003x [0.979, 1.021]
GB300 sm_103a (152 SM) gate_up E16 M131072 balanced full backward 7.9445 ms 7.3576 ms (per-op best composite) 7.2800 ms 1.090x [1.082, 1.106] 1.015x [1.001, 1.028]
GB300 sm_103a (152 SM) gate_up E32 M131072 balanced full backward 8.6210 ms 7.3405 ms (per-op best composite) 7.5865 ms 1.144x [1.128, 1.156] 0.965x [0.953, 0.992]
GB300 sm_103a (152 SM) down E32 M131072 short16 full backward 4.3612 ms 3.8741 ms (per-op best composite) 3.7938 ms 1.148x [1.142, 1.153] 1.029x [1.026, 1.035]
GB300 sm_103a (152 SM) gate_up E32 M131072 short16 full backward 8.8026 ms 8.1333 ms (TE GroupedLinear) 7.8448 ms 1.117x [1.106, 1.141] 1.036x [1.027, 1.052]
GB300 sm_103a (152 SM) down E4 M112576 balanced checkpointed 2×fwd + bwd 6.3428 ms 6.4330 ms (per-op best composite) 6.2628 ms 1.007x [1.001, 1.031] 1.027x [1.016, 1.039]
GB300 sm_103a (152 SM) down E4 M112576 one_empty checkpointed 2×fwd + bwd 6.4099 ms 6.5694 ms (per-op best composite) 6.2990 ms 1.018x [1.008, 1.025] 1.041x [1.038, 1.047]
GB300 sm_103a (152 SM) down E4 M112576 skewed checkpointed 2×fwd + bwd 6.3451 ms 6.3584 ms (per-op best composite) 6.2401 ms 1.013x [1.011, 1.017] 1.019x [1.016, 1.023]
GB300 sm_103a (152 SM) down E4 M136064 balanced checkpointed 2×fwd + bwd 7.6025 ms 7.6314 ms (per-op best composite) 7.5204 ms 1.011x [1.010, 1.014] 1.016x [1.014, 1.018]
GB300 sm_103a (152 SM) down E4 M136064 one_empty checkpointed 2×fwd + bwd 7.6967 ms 7.7997 ms (per-op best composite) 7.5673 ms 1.016x [1.010, 1.023] 1.032x [1.020, 1.035]
GB300 sm_103a (152 SM) down E4 M136064 skewed checkpointed 2×fwd + bwd 7.7887 ms 7.8546 ms (per-op best composite) 7.6672 ms 1.016x [1.012, 1.021] 1.026x [1.023, 1.029]
GB300 sm_103a (152 SM) down E8 M131072 balanced checkpointed 2×fwd + bwd 7.5837 ms 7.7344 ms (per-op best composite) 7.4210 ms 1.022x [1.019, 1.024] 1.042x [1.036, 1.045]
GB300 sm_103a (152 SM) down E16 M131072 balanced checkpointed 2×fwd + bwd 7.8120 ms 7.7633 ms (TE GroupedLinear) 7.4921 ms 1.041x [1.039, 1.045] 1.034x [1.029, 1.039]
GB300 sm_103a (152 SM) down E32 M131072 balanced checkpointed 2×fwd + bwd 8.1318 ms 7.6910 ms (per-op best composite) 7.6039 ms 1.071x [1.070, 1.073] 1.010x [1.005, 1.023]
GB300 sm_103a (152 SM) gate_up E4 M112576 balanced checkpointed 2×fwd + bwd 12.8462 ms 13.0189 ms (per-op best composite) 12.6623 ms 1.014x [1.012, 1.017] 1.032x [1.025, 1.034]
GB300 sm_103a (152 SM) gate_up E4 M112576 one_empty checkpointed 2×fwd + bwd 12.7547 ms 12.7183 ms (per-op best composite) 12.5398 ms 1.018x [1.015, 1.020] 1.014x [1.011, 1.018]
GB300 sm_103a (152 SM) gate_up E4 M112576 skewed checkpointed 2×fwd + bwd 12.8508 ms 12.8491 ms (per-op best composite) 12.6548 ms 1.013x [1.012, 1.018] 1.018x [1.012, 1.021]
GB300 sm_103a (152 SM) gate_up E4 M136064 balanced checkpointed 2×fwd + bwd 15.3515 ms 15.5987 ms (per-op best composite) 15.1756 ms 1.012x [1.009, 1.014] 1.029x [1.024, 1.033]
GB300 sm_103a (152 SM) gate_up E4 M136064 one_empty checkpointed 2×fwd + bwd 15.6900 ms 15.7563 ms (TE GroupedLinear) 15.4658 ms 1.014x [1.011, 1.015] 1.017x [1.017, 1.019]
GB300 sm_103a (152 SM) gate_up E4 M136064 skewed checkpointed 2×fwd + bwd 15.3555 ms 15.4034 ms (per-op best composite) 15.2488 ms 1.008x [1.004, 1.010] 1.013x [1.007, 1.014]
GB300 sm_103a (152 SM) gate_up E8 M131072 balanced checkpointed 2×fwd + bwd 15.0113 ms 15.1252 ms (TE GroupedLinear) 14.6982 ms 1.021x [1.021, 1.022] 1.029x [1.027, 1.031]
GB300 sm_103a (152 SM) gate_up E16 M131072 balanced checkpointed 2×fwd + bwd 15.4264 ms 15.5549 ms (per-op best composite) 14.8621 ms 1.039x [1.036, 1.041] 1.047x [1.038, 1.051]
GB300 sm_103a (152 SM) gate_up E32 M131072 balanced checkpointed 2×fwd + bwd 16.1838 ms 15.7042 ms (per-op best composite) 15.2601 ms 1.062x [1.060, 1.065] 1.020x [1.010, 1.027]
GB300 sm_103a (152 SM) down E32 M131072 short16 checkpointed 2×fwd + bwd 8.2723 ms 7.9497 ms (per-op best composite) 7.7547 ms 1.068x [1.065, 1.070] 1.030x [1.027, 1.034]
GB300 sm_103a (152 SM) gate_up E32 M131072 short16 checkpointed 2×fwd + bwd 16.4364 ms 16.4537 ms (TE GroupedLinear) 15.5692 ms 1.060x [1.056, 1.062] 1.054x [1.052, 1.059]

B200 sm_100a

GPU / architecture workload / shape operation deterministic Cake latency non-Cake SOTA latency new non-deterministic Cake latency speedup vs deterministic Cake speedup vs non-Cake SOTA
B200 sm_100a (148 SM) down E4 M112576 balanced wgrad accumulate main_grad += dW 2.1146 ms 2.1212 ms (TE grouped tensor) 2.0364 ms 1.038x [1.035, 1.051] 1.043x [1.039, 1.051]
B200 sm_100a (148 SM) down E4 M112576 one_empty wgrad accumulate main_grad += dW 2.1025 ms 2.1250 ms (cuBLAS per expert) 2.0127 ms 1.047x [1.036, 1.050] 1.054x [1.036, 1.058]
B200 sm_100a (148 SM) down E4 M112576 skewed wgrad accumulate main_grad += dW 2.2371 ms 2.1467 ms (TE GroupedLinear) 2.0726 ms 1.079x [1.068, 1.081] 1.034x [1.017, 1.046]
B200 sm_100a (148 SM) down E4 M136064 balanced wgrad accumulate main_grad += dW 2.6556 ms 2.5723 ms (TE grouped tensor) 2.5157 ms 1.054x [1.026, 1.071] 1.022x [1.006, 1.034]
B200 sm_100a (148 SM) down E4 M136064 one_empty wgrad accumulate main_grad += dW 2.5527 ms 2.5657 ms (cuBLAS per expert) 2.4208 ms 1.041x [1.038, 1.056] 1.058x [1.043, 1.062]
B200 sm_100a (148 SM) down E4 M136064 skewed wgrad accumulate main_grad += dW 2.5438 ms 2.5861 ms (cuBLAS per expert) 2.4523 ms 1.044x [1.031, 1.050] 1.058x [1.046, 1.068]
B200 sm_100a (148 SM) down E8 M131072 balanced wgrad accumulate main_grad += dW 2.5851 ms 2.5643 ms (cuBLAS per expert) 2.4340 ms 1.062x [1.060, 1.063] 1.053x [1.049, 1.065]
B200 sm_100a (148 SM) down E16 M131072 balanced wgrad accumulate main_grad += dW 2.7860 ms 2.5025 ms (TE GroupedLinear) 2.5049 ms 1.122x [1.112, 1.123] 1.007x [0.983, 1.013]
B200 sm_100a (148 SM) down E32 M131072 balanced wgrad accumulate main_grad += dW 3.2363 ms 2.4587 ms (TE GroupedLinear) 2.6147 ms 1.241x [1.236, 1.248] 0.945x [0.938, 0.953]
B200 sm_100a (148 SM) gate_up E4 M112576 balanced wgrad accumulate main_grad += dW 4.2588 ms 4.1176 ms (TE GroupedLinear) 4.1358 ms 1.030x [1.029, 1.039] 0.996x [0.992, 1.013]
B200 sm_100a (148 SM) gate_up E4 M112576 one_empty wgrad accumulate main_grad += dW 4.4717 ms 4.0616 ms (TE GroupedLinear) 4.2754 ms 1.043x [1.037, 1.048] 0.950x [0.937, 0.958]
B200 sm_100a (148 SM) gate_up E4 M112576 skewed wgrad accumulate main_grad += dW 4.3154 ms 4.0644 ms (TE GroupedLinear) 4.1785 ms 1.033x [1.030, 1.039] 0.973x [0.964, 0.980]
B200 sm_100a (148 SM) gate_up E4 M136064 balanced wgrad accumulate main_grad += dW 5.0621 ms 4.9929 ms (TE GroupedLinear) 4.9543 ms 1.022x [1.014, 1.028] 1.007x [0.976, 1.017]
B200 sm_100a (148 SM) gate_up E4 M136064 one_empty wgrad accumulate main_grad += dW 5.2659 ms 4.9348 ms (TE GroupedLinear) 5.1028 ms 1.025x [1.010, 1.037] 0.971x [0.953, 0.979]
B200 sm_100a (148 SM) gate_up E4 M136064 skewed wgrad accumulate main_grad += dW 5.3673 ms 5.0366 ms (TE GroupedLinear) 5.1540 ms 1.041x [1.011, 1.042] 0.956x [0.948, 0.978]
B200 sm_100a (148 SM) gate_up E8 M131072 balanced wgrad accumulate main_grad += dW 5.0555 ms 4.7562 ms (TE GroupedLinear) 4.7610 ms 1.062x [1.051, 1.066] 1.001x [0.986, 1.011]
B200 sm_100a (148 SM) gate_up E16 M131072 balanced wgrad accumulate main_grad += dW 5.4465 ms 4.9764 ms (TE GroupedLinear) 4.9035 ms 1.111x [1.107, 1.115] 1.014x [1.005, 1.019]
B200 sm_100a (148 SM) gate_up E32 M131072 balanced wgrad accumulate main_grad += dW 6.3659 ms 4.8964 ms (TE GroupedLinear) 5.1929 ms 1.224x [1.221, 1.228] 0.949x [0.933, 0.951]
B200 sm_100a (148 SM) down E32 M131072 short16 wgrad accumulate main_grad += dW 3.3234 ms 2.6744 ms (TE GroupedLinear) 2.7371 ms 1.213x [1.207, 1.230] 0.969x [0.957, 0.977]
B200 sm_100a (148 SM) gate_up E32 M131072 short16 wgrad accumulate main_grad += dW 6.5647 ms 5.4345 ms (TE GroupedLinear) 5.4054 ms 1.213x [1.200, 1.218] 1.005x [0.996, 1.017]
B200 sm_100a (148 SM) down E4 M112576 balanced full backward 3.8158 ms 3.9179 ms (per-op best composite) 3.8630 ms 0.988x [0.953, 1.035] 1.021x [0.973, 1.060]
B200 sm_100a (148 SM) down E4 M112576 one_empty full backward 3.8533 ms 3.9106 ms (cuBLAS per expert) 3.7897 ms 1.009x [0.966, 1.039] 1.037x [1.010, 1.058]
B200 sm_100a (148 SM) down E4 M112576 skewed full backward 3.9614 ms 3.9705 ms (TE GroupedLinear) 3.8252 ms 1.022x [0.972, 1.075] 1.046x [1.018, 1.069]
B200 sm_100a (148 SM) down E4 M136064 balanced full backward 4.7381 ms 4.8586 ms (per-op best composite) 4.7544 ms 1.003x [0.935, 1.015] 1.020x [0.975, 1.064]
B200 sm_100a (148 SM) down E4 M136064 one_empty full backward 4.7094 ms 4.7898 ms (per-op best composite) 4.6720 ms 0.996x [0.947, 1.019] 1.011x [0.965, 1.032]
B200 sm_100a (148 SM) down E4 M136064 skewed full backward 4.6628 ms 4.7713 ms (per-op best composite) 4.6273 ms 1.009x [0.988, 1.047] 1.032x [0.984, 1.064]
B200 sm_100a (148 SM) down E8 M131072 balanced full backward 4.6609 ms 4.3761 ms (per-op best composite) 4.5687 ms 1.029x [0.989, 1.058] 0.951x [0.928, 0.987]
B200 sm_100a (148 SM) down E16 M131072 balanced full backward 4.8343 ms 4.4518 ms (per-op best composite) 4.6224 ms 1.042x [1.023, 1.052] 0.968x [0.935, 0.984]
B200 sm_100a (148 SM) down E32 M131072 balanced full backward 5.2881 ms 4.6164 ms (per-op best composite) 4.5901 ms 1.142x [1.127, 1.165] 1.012x [1.007, 1.023]
B200 sm_100a (148 SM) gate_up E4 M112576 balanced full backward 7.8503 ms 7.7636 ms (per-op best composite) 7.8527 ms 0.996x [0.907, 1.030] 0.989x [0.892, 1.038]
B200 sm_100a (148 SM) gate_up E4 M112576 one_empty full backward 7.8770 ms 7.6493 ms (per-op best composite) 8.1240 ms 0.962x [0.815, 1.009] 0.943x [0.805, 0.982]
B200 sm_100a (148 SM) gate_up E4 M112576 skewed full backward 7.8144 ms 7.6672 ms (per-op best composite) 7.9282 ms 0.988x [0.928, 1.008] 0.978x [0.887, 1.009]
B200 sm_100a (148 SM) gate_up E4 M136064 balanced full backward 9.5062 ms 9.4573 ms (per-op best composite) 10.1213 ms 0.940x [0.825, 0.993] 0.942x [0.800, 0.999]
B200 sm_100a (148 SM) gate_up E4 M136064 one_empty full backward 9.7194 ms 9.2951 ms (TE GroupedLinear) 9.7383 ms 0.974x [0.847, 1.020] 0.953x [0.775, 1.001]
B200 sm_100a (148 SM) gate_up E4 M136064 skewed full backward 9.6177 ms 9.3882 ms (per-op best composite) 10.4499 ms 0.912x [0.811, 1.012] 0.910x [0.781, 1.014]
B200 sm_100a (148 SM) gate_up E8 M131072 balanced full backward 9.3142 ms 9.0295 ms (per-op best composite) 9.4965 ms 0.961x [0.874, 1.019] 0.959x [0.846, 0.997]
B200 sm_100a (148 SM) gate_up E16 M131072 balanced full backward 9.9937 ms 9.0354 ms (TE GroupedLinear) 9.3878 ms 1.065x [1.018, 1.100] 0.959x [0.931, 1.006]
B200 sm_100a (148 SM) gate_up E32 M131072 balanced full backward 10.8033 ms 9.0151 ms (per-op best composite) 9.6466 ms 1.120x [1.087, 1.143] 0.931x [0.904, 0.943]
B200 sm_100a (148 SM) down E32 M131072 short16 full backward 5.3967 ms 4.6995 ms (per-op best composite) 4.8538 ms 1.101x [1.081, 1.131] 0.977x [0.928, 0.988]
B200 sm_100a (148 SM) gate_up E32 M131072 short16 full backward 10.9584 ms 9.5631 ms (per-op best composite) 10.0304 ms 1.095x [1.073, 1.120] 0.934x [0.915, 0.972]
B200 sm_100a (148 SM) down E4 M112576 balanced checkpointed 2×fwd + bwd 7.9732 ms 8.0072 ms (per-op best composite) 7.8860 ms 1.010x [1.004, 1.018] 1.018x [1.005, 1.032]
B200 sm_100a (148 SM) down E4 M112576 one_empty checkpointed 2×fwd + bwd 7.9394 ms 8.0950 ms (cuBLAS per expert) 7.7809 ms 1.017x [1.012, 1.024] 1.044x [1.036, 1.052]
B200 sm_100a (148 SM) down E4 M112576 skewed checkpointed 2×fwd + bwd 7.9293 ms 8.0271 ms (TE GroupedLinear) 7.7819 ms 1.019x [1.013, 1.022] 1.031x [1.018, 1.038]
B200 sm_100a (148 SM) down E4 M136064 balanced checkpointed 2×fwd + bwd 9.6260 ms 9.7217 ms (per-op best composite) 9.5195 ms 1.010x [1.001, 1.024] 1.022x [1.016, 1.036]
B200 sm_100a (148 SM) down E4 M136064 one_empty checkpointed 2×fwd + bwd 9.5560 ms 9.5924 ms (per-op best composite) 9.5112 ms 1.012x [1.001, 1.017] 1.012x [1.002, 1.023]
B200 sm_100a (148 SM) down E4 M136064 skewed checkpointed 2×fwd + bwd 9.6129 ms 9.7576 ms (per-op best composite) 9.5258 ms 1.009x [1.003, 1.020] 1.023x [1.021, 1.030]
B200 sm_100a (148 SM) down E8 M131072 balanced checkpointed 2×fwd + bwd 9.4106 ms 9.4518 ms (per-op best composite) 9.2273 ms 1.020x [1.002, 1.023] 1.020x [1.011, 1.029]
B200 sm_100a (148 SM) down E16 M131072 balanced checkpointed 2×fwd + bwd 9.6754 ms 9.5837 ms (per-op best composite) 9.3735 ms 1.025x [1.019, 1.041] 1.022x [1.008, 1.040]
B200 sm_100a (148 SM) down E32 M131072 balanced checkpointed 2×fwd + bwd 10.1720 ms 9.6803 ms (TE GroupedLinear) 9.5480 ms 1.068x [1.060, 1.073] 1.012x [1.006, 1.017]
B200 sm_100a (148 SM) gate_up E4 M112576 balanced checkpointed 2×fwd + bwd 16.0383 ms 16.1822 ms (TE GroupedLinear) 15.9764 ms 1.012x [0.997, 1.017] 1.019x [1.009, 1.027]
B200 sm_100a (148 SM) gate_up E4 M112576 one_empty checkpointed 2×fwd + bwd 16.2276 ms 15.9097 ms (TE GroupedLinear) 15.9490 ms 1.015x [1.008, 1.024] 1.002x [0.986, 1.008]
B200 sm_100a (148 SM) gate_up E4 M112576 skewed checkpointed 2×fwd + bwd 16.0908 ms 16.0870 ms (TE GroupedLinear) 15.8985 ms 1.012x [0.995, 1.021] 1.011x [1.009, 1.019]
B200 sm_100a (148 SM) gate_up E4 M136064 balanced checkpointed 2×fwd + bwd 19.4156 ms 19.4897 ms (TE GroupedLinear) 19.2383 ms 1.009x [0.996, 1.019] 1.014x [1.006, 1.025]
B200 sm_100a (148 SM) gate_up E4 M136064 one_empty checkpointed 2×fwd + bwd 19.5459 ms 19.4731 ms (TE GroupedLinear) 19.3653 ms 1.011x [1.007, 1.017] 1.012x [1.000, 1.017]
B200 sm_100a (148 SM) gate_up E4 M136064 skewed checkpointed 2×fwd + bwd 19.4896 ms 19.4274 ms (per-op best composite) 19.4804 ms 1.006x [0.994, 1.011] 1.000x [0.989, 1.006]
B200 sm_100a (148 SM) gate_up E8 M131072 balanced checkpointed 2×fwd + bwd 18.7785 ms 18.6674 ms (per-op best composite) 18.4058 ms 1.022x [1.013, 1.028] 1.018x [1.006, 1.027]
B200 sm_100a (148 SM) gate_up E16 M131072 balanced checkpointed 2×fwd + bwd 19.4098 ms 19.0378 ms (TE GroupedLinear) 18.7942 ms 1.036x [1.020, 1.039] 1.013x [1.010, 1.021]
B200 sm_100a (148 SM) gate_up E32 M131072 balanced checkpointed 2×fwd + bwd 20.3543 ms 19.4478 ms (TE GroupedLinear) 19.2097 ms 1.055x [1.053, 1.062] 1.009x [1.002, 1.015]
B200 sm_100a (148 SM) down E32 M131072 short16 checkpointed 2×fwd + bwd 10.3874 ms 9.9309 ms (per-op best composite) 9.6838 ms 1.071x [1.065, 1.076] 1.023x [1.002, 1.037]
B200 sm_100a (148 SM) gate_up E32 M131072 short16 checkpointed 2×fwd + bwd 20.7306 ms 20.1212 ms (per-op best composite) 19.6054 ms 1.057x [1.045, 1.069] 1.035x [1.018, 1.041]

R200 sm_107a

GPU / architecture workload / shape operation deterministic Cake latency non-Cake SOTA latency new non-deterministic Cake latency speedup vs deterministic Cake speedup vs non-Cake SOTA
R200 sm_107a (208 SM) down E4 M112576 balanced wgrad accumulate main_grad += dW 0.9899 ms 0.9392 ms (TE GroupedLinear) 0.9569 ms 1.035x [1.033, 1.038] 0.981x [0.968, 0.985]
R200 sm_107a (208 SM) down E4 M112576 one_empty wgrad accumulate main_grad += dW 1.0000 ms 0.9308 ms (TE GroupedLinear) 0.9463 ms 1.057x [1.055, 1.062] 0.984x [0.977, 0.987]
R200 sm_107a (208 SM) down E4 M112576 skewed wgrad accumulate main_grad += dW 0.9990 ms 0.9412 ms (TE GroupedLinear) 0.9475 ms 1.053x [1.050, 1.059] 0.991x [0.989, 0.994]
R200 sm_107a (208 SM) down E4 M136064 balanced wgrad accumulate main_grad += dW 1.1965 ms 1.1246 ms (TE GroupedLinear) 1.1614 ms 1.024x [1.019, 1.032] 0.963x [0.958, 0.984]
R200 sm_107a (208 SM) down E4 M136064 one_empty wgrad accumulate main_grad += dW 1.1866 ms 1.1092 ms (TE GroupedLinear) 1.1556 ms 1.029x [1.018, 1.044] 0.961x [0.954, 0.972]
R200 sm_107a (208 SM) down E4 M136064 skewed wgrad accumulate main_grad += dW 1.1936 ms 1.1247 ms (TE GroupedLinear) 1.1492 ms 1.040x [1.039, 1.045] 0.981x [0.974, 0.993]
R200 sm_107a (208 SM) down E8 M131072 balanced wgrad accumulate main_grad += dW 1.1884 ms 1.1138 ms (TE GroupedLinear) 1.1190 ms 1.059x [1.057, 1.067] 0.994x [0.991, 0.997]
R200 sm_107a (208 SM) down E16 M131072 balanced wgrad accumulate main_grad += dW 1.3292 ms 1.1326 ms (TE GroupedLinear) 1.1704 ms 1.135x [1.132, 1.144] 0.970x [0.965, 0.973]
R200 sm_107a (208 SM) down E32 M131072 balanced wgrad accumulate main_grad += dW 1.5826 ms 1.1977 ms (TE GroupedLinear) 1.2037 ms 1.318x [1.315, 1.324] 0.998x [0.992, 0.999]
R200 sm_107a (208 SM) down E32 M131072 short16 wgrad accumulate main_grad += dW 1.6067 ms 1.2224 ms (TE GroupedLinear) 1.2442 ms 1.290x [1.282, 1.304] 0.984x [0.974, 0.985]
R200 sm_107a (208 SM) gate_up E4 M112576 balanced wgrad accumulate main_grad += dW 1.9847 ms 1.9292 ms (cuBLAS per expert) 1.8860 ms 1.050x [1.042, 1.061] 1.022x [1.016, 1.045]
R200 sm_107a (208 SM) gate_up E4 M112576 one_empty wgrad accumulate main_grad += dW 2.0270 ms 1.9360 ms (cuBLAS per expert) 1.9215 ms 1.053x [1.050, 1.058] 1.001x [0.992, 1.022]
R200 sm_107a (208 SM) gate_up E4 M112576 skewed wgrad accumulate main_grad += dW 2.0295 ms 1.9266 ms (cuBLAS per expert) 1.9248 ms 1.055x [1.049, 1.065] 1.000x [0.990, 1.010]
R200 sm_107a (208 SM) gate_up E4 M136064 balanced wgrad accumulate main_grad += dW 2.3934 ms 2.3381 ms (cuBLAS per expert) 2.2900 ms 1.041x [1.029, 1.060] 1.028x [1.002, 1.053]
R200 sm_107a (208 SM) gate_up E4 M136064 one_empty wgrad accumulate main_grad += dW 2.3997 ms 2.3025 ms (TE GroupedLinear) 2.2915 ms 1.043x [1.040, 1.051] 1.002x [0.998, 1.013]
R200 sm_107a (208 SM) gate_up E4 M136064 skewed wgrad accumulate main_grad += dW 2.3996 ms 2.2990 ms (cuBLAS per expert) 2.3025 ms 1.041x [1.036, 1.044] 0.996x [0.987, 1.005]
R200 sm_107a (208 SM) gate_up E8 M131072 balanced wgrad accumulate main_grad += dW 2.3640 ms 2.3010 ms (cuBLAS per expert) 2.2308 ms 1.058x [1.049, 1.079] 1.036x [1.017, 1.046]
R200 sm_107a (208 SM) gate_up E16 M131072 balanced wgrad accumulate main_grad += dW 2.5991 ms 2.3561 ms (TE GroupedLinear) 2.3176 ms 1.122x [1.117, 1.124] 1.016x [1.010, 1.030]
R200 sm_107a (208 SM) gate_up E32 M131072 balanced wgrad accumulate main_grad += dW 3.1305 ms 2.4561 ms (TE GroupedLinear) 2.4371 ms 1.285x [1.283, 1.287] 1.009x [1.006, 1.010]
R200 sm_107a (208 SM) gate_up E32 M131072 short16 wgrad accumulate main_grad += dW 3.2321 ms 2.5446 ms (TE GroupedLinear) 2.4962 ms 1.293x [1.287, 1.301] 1.018x [1.015, 1.025]
R200 sm_107a (208 SM) down E4 M112576 balanced full backward 1.6804 ms 1.6770 ms (TE GroupedLinear) 1.6289 ms 1.032x [1.027, 1.037] 1.026x [1.018, 1.031]
R200 sm_107a (208 SM) down E4 M112576 one_empty full backward 1.6982 ms 1.6540 ms (TE GroupedLinear) 1.6253 ms 1.046x [1.043, 1.048] 1.017x [1.015, 1.022]
R200 sm_107a (208 SM) down E4 M112576 skewed full backward 1.6859 ms 1.6740 ms (TE GroupedLinear) 1.6057 ms 1.054x [1.049, 1.055] 1.041x [1.039, 1.044]
R200 sm_107a (208 SM) down E4 M136064 balanced full backward 2.0527 ms 2.0596 ms (TE grouped tensor) 2.0034 ms 1.025x [1.023, 1.026] 1.027x [1.016, 1.031]
R200 sm_107a (208 SM) down E4 M136064 one_empty full backward 2.1099 ms 2.0495 ms (TE GroupedLinear) 2.0380 ms 1.034x [1.030, 1.039] 1.007x [1.001, 1.009]
R200 sm_107a (208 SM) down E4 M136064 skewed full backward 2.1254 ms 2.0529 ms (TE GroupedLinear) 2.0441 ms 1.043x [1.040, 1.044] 1.004x [0.999, 1.009]
R200 sm_107a (208 SM) down E8 M131072 balanced full backward 2.0192 ms 2.0115 ms (TE GroupedLinear) 1.9082 ms 1.057x [1.054, 1.062] 1.055x [1.043, 1.063]
R200 sm_107a (208 SM) down E16 M131072 balanced full backward 2.1650 ms 2.0776 ms (per-op best composite) 1.9439 ms 1.116x [1.109, 1.129] 1.070x [1.064, 1.080]
R200 sm_107a (208 SM) down E32 M131072 balanced full backward 2.5465 ms 2.1716 ms (per-op best composite) 2.0818 ms 1.220x [1.202, 1.234] 1.037x [1.025, 1.057]
R200 sm_107a (208 SM) down E32 M131072 short16 full backward 2.5853 ms 2.2696 ms (per-op best composite) 2.1972 ms 1.184x [1.157, 1.211] 1.039x [1.004, 1.054]
R200 sm_107a (208 SM) gate_up E4 M112576 balanced full backward 3.4967 ms 3.7043 ms (TE grouped tensor) 3.4087 ms 1.031x [1.004, 1.049] 1.089x [1.056, 1.112]
R200 sm_107a (208 SM) gate_up E4 M112576 one_empty full backward 3.5770 ms 3.6093 ms (cuBLAS per expert) 3.3858 ms 1.058x [1.036, 1.062] 1.061x [1.049, 1.066]
R200 sm_107a (208 SM) gate_up E4 M112576 skewed full backward 3.5532 ms 3.6222 ms (cuBLAS per expert) 3.3980 ms 1.050x [1.030, 1.061] 1.073x [1.050, 1.077]
R200 sm_107a (208 SM) gate_up E4 M136064 balanced full backward 4.3097 ms 4.5496 ms (per-op best composite) 4.1925 ms 1.028x [1.004, 1.047] 1.086x [1.074, 1.104]
R200 sm_107a (208 SM) gate_up E4 M136064 one_empty full backward 4.4614 ms 4.3396 ms (cuBLAS per expert) 4.3136 ms 1.032x [0.998, 1.067] 1.019x [0.975, 1.040]
R200 sm_107a (208 SM) gate_up E4 M136064 skewed full backward 4.3926 ms 4.4356 ms (TE GroupedLinear) 4.2812 ms 1.022x [0.992, 1.040] 1.029x [1.019, 1.046]
R200 sm_107a (208 SM) gate_up E8 M131072 balanced full backward 4.2620 ms 4.2412 ms (TE GroupedLinear) 4.0659 ms 1.051x [1.028, 1.069] 1.044x [1.028, 1.063]
R200 sm_107a (208 SM) gate_up E16 M131072 balanced full backward 4.6161 ms 4.3638 ms (TE GroupedLinear) 4.0961 ms 1.129x [1.069, 1.174] 1.058x [1.036, 1.118]
R200 sm_107a (208 SM) gate_up E32 M131072 balanced full backward 5.1904 ms 4.2898 ms (TE GroupedLinear) 4.2737 ms 1.211x [1.184, 1.226] 1.002x [0.980, 1.021]
R200 sm_107a (208 SM) gate_up E32 M131072 short16 full backward 5.1411 ms 4.5700 ms (TE GroupedLinear) 4.4042 ms 1.178x [1.166, 1.199] 1.027x [1.014, 1.044]
R200 sm_107a (208 SM) down E4 M112576 balanced checkpointed 2×fwd + bwd 3.8093 ms 3.8539 ms (per-op best composite) 3.7410 ms 1.015x [1.008, 1.024] 1.030x [1.026, 1.037]
R200 sm_107a (208 SM) down E4 M112576 one_empty checkpointed 2×fwd + bwd 3.8047 ms 3.7793 ms (per-op best composite) 3.7331 ms 1.015x [1.011, 1.021] 1.010x [1.004, 1.021]
R200 sm_107a (208 SM) down E4 M112576 skewed checkpointed 2×fwd + bwd 3.7876 ms 3.7742 ms (per-op best composite) 3.7193 ms 1.014x [1.006, 1.022] 1.012x [1.007, 1.019]
R200 sm_107a (208 SM) down E4 M136064 balanced checkpointed 2×fwd + bwd 4.5902 ms 4.6170 ms (per-op best composite) 4.5379 ms 1.012x [1.005, 1.016] 1.013x [1.005, 1.018]
R200 sm_107a (208 SM) down E4 M136064 one_empty checkpointed 2×fwd + bwd 4.5390 ms 4.5589 ms (per-op best composite) 4.4244 ms 1.019x [1.012, 1.034] 1.028x [1.015, 1.039]
R200 sm_107a (208 SM) down E4 M136064 skewed checkpointed 2×fwd + bwd 4.5266 ms 4.5777 ms (per-op best composite) 4.4950 ms 1.005x [1.002, 1.012] 1.020x [1.009, 1.031]
R200 sm_107a (208 SM) down E8 M131072 balanced checkpointed 2×fwd + bwd 4.4575 ms 4.5334 ms (per-op best composite) 4.4028 ms 1.012x [1.011, 1.026] 1.032x [1.029, 1.037]
R200 sm_107a (208 SM) down E16 M131072 balanced checkpointed 2×fwd + bwd 4.6076 ms 4.6899 ms (TE GroupedLinear) 4.4066 ms 1.041x [1.033, 1.055] 1.053x [1.044, 1.067]
R200 sm_107a (208 SM) down E32 M131072 balanced checkpointed 2×fwd + bwd 4.8152 ms 4.6936 ms (TE GroupedLinear) 4.4767 ms 1.075x [1.067, 1.108] 1.050x [1.044, 1.057]
R200 sm_107a (208 SM) down E32 M131072 short16 checkpointed 2×fwd + bwd 4.9225 ms 4.8810 ms (TE GroupedLinear) 4.6299 ms 1.065x [1.057, 1.073] 1.058x [1.051, 1.061]
R200 sm_107a (208 SM) gate_up E4 M112576 balanced checkpointed 2×fwd + bwd 7.7461 ms 7.9608 ms (cuBLAS per expert) 7.6561 ms 1.014x [1.008, 1.018] 1.041x [1.023, 1.056]
R200 sm_107a (208 SM) gate_up E4 M112576 one_empty checkpointed 2×fwd + bwd 7.8350 ms 7.9797 ms (TE GroupedLinear) 7.5770 ms 1.026x [1.012, 1.042] 1.051x [1.039, 1.068]
R200 sm_107a (208 SM) gate_up E4 M112576 skewed checkpointed 2×fwd + bwd 7.7205 ms 7.9198 ms (per-op best composite) 7.6066 ms 1.011x [1.004, 1.034] 1.044x [1.020, 1.050]
R200 sm_107a (208 SM) gate_up E4 M136064 balanced checkpointed 2×fwd + bwd 9.3406 ms 9.5523 ms (per-op best composite) 9.2435 ms 1.011x [1.002, 1.017] 1.032x [1.025, 1.039]
R200 sm_107a (208 SM) gate_up E4 M136064 one_empty checkpointed 2×fwd + bwd 9.0654 ms 9.2369 ms (per-op best composite) 8.9604 ms 1.015x [1.006, 1.024] 1.030x [1.021, 1.041]
R200 sm_107a (208 SM) gate_up E4 M136064 skewed checkpointed 2×fwd + bwd 9.1660 ms 9.2383 ms (per-op best composite) 9.0998 ms 1.012x [1.005, 1.019] 1.020x [1.011, 1.028]
R200 sm_107a (208 SM) gate_up E8 M131072 balanced checkpointed 2×fwd + bwd 9.1075 ms 9.3610 ms (cuBLAS per expert) 8.9517 ms 1.023x [1.006, 1.027] 1.047x [1.038, 1.066]
R200 sm_107a (208 SM) gate_up E16 M131072 balanced checkpointed 2×fwd + bwd 9.2294 ms 9.5625 ms (per-op best composite) 8.9940 ms 1.023x [1.015, 1.032] 1.061x [1.053, 1.075]
R200 sm_107a (208 SM) gate_up E32 M131072 balanced checkpointed 2×fwd + bwd 9.5484 ms 9.6964 ms (TE GroupedLinear) 9.0490 ms 1.054x [1.047, 1.058] 1.069x [1.065, 1.073]
R200 sm_107a (208 SM) gate_up E32 M131072 short16 checkpointed 2×fwd + bwd 9.8620 ms 9.9044 ms (TE GroupedLinear) 9.4239 ms 1.049x [1.039, 1.054] 1.058x [1.047, 1.063]

The family also ships the deterministic variant, BF16 and FP32 dW outputs, and the forward and data-gradient programs on sm_100a (B200), sm_103a (GB300) and sm_107a (R200), and this PR's fused accumulate builds cover all three architectures.

grouped_gemm_wgrad / prepare_grouped_gemm_wgrad take accumulate=True:
the launch adds G_e^T X_e into the caller's out[e] (out <- out + dW).
The fused route binds the accumulating build of the selected main stage
(K tile 512, 32-byte aligned out); every other plan computes into a
scratch of out's dtype and adds it (composed route).  plan["accumulate"]
names the route.  Both routes check out before any launch: dtype, row
and expert strides (an expanded out is rejected) and no overlap with the
operands.  The fused route bumps out's version counter.

cake_grouped_mm(..., fuse_wgrad_accumulation=True) accumulates the
weight gradient into w.main_grad in the backward (Megatron-Core
gradient_accumulation_fusion convention) and returns the placeholder
weight gradient.  The facade routes accumulate=True on the deterministic
route through the deterministic weight gradient plus an add.

Adds the accumulation tests, the benchmark arms and the README / API
docs sections.  Defaults are unchanged.
… builds

Regenerate the package's generated files (the PROGRAMS and ROUTES tables of
cake_jit.py, build.json and csrc/cake_moe_grouped_gemm/) with the fp32
accumulate builds of the three half-release forms of the 512-wide weight
gradient, which add the weight gradient to out (out += dW):

- 3 programs, each served as a stage of the fp32 512-wide route only:
  main_halves_acc (sm_100a, sm_103a, sm_107a), main_wave_halves_acc
  (sm_100a, sm_103a) and main_halves_k256t_acc (sm_107a).  The existing
  stages keep their order and programs; the bf16 route is unchanged.
- 6 build.json entries, min_cuda 13.4 (the fp32 .noftz reduction needs PTX
  ISA 9.4).  The accumulate programs share their own binding templates.
- The existing generated kernel units drop unused macros and reword
  comments; their SASS and resource usage are unchanged on every
  architecture they build for.  No existing program is renamed or removed.
…ey load

Follow-up of the fp32 accumulate builds for the host, tests, docs and
benchmark:

- Route rule: an accumulate call is fused only when the 512-wide k tile
  adds its split tail in place (never beside an overwriting tail-reduce
  stage: reason "tail"), the route serves the stage's accumulate build, its
  library can load by the loader's static rule (a prebuilt library under
  aot/, or a FlashInfer JIT toolkit at the build's min_cuda; nothing is
  compiled or loaded to decide it: reason "min_cuda", one warning) and out is
  32-byte aligned.  An fp32 accumulate on a toolkit below CUDA 13.4 now
  composes instead of failing at the preparation.
  generated_program_available(accumulate=True) applies the same rule and is
  False for a dtype the weight gradient does not write.
- Docs: the fused builds add into an fp32 out only; a bf16 out composes (the
  bf16 overwrite and a same-dtype add_: AccumulateGrad's bits and cost).
  The numerical contract states that subnormals are kept in the add into C,
  not in the split tail's partial sum; the composed scratch is owned by the
  prepared launch (keep it alive while a captured graph may replay); the peak
  memory saving is stated against an fp32 dW plus add_ (2 x E x N x K bytes
  with the placeholder gradient) and against the bf16 w.grad path (equal).
- Tests: the registry's accumulate stages must be exactly the shipped set
  (also stated by the README and rst feature rows), the build.json entries
  are required, a shipped build is required to fuse wherever it can load,
  the loader rule and the ordered-tail rule have CPU tests, every benchmark
  row is checked on the fused fp32 route as planned (fp64 budget, no lost
  update, empty groups bitwise, bitwise out0.add_(dW32) outside the split
  tail) and on the composed bf16 route, and the bf16 budget of an
  accumulate is operand-scaled.
- Benchmark: the deterministic package's baselines (det_acc: its fp32 dW
  plus main_grad.add_, also in the autograd step; det_mgB: its bf16 w.grad
  plus the fp32 add) and a backward-only accumulation row (bwd_acc).
…y device

The sanitize entry searched its split case over four small groups that
never split a tail, so it printed "no shape" and sanitized unsplit tails
only. The split case now takes the groups the split-tail tests use, and
the entry fails when a shipped build has no split or unsplit case.
…backward only

With fuse_wgrad_accumulation=True the forward checked w.main_grad on every
call. In nested non-reentrant checkpoints, torch recomputes the inner
region inside the backward with an alias of w that has no Python
attributes, so the recompute raised "w has no main_grad tensor". The
forward now checks main_grad only outside the autograd engine (graph task
id -1). The backward of the original forward reads its own ctx.w and
checks main_grad there, so a reentrant checkpoint still raises at the
backward.
… count

The split-tail test and the sanitize entry searched one set of group
sizes, which splits no k256t tail at 160 or 208 SMs (R200 208-SM board:
"no candidate shape splits the main_halves_k256t tail"). Both now try
SPLIT_SIZES in order (the old sizes first, so other devices keep their
case) and take the first whose plan splits the tail.
…autograd records

With fuse_wgrad_accumulation=True, a forward under torch.no_grad() or
inference mode raised "w has no main_grad tensor" for a w that requires
grad but has no main_grad, although no backward reads it then. The check
now runs in cake_grouped_mm before apply, when w requires grad, grad mode
is on and the call is not a checkpoint recompute inside a backward. It
leaves CakeGroupedMm.forward, which runs with grad mode off and cannot
see the caller's mode. The backward still checks w.main_grad, so a direct
apply is checked there. The host refusal test covers no_grad and
inference mode.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df9ce5fa-86d8-4847-a91c-f94c1d4c9f5e
Commits

Reviewing files that changed from the base of the PR and between c5db8d3 and 285356f.

Files selected for processing: 34
  • benchmarks/bench_cake_moe_grouped_gemm.py
  • docs/api/cake_moe_grouped_gemm.rst
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/README.md
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/__init__.py
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/build.json
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/cake_autograd.py
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/cake_backend.py
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/cake_jit.py
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_037c741e69a0ccc696e0_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_1edcad995dcc790600cb_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_276cec1f1d2c8ba1e4cb_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_31c75174ffde0411360a_wgrad_out32_binding.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_31c75174ffde0411360a_wgrad_out32_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_3edd5c53a1269a6095a7_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_4f40b5f07baf6e086fdd_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_5064b19de3716266ed03_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_55833be10c8515562245_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_56f7360e67516c1d0ed4_wgrad_out32_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_594235460aac7658daab_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_6bd667b99e236d0c69df_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_6be356d4d7ce990aa413_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_6db26c5927b4738a8b8f_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_6e4ada2cdc0bc78f14ba_wgrad_out32_binding.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_6e4ada2cdc0bc78f14ba_wgrad_out32_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_7e39db00fc7c99693f3e_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_994f65a456ae68a92e84_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_9df3c426f0afac83124c_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_aba5ff762eb9355f540a_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_c6cc9d6508fe7a5e9b67_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_ce655879551e583539e2_kernel.cu
  • flashinfer/experimental/cake/cake_moe_grouped_gemm/csrc/cake_moe_grouped_gemm/cake_moe_grouped_gemm_fc0a5c2da4d4782f42eb_kernel.cu
  • flashinfer/experimental/cake/grouped_mm.py
  • tests/experimental/test_cake_moe_grouped_gemm_acc.py
  • tests/experimental/test_cake_moe_grouped_gemm_reproducibility.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@yyihuang

yyihuang commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

@flashinfer-bot run tests/experimental/test_cake_moe_grouped_gemm.py tests/experimental/test_cake_moe_grouped_gemm_acc.py tests/experimental/test_cake_moe_grouped_gemm_api.py tests/experimental/test_cake_moe_grouped_gemm_reproducibility.py tests/experimental/test_cake_moe_grouped_gemm_standalone.py tests/experimental/test_cake_moe_grouped_det_gemm.py tests/experimental/test_cake_moe_grouped_det_gemm_alias.py tests/experimental/test_cake_moe_grouped_det_gemm_api.py tests/experimental/test_cake_moe_grouped_det_gemm_standalone.py

@yyihuang

yyihuang commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

@flashinfer-bot run tests/experimental/test_cake_moe_grouped_gemm.py tests/experimental/test_cake_moe_grouped_gemm_acc.py tests/experimental/test_cake_moe_grouped_gemm_api.py tests/experimental/test_cake_moe_grouped_gemm_reproducibility.py tests/experimental/test_cake_moe_grouped_gemm_standalone.py tests/experimental/test_cake_moe_grouped_det_gemm.py tests/experimental/test_cake_moe_grouped_det_gemm_alias.py tests/experimental/test_cake_moe_grouped_det_gemm_api.py tests/experimental/test_cake_moe_grouped_det_gemm_standalone.py

@yyihuang
yyihuang marked this pull request as ready for review November 4, 2026 07:25
@yyihuang
yyihuang enabled auto-merge (squash) November 4, 2026 07:25
@yyihuang

yyihuang commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

@flashinfer-bot run tests/experimental/test_cake_moe_grouped_gemm.py tests/experimental/test_cake_moe_grouped_gemm_acc.py tests/experimental/test_cake_moe_grouped_gemm_api.py tests/experimental/test_cake_moe_grouped_gemm_reproducibility.py tests/experimental/test_cake_moe_grouped_gemm_standalone.py tests/experimental/test_cake_moe_grouped_det_gemm.py tests/experimental/test_cake_moe_grouped_det_gemm_alias.py tests/experimental/test_cake_moe_grouped_det_gemm_api.py tests/experimental/test_cake_moe_grouped_det_gemm_standalone.py

@yzh119 yzh119 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One nit: cake_backend.py imports _jit_toolchain, _local_cuda_version, _version, libraries_by_name and prebuilt_path from cake_build. Make sure they all exist there, since that file isn't in the diff.

@yyihuang
yyihuang merged commit 3064b3e into flashinfer-ai:main Nov 4, 2026
43 checks passed
yyihuang added a commit that referenced this pull request Nov 6, 2026
…ic=False, and deterministic weight-gradient accumulation (#8924)

## Summary

This PR changes the Cake MoE grouped GEMM in FlashInfer host code only.
Kernels and programs are unchanged.

1. **Det-only names.** The deterministic grouped GEMM can now be reached
only through names that contain `det`. All old det-free names and
compatibility aliases are removed with no shim. Old imports raise
`ModuleNotFoundError` and old attributes raise `AttributeError`.
2. **Explicit `deterministic=False`.** The non-deterministic package and
the `flashinfer.experimental.cake.grouped_mm` facade run only when
`deterministic=False` is passed explicitly. PyTorch's non-determinism
alert fires only right before an order-varying launch.
3. **Deterministic weight-gradient accumulation.**
`grouped_det_gemm_wgrad(..., out=main_grad, accumulate=True)` and
`cake_grouped_det_mm(..., fuse_wgrad_accumulation=True)` accumulate into
`main_grad`. The result is bitwise equal to AccumulateGrad of the
deterministic dW and bitwise identical from run to run.

In this description, the *det package* is
`flashinfer.experimental.cake_moe_grouped_det_gemm` and the *non-det
package* is `flashinfer.experimental.cake.cake_moe_grouped_gemm`.

## Breaking change: det-only names

No alias, shim, module `__getattr__` or compatibility entry is left
anywhere.

| Old (removed) | Error now | Det name to use |
| --- | --- | --- |
| package `flashinfer.experimental.cake_moe_grouped_gemm` and submodules
`cake_autograd`, `cake_backend`, `cake_build`, `cake_jit` (directory
deleted) | `ModuleNotFoundError` |
`flashinfer.experimental.cake_moe_grouped_det_gemm` (same submodules) |
| module `flashinfer.grouped_mm.cake` (renamed with `git mv`) |
`ModuleNotFoundError` | `flashinfer.grouped_mm.cake_det` |
| `flashinfer.grouped_mm.{grouped_gemm_fwd, grouped_gemm_dgrad,
grouped_gemm_wgrad, cake_grouped_mm}` | `AttributeError` |
`flashinfer.grouped_mm.{grouped_det_gemm_fwd, grouped_det_gemm_dgrad,
grouped_det_gemm_wgrad, cake_grouped_det_mm}` |
| det package root `grouped_gemm_{fwd,dgrad,wgrad}`,
`prepare_grouped_gemm_{fwd,dgrad,wgrad}`, `GroupedGemmLaunch`,
`CakeGroupedMm`, `cake_grouped_mm` | `AttributeError` |
`grouped_det_gemm_{fwd,dgrad,wgrad}`,
`prepare_grouped_det_gemm_{fwd,dgrad,wgrad}`, `GroupedDetGemmLaunch`,
`CakeGroupedDetMm`, `cake_grouped_det_mm` |
| det `cake_backend.{GroupedGemmLaunch, grouped_mm_bf16_cake,
prepare_grouped_gemm_*}` | `AttributeError` |
`cake_backend.{GroupedDetGemmLaunch, grouped_det_mm_bf16_cake,
prepare_grouped_det_gemm_*}` |
| det `cake_autograd.{CakeGroupedMm, cake_grouped_mm}` |
`AttributeError` | `cake_autograd.{CakeGroupedDetMm,
cake_grouped_det_mm}` |
| `_RENAMED` maps and alias `__getattr__` in det `__init__`,
`cake_autograd`, `cake_backend`, `grouped_mm/cake(_det).py`,
`grouped_mm/__init__.py` (and its `_Any` import) | deleted | - |
| `deterministic` parameter of every det entry (`cake_grouped_det_mm` in
the det package and in `grouped_mm.cake_det`) | `TypeError` | omit it |
| `CakeGroupedDetMm.apply(x, w, offs, <mode>)` (stale 4th positional
mode) | `TypeError` "takes no fourth argument" | `apply(x, w, offs)`;
fuse: `apply(x, w, offs, None, True)` |
| test-helper key `PACKAGES["cake_moe_grouped_gemm"]` (MoE entry of the
shared `tests/test_helpers/cake_package.py` only) | `KeyError` |
`"cake_moe_grouped_det_gemm"` (and `"cake.cake_moe_grouped_gemm"` for
the non-det package) |
| `tests/experimental/test_cake_moe_grouped_det_gemm_alias.py` | deleted
| absence tests in `test_cake_moe_grouped_det_gemm_api.py` /
`test_cake_moe_grouped_gemm_api.py` |
| det benchmark `benchmarks/bench_cake_moe_grouped_det_gemm.py`: arms
`cake`, `cake_inforward`; functions `cake_arm`, `cake_inforward_arm`,
`_cake_vs_inforward`; JSON key `cake_vs_inforward` | `parser.error` /
`AttributeError` | arms `cake_det`, `cake_det_inforward`;
`cake_det_arm`, `cake_det_inforward_arm`, `_cake_det_vs_inforward`; key
`cake_det_vs_inforward` |
| non-det `cake_backend._check_accumulate_call` (used only by the old
facade det route) | deleted | - |

**Unchanged names:**
- `flashinfer.grouped_mm.grouped_mm_bf16(..., backend="cake")` keeps the
value `"cake"`. It runs the forward pass only, and the det and non-det
forward programs are bitwise identical.
- The non-det package, the facade
`flashinfer.experimental.cake.grouped_mm` and the non-det program names
stay as they are.

**Editable installs:** a stale
`flashinfer/experimental/cake_moe_grouped_gemm/__pycache__` makes the
removed path import as an empty namespace package. To fix this, run `git
clean -fdX flashinfer/experimental/cake_moe_grouped_gemm`. Fresh clones,
wheels and CI are not affected.

## Mode rules

| Entry | `deterministic` | `torch.use_deterministic_algorithms(True)` |
`warn_only=True` |
| --- | --- | --- | --- |
| det package, `flashinfer.grouped_mm.cake_det`,
`flashinfer.grouped_mm.{grouped_det_gemm_*, cake_grouped_det_mm}` | No
parameter. Passing it (`True`/`False`/`None`) raises `TypeError`. | No
alert, no warning | same |
| `CakeGroupedDetMm.apply(x, w, offs[, None[, fuse]])` | A 4th argument
other than `None` (e.g. a stale `True`/`False`/`0`/`1`) raises
`TypeError` before any launch. A non-bool `fuse` raises `ValueError`. |
No change | same |
| `grouped_mm_bf16(backend="cake")` | No parameter. Passing it raises
`TypeError`. | Det forward, no alert | same |
| det accumulate: `grouped_det_gemm_wgrad(..., out=out,
accumulate=True)` / `cake_grouped_det_mm(...,
fuse_wgrad_accumulation=True)` | n/a | No alert. Result has the
AccumulateGrad bits of the det dW and is bitwise identical run to run. |
same |
| non-det package entries (`grouped_gemm_*`, `prepare_grouped_gemm_*`,
`cake_grouped_mm`) and the four facade entries | Keyword-only
`deterministic: bool = True`. Only the bool `False` runs.
Omitted/`True`/`None`/`0`/`1`/`"False"`/`np.False_` raise `ValueError`,
which names `flashinfer.experimental.cake_moe_grouped_det_gemm.<det
entry>` and says "pass deterministic=False for the non-deterministic
path". | `RuntimeError` naming the entry and its det entry, raised right
before an order-varying launch only | `UserWarning` with the same names,
then the launch runs |
| `CakeGroupedMm.apply(x, w, offs[, mode[, None[, fuse]]])` | The 4th
argument is the mode, with default `True`, so omitting it raises
`ValueError` like every value other than `False`. Anything but `None` in
the 5th (internal) slot raises `TypeError`, so `apply(x, w, offs, False,
True)` no longer drops the fuse flag. The 6th argument is the fuse flag.
| as above | as above |

- **No routing to det.** Nothing routes to the det package and there is
no fallback. The facade's old det route is gone; call the det entry
directly.
- **Order-varying launches.** Only the weight gradient's split tail
varies in order: the 512-wide k tile with `unordered_tail` and
`tail_splits > 1`, in overwrite or accumulate mode. It is reached
through:
  - `grouped_gemm_wgrad`
  - `GroupedGemmLaunch.launch()`, checked at every launch
  - `CakeGroupedMm.backward` when it computes dW
- **What the alert names.** The alert names the det replacement:
`grouped_det_gemm_wgrad`, `GroupedDetGemmLaunch.launch` or
`CakeGroupedDetMm`.
- **What never alerts.** fwd, dgrad, k256 or unsplit wgrad, and
preparation never alert.
- **Where the warning points.** Under `warn_only`, the warning points at
the caller's line for direct calls and at a PyTorch autograd frame for
the backward.
- **No shared state between packages.** No tape, saved tensor or
workspace crosses between the two packages.
- **Other Cake families.** This is the rule the other Cake families
adopt.

## Deterministic weight-gradient accumulation

### API

- **`grouped_det_gemm_wgrad`.** New signature `grouped_det_gemm_wgrad(g,
x, offs, out=None, out_dtype=None, num_groups=None, *,
accumulate=False)`, available in the det package,
`flashinfer.grouped_mm.cake_det` and `flashinfer.grouped_mm`.
- **`cake_grouped_det_mm`.** New signature `cake_grouped_det_mm(x, w,
offs, *, fuse_wgrad_accumulation=False)`, in the same three places, plus
`CakeGroupedDetMm.forward(ctx, x, w, offs, _launch=None,
fuse_wgrad_accumulation=False)`. With `fuse_wgrad_accumulation=True` the
backward accumulates into `w.main_grad`, following the Megatron
`main_grad` / `grad_added_to_main_grad` convention used by the non-det
`cake_grouped_mm`.
- **Prepared launches.**
`cake_backend.prepare_grouped_det_gemm_wgrad(..., *, accumulate=False)`,
`cake_backend.ACCUMULATE_MODES = ("off", "composed")`,
`plan["accumulate"]` and `GroupedDetGemmLaunch.add_from`.
- **Benchmark.** The non-det benchmark
`benchmarks/bench_cake_moe_grouped_gemm.py` gains the arm `det_mgX` and
the ratios `det_mgX/det_acc`, `det_mgX/det_mgB` and `mgX/det_mgX`.

### Design and numerics

- **Composed accumulation.** The unchanged deterministic dW programs
write to a launch-owned scratch of `out`'s dtype, and then `out.add_`
runs on the same stream. Accumulation uses exactly the same plan and
stages as the overwrite path.
- **Bitwise equality.** For fp32 `out` the result is `RN32(out + dW)`.
For bf16 `out`, the bf16 dW is added in bf16. Both are bitwise equal to
AccumulateGrad of the deterministic dW and bitwise identical from run to
run.
- **Overlap checks.** A `w.main_grad` with overlapping rows or experts
(expanded, row stride < K) raises `ValueError` at the recorded forward.
Memory shared with the operands is still refused at the backward.
- **CUDA graphs.** Both autograd backwards (det and non-det) query the
current stream only outside a capture, guarded by
`torch.cuda.is_current_stream_capturing()`. As a result, capturing the
fused backward in a CUDA graph no longer fails at a stream query.
- **Scratch lifetime.** The scratch has no `record_stream`. If you
launch a prepared launch on a stream other than the one it was prepared
on, keep the launch alive until that launch completes.

### Cost

The transient scratch takes `4*E*N*K` bytes for an fp32 `out`. On the
#8602 MoE shapes:

| shape | E=4 | E=8 | E=16 | E=32 |
| --- | --- | --- | --- | --- |
| gate_up (N=4096, K=6144) | 384 MiB | 768 MiB | 1.5 GiB | 3 GiB |
| down (N=6144, K=2048) | 192 MiB | 384 MiB | 768 MiB | 1.5 GiB |

Under `torch.use_deterministic_algorithms(True)` with
`fill_uninitialized_memory` on, PyTorch NaN-fills the scratch when it is
allocated, which adds the cost of that fill. The extra write and read of
the scratch cost time; see Performance.

A fused deterministic accumulate program, which would not need the
scratch, is future work.

## Performance

Measured per architecture (B200 sm_100a, GB300 sm_103a, R200 sm_107a);
table follows.

## Tests

CPU suites pass; GPU suites on B200 / GB300 / R200: results follow.

---------

Co-authored-by: Yingyi Huang <averyh@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants