Element-wise product
×Gate the bounded up features by the activated gate, feature by feature.
- in
- [B batch, T positions, 2048 d_ff] [B batch, T positions, 2048 d_ff]
- out
- [B batch, T positions, 2048 d_ff]
Sources
In codeF.silu(gate) * up · 603
Direct evidence
An expert is a SwiGLU whose gate is clamped above at 10 and whose up branch is clamped to ±10, computed in float32, with the routing weight applied before the down projection.
model.py 587–606 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6
Excerpt
class Expert(nn.Module):
"""Single MoE expert: SwiGLU FFN (w1, w2, w3). Computation in float32 for stability."""
def __init__(self, dim: int, inter_dim: int, dtype=None, swiglu_limit=0):
super().__init__()
self.w1 = Linear(dim, inter_dim, dtype=dtype)
self.w2 = Linear(inter_dim, dim, dtype=dtype)
self.w3 = Linear(dim, inter_dim, dtype=dtype)
self.swiglu_limit = swiglu_limit
def forward(self, x: torch.Tensor, weights: Optional[torch.Tensor] = None) -> torch.Tensor:
dtype = x.dtype
gate = self.w1(x).float()
up = self.w3(x).float()
if self.swiglu_limit > 0:
up = torch.clamp(up, min=-self.swiglu_limit, max=self.swiglu_limit)
gate = torch.clamp(gate, max=self.swiglu_limit)
x = F.silu(gate) * up
if weights is not None:
x = weights * x
return self.w2(x.to(dtype))