Skip to content

[None][feat] Integrate KVCMv2 commit_min_snapshot in runtime - #16185

Merged
jiaganc merged 2 commits into
NVIDIA:mainfrom
jiaganc:codex/integrate-commit-min-snapshot-main
Jul 14, 2026
Merged

[None][feat] Integrate KVCMv2 commit_min_snapshot in runtime#16185
jiaganc merged 2 commits into
NVIDIA:mainfrom
jiaganc:codex/integrate-commit-min-snapshot-main

Conversation

@jiaganc

@jiaganc jiaganc commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added support for configuring partial KV-cache reuse.
    • Improved block-reuse behavior so eligible partial context blocks can be committed.
    • Added policy-aware snapshot commit handling for cache reuse configurations.
  • Bug Fixes
    • Corrected propagation of cache reuse settings across supported cache managers.
  • Tests
    • Expanded coverage for partial reuse, block-reuse policies, snapshot commits, and SSM configurations.

Description

Integrate commit_min_snapshot support for SSM reuse from #15752 and connect it to the KV cache manager V2 block-reuse policies.

The cache manager now commits a minimal SSM snapshot when block reuse is enabled for policies other than all_reusable, propagates partial-reuse configuration, and handles the final context commit path. The change includes coverage for SSM/SWA reuse, partial-page commits, cache statistics, DeepSeek V4 sparse cache configuration, and V2 reuse-policy selection.

Test Coverage

  • Pre-commit hooks passed for both commits.
  • python3 -m py_compile passed for the directly modified Python implementation and test files.
  • Targeted pytest files were not run locally because the current environment does not have pytest installed.

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-compatible or api-breaking. For api-breaking, include BREAKING in 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.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@jiaganc jiaganc changed the title [None][feat] Add commit min snapshot for SSM reuse [None][feat] Integrate KVCMv2 commit_min_snapshot in runtime Jul 9, 2026
@jiaganc

jiaganc commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

This PR depends on #15752 and should wait for it to be merged first.

Signed-off-by: Jiagan Cheng <jiaganc@nvidia.com>
@jiaganc
jiaganc force-pushed the codex/integrate-commit-min-snapshot-main branch from 52fe3a7 to 2a525b0 Compare July 13, 2026 06:46
@jiaganc
jiaganc marked this pull request as ready for review July 13, 2026 06:54
@jiaganc
jiaganc requested review from a team as code owners July 13, 2026 06:54
@jiaganc
jiaganc requested a review from yuxianq July 13, 2026 06:54
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

KV cache reuse behavior

Layer / File(s) Summary
Cache configuration propagation
tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py, tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py, tests/unittest/_torch/attention/sparse/deepseek_v4/test_deepseek_v4_cache_manager.py, tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py, tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_stats_behavior.py
Cache configuration builders propagate enable_partial_reuse and derive commit_min_snapshot from block-reuse policy, with DeepSeek V4, SSM, and V2 propagation tests.
Partial block commit behavior
tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py, tests/unittest/_torch/executor/test_kv_cache_manager_v2.py, tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_stats_behavior.py
Commit tests cover delayed commits, partial final context chunks, committed-token counts, history length, and reuse-token lengths under different policies.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: qijune, joyang-nv, arysef, tburt-nv

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title is concise and clearly reflects the main change: adding commit_min_snapshot support to KVCMv2 runtime.
Description check ✅ Passed The description follows the template with Description, Test Coverage, and PR Checklist sections and gives relevant implementation and testing details.
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: 1

🧹 Nitpick comments (3)
tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py (1)

2739-2762: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

TODO is a legitimate, self-scoped perf follow-up — not blocking.

The is_end=True TODO matches the commit()/_KVCache semantics shown in context (partial-block "move vs copy" on final chunk), so this is purely a performance optimization for disaggregated-prefill, not a correctness gap. Fine to defer.

Happy to draft the is_end=True wiring for the last context chunk (using request.context_remaining_length == 0) if you'd like to pick this up now rather than later — let me know.

🤖 Prompt for 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.

In `@tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py` around lines 2739 -
2762, No code change is required; retain the existing TODO in try_commit_blocks.
Treat is_end=True wiring for the final disaggregated-prefill context chunk as a
deferred performance follow-up, preserving the current kv_cache.commit(tokens)
behavior.
tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py (1)

1524-1586: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Coverage gap: no test exercises KVCacheManagerV2._build_cache_config's commit_min_snapshot formula against a manager that actually has SSM layers.

TestSSMSupport._make_ssm_config constructs KVCacheManagerConfig by hand and passes commit_min_snapshot explicitly, so it never goes through the real _build_cache_config computation added in this PR. Given the concern raised on tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py (lines 1545-1559) about enable_block_reuse=False + SSM layers potentially violating the commit_min_snapshot invariant, this file would be the natural place to add a regression test (e.g. build a manager subclass with SSM layers via _build_cache_config, set enable_block_reuse=False, and assert construction either raises clearly or is handled). Coverage here is currently insufficient for that interaction and should be added either in this PR or as an explicit follow-up in tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py.

🤖 Prompt for 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.

In `@tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py` around
lines 1524 - 1586, Add a regression test in TestSSMSupport that exercises
KVCacheManagerV2._build_cache_config with SSM layers and
enable_block_reuse=False, rather than relying on _make_ssm_config’s explicitly
supplied commit_min_snapshot. Assert the construction behavior required by the
invariant—either a clear error is raised or the configuration is handled
correctly—and preserve existing SSM test setup and teardown.

Source: Path instructions

tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py (1)

939-955: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Extract the shared commit_min_snapshot predicate
This is duplicated in pyexecutor/kv_cache_manager_v2.py and here; a small shared helper on KVCacheManagerV2 would keep future subclasses consistent.

🤖 Prompt for 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.

In `@tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py`
around lines 939 - 955, Extract the duplicated commit_min_snapshot predicate
into a shared helper on KVCacheManagerV2, then update the configuration
construction here and in pyexecutor/kv_cache_manager_v2.py to call that helper.
Preserve the existing condition based on enable_block_reuse and
block_reuse_policy.
🤖 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
`@tests/unittest/_torch/attention/sparse/deepseek_v4/test_deepseek_v4_cache_manager.py`:
- Around line 38-49: Update the BlockReusePolicy import in the DeepSeek V4 cache
manager test to import it from
tensorrt_llm._torch.pyexecutor.kv_cache_manager_v2 instead of resource_manager,
leaving the other imports unchanged.

---

Nitpick comments:
In `@tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py`:
- Around line 939-955: Extract the duplicated commit_min_snapshot predicate into
a shared helper on KVCacheManagerV2, then update the configuration construction
here and in pyexecutor/kv_cache_manager_v2.py to call that helper. Preserve the
existing condition based on enable_block_reuse and block_reuse_policy.

In `@tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py`:
- Around line 2739-2762: No code change is required; retain the existing TODO in
try_commit_blocks. Treat is_end=True wiring for the final disaggregated-prefill
context chunk as a deferred performance follow-up, preserving the current
kv_cache.commit(tokens) behavior.

In `@tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py`:
- Around line 1524-1586: Add a regression test in TestSSMSupport that exercises
KVCacheManagerV2._build_cache_config with SSM layers and
enable_block_reuse=False, rather than relying on _make_ssm_config’s explicitly
supplied commit_min_snapshot. Assert the construction behavior required by the
invariant—either a clear error is raised or the configuration is handled
correctly—and preserve existing SSM test setup and teardown.
🪄 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: 504a6fa7-9b10-4b22-9c23-24ef87a47e3a

📥 Commits

Reviewing files that changed from the base of the PR and between 17190cf and 2a525b0.

📒 Files selected for processing (6)
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py
  • tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py
  • tests/unittest/_torch/attention/sparse/deepseek_v4/test_deepseek_v4_cache_manager.py
  • tests/unittest/_torch/executor/test_kv_cache_manager_v2.py
  • tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py
  • tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_stats_behavior.py

Signed-off-by: Jiagan Cheng <jiaganc@nvidia.com>
@jiaganc

jiaganc commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58925 [ run ] triggered by Bot. Commit: 77134d3 Link to invocation

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

attention part LGTM

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58925 [ run ] completed with state SUCCESS. Commit: 77134d3
/LLM/main/L0_MergeRequest_PR pipeline #47460 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

@jiaganc

jiaganc commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58993 [ run ] triggered by Bot. Commit: 77134d3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58993 [ run ] completed with state SUCCESS. Commit: 77134d3
/LLM/main/L0_MergeRequest_PR pipeline #47523 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

@jiaganc

jiaganc commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59084 [ run ] triggered by Bot. Commit: 77134d3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59084 [ run ] completed with state SUCCESS. Commit: 77134d3
/LLM/main/L0_MergeRequest_PR pipeline #47599 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

@jiaganc

jiaganc commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59113 [ run ] triggered by Bot. Commit: 77134d3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59113 [ run ] completed with state SUCCESS. Commit: 77134d3
/LLM/main/L0_MergeRequest_PR pipeline #47625 completed with status: 'SUCCESS'

CI Report

Link to invocation

@juney-nvidia
juney-nvidia requested a review from yizhang-nv July 14, 2026 06:59

@yizhang-nv yizhang-nv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jiaganc
jiaganc enabled auto-merge (squash) July 14, 2026 08:12
@jiaganc
jiaganc disabled auto-merge July 14, 2026 09:36
@jiaganc
jiaganc merged commit 3249f03 into NVIDIA:main Jul 14, 2026
8 checks passed
@jiaganc
jiaganc deleted the codex/integrate-commit-min-snapshot-main branch July 21, 2026 03:03
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