nm-research commited on
Commit
10c59be
·
verified ·
1 Parent(s): c16e30f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +212 -3
README.md CHANGED
@@ -1,4 +1,213 @@
1
  ---
2
- base_model:
3
- - google/gemma-3-4b-it
4
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-4b-it
12
+ library_name: transformers
13
+ ---
14
+
15
+ # gemma-3-4b-it-FP8-Dynamic
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** gemma-3-4b-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-4b-it](https://huggingface.co/google/gemma-3-4b-it).
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights of [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-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-4b-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-4b-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
+ ### Accuracy
137
+
138
+ <table>
139
+ <thead>
140
+ <tr>
141
+ <th>Category</th>
142
+ <th>Metric</th>
143
+ <th>google/gemma-3-4b-it</th>
144
+ <th>RedHatAI/gemma-3-4b-it-FP8-Dynamic</th>
145
+ <th>Recovery (%)</th>
146
+ </tr>
147
+ </thead>
148
+ <tbody>
149
+ <tr>
150
+ <td rowspan="7"><b>OpenLLM V1</b></td>
151
+ <td>ARC Challenge</td>
152
+ <td>56.57%</td>
153
+ <td>57.08%</td>
154
+ <td>100.90%</td>
155
+ </tr>
156
+ <tr>
157
+ <td>GSM8K</td>
158
+ <td>76.12%</td>
159
+ <td>75.51%</td>
160
+ <td>99.20%</td>
161
+ </tr>
162
+ <tr>
163
+ <td>Hellaswag</td>
164
+ <td>74.96%</td>
165
+ <td>74.92%</td>
166
+ <td>99.95%</td>
167
+ </tr>
168
+ <tr>
169
+ <td>MMLU</td>
170
+ <td>58.38%</td>
171
+ <td>57.98%</td>
172
+ <td>99.32%</td>
173
+ </tr>
174
+ <tr>
175
+ <td>Truthfulqa (mc2)</td>
176
+ <td>51.87%</td>
177
+ <td>51.62%</td>
178
+ <td>99.52%</td>
179
+ </tr>
180
+ <tr>
181
+ <td>Winogrande</td>
182
+ <td>70.32%</td>
183
+ <td>71.03%</td>
184
+ <td>101.01%%%%</td>
185
+ </tr>
186
+ <tr>
187
+ <td><b>Average Score</b></td>
188
+ <td><b>64.70%</b></td>
189
+ <td><b>64.69%</b></td>
190
+ <td><b>99.98%</b></td>
191
+ </tr>
192
+ <tr>
193
+ <td rowspan="3"><b>Vision Evals</b></td>
194
+ <td>MMMU (val)</td>
195
+ <td>%</td>
196
+ <td>%</td>
197
+ <td>%</td>
198
+ </tr>
199
+ <tr>
200
+ <td>ChartQA</td>
201
+ <td>%</td>
202
+ <td>%</td>
203
+ <td>%</td>
204
+ </tr>
205
+ <tr>
206
+ <td><b>Average Score</b></td>
207
+ <td><b>%</b></td>
208
+ <td><b>%</b></td>
209
+ <td><b>%</b></td>
210
+ </tr>
211
+ </tbody>
212
+ </table>
213
+