Transformer block › Attention
Q, K, V split
×no parameterstf.split(c, 3, axis=2)
Split the fused 2,304 features into three 768-feature tensors: queries, keys, and values.
- in
- [B batch, 1 position, 2304 q, k, v]
- out
- [B batch, 1 position, 768 d]
Codemodel.py 75–103
def split_heads(x): return tf.transpose(split_states(x, hparams.n_head), [0, 2, 1, 3]) q, k, v = map(split_heads, tf.split(c, 3, axis=2))Sources1
Direct evidence
The fused field is split three ways and each result is reshaped into the head axis.
openai · openai/gpt-2 / src/model.py
Pinned revision 9b63575ef427 ↗ · lines 75–103
Read code excerpt
def split_heads(x):… lines 76–76 omitted …
return tf.transpose(split_states(x, hparams.n_head), [0, 2, 1, 3])… lines 78–102 omitted …
q, k, v = map(split_heads, tf.split(c, 3, axis=2))