Skip to content
nonconvexcard

When does attention dominate the MLP?

NumericalBeginner⏱ 30 minDeep Learningcomplexityflopslong contextmemory

Problem

For a transformer layer with width dd, sequence length nn, hh heads and MLP expansion 44:

  1. Write the FLOP counts for the attention and MLP sublayers.
  2. Find the nn at which they are equal.
  3. Evaluate for d=4096d = 4096 at n=2048n = 2048 and n=128,000n = 128{,}000.
  4. Compute the attention matrix memory in both cases and comment.

Compute the requested quantities and say what they mean. A number without an interpretation is not an answer.

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
Count the FLOPs of a forward passLLM OpsNumericalFoundation15 min
Derive the attention crossover lengthLLM OpsProofBeginner15 min
KV cache sizing with MHA and GQALLM OpsNumericalBeginner30 min
Product quantisation budget arithmeticRAGNumericalBeginner30 min
The 6ND FLOP estimateLLMsNumericalBeginner15 min