🚀 gemma-3-27b-it-FP8-Dynamic
这是 google/gemma-3-27b-it 的量化版本,该模型采用 FP8 数据类型对权重进行量化,适用于视觉 - 文本输入并输出文本,可借助 vLLM 高效部署进行推理。
🚀 快速开始
本模型可使用 vLLM 后端进行高效部署。以下是使用示例:
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
from transformers import AutoProcessor
model_name = "RedHatAI/gemma-3-27b-it-FP8-dynamic"
image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
chat = [
{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "What is the content of this image?"}]},
{"role": "assistant", "content": []}
]
prompt = processor.apply_chat_template(chat, add_generation_prompt=True)
llm = LLM(model=model_name, trust_remote_code=True)
inputs = {"prompt": prompt, "multi_modal_data": {"image": [image]}}
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
print("RESPONSE:", outputs[0].outputs[0].text)
vLLM 还支持与 OpenAI 兼容的服务。更多详细信息请参阅 文档。
✨ 主要特性
模型概述
- 模型架构:gemma - 3 - 27b - it
- 模型优化:
- 发布日期:2025 年 2 月 24 日
- 版本:1.0
- 模型开发者:Neural Magic
模型优化
该模型是通过将 google/gemma-3-27b-it 的权重量化为 FP8 数据类型得到的,可用于 vLLM >= 0.5.2 的推理。
📦 安装指南
文档未提及安装相关步骤,故跳过此章节。
💻 使用示例
基础用法
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
from transformers import AutoProcessor
model_name = "RedHatAI/gemma-3-27b-it-FP8-dynamic"
image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
chat = [
{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "What is the content of this image?"}]},
{"role": "assistant", "content": []}
]
prompt = processor.apply_chat_template(chat, add_generation_prompt=True)
llm = LLM(model=model_name, trust_remote_code=True)
inputs = {"prompt": prompt, "multi_modal_data": {"image": [image]}}
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
print("RESPONSE:", outputs[0].outputs[0].text)
高级用法
文档未提及高级用法相关代码,故跳过此部分。
📚 详细文档
模型创建
此模型使用 llm - compressor 创建,以下是作为多模态公告博客一部分运行的代码片段:
模型创建代码
import requests
import torch
from PIL import Image
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
from llmcompressor.transformers import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
model_id = google/gemma-3-27b-it
model = Gemma3ForConditionalGeneration.from_pretrained(
model_id, device_map="auto", torch_dtype="auto"
)
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
recipe = [
QuantizationModifier(
targets="Linear",
scheme="FP8_DYNAMIC",
sequential_targets=["Gemma3DecoderLayer"],
ignore=["re:.*lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
),
]
SAVE_DIR=f"{model_id.split('/')[1]}-FP8-Dynamic"
oneshot(
model=model,
recipe=recipe,
trust_remote_code_model=True,
output_dir=SAVE_DIR
)
模型评估
该模型使用 lm_evaluation_harness 进行 OpenLLM v1 文本基准测试。评估使用以下命令进行:
评估命令
OpenLLM v1
lm_eval \
--model vllm \
--model_args pretrained="<model_name>",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=<n>,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True,enforce_eager=True \
--tasks openllm \
--batch_size auto
准确率
类别 |
指标 |
google/gemma - 3 - 27b - it |
RedHatAI/gemma - 3 - 27b - it - FP8 - Dynamic |
恢复率(%) |
OpenLLM V1 |
ARC Challenge |
72.53% |
72.70% |
100.24% |
OpenLLM V1 |
GSM8K |
92.12% |
91.51% |
99.34% |
OpenLLM V1 |
Hellaswag |
85.78% |
85.69% |
99.90% |
OpenLLM V1 |
MMLU |
77.53% |
77.45% |
99.89% |
OpenLLM V1 |
Truthfulqa (mc2) |
62.20% |
62.20% |
99.99% |
OpenLLM V1 |
Winogrande |
79.40% |
78.77% |
99.20% |
OpenLLM V1 |
平均得分 |
78.26% |
78.05% |
99.73% |
视觉评估 |
MMMU (val) |
50.89% |
51.00% |
100.22% |
视觉评估 |
ChartQA |
72.16% |
72.16% |
100.0% |
视觉评估 |
平均得分 |
61.53% |
61.58% |
100.11% |
🔧 技术细节
文档未提及具体技术细节内容,故跳过此章节。
📄 许可证
本模型采用 Apache 2.0 许可证。