New Tool Radar

AI Concepts

How to Choose a Quantization Level That Fits Your VRAM

Pick the quantization level that fits the model in your available VRAM, with room left for the KV cache.

Schematic illustration with three step boxes: count the weights, add the KV cache, and pick the level.

Weight memory is roughly parameters times bits per weight divided by 8: an 8B model in BF16 needs about 16 GB, and in Q4_K_M about 4.9 GB. But weights are only part of what a server needs: the KV cache holds the context of every running request and has to fit next to them. A level that fits the weights but leaves no room for context will fail on the first long prompt.

Before you start

The parameter count of your model, the VRAM on your card, and the longest context you must serve.

Count the weights at each level

Work out the weight memory at 16, 8 and 4 bits: parameters in billions times bits per weight divided by 8. An 8B model is about 16 GB at 16 bits, 8 GB at 8 bits and 4.9 GB at Q4_K_M, which averages 4.89 bits per weight.

Check the real file size too: published files run a little larger than the arithmetic, because most formats keep embedding and output layers in 16 bits.

Add the KV cache for your longest context

Estimate the KV cache for your longest context and your expected concurrent users, and add it to the weight memory. A 4-bit 70B model on a 48 GB card leaves room for about 14,000 tokens of context, which shows how fast the cache eats the space the weights saved.

If the cache does not fit, either shorten the context, serve fewer users at once, or quantize the cache as well as the weights.

Pick the highest level that fits

Pick the highest bit-width whose weights plus KV cache fit in VRAM with room to spare. Higher bits cost more memory and lose less quality, so the best level is the highest one that fits, not the smallest one that runs.

Write the arithmetic down with the model, the level and the context length, so the next person can check it.

Practice check: fictional Maple Corner 8B model, 24 GB card, 8,000-token context

The table below is fictional practice material, worked out by hand from the stated formula. It is the expected result for the practice setup, not a run of any server.

Level Weights KV cache Total Verdict
BF16 16.0 GB 1.0 GB 17.0 GB Pass – fits
Q8_0 8.5 GB 1.0 GB 9.5 GB Pass – room to spare
Q4_K_M 4.9 GB 1.0 GB 5.9 GB Pass – most room
Q2_K 3.0 GB 1.0 GB 4.0 GB Pass, quality fails

All four levels fit the weights plus cache on a 24 GB card, so the choice turns on quality, not size: Q8_0 is the highest level that fits comfortably, and Q2_K is rejected on quality, not on memory.

Expected result. UNTESTED: the memory figures in the practice table are worked out by hand from the stated formula, not measured by running any server. Work out weights plus KV cache for your own model, card and context length, and pick the highest level that fits.

Limits

  • The formula leaves out activations, kernel workspaces and fragmentation, so leave a safety margin in VRAM.
  • File sizes on model hubs run above the plain arithmetic, because embedding and output layers stay in 16 bits.

Sources

See all