Skip to content

[None][feat] Add paged KV cache support to Vanilla attention - #16714

Merged
yihwang-nv merged 5 commits into
NVIDIA:mainfrom
yihwang-nv:vanilla-paged-kv-cache
Aug 3, 2026
Merged

[None][feat] Add paged KV cache support to Vanilla attention#16714
yihwang-nv merged 5 commits into
NVIDIA:mainfrom
yihwang-nv:vanilla-paged-kv-cache

Conversation

@yihwang-nv

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

Copy link
Copy Markdown
Collaborator

Summary

  • add multi-page paged KV cache reads and writes for Vanilla attention
  • honor the configured tokens_per_block in the production PyTorch executor
  • preserve BAD_PAGE_INDEX logical holes for KVCacheManagerV2 sliding-window eviction

Testing

  • B200, Docker: 6 affected tests passed
  • H100, Docker: 6 affected tests passed
  • pre-commit and DCO hooks passed

Dev Engineer Review

  • Vanilla attention now supports paged KV-cache reads and writes across multiple blocks, including BAD_PAGE_INDEX holes and sliding-window eviction.
  • Production PyTorch execution preserves the configured tokens_per_block for the VANILLA backend.
  • Writes to invalid pages are guarded, and inconsistent block metadata fails explicitly.
  • No public API changes or configuration/test-list changes were identified.

QA Engineer Review

  • Added test_kv_cache_manager_v2_sliding_window_eviction.
  • No corresponding test-db/ or qa/ registration was identified; CI coverage data is unavailable.
  • Verdict: needs follow-up.

Signed-off-by: Yihan Wang <yihwang@nvidia.com>
@yihwang-nv
yihwang-nv requested review from a team as code owners July 22, 2026 06:54
@yihwang-nv
yihwang-nv requested a review from yuxianq July 22, 2026 06:55
@yihwang-nv yihwang-nv changed the title [None][feat] add paged KV cache support to Vanilla attention [None][feat] Add paged KV cache support to Vanilla attention Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 83aa2cd6-2766-4d01-aaf7-cd86990c3c36

📥 Commits

Reviewing files that changed from the base of the PR and between 4ccd3ab and ba6c506.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/attention_backend/vanilla.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/attention_backend/vanilla.py

Walkthrough

Vanilla attention now supports paged KV-cache reads and writes using per-request block IDs, including MLA latent gathering and invalid-page handling. Backend configuration and capabilities are updated, with a sliding-window eviction test added.

Changes

Vanilla paged KV-cache support

Layer / File(s) Summary
Paged cache update and materialization
tensorrt_llm/_torch/attention_backend/vanilla.py
Vanilla attention writes tokens across paged blocks, gathers logical K/V and MLA latent sequences, handles invalid pages, and propagates block ID lists through forward paths.
Paged backend configuration and validation
tensorrt_llm/_torch/pyexecutor/py_executor_creator.py, tests/unittest/_torch/attention/backend_capability.py, tests/unittest/_torch/attention/test_vanilla_attention.py
Vanilla preserves configured block sizing, advertises paged-cache support, and tests sliding-window eviction with KVCacheManagerV2.

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

Sequence Diagram(s)

sequenceDiagram
  participant VanillaAttention
  participant PagedKVCache
  participant ScaledDotProductAttention
  VanillaAttention->>PagedKVCache: write K/V tokens using block_ids
  VanillaAttention->>PagedKVCache: gather logical cached K/V tokens
  PagedKVCache-->>VanillaAttention: materialized K/V prefix
  VanillaAttention->>ScaledDotProductAttention: run attention over gathered K/V
Loading

Suggested labels: api-compatible

Suggested reviewers: kris1025

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title is concise, specific, and matches the main change to Vanilla attention.
Description check ✅ Passed Description includes Summary and Testing sections and covers the main change and validation steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/attention_backend/vanilla.py`:
- Around line 185-219: Update the write loop in _single_request_update_kv_cache
to validate each block_ids-derived blk before indexing kv_cache_tensor. If blk
equals BAD_PAGE_INDEX, fail loudly with the established error mechanism instead
of writing through negative indexing; preserve the existing cache-write behavior
for valid block indices.

In
`@tests/unittest/_torch/executor/test_py_executor_creator_flash_mla_tokens_per_block.py`:
- Around line 94-102: Replace the source-text regex assertion in
test_vanilla_preserves_configured_tokens_per_block with a behavioral test that
invokes create_py_executor, or the specific tokens_per_block resolution helper,
using attn_backend="VANILLA" and a configured page size. Assert that the
resulting tokens_per_block equals the configured value, and preserve the test’s
focus on preventing KV-cache linearization.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9f4d69e1-6301-4757-b329-ba82c76343d1

📥 Commits

Reviewing files that changed from the base of the PR and between 858fd17 and 4ccd3ab.

📒 Files selected for processing (5)
  • tensorrt_llm/_torch/attention_backend/vanilla.py
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
  • tests/unittest/_torch/attention/backend_capability.py
  • tests/unittest/_torch/attention/test_vanilla_attention.py
  • tests/unittest/_torch/executor/test_py_executor_creator_flash_mla_tokens_per_block.py
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/pyexecutor/py_executor_creator.py

Comment thread tensorrt_llm/_torch/attention_backend/vanilla.py
@yihwang-nv
yihwang-nv requested a review from wenmingw July 22, 2026 07:03
@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60922 [ run ] triggered by Bot. Commit: 4ccd3ab Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60922 [ run ] completed with state FAILURE. Commit: 4ccd3ab
/LLM/main/L0_MergeRequest_PR pipeline #49188 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 #61201 [ run ] triggered by Bot. Commit: 4ccd3ab Link to invocation

Comment thread tensorrt_llm/_torch/attention_backend/vanilla.py Outdated
…parsing test

- _single_request_update_kv_cache: assert the destination block is not
  BAD_PAGE_INDEX before writing, so an inconsistent block_ids/metadata fails
  loudly instead of silently writing the last page via negative indexing.
- _gather_paged_kv: the empty-slice (num_tokens<=0) path indexed block_ids[0],
  which may be BAD_PAGE_INDEX; index the always-valid block 0 instead.
- Remove test_vanilla_preserves_configured_tokens_per_block: a regex-on-source
  assertion is brittle; the paged behavior is covered by the attention sweep.

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 #61257 [ run ] triggered by Bot. Commit: ba6c506 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61201 [ run ] completed with state ABORTED. Commit: 4ccd3ab

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@yihwang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62756 [ run ] triggered by Bot. Commit: ac79815 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62756 [ run ] completed with state SUCCESS. Commit: ac79815
/LLM/main/L0_MergeRequest_PR pipeline #50887 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 #62804 [ run ] triggered by Bot. Commit: ac79815 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62804 [ run ] completed with state FAILURE. Commit: ac79815
/LLM/main/L0_MergeRequest_PR pipeline #50930 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 #62912 [ run ] triggered by Bot. Commit: ac79815 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62912 [ run ] completed with state SUCCESS. Commit: ac79815
/LLM/main/L0_MergeRequest_PR pipeline #51036 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 #62988 [ run ] triggered by Bot. Commit: f4a8696 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62988 [ run ] completed with state SUCCESS. Commit: f4a8696
/LLM/main/L0_MergeRequest_PR pipeline #51096 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 #63279 [ run ] triggered by Bot. Commit: f4a8696 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63279 [ run ] completed with state DISABLED
Pipeline is freezed and top-1 instance is under maintenance. For urgent request, contact Yiteng Niu

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 #63333 [ run ] triggered by Bot. Commit: f4a8696 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63333 [ run ] completed with state SUCCESS. Commit: f4a8696
/LLM/main/L0_MergeRequest_PR pipeline #51328 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 #63366 [ run ] triggered by Bot. Commit: f4a8696 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63366 [ run ] completed with state SUCCESS. Commit: f4a8696
/LLM/main/L0_MergeRequest_PR pipeline #51353 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yihwang-nv
yihwang-nv enabled auto-merge (squash) August 3, 2026 06:47
Comment thread tensorrt_llm/_torch/pyexecutor/py_executor_creator.py
@yihwang-nv
yihwang-nv merged commit ea39429 into NVIDIA:main Aug 3, 2026
8 checks passed
Comment thread tensorrt_llm/_torch/attention_backend/vanilla.py
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.

5 participants