Gate, merge and project

Gated RMSNorm

×

Normalize each head’s read-out and scale every feature by SiLU of the gate.

og=RMSNorm⁡(o~)⊙SiLU⁡(z){\htmlData{light=gated-norm}{o^{g}}}=\operatorname{RMSNorm}({\htmlData{light=read-out}{\tilde o}})\odot\operatorname{SiLU}({\htmlData{light=output-gate}{z}})
in
o~\tilde o [B batch, 128 heads, 1 position, 128 value d_h]zz [B batch, 1 position, 16384 heads × d_h]
out
ogo^{g} [B batch, 128 heads, 1 position, 128 value d_h]

Unlike the model’s other norms this one is not zero-centred: its gain starts at one and multiplies directly (modeling_qwen3_5_moe.py 209, 219). The gate is SiLU (211); the configuration’s output_gate_type: "swish" names the same function and is not read by this implementation.

Parameters128 × 69 layers

128 parameters owned by this component

ComponentParameters
RMSNorm gain128

One in each of the 69 GDN layers, each with its own weights.

One gain for each of the 128 features of a head, shared by the heads.

Sources

In codeself.norm(core_attn_out, z) · 647

Open pinned code ↗

Direct evidence

The gated RMSNorm of the Gated DeltaNet output owns one weight per feature, initialised to ones: it normalises in float32, multiplies by the weight in the input’s precision, and multiplies by SiLU of the gate in float32.

modeling_qwen3_5_moe.py 206–222 ↗ · huggingface/transformers @ 18329f106538

Excerpt
class Qwen3_5MoeRMSNormGated(nn.Module):
    def __init__(self, hidden_size: int, eps: float = 1e-6, **kwargs) -> None:
        super().__init__()
        self.weight = nn.Parameter(torch.ones(hidden_size))
        self.variance_epsilon = eps
        self.activation = "silu"

    def forward(self, hidden_states: torch.Tensor, gate: torch.Tensor) -> torch.Tensor:
        input_dtype = hidden_states.dtype
        hidden_states = hidden_states.to(torch.float32)
        variance = hidden_states.pow(2).mean(-1, keepdim=True)
        # Norm before gate
        hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
        hidden_states = self.weight * hidden_states.to(input_dtype)
        hidden_states = hidden_states * ACT2FN[self.activation](gate.to(torch.float32))

        return hidden_states.to(input_dtype)

The kernel’s output passes the gated RMSNorm, gated by z, head by head, is flattened and projected to the model width.

modeling_qwen3_5_moe.py 644–651 ↗ · huggingface/transformers @ 18329f106538

Excerpt
        # reshape input data into 2D tensor
        core_attn_out = core_attn_out.reshape(-1, self.head_v_dim)
        z = z.reshape(-1, self.head_v_dim)
        core_attn_out = self.norm(core_attn_out, z)
        core_attn_out = core_attn_out.reshape(batch_size, seq_len, -1)

        output = self.out_proj(core_attn_out)
        return output

Gated DeltaNet owns one projection to queries, keys and values (2 × 16 × 128 + 128 × 128 = 20,480 channels), one depthwise causal convolution over them without bias, a projection to the output gate z as wide as the values, one projection each to the write strength b and the decay a, one per value head, a per-head A_log and dt_bias, a gated RMSNorm over each value head and an output projection.

modeling_qwen3_5_moe.py 492–535 ↗ · huggingface/transformers @ 18329f106538

Excerpt
class Qwen3_5MoeGatedDeltaNet(nn.Module):
    def __init__(self, config: Qwen3_5MoeConfig, layer_idx: int):
        super().__init__()
        self.hidden_size = config.hidden_size
        self.num_v_heads = config.linear_num_value_heads
        self.num_k_heads = config.linear_num_key_heads
        self.head_k_dim = config.linear_key_head_dim
        self.head_v_dim = config.linear_value_head_dim
        self.key_dim = self.head_k_dim * self.num_k_heads
        self.value_dim = self.head_v_dim * self.num_v_heads

        self.conv_kernel_size = config.linear_conv_kernel_dim
        self.layer_idx = layer_idx
        self.activation = config.hidden_act
        self.layer_norm_epsilon = config.rms_norm_eps

        # QKV
        self.conv_dim = self.key_dim * 2 + self.value_dim
        self.conv1d = nn.Conv1d(
            in_channels=self.conv_dim,
            out_channels=self.conv_dim,
            bias=False,
            kernel_size=self.conv_kernel_size,
            groups=self.conv_dim,
            padding=self.conv_kernel_size - 1,
        )

        # time step projection (discretization)
        # instantiate once and copy inv_dt in init_weights of PretrainedModel
        self.dt_bias = nn.Parameter(torch.ones(self.num_v_heads))

        # Lower bound kept away from 0 so log(A) never becomes -inf
        A = torch.empty(self.num_v_heads).uniform_(0.01, 16)
        self.A_log = nn.Parameter(torch.log(A))

        self.norm = Qwen3_5MoeRMSNormGated(self.head_v_dim, eps=self.layer_norm_epsilon)
        self.out_proj = nn.Linear(self.value_dim, self.hidden_size, bias=False)

        self.layer_type = config.layer_types[layer_idx]

        self.in_proj_qkv = nn.Linear(self.hidden_size, self.key_dim * 2 + self.value_dim, bias=False)
        self.in_proj_z = nn.Linear(self.hidden_size, self.value_dim, bias=False)
        self.in_proj_b = nn.Linear(self.hidden_size, self.num_v_heads, bias=False)
        self.in_proj_a = nn.Linear(self.hidden_size, self.num_v_heads, bias=False)