Skip to content

[None][fix] Release stale-range holder after _commit_block in KVCache… - #14478

Merged
Tabrizian merged 3 commits into
NVIDIA:feat/deepseek_v4from
Tabrizian:user/imant/dsv4-kvcm-v2-stale-range-commit-fix
May 27, 2026
Merged

[None][fix] Release stale-range holder after _commit_block in KVCache…#14478
Tabrizian merged 3 commits into
NVIDIA:feat/deepseek_v4from
Tabrizian:user/imant/dsv4-kvcm-v2-stale-range-commit-fix

Conversation

@Tabrizian

@Tabrizian Tabrizian commented May 23, 2026

Copy link
Copy Markdown
Member

…ManagerV2

When _commit_block finalizes a block that is already inside stale_range[lc] for some finite-window lifecycle (e.g. DSv4 DSA / SWA), the freshly assigned holder (_PageHolder or _SharedPageLock from line 1268 / 1312-1325) was left in place. _check_sanity then asserted on the precondition of suspend():

/workspaces/tensorrt_llm/.../sampler.../suspend()
-> _kv_cache.py:931 assert self._check_sanity()
-> _kv_cache.py:1531 assert holder is None # for committed stale block

This trips deterministically on DSv4-Pro disagg GEN runs under MAX_UTILIZATION scheduling: when the V2 scheduler tries to suspend an in-flight request to make room, the precondition check aborts the worker. The previously-known release paths (_on_stop_committing, _unlock_stale_blocks) never revisit a committed-and-already-stale ordinal, so a 'commit-into-stale-range' case slipped through.

Fix: at the tail of _commit_block, for the committed block, iterate each non-SSM lifecycle and clear beam_block[lc] when the ordinal lies inside that lifecycle's stale_range. The committed page itself remains alive in the radix tree (committed pages are shareable across caches); only this _KVCache's redundant strong reference is dropped, restoring the 'committed AND stale -> holder is None' invariant.

Validated end-to-end on DSv4-Pro disagg sweep on Lyris GB300 (c=4/8/16/32/64, DEP8/TEP8): zero _check_sanity AssertionError across ~160k commit-into-stale events under real traffic.

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

@Tabrizian

Copy link
Copy Markdown
Member Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50027 [ run ] triggered by Bot. Commit: 7ebf4a5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50071 [ run ] triggered by Bot. Commit: 192787a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50071 [ run ] completed with state SUCCESS. Commit: 192787a
/LLM/main/L0_MergeRequest_PR pipeline #39626 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yizhang-nv
yizhang-nv requested a review from lowsfer May 25, 2026 05:29
@yizhang-nv

Copy link
Copy Markdown
Member

Could we add a focused regression UT for this state transition?

I locally reproduced the pre-fix failure on a B200 node with a minimal KVCacheManagerV2 sequence:

  1. create an SWA KV cache without scratch reuse,
  2. resize(capacity=N, history_length=0) to allocate real uncommitted pages,
  3. resize(capacity=N, history_length=N) so early SWA blocks become stale but are still held as _PageHolder for future commit,
  4. commit(tokens),
  5. suspend().

The observed state was:

  • after initial resize: block0/lc0 = _SharedPageLock
  • after advancing history length: block0/lc0 = _PageHolder
  • after commit: block0/lc0 was still _PageHolder
  • suspend() then failed in _check_sanity() at assert holder is None

So my read is that existing SWA tests cover the normal commit-before-stale path and the scratch-reuse path, but not this history-before-commit path. A focused test in tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py would make the intended "history length can advance before KV-cache-reuse commit" behavior explicit and should fail before this patch / pass after it.

Comment thread tensorrt_llm/runtime/kv_cache_manager_v2/_core/_kv_cache.py
@lowsfer

lowsfer commented May 25, 2026

Copy link
Copy Markdown
Member

For unit test, I think we can cover it by updating existing tests instead of creating a new one. We can add a parameter delay_commit to TestNoBatching.run_naive defaulting to False, then if True, only commit all tokens at end. And add that arg to TestNoBatching.test_naive().

Tabrizian added a commit to Tabrizian/TensorRT-LLM that referenced this pull request May 26, 2026
Address review comment on PR NVIDIA#14478: use the
life_cycles.attention_life_cycles() iterator (which already filters out
the SSM lifecycle) instead of items() + a manual ssm_life_cycle_id
guard, drop the redundant 'is not None' check (assigning None to None
is a no-op), and swap the loop nesting so the per-lifecycle stale-range
computation runs once per lifecycle rather than once per beam x
lifecycle.

Behavior is unchanged: for every committed seq_block whose ordinal sits
in the stale range of an attention lifecycle, the per-beam holder for
that lifecycle is released, restoring the
'committed AND stale -> holder is None' invariant that _check_sanity
expects in suspend().

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Tabrizian added 3 commits May 26, 2026 16:30
…ManagerV2

When _commit_block finalizes a block that is already inside stale_range[lc]
for some finite-window lifecycle (e.g. DSv4 DSA / SWA), the freshly assigned
holder (_PageHolder or _SharedPageLock from line 1268 / 1312-1325) was left
in place. _check_sanity then asserted on the precondition of suspend():

  /workspaces/tensorrt_llm/.../sampler.../suspend()
    -> _kv_cache.py:931 assert self._check_sanity()
    -> _kv_cache.py:1531 assert holder is None   # for committed stale block

This trips deterministically on DSv4-Pro disagg GEN runs under MAX_UTILIZATION
scheduling: when the V2 scheduler tries to suspend an in-flight request to
make room, the precondition check aborts the worker. The previously-known
release paths (_on_stop_committing, _unlock_stale_blocks) never revisit a
committed-and-already-stale ordinal, so a 'commit-into-stale-range' case
slipped through.

Fix: at the tail of _commit_block, for the committed block, iterate each
non-SSM lifecycle and clear beam_block[lc] when the ordinal lies inside
that lifecycle's stale_range. The committed page itself remains alive in
the radix tree (committed pages are shareable across caches); only this
_KVCache's redundant strong reference is dropped, restoring the
'committed AND stale -> holder is None' invariant.

Validated end-to-end on DSv4-Pro disagg sweep on Lyris GB300 (c=4/8/16/32/64,
DEP8/TEP8): zero _check_sanity AssertionError across ~160k commit-into-stale
events under real traffic.

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
…ng.test_naive

Add a delay_commit parameter to TestNoBatching.run_request /
TestNoBatching.run_naive that, when True, skips the per-step
kv_cache.commit() inside the decode loop and only commits the full
generated range at the very end of the request.

This exercises the "commit a large pending range into a stale lifecycle
window" path that the preceding fix targets (commit-into-stale-range
where _commit_block needs to release a holder it just placed). Extend
TestNoBatching.test_naive to parameterize over delay_commit alongside
the existing use_external_page_index_buf x use_block_quant axes; this
goes from 4 to 8 parametrized cases with no new test function.

All other call sites of run_request / run_naive default to
delay_commit=False and keep their existing behavior unchanged.

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Address review comment on PR NVIDIA#14478: use the
life_cycles.attention_life_cycles() iterator (which already filters out
the SSM lifecycle) instead of items() + a manual ssm_life_cycle_id
guard, drop the redundant 'is not None' check (assigning None to None
is a no-op), and swap the loop nesting so the per-lifecycle stale-range
computation runs once per lifecycle rather than once per beam x
lifecycle.

Behavior is unchanged: for every committed seq_block whose ordinal sits
in the stale range of an attention lifecycle, the per-beam holder for
that lifecycle is released, restoring the
'committed AND stale -> holder is None' invariant that _check_sanity
expects in suspend().

Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
@Tabrizian
Tabrizian force-pushed the user/imant/dsv4-kvcm-v2-stale-range-commit-fix branch from 390c5d5 to e0e3ce0 Compare May 26, 2026 23:30
@Tabrizian

Copy link
Copy Markdown
Member Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50406 [ run ] triggered by Bot. Commit: e0e3ce0 Link to invocation

@Tabrizian
Tabrizian requested a review from lowsfer May 27, 2026 01:06
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@Tabrizian

Copy link
Copy Markdown
Member Author

/bot run --disable-fail-fast

@Tabrizian

Copy link
Copy Markdown
Member Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50583 [ run ] triggered by Bot. Commit: e0e3ce0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50583 [ run ] completed with state SUCCESS. Commit: e0e3ce0
/LLM/main/L0_MergeRequest_PR pipeline #40083 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Tabrizian
Tabrizian merged commit 210a290 into NVIDIA:feat/deepseek_v4 May 27, 2026
6 checks passed
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 10, 2026
NVIDIA#14478)

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#14478)

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#14478)

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