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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
tags:
|
| 3 |
+
- vllm
|
| 4 |
+
- vision
|
| 5 |
+
- fp8
|
| 6 |
+
license: apache-2.0
|
| 7 |
+
license_link: >-
|
| 8 |
+
https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md
|
| 9 |
+
language:
|
| 10 |
+
- en
|
| 11 |
+
base_model: google/gemma-3-12b-it
|
| 12 |
+
library_name: transformers
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# gemma-3-12b-it-FP8-Dynamic
|
| 16 |
+
|
| 17 |
+
## Model Overview
|
| 18 |
+
- **Model Architecture:** gemma-3-12b-it
|
| 19 |
+
- **Input:** Vision-Text
|
| 20 |
+
- **Output:** Text
|
| 21 |
+
- **Model Optimizations:**
|
| 22 |
+
- **Weight quantization:** FP8
|
| 23 |
+
- **Activation quantization:** FP8
|
| 24 |
+
- **Release Date:** 2/24/2025
|
| 25 |
+
- **Version:** 1.0
|
| 26 |
+
- **Model Developers:** Neural Magic
|
| 27 |
+
|
| 28 |
+
Quantized version of [google/gemma-3-12b-it](https://huggingface.co/google/gemma-3-12b-it).
|
| 29 |
+
|
| 30 |
+
### Model Optimizations
|
| 31 |
+
|
| 32 |
+
This model was obtained by quantizing the weights of [google/gemma-3-12b-it](https://huggingface.co/google/gemma-3-12b-it) to FP8 data type, ready for inference with vLLM >= 0.5.2.
|
| 33 |
+
|
| 34 |
+
## Deployment
|
| 35 |
+
|
| 36 |
+
### Use with vLLM
|
| 37 |
+
|
| 38 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from vllm import LLM, SamplingParams
|
| 42 |
+
from vllm.assets.image import ImageAsset
|
| 43 |
+
from transformers import AutoProcessor
|
| 44 |
+
|
| 45 |
+
# Define model name once
|
| 46 |
+
model_name = "RedHatAI/gemma-3-12b-it-FP8-dynamic"
|
| 47 |
+
|
| 48 |
+
# Load image and processor
|
| 49 |
+
image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
|
| 50 |
+
processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
|
| 51 |
+
|
| 52 |
+
# Build multimodal prompt
|
| 53 |
+
chat = [
|
| 54 |
+
{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "What is the content of this image?"}]},
|
| 55 |
+
{"role": "assistant", "content": []}
|
| 56 |
+
]
|
| 57 |
+
prompt = processor.apply_chat_template(chat, add_generation_prompt=True)
|
| 58 |
+
|
| 59 |
+
# Initialize model
|
| 60 |
+
llm = LLM(model=model_name, trust_remote_code=True)
|
| 61 |
+
|
| 62 |
+
# Run inference
|
| 63 |
+
inputs = {"prompt": prompt, "multi_modal_data": {"image": [image]}}
|
| 64 |
+
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
|
| 65 |
+
|
| 66 |
+
# Display result
|
| 67 |
+
print("RESPONSE:", outputs[0].outputs[0].text)
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
| 72 |
+
|
| 73 |
+
## Creation
|
| 74 |
+
|
| 75 |
+
This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below as part a multimodal announcement blog.
|
| 76 |
+
|
| 77 |
+
<details>
|
| 78 |
+
<summary>Model Creation Code</summary>
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
import requests
|
| 82 |
+
import torch
|
| 83 |
+
from PIL import Image
|
| 84 |
+
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
|
| 85 |
+
from llmcompressor.transformers import oneshot
|
| 86 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
| 87 |
+
|
| 88 |
+
# Load model.
|
| 89 |
+
model_id = google/gemma-3-12b-it
|
| 90 |
+
model = Gemma3ForConditionalGeneration.from_pretrained(
|
| 91 |
+
model_id, device_map="auto", torch_dtype="auto"
|
| 92 |
+
)
|
| 93 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 94 |
+
|
| 95 |
+
# Recipe
|
| 96 |
+
recipe = [
|
| 97 |
+
QuantizationModifier(
|
| 98 |
+
targets="Linear",
|
| 99 |
+
scheme="FP8_DYNAMIC",
|
| 100 |
+
sequential_targets=["Gemma3DecoderLayer"],
|
| 101 |
+
ignore=["re:.*lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
|
| 102 |
+
),
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
SAVE_DIR=f"{model_id.split('/')[1]}-FP8-Dynamic"
|
| 106 |
+
|
| 107 |
+
# Perform oneshot
|
| 108 |
+
oneshot(
|
| 109 |
+
model=model,
|
| 110 |
+
recipe=recipe,
|
| 111 |
+
trust_remote_code_model=True,
|
| 112 |
+
output_dir=SAVE_DIR
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
</details>
|
| 118 |
+
|
| 119 |
+
## Evaluation
|
| 120 |
+
|
| 121 |
+
The model was evaluated using [lm_evaluation_harness](https://github.com/neuralmagic/lm-evaluation-harness) for OpenLLM v1 text benchmark. The evaluations were conducted using the following commands:
|
| 122 |
+
|
| 123 |
+
<details>
|
| 124 |
+
<summary>Evaluation Commands</summary>
|
| 125 |
+
|
| 126 |
+
### OpenLLM v1
|
| 127 |
+
```
|
| 128 |
+
lm_eval \
|
| 129 |
+
--model vllm \
|
| 130 |
+
--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 \
|
| 131 |
+
--tasks openllm \
|
| 132 |
+
--batch_size auto
|
| 133 |
+
```
|
| 134 |
+
</details>
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
### Accuracy
|
| 138 |
+
|
| 139 |
+
<table>
|
| 140 |
+
<thead>
|
| 141 |
+
<tr>
|
| 142 |
+
<th>Category</th>
|
| 143 |
+
<th>Metric</th>
|
| 144 |
+
<th>google/gemma-3-12b-it</th>
|
| 145 |
+
<th>RedHatAI/gemma-3-12b-it-FP8-Dynamic</th>
|
| 146 |
+
<th>Recovery (%)</th>
|
| 147 |
+
</tr>
|
| 148 |
+
</thead>
|
| 149 |
+
<tbody>
|
| 150 |
+
<tr>
|
| 151 |
+
<td rowspan="7"><b>OpenLLM V1</b></td>
|
| 152 |
+
<td>ARC Challenge</td>
|
| 153 |
+
<td>68.43%</td>
|
| 154 |
+
<td>%</td>
|
| 155 |
+
<td>%</td>
|
| 156 |
+
</tr>
|
| 157 |
+
<tr>
|
| 158 |
+
<td>GSM8K</td>
|
| 159 |
+
<td>88.10%</td>
|
| 160 |
+
<td>%</td>
|
| 161 |
+
<td>%</td>
|
| 162 |
+
</tr>
|
| 163 |
+
<tr>
|
| 164 |
+
<td>Hellaswag</td>
|
| 165 |
+
<td>83.76%</td>
|
| 166 |
+
<td>%</td>
|
| 167 |
+
<td>%</td>
|
| 168 |
+
</tr>
|
| 169 |
+
<tr>
|
| 170 |
+
<td>MMLU</td>
|
| 171 |
+
<td>72.15%</td>
|
| 172 |
+
<td>%</td>
|
| 173 |
+
<td>%</td>
|
| 174 |
+
</tr>
|
| 175 |
+
<tr>
|
| 176 |
+
<td>Truthfulqa (mc2)</td>
|
| 177 |
+
<td>58.13%</td>
|
| 178 |
+
<td>%</td>
|
| 179 |
+
<td>%</td>
|
| 180 |
+
</tr>
|
| 181 |
+
<tr>
|
| 182 |
+
<td>Winogrande</td>
|
| 183 |
+
<td>79.40%%</td>
|
| 184 |
+
<td>%</td>
|
| 185 |
+
<td>%</td>
|
| 186 |
+
</tr>
|
| 187 |
+
<tr>
|
| 188 |
+
<td><b>Average Score</b></td>
|
| 189 |
+
<td><b>74.99%</b></td>
|
| 190 |
+
<td><b>%</b></td>
|
| 191 |
+
<td><b>%</b></td>
|
| 192 |
+
</tr>
|
| 193 |
+
<tr>
|
| 194 |
+
<td rowspan="3"><b>Vision Evals</b></td>
|
| 195 |
+
<td>MMMU (val)</td>
|
| 196 |
+
<td>48.78%</td>
|
| 197 |
+
<td>%</td>
|
| 198 |
+
<td>%</td>
|
| 199 |
+
</tr>
|
| 200 |
+
<tr>
|
| 201 |
+
<td>ChartQA</td>
|
| 202 |
+
<td>68.08%</td>
|
| 203 |
+
<td>%</td>
|
| 204 |
+
<td>%</td>
|
| 205 |
+
</tr>
|
| 206 |
+
<tr>
|
| 207 |
+
<td><b>Average Score</b></td>
|
| 208 |
+
<td><b>58.43%</b></td>
|
| 209 |
+
<td><b>%</b></td>
|
| 210 |
+
<td><b>%</b></td>
|
| 211 |
+
</tr>
|
| 212 |
+
</tbody>
|
| 213 |
+
</table>
|
| 214 |
+
|