[https://nvbugs/6418912][fix] Clear detached KV cache sequence links - #16037
[https://nvbugs/6418912][fix] Clear detached KV cache sequence links#16037chienchunhung wants to merge 1 commit into
Conversation
Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
📝 WalkthroughWalkthroughModifies ChangesDetached Block Pointer Fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Related PRs: None specified in the provided context. Suggested reviewers: None specified in the provided context. 🐰 A block let go, its old link cleared, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp (1)
222-226: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the attached-block path too.
This only checks the detached case (isEnableBlockReuse=false). Add one reuse-enabled case that keeps a block attached to the reuse tree and assertsgetPrevBlockInSeq()stays non-null afterreleaseBlocks;WindowBlockManager::releaseBlocksonly clears the link for detached blocks.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp` around lines 222 - 226, The current test only covers the detached block-reuse path and misses the attached-block behavior in WindowBlockManager::releaseBlocks. Add a reuse-enabled case in kvCacheManagerTest.cpp that leaves a block attached to the reuse tree, calls releaseBlocks, and asserts getPrevBlockInSeq() remains non-null; keep the existing detached-case assertion for the no-reuse path and use the same blockManager/getBlockById setup to locate the block under test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp`:
- Around line 222-226: The current test only covers the detached block-reuse
path and misses the attached-block behavior in
WindowBlockManager::releaseBlocks. Add a reuse-enabled case in
kvCacheManagerTest.cpp that leaves a block attached to the reuse tree, calls
releaseBlocks, and asserts getPrevBlockInSeq() remains non-null; keep the
existing detached-case assertion for the no-reuse path and use the same
blockManager/getBlockById setup to locate the block under test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: cf40e400-ce5e-4823-b27d-f2ba900d6c00
📒 Files selected for processing (2)
cpp/tensorrt_llm/batch_manager/kvCacheManager.cppcpp/tests/unit_tests/batch_manager/kvCacheManagerTest.cpp
|
Closing this PR as it is subsumed by #16019 |
Summary
mPrevBlockInSeqownership links when detached KV-cache blocks are releasedRoot cause
PR #11685 began returning detached blocks to the front of the free queue. Those blocks still retained strong
mPrevBlockInSeqlinks. Reusing a subset of each completed request's blocks could therefore join otherwise completed request chains; the largeFillKvCacheWithRequestsAndCompleteOneByOne/5fixture eventually tears down an unbounded shared-ownership chain and segfaults.Detached blocks have no reusable hash chain, so their predecessor link is obsolete once their reference count reaches zero. Reusable radix-tree blocks are unchanged.
Validation
Local:
git diff --checkTargeted CI through combined integration PR #16019:
1248a1862d69a3ef8c2e9bca0a2207f383ba31bdPR_Github #57931→L0_MergeRequest_PR #46619: SUCCESSA30-CPP-1cpp/test_unit_tests.py::test_unit_tests[batch_manager-80]FillKvCacheAndCompleteRequestsTest.FillKvCacheWithRequestsAndCompleteOneByOne/5: OK in 1,739 msRegression evidence
The preceding integration run, pipeline #46583 on head
656e9e6, reproduced the exact/5segfault twice (initial run and CTest rerun). All other concrete gtests inbatch_manager-80, including the nine partial-copy variants, passed. The only code delta in the successful integration rerun is this fix.Summary by CodeRabbit