Repository navigation
[None][feat] Add CSA2 Vanilla sparse attention - #20431
yihwang-nv wants to merge 6 commits into
Conversation
Signed-off-by: Yihan Wang <yihwang@nvidia.com>
Signed-off-by: Yihan Wang <yihwang@nvidia.com>
Signed-off-by: Yihan Wang <yihwang@nvidia.com>
Preserve the independent DSA Vanilla backend and its regression coverage. Reconcile the indexer test helper with upstream and limit signature exclusions to optional non-DSA modes. Signed-off-by: yihwang-nv <yihwang@nvidia.com>
Share phase, score, TopK mapping, and latent-cache helpers while preserving the independent PyTorch reference. Document quantization and cache contracts, improve input validation, and move kernel-only reference adapters into test utilities. Trim redundant tests while retaining quantized Q projection and generation RoPE/cache ownership coverage. Validation on umbriel-b200-043 (B200): 1305 passed, 4 existing skips, 0 failed. Ruff lint, formatting, and diff checks passed. Signed-off-by: yihwang-nv <yihwang@nvidia.com>
Add CSA2VanillaAttention and CSA2VanillaIndexer, a pure-PyTorch golden of CSA2 sparse attention: sliding-window and compressed-group cache writes, candidate publication, exact top-k selection inside the published candidates, and sink attention over the window plus selected rows. Geometry comes from request lengths and the cache manager's host page lists, never from the kernel-produced slot or page tables. Tests cover the golden on CPU tensors with hand-derived values and compare it with the TRTLLM backend on SM100. Move the RoPE and phase helpers shared with the DSA golden into sparse/_vanilla_utils.py. Signed-off-by: yihwang-nv <yihwang@nvidia.com>
|
@farazkh80, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~ Assignment explanation
Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once. |
farazkh80
left a comment
There was a problem hiding this comment.
Approved from attention perspective, with two questions (non-blocking).
| swa_slots, | ||
| state.swa_kv, | ||
| "swa", | ||
| state.swa_transform, |
There was a problem hiding this comment.
main_transform and index_transform RoPE positions are checked against the golden's geometry, but swa_transform isn't. A wrong SWA position would match in both golden and TRTLLM.
Same check apply to swa_transform?
| if query_start < batch.num_ctx_tokens < end: | ||
| raise ValueError("CSA2 query tiles must not cross the context/generation boundary") | ||
| if query_start == 0: | ||
| self._enter_layer(source, layer) |
There was a problem hiding this comment.
_enter_layer runs before the write-time checks. After a rejection, a retry on the same metadata fails with "cannot be reused" instead of the real error.
Should we move it after those checks?
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
Dev Engineer Review
vanilla.py. It does not change runtime behavior.QA Engineer Review
No test changes.
Per-File QA Perspective
tensorrt_llm/_torch/attention/backends/vanilla.py: Import formatting only. No QA behavior change to verify.Depends on #16309. Only the last commit belongs to this PR.
Description
CSA2VanillaAttentionand a weightlessCSA2VanillaIndexer(tensorrt_llm/_torch/attention/backends/sparse/csa2/vanilla_backend.py), a pure-PyTorch golden reference for CSA2 sparse attention:kv_lens_cuda - seq_lensand pages from the cache manager's host page lists. The golden never reads the kernel-produced slot tables, page tables or visible lengths.sparse/_vanilla_utils.py(pure move; thephase_is_generationerror now says "Sparse MLA requires…" instead of "DSA requires…", andDSAVanillaEmbeddingis no longer listed in the DSA golden's__all__).Scope: the sparse registry and the CSA2 module are unchanged, so
attn_backend="VANILLA"still raises forcsa2(the module buildscreate_attention("TRTLLM", ...)). Tests construct the golden directly; plumbing the configured backend into the module is a separate change. Like the other Vanilla goldens, it rejects CUDA graph capture.Test Coverage
tests/unittest/_torch/attention/sparse/csa2/test_vanilla_backend.py:Results on B200:
pytest tests/unittest/_torch/attention/sparse/csa2/test_vanilla_backend.py— 18 passed (3 consecutive runs).pytest tests/unittest/_torch/attention/sparse/csa2(existing tests) — 592 passed, 12 skipped.pytest tests/unittest/_torch/attention/sparse/dsa/test_dsa_sparse_mla.py(shared helper move) — 16 passed.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.