New Tool Radar

AI Concepts

How to Benchmark Generation Speed After Quantizing to Confirm the Smaller Model Is Actually Faster

Measure prefill and decode tokens per second before and after quantizing on the same prompts, and check peak memory too.

Schematic with three steps: Benchmark the full-precision model first; Benchmark the quantized model the same way; Compare speed and memory together.

A smaller model is not automatically a faster model: the speed gain depends on whether the hardware has a fast kernel for the quantized format. The GPTQ paper reports end-to-end inference speedups over FP16 of around 3.25x on high-end GPUs and 4.5x on more cost-effective ones, but those are the paper numbers on its hardware. The Hugging Face AWQ guide publishes its own benchmark tables for fused and unfused modules, with prefill tokens per second, decode tokens per second and memory use. Measure your own model on your own hardware before claiming a speedup.

What you need

  • The full-precision model and the quantized model, on the same hardware
  • A fixed set of prompts with fixed lengths
  • A way to record tokens per second and peak memory

Step 1: Benchmark the full-precision model first

Run the fixed prompts on the full-precision model and record prefill tokens per second, decode tokens per second and peak memory. Use the same batch size and the same generation length for every later run.

Step 2: Benchmark the quantized model the same way

Run the identical prompts on the quantized model with the same settings. A quantized format without a fast kernel can be slower than full precision, even though it uses less memory.

Step 3: Compare speed and memory together

Compare both numbers side by side. Keep the quantized model only when it is faster or at least as fast at the memory saving you need; a model that is smaller but slower is only useful when memory, not speed, is the constraint.

Worked example: synthetic speed benchmark after quantizing

The table below is a synthetic example. It shows the expected result of benchmarking speed; no model was run.

Model Decode tokens/s Peak memory
Full precision 30 16GB
4-bit, fast kernel 95 5GB
4-bit, slow kernel 25 5GB
8-bit 45 8GB

Expected result (UNTESTED). the 4-bit model with a fast kernel is fastest, but the same 4-bit model with a slow kernel is slower than full precision. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Speed depends on the kernel, the hardware and the batch size, so a benchmark on one setup does not transfer to another.
  • Prefill and decode speeds behave differently: a format can be fast at one and slow at the other.
  • Fused AWQ modules change both speed and memory, so benchmark the exact configuration you will run.
  • Measure with the same prompts and lengths, or the comparison is meaningless.

Sources

See all