Skip to content

[TRTLLM-11875][feat] MambaCacheManager based on KVCacheManagerV2 & add multi-turn chat optimized reuse#15653

Closed
VALLIS-NERIA wants to merge 5 commits into
NVIDIA:mainfrom
VALLIS-NERIA:v2kv_mamba
Closed

[TRTLLM-11875][feat] MambaCacheManager based on KVCacheManagerV2 & add multi-turn chat optimized reuse#15653
VALLIS-NERIA wants to merge 5 commits into
NVIDIA:mainfrom
VALLIS-NERIA:v2kv_mamba

Conversation

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator

Summary

This PR adds V2 Mamba SSM state snapshot reuse support, including saving partial tail snapshots and reusing them for longer prompts with the same prefix.

Key changes:

  • Add KvCacheConfig.mamba_save_last_snapshot and propagate it through runtime and compatibility config surfaces.
  • Extend V2 KV cache/runtime state handling so Mamba SSM/conv snapshots can be committed and reused at interval boundaries or prompt end.
  • Make V2 FORCE_CHUNK scheduling honor manager-provided expect_chunking_points and fail fast if they are missing.
  • Update repeat-shuffle accuracy tasks to warm reusable base prompts immediately before full prompts and still run normal accuracy scoring.
  • Add/extend unit and integration coverage for interval reuse, save-last snapshot reuse, and MTP block reuse.

Root Cause

V2 scheduling did not honor Mamba snapshot chunk boundaries, so live SSM state could be committed at the wrong semantic position. The integration test also warmed all base prompts before running all full prompts, which could evict reusable entries before they were checked.

Validation

  • python -m py_compile tensorrt_llm/_torch/pyexecutor/scheduler/scheduler_v2.py tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py tests/unittest/_torch/executor/test_kv_cache_v2_scheduler.py tests/unittest/_torch/executor/test_mamba_cache_manager.py tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py tests/integration/defs/accuracy/accuracy_core.py tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • pytest -q tests/unittest/_torch/executor/test_kv_cache_v2_scheduler.py::TestChunkedContext::test_force_chunk_uses_expected_chunking_points tests/unittest/_torch/executor/test_kv_cache_v2_scheduler.py::TestChunkedContext::test_force_chunk_requires_expected_chunking_points tests/unittest/_torch/executor/test_kv_cache_v2_scheduler.py::TestChunkedContext::test_force_chunk_uses_next_expected_chunking_point tests/unittest/_torch/executor/test_kv_cache_v2_scheduler.py::TestChunkedContext::test_force_chunk_allows_prompt_end_shorter_than_unit_size tests/unittest/_torch/executor/test_mamba_cache_manager.py::test_v2_hybrid_prepare_expect_chunking_points tests/unittest/_torch/executor/test_mamba_cache_manager.py::test_v2_hybrid_prepare_expect_chunking_points_save_last_only tests/unittest/_torch/executor/test_mamba_cache_manager.py::test_v2_hybrid_prepare_expect_chunking_points_clears_when_reuse_disabled tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py::TestSSMSupport::test_ssm_interval_snapshot_reuses_longer_prompt_prefix
  • pytest -q -s tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestQwen3_5_4B::test_fp8_block_reuse_interval_repeat_shuffle
    • GSM8K average accuracy: 80.023, threshold: 77.297
  • pytest -q -s tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestNemotronV3Super::test_nvfp4_4gpus_block_reuse[TEP4_ADP_MTP]
    • MMLU weighted average accuracy: 83.927, threshold: 83.313
    • GSM8K average accuracy: 92.077, threshold: 88.677
    • Logs confirmed V2 block reuse hits with MTP enabled.

@VALLIS-NERIA VALLIS-NERIA changed the title [None][feat] support V2 Mamba state snapshot reuse [None][feat] MambaCacheManager based on KVCacheManagerV2 & add multi-turn chat optimized reuse Jun 29, 2026
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot help

@github-actions

Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot --help

@github-actions

Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --gpu-type B200

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56312 [ run ] triggered by Bot. Commit: f204c72 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56312 [ run ] completed with state FAILURE. Commit: f204c72
/LLM/main/L0_MergeRequest_PR pipeline #45164 (Partly Tested) 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

@VALLIS-NERIA VALLIS-NERIA changed the title [None][feat] MambaCacheManager based on KVCacheManagerV2 & add multi-turn chat optimized reuse [TRTLLM-11875][feat] MambaCacheManager based on KVCacheManagerV2 & add multi-turn chat optimized reuse Jun 30, 2026
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler_v2.py Outdated
Comment thread tensorrt_llm/runtime/kv_cache_manager_v2/_core/_kv_cache.py Outdated
Comment thread tensorrt_llm/runtime/kv_cache_manager_v2/_core/_kv_cache.py Outdated
Comment thread tensorrt_llm/runtime/kv_cache_manager_v2/_core/_kv_cache.py Outdated
Comment thread tensorrt_llm/runtime/kv_cache_manager_v2/_block_radix_tree.py Outdated
Comment thread tensorrt_llm/serve/openai_server.py
nv-guomingz added a commit to nv-guomingz/TensorRT-LLM that referenced this pull request Jul 5, 2026
… (fork PR #1)

Supersedes the previous PR NVIDIA#15653 squash with the updated v2kv_mamba
branch from #1:
- V2 Mamba state snapshot reuse (updated after upstream review)
- Fix KV cache v2 test request mocks
- Fix V2 page table roles for Mamba pools
- Support V2 Mamba hybrid cache in disagg

Also carries the upstream main commits pulled in by the v2kv_mamba
merge: DSv4 follow-up runtime KV and cache foundations (NVIDIA#15633),
DeepGEMM and MegaMoE (NVIDIA#15632), and _is_effective_dynamic_tree fix
(NVIDIA#15842).

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
VALLIS-NERIA pushed a commit to VALLIS-NERIA/TensorRT-LLM that referenced this pull request Jul 6, 2026
… (fork PR #1)

Supersedes the previous PR NVIDIA#15653 squash with the updated v2kv_mamba
branch from nv-guomingz#1:
- V2 Mamba state snapshot reuse (updated after upstream review)
- Fix KV cache v2 test request mocks
- Fix V2 page table roles for Mamba pools
- Support V2 Mamba hybrid cache in disagg

Also carries the upstream main commits pulled in by the v2kv_mamba
merge: DSv4 follow-up runtime KV and cache foundations (NVIDIA#15633),
DeepGEMM and MegaMoE (NVIDIA#15632), and _is_effective_dynamic_tree fix
(NVIDIA#15842).

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
@VALLIS-NERIA
VALLIS-NERIA force-pushed the v2kv_mamba branch 5 times, most recently from 9340fe0 to 81a22bc Compare July 10, 2026 08:01
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --gpu-type B200 --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58647 [ run ] triggered by Bot. Commit: 13917c1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58647 [ run ] completed with state SUCCESS. Commit: 13917c1
/LLM/main/L0_MergeRequest_PR pipeline #47236 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

@VALLIS-NERIA VALLIS-NERIA left a comment

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.

The V2 Mamba path contains replay-state corruption and a deterministic state-index buffer crash, while several supported configurations either lose reuse behavior or fail during startup. These issues prevent the patch from being considered correct despite the focused unit tests passing.

One additional finding applies to unpushed local commit 032279800f and therefore cannot yet be anchored to the current GitHub diff:

[P2] Restore the GPU-only fallback after host-cache setup failuretensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py:891

When a host cache tier is configured and host allocation or cuMemHostRegister fails because of memory or memlock limits, KVCacheManagerPy still raises CuError/OutOfMemoryError. The removed handling retried with GPU-only tiers, whereas this direct construction now aborts model startup. Retain the fallback for configurations where the optional host tier cannot be initialized.

Comment thread tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py Outdated
Comment thread tensorrt_llm/serve/openai_server.py
Comment thread tensorrt_llm/llmapi/llm_args.py
Comment thread tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py Outdated
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58894 [ run ] triggered by Bot. Commit: 6981cac Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58894 [ run ] completed with state SUCCESS. Commit: 6981cac
/LLM/main/L0_MergeRequest_PR pipeline #47435 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: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
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.

2 participants