Heavy-Hitter KV Cache Eviction (H2O)

hard
Unit 25 · Inference III0/0 to milestone

H2O (Zhang et al., 2023) keeps the KV cache small by observing that a few "heavy-hitter" tokens receive most of the attention. It keeps the tokens with the highest accumulated attention, plus a window of the most recent tokens.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Heavy-Hitter KV Cache Eviction (H2O) · TechGradify