🚀 Qwen2.5-VL-7B-Instruct-gptqmodel-int8
這是一個使用 GPTQModel 工具包對 Qwen2.5-VL-7B-Instruct 進行 GPTQ-INT8 量化的模型。
🚀 快速開始
✨ 主要特性
📦 安裝指南
pip3 install -v "gptqmodel>=2.2.0" --no-build-isolation
💻 使用示例
基礎用法
python3 gptqmodel_quantize.py /path/to/Qwen2.5-VL-7B-Instruct/ /path/to/Qwen2.5-VL-7B-Instruct-gptqmodel-int8 8
高級用法
import fire
from datasets import load_dataset
from gptqmodel import GPTQModel, QuantizeConfig
from gptqmodel.models.definitions.base_qwen2_vl import BaseQwen2VLGPTQ
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
os.environ["PYTHONUTF8"]="1"
def format_qwen2_vl_dataset(image, assistant):
return [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": "generate a caption for this image"},
],
},
{"role": "assistant", "content": assistant},
]
def prepare_dataset(format_func, n_sample: int = 20) -> list[list[dict]]:
from datasets import load_dataset
dataset = load_dataset(
"laion/220k-GPT4Vision-captions-from-LIVIS", split=f"train[:{n_sample}]"
)
return [
format_func(sample["url"], sample["caption"])
for sample in dataset
]
def get_calib_dataset(model):
if isinstance(model, BaseQwen2VLGPTQ):
return prepare_dataset(format_qwen2_vl_dataset, n_sample=256)
raise NotImplementedError(f"Unsupported MODEL: {model.__class__}")
def quantize(model_path: str,
output_path: str,
bit: int):
quant_config = QuantizeConfig(bits=bit, group_size=128)
model = GPTQModel.load(model_path, quant_config)
calibration_dataset = get_calib_dataset(model)
model.quantize(calibration_dataset, batch_size=8)
model.save(output_path)
model = GPTQModel.load(output_path)
result = model.generate("Uncovering deep insights begins with")[0]
print(model.tokenizer.decode(result))
if __name__ == "__main__":
fire.Fire(quantize)
📄 許可證
本項目採用 MIT 許可證。
信息表格
屬性 |
詳情 |
模型類型 |
經過 GPTQ-INT8 量化的 Qwen2.5-VL-7B-Instruct 模型 |
訓練數據 |
未提及 |
管道標籤 |
圖像文本到文本 |
庫名稱 |
transformers |
標籤 |
text-generation-inference |