Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
98aa836b
Unverified
Commit
98aa836b
authored
Jul 12, 2025
by
Cheng Wan
Committed by
GitHub
Jul 12, 2025
Browse files
Overlap the gating function with shared experts in DeepSeek (#7978)
parent
22bd857c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
python/sglang/srt/models/deepseek_v2.py
python/sglang/srt/models/deepseek_v2.py
+3
-3
No files found.
python/sglang/srt/models/deepseek_v2.py
View file @
98aa836b
...
@@ -437,21 +437,21 @@ class DeepseekV2MoE(nn.Module):
...
@@ -437,21 +437,21 @@ class DeepseekV2MoE(nn.Module):
def
forward_normal_dual_stream
(
def
forward_normal_dual_stream
(
self
,
hidden_states
:
torch
.
Tensor
,
can_fuse_mlp_allreduce
:
bool
=
False
self
,
hidden_states
:
torch
.
Tensor
,
can_fuse_mlp_allreduce
:
bool
=
False
)
->
torch
.
Tensor
:
)
->
torch
.
Tensor
:
# router_logits: (num_tokens, n_experts)
router_logits
=
self
.
gate
(
hidden_states
)
current_stream
=
torch
.
cuda
.
current_stream
()
current_stream
=
torch
.
cuda
.
current_stream
()
self
.
alt_stream
.
wait_stream
(
current_stream
)
self
.
alt_stream
.
wait_stream
(
current_stream
)
shared_output
=
self
.
_forward_shared_experts
(
hidden_states
)
shared_output
=
self
.
_forward_shared_experts
(
hidden_states
)
with
torch
.
cuda
.
stream
(
self
.
alt_stream
):
with
torch
.
cuda
.
stream
(
self
.
alt_stream
):
# router_logits: (num_tokens, n_experts)
router_logits
=
self
.
gate
(
hidden_states
)
final_hidden_states
=
self
.
experts
(
final_hidden_states
=
self
.
experts
(
hidden_states
=
hidden_states
,
router_logits
=
router_logits
hidden_states
=
hidden_states
,
router_logits
=
router_logits
)
)
if
not
_is_cuda
:
if
not
_is_cuda
:
final_hidden_states
*=
self
.
routed_scaling_factor
final_hidden_states
*=
self
.
routed_scaling_factor
current_stream
.
wait_stream
(
self
.
alt_stream
)
current_stream
.
wait_stream
(
self
.
alt_stream
)
final_hidden_states
=
final_hidden_states
+
shared_output
final_hidden_states
+
=
shared_output
if
self
.
tp_size
>
1
and
not
can_fuse_mlp_allreduce
:
if
self
.
tp_size
>
1
and
not
can_fuse_mlp_allreduce
:
final_hidden_states
=
tensor_model_parallel_all_reduce
(
final_hidden_states
)
final_hidden_states
=
tensor_model_parallel_all_reduce
(
final_hidden_states
)
return
final_hidden_states
return
final_hidden_states
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment