Reshape into attention heads
×Reshape and permute Q, K, and V independently into 12 heads of width 64.
- in
- [B batch, 1, 768 d] [B batch, 1, 768 d] [B batch, 1, 768 d]
- out
- [B batch, 12 heads, 1, 64 d_h]
Sources
In codemap(split_heads, tf.split(c, 3, axis=2))
Direct evidence
The released split_heads function introduces a head axis and moves it before the position axis.
model.py 75–79 ↗ · openai/gpt-2 @ 9b63575ef427
Excerpt
def split_heads(x):… lines 76–76 omitted …
return tf.transpose(split_states(x, hparams.n_head), [0, 2, 1, 3])