KV-cache memory

The KV-cache challenge

Two questions you can check by hand, then a calculator for every factor. Every number here is exact arithmetic.

prediction firstanswers kept in this browserno account

One question, before anything is revealed

Hold batch, layers, sequence length, head dimension, and precision fixed. Query heads stay at 32. Cached key/value heads fall from 32 to 8. What is the exact KV-cache ratio?

Batch
1
Layers
32
Sequence length
8,192
Head dimension
128
Precision
fp16/bf16

The same model as the site's worked KV-cache reference, at twice its sequence length (8,192 positions instead of 4,096), so the numbers here are new.

Your prediction

The MHA cache is how many times the size of the new grouped-query cache?

times the size

A wrong number is more useful than none: it shows which factor you were tracking. Just show me opens the equation, the second question and the calculator without recording a prediction.

What this page is and is not

Calculated here

The bytes of the key and value tensors, from the equation shown, in decimal GB. Every number on this page is exact arithmetic you can redo by hand.

Not measured here

Nothing on this page is a benchmark: no latency, throughput, memory overhead or model quality was measured.

Where your answers live

In this browser only. They are not sent anywhere, and no account or email is needed. Clearing this site's data in your browser removes them.