🚀 gemma-3-12b-it-quantized.w8a8
これは、google/gemma-3-12b-it
をベースにした量子化バージョンのモデルです。vLLM を使用することで、視覚的なテキスト入力とテキスト出力のシナリオに対応した効率的なデプロイが可能です。
🚀 クイックスタート
このモデルは、vLLM バックエンドを使用して効率的にデプロイできます。以下は使用例です。
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
from transformers import AutoProcessor
model_name = "RedHatAI/gemma-3-12b-it-quantized.w8a8"
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 互換サービスもサポートしています。詳細については ドキュメント を参照してください。
✨ 主な機能
モデル概要
属性 |
詳細 |
モデルタイプ |
google/gemma-3-12b-it をベースにした量子化バージョン |
入力タイプ |
視覚 - テキスト |
出力タイプ |
テキスト |
重み量子化 |
INT8 |
活性化量子化 |
INT8 |
リリース日 |
2025 年 6 月 4 日 |
バージョン |
1.0 |
モデル開発者 |
RedHatAI |
このモデルは、google/gemma-3-12b-it の重みを INT8 データ型に量子化することで作成され、vLLM >= 0.8.0 の推論に使用できます。
💻 使用例
基本的な使用法
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
from transformers import AutoProcessor
model_name = "RedHatAI/gemma-3-12b-it-quantized.w8a8"
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 base64
from io import BytesIO
import torch
from datasets import load_dataset
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.transformers import oneshot
model_id = "google/gemma-3-12b-it"
model = Gemma3ForConditionalGeneration.from_pretrained(
model_id,
device_map="auto",
torch_dtype="auto",
)
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
DATASET_ID = "neuralmagic/calibration"
DATASET_SPLIT = {"LLM": "train[:1024]"}
NUM_CALIBRATION_SAMPLES = 1024
MAX_SEQUENCE_LENGTH = 2048
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
ds = ds.shuffle(seed=42)
dampening_frac=0.01
def data_collator(batch):
assert len(batch) == 1, "Only batch size of 1 is supported for calibration"
item = batch[0]
collated = {}
import torch
for key, value in item.items():
if isinstance(value, torch.Tensor):
collated[key] = value.unsqueeze(0)
elif isinstance(value, list) and isinstance(value[0][0], int):
collated[key] = torch.tensor(value)
elif isinstance(value, list) and isinstance(value[0][0], float):
collated[key] = torch.tensor(value)
elif isinstance(value, list) and isinstance(value[0][0], torch.Tensor):
collated[key] = torch.stack(value)
elif isinstance(value, torch.Tensor):
collated[key] = value
else:
print(f"[WARN] Unrecognized type in collator for key={key}, type={type(value)}")
return collated
recipe = [
GPTQModifier(
targets="Linear",
ignore=["re:.*lm_head.*", "re:.*embed_tokens.*", "re:vision_tower.*", "re:multi_modal_projector.*"],
sequential_update=True,
sequential_targets=["Gemma3DecoderLayer"],
dampening_frac=dampening_frac,
)
]
SAVE_DIR=f"{model_id.split('/')[1]}-quantized.w8a8"
oneshot(
model=model,
tokenizer=model_id,
dataset=ds,
recipe=recipe,
max_seq_length=MAX_SEQUENCE_LENGTH,
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
trust_remote_code_model=True,
data_collator=data_collator,
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-12b-it |
RedHatAI/gemma-3-12b-it-quantized.w8a8 |
回復率 (%) |
OpenLLM V1 |
ARC Challenge |
68.43% |
68.43% |
100.00% |
OpenLLM V1 |
GSM8K |
88.10% |
87.72% |
99.57% |
OpenLLM V1 |
Hellaswag |
83.76% |
83.53% |
99.73% |
OpenLLM V1 |
MMLU |
72.15% |
71.65% |
99.30% |
OpenLLM V1 |
Truthfulqa (mc2) |
58.13% |
58.44% |
100.54% |
OpenLLM V1 |
Winogrande |
79.40% |
78.77% |
99.20% |
OpenLLM V1 |
平均スコア |
74.99% |
74.76% |
99.68% |
視覚評価 |
MMMU (val) |
48.78% |
47.44% |
97.25% |
視覚評価 |
ChartQA |
68.08% |
67.04% |
98.47% |
視覚評価 |
平均スコア |
58.43% |
57.24% |
97.86% |
📄 ライセンス
このモデルは gemma ライセンスを使用しています。