Transformers 文件
AutoRound
並獲得增強的文件體驗
開始使用
AutoRound
AutoRound 是一種先進的量化演算法,即使在 2 位精度下也能提供強大的準確性。它利用符號梯度下降在僅僅 200 步內微調舍入值和最小-最大裁剪閾值。它設計用於廣泛的相容性,無縫支援各種大型語言模型(LLM),並正在積極擴充套件以涵蓋更多的視覺語言模型(VLM)。它還支援跨多個硬體平臺進行量化和推理,包括 CPU、XPU 和 CUDA。
AutoRound 還提供各種實用功能,包括混合位調優和推理、lm-head 量化、支援匯出為 GPTQ/AWQ/GGUF 等格式,以及靈活的調優方案。有關全面的概述和最新更新,請查閱 AutoRound 的 README。
AutoRound 最初是作為 Intel Neural Compressor 的一部分開發的,作為深度學習的通用模型壓縮庫。此後,它演變為一個獨立的庫,專門專注於大型語言模型(LLM)的低精度最佳化。AutoRound 仍與 Intel Neural Compressor 完全整合,您可以瀏覽儲存庫瞭解更多詳情。
安裝
pip install auto-round
支援的量化配置
AutoRound 支援多種量化配置:
- Int8 僅權重
- Int4 僅權重
- Int3 僅權重
- Int2 僅權重
- 混合位僅權重
硬體相容性
支援 CPU、XPU 和 CUDA 進行量化和推理。
量化和序列化(離線)
目前,僅支援離線模式生成量化模型。
命令列用法
auto-round \ --model facebook/opt-125m \ --bits 4 \ --group_size 128 \ --output_dir ./tmp_autoround
AutoRound 還提供了另外兩種方案,`auto-round-best` 和 `auto-round-light`,分別旨在提供最佳準確性和提高速度。對於 2 位量化,我們建議使用 `auto-round-best` 或 `auto-round`。
W4G128 13 項任務(mmlu-pro、if_eval、gsm8k 等)的平均準確率和時間消耗結果(測試在 Nvidia A100 80G 上進行,使用 PyTorch 2.6.0 版本,並啟用了 `torch_compile`)
模型 | Qwen2.5-0.5B-Instruct | Falcon3-3B | Qwen2.5-7B-Instruct | Meta-Llama-3.1-8B-Instruct | Falcon3-10B | Qwen2.5-72B-Instruct |
---|---|---|---|---|---|---|
16位元 | 0.4192 | 0.5203 | 0.6470 | 0.6212 | 0.6151 | 0.7229 |
最佳 | 0.4137(7分鐘) | 0.5142(23分鐘) | 0.6426(58分鐘) | 0.6116(65分鐘) | 0.6092(81分鐘) | 0.7242(575分鐘) |
預設 | 0.4129(2分鐘) | 0.5133(6分鐘) | 0.6441(13分鐘) | 0.6106(13分鐘) | 0.6080(18分鐘) | 0.7252(118分鐘) |
輕量級 | 0.4052(2分鐘) | 0.5108(3分鐘) | 0.6453(5分鐘) | 0.6104(6分鐘) | 0.6063(6分鐘) | 0.7243(37分鐘) |
推理
AutoRound 會根據已安裝的庫自動選擇最佳可用後端,並在找到更好的後端時提示使用者安裝額外的庫。
CPU
支援 2、4 和 8 位。我們建議使用 intel-extension-for-pytorch (IPEX) 進行 4 位推理。
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "OPEA/Qwen2.5-1.5B-Instruct-int4-sym-inc"
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cpu", torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(model_name)
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
問題
如果您在使用 transformers 整合時遇到任何問題,請在 transformers 倉庫中提出問題。
如果您在使用 auto-round 時遇到任何問題,請在 AutoRound 倉庫中提出問題。
致謝
特別感謝 AutoGPTQ、AutoAWQ、GPTQModel、Triton、Marlin 和 ExLLaMAV2 等開源低精度庫,它們提供了 AutoRound 中利用的低精度 CUDA 核心。
貢獻
歡迎並非常感謝對 AutoRound 的貢獻!無論是修復 bug、改進文件、新增新功能還是提出改進建議,您的幫助都非常寶貴。
< > 在 GitHub 上更新