What does 'position-wise' actually mean for the transformer FFN sublayer?
Position-wise means the same FFN weight set is applied independently to every token in the sequence.
Imagine a transformer block as a two-stage assembly line. The first stage, attention, is a group meeting where every word talks to every other word and gathers context. The second stage, the FFN, is a private booth where each word goes in alone, gets reshaped according to a fixed recipe, and comes back out. Crucially, the recipe is the same for every word; nothing about the booth changes between word 1 and word 100. Also, two words in two adjacent booths never see each other. The booth is private and per-word. The booth's only job is to transform a single word; the group meeting was where the cross-talk happened.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: precise meaning of position-wise, the (B, T, D) reshape test, why attention and FFN have different roles, the O(n) vs O(n^2) asymptotic split, mechanistic implication for FFN-as-memory, MoE as the natural extension.
| Property | Attention sublayer | FFN sublayer (position-wise) |
|---|---|---|
| Cross-token mixing | Yes, reads and writes across positions | No, operates per position |
| Cost in seq_len | O(n^2 * d_model) | O(n * d_model * d_ff) |
| Weight sharing across positions | Yes (Q, K, V, O matrices shared) | Yes (W_up, W_down shared) |
| Permutation behavior | Permutation-equivariant given positional encoding | Permutation-equivariant |
| Per-token output depends on | All tokens in the sequence | Only that token |
| Role in mechanistic story | Routing / cross-token information transfer | Per-token knowledge retrieval and transformation |
Real products, models, and research that use this idea.
- PyTorch's nn.Linear applied to a (B, T, D) tensor is automatically position-wise: it operates on the last dimension and broadcasts across batch and sequence.
- FlashAttention is concerned only with the attention sublayer; the FFN sublayer needs no special kernel because its position-wise nature already saturates GPU tensor cores.
- MoE designs like Mixtral and DeepSeek route each token independently to a subset of expert FFNs. This per-token routing only makes sense because the FFN is position-wise.
- Mechanistic interpretability work (Geva et al. 2021 on FFN as key-value memory; Anthropic's circuits work) all relies on the position-wise FFN structure to define per-token 'features' cleanly.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf the FFN is position-wise, why is it not just called a 'token-wise MLP'?
QHow does this design relate to mechanistic interpretability claims that 'FFNs store facts' and 'attention does routing'?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking 'position-wise' means the weights vary by position. It means the opposite: the weights are SHARED across positions and the operation is applied INDEPENDENTLY at each position.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.