许可证: gemma
库名称: transformers
流水线标签: 图像文本到文本
标签:
- int4
- vllm
- llmcompressor
基础模型: google/gemma-3-12b-it
gemma-3-12b-it-GPTQ-4b-128g
模型概述
该模型通过对gemma-3-12b-it的权重进行INT4量化获得。这一优化将每个参数的比特数从16降至4,使磁盘空间和GPU内存需求减少约75%。
仅对language_model
转换器块中的线性算子权重进行量化。视觉模型和多模态投影保持原始精度。权重采用对称分组方案量化,组大小为128。量化过程应用了GPTQ算法。
模型检查点以compressed_tensors格式保存。
评估
该模型在OpenLLM v1基准测试中进行了评估。模型输出由vLLM
引擎生成。
模型 |
ArcC |
GSM8k |
Hellaswag |
MMLU |
TruthfulQA-mc2 |
Winogrande |
平均分 |
恢复率 |
gemma-3-12b-it |
0.7125 |
0.8719 |
0.8377 |
0.7230 |
0.5798 |
0.7893 |
0.7524 |
1.0000 |
gemma-3-12b-it-INT4 (本模型) |
0.6988 |
0.8643 |
0.8254 |
0.7078 |
0.5638 |
0.7830 |
0.7405 |
0.9842 |
复现方法
使用以下命令获得结果:
MODEL=ISTA-DASLab/gemma-3-12b-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
使用方法
以下是通过transformers进行推理的示例:
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
from PIL import Image
import requests
import torch
model_id = "ISTA-DASLab/gemma-3-12b-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": "你是一个乐于助人的助手。"}]
},
{
"role": "用户",
"content": [
{"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
{"type": "text", "text": "详细描述这张图片。"}
]
}
]
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)