[Qwen][Bugfix] Fixes sigmoid activation in torch impl of RMSNormGated. (#40245)

Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
This commit is contained in:
Tao He
2026-04-20 04:28:19 +00:00
committed by GitHub
parent 67ed01c353
commit 8936118134
2 changed files with 13 additions and 2 deletions
+5 -2
View File
@@ -478,9 +478,12 @@ class RMSNormGated(CustomOp):
weight = self.weight.float()
z = z.float() if z is not None else None
assert self.activation in ["silu", "sigmoid", "swish"]
act_fn = F.sigmoid if self.activation == "sigmoid" else F.silu
# Apply gating before normalization if needed
if z is not None and not self.norm_before_gate:
x = x * F.silu(z)
x = x * act_fn(z)
# RMS Normalization
if self.group_size is None:
@@ -499,7 +502,7 @@ class RMSNormGated(CustomOp):
# Apply gating after normalization if needed
if z is not None and self.norm_before_gate:
out = out * F.silu(z)
out = out * act_fn(z)
return out.to(orig_dtype)