[None][feat] Support the masked DSA indexer k-cache pool in the Python cache transceiver - #17283
[None][feat] Support the masked DSA indexer k-cache pool in the Python cache transceiver#17283Tabrizian wants to merge 1 commit into
Conversation
…n cache transceiver The Python (v2) KV-cache transceiver previously raised NotImplementedError for the per-layer masked DSA indexer k-cache pool (cross-layer indexer sharing, e.g. GLM 5.2), forcing those checkpoints onto the C++ transceiver. Teach build_page_table's indexer REPLICATED view to cover only the indexer-owning layers: one buffer entry per owning layer, mapped to its packed row via get_indexer_k_cache_pool_layer_idx, and skip the pool for a layer group with no owning layers. The Python transfer machinery already matches peers per-pool by role + global_layer_id overlap, so a masked subset transfers correctly (including PP reshard) with no further changes; the dense/unmasked layout is byte-for-byte unchanged. With Python support in place, GlmMoeDsaForCausalLM prefers the Python transceiver again like the other DeepSeek-family checkpoints, reverting the CPP override that was added only because Python lacked masked-pool support. Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
|
/bot run --disable-fail-fast |
WalkthroughV1 page-table construction now supports partially masked indexer K-cache layers. Fully masked groups omit the indexer pool. DeepSeek and GLM 5.2 configurations now use the Python KV-cache transceiver. ChangesMasked DSA indexer cache support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant KVCacheManager
participant KVCacheExtractor
participant IndexerPoolViews
KVCacheManager->>KVCacheExtractor: provide layer mask and packed indices
KVCacheExtractor->>IndexerPoolViews: append owning-layer pools and views
KVCacheExtractor->>IndexerPoolViews: build masked page-table entries
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/unittest/disaggregated/test_extractor.py (1)
211-215: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAnnotate
indexer_k_cache_layer_mask.Declare the new parameter as
list[bool] | None. This preserves the helper contract and matches the documented global mask format.As per coding guidelines, “Annotate every function” and “prefer built-in generic types and
|.”🤖 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 `@tests/unittest/disaggregated/test_extractor.py` around lines 211 - 215, Update the _make_v1_dsa_manager parameter annotation for indexer_k_cache_layer_mask to list[bool] | None, preserving its existing default and behavior.Source: Coding guidelines
tensorrt_llm/_torch/disaggregation/resource/kv_extractor.py (1)
336-337: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse declared
KVCacheManagerattributes.
KVCacheManager.__init__always setsenable_indexer_k_cacheandindexer_k_cache_local_layer_mask. Replace bothgetattrcalls with direct attribute access. This keeps the manager contract type-checkable and fails fast on an invalid manager.As per coding guidelines, “Avoid reflection when ordinary explicit code is sufficient.”
🤖 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 `@tensorrt_llm/_torch/disaggregation/resource/kv_extractor.py` around lines 336 - 337, In the KV cache extraction logic, replace both getattr calls on kv_cache_manager with direct access to its declared enable_indexer_k_cache and indexer_k_cache_local_layer_mask attributes, preserving the existing conditional behavior and allowing invalid managers to fail fast.Source: Coding guidelines
🤖 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 `@tensorrt_llm/_torch/disaggregation/resource/kv_extractor.py`:
- Around line 336-337: In the KV cache extraction logic, replace both getattr
calls on kv_cache_manager with direct access to its declared
enable_indexer_k_cache and indexer_k_cache_local_layer_mask attributes,
preserving the existing conditional behavior and allowing invalid managers to
fail fast.
In `@tests/unittest/disaggregated/test_extractor.py`:
- Around line 211-215: Update the _make_v1_dsa_manager parameter annotation for
indexer_k_cache_layer_mask to list[bool] | None, preserving its existing default
and behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 37d069cf-5d7c-4823-a88e-1fc952bcb392
📒 Files selected for processing (4)
tensorrt_llm/_torch/disaggregation/resource/kv_extractor.pytensorrt_llm/_torch/models/modeling_deepseekv3.pytests/unittest/disaggregated/test_extractor.pytests/unittest/llmapi/test_llm_args.py
|
PR_Github #63946 [ run ] triggered by Bot. Commit: |
|
PR_Github #63946 [ run ] completed with state
|
Description
The Python (v2) KV-cache transceiver previously raised
NotImplementedErrorfor the per-layer masked DSA indexer k-cache pool (cross-layer indexer sharing, e.g. GLM 5.2), so those checkpoints were forced onto the C++ transceiver — #16558 added aGlmMoeDsaForCausalLM -> CPPpreference as a stop-gap while the Python path lacked this support.This PR teaches the Python transceiver to handle the masked layout, mirroring the C++ support added in #16558:
build_page_table(tensorrt_llm/_torch/disaggregation/resource/kv_extractor.py): the indexerREPLICATEDpool view now covers only the indexer-owning layers — onebuffer_entriesrow per owning layer, each mapped to its packed pool row viaimpl.get_indexer_k_cache_pool_layer_idx(lid)— and skips the indexer pool entirely for a layer group with no owning layers (which would otherwise hit the null-pool getter). The dense/unmasked layout is byte-for-byte unchanged.pool_role+global_layer_idoverlap, so a masked subset transfers correctly, including under PP resharding (the generic analogue of the C++indexerLayerNumPerPP/targetIRanksForIndexerKCacheinterval logic).GlmMoeDsaForCausalLMprefers the Python transceiver again like the other DeepSeek-family checkpoints, reverting theCPPoverride that [None][perf] Allocate DSA indexer k-cache only for layers that own an indexer #16558 added only because Python lacked masked-pool support.Test Coverage
tests/unittest/disaggregated/test_extractor.py::test_v1_dsa_masked_indexer_page_table_covers_owning_layers(new) — builds a V1KVCacheManagerwith a per-layer indexer mask ([True, False, True, False]) and asserts the indexer view isREPLICATED, covers exactly the two owning layers, and maps them to the correct packed pool rows/offsets.test_extractor.py::test_v1_dsa_indexer_page_table_is_replicated_with_per_layer_entriesand::test_v1_dsa_indexer_replicated_transfer_across_pp(existing) — continue to guard the dense layout and the end-to-end replicated transfer path.tests/unittest/llmapi/test_llm_args.py::TestDeepseekTransceiverPreference::test_preference_per_architecture— updated to expectPYTHONforglm_moe_dsaagain.PR Checklist
get_preferred_transceiver_runtimeis an internal preference hook).GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.Dev Engineer Review
build_page_tablenow supports masked DSA indexer K-cache pools.REPLICATEDviews only for indexer-owning layers.GlmMoeDsaForCausalLMnow prefers the Python transceiver.CODING_GUIDELINES.md, with focus on offset mapping, empty-group handling, and regression coverage for dense layouts.QA Engineer Review
_make_v1_dsa_manager, updated to accept an indexer K-cache mask.test-db/orqa/coverage was identified in the provided changes.