Sub topic 11
Fitting Larger Models with Quantization
What quantization changes
Prerequisites: you should understand GPU memory, model weights, and the basic vllm serve command.
Quantization stores model numbers with fewer bits. A standard half-precision model uses 16 bits per weight. An 8-bit model uses about half the weight memory, and a 4-bit model uses about one quarter. This can let a model fit on a GPU that could not load the original weights.
Quantization mainly reduces the memory used by model weights. It does not remove the KV cache, temporary activations, or scheduler overhead. A quantized model can therefore load successfully but still run out of memory when many long requests are active.
| Format | Approximate weight memory | Typical trade-off |
|---|---|---|
| FP16 or BF16 | 2 bytes per parameter | Best quality and broad compatibility |
| INT8 | 1 byte per parameter | Small quality change, moderate savings |
| INT4 | 0.5 bytes per parameter | Large savings, possible quality and speed changes |
The actual memory use includes metadata and runtime buffers, so these values are estimates.
Choosing a quantization method
Common weight-only formats include AWQ and GPTQ. They store weights at low precision while keeping some calculations at a higher precision. The model must have a checkpoint prepared for the selected format. Adding a flag to an unquantized checkpoint does not quantize it automatically.
Use the model card to check:
- The supported quantization method.
- The intended GPU architecture.
- Whether the checkpoint is compatible with your vLLM version.
- The expected quality and performance.
- Whether the model uses a custom architecture or tokenizer.
A quantized model may use less memory but generate tokens more slowly if its kernels are less optimized for your GPU. Test the complete workload rather than comparing only startup memory.
Loading a quantized checkpoint
For an AWQ checkpoint, select the quantization method when starting the server:
vllm serve TheBloke/Mistral-7B-Instruct-v0.2-AWQ \
--quantization awq \
--dtype half \
--max-model-len 4096 \
--gpu-memory-utilization 0.90The checkpoint name is an example. Replace it with a compatible model from the Hugging Face Hub. Some checkpoints declare their quantization configuration in the model files, so the explicit --quantization option may be unnecessary. If vLLM reports an unsupported method or kernel, use a compatible checkpoint, update the deployment, or choose another format.
Quantization does not replace context-length tuning. Reducing --max-model-len limits the maximum KV-cache allocation and may be necessary even after the weights fit.
Quantization versus other options
Choose quantization when the model almost fits on the available GPUs and a small quality or latency change is acceptable. Choose tensor parallelism when several GPUs are available and preserving the original weight precision matters. Choose a shorter context or lower concurrency when the weights fit but active requests exhaust the KV-cache budget.
Exercise
A model loads in FP16 but leaves too little memory for concurrent requests. Which two changes could help, and what trade-off does each introduce?
Show answer
Use a quantized checkpoint to reduce weight memory, accepting possible quality or kernel-speed changes. Reduce maxmodellen or concurrency to reserve more memory for the KV cache, accepting shorter prompts or fewer simultaneous requests.