12/42
Part 2 of 6 · Split the headsLearn

All three in one line

q, k and v all need the same split, so one line does all three.

q, k, v = (t.view(B, T, H, d).transpose(1, 2) for t in (q, k, v))
print(tuple(q.shape), tuple(k.shape), tuple(v.shape))
(2, 4, 5, 3) (2, 4, 5, 3) (2, 4, 5, 3)

t.view(B, T, H, d).transpose(1, 2) is what happens to each t, and for t in (q, k, v) runs it on all three. q, k, v = unpacks the three results back into the same names.