Skip to content

[TRTLLM-11875][feat] Support fine-grained context chunk management#16427

Open
VALLIS-NERIA wants to merge 12 commits into
NVIDIA:mainfrom
VALLIS-NERIA:agent/mamba-scheduling-disagg-lifecycle
Open

[TRTLLM-11875][feat] Support fine-grained context chunk management#16427
VALLIS-NERIA wants to merge 12 commits into
NVIDIA:mainfrom
VALLIS-NERIA:agent/mamba-scheduling-disagg-lifecycle

Conversation

@VALLIS-NERIA

@VALLIS-NERIA VALLIS-NERIA commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added snapshot-aware context chunking to align processing with recurrent-state snapshot points.
    • Exposed expected snapshot points through the Python request interface.
    • Improved cache reuse scheduling across hybrid model execution.
  • Bug Fixes

    • Improved chunk sizing under context and compute-capacity limits.
    • Corrected KV-head selection when earlier layers report zero heads.
    • Added validation for incompatible hybrid cache transceiver configurations.
    • Improved cache buffer sizing and alignment for FlashMLA setups.

Description

This PR has two goals:

  1. Fix several independent KV-cache correctness issues.
  2. Add expect_snapshot_points as the manager-to-scheduler contract and move the existing C++ Mamba interval-reuse chunking onto that contract.

Snapshot-aware context chunking

  • Store expect_snapshot_points on the C++ request object and expose it through nanobind, so the C++ and Python schedulers share the same per-request field.
  • Have CppMambaHybridCacheManager publish regular states_snapshot_interval boundaries before scheduling when block reuse is enabled. Prompt end remains the implicit final boundary.
  • Make the C++ MicroBatchScheduler, Python PyMicroBatchScheduler, and KVCacheV2Scheduler honor these absolute boundaries under FORCE_CHUNK.
  • Preserve the existing fallback for requests without snapshot points and block-align capacity and max-context truncation.
  • Add focused C++ and Python coverage for interval publication, successive boundaries, prompt-end handling, and capacity truncation.

KV-cache fixes

  • Calculate the default max_tokens_in_buffer only after the effective tokens_per_block is known, including the FlashMLA override, and round it up to a block boundary.
  • Publish the first non-zero per-layer KV-head count in hybrid-model RankInfo, because layer 0 may be a linear-attention layer with no KV heads.
  • Reject MixedMambaHybridCacheManager with a non-Python transceiver runtime, since its separately managed attention-KV and Mamba-state pools require the Python routing path.

This PR does not add the V2 Mamba cache manager, save-last reuse, or V2 Mamba disaggregated transfer.

Test Coverage

  • Full native rebuild for SM100 and SM103
  • C++ ForceChunkTest.*: 15 passed
  • Python TestForceChunkPolicy: 14 passed
  • Focused interval, KV-cache buffer, hybrid RankInfo, and runtime-guard tests: 13 passed
  • Mixed Mamba Python transceiver coverage across all 8 dtype combinations, plus runtime guards: 10 passed
  • Native request snapshot-point default, assignment, and copy probe
  • Complete pre-commit hook set

PR Checklist

  • Please check this after reviewing the above items as appropriate for this PR.

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59453 [ run ] triggered by Bot. Commit: 7014727 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Author notes explaining the purpose and scope of each production change block and its focused regression coverage.

Comment thread tensorrt_llm/_torch/pyexecutor/llm_request.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/py_executor.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler.py
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler_v2.py
Comment thread tensorrt_llm/_torch/pyexecutor/resource_manager.py Outdated
Comment thread tests/unittest/_torch/executor/test_py_scheduler.py
Comment thread tests/unittest/_torch/executor/test_kv_cache_v2_scheduler.py
Comment thread tests/unittest/_torch/executor/test_resource_manager.py Outdated
Comment thread tests/unittest/_torch/executor/test_disagg_index_mapper_early_release.py Outdated
Comment thread tests/unittest/others/test_kv_cache_transceiver.py Outdated
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>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA
VALLIS-NERIA force-pushed the agent/mamba-scheduling-disagg-lifecycle branch from 7014727 to 5a5b53d Compare July 16, 2026 07:42
@VALLIS-NERIA VALLIS-NERIA changed the title [None][fix] Harden scheduling and disaggregated transfer lifecycle [None][feat] Support fine-grained context chunk management Jul 16, 2026
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59667 [ run ] triggered by Bot. Commit: 5a5b53d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59667 [ run ] completed with state FAILURE. Commit: 5a5b53d
/LLM/main/L0_MergeRequest_PR pipeline #48100 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>
Comment thread tensorrt_llm/_torch/pyexecutor/llm_request.py Outdated
Comment thread tests/unittest/_torch/executor/test_disagg_index_mapper_early_release.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/kv_cache_transceiver.py Outdated
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/scheduler.py
Comment thread tensorrt_llm/_torch/pyexecutor/py_executor.py
@VALLIS-NERIA
VALLIS-NERIA marked this pull request as ready for review July 16, 2026 12:25
@VALLIS-NERIA
VALLIS-NERIA requested review from a team as code owners July 16, 2026 12:25
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59725 [ run ] triggered by Bot. Commit: 85bb37f Link to invocation

@VALLIS-NERIA VALLIS-NERIA changed the title [None][feat] Support fine-grained context chunk management [TRTLLM-11875][feat] Support fine-grained context chunk management Jul 16, 2026
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59738 [ run ] triggered by Bot. Commit: 605d535 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59725 [ run ] completed with state ABORTED. Commit: 85bb37f

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59738 [ run ] completed with state FAILURE. Commit: 605d535
/LLM/main/L0_MergeRequest_PR pipeline #48164 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

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59811 [ run ] triggered by Bot. Commit: f0f16f2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59823 [ run ] triggered by Bot. Commit: f0f16f2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59850 [ run ] triggered by Bot. Commit: f0f16f2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59883 [ run ] triggered by Bot. Commit: f0f16f2 Link to invocation

@BowenFu BowenFu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — the fine-grained context-chunk changes preserve the existing default scheduling path: the FORCE_CHUNK capacity-overflow now rounds down to a unit boundary (equivalent to the prior zeroing since chunkSize <= unit), and the mamba snapshot-range addition is a no-op boundary for existing configs. Core scheduler change, but existing behavior is unchanged.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59897 [ run ] triggered by Bot. Commit: f0f16f2 Link to invocation

@Shixiaowei02
Shixiaowei02 requested a review from bo-nv July 17, 2026 06:05
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59966 [ run ] triggered by Bot. Commit: f0f16f2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59966 [ run ] completed with state SUCCESS. Commit: f0f16f2
/LLM/main/L0_MergeRequest_PR pipeline #48360 completed with status: 'SUCCESS'

CI Report

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.

5 participants