New Tool Radar

AI Concepts

How to Work Out Whether a Quantized Model Fits Your GPU Memory Budget Before Downloading It

Multiply parameters by bytes per weight at the target precision, add room for the KV cache and activations, and compare the total with free GPU memory.

Schematic with three steps: Compute the weights size; Add room for the KV cache and; Compare with free GPU memory and choose.

Downloading a model you cannot load wastes time and disk, so do the arithmetic first. The Hugging Face quantization overview gives the rule of thumb: models usually load in bf16 at 2 bytes per parameter, so an 8B model needs about 16GB for its weights in bf16, about 8GB at 8 bits, and about 4 to 5GB at 4 bits. Weights are not the whole story: the KV cache, activations and the framework itself also need memory, so leave headroom.

What you need

  • The model parameter count
  • The target precision in bits
  • The free memory on your GPU

Step 1: Compute the weights size

Multiply the parameter count by the bytes per weight at the target precision: 2 bytes at bf16, 1 byte at 8 bits, about half a byte at 4 bits. An 8B model is about 16GB at bf16, 8GB at 8 bits, and 4 to 5GB at 4 bits.

Step 2: Add room for the KV cache and activations

Add memory for the KV cache, which grows with context length and batch size, plus activations and framework overhead. A long context can need several extra gigabytes, so a model that only just fits its weights will run out of memory during generation.

Step 3: Compare with free GPU memory and choose

Compare the total with the free memory on your GPU. If it does not fit, drop to a lower precision, shorten the context, or pick a smaller model, before downloading anything.

Worked example: synthetic memory budget for an 8B model

The table below is a synthetic example. It shows the expected result of budgeting memory; no model was loaded.

Precision Weights size Fits in 12GB?
bf16 About 16GB No
8-bit About 8GB Yes, with room
4-bit About 4 to 5GB Yes, with room
4-bit, long context About 4 to 5GB plus cache Check the cache size

Expected result (UNTESTED). the 8B model fits at 8-bit and 4-bit in 12GB, but not at bf16, and a long context needs a separate cache check. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • The rule of thumb covers weights only: the KV cache, activations and optimizer state are extra.
  • Some GGUF models are dequantized to full precision as they load, so they use as much memory as an unquantized model.
  • A quantized model that fits may still be slow if the hardware lacks a fast kernel for its format.
  • Use the quantization picker in the Transformers docs to check whether a model fits your hardware at each precision.

Sources

See all