← Back to Pull requests

perf(attention): e4m3-query FA2 tensor-core decode on SM120 #6574

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 16, 2026 05:47 UTC
Author

<!-- .github/pull_request_template.md -->

📌 Description

FA2 tensor-core decode now takes an e4m3 query over an e4m3 KV cache. Q·Kᵀ and P·V both run on m16n8k32 e4m3 MMA, so no K or V element is converted to bf16. The softmax uses the VO-split layout, here from head_dim_vo 256: each KV warp stages its probabilities in shared memory as e4m3 words (P × 256) and multiplies the whole 64-token tile into its own 64-dim output slice. A thread then keeps 32 output accumulators instead of 128, and no cross-warp output merge is needed. The denominator stays the fp32 cross-warp sum. The query scale reaches the kernel the existing way, run(q_scale=...) folded into sm_scale.

The query dtype is part of the JIT module key, so bf16 and fp16 query modules do not change; their SASS matches the merge base. The ragged kernel is not instantiated for an e4m3 query.

plan() accepts an e4m3 query only where it was validated: SM120, single-token decode, e4m3 KV cache, bf16 output, head_dim 256, no RoPE or soft cap, and 1, 2, 4 or 8 query heads per KV head. Anything else raises NotImplementedError, and fast_decode_plan() rejects multi-token requests for this query.

🔍 Related Issues

The FA3 and trtllm-gen paths already take an fp8 query; FA2 did not.

🚀 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

  • 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 on the changed files with pre-commit run --files <changed files> and fixed any reported issues.
  • If you are unsure about how to set up pre-commit, see the pre-commit documentation.

    🧪 Tests

  • Tests have been added or updated as needed.

  • All tests are passing (unittest, etc.).
  • test_tensor_core_decode_fp8_query compares the e4m3-query decode against the bf16-query decode on the same query values (q_scale 0.5, exact in bf16), for 1, 2, 4 and 8 query heads per KV head. All four pass on SM120; the test is skipped elsewhere.

    Further checks on one SM120 GPU (16 query heads, 8 KV heads, head_dim 256, e4m3 KV with k/v scales):

  • Accuracy: against an fp64 reference that uses the rounded query, lengths 1 to 2000, windows 1023 and 4095, and split off, fixed and default. O max abs error is 0.0138, in line with vLLM's Triton unified attention on the same inputs. LSE max abs error is 7.9e-6. Re-planning a captured CUDA graph with other lengths and replaying it gives the same agreement.

  • SASS: bf16-query e4m3-KV head-256 and fp16 head-128 batch-prefill modules built for sm_120a match the merge base (20 objects).

  • Speed: CUDA-graph GPU time per call for a 1024-token sliding-window decode at 31 batch sizes from 20 to 128, with two length profiles. The timed build is this commit plus the separate CUDA-graph merge-path change; it is not this commit alone. Each row is the geometric mean over the batch sizes.
  • | Comparison | Profile 1 | Profile 2 |
    |---|---|---|
    | e4m3 query / bf16 query (this decode) | 0.963 | 0.962 |
    | e4m3 query / vLLM Triton unified attention, both given a pre-quantized query | 0.961 | 0.960 |
    | The same, both quantizing the query inside the call | 0.962 | 0.962 |

    The e4m3 query was faster than the bf16 query at every batch size.

    🔬 Experimental Track

    <!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends").
    Leave this section untouched for normal PRs. -->

  • This PR is experimental: it adds or changes code under 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 from backend="auto" without FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1. (Calling an @flashinfer_experimental_api or 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-tests tag — the experimental-track
    watcher 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

    <!-- Optional: anything you'd like reviewers to focus on, concerns, etc. -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Added support for FP8 E4M3 queries in FlashAttention 2 batch prefill when the query and KV cache use the matching format.
    Added support for FP8 E4M3 queries in paged prefill on SM120 when the query and KV cache use the matching format.
    Added support for FP8 E4M3 queries in tensor-core decode on SM120, with BF16 outputs and query-to-KV head ratios of 1, 2, 4, or 8. Decode is limited to single-token queries and supported attention configurations.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: lesj0610 Review duration: 2909m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6574"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%