# EETQ

[Easy & Efficient Quantization for Transformers (EETQ)](https://github.com/NetEase-FuXi/EETQ) 库支持针对 NVIDIA GPU 的 int8 仅权重逐通道量化。它使用了来自 [FasterTransformer](https://github.com/NVIDIA/FasterTransformer) 和 [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM) 的高性能 GEMM 和 GEMV 内核。注意力层通过 [FlashAttention2](https://github.com/Dao-AILab/flash-attention) 进行了优化。无需校准数据集，模型也无需预先量化。得益于逐通道量化，精度损失可以忽略不计。

EETQ 还支持使用 [PEFT](https://huggingface.co/docs/peft) 进行微调。

从[发布页面](https://github.com/NetEase-FuXi/EETQ/releases)或[源代码](https://github.com/NetEase-FuXi/EETQ)安装 EETQ。EETQ 需要 CUDA 11.4 或更高版本。

```bash
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
```

```bash
git clone https://github.com/NetEase-FuXi/EETQ.git
cd EETQ/
git submodule update --init --recursive
pip install .
```

通过在 [EetqConfig](/docs/transformers/main/zh/main_classes/quantization#transformers.EetqConfig) 中定义量化数据类型，即可在运行时对模型进行量化。

```py
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()](/docs/transformers/main/zh/main_classes/model#transformers.PreTrainedModel.save_pretrained) 保存量化后的模型，以便之后通过 [from_pretrained()](/docs/transformers/main/zh/main_classes/model#transformers.PreTrainedModel.from_pretrained) 再次加载使用。

```py
quant_path = "/path/to/save/quantized/model"
model.save_pretrained(quant_path)
model = AutoModelForCausalLM.from_pretrained(quant_path, device_map="auto")
```

