transformers/docs/source/en/quantization/overview.md
Andrei Panferov 64c05eecd6
HIGGS Quantization Support (#34997)
* higgs init

* working with crunches

* per-model workspaces

* style

* style 2

* tests and style

* higgs tests passing

* protecting torch import

* removed torch.Tensor type annotations

* torch.nn.Module inheritance fix maybe

* hide inputs inside quantizer calls

* style structure something

* Update src/transformers/quantizers/quantizer_higgs.py

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>

* reworked num_sms

* Update src/transformers/integrations/higgs.py

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>

* revamped device checks

* docstring upd

* Update src/transformers/quantizers/quantizer_higgs.py

Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>

* edited tests and device map assertions

* minor edits

* updated flute cuda version in docker

* Added p=1 and 2,3bit HIGGS

* flute version check update

* incorporated `modules_to_not_convert`

* less hardcoding

* Fixed comment

* Added docs

* Fixed gemma support

* example in docs

* fixed torch_dtype for HIGGS

* Update docs/source/en/quantization/higgs.md

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>

* Collection link

* dequantize interface

* newer flute version, torch.compile support

* unittest message fix

* docs update compile

* isort

* ValueError instead of assert

---------

Co-authored-by: Marc Sun <57196510+SunMarc@users.noreply.github.com>
Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
2024-12-23 16:54:49 +01:00

8.4 KiB

Quantization

Quantization techniques focus on representing data with less information while also trying to not lose too much accuracy. This often means converting a data type to represent the same information with fewer bits. For example, if your model weights are stored as 32-bit floating points and they're quantized to 16-bit floating points, this halves the model size which makes it easier to store and reduces memory-usage. Lower precision can also speedup inference because it takes less time to perform calculations with fewer bits.

Interested in adding a new quantization method to Transformers? Read the HfQuantizer guide to learn how!

If you are new to the quantization field, we recommend you to check out these beginner-friendly courses about quantization in collaboration with DeepLearning.AI:

When to use what?

The community has developed many quantization methods for various use cases. With Transformers, you can run any of these integrated methods depending on your use case because each method has their own pros and cons.

For example, some quantization methods require calibrating the model with a dataset for more accurate and "extreme" compression (up to 1-2 bits quantization), while other methods work out of the box with on-the-fly quantization.

Another parameter to consider is compatibility with your target device. Do you want to quantize on a CPU, GPU, or Apple silicon?

In short, supporting a wide range of quantization methods allows you to pick the best quantization method for your specific use case.

Use the table below to help you decide which quantization method to use.

Quantization method On the fly quantization CPU CUDA GPU RoCm GPU (AMD) Metal (Apple Silicon) Intel GPU torch.compile() support Number of bits Supports fine-tuning (through PEFT) 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 🟢 🟡 * 🟢 🟡 * 🔴 ** 🟡 * 🔴 (soon!) 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 GGUF section See GGUF section https://github.com/ggerganov/llama.cpp
GPTQ 🔴 🔴 🟢 🟢 🔴 🔴 🔴 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 🟢 🟢 🔴 partial support (int4 weight only) 🔴 4 / 8 🟢🔴 🟢 https://github.com/pytorch/ao
VPTQ 🔴 🔴 🟢 🟡 🔴 🔴 🟢 1 - 8 🔴 🟢 🟢 https://github.com/microsoft/VPTQ

* bitsandbytes is being refactored to support multiple backends beyond CUDA. Currently, ROCm (AMD GPU) and Intel CPU implementations are mature, with Intel XPU in progress and Apple Silicon support expected by Q4/Q1. For installation instructions and the latest backend updates, visit this link.

We value your feedback to help identify bugs before the full release! Check out these docs for more details and feedback links.

** bitsandbytes is seeking contributors to help develop and lead the Apple Silicon backend. Interested? Contact them directly via their repo. Stipends may be available through sponsorships.