perf(attention): group tiny-KV FP8 context for uniform Q1-3 #9018
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 #9018"
general
weight: 0.35
qsang-nv
<!-- .github/pull_request_template.md -->
📌 Description
The tiny-KV optimization added in #8736 only admitted BF16 Q/KV and two query tokens. FP8-E4M3 Q/KV with BF16 output therefore continued to use the Context path, whose latency grows sharply with batch size for the workload in #7965.
Extend the existing grouped route to equal BF16 or FP8-E4M3 Q/KV with BF16 output and uniform query lengths 1, 2, or 3. Keep the SM103, batch 4–256, declared KV length 1–32, 16:1 query/KV heads, head dimension 128, page size 128, packed HND layout, and existing feature/stride restrictions. Preserve Context workspace and no-split behavior; excluded inputs retain their existing dispatch.
B300 SM103 / CUDA 13.0 measurements for FP8 Q/KV → BF16, Q2/KV2, H16:1, D128, page128, causal attention and PDL enabled:
| Batch | Native before → after (µs) | Speedup | Wrapper before → after (µs) | Speedup |
| ---: | ---: | ---: | ---: | ---: |
| 8 | 6.337 → 5.543 | 1.14× | 6.327 → 5.533 | 1.14× |
| 16 | 8.554 → 5.539 | 1.54× | 8.548 → 5.538 | 1.54× |
| 24 | 10.971 → 5.588 | 1.96× | 10.943 → 5.578 | 1.96× |
| 32 | 13.008 → 5.595 | 2.32× | 13.012 → 5.599 | 2.32× |
| 48 | 17.642 → 5.687 | 3.10× | 17.648 → 5.694 | 3.10× |
| 64 | 21.538 → 5.811 | 3.71× | 21.570 → 5.683 | 3.80× |
Matched baseline–candidate–candidate–baseline runs compare the unchanged Context launcher at
e9735b0239f834fa2f46a633e7ab76be49a2cc06with this patch, using identical represented FP8 inputs, unit scales, preallocated output/workspace/counters and separate JIT caches. Warm CUDA graphs contain 100 calls; each run uses three rounds of ten CUDA-event samples, excluding allocation, wrapper planning and JIT warmup. Row order is reversed in the latter pair. Values are aggregate medians; all twelve rows exceed the predefined 0.3 µs and 5% improvement margins. Actual kernel traces confirm grouped dispatch, including the separate Q3 kernel family.🔍 Related Issues
Related to https://github.com/flashinfer-ai/flashinfer/issues/7965, especially the FP8 reproducer. Follow-up to https://github.com/flashinfer-ai/flashinfer/pull/8736. Exact GB300 confirmation remains pending; this PR does not close the issue.
🚀 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.All applicable hooks passed for the two changed files. The repository-wide
--all-filescommand was not run.🧪 Tests
unittest, etc.).Reason: Targeted attention coverage is appropriate; no full-suite run is requested.
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_trtllm_gen_attention_prefill.pyTargeted B300 validation:
python3 -m pytest tests/attention/test_trtllm_gen_attention_prefill.py -q -k tiny_kv --maxfail=5: 345 passed, 14,906 deselected.🔬 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
This remains a draft pending exact GB300/SM103 CUDA13 validation. B300 results establish preliminary kernel behavior and warm-graph performance, not the reporter's target-system or end-to-end serving result. The bounded cold-cache result remains inconclusive. FlashAttention parity, the full reporter shape census, and the full repository suite are unverified.
Review focus: admission/fallback boundaries, Q3 dispatch, scale/masking/output semantics, and containment of the inherited numerical exceptions.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Expanded support for tiny-KV attention with BF16 and FP8 inputs across a wider range of query lengths and batch sizes.
Bug Fixes
Improved output correctness for empty requests, fully masked rows, and varied scaling settings.
* Improved reliability when replaying captured graphs after input scales or KV-length metadata changes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->