Skip to content

perf(b12x/gemm): stream BF16 GEMV weights with .cs and add tk=128 TMA prefill tiles - #187

Open
original-el8 wants to merge 1 commit into
mainfrom
perf/b12x-bf16-gemv-cs-and-tk128-prefill
Open

original-el8 wants to merge 1 commit into
mainfrom
perf/b12x-bf16-gemv-cs-and-tk128-prefill

Conversation

@original-el8

Copy link
Copy Markdown

📌 Description

Optimize BF16->BF16/FP32 projections on SM121 (and large-N prefill projections) with cache-streaming SIMT weight loads, block_threads=256 wide-N decode defaults, and tk=128 2-stage TMA prefill tiles:

  • flashinfer/experimental/b12x/gemm/bf16_gemv/_kernel.py: switch SmallNGemvKernel global weight loads to ld_global_cs_v4_u32 (preserving .nc caching on activations) and bump gemm.bf16_projection.selected compile spec version (4 -> 5).
  • flashinfer/experimental/b12x/gemm/bf16_gemv/_prefill.py: parameterize Bf16PrefillKernel (tile_m, tile_n, tile_k, num_stages, m_warps, n_warps, evict_b, k_chunk_flush), switch launch grid order to (grid_m, n_tiles, split_k) (mn order) to avoid L2 thrashing at M >= 128, attach create_l2_evict_first_policy() on tma_atom_B when evict_b is active, add _warp_gemm_direct with periodic k_chunk_flush=16 accumulation for tk=128 tiles, and bump gemm.bf16_prefill compile spec version (3 -> 4).
  • flashinfer/experimental/b12x/gemm/bf16_gemv/_preparation.py & _tuning.py: add prefill_tile to GemvConfig (config schema 24 -> 25, candidate contract 18 -> 19), default block_threads=256 on <=64-SM GPUs for wide-N (out_features >= 16384, max_rows <= 8) SIMT decode, expose _PREFILL_TK128_TILES alongside torch for max_rows >= 24, out_features >= 8192, in_features >= 1024, in_features % 128 == 0, and validate prefill_tile across all backends.
  • tests/experimental/b12x/gemm/test_bf16_gemv_search_levels.py: update TC_MAX_ROWS and _tc_split_k_candidates expectations to match _tensor_core.py, and add unit tests for SM121 block_threads=256 decode defaults, large-N prefill_tile candidate exposure, and validate_config prefill_tile guards.

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

Conditions: captured CUDA graph replay for K=5120 -> N=32320 BF16->FP32 (330.96 MB weight, theoretical 273 GB/s floor 1212.8 us at M=1 to 1343.1 us at M=256):

M Baseline (backend, us, % 273) Tuned (config, us, GB/s, % 273) Speedup vs Baseline Max Abs Err vs FP32 Ref
1 simt(r8,t128) 1342.2 (90.4%) simt(r8,t256,cs) 1284.4 (257.8, 94.4%) -57.8 us (-111.8 us vs torch) 1.19e-6
3 simt(r8,t128) 1322.3 (91.8%) simt(r8,t256,cs) 1290.2 (256.8, 94.1%) -32.1 us 1.91e-6
6 simt(r8,t128) 1362.1 (89.2%) simt(r8,t256,cs) 1292.0 (256.8, 94.1%) -70.1 us 1.91e-6
8 simt(r8,t128) 1355.7 (89.7%) simt(r8,t256,cs) 1295.5 (256.3, 93.9%) -60.2 us 8.11e-6
16 torch 1409.6 (86.6%) torch 1409.6 (86.6%) torch retained 5.05e-5 (torch)
24 torch 1510.3 (81.1%) TMA(16x64x128,st2,w1x2,ev1,kf10) 1437.1 (85.2%) -73.2 us (+4.8%) 1.24e-5
32 torch 1518.0 (80.9%) TMA(64x64x128,st2,w4x2,ev1,kf0) 1428.3 (234.8, 86.0%) -89.7 us (+5.9%) 4.72e-5
64 torch 1547.3 (80.5%) TMA(64x64x128,st2,w4x2,ev1,kf0) 1451.2 (234.2, 85.8%) -96.1 us (+6.2%) 4.72e-5
128 torch 1624.4 (78.7%) TMA(64x64x128,st2,w4x2,ev1,kf0) 1502.6 (232.1, 85.0%) -121.8 us (+7.5%) 4.86e-5
256 torch 1895.9 (70.8%) TMA(128x64x128,st2,w4x2,ev1,kf20) 1635.0 (224.3, 82.2%) -260.9 us (+13.8%) 2.53e-5

Conclusion: streaming weights via ld.global.cs.v4.u32 with 256-thread CTAs reaches 93.9%–94.4% of GB10 peak bandwidth at M=1..8, while tk=128 2-stage TMA tiles with mn grid order and L2 evict_first on weights reduce M=256 latency by 261 us vs torch (and 644 us vs the 64x64x64 prefill baseline at 2279.4 us).

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_bf16_gemv.py tests/experimental/b12x/gemm/test_bf16_gemv_search_levels.py tests/experimental/b12x/gemm/test_bf16_gemv_vocab_summary.py tests/experimental/b12x/gemm/test_bf16_vocab_projection.py tests/experimental/b12x/gemm/test_bf16_vocab_search_levels.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/bf16_gemv/).
    • 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_bf16_gemv.py
tests/experimental/b12x/gemm/test_bf16_gemv_search_levels.py
tests/experimental/b12x/gemm/test_bf16_gemv_vocab_summary.py
tests/experimental/b12x/gemm/test_bf16_vocab_projection.py
tests/experimental/b12x/gemm/test_bf16_vocab_search_levels.py

Reviewer Notes

  • CPU unit tests executed with CUDA_VISIBLE_DEVICES="" (113 passed, 349 skipped across all tests/experimental/b12x/gemm/test_bf16*.py; CUDA runtime cases skipped on CPU build host).

… prefill tiles

- Use ld_global_cs_v4_u32 for SmallNGemvKernel weight loads and default
  block_threads=256 on <=64-SM GPUs for wide-N (out_features >= 16384,
  max_rows <= 8) SIMT decode.
- Parameterize Bf16PrefillKernel with (tile_m, tile_n, tile_k, m_warps,
  n_warps, evict_b, k_chunk_flush), switch grid order to (grid_m, n_tiles,
  split_k), apply L2 evict-first cache policy on TMA B loads, and add
  _warp_gemm_direct with periodic k_chunk_flush=16 for tk=128 tiles.
- Expose _PREFILL_TK128_TILES alongside torch in gemm.bf16_gemv for large-N
  prefill projections (max_rows >= 24, out_features >= 8192, in_features >= 1024),
  validate prefill_tile across all backends, and bump config_schema_version
  (24 -> 25) and candidate_contract_version (18 -> 19).
- Update test_bf16_gemv_search_levels.py for TC_MAX_ROWS/split_k contracts
  and add coverage for SM121 256-thread defaults and prefill_tile tuning.

Validated on CPU with CUDA_VISIBLE_DEVICES="" (113 passed, 349 CUDA-skipped
across tests/experimental/b12x/gemm/test_bf16*.py).

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