Skip to content

[None][fix] disagg-gen-init: pass context_current_position as history… - #14377

Merged
Tabrizian merged 1 commit into
NVIDIA:feat/deepseek_v4from
Tabrizian:user/itabrizian/fix-disagg-gen-init-history-length
May 21, 2026
Merged

[None][fix] disagg-gen-init: pass context_current_position as history…#14377
Tabrizian merged 1 commit into
NVIDIA:feat/deepseek_v4from
Tabrizian:user/itabrizian/fix-disagg-gen-init-history-length

Conversation

@Tabrizian

@Tabrizian Tabrizian commented May 20, 2026

Copy link
Copy Markdown
Member

Description

The V2 scheduler's _try_schedule_disagg_gen_init was passing req.context_remaining_length as history_length to kv_cache_manager.resize_context. That field is the prompt suffix still to be processed, not the historic prefix already in the cache.

When GEN-side block reuse hits a long matching prefix, prepare_context sets req.context_current_position to the number of reused tokens and the cache's _history_length to the same value. The subsequent resize_context(..., history_length=req.context_remaining_length) then violates the "history length cannot be decreased" invariant in
_KVCache.resize() and aborts the GEN event loop.

Pass req.context_current_position instead, matching the cache's established history boundary in both reuse-hit and reuse-miss paths. The block comment above the call already states the right intent ("Prompt is already historic ... history_length so SWA layers skip pre-window block allocation"); only the field was wrong.

Reproduced on DSV4-Pro disagg smoke (1×CTX TEP8 + 1×GEN TEP8 on GB300, concurrency 2). With this fix the GEN side no longer raises "History length cannot be decreased".

@coderabbitai summary

Description

Test Coverage

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.

…_length

The V2 scheduler's `_try_schedule_disagg_gen_init` was passing
`req.context_remaining_length` as `history_length` to
`kv_cache_manager.resize_context`. That field is the prompt
suffix still to be processed, not the historic prefix already
in the cache.

When GEN-side block reuse hits a long matching prefix,
`prepare_context` sets `req.context_current_position` to the
number of reused tokens and the cache's `_history_length` to the
same value. The subsequent `resize_context(...,
history_length=req.context_remaining_length)` then violates the
"history length cannot be decreased" invariant in
`_KVCache.resize()` and aborts the GEN event loop.

Pass `req.context_current_position` instead, matching the cache's
established history boundary in both reuse-hit and reuse-miss
paths. The block comment above the call already states the right
intent ("Prompt is already historic ... history_length so SWA
layers skip pre-window block allocation"); only the field was
wrong.

Reproduced on DSV4-Pro disagg smoke (1×CTX TEP8 + 1×GEN TEP8 on
GB300, concurrency 2). With this fix the GEN side no longer
raises "History length cannot be decreased".

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
@Tabrizian
Tabrizian requested a review from a team as a code owner May 20, 2026 23:38
@Tabrizian
Tabrizian requested review from joyang-nv and removed request for a team May 20, 2026 23:38
@Tabrizian

Copy link
Copy Markdown
Member Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #49505 [ run ] triggered by Bot. Commit: 53c4151 Link to invocation

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

LGTM~

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #49505 [ run ] completed with state SUCCESS. Commit: 53c4151
/LLM/main/L0_MergeRequest_PR pipeline #39142 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Tabrizian
Tabrizian merged commit ff5d6f3 into NVIDIA:feat/deepseek_v4 May 21, 2026
10 of 11 checks passed
Shixiaowei02 added a commit to Shixiaowei02/TensorRT-LLM that referenced this pull request May 27, 2026
For a disagg gen init request entering the V2 scheduler,
context_current_position is still 0 — it is only advanced to
prompt_len in _prepare_disagg_gen_transmission_complete after KV
transfer completes. Passing history_length=context_current_position
degenerates to history_length=0, the SWA stale range collapses to an
empty interval, and pre-window blocks are still allocated before KV
transfer — defeating the over-allocation fix from NVIDIA#13845/NVIDIA#14377.

Use req.prompt_len, which is known statically at scheduler time and
correctly conveys that the entire prompt is history.

Signed-off-by: Shixiaowei02 <39303645+Shixiaowei02@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 10, 2026
NVIDIA#14377)

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 11, 2026
NVIDIA#14377)

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
NVIDIA#14377)

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants