Query–key dot product
×Measure the feature agreement of rotated queries and their grouped keys.
- in
- [B batch, 32 q heads, 1 position, 128 d_h] [B batch, 32 q heads, 1001 positions, 128 d_h]
- out
- [B batch, 32 q heads, 1 query, 1001 keys]
Sources
In codetorch.matmul(xq, keys.transpose(2, 3))
Direct evidence
Queries multiply transposed keys over their common head-feature axis.
model.py 179–184 ↗ · meta-llama/llama3 @ a0940f9cf706
Excerpt
xq = xq.transpose(1, 2) # (bs, n_local_heads, seqlen, head_dim)
keys = keys.transpose(1, 2) # (bs, n_local_heads, cache_len + seqlen, head_dim)
values = values.transpose(
1, 2
) # (bs, n_local_heads, cache_len + seqlen, head_dim)
scores = torch.matmul(xq, keys.transpose(2, 3)) / math.sqrt(self.head_dim)