[Model][GLM-5.3-Flash] Support DCP for the kpool sparse indexer (#59211)

Signed-off-by: NickLucche <nicolo.lucchesi@mistral.ai>
This commit is contained in:
Nicolò Lucchesi
2026-10-05 16:44:14 +02:00
committed by GitHub
parent f9c9e8ac24
commit 30d4032363
9 changed files with 243 additions and 38 deletions
@@ -315,6 +315,9 @@ def test_compressed_slot_mapping_warmup_includes_index_kpool():
config = SimpleNamespace(
cache_config=SimpleNamespace(block_size=256),
model_config=SimpleNamespace(hf_text_config=SimpleNamespace(index_kpool=32)),
parallel_config=SimpleNamespace(
decode_context_parallel_size=1, cp_kv_cache_interleave_size=1
),
)
keys = CompressedSlotMappingKernel().get_warmup_keys(config)
@@ -343,6 +346,41 @@ def test_compressed_slot_mapping_inherits_padded_token_slots():
assert compressed.tolist() == [-1, -1, -1, -1, -1, 3 * 4 + 2, -1, 3 * 4 + 3]
@pytest.mark.skipif(not torch.cuda.is_available(), reason="requires CUDA")
def test_compressed_slot_mapping_dcp_uses_rank_local_state_positions():
"""Under DCP each rank writes only the states it owns, at the state's
rank-local position."""
device = torch.device("cuda")
dcp, interleave, ratio, block_size = 2, 4, 2, 4
num_tokens = 32
query_start_loc = torch.tensor([0, num_tokens], dtype=torch.int32, device=device)
seq_lens = torch.tensor([num_tokens], dtype=torch.int32, device=device)
block_table = torch.tensor([[5, 7]], dtype=torch.int32, device=device)
pos = torch.arange(num_tokens)
for rank in range(dcp):
owned = (pos // interleave) % dcp == rank
slot_mapping = torch.where(owned, 0, -1).to(torch.int64).to(device)
compressed = get_compressed_slot_mapping(
num_tokens,
slot_mapping,
query_start_loc,
seq_lens,
block_table,
block_size=block_size,
compress_ratio=ratio,
dcp_world_size=dcp,
cp_interleave=interleave,
)
local_pos = pos // (interleave * dcp) * interleave + pos % interleave
state = local_pos // ratio
expected = torch.where(
owned & ((pos + 1) % ratio == 0),
block_table[0].cpu()[state // block_size] * block_size + state % block_size,
-1,
)
assert compressed.tolist() == expected.tolist()
def test_index_conversion_warmup_uses_physical_block_stride():
config = SimpleNamespace(
cache_config=SimpleNamespace(block_size=64),
@@ -370,6 +408,8 @@ def test_zero_token_pcp_rank_participates_in_compressed_mapping_gather(monkeypat
builder.use_pcp = True
builder.pcp_world_size = 4
builder.pcp_rank = 0
builder.dcp_world_size = 1
builder.cp_kv_cache_interleave_size = 1
builder.kernel_block_size = None
builder.kv_cache_spec = SimpleNamespace(block_size=64, num_states=64)
builder.compressed_slot_mapping_buffer = torch.zeros(8, dtype=torch.int64)
@@ -383,8 +423,11 @@ def test_zero_token_pcp_rank_participates_in_compressed_mapping_gather(monkeypat
block_size,
compress_ratio,
out,
dcp_world_size,
cp_interleave,
):
assert num_tokens == 0
assert dcp_world_size == 1
assert block_size == 64
assert compress_ratio == 4
out.fill_(-1)
+21
View File
@@ -1873,6 +1873,27 @@ def test_dcp_target_allocates_replicated_draft_independently(
assert [len(group) for group in cached_blocks.blocks] == [1, 4]
def test_dcp_replicated_kpool_tail_keeps_block_interior_layout(monkeypatch):
"""A replicated kpool tail ring is per-request state, not a draft group."""
from vllm.v1.attention.backends.utils import resolve_kv_cache_layout
monkeypatch.delenv("VLLM_KV_CACHE_LAYOUT", raising=False)
config = VllmConfig(model_config=ModelConfig(max_model_len=1024))
config.parallel_config.decode_context_parallel_size = 4
config.cache_config.kv_cache_layout = None
tail = KpoolTailSpec(
block_size=4,
num_kv_heads=2,
head_size=128,
head_size_v=0,
dtype=torch.bfloat16,
sliding_window=4,
dcp_sharded=False,
)
layout = resolve_kv_cache_layout(config, [["LBHNC"]], [new_mla_spec(), tail])
assert layout == KVCacheLayout.LBHNC
@pytest.mark.parametrize("use_mla", [False, True])
def test_full_attention_merge_preserves_replicated_cache_geometry(use_mla):
config = VllmConfig(model_config=ModelConfig(max_model_len=1024))