feat(mla): enable mega output for NVFP4 decode #9439
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
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 #9439"
general
weight: 0.35
qsang-nv
<!-- .github/pull_request_template.md -->
📌 Description
Enable fused Q RoPE, inverse output RoPE, and FP8 quantization for native NVFP4 split-KV decode through
run_mega. Both existing CTA schedules support Direct, Merge2, and General final-output plans. Direct plans write FP8 in the attention CTA. Split plans write partial contexts and LSEs, and the existing merge kernel writes the FP8 result. Stage-1-only plans require a separate final output step.Tests compare mega output, scales, and LSE with the separate kernels. They cover aligned and offset queries, empty and partial selections, more than 32 splits, single and dual caches, and CUDA Graph replay with poisoned destinations.
Performance
RTX PRO 6000 Blackwell Server Edition, 188 SMs. DSpark block size 6 and batch size 20 produce Q=140 verification queries, with H=64 and D=512. Inputs use 20 independent 32K-token histories, seven shifted SWA windows per request, and causal top-512 selections for sparse layers.
Times are median microseconds from three alternating trials using warmed CUDA Graph replay and warm L2. Both arms include Q RoPE, attention, inverse output RoPE, and FP8 quantization. Cache packing and index construction occur before timing.
Public dispatch
The table includes existing FP8 and NVFP4 prefill paths for context. This PR enables the native NVFP4 decode paths measured below.
| Cache | Selected KV | Selected implementation | Mega µs | Separate pipeline µs | Speedup |
|---|---:|---|---:|---:|---:|
| FP8 inline | 640 | Unsplit FP8 decode | 81.98 | 93.04 | 1.14× |
| FP8 inline | 128 | Unsplit FP8 decode | 29.86 | 40.08 | 1.34× |
| FP8 footer | 640 | Unsplit FP8 decode | 92.63 | 102.57 | 1.11× |
| FP8 footer | 128 | Unsplit FP8 decode | 29.45 | 38.67 | 1.31× |
| NVFP4 | 640 | NVFP4 prefill | 80.45 | 89.05 | 1.11× |
| NVFP4 | 128 | NVFP4 prefill | 24.31 | 33.34 | 1.37× |
NVFP4 decode plans
Q=140, H=64, 128 SWA entries plus 512 selected entries. Each chunk contains 64 entries. All rows use the existing grouped decode schedule. Each comparison uses identical partitions in its fused and separate-transform arms.
| Chunks per split | Merge | Mega µs | Separate pipeline µs | Speedup |
|---|---|---:|---:|---:|
| 1+1+1+1+1+1+1+1+1+1 | general | 182.13 | 208.34 | 1.14× |
| 2+2+2+2+2 | general | 113.52 | 126.22 | 1.11× |
| 3+3+3+1 | general | 106.97 | 118.44 | 1.11× |
| 4+4+2 | general | 98.67 | 108.50 | 1.10× |
| 5+5 | merge2 | 104.10 | 114.34 | 1.10× |
| 6+4 | merge2 | 102.16 | 112.29 | 1.10× |
| 7+3 | merge2 | 102.05 | 111.27 | 1.09× |
| 8+2 | merge2 | 81.73 | 91.61 | 1.12× |
| 9+1 | merge2 | 90.07 | 100.21 | 1.11× |
| 10 | direct | 95.50 | 103.79 | 1.09× |
All measured plans passed CUDA Graph replay with poisoned destinations and comparisons against separate transforms. NVFP4 output values, scales, and LSE matched exactly for the same partition. Independent numerical checks sampled query rows across request boundaries.
🔍 Related Issues
This PR builds on #9356, which enables native NVFP4 prefill mega.
🚀 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
Reason: <!-- e.g. cross-cutting change to shared infrastructure -->
Suggested CI test targets (optional; paths under
tests/, whitespace-separated — a startingpoint for
@flashinfer-bot run <targets>//bot run <targets>, reviewers may adjust):tests/attention/test_sparse_mla_sm120_nvfp4_decode_mega.py tests/attention/test_sparse_mla_sm120_dsv4_nvfp4.py tests/attention/test_sparse_mla_sm120_nvfp4_prefill_mega.py🔬 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
Review against #9356. The decode scheduling and attention pipeline stay in the existing implementation. Code and validation were assisted by Codex.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
NVFP4 sparse MLA decode now supports mega output, including grouped and ungrouped decode paths and result merging.
Tests
Expanded coverage across request counts, chunk settings, query offsets, and boundary sequence lengths.
* Added checks for CUDA graph replay, output validity, reference accuracy, and consistency with baseline results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->