Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
046118b9
Unverified
Commit
046118b9
authored
Oct 08, 2025
by
isharif168
Committed by
GitHub
Oct 07, 2025
Browse files
Add SwigluOAI implementation for CPUFusedMOE (#26347)
Signed-off-by:
Sharif Inamdar
<
sharif.inamdar@arm.com
>
parent
b32260ab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
vllm/model_executor/layers/fused_moe/cpu_fused_moe.py
vllm/model_executor/layers/fused_moe/cpu_fused_moe.py
+16
-2
No files found.
vllm/model_executor/layers/fused_moe/cpu_fused_moe.py
View file @
046118b9
...
...
@@ -13,6 +13,17 @@ def silu_and_mul(x: torch.Tensor) -> torch.Tensor:
return
F
.
silu
(
x
[...,
:
d
])
*
x
[...,
d
:]
def
swigluoai_and_mul
(
x
:
torch
.
Tensor
,
alpha
:
float
=
1.702
,
limit
:
float
=
7.0
)
->
torch
.
Tensor
:
d
=
x
.
shape
[
-
1
]
//
2
gate
,
up
=
x
[...,
:
d
],
x
[...,
d
:]
gate
=
gate
.
clamp
(
max
=
limit
)
up
=
up
.
clamp
(
min
=-
limit
,
max
=
limit
)
glu
=
gate
*
torch
.
sigmoid
(
alpha
*
gate
)
return
(
up
+
1
)
*
glu
def
grouped_topk
(
hidden_states
:
torch
.
Tensor
,
gating_output
:
torch
.
Tensor
,
...
...
@@ -247,7 +258,7 @@ class CPUFusedMOE:
apply_router_weight_on_input
:
bool
=
False
,
activation
:
str
=
"silu"
,
)
->
torch
.
Tensor
:
assert
activation
==
"silu"
,
f
"
{
activation
}
is not supported."
assert
activation
in
{
"silu"
,
"swigluoai"
}
,
f
"
{
activation
}
is not supported."
assert
not
apply_router_weight_on_input
topk_weights
,
topk_ids
=
select_experts
(
hidden_states
=
x
,
...
...
@@ -293,6 +304,9 @@ class CPUFusedMOE:
gate_up
=
F
.
linear
(
tokens_for_this_expert
,
layer_w13_weight
,
bias
=
layer_w13_bias
)
if
activation
==
"swigluoai"
:
gate_up
=
swigluoai_and_mul
(
gate_up
)
else
:
gate_up
=
silu_and_mul
(
gate_up
)
expert_out
=
F
.
linear
(
gate_up
,
layer_w2_weight
,
bias
=
layer_w2_bias
)
outputs
.
append
(
expert_out
)
...
...
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