Transformers 文件

EETQ

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

EETQ

Easy & Efficient Quantization for Transformers (EETQ) 庫支援 NVIDIA GPU 的 int8 僅權重逐通道量化。它使用來自 FasterTransformerTensorRT-LLM 的高效能 GEMM 和 GEMV 核。注意力層使用 FlashAttention2 進行了最佳化。無需校準資料集,模型也不需要預量化。由於逐通道量化,精度下降可以忽略不計。

EETQ 進一步支援使用 PEFT 進行微調。

釋出頁面原始碼安裝 EETQ。EETQ 需要 CUDA 11.4+。

釋出頁面
原始碼
pip install --no-cache-dir https://github.com/NetEase-FuXi/EETQ/releases/download/v1.0.0/EETQ-1.0.0+cu121+torch2.1.2-cp310-cp310-linux_x86_64.whl

透過在 EetqConfig 中定義量化資料型別來動態量化模型。

from transformers import AutoModelForCausalLM, EetqConfig

quantization_config = EetqConfig("int8")
model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-3.1-8B",
    torch_dtype="auto",
    device_map="auto",
    quantization_config=quantization_config
)

使用 save_pretrained() 儲存量化模型,以便可以使用 from_pretrained() 再次重用。

quant_path = "/path/to/save/quantized/model"
model.save_pretrained(quant_path)
model = AutoModelForCausalLM.from_pretrained(quant_path, device_map="auto")
< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.