[DeepSeek V3] Reland: run routed experts on main stream in dual-stream MoE (#29463)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
45314a9fcb
commit
6bdecb8206
@@ -926,11 +926,13 @@ class DeepseekV2MoE(nn.Module):
|
||||
*,
|
||||
use_flashinfer_trtllm_bypass: bool = False,
|
||||
) -> torch.Tensor:
|
||||
# Note(kpham-sgl): launch the shared expert BEFORE the routed call.
|
||||
# The routed deep_gemm pre-permute calls `dispose_tensor` which
|
||||
# `set_()`s `hidden_states` to empty (host-side); any later kernel
|
||||
# launch consuming `hidden_states` then captures `data_ptr() == 0`
|
||||
# into the decode CUDA graph and replays from null.
|
||||
current_stream = torch.cuda.current_stream()
|
||||
self.alt_stream.wait_stream(current_stream)
|
||||
shared_output = self._forward_shared_experts(
|
||||
hidden_states, gemm_output_zero_allocator
|
||||
)
|
||||
server_args = get_global_server_args()
|
||||
dispatch_info = (
|
||||
ExpertLocationDispatchInfo.init_new(layer_id=self.layer_id)
|
||||
@@ -938,6 +940,9 @@ class DeepseekV2MoE(nn.Module):
|
||||
else None
|
||||
)
|
||||
with torch.cuda.stream(self.alt_stream):
|
||||
shared_output = self._forward_shared_experts(
|
||||
hidden_states, gemm_output_zero_allocator
|
||||
)
|
||||
# router_logits: (num_tokens, n_experts)
|
||||
router_logits = self.gate(hidden_states, gemm_output_zero_allocator)
|
||||
if use_flashinfer_trtllm_bypass:
|
||||
@@ -969,9 +974,7 @@ class DeepseekV2MoE(nn.Module):
|
||||
hidden_states, topk_output
|
||||
)
|
||||
elif use_flashinfer_trtllm_bypass:
|
||||
final_hidden_states = self.experts.forward_impl(
|
||||
hidden_states, topk_output
|
||||
)
|
||||
final_hidden_states = self.experts.forward_impl(hidden_states, topk_output)
|
||||
else:
|
||||
final_hidden_states = self.experts(hidden_states, topk_output)
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user