Raw similarities
×Query–key dot products before scaling and causal masking.
- shape
- [B batch, 32 q heads, 1 query, 1001 keys]
Sources
In codetorch.matmul(xq, keys.transpose(2, 3))
Contextual 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)