How many parameters does a multi-head self-attention layer with and heads have (with biases)? Does the number of heads change the count? How many does a full transformer encoder layer with feed-forward width have?
Sequence models and transformers, Attention
Level L2 Elementary. Length Short. Nature Mat Mathematical.
What's being asked
Whether you know the shapes of the per-head projections, and that heads split rather than multiply it.
Key idea
Each of (the query, key, value and output projections) is with a bias of size , where . The heads, each of size , are just slices of these matrices. So the count is , independent of .
Steps
- Per head: , since . Concatenating 8 heads gives for each of .
- Output projection: .
- Total: .
- Changing changes how the dimensions are split, not the count.
- Encoder layer: the feed-forward network (two linear layers, ) has parameters. The two layer norms have (a and a each). Total: , about .
Common mistakes
- Giving each head its own matrices, which overcounts by a factor of .
- Forgetting .
- Forgetting the biases, or the layer norm and , when asked for the full layer.
How long your answer should be
4–5 lines of arithmetic.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: What are the time and memory costs of one self-attention layer for sequence length and model dimension ? For and , which part dominates?
Next in Sequence models and transformers: A language model assigns probabilities , , and to the four tokens of a test sentence (each conditioned on the tokens before it). What is the perplexity? What is the perplexity of a model that is uniform over a vocabulary of size ?