[KV Connector] Add canonical KV layout fields for TP-agnostic offload - #46954
Closed
Etelis wants to merge 4 commits into
Closed
[KV Connector] Add canonical KV layout fields for TP-agnostic offload#46954Etelis wants to merge 4 commits into
Etelis wants to merge 4 commits into
Conversation
Signed-off-by: Itay Etelis <itay.etelis@ibm.com>
Contributor
|
This pull request has merge conflicts that must be resolved before it can be |
…flag Signed-off-by: Itay Etelis <itay.etelis@ibm.com>
Etelis
marked this pull request as ready for review
July 9, 2026 10:43
Etelis
requested review from
ApostaC,
NickLucche,
ivanium,
orozery and
xuechendi
as code owners
July 9, 2026 10:43
Etelis
marked this pull request as draft
July 12, 2026 11:40
Contributor
Author
|
Closed as #48408 implements that. |
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.
Extends
CanonicalKVCacheRefwith the per-layer intra-block layout needed to offload KV in a tensor-parallel-agnostic format, so a cache offloaded under one TP size can later be loaded under another by slicing on the global head dimension.A head-sliceable block is
(block_size, n_heads, head_bytes):n_heads— global KV head count;0= no head decompositionh_stride— bytes per head per token (the head-slice unit)bs_stride— bytes per token (n_heads * h_stride)replicated— meaningful whenn_heads == 0:True= page is identical on every TP rank (MLA latent; any one rank's copy is complete),False= rank-specific shards (Mamba states, packed blocks; no single rank's page is complete)register_kv_cachespopulates these per layer from eachKVCacheSpec(h_stride = real_page_size_bytes / (block_size * num_kv_heads), which is TP-invariant). The fields live on the per-layer ref rather than the tensor, since layers of different types (e.g. attention + mamba in hybrid models) can share one tensor.Population fails closed to the opaque default (
n_heads=0,replicated=False) whenever head slicing would not be valid: DCP token-sharding, KV head replication (tp > total heads) or per-layer head count mismatch, per-token-head quant scales stored outside the page, or a page that does not divide evenly into head cells.Schema-only: all fields have inert defaults and nothing reads them yet.
Backend KV cache layouts
Source layouts the canonical fields normalize. Per-head backends differ only by
dim order / K-V packing and reduce to
n_heads = total; MLA latent and SSMstate carry no head dim and stay head-less.
get_kv_cache_shape(nb, 2, bs, H, D)(nb, 2, bs, H, D)[1](nb, 2, bs, H, D+scale)(2, nb, bs, H, D)[2](nb, 2, bs, H, D)(nb, 2, bs, H, D)[3](nb, bs, H, slot)[4](nb, H, bs, 2·D)[5](nb, bs, H, D+Dv)(nb, bs, D)(nb, bs, 656|584)[6](nb, bs, D)((I+2GN)/tp, K−1)+ state(nh/tp, hd, N)(I/tp, K−1)(+ ssm(I/tp, N))((2·hk·nk+hv·nv)/tp, K−1)+ state(nv/tp, hv, hk)(nh/tp, hd, hd)Legend:
nb=num_blocks,bs=block_size,H=num_kv_heads (per-worker),D=head_size,Dv=head_size_v; SSM:I=intermediate,nh=num_heads,hd=head_dim,N=state_size,K=conv_kernel,G=n_groups,tp=TP size.