-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[None][fix] Enable KVCM V2 by default for KimiLinear #19387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| Caching | ||
| ------- | ||
| KDA states live on the mamba side of a ``MixedMambaHybridCacheManager`` | ||
| KDA states live on the mamba side of a ``MambaHybridCacheManagerV2`` | ||
| (wired in ``pyexecutor/_util.py``): per layer, a short-conv slot of | ||
| ``[3 * num_heads * head_dim, W]`` bf16 (the full FLA ``ShortConvolution`` | ||
| cache window, sections ``[q | k | v]``) and a delta-rule recurrent slot of | ||
|
|
@@ -68,13 +68,12 @@ | |
| and the MLA prefill path natively attends over the cached latent prefix | ||
| (``kv_len = cached + q_len``). KV-cache block reuse is supported as an | ||
| opt-in via ``kv_cache_config.enable_block_reuse=true``, which routes to | ||
| the unified-pool ``CppMambaHybridCacheManager`` (per-block KDA state | ||
| snapshots every ``mamba_state_cache_interval`` tokens, FORCE_CHUNK | ||
| context chunking). | ||
| ``MambaHybridCacheManagerV2`` (per-block KDA state snapshots every | ||
| ``mamba_state_cache_interval`` tokens, FORCE_CHUNK context chunking). | ||
|
|
||
| Not supported: pipeline parallelism, draft-head spec-dec modes | ||
| (MTP/Eagle — no draft-head checkpoint exists). SA speculative decoding | ||
| is validated only without block reuse (Mixed cache manager). | ||
| is validated only without block reuse. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
@@ -2103,9 +2102,7 @@ def _setup_helix_mappings( | |
| @classmethod | ||
| def get_model_defaults(cls, llm_args) -> dict: | ||
| # - enable_block_reuse defaults off: reuse is supported as an | ||
| # explicit opt-in (routes to CppMambaHybridCacheManager with | ||
| # per-block KDA state snapshots); the default stays on the | ||
| # Mixed manager, which SA speculative decoding requires. | ||
| # explicit opt-in with per-block KDA state snapshots. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rewrite drops the reason and leaves a restatement: "defaults off: reuse is supported as an explicit opt-in." The original rationale (the default had to stay on the Mixed manager for SA spec-dec) is void now, so record the current reason for keeping reuse off by default — unqualified accuracy, memory cost, or whatever it actually is — or drop the default if there is none. |
||
| # - tokens_per_block=64: with 32, the flashinfer trtllm-gen FMHA lib | ||
| # rejects the MLA (576, 512) generation kernel (marked slower) and | ||
| # the fallback C++ path requires num_heads % 64 == 0, which K3's | ||
|
|
@@ -2117,6 +2114,14 @@ def get_model_defaults(cls, llm_args) -> dict: | |
| } | ||
| } | ||
|
|
||
| @classmethod | ||
| def get_preferred_kv_cache_manager_version( | ||
| cls, | ||
| pretrained_config: Any = None, | ||
| ) -> Literal["V2"]: | ||
| """Prefer KV cache manager V2 for KimiLinear.""" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also flips the disaggregated default, which the description doesn't mention. The only KDA disagg transfer test ( |
||
| return "V2" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Add a concrete Kimi disaggregated-manager selection test. The existing NIXL test resolves Add a case in 🤖 Prompt for AI AgentsSource: Path instructions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
|
||
| @classmethod | ||
| def get_preferred_transceiver_runtime( | ||
| cls, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -844,10 +844,10 @@ def test_qwen3_gdn_replay_uses_v2_preference( | |
| ) | ||
|
|
||
|
|
||
| def test_kimi_without_v2_preference_uses_mixed_manager( | ||
| def test_kimi_model_preference_uses_v2_manager( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| """Kimi K3 uses separate KV and recurrent-state pools for SA decoding.""" | ||
| """Kimi's model preference selects V2 for its KDA and MLA cache.""" | ||
| from tensorrt_llm._torch.models.modeling_kimi_linear import KimiLinearForCausalLM | ||
|
|
||
| monkeypatch.delenv("TRTLLM_USE_PY_MAMBA", raising=False) | ||
|
|
@@ -862,13 +862,13 @@ def test_kimi_without_v2_preference_uses_mixed_manager( | |
| ) | ||
| resolved = _resolve_kv_cache_manager_v2_auto(llm_args, KimiLinearForCausalLM) | ||
|
|
||
| assert resolved is False | ||
| assert llm_args.kv_cache_config.use_kv_cache_manager_v2 is False | ||
| assert resolved is True | ||
| assert llm_args.kv_cache_config.use_kv_cache_manager_v2 is True | ||
| assert llm_args.kv_cache_config.enable_block_reuse is False | ||
| assert llm_args.kv_cache_config.tokens_per_block == 64 | ||
| assert ( | ||
| get_kv_cache_manager_cls(_kimi_model_config(), llm_args.kv_cache_config) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This covers the aggregated route only. Add the disagg counterpart: Related: |
||
| is MixedMambaHybridCacheManager | ||
| is MambaHybridCacheManagerV2 | ||
| ) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now reads as if block reuse is what routes to
MambaHybridCacheManagerV2, but both paths land there after this change. Suggest: reuse stays opt-in; enabling it adds per-block KDA state snapshots everymamba_state_cache_intervaltokens and FORCE_CHUNK context chunking on the same V2 manager.