After attention mixes information across positions, every token passes through a position-wise feed-forward network (FFN) — the same small MLP applied independently to each position. The FFN expands d_model up to d_ff (the "intermediate" dimension, typically 4× d_model), applies a non-linear activation, and projects back down.
The expand-then-contract pattern is the point. The intermediate representation has 4x as many dimensions as d_model, giving the FFN room to compute non-linear functions of features the attention layer extracted. The projection back down reuses learned reductions to compress the result back into d_model.
How much of the parameter budget lives here
For a typical decoder block with d_model=4096 and d_ff=14336 (Llama 3 8B):
- Attention: 4 × d_model² = 67M parameters per layer.
- FFN (SwiGLU, 3 matrices): 3 × d_model × d_ff ≈ 176M parameters per layer.