Repository navigation
[#57652 suggestion] AttentionSpec.max_tp_shards + KVCacheConfig.kv_tp_replicas for TP-replication detection - #176
Merged
varun-sundar-rabindranath merged 4 commits intoSep 28, 2026
Conversation
…nfig KVCacheConfig.kv_layers_tp_replicated now records only the per-layer spec fact (MLA / SWA-MLA with one KV head), resolved before the scheduler flattens UniformTypeKVCacheSpecs. The offloading MVP parallelism limits move back into build_offloading_config. Adds a regression test for a mixed MLA + GQA uniform group whose flattened scheduler spec is MLA. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
LucasWilkinson
requested review from
alexm-redhat and
robertgshaw2-redhat
as code owners
September 28, 2026 14:55
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
…replicas AttentionSpec.max_tp_shards records how many distinct shards a cache splits into across TP (MLA / SWA-MLA default to 1; None means shards across any TP size). get_kv_cache_configs resolves KVCacheConfig.kv_tp_replicas as the gcd of each layer's tp_size // max_tp_shards, so partial replication (e.g. GQA with tp > num KV heads) can later be expressed without changing the config field. Offloading's replicated layout requires kv_tp_replicas == tp_size. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Drop the class-level max_tp_shards=1 default on MLAAttentionSpec and SlidingWindowMLASpec so no spec claims TP replication by inheritance. None now means unknown and is treated as not replicated. Set max_tp_shards=1 explicitly where the cache is verified identical on every TP rank: generic MLAAttention (DSv3/V3.2/GLM-5.3 latent), the DSv3.2 indexer cache, DeepSeek-V4 attention/indexer/compressor state caches and the DeepSeek-V4 SWA cache. Kimi-K3, MiniMax-M3, Qwen4-exp and DSv4.1 attention stay unset until their owners opt in. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
varun-sundar-rabindranath
merged this pull request
into
neuralmagic:varun/dsv4-fix
Sep 28, 2026
5 checks passed
varun-sundar-rabindranath
pushed a commit
that referenced
this pull request
Sep 29, 2026
…Config.kv_tp_replicas for TP-replication detection (#176) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> --------- Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Varun Sundar Rabindranath <vsundarr@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Suggested follow-up for vllm-project#57652.
What
AttentionSpec.max_tp_shards: int | None = None: how many distinct shards this cache splits into across TP. TP ranks beyond that count hold replicas.Nonemeans unknown and is treated as not replicated.MambaSpec.tp_replicated.max_tp_shards=1is set only where the cache has been checked to be identical on every TP rank:MLAAttention(mla_attention.py), which covers the DSv3 / V3.2 / GLM-5.3 latent cache;deepseek_v2.py;wk_weights_projusesdisable_tp=True);deepseek_v4/attention.py);fused_wkv_wgateusesdisable_tp=True);sparse_swa.py).Noneuntil their owners opt in.merge().KVCacheConfig.kv_tp_replicas: int = 1replacesall_groups_are_tp_replicated. It's the number of consecutive TP ranks holding identical KV for every layer.get_kv_cache_configssets it throughkv_cache_groups_tp_replicas(groups, tp_size, dcp_size): the gcd of each layer'stp_size // max_tp_shards, taken per layer throughiter_layer_specs. A layer counts as 1 if it isn't an attention spec, has no value set, or is DCP-sharded under DCP. Thetype(spec) in (MLA, SWA-MLA)check is gone.replicated_layoutrequirestp > 1 and kv_tp_replicas == tp. The TP-only / no-PP / no-CP limits stay inbuild_offloading_config, as on main.Why
Why a per-layer value on
KVCacheConfig:MLAAttentionSpecsharesuniform_type_base_spec=FullAttentionSpec, so oneUniformTypeKVCacheSpecsgroup can mix MLA and GQA layers.generate_scheduler_kv_cache_configkeeps an arbitrary layer spec, so the value has to be computed before that. Otherwise the scheduler could see an MLA spec and wrongly de-duplicate head-sharded KV.Why a count, not a bool: it can express partial replication later. For example, GQA with 8 KV heads at TP16 is
max_tp_shards=8, which giveskv_tp_replicas=2. The config field wouldn't need to change. Offloading could then useworld_size // replicascopies, slotrank // replicas, and one writer per replica group. GQA and Mamba (tp_replicated) aren't wired up here; they default to 1, which is today's behaviour.max_tp_shardsis on the spec rather thantp_replicasbecause it doesn't depend on the TP size, so a layer can set it without knowing the TP size. The TP-dependent replica count is computed once, inget_kv_cache_configs.Testing
New
test_kv_cache_groups_tp_replicascases:kv_tp_replicasmax_tp_shards=2max_tp_shards=8max_tp_shards=4max_tp_shardsunsetpre-commit (ruff, ruff-format, mypy-3.10) and mypy-3.12 pass on the changed files.
AI assistance (Claude Code) was used; I reviewed the changes.
🤖 Generated with Claude Code