← Back to Pull requests

refactor(prims-ts): derive MLA CP bounds from global sequence lengths #9641

Closed
unknown closed this pull request without merging on Nov 20, 2026 06:22 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 03:28 UTC
Author

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

📌 Description

Follow up merged #5489 by replacing Prims-TS MLA decode's use_kv_bounds / per-query kv_bounds interface with context-parallel topology and global request lengths.

  • plan() specializes cp_world and cp_interleave_size.

  • run() receives cp_rank and graph-live global seq_lens_kv, including the current query tokens. Planned max_kv_len and block tables remain rank-local physical capacity.

  • Both 1-CTA and 2-CTA kernels derive rank-local lengths and causal prefixes directly. Packed queries use actual qo_indptr differences; rank changes do not enter the compilation key.

  • Preserve CP=1 behavior, empty/inactive-row contracts, split reduction and LSE. The optional neutral writer uses a flattened grid without a 65,535-request grid-Y limit.

  • Validate split-KV cluster size against the CUDA device’s launch limit as well as occupancy. On B200 an occupancy query can report active clusters for 17 CTAs, even though only 16 can launch. Over-limit automatic splits use the separate reducer.

  • Update validation, trace schemas/examples, documentation and the existing focused regression file. Seven GPU cases remain; no large new matrix is introduced.
  • The branch is based on upstream main. CP documentation updates are confined to the PrimTS READMEs; docs/development/backend_notes.md is unchanged. No new context-kernel or standard-attention changes are introduced by this PR.

    Retained integration performance evidence

    Same MLA implementation validated in the TRT-LLM integration, with full FP8 KV cache, page size 128, 96 heads, latent/RoPE dimensions 512/64. H-D1/H-D8: local batch 1/8, Q=8, CP8 rank 0, local history 512 (global total 4104). D-D8/D-D16: local batch 8/16, Q=6, CP1, history 4096.

    Values are previous PrimTS → updated PrimTS microseconds, using the conservative order of balanced AB/BA runs and predefined confirmations. These are retained integration-snapshot measurements, not a new GPU run on this freshly main-based PR head.

    | Scope | Case | Rubin SM107 | B200 SM100 | B300 SM103 |
    |---|---|---|---|---|
    | Raw generation | H-D1 | 14.240 → 13.752 | 20.480 → 20.480 | 20.448 → 18.432 |
    | Raw generation | H-D8 | 18.000 → 17.936 | 16.368 → 16.384 | 16.352 → 16.368 |
    | Raw generation | D-D8 | 26.656 → 26.624 | 36.832 → 36.864 | 34.784 → 34.816 |
    | Raw generation | D-D16 | 30.552 → 30.584 | 65.504 → 65.536 | 65.792 → 66.261 |
    | Attention backend | H-D1 | 17.680 → 17.536 | 24.576 → 24.608 | 24.448 → 22.560 |
    | Attention backend | H-D8 | 23.360 → 23.840 | 24.576 → 24.472 | 22.496 → 22.496 |
    | Attention backend | D-D8 | 30.464 → 30.472 | 40.960 → 40.944 | 38.896 → 38.896 |
    | Attention backend | D-D16 | 36.984 → 36.992 | 73.712 → 73.712 | 73.744 → 73.752 |

    50 warmups and 100 CUDA-event samples per process, CUDA graph replay, 2×L2 flush outside event intervals, clocks unlocked; startup/JIT/reference work excluded. Backend timing includes metadata/preprocessing/cache work, raw generation does not. TRT-LLM still prepares compatibility bounds for other providers, so no eliminated producer cost is claimed. Rubin H-D8 backend has a valid +2.055% regression, narrowly above the predefined 2% cap; other Rubin generation scopes and all Blackwell scopes pass. These are rank-local component results, not CP communication, full-model throughput or TTFT.

    The consumer also contains a separate native single-is_lse merge cleanup and dispatch-policy update; those are not FlashInfer changes.

    🔍 Related Issues

  • Follow-up to merged #5489.

  • Consumer integration: https://github.com/NVIDIA/TensorRT-LLM/pull/19395

  • Existing experimental PrimTS tracking context: #4829, #5059, #5082.
  • 🚀 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.
  • Changed-file pre-commit checks passed, including mypy and Ruff. The existing checkout disables automatic hooks; hooks were run manually. A full-repository hook run is not claimed.

    🧪 Tests

  • Cluster-limit regression: the existing device-local occupancy test passed. Three B200 numerical checks covered the 17-CTA fallback on both devices and a legal 16-CTA cluster; both previously failing TRT-LLM TP2 MTP tests passed.
  • 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_cp.py tests/attention/test_attention_ts_mla_decode.py tests/trace/test_fi_trace_template_consistency.py

    Current-head local results:

  • Focused CPU contract checks in test_attention_ts_mla_decode.py: 9 passed.

  • Trace consistency: 1,240 passed, 2 skipped.

  • CP GPU regression collection: 7 cases, not executed again during publication.

  • Earlier matching-implementation GPU validation: seven CP kernel cases plus strict two-GPU Helix/MTP replay on Rubin; retained TRT-LLM focused/native/backend checks and paired generation measurements on Rubin, B200 and B300. These historical results are not represented as a fresh full-suite CI run.

  • No FlashInfer CI bot command was issued; CI is left to the maintainer.
  • 🔬 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 updates existing experimental PrimTS APIs marked with @flashinfer_experimental_api. Tracking context: #5489, #4829, #5059, #5082; a separate graduation-tracking issue is not claimed.

  • - [ ] 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.
    - [x] 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.)
    - [x] 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
    tests/experimental/test_experimental_api.py
    `

    As in #5489, this scope covers shared experimental opt-in behavior, not kernel correctness. Existing PrimTS implementation/tests remain under flashinfer/attention/prims_ts/ and tests/attention/`; the targeted attention tests above cover the kernels. Relocation/graduation is outside this follow-up.

    Reviewer Notes

    Please focus on global-to-local prefix arithmetic, packed-query alignment, split-reduction empty rows and graph-live metadata. This was developed and validated with Codex assistance. No NVIDIA-specific notices were added to FlashInfer files.

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

    Summary by CodeRabbit

    New Features
    Added context-parallel support for paged MLA decode, with configurable rank and interleave settings. Global KV lengths are mapped to rank-local cache prefixes.
    Empty rows on ranks with no locally visible KV tokens now return zero output and negative-infinity LSE by default; this behavior can be disabled.
    Bug Fixes
    Improved handling of supported cluster sizes when selecting attention launch configurations.
    Documentation
    * Updated MLA decode guidance and trace examples for context-parallel settings, local cache capacity, and empty-row behavior.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: qsang-nv Review duration: 3054m
    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 #9641"
    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%