32 independent transformer blocks › Attention
Merge heads
×no parametersoutput.transpose(1, 2).contiguous().view(bsz, seqlen, -1)
Join all retrieved head features into the model-width field.
- in
- [B batch, 32 q heads, 1 positions, 128 d_h]
- out
- [B batch, 1 positions, 4096 d]
Explanation
Heads are concatenated in order: head fills features .
Codemodel.py 188–189
output = torch.matmul(scores, values) # (bs, n_local_heads, seqlen, head_dim)
output = output.transpose(1, 2).contiguous().view(bsz, seqlen, -1)Sources1
Direct evidence
The head output is transposed and reshaped into the full model-width field.
attn-merge · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 188–189
Read code excerpt
output = torch.matmul(scores, values) # (bs, n_local_heads, seqlen, head_dim)
output = output.transpose(1, 2).contiguous().view(bsz, seqlen, -1)