🚀 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 許可證。