Skip to content
Closed
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
6 changes: 6 additions & 0 deletions vllm/model_executor/models/deepseek_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def __init__(
quant_config: QuantizationConfig | None = None,
reduce_results: bool = True,
is_sequence_parallel=False,
swiglu_limit: float | None = None,
prefix: str = "",
) -> None:
super().__init__()
Expand Down Expand Up @@ -226,9 +227,14 @@ def __init__(
f"Unsupported activation: {hidden_act}. Only silu is supported for now."
)
self.act_fn = SiluAndMul()
self.swiglu_limit = swiglu_limit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: avoid cast at runtime?

Suggested change
self.swiglu_limit = swiglu_limit
self.swiglu_limit = float(swiglu_limit) if swiglu_limit is not None else None


def forward(self, x):
gate_up, _ = self.gate_up_proj(x)
if self.swiglu_limit is not None:
lim = float(self.swiglu_limit)
g, u = gate_up.chunk(2, dim=-1)
gate_up = torch.cat([g.clamp(max=lim), u.clamp(min=-lim, max=lim)], dim=-1)
x = self.act_fn(gate_up)
x, _ = self.down_proj(x)
return x
Expand Down
1 change: 1 addition & 0 deletions vllm/model_executor/models/deepseek_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def __init__(
hidden_act=config.hidden_act,
quant_config=quant_config,
reduce_results=False,
swiglu_limit=self.swiglu_limit,
prefix=f"{prefix}.shared_experts",
)

Expand Down