feat(mla): add FP8 split-KV decode and wave-aware mega dispatch #9274
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9274"
general
weight: 0.35
qsang-nv
<!-- .github/pull_request_template.md -->
📌 Description
Replace homogeneous DSv4.1 FP8 sparse-MLA decode with a cooperative CuTe C++ implementation and reuse the FP8 prefill backbone for throughput. Public
runandrun_megaacceptimpl="auto" | "decode-splitkv" | "decode"for inline and footer FP8 caches, H=8/16/32/64, D=512. Auto selects from query/head tasks, SM count, and resident CTA waves.The low-latency core uses four compute warps per eight-head group, with a separate loader warp and CUTLASS transaction pipelines for double-buffered bulk gathers. Eight-head tasks use 32-candidate tiles; sixteen-head tasks use 64. QK partitions candidates across cooperating warps; PV partitions the 512 output features. Unfused attention uses independent CTAs plus a separate merge. The workspace-managed mega path performs cluster finalization inside the attention launch. Single-buffered scores have their own consumer-reuse barrier, separate from the two-stage KV pipeline.
Mega fuses query RoPE and quantization, sparse QK/softmax/PV with sink normalization, BF16 context rounding, inverse output RoPE, and FP8 output/scales. Learned projections, query normalization, cache construction, and sparse-index selection remain caller operations.
Caller-managed entries use the same CuTe core while preserving their scratch strides, 64-candidate chunk boundaries, pitched indices, partial heads, and separate merge contract. Their reduction supports more than 32 splits. Both cache layouts handle independent main/extra page sizes, page gaps, and nonzero aligned origins.
The replaced homogeneous FP8 kernel instantiations, the register-heavy one-warp variant, its unused gather machinery, and the obsolete tiny-footer cutoff are removed. Shared legacy bodies remain where other model/cache formats and BF16 computation still use them. Existing licenses and original baseline library/kernel sources were not changed.
Implementation and validation were prepared with Codex assistance.
Review follow-up at
49425854d: corrected the two new launch files to Apache-2.0, documented implementation selection versus mega fusion and CTA ownership at the cluster barrier, and kept the decode scheduling benchmark harness local. Migration and legacy-removal tracking: #9599. These commits change comments/licenses and remove the local-only benchmark from the PR; executable C++ tokens and Python test logic are unchanged from the validated310a1ed89. Changed-file pre-commit checks pass, and all 157 decode test cases still collect. GPU and benchmark results below retain their actual measured revision.Matched performance
RTX PRO 6000 Blackwell Server Edition, 188 SMs, 96 GB, driver 615.71.10. Baseline is original main
18fb0bfcc6d7e8a0c25a7784af559cc1e58124cb; replacement is310a1ed89. Both checkouts use the same external fixture and transform helpers, with identical input hashes. Compilation and setup are outside timing.Public
auto; warm-L2 CUDA Graph replay; 100 ms warmup and 1000 ms measurement per mode; CUDA-event timing, natural clocks, serialized GPU execution, alternating mode order. Times below are medians in microseconds. Attention-only includes partial reduction. Complete separate pipelines include Q RoPE, attention, inverse output RoPE, and FP8 casting/scales. Mega is compared with that complete original pipeline and checked exactly against the current separate implementation.Across all 46 cases, unfused attention ranges from 0.2% slower at its worst point to 2.33x faster, and mega is 1.16x–2.49x faster than the original complete pipeline. The worst attention-only point is T1/H64/K512 inline: 9.766 us original versus 9.786 us CuTe, a 0.020 us difference. There are no public-auto mega regressions in this matrix. The complete separate-transform chain still has three inline cases 3.7–5.2% slower (at most 0.62 us), despite attention-core parity; those measurements are retained below.
Canonical dual-cache workload: H64, D512, T=7B, 128 SWA + 512 compressed FP8 entries, independent 32,768-token histories per request.
| Local Q | Gathered KV | Layout | Baseline separate kernels | CuTe separate kernels | CuTe mega | Baseline / mega | Baseline / CuTe separate |
| --- | --- | --- | ---: | ---: | ---: | ---: | ---: |
| 7 | 128 + 512 | inline | 20.24 | 16.96 | 14.70 | 1.376x | 1.193x |
| 49 | 128 + 512 | inline | 88.23 | 42.66 | 39.49 | 2.234x | 2.068x |
| 98 | 128 + 512 | inline | 158.45 | 87.90 | 80.60 | 1.966x | 1.803x |
| 119 | 128 + 512 | inline | 160.22 | 89.66 | 81.18 | 1.974x | 1.787x |
| 140 | 128 + 512 | inline | 162.68 | 90.67 | 80.88 | 2.011x | 1.794x |
| 280 | 128 + 512 | inline | 321.96 | 150.38 | 129.28 | 2.490x | 2.141x |
<details>
<summary>All 46 paired cases, including unfused attention</summary>
Single-cache sweep: T=1/4/16/32/64, H=8/16/32/64, K=512, inline/footer, 1,048,576 cached tokens. The six canonical rows use the dual-cache workload above.
| T | H | KV | Layout | Original attention | CuTe attention | Original complete | CuTe separate | CuTe mega | Original complete / mega |
|---:|---:|---|---|---:|---:|---:|---:|---:|---:|
| 1 | 64 | 512 | inline | 9.77 | 9.79 | 12.04 | 12.04 | 10.35 | 1.163x |
| 1 | 8 | 512 | inline | 9.38 | 8.97 | 11.42 | 11.62 | 8.76 | 1.304x |
| 1 | 16 | 512 | inline | 9.97 | 9.77 | 11.83 | 11.84 | 9.99 | 1.184x |
| 1 | 32 | 512 | inline | 9.79 | 9.79 | 11.84 | 12.45 | 10.20 | 1.161x |
| 4 | 64 | 512 | inline | 10.38 | 9.99 | 12.45 | 12.45 | 10.60 | 1.174x |
| 4 | 8 | 512 | inline | 9.38 | 8.97 | 11.43 | 11.63 | 8.97 | 1.274x |
| 4 | 16 | 512 | inline | 10.20 | 9.79 | 11.84 | 12.04 | 10.20 | 1.160x |
| 4 | 32 | 512 | inline | 9.80 | 9.79 | 12.04 | 12.65 | 10.40 | 1.157x |
| 16 | 64 | 512 | inline | 24.10 | 16.52 | 25.98 | 19.00 | 17.77 | 1.462x |
| 16 | 8 | 512 | inline | 9.17 | 8.97 | 11.22 | 11.64 | 9.17 | 1.223x |
| 16 | 16 | 512 | inline | 9.99 | 9.77 | 12.04 | 12.04 | 10.20 | 1.180x |
| 16 | 32 | 512 | inline | 13.25 | 12.23 | 15.62 | 14.50 | 12.45 | 1.254x |
| 32 | 64 | 512 | inline | 34.78 | 23.31 | 38.26 | 27.20 | 23.92 | 1.599x |
| 32 | 8 | 512 | inline | 12.45 | 9.79 | 14.70 | 11.84 | 9.99 | 1.471x |
| 32 | 16 | 512 | inline | 13.48 | 12.25 | 15.73 | 14.70 | 12.60 | 1.248x |
| 32 | 32 | 512 | inline | 23.31 | 16.14 | 26.17 | 19.00 | 17.57 | 1.489x |
| 64 | 64 | 512 | inline | 61.83 | 31.71 | 67.76 | 37.46 | 33.55 | 2.020x |
| 64 | 8 | 512 | inline | 21.26 | 13.07 | 23.81 | 15.73 | 13.48 | 1.767x |
| 64 | 16 | 512 | inline | 23.31 | 16.34 | 26.38 | 19.41 | 17.59 | 1.500x |
| 64 | 32 | 512 | inline | 34.39 | 23.29 | 38.34 | 27.09 | 24.12 | 1.589x |
| 1 | 64 | 512 | footer | 10.20 | 9.38 | 12.24 | 11.43 | 9.79 | 1.250x |
| 1 | 8 | 512 | footer | 9.75 | 8.56 | 11.82 | 10.40 | 8.15 | 1.450x |
| 1 | 16 | 512 | footer | 10.20 | 9.38 | 12.23 | 11.43 | 9.58 | 1.277x |
| 1 | 32 | 512 | footer | 10.20 | 9.38 | 12.25 | 11.61 | 9.62 | 1.274x |
| 4 | 64 | 512 | footer | 10.38 | 9.56 | 12.65 | 11.84 | 9.99 | 1.265x |
| 4 | 8 | 512 | footer | 10.20 | 8.97 | 12.04 | 10.81 | 8.56 | 1.407x |
| 4 | 16 | 512 | footer | 10.60 | 9.79 | 12.66 | 12.03 | 10.20 | 1.241x |
| 4 | 32 | 512 | footer | 10.20 | 9.58 | 12.45 | 11.63 | 9.79 | 1.272x |
| 16 | 64 | 512 | footer | 25.56 | 20.03 | 28.21 | 22.69 | 21.26 | 1.327x |
| 16 | 8 | 512 | footer | 9.81 | 8.56 | 12.04 | 10.81 | 8.56 | 1.406x |
| 16 | 16 | 512 | footer | 10.41 | 9.56 | 12.65 | 11.64 | 9.99 | 1.265x |
| 16 | 32 | 512 | footer | 14.29 | 13.07 | 16.75 | 15.32 | 13.27 | 1.262x |
| 32 | 64 | 512 | footer | 37.19 | 33.06 | 40.92 | 36.84 | 33.56 | 1.219x |
| 32 | 8 | 512 | footer | 13.68 | 9.79 | 15.93 | 12.04 | 9.99 | 1.594x |
| 32 | 16 | 512 | footer | 14.29 | 13.05 | 16.75 | 15.52 | 13.27 | 1.262x |
| 32 | 32 | 512 | footer | 25.54 | 20.03 | 28.42 | 22.80 | 21.26 | 1.337x |
| 64 | 64 | 512 | footer | 64.68 | 37.00 | 70.62 | 42.97 | 38.46 | 1.836x |
| 64 | 8 | 512 | footer | 23.92 | 15.73 | 26.57 | 18.19 | 15.72 | 1.691x |
| 64 | 16 | 512 | footer | 25.52 | 20.01 | 28.63 | 23.11 | 21.26 | 1.347x |
| 64 | 32 | 512 | footer | 37.21 | 33.04 | 41.14 | 36.91 | 33.55 | 1.226x |
| 7 | 64 | 128+512 | inline | 17.98 | 14.50 | 20.24 | 16.96 | 14.70 | 1.376x |
| 49 | 64 | 128+512 | inline | 83.32 | 37.74 | 88.23 | 42.66 | 39.49 | 2.234x |
| 98 | 64 | 128+512 | inline | 150.38 | 78.19 | 158.45 | 87.90 | 80.60 | 1.966x |
| 119 | 64 | 128+512 | inline | 150.39 | 78.91 | 160.22 | 89.66 | 81.18 | 1.974x |
| 140 | 64 | 128+512 | inline | 150.59 | 78.50 | 162.68 | 90.67 | 80.88 | 2.011x |
| 280 | 64 | 128+512 | inline | 299.28 | 128.60 | 321.96 | 150.38 | 129.28 | 2.490x |
</details>
Raw timings, plans, input hashes, numerical checks, source hashes, and the exact external comparison driver are preserved in the measurement workspace at
results/low_h_release/(results.jsonl,provenance.json,run.py,report.md), with shared workerresults/pr9274_matched/worker.py. Baselineflashinfer/,csrc/, andinclude/remain unchanged.Profiler-guided correction
The earlier regression was in the unfused attention core: the one-warp schedule carried all 512 PV features per warp and used 255 registers/thread for H8, while cluster finalization also burdened unfused calls. The cooperative rewrite reduces per-warp work, restores independent-CTA unfused execution, and shares reduction arithmetic with mega. For T16/H8/K512 inline, final NCU reports 113 registers/thread, 160 threads/CTA, 43,648 shared bytes/CTA, and 128 independent CTAs; the previous CuTe kernel used 255 registers/thread and 64 threads/CTA. Achieved active warps/SM rose from 1.80 to 4.89. The separate merge uses 40 registers/thread and 64 threads/CTA.
The final report captures both kernels, with source/SASS embedded and verified:
results/low_h_diagnosis/cute-final.ncu-repz(1,030,861 bytes; SHA25640e588f7bbc1c7a478101d1f9ead1b5c9e9326ef3e33c9281a0bf26d8b0322a6). Basic + scheduler/warp-state sections, 16 replay passes/kernel,--clock-control none --pipeline-boost-state dynamic --cache-control none; measured SM frequency 2.31/2.28 GHz for decode/merge. Replayed profiler durations are not used as benchmark latencies. Race-isolation binaries, source/SASS, and before/after evidence are preserved underresults/low_h_race/.🔍 Related Issues
Stack:
main(merged #8747, FP8 prefill) → this PR → #9356 (NVFP4 prefill) → #9439 (NVFP4 decode).🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
At
310a1ed89on RTX PRO 6000 Blackwell Server:tests/attention/test_sparse_mla_sm120.pyfiles with--full.dsv4_fp8_splitkv_decodedecode/merge, excluding unrelated PyTorch reference kernels.scripts/task_run_unit_tests.sh(complete deterministic CI run, no sampling), 7m05s. Internal CUDA 13.0 image20261106-54b9f685, Python 3.10.22, PyTorch 2.14.1+cu130, Triton 3.8.0; GB10 48 SMs, driver 580.142. Fresh JIT/Triton caches. The RTX PRO 6000 lane also completed 1,430 passed, zero failed/skipped using the same internal CI image and runner, 7m31s; the earlier RTX sanitizer checks above remain separate results. The first RTX setup attempt hit an artifact-index network timeout; the unchanged retry passed. Both runs cover all 13 affected sparse-MLA files, not the repository-wide suite.Reason: <!-- e.g. cross-cutting change to shared infrastructure -->
Suggested CI targets: the 13
tests/attention/test_sparse_mla_sm120.pyfiles.🔬 Experimental Track
<!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends").
Leave this section untouched for normal PRs. -->
flashinfer/experimental/and/or an@flashinfer_experimental_api. Tracking issue: #- [ ] 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 a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff).
- [ ] Tests live in
tests/experimental/and were validated on the intended hardware; a runnable example is included.- [ ] Nothing is registered in
flashinfer/aot.py, and no experimental backend is reachable frombackend="auto"withoutFLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1. (Calling an@flashinfer_experimental_apior naming a backend explicitly is itself the opt-in and needs no environment variable.)- [ ] Test scope declared below. The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows.
<!-- Required for experimental PRs. Replace the commented lines below with your targets.
Do not delete the fence or change its
experimental-teststag — the experimental-trackwatcher reads it verbatim to decide which targets to ask CI for. -->
``
experimental-tests
``One target per line: a directory or a file. (A pytest ::selector is not
supported -- the sharding runner cannot consume one.) Must be under
tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.
# tests/experimental/test_my_backend.py
tests/experimental/my_backend/
# Declaring the whole tree (tests/experimental/) is allowed but means every
experimental PR pays for every other feature's tests, in every matrix cell.
Reviewer Notes
FP8 decode scope. The attention core is within 0.3% of baseline at worst in the paired measurements, and mega beats the original complete pipeline throughout the matrix. The separate-transform chain's three small slowdowns are reported explicitly rather than hidden by the fused comparison.