← Back to Pull requests

fix(prims-ts): work around QuACK AST rewrite in MLA reduction #9087

Closed
unknown closed this pull request without merging on Nov 10, 2026 07:05 UTC
View on GitHub
unknown unknown commented on Nov 07, 2026 10:20 UTC
Author

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

📌 Description

When QuACK is imported before PrimTS compilation, its process-wide patch of CuTe's DSLPreprocessor.visit_If rewrites mixed compile-time/runtime conditions in other libraries' kernels too. With QuACK 0.6.2 and CuTe DSL 4.8.0, this exposes UNOBSERVED_WRITE_POSITION_UNKNOWN when the MLA reducer reuses stats_split_idx in its normalized-weight phase after intervening control-flow boundaries.

This PR is a compatibility workaround for that QuACK/CuTe interaction, tracked in Dao-AILab/quack#217. It gives the normalized-weight phase of _run_parallel_gmem_reduction_g1_shared_stats its own weight_split_idx local, separate from the LSE-load phase's stats_split_idx. Arithmetic, addresses, loop bounds, and synchronization are unchanged.

The original local name is valid without QuACK's AST rewrite. Standalone probes without the patch pass before and after the rename. Restoring only CuTe's original visit_If also makes the unmodified reducer and the TRT-LLM integration test pass, confirming the import-dependent compiler interaction. Scoping QuACK's rewrite remains the underlying upstream fix; this change keeps PrimTS compatible with affected environments.

This is a follow-up to the compatibility backport in NVIDIA/TensorRT-LLM#21354. The current TRT-LLM vendor pin and patch are unchanged by this follow-up.

🔍 Related Issues

  • https://github.com/Dao-AILab/quack/issues/217 — underlying process-wide AST patch issue

  • #8103

  • https://github.com/NVIDIA/TensorRT-LLM/pull/21354
  • 🚀 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

    The full GitHub Actions H100 run #42548670290 reported 127 failing CPU-test cases in test_cudnn_prepared_contract.py and test_cake_kcp_partition_parity.py. These are unrelated baseline fixture/API-discovery issues, outside the MLA reducer change. Their fixes are not included in this PR.

    Local validation on NVIDIA B300/SM103, PyTorch 2.14.0a0+b2c75dd062.nv26.09 / CUDA 13.4, and CuTe DSL 4.8.0:

  • Existing test_mla_runtime_count_changes[8-1-9216-dtype0] passed, including varying split counts and graph replay.

  • A local no-LSE probe (BF16, batch 2, 32 heads, one query, KV capacity 1024) passed against the existing independent MLA reference.

  • Both probes also pass on the unmodified standalone base f5ab85cc77edbd0257b0145eefe0113074dc6ee2. No redundant GPU test or test-matrix expansion is added to CI.

  • AST comparison confirms that only the index identifier changes; the reducer operations are unchanged. Scoped pre-commit passes.

  • The original TRT-LLM test_prims_ts_mla_live_wrapper_cuda_graph_replay[regular-kv] failed with the compiler diagnostic before its backport and passed after it.

  • A standalone reducer reproduction with a direct QuACK 0.6.2 import also fails with the original variable names. Restoring only CuTe's original DSLPreprocessor.visit_If makes both that reducer and the full TRT-LLM integration test pass without renaming the variable. These comparisons used separate fresh compiler caches.

  • The diagnostic reproductions are local only; no additional GPU tests are added to CI. Full upstream CI has not been run.
  • 🔬 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 review this as a narrow compatibility workaround for QuACK's process-wide AST rewrite. The underlying rewrite-scoping issue is tracked in Dao-AILab/quack#217. The reducer schedule and numerical implementation are unchanged.

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

    Summary by CodeRabbit

    Refactor
    Clarified parallel-reduction bookkeeping. Calculations and results remain unchanged.
    Tests
    Strengthened checks for prepared-state cleanup and function selection, helping ensure these behaviors remain consistent. No user-facing behavior changes are included.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

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