How to Work Out How Much GPU Memory a KV Cache Needs
Multiply layers, heads, head size and tokens, then check the total against your GPU before you start a long conversation.
THE FIELD GUIDE
Understand model formats, context windows, quantization, embeddings, and sampling before choosing settings for a real task.
Multiply layers, heads, head size and tokens, then check the total against your GPU before you start a long conversation.
Shift the quantization difficulty from activations into weights, then check INT8 quality on your own tasks.
Enable a quantized KV cache, pick the backend and bit width, and check the quality loss is acceptable for your context length.
Use INT4 when weights are evenly spread, and FP4 when a few large weights need the wider dynamic range of a float.
Pass a BitsAndBytesConfig to from_pretrained, set the compute dtype, and check the memory footprint before you generate.
Use AWQ when a few salient weights carry most of the model behaviour, and check the result on instruction-following tasks.
Use EXL2 when you need mixed bit rates on a consumer GPU, and check the model is available in EXL2 before you…
Normalise every vector to length 1 before storing it, so cosine similarity becomes a simple dot product and rankings stay comparable.
Test embedding models in every language your documents use, and pick the one that stays consistent, not the one that wins in…
Use a Matryoshka-trained model, truncate its vectors to the size you need, and re-normalise before you store them.