Quantization recipes for LLMs (AIMET Torch)

This page is a companion to the Quantization recipes for LLMs tutorial. The primary tutorial reports results using aimet-onnx. For completeness, this page reports the equivalent results obtained by quantizing with aimet-torch.

The same two reference recipes are applied (INT4 weights, INT16 activations):

  1. PCQ + SpinQuant + AdaScale

  2. LPBQ + SeqMSE

Refer to the primary tutorial for the recipe descriptions, system requirements, workflow overview, and FAQs.

Note

Due to PyTorch limitations, certain functional operations (torch.nn.functional) cannot have quantizers inserted, which makes a mixed-precision profile (e.g., INT8 KV Cache) challenging to apply directly. To address this, models quantized with aimet-torch are evaluated on aimet-onnx, which provides a static graph that ensures correct quantizer insertion for all activations and a more accurate quantization simulation.

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

Models are quantized with aimet-torch and evaluated on aimet-onnx, using a sequence length of 2048 tokens (AR-2048) 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_batches=20

  • SeqMSE: num_batches=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>).

ModelWeightsActsRecipe PPLMMLUTime (min)CUDA (GB)
LLaMA 3.2 1B Instruct FP32FP3212.1446.06<16
INT4 PCQINT16
KV=INT8
SpinQuant
AdaScale (b=128, i=2048)
13.6742.2515121
INT4 LPBQINT16
KV=INT8
SeqMSE 14.0743.094529
LLaMA 3.2 3B Instruct FP32FP3210.1360.74<114
INT4 PCQINT16
KV=INT8
SpinQuant
AdaScale (b=128, i=1024)
11.0158.0939541
INT4 LPBQINT16
KV=INT8
SeqMSE 10.6959.0816251
Qwen 2.5 0.5B Instruct FP32FP3213.1446.30<14
INT4 PCQINT16
KV=INT16
SpinQuant
AdaScale (b=128, i=2048)
13.8944.1920013
INT4 LPBQINT16
KV=INT16
SeqMSE 15.3242.332314
Qwen 2.5 1.5B Instruct FP32FP3212.4154.65<18
INT4 PCQINT16
KV=INT16
SpinQuant
AdaScale (b=128, i=1024)
13.5749.8118323
INT4 LPBQINT16
KV=INT16
SeqMSE 14.8649.256826
Qwen 3 4B FP32FP3212.4170.06<117
INT4 PCQINT16
KV=INT8
SpinQuant
AdaScale (b=128, i=512)
13.8565.0740248
INT4 LPBQINT16
KV=INT8
SeqMSE 13.1065.6616239
Phi 3.5 mini instruct FP32FP325.7768.89<116
INT4 PCQINT16
KV=INT8
SpinQuant
AdaScale (b=32, i=256)
6.5862.6225748
INT4 LPBQINT16
KV=INT8
SeqMSE 6.4564.6312438

Quick Start

Quantize the Llama 3.2 1B model using aimet-torch.

Example: Apply Recipe 1 (pcq_spinquant_adascale)

python -m Examples.torch.quantize \
 --model-id "meta-llama/Llama-3.2-1B-Instruct" \
 --recipe "pcq_spinquant_adascale" \
 --export-path "./torch_pcq" \
 --adascale-num-batches 128 --adascale-num-iterations 2048

Example: Apply Recipe 2 (lpbq_seqmse)

python -m Examples.torch.quantize \
 --model-id "meta-llama/Llama-3.2-1B-Instruct" \
 --recipe "lpbq_seqmse" \
 --export-path "./torch_lpbq" \
 --seqmse-num-batches 20

Evaluate the checkpoint on aimet-onnx.

python -m Examples.onnx.evaluate \
 --model-id "meta-llama/Llama-3.2-1B-Instruct" \
 --checkpoint "./torch_lpbq" \
 --eval-ppl

Contact Us

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

</content> </invoke>