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-4b-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-4b-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-4b-it | RedHatAI/gemma-3-4b-it-FP8-Dynamic | Recovery (%) |
|---|---|---|---|---|
| OpenLLM V1 | ARC Challenge | 56.57% | 57.08% | 100.90% |
| GSM8K | 76.12% | 75.51% | 99.20% | |
| Hellaswag | 74.96% | 74.92% | 99.95% | |
| MMLU | 58.38% | 57.98% | 99.32% | |
| Truthfulqa (mc2) | 51.87% | 51.62% | 99.52% | |
| Winogrande | 70.32% | 71.03% | 101.01%%%% | |
| Average Score | 64.70% | 64.69% | 99.98% | |
| Vision Evals | MMMU (val) | 39.89%/td> | 38.33% | 96.09% |
| ChartQA | 50.76% | 51.60% | 101.65% | |
| Average Score | 45.33% | 44.97% | 98.87% |