Transformers 文档

概览

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

概述

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

Transformers 支持多种量化方法,每种方法都有其优缺点,因此您可以根据您的特定用例选择最佳方法。有些方法需要校准才能获得更高的准确性和极致压缩(1-2 位),而其他方法则可以直接进行即时量化。

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

量化方法 即时量化 CPU CUDA GPU ROCm GPU Metal (Apple Silicon) 英特尔 GPU Torch 编译 () 位数 PEFT 微调 可使用 🤗Transformers 序列化 🤗Transformers 支持 库链接
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
压缩张量 🔴 🟢 🟢 🟢 🔴 🔴 🔴 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 合作提供的这些适合初学者的量化课程。

用户友好的量化工具

如果您正在寻找用户友好的量化体验,可以使用以下社区空间和笔记本

< > 在 GitHub 上更新