[NPU] enable index Cache for npu (#21502)
This commit is contained in:
@@ -302,6 +302,7 @@ def forward_dsa_prepare_npu(
|
|||||||
forward_batch: "ForwardBatch",
|
forward_batch: "ForwardBatch",
|
||||||
zero_allocator: "BumpAllocator",
|
zero_allocator: "BumpAllocator",
|
||||||
layer_scatter_modes,
|
layer_scatter_modes,
|
||||||
|
prev_topk_indices: torch.Tensor = None,
|
||||||
):
|
):
|
||||||
dynamic_scale = None
|
dynamic_scale = None
|
||||||
if is_mla_preprocess_enabled() and forward_batch.forward_mode.is_decode():
|
if is_mla_preprocess_enabled() and forward_batch.forward_mode.is_decode():
|
||||||
@@ -401,15 +402,18 @@ def forward_dsa_prepare_npu(
|
|||||||
latent_cache, forward_batch, k_nope, k_pe
|
latent_cache, forward_batch, k_nope, k_pe
|
||||||
)
|
)
|
||||||
|
|
||||||
topk_indices = m.indexer(
|
if m.skip_topk:
|
||||||
hidden_states,
|
topk_indices = prev_topk_indices
|
||||||
q_lora,
|
else:
|
||||||
positions,
|
topk_indices = m.indexer(
|
||||||
forward_batch,
|
hidden_states,
|
||||||
m.layer_id,
|
q_lora,
|
||||||
layer_scatter_modes,
|
positions,
|
||||||
dynamic_scale,
|
forward_batch,
|
||||||
)
|
m.layer_id,
|
||||||
|
layer_scatter_modes,
|
||||||
|
dynamic_scale,
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
q_pe,
|
q_pe,
|
||||||
@@ -472,7 +476,10 @@ def forward_dsa_core_npu(
|
|||||||
attn_bmm_output = attn_bmm_output.reshape(-1, m.num_local_heads * m.v_head_dim)
|
attn_bmm_output = attn_bmm_output.reshape(-1, m.num_local_heads * m.v_head_dim)
|
||||||
|
|
||||||
output, _ = m.o_proj(attn_bmm_output)
|
output, _ = m.o_proj(attn_bmm_output)
|
||||||
return output
|
if not m.next_skip_topk:
|
||||||
|
return output, None
|
||||||
|
else:
|
||||||
|
return output, topk_indices
|
||||||
|
|
||||||
|
|
||||||
def npu_mla_preprocess(
|
def npu_mla_preprocess(
|
||||||
|
|||||||
@@ -1467,6 +1467,7 @@ class DeepseekV2AttentionMLA(
|
|||||||
forward_batch,
|
forward_batch,
|
||||||
zero_allocator,
|
zero_allocator,
|
||||||
layer_scatter_modes,
|
layer_scatter_modes,
|
||||||
|
prev_topk_indices,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|||||||
Reference in New Issue
Block a user