Assume GPT-2 small has 12 layers, d=768, feed-forward width 3072, vocabulary 50,257 and context length 1024 with learned positional embeddings, and output weights tied to the token embedding, where each projection has a bias and each layer has two layer norms. How many parameters does it have?

Sequence models and transformers, Transformers
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can count parameters systematically by component and arrive at the well-known ≈124 million.

Key idea

One block has 12d2+13d parameters (attention 4d2+4d, MLP 8d2+5d, two layer norms 4d), so the model has about 12Ld2 block parameters plus the embeddings.

Steps

  1. Attention: WQ,WK,WV,WO are four d×d matrices with biases, so 4d2+4d.
  2. MLP: d→4d has 4d2+4d and 4d→d has 4d2+d, so 8d2+5d.
  3. Two layer norms, each with scale and shift: 2×2d=4d.
  4. Per block: 12d2+13d=12(589,824)+9,984=7,087,872.
  5. Twelve blocks: 85,054,464.
  6. Token embedding: 50,257×768=38,597,376. Positional embedding: 1024×768=786,432. Final layer norm: 2×768=1,536. The output projection reuses the token embedding, so it adds nothing.
  7. Total =85,054,464+38,597,376+786,432+1,536=124,439,808≈124 million.

Common mistakes

How long your answer should be

Half a page with a small table; 5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Sequence models and transformers: Count the matrix-multiply FLOPs of one transformer layer's forward pass for sequence length n=2048, model width d=1024 and feed-forward width dff=4d (one sequence, ignoring softmax, layer norm and biases). Which part dominates, and at what n does attention's n2 term equal the linear-in-n part?
Next in Sequence models and transformers: A corpus has the words low (×5), lower (×2), newest (×6) and widest (×3), each split into characters. BPE merges the most frequent adjacent pair. WordPiece merges the pair with the highest score c(ab)c(a) c(b). Which pair does each choose first, and why do they differ?