huggingface/optimum-quanto
A pytorch quantization backend for optimum
What it solves
Large machine learning models take up a lot of memory and are slow to run. Optimum Quanto shrinks models by converting their weights and activations from high-precision numbers (like 32-bit floats) to lower-precision formats (like 8-bit or 4-bit integers). This reduces the memory footprint roughly by the ratio of the bit widths (e.g., 32-bit to 8-bit cuts memory by about 4x) and can make inference faster on supported hardware.
How it works
Quanto works as a backend for the Hugging Face Optimum library and also provides a low-level API for vanilla PyTorch models. It automatically replaces standard PyTorch modules (like Linear and Conv2D) with quantized versions that handle the conversion of weights and activations. The tool supports both dynamic quantization (where conversion happens on the fly) and static quantization, where you first calibrate the model by passing sample data to determine optimal scaling ranges. You can also fine-tune the quantized model to recover accuracy, and then freeze the integer weights for deployment. Quantized models can be saved and reloaded using standard serialization formats like safetensors.
Who it's for
Developers and researchers who want to deploy PyTorch models (especially LLMs and diffusion models like LLaMA or PixArt) on devices with limited memory or who need faster inference without writing custom quantization code. It is also useful for those who want to experiment with quantization-aware training.
Highlights
- Supports eager mode, so it works with models that cannot be traced.
- Quantized models can be placed on any device (CPU, CUDA, MPS).
- Automatically inserts quantization stubs, functional operations, and quantized modules.
- Works with int2, int4, int8, and float8 weights, plus int8 and float8 activations.
- Accelerated matrix multiplications on CUDA for several mixed-precision combinations.
- Provides calibration and tuning steps to maintain accuracy.
- Serialization compatible with PyTorch's weight-only format and Hugging Face safetensors.
Related
- Dispatch
- Project
- Dispatch
- Project
- Dispatch