NumPy allowed · plain Python earns 10 bonus points
Softmax(logits) → probability distribution
Maintain autoregressive key and value states during incremental decoding with optional sliding window eviction.
Implement update_kv_cache(cached_keys, cached_values, new_key, new_value, window_size=None). Verify that len(new_key) == len(new_value) and that their dimensions match existing cached entries (if any). Append new_key to cached_keys and new_value to cached_values. If window_size is specified, retain only the most recent window_size vectors, evicting older entries from the front. If window_size <= 0, raise ValueError. Return a dict containing keys, values, seq_len (int), and evicted_count (int).
update_kv_cache(cached_keys: list[list[float]], cached_values: list[list[float]], new_key: list[float], new_value: list[float], window_size: int | None = None) -> dict