Skip to main content

KV Estimator

Pure functions for computing KV cache memory requirements. No side effects, no runtime dependencies.

kvBytesPerToken(arch, precision?)

Returns the number of bytes required to store one token’s KV cache entry.
Formula: 2 × layers × kvHeads × headDim × precisionBytes The accounts for both K and V tensors.

kvCacheForContext(arch, tokens, precision?)

Total KV cache memory for a given context length.

maxContextForMemory(arch, memoryGb, precision?)

Inverse: how many tokens fit in a given memory budget?

weightMemory(arch, precision?)

Model weight memory at the given quantization level.

Practical Examples

How many 4K sessions fit on 2× H100?

What’s the KV budget for a 128K context?