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
4799ca5f
Commit
4799ca5f
authored
Mar 03, 2026
by
laibao
Browse files
fix: 修复 RMSNormGated 输出类型不一致问题
parent
d146a231
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
vllm/model_executor/layers/layernorm.py
vllm/model_executor/layers/layernorm.py
+9
-4
No files found.
vllm/model_executor/layers/layernorm.py
View file @
4799ca5f
...
...
@@ -458,16 +458,18 @@ class RMSNormGated(CustomOp):
- norm_before_gate=True: out = norm(x) * silu(z)
- norm_before_gate=False: out = norm(x * silu(z))
"""
input_dtype
=
x
.
dtype
# Apply gating before normalization if needed
if
z
is
not
None
and
not
self
.
norm_before_gate
:
x
=
x
*
F
.
silu
(
z
)
x
=
torch
.
mul
(
x
,
F
.
silu
(
z
)
)
# RMS Normalization
if
self
.
group_size
is
None
:
# Standard RMS norm across the last dimension
variance
=
x
.
pow
(
2
).
mean
(
dim
=-
1
,
keepdim
=
True
)
x_normed
=
x
*
torch
.
rsqrt
(
variance
+
self
.
eps
)
out
=
x_normed
*
self
.
weight
out
=
torch
.
mul
(
x_normed
,
self
.
weight
)
else
:
# Group RMS norm
from
einops
import
rearrange
...
...
@@ -475,11 +477,14 @@ class RMSNormGated(CustomOp):
x_group
=
rearrange
(
x
,
"... (g d) -> ... g d"
,
d
=
self
.
group_size
)
variance
=
x_group
.
pow
(
2
).
mean
(
dim
=-
1
,
keepdim
=
True
)
x_normed
=
x_group
*
torch
.
rsqrt
(
variance
+
self
.
eps
)
out
=
rearrange
(
x_normed
,
"... g d -> ... (g d)"
)
*
self
.
weight
out
=
torch
.
mul
(
rearrange
(
x_normed
,
"... g d -> ... (g d)"
)
,
self
.
weight
)
# Apply gating after normalization if needed
if
z
is
not
None
and
self
.
norm_before_gate
:
out
=
out
*
F
.
silu
(
z
)
out
=
torch
.
mul
(
out
,
F
.
silu
(
z
))
if
out
.
dtype
!=
input_dtype
:
out
=
out
.
to
(
input_dtype
)
return
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