Transformers documentation
EETQ
EETQ
Thư viện Easy & Efficient Quantization for Transformers (EETQ) hỗ trợ lượng tử hóa chỉ trọng số int8 theo kênh cho GPU NVIDIA. Nó sử dụng các kernel GEMM và GEMV hiệu năng cao từ FasterTransformer và TensorRT-LLM. Lớp attention được tối ưu hóa bằng FlashAttention2. Không yêu cầu bộ dữ liệu hiệu chuẩn và mô hình không cần được lượng tử hóa trước. Sự suy giảm độ chính xác là không đáng kể nhờ vào lượng tử hóa theo kênh.
EETQ hỗ trợ thêm việc tinh chỉnh với PEFT.
Cài đặt EETQ từ trang phát hành hoặc mã nguồn. EETQ yêu cầu CUDA 11.4 trở lên.
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
git clone https://github.com/NetEase-FuXi/EETQ.git
cd EETQ/
git submodule update --init --recursive
pip install .Thực hiện lượng hóa mô hình ngay khi chạy bằng cách định nghĩa kiểu dữ liệu lượng hóa trong 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
)Lưu mô hình đã lượng tử hóa bằng save_pretrained() để có thể tái sử dụng bằng from_pretrained().
quant_path = "/path/to/save/quantized/model"
model.save_pretrained(quant_path)
model = AutoModelForCausalLM.from_pretrained(quant_path, device_map="auto")