Implement a KVCache and the single-token attention step that uses it.
KVCache
append(self, k, v) - concatenate the new keys and values onto the cache along the sequence dimension and return the full (k, v) so far. Tensors are shaped (batch, heads, seq, head_dim), so the sequence dimension is dim=2.__len__(self) - number of cached positions (0 when empty).reset(self) - empty the cache.attend_with_cache(q, k_new, v_new, cache)
k_new/v_new to the cache, then attend q over everything cached so far.torch.cat([...], dim=2) grows the cache.q.shape[-1] ** 0.5, not by the sequence length.