18/42
Part 3 of 6 · The worked exampleLearn
Transpose back, then join each position's pieces
After attention, the heads have to go back together.
heads = q.view(B, T, H, d).transpose(1, 2).contiguous()
print(heads.transpose(1, 2).reshape(B, T, C))
tensor([[[ 0, 1, 2, 3],
[10, 11, 12, 13],
[20, 21, 22, 23]]])
Here heads stands in for att @ v: every head's output at every position, (B, H, T, d), in a fresh tensor. The rows come back exactly as they went in.
Undo the split in reverse:
(B, H, T, d). Every head's output at every position