Transformers documentation

EETQ

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

EETQ

Easy & Efficient Quantization for Transformers (EETQ) ライブラリは、NVIDIA GPU 向けの int8 weight-only per-channel 量子化をサポートしています。FasterTransformer および TensorRT-LLM の高性能な GEMM および GEMV カーネルを使用しています。アテンション層は FlashAttention2 で最適化されています。キャリブレーションデータセットは不要であり、モデルを事前量子化する必要もありません。per-channel 量子化により、精度の低下はほぼ無視できるレベルです。

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",
    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")
Update on GitHub