In a 7B transformer, do attention or MLP layers eat more FLOPs, and does context length change the answer?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Inside a standard 7B decoder-only transformer block (multi-head attention + a GLU-style MLP), which sub-layer dominates the FLOP budget at short context (say 2k tokens)? Does the answer flip at long context (say 128k tokens), and why?
MLP dominates at short context (about 2/3 of FLOPs at 2k). Attention's O(n^2) terms overtake at long context, crossover near 8-16k for typical 7B configs.
Picture two workers handling letters in a mailroom. The first worker sorts each letter by recipient, that work grows in step with how many letters there are. Ten letters means ten sorts, a hundred letters means a hundred sorts. The second worker checks every letter against every other letter to find duplicates, so a hundred letters means ten thousand checks. With only a few letters, the first worker is way busier because there is more to do per letter. Once the stack gets tall enough, the second worker takes the lead because their workload grows much faster. MLP and attention split the work the same way: MLP is the per-letter sorter, attention is the pairwise checker.
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.
6-8 min: per-block FLOP breakdown + concrete numbers at 2k and 128k for 7B + crossover length analysis + FlashAttention as memory optimization + MoE wrinkle + decode-phase bandwidth story.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming attention is always the dominant cost. At short context the MLP wins comfortably; attention only overtakes once the n^2 terms grow past the linear MLP work.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.