[Bugfix][DCP] Materialize prefill keys on non-owner ranks (#54908)

Signed-off-by: 云挚 <ningyunxiao.nyx@antgroup.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Yunxiao Ning
2026-09-04 02:12:07 +00:00
committed by GitHub
co-authored by OpenAI Codex
parent 560ef78bfe
commit 19c018ec05
2 changed files with 20 additions and 4 deletions
@@ -234,7 +234,7 @@ def test_fused_norm_rope(num_tokens: int, index_interleave: bool, mla_dtype: str
assert (topk == -1).all(), "topk buffer not cleared on indexer layer"
def test_fused_norm_rope_normalizes_query_without_local_cache_slots():
def test_fused_norm_rope_materializes_qk_without_local_cache_slots():
"""DCP non-owner ranks still need valid query shards for query AllGather."""
torch.manual_seed(7)
dev = "cuda"
@@ -259,6 +259,8 @@ def test_fused_norm_rope_normalizes_query_without_local_cache_slots():
idx_cache = torch.zeros(1, max_pos, idx_row, device=dev, dtype=torch.uint8)
no_local_slots = torch.full((num_tokens,), -1, device=dev, dtype=torch.int64)
topk = torch.full((num_tokens, 2048), 7, device=dev, dtype=torch.int32)
kv_out = torch.empty_like(kv_c)
kpe_out = torch.empty_like(k_pe)
q_out = K.fused_norm_rope(
pos,
@@ -283,9 +285,17 @@ def test_fused_norm_rope_normalizes_query_without_local_cache_slots():
mla_k_scale=None,
has_indexer=True,
index_rope_interleave=True,
kv_c_out=kv_out,
k_pe_out=kpe_out,
)
assert_bf16(q_out, rms_norm(q_c, qw), "q_c rmsnorm without local cache slots")
assert_bf16(kv_out, rms_norm(kv_c, kvw), "kv_c rmsnorm without local slots")
assert_bf16(
kpe_out,
rope(k_pe.float(), pos, cos_sin, interleave=True),
"k_pe RoPE without local slots",
)
assert not mla_cache.any(), "non-owner rank wrote the MLA KV cache"
assert not idx_cache.any(), "non-owner rank wrote the indexer KV cache"
assert (topk == -1).all(), "topk buffer not cleared on non-owner rank"
+9 -3
View File
@@ -198,9 +198,13 @@ def _fused_norm_rope_kernel(
if slot_mapping_ptr is None:
if kv_out_ptr is None and kpe_out_ptr is None and index_k_out_ptr is None:
return
elif tl.load(slot_mapping_ptr + tok_idx) < 0:
# Padding, or (under DCP) a token whose KV slot another rank owns:
# skip the K-side norms and cache writes.
elif tl.load(slot_mapping_ptr + tok_idx) < 0 and (
pid != 1 or (kv_out_ptr is None and kpe_out_ptr is None)
):
# Padding, or (under DCP) a token whose KV slot another rank owns.
# Dense prefill still consumes the materialized normalized/rotated K
# rows on every rank, so pid 1 must produce them even when this rank
# must not write the owner-local cache slot.
return
if pid == 1:
@@ -250,6 +254,8 @@ def _fused_norm_rope_kernel(
return
slot_idx = tl.load(slot_mapping_ptr + tok_idx)
if slot_idx < 0:
return
mla_block_size = MLA_CACHE_BLOCK_SIZE
mla_block_idx = slot_idx // mla_block_size
mla_block_off = slot_idx % mla_block_size