Quantization is a technique used to make Large Language Models (LLMs) smaller and faster by reducing the precision of the numbers used to represent their “weights” (the learned parameters of the model).
Think of it as compressing the model so that it can run on consumer hardware (like a laptop or a single GPU) instead of requiring a massive data center.
Here is a breakdown of how it works, why we do it, and the trade-offs involved.
1. The Basic Concept: Precision vs. Size
When an LLM is first trained, its weights are usually stored in high-precision formats, such as FP32 (32-bit Floating Point).
- FP32: Uses 32 bits to represent a single number. It is extremely accurate but takes up a lot of memory.
- FP16 / BF16: Uses 16 bits. This is the standard for “full-sized” inference.
- INT8 / INT4: Uses 8 bits or 4 bits. These are much smaller.
The Analogy: Imagine you are describing the color of a room.
- High Precision (FP32): You describe the color as “A very specific shade of eggshell white with a hint of warm beige and a slight grey undertone.” (Very accurate, but takes a long time to say).
- Quantized (INT4): You just say, “It’s off-white.” (Much faster to say, and for most people, it’s “good enough” to understand the room).
2. Why do we need Quantization?
The primary reason is VRAM (Video RAM) limits.
If you want to run a 70B parameter model (like Llama-3 70B):
- In FP16: You would need about 140 GB of VRAM just to load the model. Most high-end consumer GPUs (like the RTX 4090) only have 24 GB.
- In 4-bit Quantization: That same model only requires about 35–40 GB of VRAM. With further compression (like 3-bit), it can even fit into smaller setups.
Quantization allows us to:
- Run larger models on cheaper hardware.
- Increase inference speed (calculating with integers is often faster than floating-point math).
- Reduce electricity and hosting costs.
3. How is it done?
There are two main ways to apply quantization:
- Post-Training Quantization (PTQ): This is the most common method. You take a finished, trained model and “squash” the weights down to a lower precision. It’s fast and doesn’t require retraining the model.
- Quantization-Aware Training (QAT): During the actual training process, the model is taught to “expect” lower precision. This usually results in a much higher-quality model because it learns to compensate for the loss of detail, but it is much more computationally expensive.
4. Common Quantization Formats
If you’ve been looking at models on Hugging Face, you’ve probably seen these terms:
- GGUF: Popular for running models on CPUs (via
llama.cpp). It allows for “layer-offloading,” where you can run part of the model on your GPU and part on your RAM. - EXL2 / GPTQ: Optimized for high-speed inference on NVIDIA GPUs.
- AWQ (Activation-aware Weight Quantization): A smarter way to quantize that protects the most “important” weights of the model to maintain high accuracy.
- NF4 (NormalFloat 4): Often used with QLoRA, a method that allows people to “fine-tune” massive models on consumer hardware.
5. The Trade-off: Accuracy vs. Efficiency
The “cost” of quantization is Perplexity. Perplexity is a measure of how “confused” the model is.
- As you move from 16-bit to 8-bit, the drop in intelligence is usually almost unnoticeable.
- As you move down to 4-bit, the model stays very capable but might start making slightly more “hallucinations” or lose some nuance in complex reasoning.
- If you go too low (like 2-bit), the model usually becomes incoherent and starts outputting gibberish.
Summary Table
| Format | Precision | VRAM Usage (for 70B Model) | Quality | Best Use Case |
|---|---|---|---|---|
| FP16 | High | ~140 GB | Maximum | Research / Production Servers |
| INT8 | Medium | ~70 GB | Near-Lossless | High-end Workstations |
| INT4 | Low | ~35-40 GB | Very Good | Consumer GPUs (Most common) |
| 2-bit | Very Low | ~20 GB | Poor | Experimental / Very tiny hardware |





