Layer

MLP residual addition

×

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

xn+1=xn′+Δmlp{\htmlData{light=block-output mlp-add}{x_{n+1}}}={\htmlData{light=residual attention-add}{x'_n}}+{\htmlData{light=mlp}{\Delta_{\mathrm{mlp}}}}
in
xn′x'_n [B batch, T positions, 4096 d]Δmlp\Delta_{\mathrm{mlp}} [B batch, T positions, 4096 d]
out
xn+1x_{n+1} [B batch, T positions, 4096 d]
Sources

In codeh + self.feed_forward(…)

Open pinned code ↗

Direct evidence

Two independently normalized mechanism branches are added to their corresponding residual inputs.

model.py 236–248 ↗ · meta-llama/llama3 @ a0940f9cf706

Excerpt
        self.attention_norm = RMSNorm(args.dim, eps=args.norm_eps)
        self.ffn_norm = RMSNorm(args.dim, eps=args.norm_eps)

    def forward(
        self,
        x: torch.Tensor,
        start_pos: int,
        freqs_cis: torch.Tensor,
        mask: Optional[torch.Tensor],
    ):
        h = x + self.attention(self.attention_norm(x), start_pos, freqs_cis, mask)
        out = h + self.feed_forward(self.ffn_norm(h))
        return out