Module 4 Lesson 2: Quantization Concepts
Compressing intelligence. How we fit 100GB models into 5GB files without making them stupid.
Quantization: The Art of the Squeeze
If Transformers are the "Brain" of the LLM, Quantization is the "Compression" that makes that brain fit inside your pocket. Without quantization, local AI would only be possible for people with $30,000 server racks.
1. The Numbers Problem
In a raw, "Full Precision" model (FP32), every single parameter (weight) is a 32-bit floating-point number.
- 7 Billion parameters * 4 bytes per parameter (32-bit) = 28 GB.
Most consumer laptops have 8GB or 16GB of RAM. A 28GB model simply won't open.
2. What is Quantization?
Quantization is the process of reducing the precision of those numbers. Think of it like a digital photo:
- FP32: A massive, uncompressed RAW image.
- Int8 / 4-bit: A high-quality JPEG. It's much smaller, and if you look really closely, you might see some artifacts, but for most people, it looks identical.
We map a wide range of numbers (e.g., 0.00000001 to 0.99999999) into a smaller set of discrete values (e.g., 1 to 16 in a 4-bit system).
3. Common Quantization Levels
8-bit (Q8)
- Size: 50% of the original.
- Brain Power: ~99.9% of full precision.
- Verdict: Great if you have the RAM, but often overkill.
4-bit (Q4)
- Size: 25% of the original. (7B model becomes ~4GB).
- Brain Power: ~95-98% of full precision.
- Verdict: The "Golden Standard" for Ollama and local LLMs. It is the best balance of size and smarts.
2-bit (Q2)
- Size: Tiny.
- Brain Power: Significant loss. The model starts "hallucinating" or speaking gibberette.
- Verdict: Only use this for very simple, repetitive tasks or very old hardware.
4. The "K-Means" and "GGUF" Secret
Modern quantization (like the q4_K_M you see in Ollama) doesn't just treat all numbers the same. It is "smarter":
- It keeps critical layers (the "important parts of the brain") at higher precision.
- It squeezes the less important layers much harder.
This is why an Ollama q4 model often feels just as smart as a cloud-based FP16 model.
5. Why Does Speed Increase?
You might think that "decompressing" the model would make it slower. Actually, it makes it faster. The biggest bottleneck in AI is Memory Bandwidth—the speed at which data travels from RAM to the GPU. Since a quantized model is 4x smaller, the GPU spends 4x less time "waiting" for data to arrive, allowing it to generate text much quicker.
Key Takeaways
- Quantization reduces 32-bit numbers into 4-bit or 8-bit values.
- Size reduction allows large models to fit in consumer RAM.
- Intelligence loss is minimal at 4-bit but significant at 2-bit.
- Smaller models load faster and generate text faster because they require less memory bandwidth.