🚀 gemma-3-4b-it-GPTQ-4b-128g
本项目是一个经过量化处理的模型,将原始模型的权重量化为INT4数据类型,有效减少了磁盘空间和GPU内存需求。它在图像文本到文本的任务中表现出色,可用于多种实际应用场景。
✨ 主要特性
- 量化优化:将gemma-3-4b-it的权重量化为INT4数据类型,每个参数的位数从16位减少到4位,磁盘大小和GPU内存需求降低约75%。
- 部分量化:仅对
language_model
变压器块内的线性算子权重进行量化,视觉模型和多模态投影保持原始精度。
- 量化方案:采用对称的每组方案进行权重量化,组大小为128,并应用GPTQ算法。
- 模型格式:模型检查点以compressed_tensors格式保存。
📦 安装指南
安装transformers
若要在transformers
中使用该模型,请将包更新到Gemma3的稳定版本:
pip install git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3
安装vLLM
若要在vLLM
中使用该模型,请将包更新到此PR之后的版本。
💻 使用示例
基础用法
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
from PIL import Image
import requests
import torch
model_id = "ISTA-DASLab/gemma-3-4b-it-GPTQ-4b-128g"
model = Gemma3ForConditionalGeneration.from_pretrained(
model_id, device_map="auto"
).eval()
processor = AutoProcessor.from_pretrained(model_id)
messages = [
{
"role": "system",
"content": [{"type": "text", "text": "You are a helpful assistant."}]
},
{
"role": "user",
"content": [
{"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
{"type": "text", "text": "Describe this image in detail."}
]
}
]
inputs = processor.apply_chat_template(
messages, add_generation_prompt=True, tokenize=True,
return_dict=True, return_tensors="pt"
).to(model.device, dtype=torch.bfloat16)
input_len = inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
generation = generation[0][input_len:]
decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
📚 详细文档
模型评估
该模型在OpenLLM v1基准测试中进行了评估,模型输出使用vLLM
引擎生成。评估结果如下:
模型 |
ArcC |
GSM8k |
Hellaswag |
MMLU |
TruthfulQA-mc2 |
Winogrande |
平均值 |
恢复率 |
gemma-3-4b-it |
0.6084 |
0.7528 |
0.7497 |
0.5832 |
0.5189 |
0.7072 |
0.6534 |
1.0000 |
gemma-3-4b-it-INT4 (本模型) |
0.5879 |
0.7210 |
0.7358 |
0.5650 |
0.4863 |
0.6811 |
0.6295 |
0.9635 |
结果复现
使用以下命令可复现上述结果:
MODEL=ISTA-DASLab/gemma-3-4b-it-GPTQ-4b-128g
MODEL_ARGS="pretrained=$MODEL,max_model_len=4096,tensor_parallel_size=1,dtype=auto,gpu_memory_utilization=0.80"
lm_eval \
--model vllm \
--model_args $MODEL_ARGS \
--tasks openllm \
--batch_size auto
📄 许可证
本模型的许可证为gemma。