Routed expert

Bound the up branch

×

Limit each up feature to between −10 and 10.

uˉ=clip⁡(u, −10, 10){\htmlData{light=clamp-up}{\bar u}}=\operatorname{clip}({\htmlData{light=up}{u}},\,-10,\,10)
in
uu [B batch, T positions, 3072 d_ff]
out
uˉ\bar u [B batch, T positions, 3072 d_ff]
Sources

In codetorch.clamp(up, min=-self.swiglu_limit, max=self.swiglu_limit) · 601

Open pinned code ↗

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-Pro @ b5968e9190ef

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

The reference configuration: 61 layers of width 7,168, 128 heads of 512 features with a 64-feature rotary part, a 1,536-feature query latent, a grouped output of 16 groups at rank 1,024, a window of 128, the per-layer compression ratios (128, 128, then 4 and 128 alternating, and 0 for the MTP block), an indexer of 64 heads of 128 keeping 1,024, hyper-connections of 4 streams with 20 Sinkhorn iterations, 384 routed experts of 3,072 of which 6 are used with 1 shared, square-root-softplus scores scaled by 2.5, three hash-routed layers, and YaRN over 65,536 positions.

config.json 1–34 ↗ · deepseek-ai/DeepSeek-V4-Pro @ b5968e9190ef

Excerpt
{
    "vocab_size": 129280,
    "dim": 7168,
    "moe_inter_dim": 3072,
    "n_layers": 61,
    "n_hash_layers": 3,
    "n_heads": 128,
    "n_routed_experts": 384,
    "n_shared_experts": 1,
    "n_activated_experts": 6,
    "score_func": "sqrtsoftplus",
    "route_scale": 2.5,
    "swiglu_limit": 10.0,
    "q_lora_rank": 1536,
    "head_dim": 512,
    "rope_head_dim": 64,
    "o_groups": 16,
    "o_lora_rank": 1024,
    "window_size": 128,
    "original_seq_len": 65536,
    "rope_theta": 10000,
    "rope_factor": 16,
    "beta_fast": 32,
    "beta_slow": 1,
    "index_n_heads": 64,
    "index_head_dim": 128,
    "index_topk": 1024,
    "hc_mult": 4,
    "hc_sinkhorn_iters": 20,
    "dtype": "fp8",
    "scale_fmt": "ue8m0",
    "expert_dtype": "fp4",
    "compress_rope_theta": 160000,
    "compress_ratios": [128, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 128, 4, 0]