Sliding-window layer

Add MoE update

×

Add the mechanism’s update to the residual stream element by element.

hnext=h′+Δffn{\htmlData{light=block-output ffn-add}{h_{\mathrm{next}}}}={\htmlData{light=residual attention-add}{h'}}+{\htmlData{light=moe}{\Delta_{\mathrm{ffn}}}}
in
h′h' [B batch, 1 position, 6144 d]Δffn\Delta_{\mathrm{ffn}} [B batch, 1 position, 6144 d]
out
hnexth_{\mathrm{next}} [B batch, 1 position, 6144 d]
Sources

In coderesidual + hidden_states · 441

Open pinned code ↗

Direct evidence

A layer is pre-norm: attention reads the normalised input and its output is added to the residual; the feed-forward reads the normalised sum and its output is added again.

modeling_mimo_v2.py 413–442 ↗ · XiaomiMiMo/MiMo-V2.6-Pro-RL @ b61f21852680

Excerpt
    def forward(
        self,
        hidden_states: torch.Tensor,
        attention_mask: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.LongTensor] = None,
        past_key_values: Optional[Cache] = None,
        use_cache: Optional[bool] = False,
        cache_position: Optional[torch.LongTensor] = None,
        position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None,
        **kwargs: Unpack[TransformersKwargs],
    ) -> torch.Tensor:
        residual = hidden_states
        hidden_states = self.input_layernorm(hidden_states)
        hidden_states, _ = self.self_attn(
            hidden_states=hidden_states,
            attention_mask=attention_mask,
            position_ids=position_ids,
            past_key_values=past_key_values,
            use_cache=use_cache,
            cache_position=cache_position,
            position_embeddings=position_embeddings,
            **kwargs,
        )
        hidden_states = residual + hidden_states

        residual = hidden_states
        hidden_states = self.post_attention_layernorm(hidden_states)
        hidden_states = self.mlp(hidden_states)
        hidden_states = residual + hidden_states
        return hidden_states