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 and Efficient Quantization for Transformers (EETQ) quantizes weights to int8 with one scale per output channel, and runs the matmul with int8 weights and 16-bit activations. Use it for 8-bit weight-only quantization on NVIDIA GPUs without calibration data.

下表总结了 EETQ 在 Transformers 中的支持情况。

配置EetqConfig
quant_methodeetq
工作流加载时量化
位8
硬件CUDA
保存✅
微调✅
自动编译❌

安装 EETQ 内核

Transformers 会从 Hub 上的 kernels-community/quantization-eetq 仓库下载 EETQ 内核,因此您无需自行构建 EETQ。请安装 kernels 和 Accelerate 库。

pip install -U "transformers[kernels]" accelerate

使用 EETQ 量化模型

创建一个 EetqConfig 并将其传递给 from_pretrained()。weights 用于设置权重的数据类型,且仅接受 "int8",这也是默认值。

import torch
from transformers import AutoModelForCausalLM, EetqConfig

quantization_config = EetqConfig("int8")
model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-8B",
    quantization_config=quantization_config,
    dtype=torch.float16,
    device_map="cuda",
)

使用 dtype=torch.float16 加载模型以获得最佳效率。EETQ 以 fp16 格式存储其缩放因子。

局限性

  • EETQ 需要 CUDA GPU。在没有 CUDA GPU 的情况下加载会引发 RuntimeError。
  • EETQ 无法卸载到 CPU 或磁盘。包含 "cpu" 或 "disk" 的 device_map 会引发 ValueError。

资源

Update on GitHub