Transformers documentation

Choose a method

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Choose a method

If your checkpoint is already quantized, the checkpoint decides the method. Load it as shown in Load a pre-quantized checkpoint. Otherwise, pick a method based on your hardware and what you need to do with the model after loading it.

Start from your goal

Each row recommends a first method to try. Check the full comparison table before you commit to one.

GoalStart withWhy
Fit a model in less memory with the least setupbitsandbytesQuantizes to 4 or 8 bits while loading without calibration, runs on CUDA, XPU, HPU, and CPU, and supports saving and fine-tuning.
Fine-tune with QLoRAbitsandbytesSupports 4-bit NF4 with PEFT. HQQ, EETQ, GPTQ, SINQ, and Quanto also support fine-tuning.
Speed up inference with torch.compiletorchaogenerate compiles torchao models automatically with a static cache, and torchao has int4, int8, and FP8 schemes for CUDA, XPU, and CPU.
Get the best 4-bit accuracyGPTQCalibrates on a dataset while loading. To use AWQ or AutoRound instead, quantize with their libraries and load the checkpoint.
Run FP8 on Ada, Hopper, or Intel XPUFine-grained FP8Needs CUDA compute capability 8.9 or higher, or an XPU. FBGEMM FP8 needs compute capability 9.0 or higher, or an XPU.
Run FP4 on BlackwellNVFP4Quantizes to NVIDIA’s 4-bit float format while loading. MXFP4 runs on compute capability 7.5 or higher, XPU, and CPU.
Run on Apple siliconMetalQuantizes to 2, 4, or 8 bits on MPS while loading. GGUF files also load on MPS.
Load checkpoints made with llm-compressorcompressed-tensorsLoads FP8, int4, and int8 checkpoints in the compressed-tensors format.
Compress below 4 bitsHQQ or SINQQuantize to 2 or 3 bits while loading without calibration. AQLM, VPTQ, and SpQR checkpoints go lower but must be quantized with their own libraries.
Show the full comparison table
Methodquant_methodWorkflowBitsHardwareSaveFine-tuneAuto-compile
AQLMaqlmPre-quantized only1–2CUDA, CPUβœ…βœ… with aqlm>=1.0.2❌
AutoRoundauto-roundPre-quantized only2–8CUDA, XPU, CPUβœ…βŒβŒ
AWQawqPre-quantized only4CUDA, ROCm, XPU, CPUβœ… except ExLlama backendsβœ… with gptqmodel>=5.0.0❌
BitNetbitnetPre-quantized only1.58CUDAβœ…Only autobitlinear in online mode❌
bitsandbytesbitsandbytesWhile loading4, 8CUDA, XPU, HPU, CPUβœ…βœ…βŒ
compressed-tensorscompressed-tensorsPre-quantized onlySet by checkpointCUDA, XPU, MPS, CPUβœ…βœ… except with FP8 kernelsβœ…
EETQeetqWhile loading8CUDAβœ…βœ…βŒ
FBGEMM FP8fbgemm_fp8While loading8CUDA (compute capability 9.0+), XPUβœ…βŒβŒ
Fine-grained FP8fp8, mxfp8While loading8CUDA (compute capability 8.9+), XPUβœ…βŒβœ…
Four Over SixfouroversixWhile loading4CUDA (fastest on Blackwell), CPUβœ…Only with keep_master_weights=True❌
FP-Quantfp_quantWhile loading4CUDA, XPUβœ…Only with store_master_weights=True❌
GGUFggufPre-quantized only1–8CUDA, MPS, XPU, CPUβŒβŒβœ…
GPTQgptqWhile loading, with calibration2, 3, 4, 8CUDA, ROCm, XPU, CPUβœ…βœ…βŒ
HIGGShiggsWhile loading2, 3, 4CUDAβœ…βŒβŒ
HQQhqqWhile loading1, 2, 3, 4, 8CUDA, XPUβœ…βœ…βŒ
MetalmetalWhile loading2, 4, 8MPSβœ…βŒβŒ
MXFP4mxfp4While loading4CUDA (compute capability 7.5+), XPU, CPUβœ…βŒβŒ
NVFP4nvfp4While loading4One Blackwell GPUβŒβŒβœ…
QuantoquantoWhile loading2, 4, 8CUDA, MPS, XPU, CPUβŒβœ…βŒ
QuarkquarkPre-quantized onlySet by checkpointCUDA, ROCm, CPU❌❌❌
SINQsinqWhile loading2, 3, 4, 6, 8One CUDA GPU, CPUβœ…βœ…βŒ
SpQRspqrPre-quantized only3CUDAβœ…βŒβŒ
torchaotorchaoWhile loading4, 8CUDA, XPU, CPUβœ…Only 8-bit schemesβœ…
VPTQvptqPre-quantized only1–8CUDAβœ…βŒβŒ

Check memory with the quantization picker

The quantization picker estimates whether a model fits on your hardware at each precision, including the KV cache. Pick a model, your hardware, and what you need the method to do, and the Compare view lists the methods that match.

Benchmarks

The benchmarks below compare several methods on Llama 3.1 8B and 70B. They report accuracy, throughput in tokens per second, peak memory in GB, and quantization time.

Llama 3.1 70B in bf16 ran on 2 NVIDIA A100 80GB GPUs. FP8 methods ran on 1 NVIDIA H100 80GB GPU, and all other methods ran on 1 NVIDIA A100 80GB GPU. Throughput was measured at batch size 1, generating 64 tokens. Results include torch.compile and Marlin kernels where a method supports them.

The results group into three bit ranges.

BitsMethods benchmarkedMemory vs. bf16Accuracy
8bitsandbytes int8, HQQ, Quanto, torchao, FP8About 2x smallerVery close to bf16
4AWQ, GPTQ, HQQ, bitsandbytes NF4, SINQAbout 4x smallerHigh. AWQ and GPTQ often lead but need calibration.
Below 4VPTQ, AQLM, 2-bit GPTQMore than 4x smallerNoticeable drop, especially at 2 bits. AQLM and VPTQ take a long time to quantize.

Benchmark accuracy and speed on your own task and hardware before you pick a method for production.

Update on GitHub