fix(npu): fix hybrid KV transfer with PP prefill in PD disaggregation (#38402)
This commit is contained in:
@@ -174,6 +174,22 @@ class AscendKVManager(MooncakeKVManager):
|
||||
self._validate_envelope_kv_layout(
|
||||
dst_kv_ptrs, dst_kv_item_len, dst_attn_tp_size
|
||||
)
|
||||
# Hybrid MLA prefill stages expose PP-local entries, while a PP=1
|
||||
# decode peer registers all model layers. Pair only this layout by
|
||||
# global layer id; every other Ascend layout keeps the legacy path.
|
||||
if self.is_hybrid_mla_backend and self.pp_size > 1:
|
||||
return self._send_kvcache_generic(
|
||||
mooncake_session_id=mooncake_session_id,
|
||||
src_data_ptrs=self.kv_args.kv_data_ptrs,
|
||||
dst_data_ptrs=dst_kv_ptrs,
|
||||
item_lens=self.kv_args.kv_item_lens,
|
||||
prefill_data_indices=prefill_kv_indices,
|
||||
dst_data_indices=dst_kv_indices,
|
||||
executor=executor,
|
||||
src_layer_ids=self.kv_args.kv_layer_ids,
|
||||
dst_layer_ids=dst_layer_ids,
|
||||
)
|
||||
|
||||
# Group by indices
|
||||
prefill_kv_blocks, dst_kv_blocks = group_concurrent_contiguous(
|
||||
prefill_kv_indices, dst_kv_indices
|
||||
|
||||
@@ -1501,6 +1501,7 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
|
||||
dst_indices,
|
||||
src_state_layer_ids,
|
||||
dst_state_layer_ids,
|
||||
dst_item_lens,
|
||||
)
|
||||
or rc
|
||||
)
|
||||
@@ -1707,6 +1708,7 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
|
||||
dst_mamba_index: list,
|
||||
src_layer_ids: Optional[List[int]] = None,
|
||||
dst_layer_ids: Optional[List[int]] = None,
|
||||
dst_state_item_lens: Optional[list[int]] = None,
|
||||
):
|
||||
assert len(prefill_mamba_index) == 1, "Mamba should have single state index"
|
||||
|
||||
@@ -1721,6 +1723,12 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
|
||||
for i, j in pairs:
|
||||
dst_state_ptr = dst_state_data_ptrs[j]
|
||||
length = src_state_item_lens[i]
|
||||
if dst_state_item_lens and length != dst_state_item_lens[j]:
|
||||
raise RuntimeError(
|
||||
"Prefill/Decode Mamba slot size mismatch "
|
||||
f"(src={length}, dst={dst_state_item_lens[j]}). "
|
||||
"Configure matching persistent state layouts on both peers."
|
||||
)
|
||||
src_addr = src_state_data_ptrs[i] + length * int(prefill_mamba_index[0])
|
||||
dst_addr = dst_state_ptr + length * int(dst_mamba_index[0])
|
||||
transfer_blocks.append((src_addr, dst_addr, length))
|
||||
@@ -1776,6 +1784,7 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
|
||||
dst_mamba_index,
|
||||
src_layer_ids,
|
||||
dst_layer_ids,
|
||||
dst_state_item_lens,
|
||||
)
|
||||
|
||||
local_tp_rank_in_group = self.kv_args.engine_rank % self.attn_tp_size
|
||||
|
||||
@@ -3981,6 +3981,9 @@ class HybridLinearKVPool(KVCache):
|
||||
def get_kv_layer_ids(self):
|
||||
"""Global layer ids aligned with the full-attention KV buffers."""
|
||||
layer_ids = list(self.full_attention_layer_id_mapping)
|
||||
if self.use_mla and _is_npu and layer_ids:
|
||||
data_ptrs, _, _ = self.get_contiguous_buf_infos()
|
||||
return layer_ids * (len(data_ptrs) // len(layer_ids))
|
||||
return layer_ids if self.use_mla else layer_ids * 2
|
||||
|
||||
def get_state_buf_infos(self):
|
||||
|
||||
@@ -575,7 +575,6 @@ class KimiK3MoE(nn.Module):
|
||||
self._shared_experts_attn_tp_comm = (
|
||||
get_parallel().enable_shared_experts_attn_tp
|
||||
and self._ep_a2a
|
||||
and self._dp_attention
|
||||
and get_parallel().attn_tp_size > 1
|
||||
)
|
||||
shared_experts_tp_kwargs = {}
|
||||
|
||||
Reference in New Issue
Block a user