In [ ]:
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
或者通过源代码安装:https://github.com/NetEase-FuXi/EETQ。EETQ 需要 CUDA 能力 <= 8.9 且 >= 7.0。
In [ ]:
git clone https://github.com/NetEase-FuXi/EETQ.git
cd EETQ/
git submodule update --init --recursive
pip install .
未量化的模型可以通过 from_pretrained 方法进行量化。
In [ ]:
from transformers import AutoModelForCausalLM, EetqConfig
path = "/path/to/model" # 模型路径
quantization_config = EetqConfig("int8") # 量化配置
model = AutoModelForCausalLM.from_pretrained(path, device_map="auto", quantization_config=quantization_config)
量化的模型可以通过 save_pretrained 方法保存,并通过 from_pretrained 方法再次加载使用。
In [ ]:
quant_path = "/path/to/save/quantized/model" # 保存的路径
model.save_pretrained(quant_path)
model = AutoModelForCausalLM.from_pretrained(quant_path, device_map="auto")