[https://nvbugs/6255037][fix] Count DSA indexer K-cache correctly as UINT8 in KV cache size estimate - #15088
Conversation
…V cache size estimate The DSA cache-size helpers folded the indexer K-cache into the MLA latent and scaled the combined size by the KV cache dtype. The indexer K-cache is physically allocated as raw UINT8 (WindowBlockManager::allocatePools, poolDtype = kUINT8), so counting it at the KV dtype (2 bytes under BF16) over-counts it and inflates the estimated per-token cost. That inflated estimate caps the KV cache block budget, so the run under-allocated primary blocks (~10%) and left GPU memory idle. Count the MLA latent at the KV cache dtype and the indexer separately at 1 byte/element in both get_cache_size_per_token and get_cache_bytes_per_token. For GLM-5 fp8 EP8 this lowers the per-token estimate from 110448 to 100152 bytes; fp8 KV cache configs are unaffected (indexer already 1 byte). Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com> Signed-off-by: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
📝 WalkthroughWalkthroughDSACacheManager cache size accounting is refactored to explicitly separate MLA latent K-cache and indexer K-cache memory computations. Both ChangesDSA Cache Size Accounting Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
/bot run --disable-fail-fast |
|
PR_Github #52723 [ run ] triggered by Bot. Commit: |
|
PR_Github #52723 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #52811 [ run ] triggered by Bot. Commit: |
|
PR_Github #52811 [ run ] completed with state |
Description
The log change mentioned by the bug description was caused by the following code, which I have changed from the upper to latter in my latest PR #13745 for supporting Gemma4 for AutoDeploy.
The test cases runs with BF16 MLA KV cache and UINT8 indexer K cache:
- Old (everything ×2 B): 78 × (1152 + 132×2) = 78 × 1416 = 110,448 B/tok → exactly your kv size per token is 110448.
- New (indexer at 1 B): 78 × (1152 + 132) = 78 × 1284 = 100,152 B/tok → matches the bad run's 133.44 GiB ÷ 1,430,656 = 100,150.
- The gap: phantom second byte on the indexer = 78 × 132 = 10,296 B/tok × 1,430,656 tok = 13.7 GiB ≈ the 147.32 − 133.44 = 13.9 GiB drop.
This explains the reporting paged KV cache creation drop.
Given the above, this merge request accounts for token size correctly inside dsa.py.
With the MR, running
perf/test_perf.py::test_perf[glm_5_fp8-bench-pytorch-float8-maxbs:512-maxnt:2048-input_output_len:2000,500-ep:8-gpus:8], I see the improved KV cache blocks49324compared to the older44708(~10% increase).Test Coverage
Tested locally. The QA CI should restore its KV cache allocation size to the reported after this MR is merged.
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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.