← Back to Pull requests

[Perf] Optimize SM90 DOTS3 MLA sliding-window decode #9511

Closed
unknown closed this pull request without merging on Nov 16, 2026 08:19 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 03:17 UTC
Author

<!-- .github/pull_request_template.md -->
<!-- Suggested title: [Perf] Optimize SM90 DOTS3 MLA sliding-window decode -->

📌 Description

This PR further optimizes the SM90 DOTS3 MLA+sliding-window backend merged in #6823. It improves the existing flashinfer.mla.batch_decode_with_kv_cache_mla_swa implementation without changing its public signature, workspace-size API, or precision contract.

Changes

  • Derive each CTA's physical-page range from its query token's causal window, rather than the request-wide union. W513 then needs at most nine pages per CTA, including s_q=4.

  • Fuse the FP32 split combine into a bounded cooperative grid for M8-S3/S5/S9 and the new M16-S4 tactic when the complete grid fits the queried device capacity. Keep the separate FP32 combine for larger/unsupported cooperative launches; no spin counters or workspace initialization are introduced.

  • Improve M16 pipelines with six lookahead slices, register-resident softmax row state, terminal-page cleanup/softmax overlap, and per-WG DSM ready/ACK synchronization.

  • Improve M32 softmax with half-warp row ownership and vectorized loads/stores. Reuse the dead RoPE KV slice for scores, cache PV rescaling factors, and add two lookahead slices to M32-S1.

  • Extend the autotuner from six to seven qualified tactics, select M16-S4 for the two 512-query-head-row shapes, and version its cache key. Update the tactic documentation and tests.
  • The existing contract remains BF16 Q/KV/output, local Hq=64, Dq=1088, Dv=1024, Page64, window_left=512 (513 tokens including the current token), local B in {1,2,4,8,16}, and s_q in {1,4}. Scores, PV accumulators, and all split-reduction payloads/calculations remain FP32. This does not introduce BF16 partial reduction.

    Performance

    GPU: NVIDIA H100 80GB HBM3, 132 SMs; local Hq=64, Hkv=1, Dq=1088, Dv=1024, W513/Page64, BF16 input/output and FP32 partial/reduction. Measurements use the same GPU/process/inputs, preallocated workspace/output, complete-op latency including split combine, and 12 balanced/interleaved rounds × 300 warm CUDA Graph replays.

    Fallback is the original SGLang Triton MLA+SWA op, forward_dense_kvlora_swa_torch_fallback, pinned at SGLang commit 0dcac68751189e6d3417daafad52393bff01b0c9. It is not a previous FlashInfer release or the standalone benchmark's PyTorch reference.

    Latency reduction = (fallback latency − this PR's latency) / fallback latency × 100%. Across all 20 cases, latency is 21.7%–53.8% lower than fallback. The geometric-mean speedup is 1.542×, corresponding to 35.1% lower latency; this aggregate is not an arithmetic average of the row percentages.

    B below is the local, per-device batch size. For attention-DP8, the corresponding global batch is 8 × B; these are attention-op measurements, not eight-device end-to-end throughput results. The tables use the qualified optimized kernel's archived paired measurements before publication-only formatting/comment/documentation cleanup; the Release rebuild was checked separately under Tests.

    s_q = 1

    | Local B | KV length | Tactic | Fallback (µs) | This PR (µs) | Speedup |
    |---:|---:|---|---:|---:|---:|
    | 1 | 4096 | M8-S9 | 19.249 | 9.268 | 2.08× |
    | 1 | 4127 | M8-S9 | 19.281 | 8.902 | 2.17× |
    | 2 | 4096 | M8-S5 | 20.043 | 11.451 | 1.75× |
    | 2 | 4127 | M8-S5 | 19.922 | 11.768 | 1.69× |
    | 4 | 4096 | M8-S3 | 22.618 | 15.081 | 1.50× |
    | 4 | 4127 | M8-S3 | 22.647 | 15.020 | 1.51× |
    | 8 | 4096 | M16-S4 | 25.654 | 17.173 | 1.49× |
    | 8 | 4127 | M16-S4 | 25.774 | 17.872 | 1.44× |
    | 16 | 4096 | M16-S2 | 38.477 | 21.899 | 1.76× |
    | 16 | 4127 | M16-S2 | 38.572 | 22.986 | 1.68× |

    s_q = 4

    | Local B | KV length | Tactic | Fallback (µs) | This PR (µs) | Speedup |
    |---:|---:|---|---:|---:|---:|
    | 1 | 4096 | M8-S3 | 21.051 | 14.463 | 1.46× |
    | 1 | 4127 | M8-S3 | 21.144 | 14.334 | 1.48× |
    | 2 | 4096 | M16-S4 | 22.551 | 15.662 | 1.44× |
    | 2 | 4127 | M16-S4 | 22.511 | 16.185 | 1.39× |
    | 4 | 4096 | M16-S2 | 26.385 | 20.020 | 1.32× |
    | 4 | 4127 | M16-S2 | 26.497 | 20.757 | 1.28× |
    | 8 | 4096 | M32-S2 | 36.692 | 26.318 | 1.39× |
    | 8 | 4127 | M32-S2 | 36.620 | 27.424 | 1.34× |
    | 16 | 4096 | M32-S1 | 62.248 | 41.366 | 1.50× |
    | 16 | 4127 | M32-S1 | 62.292 | 42.018 | 1.48× |

    To measure the current FlashInfer op and run its FP64 reference check:

    FLASHINFER_CUDA_ARCH_LIST=9.0a FLASHINFER_JIT_DEBUG=0 python benchmarks/bench_mla_swa_sm90.py \
        --batch-sizes 1 2 4 8 16 --q-lens 1 4 --kv-len 4096 \
        --rounds 12 --replays 300 --refcheck --output results/mla_swa_4096.json
    # Repeat with --kv-len 4127 and a different output filename.
    

    This standalone command requires no SGLang installation or model weights. Its pytorch_reference_us field is a gather/mask reference, not the Triton fallback in the tables. The fallback comparison was collected with the paired development harness (optimization_archive/iterations/20261029_table_driven_optimization/benchmark.py in the development archive), using the pinned SGLang fallback; that harness is not part of this FlashInfer PR.

    🔍 Related Issues

    Follow-up to https://github.com/flashinfer-ai/flashinfer/pull/6823.

    🚀 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.
  • Before the November 15 rebase, changed-file checks passed with the repository's hooks: clang-format 19.1.1, Ruff, mypy, and the standard file checks. Hooks were run with pre-commit run --files <changed files>; the whole-repository checkbox above is intentionally not claimed. These are historical results, not a fresh hook run against the rebased head.

    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: Not requested; changes are confined to the SM90 MLA+SWA backend.

    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_mla_swa_sm90.py tests/trace/test_mla_swa.py

    Targeted validation command:

    FLASHINFER_CUDA_ARCH_LIST=9.0a FLASHINFER_JIT_DEBUG=0 pytest -q \
        tests/attention/test_mla_swa_sm90.py tests/trace/test_mla_swa.py
    

    Historical GPU validation of the pre-rebase publication commit df6d7e550f04ea79775a3123bbd20169594504a8, on H100 80GB HBM3 with PyTorch 2.14.1+cu130 / CUDA 13.0:

  • Release JIT compilation and loading passed; all 26 compiled source identities matched that publication commit. The build has -DNDEBUG and no --device-debug.

  • 219 targeted tests passed, covering all seven tactics and the trace API. The existing FP64 accuracy thresholds are unchanged.

  • All 20 default-dispatch benchmark cases passed independent FP64 checks and produced bitwise-identical BF16 outputs to the sealed M18 module.

  • Same-job publication-vs-M18 replay comparison: geometric-mean latency change +0.09%. Nineteen of 20 rows differed by at most 0.23%; (B=16, s_q=4, KV=4127) measured +2.15%. These publication checks are separate from the fallback comparison above; no new speedup is claimed from formatting or rebasing.
  • The all-tests checkbox remains open pending PR CI: the full repository suite and full default AOT matrix were not rerun locally. Release validation explicitly used FLASHINFER_JIT_DEBUG=0.

    November 15, 2026 rebase verification

  • Rebased dots3_swa_perf onto upstream main at 67d996c0a454cf975e91fd97dcce457b4a54b202; the new head is 1c0d86e2322eb2d8ac7a63c0adabdda2072498e5.

  • The rebase was conflict-free. git range-diff reports an identical patch, and SHA-256 checks confirm that all 24 files changed by this PR are byte-for-byte identical to the previously validated publication tree. The CUTLASS and CCCL submodule revisions are unchanged as well.

  • git diff --check and Python AST parsing of the three modified Python files passed after rebasing.

  • GPU tests, performance measurements, and pre-commit hooks were not rerun after this rebase. The performance tables and 219-test result above remain archived pre-rebase evidence, not fresh validation of the updated dependency tree. Please run targeted CI on the final head:
  • @flashinfer-bot run tests/attention/test_mla_swa_sm90.py tests/trace/test_mla_swa.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

  • Please focus on cooperative-grid admission/fallback, the dead-RoPE score alias lifetime, and the M16 per-WG DSM ready/ACK publication and buffer-lifetime protocol.

  • Cooperative fusion is not assumed to be legal based only on a particular H100's SM count. Admission queries cooperative-launch support and actual kernel occupancy; non-fitting grids retain the two-kernel FP32 path.

  • Masked NaN/Inf cache slots must remain safe, the KV cache must not be modified, and the existing independent FP64 accuracy thresholds are unchanged. Tests cover all seven tactics, short/empty inputs, graph replay, non-default streams, and both fused/separate Global FP32 shapes.

  • The public API and workspace capacity are unchanged; tactic selection and the minimum opt-in shared-memory requirement are updated. No SM120 backend or SGLang code is changed.

  • The reported speedups are attention-op measurements on H100 HBM3, not model end-to-end speedups or a claim about other GPUs. No clean-sanitizer or full default AOT-build result is claimed for this follow-up.

  • Development and release preparation were AI-assisted; validation provenance and the remaining post-rebase CI requirement are stated above.
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

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

    Summary by CodeRabbit

    New Features
    Added an additional SM90 attention tactic, expanding the available options from six to seven.
    Added cooperative execution for eligible workloads, with existing execution paths used when cooperative execution is unavailable.
    Updated default tactic selection and tuning to include the new option.
    Bug Fixes
    Updated SM90 shared-memory requirements and improved coverage for correctness across tactics and context lengths.
    Documentation
    Updated SM90 requirements, tactic options, and execution behavior.

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

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