[DSv32] Overlap indexer weights_proj during dual_stream decode (#16637)

Co-authored-by: Ziang Li <ziangli@humansand.ai>
This commit is contained in:
Ziang Li
2026-01-10 13:06:44 +08:00
committed by GitHub
co-authored by Ziang Li
parent 32a569fb77
commit 20abaee26c
2 changed files with 64 additions and 22 deletions
+34 -11
View File
@@ -1666,6 +1666,7 @@ class DeepseekV2AttentionMLA(nn.Module):
from sglang.srt.model_executor.cuda_graph_runner import get_is_capture_mode
q_lora = None
topk_indices = None
if self.q_lora_rank is not None:
q, latent_cache = (
get_attn_tp_context()
@@ -1722,8 +1723,39 @@ class DeepseekV2AttentionMLA(nn.Module):
if self.use_nsa:
q_lora = q
k_nope = k_nope.unsqueeze(1)
q = self.q_b_proj(q)[0].view(-1, self.num_local_heads, self.qk_head_dim)
# overlap q_b_proj and indexer during decode
if (
self.alt_stream is not None
and get_is_capture_mode()
and forward_batch.forward_mode.is_decode_or_idle()
and q_lora is not None
):
current_stream = torch.cuda.current_stream()
self.alt_stream.wait_stream(current_stream)
with torch.cuda.stream(self.alt_stream):
k_nope = k_nope.unsqueeze(1)
q = self.q_b_proj(q)[0].view(
-1, self.num_local_heads, self.qk_head_dim
)
topk_indices = self.indexer(
x=hidden_states,
q_lora=q_lora,
positions=positions,
forward_batch=forward_batch,
layer_id=self.layer_id,
)
current_stream.wait_stream(self.alt_stream)
else:
k_nope = k_nope.unsqueeze(1)
q = self.q_b_proj(q)[0].view(-1, self.num_local_heads, self.qk_head_dim)
if q_lora is not None:
topk_indices = self.indexer(
x=hidden_states,
q_lora=q_lora,
positions=positions,
forward_batch=forward_batch,
layer_id=self.layer_id,
)
else:
q = self.q_proj(hidden_states)[0].view(
-1, self.num_local_heads, self.qk_head_dim
@@ -1818,15 +1850,6 @@ class DeepseekV2AttentionMLA(nn.Module):
k_nope, k_pe = self.rebuild_cp_kv_cache(
latent_cache, forward_batch, k_nope, k_pe
)
topk_indices = None
if q_lora is not None:
topk_indices = self.indexer(
x=hidden_states,
q_lora=q_lora,
positions=positions,
forward_batch=forward_batch,
layer_id=self.layer_id,
)
return (
q_pe,