[None][fix] Fix disagg KV cache assertion failures with enable_partial_reuse - #12641
Closed
achartier wants to merge 1 commit into
Closed
[None][fix] Fix disagg KV cache assertion failures with enable_partial_reuse#12641achartier wants to merge 1 commit into
achartier wants to merge 1 commit into
Conversation
…l_reuse Fixes three chained assertion failures in disaggregated serving when enable_partial_reuse=True (the default) and requests lack a common prefix. 1. Duplicate block IDs in storeBlocks (kvCacheManager.cpp): The same physical block can appear at multiple positions in a sequence's block list. storeBlocks now skips insertion when the block is already the current searchRoot, preventing self-referential tree corruption. 2. addNextBlock silent no-op (kvCacheManager.cpp): After PR NVIDIA#11919 replaced setPrevBlock() with lookup-node navigation, addNextBlock silently skipped attachment when a slot was occupied. Changed to evict-and-replace: detach the existing block and attach the new one, keeping getPrevBlock() consistent. 3. fromReuseTree fallback (kvCacheUtils.h, cacheFormatter.cpp): When storeBlocks skips a duplicate, the reuse tree is incomplete. Changed fromReuseTree to return std::optional and fall back to fromAllBlockIds in getBlockRangeForSending. Resolves the existing TODO about handling missing blocks. 4. Termination race (py_executor.py): When enable_partial_reuse_for_disagg was True, _handle_responses terminated requests without checking is_disagg_context_transmission_state, racing with the async CacheSender thread. Unified the termination guard to always check transmission state before terminating. Signed-off-by: Aurelien Chartier <2567591+achartier@users.noreply.github.com>
Tabrizian
reviewed
Apr 1, 2026
| # then we need to terminate the request. TODO: Remove this once disagg support from KVCache reuse | ||
| # path is fixed. | ||
| if self.enable_partial_reuse_for_disagg and not self.kv_cache_manager.is_vswa and self.dist.pp_size == 1: | ||
| if not request.is_disagg_context_transmission_state: |
Member
There was a problem hiding this comment.
Terminating the request is intentional since the blocks associated with that request are pinned (the refcount increased by 1) before termination to not evict those blocks until KVCache transfer is completed.
Collaborator
Author
There was a problem hiding this comment.
Agreed, I don't think this is correct. Closing this workaround PR in favor of !12648
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@coderabbitai summary
Description
Fixes three chained assertion failures in disaggregated serving when enable_partial_reuse=True (the default) and requests lack a common prefix.
Duplicate block IDs in storeBlocks (kvCacheManager.cpp): The same physical block can appear at multiple positions in a sequence's block list. storeBlocks now skips insertion when the block is already the current searchRoot, preventing self-referential tree corruption.
addNextBlock silent no-op (kvCacheManager.cpp): After PR [TRTLLM-11159][feat] Wire KVCacheBlock to UnifiedBlockTree, replacing mPrevBlock/mNextBlocks with lookup-node pointers. #11919 replaced setPrevBlock() with lookup-node navigation, addNextBlock silently skipped attachment when a slot was occupied. Changed to evict-and-replace: detach the existing block and attach the new one, keeping getPrevBlock() consistent.
fromReuseTree fallback (kvCacheUtils.h, cacheFormatter.cpp): When storeBlocks skips a duplicate, the reuse tree is incomplete. Changed fromReuseTree to return std::optional and fall back to fromAllBlockIds in getBlockRangeForSending. Resolves the existing TODO about handling missing blocks.
Termination race (py_executor.py): When enable_partial_reuse_for_disagg was True, _handle_responses terminated requests without checking is_disagg_context_transmission_state, racing with the async CacheSender thread. Unified the termination guard to always check transmission state before terminating.
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)
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.