Feed-Forward Network
A feed-forward network maps each position independently through dense layers and nonlinearities. In Transformers, the feed-forward network is the token-wise MLP between attention blocks.
For token matrix :
where , , is the hidden expansion width, is an activation function, and preserves the residual dimension.
Transformer FFN
A pre-norm Transformer usually applies:
The FFN does not mix tokens by itself. Token mixing comes from attention, recurrence, convolution, or message passing. The FFN changes the representation at each token after information has been mixed.
Parameter and Compute Scale
For hidden width and expansion width , a two-layer FFN has approximately:
parameters including biases. If , the FFN parameter count is roughly:
per block. This is often a large fraction of Transformer parameters and compute.
For a sequence length , token-wise FFN cost scales as:
unlike attention’s dense token-mixing cost, which often includes an term.
Gated FFN
Many modern models use a gated variant:
Here is elementwise multiplication. The gate controls which hidden features pass through, linking FFNs to gating and mixture-style computation.
Common gated variants include GLU-style, GEGLU-style, and SwiGLU-style FFNs. The paper note GLU Variants Improve Transformer is the canonical reference in this wiki for reading those variants as Transformer architecture blocks:
The gate changes both capacity and parameter count, so comparisons should state the expansion ratio and whether the total parameter budget is matched.
Role in Different Architectures
| Architecture | FFN Role | What Mixes Positions |
|---|---|---|
| Transformer | token-wise channel mixing after attention | self-attention |
| MLP-Mixer style model | channel mixing and sometimes token mixing through separate MLPs | token-mixing MLP |
| Graph network | node-wise update after aggregation | message passing |
| CNN/ViT hybrid | channel mixing after spatial mixing | convolution or attention |
| MoE model | sparse expert FFNs | router selects experts |
The phrase “MLP block” can mean channel-only mixing or token mixing depending on the architecture. State the axis.
Canonical Papers
| Paper | Why It Matters |
|---|---|
| MLP-Mixer | makes token-axis and channel-axis MLP mixing explicit in a vision backbone |
| GLU Variants Improve Transformer | canonical note for gated Transformer FFN variants |
Checks
- Does the block mix tokens, or only transform each token independently?
- What is the expansion ratio ?
- Is the activation ReLU, GELU, SiLU, GLU, or another gated form?
- Does the output dimension match the residual connection?
- Is dropout, normalization, or routing applied inside the FFN?
- Is parameter count matched when comparing gated, MoE, or wider FFNs?
- Which axis is mixed: channel, token, node, spatial location, or expert route?