# EETQ

[Easy & Efficient Quantization for Transformers (EETQ)](https://github.com/NetEase-FuXi/EETQ) ライブラリは、NVIDIA GPU 向けの int8 weight-only per-channel 量子化をサポートしています。[FasterTransformer](https://github.com/NVIDIA/FasterTransformer) および [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM) からの高性能な GEMM および GEMV カーネルを使用しています。アテンション層は [FlashAttention2](https://github.com/Dao-AILab/flash-attention) によって最適化されています。キャリブレーションデータセットは不要であり、モデルを事前量子化する必要もありません。per-channel 量子化により、精度の低下は軽微です。

EETQは、[PEFT](https://huggingface.co/docs/peft)によるファインチューニングもさらにサポートしています。

EETQは、[リリースページ](https://github.com/NetEase-FuXi/EETQ/releases)または[ソースコード](https://github.com/NetEase-FuXi/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/ja/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/ja/main_classes/model#transformers.PreTrainedModel.save_pretrained) を使用して量子化モデルを保存し、[from_pretrained()](/docs/transformers/main/ja/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")
```

