SwiGLU

Normalized MLP input

×

Normalized residual features feeding both MLP branches.

shape
xx [B batch, T positions, 4096 d]
Sources

In codeself.ffn_norm(h)

Open pinned code ↗

Contextual evidence

Attention receives attention_norm(x) and its update is added to x; the MLP receives ffn_norm(h) and its update is added to h.

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