Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions vllm/model_executor/layers/layernorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,12 @@ def forward_native(
weight = self.weight.float()
z = z.float() if z is not None else None

assert self.activation in ["silu", "sigmoid", "swish"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest doing this in __init__ to avoid overhead during forward

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:
Expand All @@ -499,7 +502,7 @@ def forward_native(

# 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)

Expand Down
8 changes: 8 additions & 0 deletions vllm/model_executor/layers/mamba/gdn_linear_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,19 @@ def __init__(
set_weight_attrs(self.A_log, {"weight_loader": sharded_weight_loader(0)})
set_weight_attrs(self.dt_bias, {"weight_loader": sharded_weight_loader(0)})

output_gate_type = getattr(config, "output_gate_type", "silu")
if output_gate_type == "swish":
output_gate_type = "silu"
assert output_gate_type in ["silu", "swish", "sigmoid"], (
f"unsupported {output_gate_type=}"
)

self.norm = RMSNormGated(
self.head_v_dim,
eps=self.layer_norm_epsilon,
group_size=None,
norm_before_gate=True,
activation=output_gate_type,
device=current_platform.current_device(),
)

Expand Down
Loading