# 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)를 통한 fine-tuning을 추가로 지원합니다.

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/v5.23.0/ko/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/v5.23.0/ko/main_classes/model#transformers.PreTrainedModel.save_pretrained)로 저장하여 [from_pretrained()](/docs/transformers/v5.23.0/ko/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")
```

