← Back to Pull requests

feat(prims-ts): add mxfp8 output quant fusion to context and decode #9618

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 17, 2026 19:38 UTC
Author

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

📌 Description

Adds MXFP8 output to the prims-ts context and decode kernels.

API Changes

  • Wrappers: BatchPrefillTSWrapper.plan, BatchPrefillPagedTSWrapper.plan and BatchDecodePagedTSWrapper.plan take out_dtype=torch.float8_e4m3fn together with out_scale_dtype=torch.float8_e8m0fnu (torch.uint8 is accepted as an alias). run(out_scale=...) returns (out, out_scale[, lse]).

  • One-shot calls: batch_prefill, batch_prefill_with_paged_kv_cache and batch_decode_with_paged_kv_cache take out_scale=, and the scale buffer's dtype selects the format. get_prims_ts_batch_decode_workspace_size(out_scale_dtype=...) sizes the quantized plan.

  • Scale layout: a flat buffer of round_up(tokens, 128) round_up(Hq Dv / 32, 4) bytes in the 128x4 swizzled layout of the block-scaled GEMMs, the same layout as mxfp8_quantize(..., is_sf_swizzled_layout=True). Padding entries are never written.

  • Format table: formats are keyed by (out_dtype, out_scale_dtype) in prims_ts/_quant_output.py, currently only having mxfp8.
  • Performance

    Tested on B300

    32 Q Heads, 4 Kv heads, non-sliding window

    | KV | Batch | Fused (µs) | Unfused (µs) | Speedup |
    |:---:|:-----:|:----------:|:------------:|:-------:|
    | 1K | 1 | 6.21 | 7.90 | 1.27× |
    | 1K | 8 | 6.50 | 8.51 | 1.31× |
    | 1K | 32 | 9.44 | 11.30 | 1.20× |
    | 1K | 128 | 24.90 | 27.20 | 1.09× |
    | 1K | 512 | 81.38 | 85.09 | 1.05× |
    | 1K | 2048 | 309.4 | 319.3 | 1.03× |
    | 1K | 8192 | 1221 | 1254 | 1.03× |
    | 8K | 1 | 7.39 | 8.96 | 1.21× |
    | 8K | 8 | 15.04 | 17.02 | 1.13× |
    | 8K | 32 | 42.30 | 44.64 | 1.06× |
    | 8K | 128 | 158.0 | 161.0 | 1.02× |
    | 8K | 512 | 606.9 | 611.6 | 1.01× |
    | 8K | 2048 | 2381 | 2394 | 1.01× |
    | 8K | 8192 | 9495 | 9534 | 1.00× |
    | 32K | 1 | 12.13 | 13.76 | 1.13× |
    | 32K | 8 | 44.53 | 46.72 | 1.05× |
    | 32K | 32 | 155.2 | 157.3 | 1.01× |
    | 32K | 128 | 608.6 | 610.9 | 1.00× |
    | 32K | 512 | 2401 | 2406 | 1.00× |
    | 32K | 2048 | 9480 | 9486 | 1.00× |

    32 Q Heads, 4 Kv heads, sliding window 128

    | KV | Batch | Fused (µs) | Unfused (µs) | Speedup |
    |:--:|:-----:|:----------:|:------------:|:-------:|
    | 8K | 1 | 5.04 | 6.69 | 1.33× |
    | 8K | 8 | 5.41 | 7.49 | 1.38× |
    | 8K | 32 | 5.86 | 7.90 | 1.35× |
    | 8K | 128 | 10.69 | 11.68 | 1.09× |
    | 8K | 512 | 27.30 | 24.42 | 0.89× |
    | 8K | 2048 | 93.70 | 78.08 | 0.83× |
    | 8K | 8192 | 359.4 | 290.0 | 0.81× |

    🔍 Related Issues

    <!-- Link any related issues here -->

    🚀 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 manually with pre-commit run --all-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.).

  • This PR requires full-scope CI, not targeted tests (expensive; justify below).

  • Reason: <!-- e.g. cross-cutting change to shared infrastructure -->

    Suggested CI test targets (optional; paths under tests/, whitespace-separated — a starting
    point for @flashinfer-bot run <targets> / /bot run <targets>, reviewers may adjust): tests/...

    🔬 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 -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Context and decode attention support block-scaled MXFP8 outputs with optional scale buffers.
    Select a supported scale format, provide a compatible buffer, or let the API allocate one. Quantized calls return the output and scales, with log-sum-exp included when requested.
    Support is limited to compatible attention configurations; quantized output is unavailable for some input and attention modes.
    Documentation
    Added guidance on scale layout, buffer sizing, graph capture, and supported configurations.
    Known Limitations
    Attention tracing does not support quantized outputs.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: qsang-nv Review duration: 25789m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). 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%
    46%
    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 #9618"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%