Skip to content

perf(b12x/mla): SM120 register-recycled MLA prefill for DeepSeek-V4.1 and GLM-5.3 - #175

Open
brandonmmusic-max wants to merge 4 commits into
local-inference-lab:mainfrom
brandonmmusic-max:b12x-mla-sm120-register-recycling
Open

brandonmmusic-max wants to merge 4 commits into
local-inference-lab:mainfrom
brandonmmusic-max:b12x-mla-sm120-register-recycling

Conversation

@brandonmmusic-max

Copy link
Copy Markdown

📌 Description

General SM120 (gb202) b12x unified MLA prefill kernel (UnifiedPrefillMGKernel in flashinfer/experimental/b12x/attention/_shared/mla/) optimization through register-recycled QK/PV pipelining and reduced shared-memory / barrier overhead. This change benefits all DeepSeek-V4.1 and GLM-5.3-Flash models (BF16, NVFP4, FP8, and TrellisMX) across both DSV41_SOURCE and GLM_NEXT (ARBITRARY_FP32) MLA prefill paths, with zero TrellisMX dependency.

Why this change is needed

On SM120 GPUs (99 KiB addressable shared memory per SM, 255 max registers per thread), the existing UnifiedPrefillMGKernel staged QK and PV tiles serially across barriers and issued repeated LDSM.x4 reloads of V/W fragments across the inner vc dimension. For compact NVFP4 KV sources (DSV41_SOURCE, 304 B/token), execution was bound by barrier stalls, shared-memory load bandwidth, and sequential QK/PV phases. For wider ARBITRARY_FP32 KV sources (GLM_NEXT, 33,792 B/tile), L2 read bandwidth saturates at ~4.0 TB/s, so optimizations must preserve full IO prefetch depth while trimming register-file and barrier overhead.

What changed

  1. SM120 unified prefill shared-memory and softmax base: Refactors prefill_mg.py, smem_mg.py, and decode_math.py for tighter SM120 mainloop scheduling, XV-NoPE handling, and softmax staging.
  2. GLM-5.3 (GLM_NEXT / ARBITRARY_FP32) XV-NoPE and softmax staging (358c16db): Replaces shared-memory atomic_max contention with lock-free packed BF16x2 quad reduction in XOR-swizzled scratch, loads 16x16 E4M3 V tiles directly via ldmatrix.m16n16.x1.trans.b8, folds sm_scale_log2 into Q block scales in S0, and defers the 4-lane softmax row-sum butterfly reduction to finalization.
  3. DeepSeek-V4.1 (DSV41_SOURCE) register-recycled PV+QK pipeline (f1649fd7):
    • Adds a 3-stage lock-free NVFP4 staging layout fitting inside SM120 shared memory (99,968 B <= 101,376 B).
    • Interleaves PV(t) and QK(t+1) using mid-PV deferred waits and register recycling across the attention tile loop.
    • Reorders PV accumulation to outer-ks / inner-vc direct accumulation, eliminating 87.5% of LDSM.x4 shared-memory loads (64 -> 8 at mg2).
    • Vectorizes QK/scale loads (LDS.128) and performs S3 index handling with register-only warp ballots.
  4. GLM-5.3 (GLM_NEXT / ARBITRARY_FP32) IO-preserving register-recycled staging (5e1764ca):
    • Keeps full IO prefetch depth (avoiding L2-bandwidth starvation observed when cross-tile QK(t+1)||PV(t) shrinks prefetch buffering on ARBITRARY_FP32).
    • Registerizes Q scales, hoists K/V scales, prefetches indices, pipelines QK ldmatrix, adds pre-packed Pair-1 W staging (mg2, 99,456 B, 0 register spills) and 8-slot simultaneous W staging (mg1, 88,704 B, reducing BAR.SYNC per tile from 5 to 3), releases empty_mbar early, and uses a 240/24 warp-group register split.

Measured performance (isolated kernel microbenchmarks on SM120)

DeepSeek-V4.1 (DSV41_SOURCE) BF16 prefill (RTX PRO 6000 Blackwell Workstation, 450 W, L2-flushed CUDA graph vs pre-recycling baseline (358c16db))

Shape (mg2 / mg1) Baseline (us) Optimized (us) Speedup Achieved TFLOPS
swa128_idx2048_h64_m2048 (mg2) 2,836.50 1,991.68 1.424x 293.3 TFLOPS
swa128_idx2048_h64_m1024 (mg2) 1,255.42 990.22 1.268x 294.9 TFLOPS
swa128_idx2048_h128_m1024 (mg2) 2,819.58 2,063.87 1.366x 283.0 TFLOPS
swa128_idx512_h64_m4096 (mg2) 1,689.28 1,345.54 1.255x 255.4 TFLOPS
swa128_idx512_h16_m4096 (mg1) 612.35 477.22 1.283x 180.0 TFLOPS

GLM-5.3 (GLM_NEXT / ARBITRARY_FP32) FP8 prefill

  • XV-NoPE & softmax staging (358c16db, 600 W RTX PRO 6000 Blackwell, M=4096, H=64, D=512, W=2051, 44 slices, L2-flushed CUDA graph): contiguous_2051 4.199 -> 3.426 ms/slice (-34.01 ms), scattered_32K_2051 4.324 -> 3.512 ms/slice (-35.73 ms), half_valid_1024 2.189 -> 1.808 ms/slice (-16.76 ms).
  • Register-recycled QK/PV staging (5e1764ca, interleaved clock-matched 2610 MHz L2-flushed CUDA graph): additional 1.003x–1.010x across 9/9 mg2 shapes (M=1024/2048/4096, contiguous/scattered/half-valid) and 1.000x at the ~4.0 TB/s SM120 L2-TMA ceiling on mg1 (H=16), with 0 register spills (STACK=0 LOCAL=0 STL=0 LDL=0) and bit-exact CUDA graph replay.

Combined-stack end-to-end serving validation (separate from isolated kernel microbenchmarks; not attributable solely to this PR)

  • DeepSeek-V4.1-Flash-1017 production checkpoint (TP4 mixed-SKU SM120, 4x RTX PRO 6000 Blackwell PCIe, 300/450/300/450 W, --mla-compute-mode bf16, --expert-scale-compression native, --embedding-table-storage ram, built on NVIDIA/hyperflare-inference@99339606 + mixed-GPU keying, local-inference-lab/hyperflare-recipes@d954b2f + general GLM-5.3 recipe PR, and local-inference-lab/flashinfer@335459b2 + this PR, zero TrellisMX and zero environment-variable flags): 76.20 GiB loaded/GPU (72.8 GiB / 21,058,816 KV tokens, 62 s startup, 135 CUDA graphs/rank, 38,944 captured kernels across 4 ranks), cold prefill 37,671 (8K, 0.217 s) / 42,053 (32K, 0.767 s) / 42,780 (64K, 1.504 s) / 43,134 tok/s (128K, 2.979 s), sustained ctx=0 decode 377.4 tok/s at C1 (159.90 steps/s, 6.25 ms/rd, 2.67 ms ITL) / 619.8 tok/s at C2 (135.59 steps/s, 7.38 ms/rd, 3.28 ms ITL) / 920.7 tok/s at C4 (100.65 steps/s, 9.94 ms/rd, 4.49 ms ITL) / 1,185.8 tok/s at C8 (72.67 steps/s, 13.76 ms/rd, 6.71 ms ITL, 0 loops, 0 errors), HTML Tetris coding 681.92 med / 715.68 tok/s best (reasoning_effort: "low", 5 runs, 0/5 CJK), 6/6 first-token prefix parity checks PASS (6/6 exact reference first tokens), 21/21 multi-turn chat & tool-calling trials PASS (3/3 tool calls on all 5 tool suites) + 5/5 DeepSeek edge-case checks PASS, image OCR vision check (4871) PASS, 0 server or CUDA errors. Relative to the prior native-scale build on NVIDIA/hyperflare-inference@96fd11fc + local-inference-lab/flashinfer@0d48af53 (16.41M KV tokens; 37,630 / 40,881 / 41,386 / 41,941 tok/s prefill; 156.37 / 133.50 / 102.63 / 72.03 steps/s at C1/C2/C4/C8), this build delivers +2.8% to +3.4% faster 32K–128K prefill (+1,193 tok/s at 128K), +28.3% KV cache capacity (+4.65M tokens), and +2.3% faster C1 step cadence (6.39 -> 6.25 ms/rd); these whole-model deltas include upstream main runtime/memory improvements between 96fd11fc/0d48af53 and 99339606/335459b2 in addition to this PR's MLA prefill kernel (1.26x–1.42x isolated).
  • GLM-5.3-Flash TP4 (gb202, 4x RTX PRO 6000 Blackwell PCIe, 300/450/300/450 W, brandonmusic/glm-5.3-flash-exl3-tr3-2.375bpw-flare): paired with the companion SM120 decode/prefill/norm/router/MXFP8 BMM kernels PR, the companion TrellisMX P8 MoE runtime PR, and the hyperflare-recipes GLM-5.3 integration: 40.75 GiB loaded/GPU (214.5 GiB / 36.21M GPU KV cache), cold prefill 12,547 (8K) / 20,330 (32K) / 20,781 (64K) / 20,805 tok/s (128K), sustained ctx=0 decode 303.4 (C1) / 899.5 (C8) / 1,241.2 (C16) / 1,666.1 tok/s (C32), HTML Tetris coding 507.7 med / 549.0 tok/s best (enable_thinking: false, 0/5 stray CJK) and 288.8 med / 316.2 tok/s best (thinking on, 0/5 stray CJK), 28-window 57,316-pos contiguous KLD 0.045665 nats (95% BCa CI [0.039007, 0.053480], +0.001985 vs 0.04368 carrier-only ref, 92.90% Top-1, 0.997412 PPL ratio), 2/2 vision PASS, 24/24 multi-turn chat & tool-calling trials PASS, 0 server or CUDA errors.
  • GLM-5.3-Flash TP2 (gb202-tp2, 2x RTX PRO 6000 Workstation @ 600 W, 17,001 MHz GDDR7, 7-token DFlash2, --online-mxfp8): 66.0 GiB / 10,382,336 tokens (10.38M) GPU KV cache (60.86-61.41 GiB loaded/GPU, 16 s startup), cold prefill 14,264 (8K, 0.57 s) / 16,588 (32K, 1.95 s) / 16,524 (64K, 3.90 s) / 16,329 tok/s (128K, 7.89 s), sustained ctx=0 decode 256.9 (C1, 4 ms ITL) / 525.4 (C2, 262.7/user) / 510.7 (C4) / 729.4 (C8) / 1,012.6 (C16, 63.3/user) / 1,428.9 tok/s (C32, 44.7/user, 22 ms ITL, 0 loops), HTML Tetris coding 478.5 med / 493.8 tok/s best (reasoning_effort: "low", 0/5 stray CJK) and 247.7 med / 256.4 tok/s best (thinking on, 0/5 stray CJK), 2/2 vision PASS, 24/24 multi-turn chat & tool-calling trials PASS (3/3 tool calls on all 5 tool cases), 4/4 GLM-5.3 edges PASS, 0 server or CUDA errors.

🔍 Related Issues

Standalone SM120 MLA prefill optimization in flashinfer/experimental/b12x/attention/_shared/mla/.

🚀 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

  • DSV41_SOURCE MLA prefill CUDA test suite on SM120: 99/99 PASS (92/92 test_compressed_sparse_mla_v41.py + test_benchmark_deepseek_v41_mla.py, 5/5 DSV4.1 binding tests, 2/2 DSV4 live-graph smoke tests; numerical parity to 6 decimal places).
  • GLM_NEXT MLA prefill CUDA test suite on SM120: 101/101 PASS (89/89 targeted MLA pytest + 12/12 GLM_NEXT parity/edge cases; bit-exact CUDA graph replay).
  • End-to-end live SM120 serving validation across both model families: (1) DeepSeek-V4.1-Flash-1017 production checkpoint TP4 (300/450/300/450 W, clean origin/main + this PR + mixed-GPU keying + general recipe PR): 21.06M KV cache (72.8 GiB), cold prefill 37,671–43,134 tok/s (8K–128K), sustained decode 377.4 (C1) to 1,185.8 tok/s (C8, 0 loops), HTML Tetris 681.92 med / 715.68 best (0/5 CJK), 6/6 first-token prefix parity checks PASS, 21/21 multi-turn chat & tool-calling trials + 5/5 DeepSeek edge-case checks PASS, image OCR vision check (4871) PASS; (2) GLM-5.3-Flash TP4 (gb202) & TP2 (gb202-tp2, 2x RTX PRO 6000 Workstation @ 600 W) on brandonmusic/glm-5.3-flash-exl3-tr3-2.375bpw-flare: TP4 28-window contiguous KLD 0.045665 nats across 57,316 positions (92.90% Top-1, 0.997412 PPL ratio); TP2 cold prefill 14,264–16,588 tok/s, sustained decode 256.9 (C1) to 1,428.9 tok/s (C32), 2/2 vision PASS, 24/24 multi-turn chat & tool-calling trials PASS, 4/4 GLM-5.3 edges PASS, 0 server or CUDA errors.
  • This PR requires full-scope CI, not targeted tests.

Suggested CI test targets: tests/experimental/b12x/attention/

🔬 Experimental Track

  • This PR is experimental: it adds or changes code under flashinfer/experimental/b12x/attention/_shared/mla/ (decode_math.py, prefill_mg.py, smem_mg.py). Scope and validation are tracked in this PR.
    • The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release.
    • Core changes are limited to flashinfer/experimental/b12x/attention/_shared/mla/ (zero non-experimental files modified).
    • Tests live in tests/experimental/b12x/attention/ and were validated on SM120 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/attention/

Reviewer Notes

  • This PR contains 4 bisectable commits directly on origin/main (335459b2) with zero file overlap against the companion SM120 decode/prefill/norm/router/MXFP8 BMM kernels PR or the companion TrellisMX P8 MoE runtime PR.
  • Validated on SM120 (gb202 TP4 & gb202-tp2 TP2, RTX PRO 6000 Blackwell); SM103/SM121 hardware was not tested locally.

Discord: Brandonmusic

@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

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 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review 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: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b711aa80-c31b-4c25-a07d-b2eb7dfefd99
Commits

Reviewing files that changed from the base of the PR and between 335459b and 5e1764c.

Files selected for processing: 3

  • flashinfer/experimental/b12x/attention/_shared/mla/decode_math.py
  • flashinfer/experimental/b12x/attention/_shared/mla/prefill_mg.py
  • flashinfer/experimental/b12x/attention/_shared/mla/smem_mg.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

…loop base

Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
…taging

Optimize the SM120 GLM_NEXT ARBITRARY_FP32 FP8 multi-group prefill path
(UnifiedPrefillMGKernel) while retaining FP32 accumulation and exact
per-head, per-V-chunk dynamic FP16 weight scaling:

- Load 16x16 E4M3 V tiles directly via ldmatrix.m16n16.x1.trans.b8 with
  matching K-order weight staging, shift-free 4-byte E4M3-to-FP16x2
  unpacking, K16 and cross-V-chunk V-load pipelining, and contiguous
  16-dim warp epilogue output indexing in s7_epilogue.
- Replace shared-memory atomic_max contention in s6_xv_nope_glm_next_mg2
  with lock-free packed BF16x2 quad reduction into XOR-swizzled 32 B
  per-slot w_head_sc scratch (99,456 B total SMEM <= 101,376 B carveout),
  LDS.128 + HMNMX2.BF16_V2 warp reduction, and exponent-subtracted packed
  BF16x2 scale broadcast.
- Fold sm_scale_log2 into Q block scales once during S0 quantization (when
  vectorized S0 runs) to eliminate per-tile QK scale multiplies in S3, and
  defer the 4-lane softmax row-sum butterfly reduction from each tile to
  s4_finalize_row_sum_mg2.

Validation (600 W SM120 RTX PRO 6000, M=4096, H=64, D=512, W=2051,
L2-flushed CUDA graph, 44 slices):
- contiguous_2051: 4.199 -> 3.426 ms/slice (184.77 -> 150.76 ms, -34.01 ms)
- scattered_32K_2051: 4.324 -> 3.512 ms/slice (190.27 -> 154.54 ms, -35.73 ms)
- half_valid_1024: 2.189 -> 1.808 ms/slice (96.33 -> 79.57 ms, -16.76 ms)
- Parity: rel_l2 0.16-0.21% / cos >= 0.9999977 across H={8,16,24,32,64},
  0.0006% / cos 1.0000000 on sink+1e6 outlier, 0.0 empty-row error,
  bit-exact zero-alloc CUDA-graph replay, 89/89 targeted MLA pytest pass.

Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
… BF16 prefill

Optimize the SM120 DeepSeek-V4.1 (ModelType.DSV41, ComputeMode.BF16,
ScaleFormat.NVFP4_E4M3) multi-group prefill path in UnifiedPrefillMGKernel
while keeping exact lossless BF16 QK and BF16 PV arithmetic and bit-exact
mg_n_hg=2 vs mg_n_hg=1 equivalence:

- Expand DSV4.1 BF16 shared-memory staging in smem_mg.py to three 64x304 B
  indexed NVFP4 buffers (58,368 B; total 99,968 B <= 101,376 B carveout at
  mg_n_hg=2; 69,632 B dual-SWA / 3-indexed at mg_n_hg=1) with 10 dedicated
  mbarriers (SWA full/empty and 3-stage indexed full/empty). Replace blocking
  384-thread BAR 0x1 barriers in the indexed loop (and mg_n_hg=1 SWA loop)
  with lock-free empty-mbarrier signaling and disjoint SWA-to-indexed tile-0
  prefetch.
- Recycle dead FP32 score registers (qk0_frag/qk1_frag) immediately after
  s4_exp_rescale_pack_dsv41_mg2 packs BF16 weights into sm_p. Run ks_pv=0..1
  of PV(t) before waiting on tile t+1, then interleave ks_pv=2..3 (16 PV
  steps) 1-to-1 with 16 bank-conflict-free LDS.128 QK(t+1) pairs (32 QK
  k-steps) in s6_s1_pv_qk_interleaved_indexed_mg2.
- Reorder s6_xv_dsv41_source_mg2 to outer-ks / inner-vc (cutting sm_p LDSM.x4
  by 87.5%, 64 -> 8 at mg2), accumulate HMMA directly into acc0/acc1, hoist
  PV scales via LDS.128 with fused row-0/row-8 bf16x2 scale conversion, and
  vectorize QK K loads via LDS.128 with batch 4-scale unpacking.
- Replace global index loads in DSV4.1 S3 with register-only warp-ballot
  masking from SMEM source tags, overlap MUFU.EX2 with accumulator rescaling,
  defer 4-lane quad row-sum reduction to s4_finalize_row_sum_mg2, and bump
  attention.mla.sm120.prefill_mg compile spec from v6 to v7.

Validation (RTX PRO 6000 Blackwell Workstation SM120 @ 450 W, L2-flushed
CUDA graph replay, vs parent 358c16d (pre-recycling baseline)):
- swa128_idx512_h16_m4096 (mg1): 612.35 -> 477.22 us (1.283x, 180.0 TFLOPS)
- swa128_idx512_h64_m1024 (mg2): 436.22 -> 346.11 us (1.260x, 248.2 TFLOPS)
- swa128_idx512_h64_m2048 (mg2): 854.02 -> 679.92 us (1.256x, 252.7 TFLOPS)
- swa128_idx512_h64_m4096 (mg2): 1689.28 -> 1345.54 us (1.255x, 255.4 TFLOPS)
- swa128_idx2048_h64_m1024 (mg2): 1255.42 -> 990.22 us (1.268x, 294.9 TFLOPS)
- swa128_idx2048_h64_m2048 (mg2): 2836.50 -> 1991.68 us (1.424x, 293.3 TFLOPS)
- swa128_idx2048_h128_m1024 (mg2): 2819.58 -> 2063.87 us (1.366x, 283.0 TFLOPS)
- swa128_only_h64_m4096 (mg2): 542.72 -> 487.42 us (1.113x, 141.0 TFLOPS)
- Numerical parity: max_abs 0.000122-0.000488, rel_err 0.00218-0.00228,
  lse_max_abs <= 2e-6 (matching baseline to 6 decimals); 92/92 pass across
  test_compressed_sparse_mla_v41.py and test_benchmark_deepseek_v41_mla.py
  (including bit-exact mg2 == mg1), 5/5 DSV4.1 binding tests, 2/2 DSV4
  unified prefill live-graph smoke tests.

Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
…efill

Add a dedicated register-recycled FP8 prefill loop (_run_glm_next_fp8_pipelined)
for the GLM_NEXT ARBITRARY_FP32 path (D_QK=512, D_V=512, 4 inline FP32 scales)
in UnifiedPrefillMGKernel while preserving lossless FP8/E4M3 + FP32 scale
numerics and leaving DSV4/DSV41_SOURCE/GLM_NSA paths unchanged:

- Preload per-head Q block scales into registers once before the tile loop
  via 128-bit shared loads (eliminating 16 SMEM scale loads per tile in QK).
- Prefetch per-lane candidate indices ahead of QK so global/L2 index latency
  overlaps with all FP8 QK MMAs, and carry hoisted inline K/V scales through
  bitwise NaN-safe S3 masking directly into XV-NoPE (zero V-scale reloads).
- Pipeline ldmatrix across all 16 k32 steps of FP8 QK-NoPE.
- Pre-pack Pair-1 FP16x2 weights into 8 Uint32 registers before Pair-0 PV on
  mg_n_hg=2 (reclaiming all 32 pv and 16 inv registers prior to PV and reducing
  the inter-pair barrier window to 8 STS.32 stores), and expand single-head-group
  (mg_n_hg=1) w_fp8 staging to 8 slots (88,704 B / 101,376 B SMEM) so all four
  V-chunks stage simultaneously (reducing math-loop BAR.SYNC from 5 to 3/tile).
- Release empty_mbar on vc=3, k16=3 immediately after unpacking the final V
  words from kv_fp8, ahead of the final HMMAs and accumulator scale-accumulate
  FFMAs, and apply 240/24 math/IO dynamic register budgets (0 spills).
- Retain attention.mla.sm120.prefill_mg KernelCompileSpec version 7 (introduced in the preceding commit).

Validation on RTX PRO 6000 Blackwell (SM120):
- SASS (cuobjdump/nvdisasm -plr): STACK=0 LOCAL=0 STL=0 LDL=0 across mg2
  (SMEM 99,456 B, peak 200 live GPRs / 240, 5 loop BAR.SYNC) and mg1
  (SMEM 88,704 B, peak 132 live GPRs / 240, 3 loop BAR.SYNC).
- Parity: 12/12 GLM_NEXT shapes/edge cases (mg2 H64/H32, mg1 H16/H8, empty,
  1-tile, all-invalid first tile, strided Q, outlier + NaN unselected) match
  baseline within <=4.88e-4 abs / <=2e-6 LSE and match FP32 reference; mg2 and
  mg1 CUDA-graph replay match eager output identically (0.0 diff).
- Interleaved clock-matched (2610 MHz) L2-flushed CUDA-graph benchmarks:
  1.003x-1.010x across all 9 mg2 shapes (M=1024/2048/4096, contiguous/scattered/
  half-valid) and 1.000x at the ~4.0 TB/s SM120 L2-TMA ceiling on mg1 (H=16).

Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
@brandonmmusic-max
brandonmmusic-max force-pushed the b12x-mla-sm120-register-recycling branch from 5e1764c to 2e6a92f Compare November 29, 2026 18:17
@brandonmmusic-max

Copy link
Copy Markdown
Author

Rebased onto main (0a40ff0eb) across #160:

@voipmonitor

Copy link
Copy Markdown

Sharing end-to-end SM120 TP4 DeepSeek-V4.1-Flash A/B numbers measured sequentially on the same 4× RTX PRO 6000 Blackwell (600 W) GPUs with --prefill-chunk-size 16384 --row-shard-prefill --row-shard-attention --mla-compute-mode bf16.

Setup

  • Control: local-inference-lab/flashinfer@210003b77 (current main, which already includes #160 prefill_mg v6 and #183) + hyperflare-recipes@8ae2d0b + hyperflare-recipes#93
  • Treatment: Same exact base + flashinfer#175 + flashinfer#176 merged cleanly on top of 210003b77 (note: combined #175 + #176 run; unit tests 121/121 PASS, exported prefill_mg v8 verified compiled, both arms benchmarked sequentially on the exact same 4 GPUs with zero concurrent load)

Correctness & VRAM

  • Greedy 17*23=391: PASS on both arms
  • Cold NIAH 8K–128K (2 reps each): 10/10 PASS on both arms
  • Retained VRAM / KV cache: identical (81,138.65 MiB/GPU, 14.26 GiB/GPU KV cache)

Prefill A/B (DeepSeek-V4.1-Flash BF16 MLA, 16K chunk)

Calibrated 1-message NIAH (Wall / Prometheus GPU tok/s, 2-rep mean):

Context Control (main w/ #160 v6) Treatment (+#175+#176 v8) Δ GPU
8K 56.3K / 59.3K 56.9K / 59.8K +0.88%
16K 67.0K / 69.4K 66.7K / 69.0K -0.51%
32K 69.9K / 71.7K 69.2K / 71.0K -1.00%
64K 71.9K / 73.5K 71.0K / 72.6K -1.27%
128K 71.2K / 72.9K 70.2K / 71.9K -1.34%

llm_decode_bench (single-turn, exact token targeting, Client / Prometheus Server GPU tok/s):

Context Tokens Control Client / Server GPU Treatment Client / Server GPU Δ Server GPU
8K 8,192 54,518 / 57,940 54,834 / 58,376 +0.75%
16K 16,383 65,071 / 67,862 64,804 / 67,477 -0.57%
32K 32,768 69,054 / 70,854 68,643 / 70,406 -0.63%
64K 65,532 70,009 / 71,603 69,476 / 71,036 -0.79%
128K 131,071 69,158 / 70,830 68,716 / 70,289 -0.76%

Key observation for DeepSeek-V4.1

Current main already includes #160 (ba974a447, prefill_mg v6 with 8× fewer ldmatrix and 3-buffer KV staging), whereas this PR was branched prior to #160. On top of post-#160 main, the combined #175 + #176 stack improves 8K prefill slightly (+0.8%) but regresses 16K–128K prefill by -0.6% to -1.3% (~+2.8 ms per 16K chunk). It may be worth re-benchmarking DSV41_SOURCE prefill_mg v8 directly against #160 v6 (and keeping v6 for DSV41_SOURCE if v6 is faster at m=2048 while landing the GLM_NEXT improvements).

@brandonmmusic-max

brandonmmusic-max commented Nov 30, 2026 •

Copy link
Copy Markdown
Author

Thank you for running the 4x RTX PRO 6000 Blackwell end-to-end A/B and pointing out the post-#160 baseline shift.

Following up on your suggestion, direct L2-flushed CUDA-graph SM120 microbenchmarks comparing #175 (prefill_mg v8) directly against main@210003b77 (#160 v6) on DSV41_SOURCE BF16 extend (RTX PRO 6000 Blackwell Max-Q, 300 W, 128K scattered 2048-page pool, median over 25-30 replays) show v8 is faster than #160 v6 on all 23 tested shapes, including both ratio-1 (indexed_page_size=64) and ratio-2 (indexed_page_size=32) layers:

Shape (128K scattered pool) main@210003b77 (#160 v6) #175 (v8) Speedup
ratio1_ips64_sink_idx512_h64_m2048 1,083.10 us 991.30 us 1.093x
ratio1_ips64_sink_idx512_h64_m4096 2,146.34 us 1,982.21 us 1.083x
ratio1_ips64_sink_idx512_h16_m4096 (mg1) 804.90 us 710.37 us 1.133x
ratio2_ips32_sink_idx512_h64_m2048 1,076.96 us 983.10 us 1.095x
ratio2_ips32_sink_idx512_h64_m4096 2,137.12 us 1,970.24 us 1.085x
ratio1_ips64_idx2048_h64_m2048 3,242.02 us 2,938.91 us 1.103x
ratio1_ips64_idx2048_h64_m4096 6,760.48 us 5,970.98 us 1.132x
swa128_only_h64_m4096 646.91 us 614.14 us 1.053x

Checking the rest of the combined #175 + #176 stack on TP4 traced the -0.6% to -1.3% 16K-128K prefill regression to #176 defaulting B12X_PCIE_DMA_MEMOP_SYNC=1 in pcie_dma.py (+37 to +66 us per 80 MiB TP4 ring collective), which is now fixed to opt-in (0 by default) in #176 (be57f60f5). With that fix in place, #175 v8 should be a net positive on DeepSeek-V4.1 16K-128K prefill as well as GLM-5.3. Happy to do end to end test with llm inference bench if you'd like.

@voipmonitor

Copy link
Copy Markdown

Re-tested combined #175 (2e6a92fd4) + updated #176 (be57f60f5, B12X_PCIE_DMA_MEMOP_SYNC=0 by default) sequentially on the exact same 4× RTX PRO 6000 Blackwell (600 W) quad (GPUs 8–11) against main@210003b77 (DeepSeek-V4.1-Flash 16K prefill TP4 C32).

The earlier 16K–128K prefill dip and C=32 decode slowdown are gone:

  • Cold Prefill (llm_decode_bench.py, GPU srv tok/s): 8k +1.40% (56,810 vs 56,028), 16k -0.05% (66,474 vs 66,505), 32k -0.07% (69,503 vs 69,551), 64k +0.19% (70,293 vs 70,159), 128k -0.45% (69,310 vs 69,621).
  • Cold NIAH 8K–128K (10/10 PASS): 8K +0.50%, 16K +0.18%, 32K +0.05%, 64K +0.07%, 128K -0.39% GPU tok/s.
  • Decode: balanced-sweep step_ms improved -1% to -2% across C=1..32 (C=1 -2.05%, C32_P256 -1.74%), and llm_decode_bench ctx=32k C=32 is parity (1,574.0 vs 1,574.5 steps/s, +0.72% agg tok/s).

Full same-GPU breakdown posted on #176: #176 (comment)

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.

2 participants