Transformers 文档

概述

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

概述

量化通过以较低精度存储权重,从而降低加载和使用模型的内存需求,同时尝试尽可能保留准确性。权重通常以全精度 (fp32) 浮点表示形式存储,但鉴于当今模型的大尺寸,半精度 (fp16 或 bf16) 越来越受欢迎的数据类型。一些量化方法可以将精度进一步降低到整数表示形式,例如 int8 或 int4。

Transformers 支持多种量化方法,每种方法都有其优点和缺点,因此您可以为您的特定用例选择最佳方法。某些方法需要校准以获得更高的精度和极端的压缩(1-2 位),而其他方法可以通过即时量化开箱即用。

使用下面的 Space 帮助您根据硬件和要量化的位数选择量化方法。

量化方法 即时量化 CPU CUDA GPU ROCm GPU Metal (Apple Silicon) Intel GPU Torch compile() 位数 PEFT 微调 可使用 🤗Transformers 序列化 🤗Transformers 支持 库链接
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 🔴 见注释 见注释 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/
Quark 🔴 🟢 🟢 🟢 🟢 🟢 ? 2/4/6/8/9/16 🔴 🔴 🟢 https://quark.docs.amd.com/latest/

资源

如果您是量化新手,我们建议您查看这些与 DeepLearning.AI 合作的初学者友好的量化课程。

用户友好的量化工具

如果您正在寻找用户友好的量化体验,您可以使用以下社区 Spaces 和 Notebooks

< > 在 GitHub 上更新