KV Cache Calculator

Live sizing for transformer KV-cache memory. Supports standard MHA as well as GQA/MQA through the number of KV heads.

Used only for comparison with standard MHA.

Results

KV bytes per token / sequence
KV cache per sequence
Total KV cache for batch
KV vector width

Memory breakdown

QuantityValue
K elements per token per layer
V elements per token per layer
K+V elements per token per layer
K+V bytes per token across all layers
Total elements cached
Total bytes cached

Core formula

KV bytes = B × N × L × 2 × n_kv × d_h × bytes_per_element 2 = K + V n_kv = number of KV heads d_h = head dimension