← Back to Pull requests

refactor(prims-ts): hoist paged context helper imports #9446

Closed
unknown closed this pull request without merging on Nov 20, 2026 08:17 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 09:12 UTC
Author

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

📌 Description

Paged-context resource methods import their helpers inside JIT-traced code, while FmhaTs.__init__ preloads the helper module through importlib to make those calls safe. This change resolves the helper functions at module import time and removes the constructor preload.

The paged helpers now take num_tokens_per_page directly instead of importing FmhaConfig from the resource module. That breaks the circular dependency and allows ordinary module-level imports. Page-bound arithmetic, resource scheduling, and public APIs are unchanged.

Current main already has the constructor preload. This is a structural cleanup for review, not a claim that the normal main-branch entry point fails. This change is now cherry-picked onto cute-dsl-precompile-api--prims-ts-upstream as 65dd30cc030043830ed46a3b688f891fd402270f; the TRT-LLM consumer pin uses it and drops the downstream helper-hoist patch.

🔍 Related Issues

  • #6529 introduced the constructor preload.

  • TensorRT-LLM carries a related helper-import hoist in its PrimTS vendor patch.

  • Related downstream integration: #9395 now includes this change as a cherry-pick.
  • 🚀 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

  • Changed-file pre-commit checks passed; no full-repository hook run is claimed.

  • The helper, resource, and kernel modules import successfully with CUDA devices hidden.

  • B200: main 2/2 and candidate 2/2 passed, with zero failures/errors/skips and clean outer exits. The same existing paged packed-launch-bounds and FP8 D256 dynamic-causal cases exercise variable sequence lengths, numerical references, and graph replay in fresh processes/caches. Baseline: ae58183fa8a21324c92a1bf2ad2ec658339cfed8; candidate: bbbf232603adbdb3bd355667333ada2502b8be3b. Both sides pass; no failing-main or performance-improvement claim is made.

  • No new test files, cases, or parameter matrix are added.
  • 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_context.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

    AI-assisted implementation. Please review the dependency direction, the scalar page-size substitution in both helper callers, and whether replacing the existing preload workaround is worth upstreaming. Ready for review. The consumer uses a cherry-pick; this PR has not been merged upstream.

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

    Summary by CodeRabbit

    Refactor
    Streamlined internal setup and configuration handling for paged attention. No user-visible behavior or public interfaces changed.
    * This maintenance update does not add or remove any user-facing capabilities. No changes to workflows or available features are expected. Users can continue using paged attention as before.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: qsang-nv Review duration: 10025m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    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
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #9446"
    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: 57% (MEDIUM) · Higher = larger blast radius
    57%
    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: 22.5% · Safe to merge
    22.5%