Skip to content

[https://nvbugs/7156469][fix] Isolate QSA decode plan-count test setup - #22958

Merged
trtllm-agent merged 3 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-v2/nvbug-7156469-r688
Nov 27, 2026
Merged

trtllm-agent merged 3 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-v2/nvbug-7156469-r688

Conversation

@trtllm-agent

@trtllm-agent trtllm-agent commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Before this change, test_decode_rows_get_exact_plans used a shared _CORE and assumed its three-row plan survived the subsequent five-row call. However, _PrimsTSSparseCore._workspace_for clears active plans when the workspace grows. On baseline 1aa8a889cf, a fresh-process run grows the workspace from 3584 to 4096 bytes and fails the existing 1 == (1 + 1) assertion.

Give the test a real, per-test sparse core with pytest's restoring monkeypatch fixture, and execute the existing five-row decode before the existing three-row decode. Require exactly one cached plan after the first call and exactly two after the second. Retain the five-row output shape and reference comparison, and compare the three-row output produced after changing row counts against the corresponding reference rows. Both decode argument sets and reference tolerances remain unchanged; no attention implementation, test ID or CI registration changes.

Fixes https://nvbugs/7156469

Test Coverage

  • tests/unittest/_torch/attention/sparse/qsa/test_qsa_prims_ts_core.py::test_decode_rows_get_exact_plans requires both distinct decode plans and checks both the initial five-row output and the three-row output after the row-count change.
  • The complete test_qsa_prims_ts_core.py module covers workspace-growth validation, packed prefill, decode, BF16/FP8 KV and CUDA-graph replay.
  • The existing GB300 post-merge attention entry continues to select this case; no additional test cases or CI matrix entries are added.

Direct GB300 verification through the repository's test_unittests.py::test_unittests_v2 launcher, with four GPUs visible and the configured SBSA CI image:

Invocation Baseline 1aa8a889cf Candidate 8ce8f15b0f
Exact case in a fresh pytest process Fails 1 == (1 + 1) Passes in 3 separate processes
Complete module, one process 19 passed 19 passed
Complete module, four xdist workers 19 passed 19 passed

The candidate runs have no failures, errors or skipped leaf cases. A separate diagnostic exact-case run also passes: the five-row call allocates 4096 bytes, then the three-row call requests 3584 bytes without replacing the workspace or discarding the five-row plan. One-time mutation checks confirm that the revised test rejects a missing cached plan for either size and incorrect output after changing row counts. These are direct test runs, not a full CI pipeline result.

PR Checklist

  • Reviewed the applicable checklist items. This test-only change adds no API, dependency or ownership change; existing regression coverage is retained.

Dev Engineer Review

  • The test now uses a fresh prims_ts_core._PrimsTSSparseCore(), set through monkeypatch.setattr(prims_ts_core, "_CORE", core). The fixture restores _CORE after the test.
  • The module-level import from ...qsa import prims_ts_core exists at line 11 of the base file. No new import is needed.
  • The test asserts absolute plan counts (1, then 2). This holds only while the isolated core starts empty, which the fresh core ensures.
  • The five-row decode now runs first, followed by the three-row decode. Both outputs are checked against the reference.
  • No source code changed. The diff touches one test function.

QA Engineer Review

Test files modified: tests/unittest/_torch/attention/sparse/qsa/test_qsa_prims_ts_core.py.

  • Function: test_decode_rows_get_exact_plans. It now uses an isolated core and runs the five-row decode first.
  • Checks: one plan after the first call, two after the second, the five-row output against expected, and the three-row output against expected[:3].
  • Test-list status: test-db/l0_gr100.yml lists only test_auto_gates_small_decode_batches from this module. The diff does not show the exact test ID in a list. The GB300 post-merge entry named in the objectives is not verified here.
  • Coverage verdict: sufficient for the stated plan-cache regression. Test-list selection needs follow-up.

Per-File QA Perspective

  • test_qsa_prims_ts_core.py: Isolates the plan-count test from shared core state. Verify it passes in a fresh process and under xdist. Confirm the exact test ID is selected by the intended CI entry.

The decode-row test uses the shared _CORE and executes three rows before
five rows. _PrimsTSSparseCore._workspace_for clears _plans when the
workspace grows, so the increment checked by
test_decode_rows_get_exact_plans can depend on earlier allocations.

Use a fresh sparse core scoped by pytest's monkeypatch fixture and run
the five-row decode first. Require exactly one cached plan after that
call and exactly two after the three-row call. Keep the five-row output
and reference checks, and compare the output after changing row counts
against the corresponding reference rows at the same tolerances in
tests/unittest/_torch/attention/sparse/qsa/test_qsa_prims_ts_core.py.

Before this change, test_decode_rows_get_exact_plans at 1aa8a88 fails
with 1 == (1 + 1) on GB300. The workspace grows from 3584 to 4096 bytes
between its three-row and five-row calls, dropping the three-row plan.

Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3d42bbe and 282fc53.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The decode test now uses an isolated _PrimsTSSparseCore instance. It checks plan counts after five-row and three-row calls, and compares the three-row output with the matching reference slice.

Changes

Decode plan test

Layer / File(s) Summary
Isolated core and decode assertions
tests/unittest/_torch/attention/sparse/qsa/test_qsa_prims_ts_core.py
The test uses a fresh core instance, checks that the calls create two plans, and compares the three-row output with the first three reference rows.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: farazkh80

Merge Risk: Minimal · previous review 3d42b

This change only makes an existing decode plan-count test more reliable and does not touch production attention code. No merge-blocking risk is identified.

Security architecture risk: Minimal · up to 8ce8f

The change isolates the decode test from shared cache state and adds an output check. It does not change production behavior or expand access.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the NVBugs ID and type [fix], and says the change isolates the QSA decode plan-count test setup. The raw summary and objectives confirm this matches the changeset: the test now uses an…
Description check Passed The description follows the template's main sections. It explains the problem (shared _CORE and workspace growth clearing plans), the fix (per-test core via monkeypatch, call reordering, plan-count an…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the NVBugs ID and type [fix], and says the change isolates the QSA decode plan-count test setup. The raw summary and objectives confirm this matches the changeset: the test now uses an isolated sparse core, runs the five-row decode first, and checks plan counts. The title is specific and follows the repository format.

Full details: Description check

Explanation

The description follows the template's main sections. It explains the problem (shared _CORE and workspace growth clearing plans), the fix (per-test core via monkeypatch, call reordering, plan-count and reference checks), and the test coverage. It links the NVBugs ID. The PR checklist is marked as reviewed. The template's Description and Test Coverage headings are present and filled in. Minor gaps: the description does not restate the template's API-change label decision, and it does not explicitly address the CODEOWNERS or documentation items beyond stating no ownership change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8ce8f15 and 3d42bbe.

Files selected for processing: 1

  • tests/unittest/_torch/attention/sparse/qsa/test_qsa_prims_ts_core.py
Files skipped from review as they are similar to previous changes: 1

  • tests/unittest/_torch/attention/sparse/qsa/test_qsa_prims_ts_core.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@yuxianq

yuxianq commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

@heyuhhh, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~

Assignment explanation
Componentsintegration/attention-tests (100%)
Tagsalgorithm:sparse (100%); specific-algorithm:qsa (100%); representation:gqa (100%); phase:decode (100%); features:paged-kv (100%)
PR effort2 points — The fresh core gives the test a known starting state. Running five rows before three avoids the workspace growth that could discard the first plan. Review requires tracing two calls and checking that the sliced inputs correspond to expected[:3].
Affinity (0–1)0.513 component/tag match
Affinity evidenceMerged authorship 2 × √points; first review 1 × √points; global normalization 0.753606
Outstanding points at selection7 → 7 (+0)
Points already reserved on this PR2
Effective weight0.5
Completed review points (preceding 168 hours)18
Combined points after assignment25
Demand-derived target25.00 points (soft share)
Additional fair share before assignment0.00 points
Share explanationWithin demand-derived share.
Selection rulebalance-first maintenance
Assignment scope (heyuhhh)sparse_attention

Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once.

@yuxianq
yuxianq removed the request for review from kris1025 November 26, 2026 13:54

@trtllm-agent-review trtllm-agent-review left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. This PR gives test_decode_rows_get_exact_plans its own sparse core and runs the 5-row decode before the 3-row one, so workspace growth no longer drops the cached plan and the test passes in a fresh process; it also checks the 3-row output against the reference.

Reviewed at commit 8ce8f15b0f (1 file, +10/−8).

This is a test-only change. The review read the production workspace-sizing code only to check the test's assumptions.

Approve: no Blocker found. 1 suggestion below is nice to have.

Nice to have (1): 1 inline, 0 below
  • (N2: Test design and organization) The 5-then-3 call order is what keeps both plans cached, but the test doesn't say so; putting the 3-row call first again fails len(core._plans) == 2 with 1 == 2. (test_qsa_prims_ts_core.py:551)
What this review checked
  • The plan counts are deterministic on every GPU that runs the test (B200 and B300 pre-merge, GB300 post-merge). In this geometry the split-KV fanout is capped at 1 (tensorrt_llm/_torch/attention/backends/prims_ts/_q_token_kv_block_sparse_policy.py:105-106), so the 3-row workspace (3584 B) never exceeds the 5-row one (4096 B) and _workspace_for keeps both plans.
  • monkeypatch.setattr(prims_ts_core, "_CORE", core) reaches both calls, because prims_ts_sparse_gqa reads _CORE at call time (tensorrt_llm/_torch/attention/backends/sparse/qsa/prims_ts_core.py:522), and the shared core is restored afterwards. The sibling test_prefill_rows_share_plans_within_bucket is not order-dependent, because its second call hits the same plan key.
  • The test can still catch a regression. The 3-row and 5-row plan keys differ in route shape and route count (tensorrt_llm/_torch/attention/backends/sparse/qsa/prims_ts_core.py:383-384), so decode plans that are bucketed or shared across row counts fail len(core._plans) == 2. expected[:3] is the matching reference for the sliced inputs.
  • Not covered: No GPU run: the test was not executed for this review.
  • Not covered: No pre-merge CI run on the PR yet.

Automated review by trtllm-agent-review. If a point is wrong, reply in its thread. Once you have pushed code changes and replied in every Blocker thread, the bot re-checks the Blockers within a few hours. A Blocker you think should not be fixed needs no code change: reply in its thread with the reason and the evidence.

Explain that the larger decode runs first because workspace growth
clears the active plan cache. Only a comment changes; the decode calls,
plan-count checks and output/reference comparisons stay unchanged.

Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
@trtllm-agent

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #87524 [ run ] triggered by Bot. Commit: 3d42bbe Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #87524 [ run ] completed with state FAILURE. Commit: 3d42bbe
/LLM/main/L0_MergeRequest_PR pipeline #72631 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

…156469-r688

Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com>
@trtllm-agent

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #87780 [ run ] triggered by Bot. Commit: 282fc53 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #87780 [ run ] completed with state SUCCESS. Commit: 282fc53
/LLM/main/L0_MergeRequest_PR pipeline #72877 completed with status: 'SUCCESS'

CI Report

Link to invocation

@trtllm-agent
trtllm-agent added this pull request to the merge queue Nov 27, 2026
Merged via the queue into NVIDIA:main with commit 62bf3cb Nov 27, 2026
11 checks passed
@trtllm-agent
trtllm-agent deleted the repair-bot-v2/nvbug-7156469-r688 branch November 27, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants