9/26
Part 2 of 4 · What the cache holdsLearn and do

New keys go on the time axis, after the old ones

Each step adds the new token's key and value to the cache.

# B=2, H=4 heads, 3 cached tokens, d=8
cache_k = torch.randn(2, 4, 3, 8)
# the same, for 1 new token
k_new = torch.randn(2, 4, 1, 8)
k = torch.cat([cache_k, k_new], dim=2)
print(k.shape)
torch.Size([2, 4, 4, 8])

After the heads are split, a key tensor is (B, H, T, d). Time is the only axis that grows: past first, then new.

Predict

In (B, T, C), time is axis 1. You cat on dim=1 after the head split, with 4 tokens cached and 1 new. What happens?

Pick an answer above to see the rest