Skip to content

perf(b12x/gemm): decouple .cs weight streaming, lower NVFP4 evict_first, and tune SM121 blockscaled/WO - #188

Open
original-el8 wants to merge 1 commit into
mainfrom
perf/b12x-sm121-blockscaled-cs-and-tuning
Open

original-el8 wants to merge 1 commit into
mainfrom
perf/b12x-sm121-blockscaled-cs-and-tuning

Conversation

@original-el8

Copy link
Copy Markdown

📌 Description

Optimize SM121 blockscaled GEMV, grouped WO projection, and MXFP8 WO quantization with decoupled cache-streaming weight loads, lowered NVFP4 L2::evict_first width thresholds, expanded SM121 tc_gemv warp/tile predicates, compact 6 <= M <= 28 MXFP8 search candidates, and 64-chunk prefill WO quantization:

  • flashinfer/experimental/b12x/gemm/blockscaled/_mxfp8_tc_gemv.py & flashinfer/experimental/b12x/gemm/wo_projection/_tc_gemv.py: decouple ld_global_cs_v4_u32 weight streaming from use_pdl so weight matrices stream with .cs while activations and scales keep .nc caching when use_pdl=False; bump gemm.blockscaled.mxfp8_tc_gemv (9 -> 10), gemm.blockscaled.mxfp8_tc_gemv_rope (5 -> 6), and gemm.wo_projection.grouped_woa_tc_gemv (5 -> 6).
  • flashinfer/experimental/b12x/gemm/blockscaled/_nvfp4_tc_gemv.py: lower NVFP4MultiRowTCGemvKernel.evict_first width threshold from n >= 65536 to n >= 16384 and bump gemm.blockscaled.nvfp4_tc_gemv (5 -> 6).
  • flashinfer/experimental/b12x/gemm/blockscaled/_tuning.py: extend _tc_gemv_default_config tile_n=32 (M >= 17, active_k >= 2048, 512 <= N <= 2560) and tc_n32_ok (M >= 12) to (12, 1), enable mma_warps=8 when chunks_per_split > 4 is divisible by 8 on M <= 16 or sm_count <= 64, retain compact 6 <= M <= 28 TMA A16 (16x{32,64,128}x256) and wide-N (N >= 16384) quantized 64x64 candidates in prefer_tc_gemv, and bump candidate_contract_version (62 -> 63).
  • flashinfer/experimental/b12x/gemm/_shared/wo_mxfp8.py: permit chunks_per_program=64 in _wo_quant_chunks_per_program for tokens > 32 and dynamic_tokens prefill paths, and launch num_warps=8 when chunks >= 32 (4x fewer programs on K=4096 / K=2048 prefill groups).
  • tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py: update SM121 tile_n=32 assertions and add unit tests for NVFP4MultiRowTCGemvKernel.evict_first, _wo_quant_chunks_per_program(..., maximum=64), SM121 mma_warps=8 defaults, and compact 6 <= M <= 28 search candidates.

Benchmark Results (NVIDIA GB10, SM121, 48 SMs, 273 GB/s LPDDR5x)

1. 20-Op Sequential Chain .cs vs PDL Ablation (174.15 MB, 637.9 us floor)

Conditions: captured CUDA graph over [qkv_a -> q_b -> GroupedWoa -> bf16.router -> shared.gate_up -> shared.down] x 3 + qkv_a + engram, bit-identical outputs across all modes:

M no_pdl (us) no_pdl + cs (us) full_pdl + cs (us) Isolated .cs Gain PDL Delta over .cs
1 860.4 826.2 829.9 -34.2 us (-4.0%) +3.7 us
6 871.8 827.7 830.1 -44.1 us (-5.1%) +2.4 us
16 910.2 850.2 850.2 -60.0 us (-6.6%) +0.0 us
24 947.7 882.6 888.5 -65.1 us (-6.9%) +5.9 us

Across M in {1, 3, 6, 8, 12, 16, 24} in bench_ds41_chain_pdl.py, full_pdl_cs reduces chain latency by 43.4–78.2 us (5.0%–8.8%) vs no_pdl.

2. NVFP4 draft.head (5120 -> 32320, 93.10 MB, 341.0 us floor)

  • Baseline (evict_first=False at M <= 16): 410.9–424.6 us (verify_final_gains.py) / 405.0–417.4 us (bench_ds41_chain_pdl.py).
  • With n >= 16384 evict_first=True (no PDL, bit-identical): 366.7–375.5 us (90.8%–93.0% of 273 GB/s, -37.7 to -49.1 us); with PDL+evict_first: 361.3–368.7 us (92.5%–94.4%).

3. Cold-Pool SM121 MXFP8 Shapes (>48 MB rotating weight pools)

Shape (K -> N, weight, floor) M Baseline default (us, % 273) Tuned Winner (us, % 273) Delta
qkv_a (5120 -> 2112, 11.16 MB, 40.9 us) 1..8 52.7–52.8 (77.5%) tc(w=8) 49.8–51.5 / a16_tma 47.1 (86.8%) -2.9 to -5.7 us
qkv_a 12 / 16 / 24 53.3 / 53.4 / 60.9 a16_tma 47.1 / 46.5 (88.0%) / 51.0 (80.2%) -6.2 / -6.9 / -9.9 us
q_b (1536 -> 3072, 4.87 MB, 17.8 us) 1..16 21.2–23.9 (74.5–84.0%) tc(tn=16,sk=1,w=8) 20.7–21.1 (85.6%) up to -3.1 us (M=6)
shared.gate_up (5120 -> 1152, 6.08 MB, 22.3 us) 1..8 28.6–29.3 (76.1–78.0%) tc(tn=16,sk=1,w=8) 24.6–24.9 (90.3%) ~-4.2 us (+14%)
shared.gate_up 12 / 16 / 24 29.1 / 29.1 / 34.8 a16_tma 26.0 / 24.8 / tc(tn=32,w=8) 26.9 -3.1 / -4.3 / -7.9 us
engram (1536 -> 25600, 40.55 MB, 148.5 us) 6 / 12 / 16 / 24 189.8 / 195.2 / 187.5 / 207.0 quant 166.5 / a16_tma 171.2 / quant 174.1 / 183.3 -13.4 to -24.0 us

Conclusion: decoupling .cs weight streaming from PDL captures 4.0%–6.9% chain speedup without enabling consumer PDL on SM121; lowering the NVFP4 evict_first threshold lifts draft.head up to 93.0% peak bandwidth; and SM121 mma_warps=8, tile_n=32, and compact 6 <= M <= 28 search candidates resolve qkv_a, shared.gate_up, and engram bottlenecks.

Combined-Stack End-to-End TP4 Serving Verification (flare run)

  • Scope note: The end-to-end TP4 flare run verification below integrates the combined SM121/RoCE kernel, recipe, and scheduler optimization set (isolated single-component GPU microbenchmarks are reported directly above).
  • Hardware & exported package: 4x NVIDIA DGX Spark (GB10, SM121, 48 SMs, 121 GiB unified LPDDR5x, dual-rail ConnectX-7 200 GbE RoCEv2), deepseek-ai/DeepSeek-V4.1-Flash-1017 TP4 exported package (draft_tokens = 7, speculative_token_capacity = 256, graph_budget = 80, prefill_chunk = 8192, row_shard_prefill = True, row_shard_attention = True, adaptive_verification_alpha = 0.75), served via flare run (27,051,776 logical KV tokens/rank, up from 26,272,640 baseline).
  • Correctness & stability qualification:
    • Greedy math (17 * 23 = 391): pass
    • Concurrent multimodal vision (4/4 distinct images, 4 vision graph launches): 4/4 pass
    • Cold needle-in-a-haystack (8K, 16K, 32K, 64K, 128K, 0 reused tokens): 5/5 pass (128K in 11.71 s)
    • Concurrent 4 x 32K long-context stress: 4/4 pass in 12.19 s, 0 failed requests, 0 preemptions
  • llm-decode-bench v0.8.0 (exact native token counting, 30 s/cell sustained decode, 0 errors, 0 CJK):
    • Integrated scout prefill (prompt_tokens / client TTFT): 8K 8,639 tok/s (0.95 s), 32K 10,994 tok/s (2.98 s, vs 10,810 tok/s baseline), 128K 11,349 tok/s (11.55 s, vs 11,181 tok/s baseline); cold 64K pass-2 prefill reached 11,390.9 tok/s wall (11,462.6 tok/s GPU).
    • Sustained decode (C = 1, 2, 4, 8):
      • 8K: 67.7 / 106.5 / 159.1 / 224.6 tok/s (vs 65.4 / 107.1 / 152.5 / 218.6 tok/s matching draft_tokens = 7, alpha = 0.75 baseline)
      • 32K: 71.2 / 107.6 / 163.1 / 227.6 tok/s (vs 70.2 / 105.0 / 154.9 / 222.4 tok/s baseline)
      • 128K: 69.1 / 99.2 / 154.0 / 219.9 tok/s (12-cell geomean 126.61 tok/s vs 124.96 tok/s baseline; B16xW1 pure 1-token/lane GPU step 75.70 ms -> 70.54 ms, -6.8%)
      • 8K C=16 / C=32 under alpha = 0.75 (272.5 / 411.0 tok/s): at alpha = 0.75 with max_verification_token_budget = 256, unclamped calibration offers ~2.8–2.9 drafts/lane on low-acceptance prose (49.4%–51.8% accept rate vs 59.7%–62.2% baseline), increasing packed verification rows; C=32 fixed-prompt sweep (P=256) reached 419.93 tok/s.
    • Coding Peak (5/5 runs, 0 CJK): 109.0 tok/s median, 110.7 tok/s mean, 118.0 tok/s peak (vs 116.5 tok/s baseline).
  • Sustained long-form generation (46,766 completion tokens: 27,108 reasoning + 19,658 HTML/JS code, temperature = 1.0, adaptive draft_tokens = 7):
    • End-to-end decode: 118.23 tok/s (179.53 tok/s 1s peak, 162.56 tok/s 5s peak; vs 114.68 tok/s fixed-W=8 baseline and 87.74 tok/s flat-ceiling adaptive W=6 baseline)
    • Reasoning segment: 105.49 tok/s (4.19 mean tokens/step, 5.40 offered drafts/round)
    • Code segment (19,655 tokens up to 47K context): 141.85 tok/s (6.11 mean tokens/step, 6.59 offered drafts/round, 77.6% accept rate, per-depth survival [0.955, 0.904, 0.854, 0.791, 0.715, 0.614, 0.279]).

🔍 Related Issues

  • None.

🚀 Pull Request Checklist

✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

🧪 Tests

  • Tests have been added or updated as needed.

  • All tests are passing (unittest, etc.).

  • This PR requires full-scope CI, not targeted tests (expensive; justify below).

    Suggested CI test targets: tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py tests/experimental/b12x/gemm/test_blockscaled.py tests/experimental/b12x/gemm/test_blockscaled_a16.py tests/experimental/b12x/gemm/test_gemm_wo_projection.py tests/experimental/b12x/gemm/test_wo_projection.py tests/experimental/b12x/gemm/test_mxfp8_tc_gemv.py tests/experimental/b12x/gemm/test_nvfp4_tc_gemv.py

🔬 Experimental Track

  • This PR is experimental: it adds or changes code under flashinfer/experimental/ and/or an @flashinfer_experimental_api.
    • Core changes are limited to a thin entry point (none in this PR; changes are confined to flashinfer/experimental/b12x/gemm/).
    • Tests live in tests/experimental/ and were validated on CPU and GB10 hardware.
    • Nothing is registered in flashinfer/aot.py, and no experimental backend is reachable from backend="auto" without FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1.
    • Test scope declared below.
tests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py
tests/experimental/b12x/gemm/test_blockscaled.py
tests/experimental/b12x/gemm/test_blockscaled_a16.py
tests/experimental/b12x/gemm/test_gemm_wo_projection.py
tests/experimental/b12x/gemm/test_wo_projection.py
tests/experimental/b12x/gemm/test_mxfp8_k256.py
tests/experimental/b12x/gemm/test_mxfp8_linear.py
tests/experimental/b12x/gemm/test_mxfp8_precision_race.py
tests/experimental/b12x/gemm/test_mxfp8_weight_scale_storage.py
tests/experimental/b12x/gemm/test_mxfp8_wide_splitk.py
tests/experimental/b12x/gemm/test_nvfp4_k1024.py
tests/experimental/b12x/gemm/test_nvfp4_precision_race.py
tests/experimental/b12x/gemm/test_nvfp4_tc_gemv.py
tests/experimental/b12x/gemm/test_gemm_mxfp8_linear.py
tests/experimental/b12x/gemm/test_tc_gemv_concurrent_streams.py
tests/experimental/b12x/gemm/test_mla_query_projection.py

Reviewer Notes

  • CPU unit tests executed with CUDA_VISIBLE_DEVICES="" (92 passed, 724 skipped across the 16 declared test files; CUDA runtime cases skipped on CPU build host).

…st, and tune SM121 blockscaled/WO

- Decouple ld_global_cs_v4_u32 weight streaming from use_pdl in MXFP8 and
  grouped WO TC-GEMV kernels while keeping .nc loads on activations/scales.
- Lower NVFP4MultiRowTCGemvKernel evict_first threshold from n >= 65536 to
  n >= 16384 so wide projections stream weights past L2 at M <= 16.
- Extend SM121 (12, 1) blockscaled tuning: enable tile_n=32 defaults
  (M >= 17, 512 <= N <= 2560), allow mma_warps=8 when chunks_per_split is
  divisible by 8 on M <= 16 or sm_count <= 64, retain compact 6 <= M <= 28
  TMA A16 and wide-N (N >= 16384) quantized M64xN64 candidates, and bump
  candidate_contract_version (62 -> 63).
- Support chunks_per_program=64 with num_warps=8 for tokens > 32 and
  dynamic_tokens prefill quantizers in wo_mxfp8.py.
- Update test_decode_gemm_moe_contracts.py for SM121 tile_n=32 and add unit
  tests for NVFP4 evict_first, 64-chunk WO quantization, and SM121 MXFP8 tuning.

Validated on CPU with CUDA_VISIBLE_DEVICES="" (92 passed, 724 CUDA-skipped
across 16 blockscaled/WO/MXFP8/NVFP4 test files).

Signed-off-by: Jason Cook <jasonc@maxlyn.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