← Back to Pull requests

perf(prims-ts): unroll runtime-split MLA reduction in dispatched windows #8103

Closed
unknown closed this pull request without merging on Nov 02, 2026 07:03 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 09:19 UTC
Author

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

📌 Description

Fixes a prims-ts MLA decode latency regression from #6925 (runtime split-KV).

The 1CTA MLA kernel now compiles with an SM-bounded split capacity and takes the active split count at launch. The parallel G1 split-KV reducer kept its fully unrolled loop only for exactly 32 splits. Any other count fell back to cutlass.range(..., unroll=4), which serializes the partial-O loads. With 36 splits (GLM-style bs1 decode) the reducer went from 2.66 us to 4.57 us. The attention kernel itself is unchanged.

This PR compiles fixed unrolled windows of 8, 16, 32, 48, 64, 96 and 128 splits into the reducer. The live count selects one at runtime.

  • Only the slots above the previous window are predicated, using clamped loads with zero weights, so each window stays branch-free.

  • Counts above 128 walk unrolled chunks of 16 the same way.

  • The compile signature is unchanged, so there are no new kernel variants or JIT-cache entries: across 512 max_kv_len plans, the number of distinct compiled MLA kernels matches main. Static-split kernels keep their exact unrolled loop.
  • GB300, flashinfer_benchmark.py --routine BatchMLAPagedAttentionWrapper --backends prims-ts, batch 1, s_qo 1, ckv 512 / kpe 64, median us:

    | Case | Before #6925 | main | This PR |
    |---|---|---|---|
    | fp8, 8 heads, s_kv 9216, page 64 | 9.77 | 11.62 | 10.19 |
    | bf16, 12 heads, s_kv 3840, page 32 | 10.94 | 12.35 | 10.87 |

    Reducer kernel only, fp8, 8 heads (main → this PR): 36 splits 4.80 → 3.31 us, 96 splits 8.45 → 4.19 us, 128 splits 10.41 → 4.92 us.

    🔍 Related Issues

    Regression introduced by #6925 (e46d856).

    🚀 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/attention/test_attention_ts_mla_decode.py tests/attention/test_attention_ts_sparse_mla.py

    🔬 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

  • test_mla_runtime_count_changes now pins both sides of every reducer window boundary (8/9 … 128/129) and adds a Q8 case.

  • Local GB300 runs (DSL 4.8.1, CUDA 13.4): test_mla_runtime_count_changes` (12/12), the MLA split-reduction / 1CTA / variable-K / runtime-K-pruning subset (26/26) and the sparse-MLA split/reduction subset (13/13) pass. Pre-commit was run on the changed files only.

  • Alternatives measured:

  • - A per-plan window in the compile signature was faster on fp8 (10.07 us), but added +14 / +16 compiled kernels per 512 plans.
    - Software-pipelined chunks were slower (10.9 us).
    - A denser window set (every 8 up to 64) was slower: each window adds code that the short reducer launch has to fetch.
  • Cold compile of one MLA kernel takes about 2–5 s (4–7%) longer for the extra unrolled windows, e.g. 49.7 → 51.5 s (fp8, s_kv 9216) and 56.4 → 58.4 s (bf16). These were measured concurrently, so the timings are noisy.

  • The fp8 case remains about 4% over its pre-#6925 latency.
  • 🤖 Generated with Claude Code

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

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Performance
    Improved attention decoding across a wider range of split counts, including large counts.
    * Runtime workloads now use appropriately sized reduction windows, with chunked handling for counts beyond the largest window. This broadens support for varying workload sizes while retaining exact-count handling for fixed split counts.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: qsang-nv Review duration: 2744m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8103"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 20.5% · Safe to merge
    20.5%