The Memory Constraint of Large Language Models
Modern Large Language Models (LLMs) are mathematical giants. A standard model like Llama-3 8B contains eight billion parameters. During training, these parameters are represented as high-precision 16-bit floating-point numbers (FP16). To load a model in FP16, you need at least 16GB of VRAM just to store the weights. For larger models like Llama-3 70B, you need over 140GB of VRAM—far beyond consumer limits.
To solve this hardware bottleneck, researchers developed **quantization**. Quantization is the process of compressing model weights from 16-bit floats down to 8-bit, 4-bit, or even 2-bit representations. This guide explains the core math, evaluates GGUF, AWQ, and GPTQ formats, and outlines when to use each for local serving.
Key Takeaway: Quantization is the single most important technology for local AI. It slashes memory requirements by 75% while retaining 95% of the model's intelligence, allowing giant models to run on standard laptops.
How Quantization Works: The Mathematics of Quantization
At its core, quantization maps a continuous, high-precision range of numbers to a discrete set of lower-precision integers. It computes scaling and zero-point offset parameters to project the float values into a targeted integer grid. The mathematical formula for symmetric quantization is defined as follows:
q = round( x / S ) + ZWhere q is the quantized integer weight, x is the original floating-point weight, S is the scale factor (determining the grid intervals), and Z is the zero-point offset parameter. During inference, these integers are **dequantized** back to float values on-the-fly for matrix multiplication:
x_approx = (q - Z) * SWhile dequantization adds a minor mathematical step on the processor register, the bandwidth saved by loading a 4-bit block from physical memory instead of a 16-bit float is massive, resulting in a net speedup of 3x to 5x.
Understanding the Three Dominant Formats
Depending on your hardware target, you must choose from three primary quantization standards:
1. GGUF (GPT-Generated Unified Format)
Designed by the author of Llama.cpp, **GGUF** is the king of local CPU and Apple Silicon serving. GGUF stores the weights, metadata, tokenizer configurations, and vocabulary in a single file. Unlike GPU-only formats, GGUF allows you to split the model, loading some layers into GPU VRAM and the rest into system RAM, ensuring you can still run the model even if you lack enough VRAM.
2. GPTQ (Generalized Post-Training Quantization)
**GPTQ** is a one-shot calibration method optimized for Nvidia GPUs. It operates by analyzing a calibration dataset to determine which weights are the most sensitive, quantizing the remaining weights while compensating for the loss in accuracy. GPTQ runs incredibly fast on Nvidia GPUs, but it does not support CPU offloading.
3. AWQ (Activation-aware Weight Quantization)
**AWQ** is the modern successor to GPTQ. It recognizes that not all weights are created equal; a tiny fraction (1%) of weights are crucial for model accuracy. AWQ keeps these salient weights in high precision (FP16) while quantizing the remaining 99% of weights to 4-bit. This yields superior reasoning capabilities compared to GPTQ with identical file sizes.
K-Quantization Block Structures: Q4_K_M vs. Q4_0
Llama.cpp supports various block structures under GGUF. Legacy quantization formats (like Q4_0 or Q4_1) quantized all layers uniformly. The modern **K-quantization** scheme applies mixed precision block layouts to optimize accuracy:
- Q4_K_S (Small): Quantizes all weights to 4-bit, but uses a smaller block scale size to save memory. High compression, but minor reasoning loss.
- Q4_K_M (Medium): The industry sweet spot. It quantizes the attention layers to 4-bit while maintaining key feed-forward layers in higher precision, minimizing perplexity loss.
- Q5_K_M (Medium): Uses 5-bit precision for attention layers. Extremely close to native FP16 reasoning, but slightly larger file footprint.





