Model Width, Head Count, and Head Width
Model width, head count, query-key width, and value width are separate design choices. Derive every projection shape, identify the common equal-width convention, and distinguish mathematical requirements from framework restrictions.
Multi-head attention uses several widths with different jobs:
- is the feature width entering and leaving the layer;
- is the number of attention heads;
- is the query and key width inside each head;
- is the value and head-output width inside each head.
These symbols describe an architecture. They are not automatically linked by one equation.
The Common Equal-Split Configuration
Many Transformers choose
Then the concatenated head width is
and must be divisible by . For example, with and , each head commonly uses .
This is a design convention, not the definition of multi-head attention. A valid layer may use and let map the concatenated width back to . Query-key width and value width may also differ.
Separate Projection Shapes
For each head ,
The head result has shape
Concatenating results along their feature axes gives
so the output projection has shape
Compare Two Valid Configurations
| Configuration | Concatenated width | |||||
|---|---|---|---|---|---|---|
| equal split | 12 | 3 | 4 | 4 | 12 | 12 by 12 |
| wider total values | 12 | 3 | 2 | 6 | 18 | 18 by 12 |
Both are mathematically valid. The second uses a larger combined value width and therefore a larger total projection and output projection. Calling both “three-head attention” does not make their parameter counts equal.
Divisibility Depends on the Implementation Choice
If an implementation reshapes one -wide vector directly into equal heads, then must be an integer. If it first projects into an explicit total width , only that total projected width needs to split evenly under the chosen equal-head convention.
Framework APIs often impose the common equal split for convenience. When an API rejects a configuration, distinguish a mathematical incompatibility from an interface constraint.
Q1. Derive the joined value width
A layer has heads and value width per head. Its model width is 48. What shape must have, ignoring bias vectors?
Select one choice, then check.
Hint
Solution
Write the Configuration Before the Shapes
A shape trace is ambiguous if , projection convention, and axis order are missing. State those choices first. Only then is a reshape such as justified.