Transformers documentation

Overview

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

and get access to the augmented documentation experience

to get started

Overview

Quantization lowers the memory requirements of loading and using a model by storing the weights in a lower precision while trying to preserve as much accuracy as possible. Weights are typically stored in full-precision (fp32) floating point representations, but half-precision (fp16 or bf16) are increasingly popular data types given the large size of models today. Some quantization methods can reduce the precision even further to integer representations, like int8 or int4.

Transformers supports many quantization methods, each with their pros and cons, so you can pick the best one for your specific use case. Some methods require calibration for greater accuracy and extreme compression (1-2 bits), while other methods work out of the box with on-the-fly quantization.

Use the Space below to help you pick a quantization method depending on your hardware and number of bits to quantize to.

Quantization Method On the fly quantization CPU CUDA GPU ROCm GPU Metal (Apple Silicon) Intel GPU Torch compile() Bits PEFT Fine Tuning Serializable with πŸ€—Transformers πŸ€—Transformers Support Link to library
AQLM πŸ”΄ 🟒 🟒 πŸ”΄ πŸ”΄ πŸ”΄ 🟒 1/2 🟒 🟒 🟒 https://github.com/Vahe1994/AQLM
AWQ πŸ”΄ 🟒 🟒 🟒 πŸ”΄ 🟒 ? 4 🟒 🟒 🟒 https://github.com/casper-hansen/AutoAWQ
bitsandbytes 🟒 🟑 🟒 🟑 πŸ”΄ 🟑 πŸ”΄ 4/8 🟒 🟒 🟒 https://github.com/bitsandbytes-foundation/bitsandbytes
compressed-tensors πŸ”΄ 🟒 🟒 🟒 πŸ”΄ πŸ”΄ πŸ”΄ 1/8 🟒 🟒 🟒 https://github.com/neuralmagic/compressed-tensors
EETQ 🟒 πŸ”΄ 🟒 πŸ”΄ πŸ”΄ πŸ”΄ ? 8 🟒 🟒 🟒 https://github.com/NetEase-FuXi/EETQ
GGUF / GGML (llama.cpp) 🟒 🟒 🟒 πŸ”΄ 🟒 πŸ”΄ πŸ”΄ 1/8 πŸ”΄ See Notes See Notes https://github.com/ggerganov/llama.cpp
GPTQModel πŸ”΄ 🟒 🟒 🟒 🟒 🟒 πŸ”΄ 2/3/4/8 🟒 🟒 🟒 https://github.com/ModelCloud/GPTQModel
AutoGPTQ πŸ”΄ πŸ”΄ 🟒 🟒 πŸ”΄ πŸ”΄ πŸ”΄ 2/3/4/8 🟒 🟒 🟒 https://github.com/AutoGPTQ/AutoGPTQ
HIGGS 🟒 πŸ”΄ 🟒 πŸ”΄ πŸ”΄ πŸ”΄ 🟒 2/4 πŸ”΄ 🟒 🟒 https://github.com/HanGuo97/flute
HQQ 🟒 🟒 🟒 πŸ”΄ πŸ”΄ πŸ”΄ 🟒 1/8 🟒 πŸ”΄ 🟒 https://github.com/mobiusml/hqq/
optimum-quanto 🟒 🟒 🟒 πŸ”΄ 🟒 πŸ”΄ 🟒 2/4/8 πŸ”΄ πŸ”΄ 🟒 https://github.com/huggingface/optimum-quanto
FBGEMM_FP8 🟒 πŸ”΄ 🟒 πŸ”΄ πŸ”΄ πŸ”΄ πŸ”΄ 8 πŸ”΄ 🟒 🟒 https://github.com/pytorch/FBGEMM
torchao 🟒 🟒 🟒 πŸ”΄ 🟑 πŸ”΄ 4/8 πŸŸ’πŸ”΄ 🟒 https://github.com/pytorch/ao
VPTQ πŸ”΄ πŸ”΄ 🟒 🟑 πŸ”΄ πŸ”΄ 🟒 1/8 πŸ”΄ 🟒 🟒 https://github.com/microsoft/VPTQ
FINEGRAINED_FP8 🟒 πŸ”΄ 🟒 πŸ”΄ πŸ”΄ πŸ”΄ πŸ”΄ 8 πŸ”΄ 🟒 🟒
SpQR πŸ”΄ πŸ”΄ 🟒 πŸ”΄ πŸ”΄ πŸ”΄ 🟒 3 πŸ”΄ 🟒 🟒 https://github.com/Vahe1994/SpQR/

Resources

If you are new to quantization, we recommend checking out these beginner-friendly quantization courses in collaboration with DeepLearning.AI.

< > Update on GitHub