perf(prims_ts): optimize NVFP4 decode conversion and scheduling #9315
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 #9315"
general
weight: 0.35
qsang-nv
📌 Description
Improve FP8-Q/NVFP4-KV decode with wide Swaps tiles, grouped Keeps conversion,
and work-based split selection. D128/D256 Keeps converts K/V into FP8 SMEM;
D512 Swaps uses staged conversion and swizzled V scales. On native SM107,
D256 Keeps retains packed rows in registers and releases raw SMEM before
conversion so loads can overlap conversion.
Conversion paths share row-scale and FP8-store helpers. Tasks stay in the flat
module and use the standard TaskManager with one-CTA resource budgets.
Swaps correction uses one early identity check; Q48 fragment coverage follows
query geometry. Explicit zero conversion depth selects the automatic depth;
unsafe converter warp counts and undersized padded statistics storage are
rejected. Wide direct-output tiles publish requested LSE, including graph replay
and padded query rows. Existing output tolerances and explicit nonzero conversion depths are
preserved.
The expanded full-grid split scoring and grouped-Keeps automatic eligibility
are limited to NVFP4. Homogeneous FP8 retains the base dispatch scope, including
the existing D128 FP16/BF16-output fixed multi-token, no-sinks grouping gate.
Explicit supported configurations are unchanged.
This PR includes the wide-tile changes previously proposed in #7409 and is
rebased directly onto main (
cfa0318a13).Performance
Rubin SM107 and GB300, CUDA 13.4, CuTe DSL 4.8.1. Hq16/Hkv2, D256, page128,
KV65536, FP8 Q/NVFP4 KV, BF16 output; Q1 dense and Q6 causal. Public auto
dispatch including reduction, seeded inputs, CUDA graphs (best of ten replays,
20 calls/replay, no L2 flush). Times are microseconds; the comparator is main
cfa0318a13on the same GPU. The PR column was measured ate294aa18b3;the resource/LSE follow-up preserves default-path outputs bit-for-bit and
changes matched Rubin timings by less than 0.1%.
| GPU | B | Q | Main µs | PR µs | Main / PR |
| --- | ---: | ---: | ---: | ---: | ---: |
| Rubin | 64 | 1 | 1924.96 | 316.32 | 6.09x |
| Rubin | 128 | 1 | 4440.33 | 629.44 | 7.05x |
| Rubin | 64 | 6 | 5648.03 | 321.80 | 17.55x |
| Rubin | 128 | 6 | 6922.52 | 638.00 | 10.85x |
| GB300 | 64 | 1 | 401.24 | 400.52 | 1.00x |
| GB300 | 128 | 1 | 824.83 | 770.44 | 1.07x |
| GB300 | 64 | 6 | 986.39 | 480.43 | 2.05x |
| GB300 | 128 | 6 | 1946.00 | 906.77 | 2.15x |
#6979 B200 verification
For the remaining D512/GQA8/Q5–Q6 cases in
#6979's update,
all 32 measured configurations select Q64 and one Q CTA per KV head.
KV splits process disjoint KV ranges and are counted separately. The cohort
covers heads 32/4 and 16/2, B8/B32, KV8K/KV32K, and page32/page64.
B200 (148 SMs), CUDA 13.4, DSL 4.8.1; FP8 Q/NVFP4 KV, FP16 output, causal
HND, uniform planned KV lengths, scale 1/sqrt(512). TRT FP8 uses the exact
logical K/V dequantized from the NVFP4 inputs. Median of 50 CUPTI CUDA-graph
samples after 10 warmups, with L2 flushed before each sample; attention and
reduction are included. Kernel source is
cf896fa52a; the subsequent changeonly adds regression coverage. Representative B32/KV32K/Q6 results in µs:
| TP | Page | Base
cfa0318a13NVFP4 | PR NVFP4 | TRT FP8 || ---: | ---: | ---: | ---: | ---: |
| 1 | 32 | 1551.49 | 564.37 | 677.94 |
| 1 | 64 | 1153.22 | 528.53 | 675.94 |
| 2 | 32 | 718.59 | 300.05 | 339.79 |
| 2 | 64 | 594.35 | 282.53 | 336.59 |
Across the 29 strict-reference-passing Q5/Q6 cases, PR/TRT latency is
0.77–1.10x; matched passing base/PR speedups are 1.22–2.76x. NCU reports
zero local and shared spilling requests in three representative Q64 profiles
(direct and separate reduction, large and small grids), and in the Q4/Q32
control. Q64 launches use 96 registers/thread and 640 threads/CTA.
The full D512 cohort including Q1/Q4 controls passes 61/64 strict FP16
comparisons on the PR and 60/64 on the base. The reference checks the first
two requests per case; all outputs are checked for finiteness. The three PR
failures also fail on the base at the same worst-error coordinates: TP2
B8/KV32K/page64/Q6, TP1 B32/KV8K/page32/Q6, and TP1 B32/KV8K/page64/Q5.
They are excluded from qualified timing claims, and no tolerance was changed.
The new maintained D512/Q64/page64 Q5/Q6 cases exercise V-scale swizzling,
partial/aligned output bands, LSE and graph replay; all 26 focused cases pass
on B200.
Scope limits remain: the small cold-cache cases can be about 10% slower than
TRT FP8. Q64 covers up to eight query tokens at GQA8; the Q9 control still
uses two Q CTAs (526.30 µs versus TRT FP8 413.81 µs). H128 page32/page64
controls pass on both base and PR with identical query-grouping policies,
confirming that the earlier page-size gate was already fixed upstream.
🔍 Related Issues
Related: #9311, #7409, #6979. SM107 staging ideas informed by #8322. This changes the
Prims backend; it does not optimize TRT NVFP4 or claim to resolve every #9311 shape.
🚀 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
unittest, etc.).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_attention_ts_decode.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
matches 1,806 supported FP8 configurations and 18 rejections; all 192 NVFP4
controls retain the previous PR choices. The scoped fix passes 225 maintained
decode checks and changed-file hooks. Six matched FP8 timings differ from
base cfa0318a13
by less than 0.6%.
Reviewed and cleaned with AI assistance. No new public tuning controls or
The resource/LSE follow-up passes 187 maintained decode/statistics checks on
The preceding optimization head passed 170 maintained checks on each GPU,
On Rubin, correction ordering was compared in four interleaved early/late rounds:
Removing the two-CTA residency policy has a tradeoff in forced Swaps
On Rubin, a separate strict FP16-output synthetic probe (B64/Q1, Hq32/Hkv4, D256, cfa0318a13` and this PR.exact-batch compilation fields are introduced.
Rubin. Its focused regression cohort has 24 cases: nine failed before the
fixes and all pass afterward, including Q48/Q64/Q128 LSE reference comparisons
and graph replay after clearing output buffers to NaN. Changed-file hooks pass.
A fresh GB300 run of this follow-up was not completed because its allocation
remained queued; the previous head's GB300 qualification is recorded below.
12 graph-replay boundary cohorts per GPU (48 request-level comparisons),
neighboring D128/D512 cases, and final-head smoke tests. Rubin also passed
page64 coverage and tensor-aware racecheck with zero hazards.
40 reference checks pass with bit-identical outputs. Early skipping lowers
latency by up to 8%; the consolidated helper reproduces the winning timings
and matches all ten saved outputs bit-for-bit on Rubin. The resource/LSE
follow-up additionally passes four interleaved before/after timing rounds
(16 reference checks) with bit-identical default-path outputs. Targeted
attention CI is requested for the updated head; the full repository suite
has not been run locally.
profiles: Rubin D256/Q48, B64/B128, KV65536, Hq16/Hkv2, page128, FP8 Q,
NVFP4 KV, BF16 output, five splits, raw/transformed ring depths 4/2 changes
from 914.48/1743.24 µs in the prior two-CTA control to 990.10/1893.79 µs
with one CTA (8–9% slower). Default D256 Keeps timings are preserved.
page64, KV8192) fails its tolerance on both base
Its numerical cause remains unresolved; no tolerance was relaxed. This
limitation is separate from the passing maintained suite and BF16 timings.
capability table is not a performance ranking. Swaps also supplies D512
coverage. D512 V-scale swizzling requires complete 1024-byte atoms and
smaller page fragments retain the unswizzled path.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Expanded attention decode support for FP8 queries with NVFP4 key/value caches, including BF16 output and head dimension 512 in supported configurations.
Added support for wider grouped-query configurations, additional paged decode setups, and larger runtime page windows.
Performance
Improved decode performance for supported NVFP4 and large grouped-query workloads, including on newer GPU architectures.
Improved handling of selected large-query and split-reduction workloads.
Documentation
Expanded guidance on supported decode configurations and scheduling behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->