Skip to content

perf(b12x/moe): raise SM121 compact W4A8 micro token threshold from 16 to 64 - #184

Open
nero- wants to merge 1 commit into
local-inference-lab:mainfrom
nero-:sm121-compact-w4a8-max-64
Open

nero- wants to merge 1 commit into
local-inference-lab:mainfrom
nero-:sm121-compact-w4a8-max-64

Conversation

@nero-

@nero- nero- commented Nov 30, 2026

Copy link
Copy Markdown

Summary

Follow-up to #181 and #163.

PR #163 widened coalesced compact W4A8 routing to 1024 pairs and lifted _COMPACT_W4A8_MAX_TOKENS to 64 on SM120, while PR #181 lifted _COMPACT_W4A8_MAX_TOKENS_SM121 from 4 to 16 based on initial T <= 16 GB10 measurements.

This PR raises _COMPACT_W4A8_MAX_TOKENS_SM121 from 16 to 64 (aligning SM121's no-tune heuristic cap with SM120 while keeping _COMPACT_W4A8_MAX_TOKENS_SM121 as an explicit separate constant so future SM120 cap changes do not silently move SM121 without GB10 validation). All shapes remain guarded by _COALESCED_MAX_PAIRS = 1024, the non-compact SM121 guard (hidden_size=6144, intermediate_size=1024) is unchanged, and autotuning continues to race both micro and dynamic backends.

Changes

  • flashinfer/experimental/b12x/moe/fused_moe/_impl.py:
    • Raise _COMPACT_W4A8_MAX_TOKENS_SM121 from 16 to 64 and update the adjacent comment in _w4a8_mx_micro_preferred.
  • tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py:
    • Update SM121 threshold assertions to 64 across (4, 7, 8, 16, 24, 32, 64, 65) and verify dynamic_tile_m == 16 / dynamic_route_mode == "grouped" fallback at 65.
  • tests/experimental/b12x/moe/test_w4a8_compact_coalesced.py:
    • Update SM121 assertions to 64 and extend the 1024-pair cap (M=64, top_k=16 vs top_k=20) and prequantized_input=True (M=64 vs 65) boundary checks to cover both SM120 and SM121.

Isolated PR Evidence (NVIDIA GB10 / SM121)

Cold-L2 CUDA-Graph Microbenchmark (E=384, H=5120, N=576, top_k=6, csf_inline=True)

Hardware: NVIDIA GB10 (SM121, 48 SMs, 0–2350 MHz cap, 128 MiB L2 flush prior to every CUDA-graph replay, median [p25, p75] IQR; negative latency delta = faster).

T Zipf uniqE Coalesced Micro (µs) Dynamic M16 (µs) Zipf Latency Δ Uniform uniqE Coalesced Micro (µs) Dynamic M16 (µs) Uniform Latency Δ
4 23 458.7 [457.0, 460.7] 511.9 [508.9, 515.0] -10.4% 23 457.7 [456.6, 459.7] 516.5 [513.0, 520.2] -11.4%
6 31 597.0 [594.8, 601.0] 631.7 [629.7, 634.8] -5.5% 35 665.5 [663.5, 669.6] 714.2 [710.6, 721.1] -6.8%
8 38 717.7 [716.7, 719.1] 752.1 [750.0, 754.7] -4.6% 47 877.1 [875.5, 879.6] 913.3 [910.3, 916.7] -4.0%
12 51 946.8 [945.4, 948.3] 986.2 [983.2, 999.2] -4.0% 68 1268.7 [1258.5, 1292.0] 1286.6 [1282.0, 1295.3] -1.4%
16 72 1327.2 [1321.0, 1349.0] 1342.5 [1338.3, 1359.0] -1.1% 88 1603.5 [1598.4, 1610.2] 1627.7 [1622.3, 1639.3] -1.5%
24 88 1602.4 [1599.3, 1616.0] 1658.9 [1644.4, 1681.3] -3.4% 117 2133.0 [2122.8, 2148.3] 2155.0 [2152.4, 2159.6] -1.0%
32 114 2062.4 [2059.2, 2079.8] 2080.7 [2075.7, 2095.2] -0.9% 153 2750.4 [2737.1, 2771.9] 2744.1 [2741.2, 2750.8] +0.2%
48 150 2697.4 [2694.0, 2708.8] 2702.8 [2699.5, 2713.5] -0.2% 200 3569.0 [3557.4, 3579.9] 3574.3 [3566.5, 3753.0] -0.1%
64 166 2978.7 [2972.6, 2996.1] 3009.1 [3004.3, 3028.0] -1.0% 241 4280.5 [4260.8, 4388.6] 4282.9 [4276.3, 4288.4] -0.1%
  • T=24 is a clear win (-3.4% Zipf / -1.0% Uniform, directly matching batch=4, width=6 MTP=5 decode), while T=32..64 is parity-to-slight-win (-0.2% to -1.0% Zipf; +0.2% to -0.1% Uniform, within noise).
  • All shapes verified 0-ULP vs uncoalesced micro and cosine >= 0.99992 vs Dynamic M16.
  • Note: microbenchmarks ran with csf_inline=True matching production serving; denser compact N64 shapes (E << 384 or top_k=16) were not separately benchmarked, and autotuning continues to race both backends.

GPU Unit & Contract Tests (NVIDIA GB10 / SM121)

FLARE_RUN_CUDA_TESTS=1 pytest -q \
  tests/experimental/b12x/moe/test_w4a8_compact_coalesced.py \
  tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py \
  tests/experimental/b12x/moe/test_compact_w4a8_backend_race.py

Result: 171 passed, 0 failed in 19.42s.

Combined-Stack Integration Qualification

Verified end-to-end as part of a combined stack (companion model recipes/kernels and Flare runtime) exporting and serving DeepSeek-V4.1-Flash TP4 on 4× DGX Spark GB10 over 200G RoCE:

  • First-token distribution (24 prompts vs TP4 reference): 24/24 top-1, mean KL 0.0200 nats
  • Teacher-forced NLL (218 words): -1.4560 vs -1.4557 reference
  • Concurrency sweep (1, 4, 8, 16, 32): 61/61 (32/32 at C32) clean, 0 errors / 0 loops
  • Cold 32K needle retrieval (cached_tokens=0): PASS
  • Observed combined-stack batch=4, width=6 (M=24) GPU decode latency: 47.08 ms/round (vs 49.34 ms/round on prior TP4 package; combined-stack measurement, not an isolated single-variable toggle).

…6 to 64

Follow-up to flashinfer-ai#181 and flashinfer-ai#163.

PR flashinfer-ai#163 widened coalesced compact W4A8 routing to 1024 pairs and lifted the
SM120 default heuristic cap `_COMPACT_W4A8_MAX_TOKENS` to 64, while PR flashinfer-ai#181
lifted SM121 (`_COMPACT_W4A8_MAX_TOKENS_SM121`) from 4 to 16 based on
initial T<=16 GB10 measurements.

Cold-L2 CUDA-graph microbenchmarks on NVIDIA GB10 (SM121, 48 SMs, 0-2350 MHz
cap, 128 MiB L2 flush, DeepSeek-V4.1 TP4 shape E=384, H=5120, N=576, top_k=6,
csf_inline=True) show coalesced W4A8CompactMicro beats Dynamic M16 at T=24
(-3.4% latency on Zipf1.1: 1602.4 vs 1658.9 us; -1.0% on Uniform: 2133.0 vs
2155.0 us — directly covering batch=4, width=6 MTP=5 decode) and stays at
parity-to-slight-win through T=64 (-0.9% at T=32, -0.2% at T=48, -1.0% at
T=64 on Zipf1.1; +0.2% at T=32, -0.1% at T=48, -0.1% at T=64 on Uniform),
all with 0-ULP parity vs uncoalesced micro and cosine >= 0.99992 vs Dynamic
M16.

Changes:
- Raise `_COMPACT_W4A8_MAX_TOKENS_SM121` from 16 to 64 in
  `flashinfer/experimental/b12x/moe/fused_moe/_impl.py`, keeping it as a
  separate SM121 constant bounded by `_COALESCED_MAX_PAIRS` (1024).
  Autotuning still races both `micro` and `dynamic` backends.
- Update SM121 contract assertions in
  `tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py` and
  `tests/experimental/b12x/moe/test_w4a8_compact_coalesced.py`, including
  SM121 coverage of the 1024-pair cap (`M=64, top_k=16` vs `top_k=20`),
  `prequantized_input=True` boundaries (`M=64` vs `65`), and dynamic M16
  fallback fields at `M=65`.

Verification (NVIDIA GB10, SM121):
- `FLARE_RUN_CUDA_TESTS=1 pytest -q tests/experimental/b12x/moe/test_w4a8_compact_coalesced.py tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py tests/experimental/b12x/moe/test_compact_w4a8_backend_race.py`:
  171 passed, 0 failed in 19.42s.
- Combined-stack integration qualification (4x DGX Spark GB10 DeepSeek-V4.1
  TP4 export & serving with companion model recipes/kernels and Flare
  runtime): 24/24 top-1 (0.0200 nats KL), NLL -1.4560 vs -1.4557 ref,
  61/61 (32/32 at C32) concurrency clean, cold 32K needle PASS.

Signed-off-by: Jonathan Gutierrez <john.gtz@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant