Skip to content

[None][feat] Add DSA Vanilla sparse attention - #16309

Open
yihwang-nv wants to merge 1 commit into
NVIDIA:mainfrom
yihwang-nv:vanilla-dsa-attention
Open

[None][feat] Add DSA Vanilla sparse attention#16309
yihwang-nv wants to merge 1 commit into
NVIDIA:mainfrom
yihwang-nv:vanilla-dsa-attention

Conversation

@yihwang-nv

@yihwang-nv yihwang-nv commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Depends on #18044.

Description

  • Add standalone DSAVanillaAttention and DSAVanillaIndexer PyTorch golden implementations with the same module-facing contracts as the TRTLLM DSA backend.
  • Implement the fake-fused RoPE path entirely with PyTorch APIs. Context and generation paths apply RoPE exactly once and preserve the same cache-ownership contract as DSATrtllmAttention.
  • Cover paged latent-cache reads and writes, selected sparse MLA, FP8-DS-MLA inline scales, FP8/FP4 indexer quantization, ragged and paged MQA logits, TopK selection, compressed index coordinates, cached-prefix generation, and the TRTLLM_DSA_INDEXER_BF16 projection mode without dispatching through the production fused kernels.
  • Register Vanilla DSA and update the sparse-MLA/backend test harnesses to use Vanilla Attention plus the Vanilla Indexer as independent golden references.
  • Fix the paged-MQA PyTorch reference for a max_model_len whose final page is partial, and validate compressed generation coordinates when a cached prefix is present.

The implementation is intentionally standalone: projection, quantization, RoPE, cache reconstruction, scoring, and selection are expressed in PyTorch so a defect in a TRTLLM/DeepGEMM/CuTe kernel cannot be hidden by sharing its implementation with the golden.

Test Coverage

  • pytest -q tests/unittest/_torch/attention/sparse/dsa — passed on B200 before the upstream rebase.
  • pytest -q tests/unittest/_torch/attention/test_attention_backends.py -k deepseekv3_2_dsa_mla — passed on B200 before the upstream rebase.
  • Repository pre-commit hooks on the rebased commits — passed.
  • ruff check, ruff format --check, and git diff --check for the rebased DSA changes — passed.

The current host cannot collect TensorRT-LLM pytest tests because its Python environment cannot load libmpi; CI should revalidate the rebased head.

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@yihwang-nv yihwang-nv changed the title [None][feat] Add DSA sparse attention to VanillaAttention [None][feat] Add DSA sparse attention + indexer reference to VanillaAttention; unify sparse backend tests Jul 15, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59376 [ run ] triggered by Bot. Commit: b3238f5 Link to invocation

# (production replays a captured decode graph); it must still match the
# eager golden.
if case.is_gen_only:
if case.is_gen_only and not case.is_sparse:

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.

Why we cannot enable cuda graph for sparse case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This backend-only path is an eager correctness oracle: the standalone sparse runner validates the injected request-local selections on the host and rebuilds each request's logical cache with Python loops, neither of which is graph-capturable. Capturing would require rewriting the runner into a static-buffer form that no longer matches its role. Graph coverage of the DSA decode kernel is exercised at the model level, not by this backend oracle. I added a code comment making the exclusion explicit; happy to file a follow-up if you'd like graph coverage added here.

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.

Please add a TODO here, let's try to add it in a follow-up PR

Comment thread tests/unittest/_torch/attention/backend_case.py Outdated
Comment thread tests/unittest/_torch/attention/backend_case.py Outdated
Comment thread tests/unittest/_torch/attention/model_attn_config.py Outdated
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59376 [ run ] completed with state SUCCESS. Commit: b3238f5
/LLM/main/L0_MergeRequest_PR pipeline #47850 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59435 [ run ] triggered by Bot. Commit: 108df3f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59435 [ run ] completed with state SUCCESS. Commit: 108df3f
/LLM/main/L0_MergeRequest_PR pipeline #47904 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@yihwang-nv
yihwang-nv marked this pull request as ready for review July 15, 2026 15:05
@yihwang-nv
yihwang-nv requested a review from a team as a code owner July 15, 2026 15:06
@yihwang-nv
yihwang-nv requested review from PerkzZheng and yunruis July 15, 2026 15:06
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

VanillaAttention now supports DSA sparse MLA with paged latent-cache handling, sparse selection routing, selected-token attention, and contiguous cache writes. The attention test harness adds sparse configuration, cache execution, deterministic inputs, capability checks, and Vanilla-versus-TRTLLM comparisons.

Changes

DSA sparse MLA support

Layer / File(s) Summary
Sparse configuration and sweep generation
tests/unittest/_torch/attention/model_attn_config.py, tests/unittest/_torch/attention/backend_capability.py, tests/unittest/_torch/attention/test_attention_backends.py
The harness defines DSA sparse configuration, enables Vanilla sparse capability, validates TRTLLM hardware requirements, and generates sparse context, generation, and mixed cases.
Vanilla sparse MLA execution
tensorrt_llm/_torch/attention_backend/vanilla.py, tensorrt_llm/_torch/attention_backend/sparse/registry.py, tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
VanillaAttention materializes NHD or HND latent caches, validates sparse inputs, performs selected-token attention, routes DSA sparse requests, and uses contiguous dtype-reinterpreted cache copies. The registry dispatches DSA to VanillaAttention.
Sparse backend harness execution
tests/unittest/_torch/attention/backend_case.py
BackendCase generates causal selections and sparse MLA inputs, builds sparse cache managers, runs context and generation phases, checks cache updates and singleton outputs, applies sparse tolerances, and skips sparse CUDA-graph replay.
Sparse golden comparison tests
tests/unittest/_torch/attention/sparse/dsa/test_dsa_sparse_mla.py
The DSA test runs VanillaAttention and TRTLLM with deterministic selections, applies backend-specific RoPE and metadata handling, and compares phase and layer outputs.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BackendCase
  participant SparseKVCacheManager
  participant VanillaAttention
  participant TRTLLM
  BackendCase->>SparseKVCacheManager: create sparse paged cache
  BackendCase->>VanillaAttention: run sparse context and generation
  VanillaAttention->>SparseKVCacheManager: read and append latent cache
  BackendCase->>TRTLLM: run matching sparse phases
  BackendCase->>BackendCase: compare outputs and singleton oracle values
Loading

Possibly related PRs

Suggested reviewers: yunruis, cascade812, perkzzheng

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the feature: DSA sparse attention in the Vanilla backend. It follows the required ticket and type format.
Description check ✅ Passed The description explains the implementation, scope, dependency, and relevant test coverage. It does not include explicit PR Checklist confirmations, but the required technical content is mostly comple…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Comment thread tests/unittest/_torch/attention/backend_capability.py Outdated
Comment thread tests/unittest/_torch/attention/model_attn_config.py Outdated
Comment thread tests/unittest/_torch/attention/test_attention_backends.py Outdated
Comment thread tests/unittest/_torch/attention/test_attention_backends.py Outdated
Comment thread tests/unittest/_torch/attention/test_attention_backends.py Outdated
Comment thread tests/unittest/_torch/attention/test_attention_backends.py Outdated
Comment thread tests/unittest/_torch/attention/test_attention_backends.py Outdated
Comment thread tests/unittest/_torch/attention/test_attention_backends.py Outdated
@yihwang-nv
yihwang-nv requested a review from a team as a code owner July 16, 2026 05:02
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #67030 [ run ] completed with state FAILURE. Commit: 743f93d
/LLM/main/L0_MergeRequest_PR pipeline #54578 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

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #67323 [ run ] triggered by Bot. Commit: 743f93d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #67323 [ run ] completed with state SUCCESS. Commit: 743f93d
/LLM/main/L0_MergeRequest_PR pipeline #54844 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68108 [ run ] triggered by Bot. Commit: ba1eec2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #68108 [ run ] completed with state SUCCESS. Commit: ba1eec2
/LLM/main/L0_MergeRequest_PR pipeline #55555 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

Comment thread tensorrt_llm/_torch/attention_backend/sparse/dsa/vanilla_backend.py Outdated

@mikeiovine mikeiovine 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.

Stamp on behalf of runtime devs; delegating review to @NVIDIA/trt-llm-torch-attention-devs

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69658 [ run ] triggered by Bot. Commit: ccd78c3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69658 [ run ] completed with state FAILURE. Commit: ccd78c3
/LLM/main/L0_MergeRequest_PR pipeline #56962 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

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69800 [ run ] triggered by Bot. Commit: ccd78c3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69800 [ run ] completed with state SUCCESS. Commit: ccd78c3
/LLM/main/L0_MergeRequest_PR pipeline #57094 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71968 [ run ] triggered by Bot. Commit: 715f6c8 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71968 [ run ] completed with state FAILURE. Commit: 715f6c8
/LLM/main/L0_MergeRequest_PR pipeline #59029 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

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71981 [ run ] triggered by Bot. Commit: 7a510e9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71981 [ run ] completed with state SUCCESS. Commit: 7a510e9
/LLM/main/L0_MergeRequest_PR pipeline #59042 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

Signed-off-by: Yihan Wang <yihwang@nvidia.com>
@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72100 [ run ] triggered by Bot. Commit: 0e9a9b8 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72100 [ run ] completed with state FAILURE. Commit: 0e9a9b8
/LLM/main/L0_MergeRequest_PR pipeline #59151 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

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72146 [ run ] triggered by Bot. Commit: 0e9a9b8 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72146 [ run ] completed with state SUCCESS. Commit: 0e9a9b8
/LLM/main/L0_MergeRequest_PR pipeline #59190 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants