[#18849][fix] Pass vocab_size to hybrid-Mamba KV cache managers - #18970
[#18849][fix] Pass vocab_size to hybrid-Mamba KV cache managers#18970dibyo10 wants to merge 4 commits into
Conversation
The hybrid-Mamba branches of _create_kv_cache_manager built the V2 cache manager without vocab_size, so self.vocab_size stayed None. It is read only when building multimodal block-reuse cache keys, so text-only traffic served fine and the first image request raised a binding TypeError inside the executor event loop, killing every rank. Move vocab_size into manager_extra_kwargs, which is already gated on KVCacheManagerV2, so every branch gets it and a new branch cannot forget it. Resolve it through the nested text_config as well, since composite VLM configs keep the field there. Also raise a named error when a manager without vocab_size is asked to build multimodal cache keys, instead of letting None reach the binding as id_offset. Signed-off-by: Dibyo Chakraborty <dibyo.dc@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review. WalkthroughThe executor resolves vocabulary size from top-level or nested text configuration and passes it to V2 KV-cache managers. Multimodal metadata generation reports missing vocabulary size explicitly. Tests cover hybrid propagation and text-only behavior. ChangesKV-cache vocabulary handling
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Severity of issue fixed: High Merge Risk: ⚪ Minimal · up to This change propagates vocabulary size to V2 hybrid-Mamba cache managers and adds a clear multimodal validation error. No concrete merge-blocking risk remains in the supplied evidence. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Follows CodeRabbit's docstring-coverage warning on NVIDIA#18970. Signed-off-by: Dibyo Chakraborty <dibyo.dc@gmail.com>
…ctor Signed-off-by: Dibyo Chakraborty <dibyo.dc@gmail.com>
mikeiovine
left a comment
There was a problem hiding this comment.
Stamp on behalf of runtime devs, delegating proper review to @NVIDIA/trt-llm-kv-cache-manager-devs; please ping me if you think this is not accurate
Description
Fixes #18849.
_create_kv_cache_managerpassedvocab_size=config.vocab_sizeon the MLA branch and the plain-attention branch only. The three hybrid-Mamba branches (Kimi K3 / KDA,nemotron_hybrid, andqwen3_next/ Qwen3.5 / Qwen4-Exp) constructed the manager without it, andMambaHybridCacheManagerV2absorbs unknown keywords through**kwargs, soKVCacheManagerV2.vocab_sizesilently stayedNone.That field is read only when building multimodal block-reuse cache keys (
_augment_tokens_with_mm_run_metadata/_augment_tokens_with_contiguous_mm_metadata), which is why a hybrid deployment serves text-only traffic indefinitely and then dies on its firstimage_urlrequest:gen_multimodal_cache_key_tokens()receivesNoneasid_offset, the resultingTypeErrorescapes into the PyExecutor event loop, and every rank is hard-killed.Two changes:
vocab_sizemoves intomanager_extra_kwargs, which is already gated onissubclass(kv_cache_manager_cls, KVCacheManagerV2), and the two per-branchvocab_size=config.vocab_sizearguments are removed. Every V2 branch now gets the value from one place, so a branch added later cannot omit it — the same reasoning_mamba_conv_layout_kwargsalready applies toconv_state_layout. The V1 managers are unaffected:KVCacheManagerswallowed the argument into**kwargswithout reading it, andMixedMambaHybridCacheManager(which has no**kwargs) must not receive it._resolve_vocab_sizehelper falls back totext_config.vocab_size, because composite VLM configs keep the field on the nested text config.Additionally,
KVCacheManagerV2._augment_tokens_for_block_reusenow raises aRuntimeErrornaming the missing construction argument when it is asked to build multimodal cache keys without avocab_size, rather than lettingNonereach the binding. Text-only requests return before that check, so they are unaffected.Not addressed here, to keep this PR to one concern: suggestion 3 in the issue — failing the individual request with a 4xx instead of terminating the executor when multimodal metadata cannot be built (which also covers the
disable_mm_encoder: truecase). That is executor-level error classification and is worth its own PR, so it is now tracked separately in #18971.I do not have Hopper hardware, so the end-to-end reproduction from the issue was not re-run; the reporter's verified workaround fills in the same value this change now passes.
Test Coverage
tests/unittest/_torch/executor/kv_cache/test_mamba_cache_manager.pytest_hybrid_v2_manager_receives_vocab_size— routes a Qwen3 hybrid config through_create_kv_cache_managerand asserts the V2 manager is constructed withvocab_size. Fails onmain.test_hybrid_v2_manager_reads_vocab_size_from_text_config— same, withvocab_sizeonly on the nestedtext_config.test_hybrid_v1_manager_does_not_receive_vocab_size— guards the V1MixedMambaHybridCacheManager, whose signature has no**kwargs.tests/unittest/_torch/executor/kv_cache/test_kv_cache_v2_multimodal_runs.pytest_augment_tokens_for_block_reuse_reports_missing_vocab_size— the guard names the missing argument.test_augment_tokens_for_block_reuse_ignores_missing_vocab_size_for_text— text-only requests still work without avocab_size.Both files are CPU-only.
pre-commit's formatters and linters (ruff 0.9.4 check/format on the Group A files, yapf 0.43.0 / isort 5.12.0 /ruff-legacyon_util.py, codespell) pass on the changed files. The test cases themselves have not been executed — TensorRT-LLM does not build on the macOS host I am working from — so please run the two files in CI.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.Dev Engineer Review
_resolve_vocab_sizereads from the main config or nestedtext_config.RuntimeErrorwhenvocab_sizeis missing. Text-only requests remain unchanged.QA Engineer Review
test_kv_cache_v2_multimodal_runs.pyadds coverage for missingvocab_sizeerrors and text-only behavior.test_mamba_cache_manager.pyadds coverage for direct and nested configuration resolution and V1 compatibility.tests/integration/test_lists/test-db/ortests/integration/test_lists/qa/.Per-File QA Perspective
tensorrt_llm/_torch/pyexecutor/_util.py: Verifyvocab_sizepropagation for hybrid-Mamba and composite VLM configurations. Verify that V1 managers do not receive the V2-only argument.tensorrt_llm/_torch/pyexecutor/kv_cache/kv_cache_manager_v2.py: Verify that missingvocab_sizeraisesRuntimeErroronly during multimodal cache-key generation.tests/unittest/_torch/executor/kv_cache/test_kv_cache_v2_multimodal_runs.py: Covers missing-value errors and unchanged text-only behavior. It is not listed in the CI or manual-QA test lists.tests/unittest/_torch/executor/kv_cache/test_mamba_cache_manager.py: Covers direct and nested configuration resolution and V1 compatibility. It is not listed in the CI or manual-QA test lists.