Views
No views yet
1from vllm import LLM, SamplingParams
2from vllm.assets.image import ImageAsset
3from transformers import AutoProcessor
4
5# Define model name once
6model_name = "RedHatAI/gemma-3-12b-it-FP8-dynamic"
7
8# Load image and processor
9image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
10processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
11
12# Build multimodal prompt
13chat = [
14 {"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "What is the content of this image?"}]},
15 {"role": "assistant", "content": []}
16]
17prompt = processor.apply_chat_template(chat, add_generation_prompt=True)
18
19# Initialize model
20llm = LLM(model=model_name, trust_remote_code=True)
21
22# Run inference
23inputs = {"prompt": prompt, "multi_modal_data": {"image": [image]}}
24outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
25
26# Display result
27print("RESPONSE:", outputs[0].outputs[0].text)
281import requests
2import torch
3from PIL import Image
4from transformers import AutoProcessor, Gemma3ForConditionalGeneration
5from llmcompressor.transformers import oneshot
6from llmcompressor.modifiers.quantization import QuantizationModifier
7
8# Load model.
9model_id = google/gemma-3-12b-it
10model = Gemma3ForConditionalGeneration.from_pretrained(
11 model_id, device_map="auto", torch_dtype="auto"
12)
13processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
14
15# Recipe
16recipe = [
17 QuantizationModifier(
18 targets="Linear",
19 scheme="FP8_DYNAMIC",
20 sequential_targets=["Gemma3DecoderLayer"],
21 ignore=["re:.*lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
22 ),
23]
24
25SAVE_DIR=f"{model_id.split('/')[1]}-FP8-Dynamic"
26
27# Perform oneshot
28oneshot(
29 model=model,
30 recipe=recipe,
31 trust_remote_code_model=True,
32 output_dir=SAVE_DIR
33)
34
35lm_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| Category | Metric | google/gemma-3-12b-it | RedHatAI/gemma-3-12b-it-FP8-Dynamic | Recovery (%) |
|---|---|---|---|---|
| OpenLLM V1 | ARC Challenge | 68.43% | 68.86% | 100.62% |
| GSM8K | 88.10% | 88.02% | 99.91% | |
| Hellaswag | 83.76% | 83.78% | 100.02% | |
| MMLU | 72.15% | 71.80% | 99.51% | |
| Truthfulqa (mc2) | 58.13% | 59.35% | 102.09% | |
| Winogrande | 79.40% | 79.48% | 100.10% | |
| Average Score | 74.99% | 75.21% | 100.29% | |
| Vision Evals | MMMU (val) | 48.78% | 49.00% | 100.45% |
| ChartQA | 68.08% | 68.88% | 101.18% | |
| Average Score | 58.43% | 58.94% | 100.81% |