Complete the KVCacheDecoder class so it produces identical outputs to the naive decoder but avoids redundant KV computation during autoregressive generation.
Autoregressive transformer decoding generates one token at a time. Without a KV cache, every new token requires recomputing K and V for ALL previous tokens, resulting in O(n^2) total compute for n tokens. A KV cache stores previously computed K and V values, so each decode step only computes Q/K/V for the single new token and reuses everything else. This is the standard optimization used in every production LLM serving system (vLLM, TGI, etc.). Your task is to implement this from scratch using NumPy.
Ask me about the code, bugs, or concepts.
I'll guide you in plain English, no code output.
Budget: 50K tokens per lab