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 (v5.13.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 MethodOn the fly quantizationCPUCUDA GPUROCm GPUMetal (Apple Silicon)Intel GPUTorch compile()BitsPEFT Fine TuningSerializable with πŸ€—TransformersπŸ€—Transformers SupportLink to library
AQLMπŸ”΄πŸŸ’πŸŸ’πŸ”΄πŸ”΄πŸŸ’πŸŸ’1/2🟒🟒🟒https://github.com/Vahe1994/AQLM
AutoRoundπŸ”΄πŸŸ’πŸŸ’πŸ”΄πŸ”΄πŸŸ’πŸ”΄2/3/4/8πŸ”΄πŸŸ’πŸŸ’https://github.com/intel/auto-round
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
Four Over SixπŸŸ’πŸŸ’πŸŸ’πŸ”΄πŸ”΄πŸ”΄πŸŸ’4πŸ”΄πŸŸ’πŸŸ’https://github.com/mit-han-lab/fouroversix
FP-QuantπŸŸ’πŸ”΄πŸŸ’πŸ”΄πŸ”΄πŸ”΄πŸŸ’4πŸ”΄πŸŸ’πŸŸ’https://github.com/IST-DASLab/FP-Quant
GGUF / GGML (llama.cpp)πŸŸ’πŸŸ’πŸŸ’πŸ”΄πŸŸ’πŸŸ’πŸ”΄1/8πŸ”΄See NotesSee Noteshttps://github.com/ggerganov/llama.cpp
GPT-QModelπŸ”΄πŸŸ’πŸŸ’πŸŸ’πŸŸ’πŸŸ’πŸ”΄2/3/4/8🟒🟒🟒https://github.com/ModelCloud/GPTQModel
HIGGSπŸŸ’πŸ”΄πŸŸ’πŸ”΄πŸ”΄πŸ”΄πŸŸ’2/4πŸ”΄πŸŸ’πŸŸ’https://github.com/HanGuo97/flute
HQQπŸŸ’πŸŸ’πŸŸ’πŸ”΄πŸ”΄πŸŸ’πŸŸ’1/8πŸŸ’πŸ”΄πŸŸ’https://github.com/mobiusml/hqq/
MetalπŸŸ’πŸ”΄πŸ”΄πŸ”΄πŸŸ’πŸ”΄πŸ”΄2/4/8πŸ”΄πŸŸ’πŸŸ’Hub Kernels
optimum-quantoπŸŸ’πŸŸ’πŸŸ’πŸ”΄πŸŸ’πŸŸ’πŸŸ’2/4/8πŸ”΄πŸ”΄πŸŸ’https://github.com/huggingface/optimum-quanto
SINQ🟒🟒🟒🟑🟑🟑🟑2/3/4/6/8πŸ”΄πŸŸ’πŸŸ’https://github.com/huawei-csl/SINQ
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πŸ”΄πŸŸ’πŸŸ’Built-in
SpQRπŸ”΄πŸ”΄πŸŸ’πŸ”΄πŸ”΄πŸ”΄πŸŸ’3πŸ”΄πŸŸ’πŸŸ’https://github.com/Vahe1994/SpQR/
QuarkπŸ”΄πŸŸ’πŸŸ’πŸŸ’πŸŸ’πŸŸ’?2/4/6/8/9/16πŸ”΄πŸ”΄πŸŸ’https://quark.docs.amd.com/latest/

Resources

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

User-Friendly Quantization Tools

If you are looking for a user-friendly quantization experience, you can use the following community spaces and notebooks:

Update on GitHub