On this page

Quantization recipes for LLMs

This page shows the recipe used to quantize a set of popular large language models (LLMs) to INT4 weights and INT16 activations using aimet-onnx. The accuracy results (PPL, MMLU) are shown, each with the GenAI Lab YAML config that produced it, followed by the steps to reproduce the results with that config.

Note that the intent here is to show how to quantize the model. To create artifacts that can be directly deployed on the target hardware, additional adaptation steps are required. Refer to the model adaptation guide for more details.

Accuracy Results

We report accuracy using two key metrics, alongside the cost of running each recipe:

  • Perplexity (PPL) on WikiText (English)

  • MMLU

  • End-to-end runtime for each quantization recipe

  • Peak CUDA memory usage during quantization

All models use a sequence length of 2048 tokens and a context length of 4096 tokens. The FP32 row for each model is the unquantized baseline. The following settings are common across all models:

  • Embedding: INT16

  • LM Head weights: INT8

  • Calibration: num_iterations=20

  • SeqMSE: num_iterations=20

The KV Cache precision varies per model and is shown on the second line of the Acts column.

AdaScale num_batches and num_iterations vary per model and are noted inline in the Recipe column as AdaScale (b=<num_batches>, i=<num_iterations>).

The Config column links the GenAI Lab YAML config for each quantized row. See Reproduce the results to run it. To reproduce an FP32 baseline, take any config for that model and remove its precision and recipe sections.

ModelWeightsActsRecipe PPLMMLUTime (min)CUDA (GB)Config
LLaMA 3.2 1B Instruct FP32FP32—12.1446.06—7—
INT4 PCQINT16
KV=INT8
SpinQuant (r1)
AdaScale (b=128, i=2048)
13.6841.8211322YAML
INT4 LPBQINT16
KV=INT8
SeqMSE 13.8443.532129YAML
LLaMA 3.2 3B Instruct FP32FP32—10.1360.74—14—
INT4 PCQINT16
KV=INT8
SpinQuant (r1)
AdaScale (b=128, i=1024)
11.1457.2829040YAML
INT4 LPBQINT16
KV=INT8
SeqMSE 10.5559.297347YAML
Qwen 2.5 0.5B Instruct FP32FP32—13.1446.30—4—
INT4 PCQINT16
KV=INT16
SpinQuant (r1)
AdaScale (b=128, i=2048)
13.8242.657715YAML
INT4 LPBQINT16
KV=INT16
SeqMSE 15.3043.261218YAML
Qwen 2.5 1.5B Instruct FP32FP32—12.4154.65—8—
INT4 PCQINT16
KV=INT16
SpinQuant (r1)
AdaScale (b=128, i=1024)
13.3550.2713423YAML
INT4 LPBQINT16
KV=INT16
SeqMSE 14.3349.973830YAML
Qwen 3 0.6B FP32FP32—19.1547.11—8—
INT4 PCQINT16
KV=INT8
SpinQuant (r2 + r3)
AdaScale (b=128, i=2048)
20.6743.416518YAML
Qwen 3 1.7B FP32FP32—15.6359.96—18—
INT4 PCQINT16
KV=INT8
AdaScale (b=128, i=2048) 16.5956.6510525YAML
Qwen 3 4B FP32FP32—12.4170.06—17—
INT4 PCQINT16
KV=INT8
SpinQuant (r1)
AdaScale (b=128, i=512)
13.7965.0727448YAML
INT4 LPBQINT16
KV=INT8
SeqMSE 12.7765.369554YAML
Qwen 3 8B FP32FP32—8.9974.96—34—
INT4 PCQINT16
KV=INT8
AdaScale (b=128, i=2048) 9.4969.8940374YAML
Qwen 3 VL 8B Instruct FP32FP32—7.7876.3—37—
INT4 PCQINT16
KV=INT8
AdaScale (b=128, i=2048) 8.3772.6336675YAML
Qwen 3.5 4B FP32FP32—8.8872.03—22—
INT4 PCQINT16
KV=INT8
AdaScale (b=128, i=2048) 10.0972.6722152YAML
Phi 3.5 mini Instruct FP32FP32—5.7768.89—17—
INT4 PCQINT16
KV=INT8
SpinQuant (r1)
AdaScale (b=32, i=256)
6.5062.5111249YAML
INT4 LPBQINT16
KV=INT8
SeqMSE 6.4163.909364YAML
Gemma 3 4B Instruct FP32FP32—13.4158.41—20—
INT4 LPBQINT16
KV=INT8
SpinQuant (r2)
SeqMSE
19.6152.7910568YAML
Gemma 3 1B Instruct FP32FP32—23.1139.92—8—
INT4 LPBQINT16
KV=INT8
SpinQuant (r2)
SeqMSE
26.7037.282927YAML
Gemma 3 270M Instruct FP32FP32—54.8826.31—4—
INT4 PCQINT16
KV=INT8
SpinQuant (r2)
AdaScale (b=128, i=2048)
64.7926.832681YAML
Gemma 4 E4B Instruct FP32FP32——58.93—34—
INT4 PCQINT16
KV=INT8
SeqMSE —53.532364YAML

System Requirements

The quantization process requires a machine with:

  • Operating System: Linux

  • Hardware: CUDA-enabled GPU

GPU Memory Requirements:

  • Minimum: 40GB VRAM

Recipes

We present two recipes for INT4 weights, INT16 activations quantization using combinations of Post-Training Quantization (PTQ) techniques available in aimet-onnx:

  1. PCQ + SpinQuant + AdaScale
    • Per-Channel Quantization (PCQ) - Uses per-output channel scales for weights on linear layers.

    • SpinQuant - A PTQ technique that improves the accuracy by inserting rotations at specific points in the model to mitigate activation outliers.

    • AdaScale - A PTQ technique that enhances accuracy by introducing learnable parameters in the weight quantizers and performing Block-wise Knowledge Distillation (BKD) against FP outputs.

  2. LPBQ + SeqMSE
    • Low Power Blockwise Quantization (LPBQ) - Applies blockwise quantization (block_size=64) for weights on linear layers.

    • SeqMSE - Calibrates layer-by-layer to minimize Mean Square Error (MSE) between quantized and FP outputs.

To maintain accuracy, activations are primarily kept at INT16, with a mixed-precision profile using INT8 activations selectively where feasible—such as for the KV cache.

Some models use a variant of these recipes, for example SpinQuant with R2 (and R3) rotations instead of R1, or SpinQuant combined with LPBQ + SeqMSE. The Recipe column and the linked config show the exact recipe for each row.

Reproduce the results

The results are produced with GenAI Lab, which is part of the AIMET repository and is not shipped in the aimet-onnx or aimet-torch packages. Clone the AIMET repository and set up GenAI Lab by following its README, then run the config linked in the results table from the repository root. For example:

python -m GenAILab --framework onnx \
    --config GenAILab/configs/recipes/llama-3.2-1b-instruct/pcq_spinquant_r1_adascale.yaml

FAQs

  1. Why does this tutorial use aimet-onnx?
    • aimet-onnx provides a static graph representation, giving full quantization coverage (including functional operations that aimet-torch cannot instrument easily) and an accurate mixed-precision simulation (e.g. INT8 KV Cache).

    • It is also the natural starting point for hardware adaptation (e.g. QAIRT) and other runtimes which consume ONNX graphs.

    • You may still prefer aimet-torch when you want to keep the workflow within the PyTorch ecosystem, apply Quantization-Aware Training (QAT), or calibrate using PyTorch datasets and dataloaders. Equivalent aimet-torch results are reported on the AIMET Torch recipes page.

  2. When should I choose Recipe 1 vs Recipe 2?
    • Choose Recipe 1: PCQ + SpinQuant + AdaScale
      • Uses Per-channel Quantization (PCQ), which provides good granularity for weights.

      • Performance KPIs (token rate, time-to-first-tokens etc.) are better on the target device.

      • Recommended when you can afford longer calibration time and prioritize throughput over accuracy.

    • Choose Recipe 2: LPBQ + SeqMSE
      • Uses Blockwise quantization, which provides finer granularity than PCQ.

      • Recommended when the accuracy is the top priority.

      • Trade off: Slight impact on performance KPIs due to INT4 -> INT8 decoding.

  3. Can I run the artifacts generated from the recipes as-is on target hardware?
    • No. The generated artifacts from the recipes are not directly compatible with QAIRT and require non-trivial adaptation steps for deployment on target hardware. Refer to the model adaptation guide for details.

  4. Why does computing MMLU takes a long time?
    • MMLU evaluation can be slow even on high-end GPUs because it involves thousands of questions across 57 subjects. To trade off accuracy for speed, replace MMLU in the config with MMLU1000, which evaluates a fixed subset of 1000 questions.

  5. Why INT8 KV Cache is not “Good enough” for Qwen 2.5?
    • Qwen 2.5 (0.5B and 1.5B) suffers with INT8 path (with only 256 discrete levels) for KV Cache activations due to wider dynamic range and INT16 offers 65,536 discrete levels which drastically reduces quantization error. So for Qwen 2.5, INT16, which doubles memory compared to INT8, maintains performance much closer to FP32, making it the better choice when quality matters and memory allows.

AIMET Torch Recipes

This page reports results using aimet-onnx. For completeness, equivalent results obtained by quantizing with aimet-torch (and evaluating on aimet-onnx) are reported on a separate page:

Contact Us

Please reach out to us if you encounter any issue with this tutorial or applying recipes to similar models.