Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Inference and servingAI guideIntermediate#inference#quantization#fp8#awq
Frame · ai-engineering / inference-serving / 05-quantization.mdGuide 064 / 103

Quantization for serving, GPTQ, AWQ, FP8 and GGUF

Quantization means storing numbers with fewer bits. For LLM serving it is the single biggest lever on cost: halve the bytes per weight and you halve the memory the model needs and roughly halve the data the GPU streams per decode step. The catch is that every format makes different trade-offs between quality, speed and hardware support, and the names are a soup of acronyms. This doc untangles them.

Why it matters

From how inference works: decode speed is bounded by memory bandwidth divided by bytes read per step. Weights dominate those bytes. A 70-billion-parameter model in 16-bit precision is about 140 GB of weights (70e9 × 2 bytes), which needs multiple datacenter GPUs. In 8-bit it is about 70 GB; in 4-bit about 35 GB plus some overhead for scales. That can be the difference between two GPUs and one, or between a server and a laptop.

Quantization also frees memory for KV cache, which raises the number of concurrent sequences, which raises throughput. So it helps both latency and capacity.

How it works

The basic operation is the same everywhere: take a group of values, pick a scale (and sometimes a zero point), and map each value to a small integer or low-precision float. At compute time, kernels either dequantize on the fly or compute directly in low precision.

Two axes describe any scheme:

  • What is quantized. Weights only (W4A16, W8A16), weights and activations (W8A8), or the KV cache too.
  • How the scales are chosen. Simple rounding, or a calibration process that uses sample data to minimise error.
Rendering diagram…

GPTQ. A post-training method that quantizes one layer at a time and uses second-order information to adjust remaining weights so the layer's output error stays small. Usually 4-bit weights with 16-bit activations. Well supported and widely available on model hubs.

AWQ (Activation-aware Weight Quantization). Observes that a small fraction of weight channels matter disproportionately, identified by looking at activation magnitudes, and scales them so they survive 4-bit quantization. Also weight-only 4-bit. In practice GPTQ and AWQ land in similar quality territory; pick whichever has a good checkpoint and fast kernels on your hardware.

FP8. An 8-bit floating point format with native tensor core support on newer NVIDIA GPUs (Ada and Hopper and later) and recent AMD GPUs. Typically W8A8: weights and activations both in FP8, so you get faster matmuls as well as smaller weights. Quality loss is usually small, which is why FP8 is a common default for production serving on hardware that supports it. Newer GPUs also add 4-bit float formats (such as NVFP4 and MXFP4), which engines are adopting.

INT8 W8A8. Similar idea with integers, supported on a wider range of GPUs and CPUs.

GGUF. Not a method but a file format from the llama.cpp project, holding weights plus metadata in one file. It comes with a family of "k-quant" types (for example Q4_K_M, Q5_K_M, Q8_0) that mix bit widths across tensors. Q4_K_M is the common starting point balancing size and quality. An importance matrix (imatrix) computed from sample text improves low-bit quants. GGUF is the format of the local ecosystem: llama.cpp, Ollama, LM Studio.

KV cache quantization. Storing K and V in FP8 roughly halves cache memory versus FP16, which can nearly double the number of tokens you can hold. It is separate from weight quantization and can be combined with it.

Reference architecture

In practice I treat quantization as a build step in the model pipeline, not something done ad hoc on a server.

Rendering diagram…

For GPU serving, the vLLM docs point to LLM Compressor as the recommended tool for producing FP8, INT8 and INT4 checkpoints in a format vLLM loads directly. NVIDIA's Model Optimizer and AMD Quark serve similar roles for their stacks. For GGUF, llama.cpp's convert_hf_to_gguf.py and llama-quantize do the job.

Code

An FP8 dynamic quantization with LLM Compressor, following its documented one-shot pattern:

from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier

model_id = "meta-llama/Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(model_id)

recipe = QuantizationModifier(targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"])
oneshot(model=model, recipe=recipe)

out_dir = "Llama-3.1-8B-Instruct-FP8-Dynamic"
model.save_pretrained(out_dir)
tokenizer.save_pretrained(out_dir)
# then: vllm serve ./Llama-3.1-8B-Instruct-FP8-Dynamic --kv-cache-dtype fp8

And the GGUF path for local use:

python convert_hf_to_gguf.py ./Llama-3.1-8B-Instruct --outtype f16 --outfile model-f16.gguf
./llama-quantize model-f16.gguf model-q4_k_m.gguf Q4_K_M

Trade-offs and pitfalls

  • Check hardware support first. vLLM's quantization page has a compatibility matrix. For example, FP8 W8A8 via LLM Compressor is listed for Ada, Hopper and AMD GPUs, not for older generations such as Ampere, where FP8 may fall back to weight-only kernels or not run at all. A format that is fast on one GPU can be slow on another.
  • Averages hide regressions. Quantized models often score close to baseline on broad benchmarks but degrade on long-context reasoning, maths, code or non-English text. Evaluate on your own tasks.
  • Calibration data matters. Calibrating on generic web text when your traffic is code or another language leaves quality on the table.
  • Small models suffer more. A 70B model at 4-bit usually holds up better than a 3B model at 4-bit. Be more conservative with small models.
  • 4-bit weights do not speed up prefill much. Weight-only schemes still compute in 16-bit, so compute-bound prefill gains less than decode. W8A8 formats help both.
  • Do not double-quantize blindly. Quantizing an already quantized checkpoint, or mixing a quantized KV cache with an aggressive weight quant, compounds error. Measure each step.

Checklist

  • I have a baseline eval in full precision and the same eval for every quantized variant.
  • I confirmed the format is supported with fast kernels on my exact GPU generation.
  • I used calibration data that looks like my production traffic.
  • I considered FP8 KV cache separately from weight quantization.
  • I recorded quantization method, bits, tool version and eval results in the model registry.
  • I re-run evals when the quantization tool or engine version changes.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.