krishnateja95 commited on
Commit
d22d2aa
·
verified ·
1 Parent(s): 5d359b5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +338 -3
README.md CHANGED
@@ -1,3 +1,338 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: text-generation
4
+ tags:
5
+ - fp8
6
+ - quantized
7
+ - llm-compressor
8
+ - compressed-tensors
9
+ - red hat
10
+ base_model:
11
+ - ibm-granite/granite-4.0-h-small
12
+ ---
13
+
14
+
15
+ # Granite-4.0-h-small
16
+
17
+ ## Model Overview
18
+ - **Model Architecture:** GraniteMoeHybridForCausalLM
19
+ - **Input:** Text
20
+ - **Output:** Text
21
+ - **Model Optimizations:**
22
+ - **Weight quantization:** FP8
23
+ - **Activation quantization:** FP8
24
+ - **Release Date:**
25
+ - **Version:** 1.0
26
+ - **Model Developers:**: Red Hat
27
+
28
+ Quantized version of [ibm-granite/granite-4.0-h-small](https://huggingface.co/ibm-granite/granite-4.0-h-small).
29
+
30
+ ### Model Optimizations
31
+
32
+ This model was obtained by quantizing the weights and activations of [ibm-granite/granite-4.0-h-small](https://huggingface.co/ibm-granite/granite-4.0-h-small) to FP8 data type.
33
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
34
+ Only the weights and activations of the linear operators within transformers blocks of the language model are quantized.
35
+
36
+ ## Deployment
37
+
38
+ ### Use with vLLM
39
+
40
+ 1. Install specific version:
41
+ ```
42
+ uv pip install -U git+https://github.com/vllm-project/vllm.git \
43
+ --extra-index-url https://wheels.vllm.ai/nightly \
44
+ --no-deps \
45
+ --no-cache
46
+
47
+ uv pip install compressed-tensors==0.12.3a20251114 --no-cache
48
+ uv pip install --upgrade torchvision --break-system-packages --no-cache
49
+ uv pip install cloudpickle msgspec zmq blake3 cachetools prometheus_client fastapi openai openai_harmony pybase64 llguidance diskcache xgrammar lm-format-enforcer partial-json-parser cbor2 einops gguf numba --no-cache
50
+
51
+ ```
52
+
53
+ 2. Initialize vLLM server:
54
+ ```
55
+ vllm serve RedHatAI/granite-4.0-h-small-FP8-block --tensor_parallel_size 1
56
+ ```
57
+
58
+ 3. Send requests to the server:
59
+
60
+ ```python
61
+ from openai import OpenAI
62
+
63
+ # Modify OpenAI's API key and API base to use vLLM's API server.
64
+ openai_api_key = "EMPTY"
65
+ openai_api_base = "http://<your-server-host>:8000/v1"
66
+
67
+ client = OpenAI(
68
+ api_key=openai_api_key,
69
+ base_url=openai_api_base,
70
+ )
71
+
72
+ model = "RedHatAI/granite-4.0-h-small-FP8-block"
73
+
74
+ messages = [
75
+ {"role": "user", "content": "Explain quantum mechanics clearly and concisely."},
76
+ ]
77
+
78
+
79
+ outputs = client.chat.completions.create(
80
+ model=model,
81
+ messages=messages,
82
+ )
83
+
84
+ generated_text = outputs.choices[0].message.content
85
+ print(generated_text)
86
+ ```
87
+
88
+ ## Creation
89
+
90
+ This model was quantized using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as shown below.
91
+
92
+
93
+ <details>
94
+ <summary>Creation details</summary>
95
+
96
+ Install specific llm-compression version:
97
+ ```
98
+ uv pip install git+https://github.com/vllm-project/llm-compressor.git@refs/pull/2001/head --no-cache
99
+ uv pip install --upgrade torchvision --break-system-packages --no-cache
100
+ ```
101
+
102
+
103
+ ```python
104
+ from transformers import AutoModelForCausalLM, AutoTokenizer
105
+
106
+ from llmcompressor import oneshot
107
+ from llmcompressor.modifiers.quantization import QuantizationModifier
108
+ from llmcompressor.utils import dispatch_for_generation
109
+ from llmcompressor.modeling import replace_modules_for_calibration
110
+ from llmcompressor.modeling.granite4 import pack_3d_experts
111
+
112
+ MODEL_ID = "ibm-granite/granite-4.0-h-small"
113
+
114
+ model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
115
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
116
+
117
+ model = replace_modules_for_calibration(model)
118
+
119
+ ignore_lay = ["lm_head", "re:.*block_sparse_moe.router", "re:.*mamba.in_proj", "re:.*shared_mlp.input_linear"]
120
+
121
+ recipe = QuantizationModifier(
122
+ targets=["Linear"],
123
+ scheme="FP8_BLOCK",
124
+ ignore=ignore_lay,
125
+ )
126
+
127
+ oneshot(model=model, recipe=recipe)
128
+
129
+ print("========== SAMPLE GENERATION ==============")
130
+ dispatch_for_generation(model)
131
+ input_ids = tokenizer(
132
+ "Describe Large Language Model", return_tensors="pt"
133
+ ).input_ids.to(model.device)
134
+ output = model.generate(input_ids, max_new_tokens=35)
135
+ print(tokenizer.decode(output[0]))
136
+ print("==========================================")
137
+
138
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-block"
139
+ print(f"Saving to {SAVE_DIR}")
140
+
141
+ model.save_pretrained(SAVE_DIR)
142
+ tokenizer.save_pretrained(SAVE_DIR)
143
+ pack_3d_experts(SAVE_DIR)
144
+ ```
145
+ </details>
146
+
147
+
148
+ ## Evaluation
149
+
150
+
151
+ The model was evaluated on the OpenLLM leaderboard task, using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness).
152
+ [vLLM](https://docs.vllm.ai/en/stable/) was used for all evaluations.
153
+
154
+ <details>
155
+ <summary>Evaluation details</summary>
156
+
157
+ Install specific version:
158
+ ```
159
+ uv pip install -U git+https://github.com/vllm-project/vllm.git \
160
+ --extra-index-url https://wheels.vllm.ai/nightly \
161
+ --no-deps \
162
+ --no-cache
163
+
164
+
165
+ uv pip install compressed-tensors==0.12.3a20251114 --no-cache
166
+ uv pip install --upgrade torchvision --break-system-packages --no-cache
167
+ uv pip install cloudpickle msgspec zmq blake3 cachetools prometheus_client fastapi openai openai_harmony pybase64 llguidance diskcache xgrammar lm-format-enforcer partial-json-parser cbor2 einops gguf numba --no-cache
168
+ ```
169
+
170
+ **Openllm V1**
171
+ ```
172
+ lm_eval \
173
+ --model vllm \
174
+ --model_args pretrained="RedHatAI/granite-4.0-h-small-FP8-block",dtype=auto,add_bos_token=True,max_model_len=16384,tensor_parallel_size=1,gpu_memory_utilization=0.9,enable_chunked_prefill=True,trust_remote_code=True \
175
+ --tasks openllm \
176
+ --write_out \
177
+ --batch_size auto \
178
+ --show_config
179
+ ```
180
+
181
+
182
+ **Openllm V2**
183
+ ```
184
+ lm_eval \
185
+ --model vllm \
186
+ --model_args pretrained="RedHatAI/granite-4.0-h-small-FP8-block",dtype=auto,add_bos_token=False,max_model_len=16384,tensor_parallel_size=1,gpu_memory_utilization=0.7,disable_log_stats=True,enable_chunked_prefill=True,trust_remote_code=True \
187
+ --tasks leaderboard \
188
+ --apply_chat_template \
189
+ --fewshot_as_multiturn \
190
+ --write_out \
191
+ --batch_size auto \
192
+ --show_config
193
+ ```
194
+
195
+
196
+ **Coding Benchmarks**
197
+
198
+ ```
199
+ evalplus.evaluate --model "RedHatAI/granite-4.0-h-small-FP8-block" \
200
+ --dataset "humaneval" \
201
+ --backend vllm \
202
+ --tp 1 \
203
+ --greedy
204
+
205
+ evalplus.evaluate --model "RedHatAI/granite-4.0-h-small-FP8-block" \
206
+ --dataset "mbpp" \
207
+ --backend vllm \
208
+ --tp 1 \
209
+ --greedy
210
+
211
+ ```
212
+
213
+ </details>
214
+
215
+
216
+ <!-- <b>*</b> I/p Length = 2048, O/p Length = 2048, #Requests = 1024 -->
217
+
218
+
219
+
220
+ ### Accuracy Comparison
221
+ <table>
222
+ <thead>
223
+ <tr>
224
+ <th>Category</th>
225
+ <th>Metric</th>
226
+ <th>ibm-granite/granite-4.0-h-small</th>
227
+ <th>ibm-granite/granite-4.0-h-small-FP8</th>
228
+ <th>RedHatAI/granite-4.0-h-small-FP8-block</th>
229
+ <th>RedHatAI/granite-4.0-h-small-FP8-dynamic</th>
230
+ </tr>
231
+ </thead>
232
+ <tbody>
233
+ <!-- OpenLLM Leaderboard V1 -->
234
+ <tr>
235
+ <td rowspan="7"><b>OpenLLM V1</b></td>
236
+ <td>ARC-Challenge (Acc-Norm, 25-shot)</td>
237
+ <td>72.27</td>
238
+ <td>72.10 (99.76%)</td>
239
+ <td>72.27 (100.00%)</td>
240
+ <td>72.10 (99.76%)</td>
241
+ </tr>
242
+ <tr>
243
+ <td>GSM8K (Strict-Match, 5-shot)</td>
244
+ <td>85.22</td>
245
+ <td>85.29 (100.09%)</td>
246
+ <td>85.52 (100.36%)</td>
247
+ <td>84.84 (99.56%)</td>
248
+ </tr>
249
+ <tr>
250
+ <td>HellaSwag (Acc-Norm, 10-shot)</td>
251
+ <td>86.08</td>
252
+ <td>85.88 (99.77%)</td>
253
+ <td>85.96 (99.86%)</td>
254
+ <td>85.88 (99.77%)</td>
255
+ </tr>
256
+ <tr>
257
+ <td>MMLU (Acc, 5-shot)</td>
258
+ <td>77.15</td>
259
+ <td>77.18 (100.03%)</td>
260
+ <td>77.23 (100.09%)</td>
261
+ <td>77.18 (100.03%)</td>
262
+ </tr>
263
+ <tr>
264
+ <td>TruthfulQA (MC2, 0-shot)</td>
265
+ <td>57.64</td>
266
+ <td>57.63 (99.99%)</td>
267
+ <td>57.94 (100.52%)</td>
268
+ <td>57.63 (100.00%)</td>
269
+ </tr>
270
+ <tr>
271
+ <td>Winogrande (Acc, 5-shot)</td>
272
+ <td>81.37</td>
273
+ <td>81.45 (100.10%)</td>
274
+ <td>80.82 (99.32%)</td>
275
+ <td>81.45 (100.10%)</td>
276
+ </tr>
277
+ <tr>
278
+ <td><b>Average Score</b></td>
279
+ <td><b>76.62</b></td>
280
+ <td><b>76.59 (99.96%)</b></td>
281
+ <td><b>76.62 (100.00%)</b></td>
282
+ <td><b>76.51 (99.86%)</b></td>
283
+ </tr>
284
+ <!-- OpenLLM Leaderboard V2 -->
285
+ <tr>
286
+ <td rowspan="7"><b>OpenLLM V2</b></td>
287
+ <td>IFEval (Inst Level Strict Acc, 0-shot)</td>
288
+ <td>87.53</td>
289
+ <td>87.17 (99.59%)</td>
290
+ <td>86.69 (99.04%)</td>
291
+ <td>87.41 (99.86%)</td>
292
+ </tr>
293
+ <tr>
294
+ <td>BBH (Acc-Norm, 3-shot)</td>
295
+ <td>61.52</td>
296
+ <td>61.31 (99.66%)</td>
297
+ <td>61.40 (99.80%)</td>
298
+ <td>61.19 (99.46%)</td>
299
+ </tr>
300
+ <tr>
301
+ <td>Math-Hard (Exact-Match, 4-shot)</td>
302
+ <td>46.22</td>
303
+ <td>43.73 (94.61%)</td>
304
+ <td>43.88 (94.93%)</td>
305
+ <td>41.77 (90.36%)</td>
306
+ </tr>
307
+ <tr>
308
+ <td>GPQA (Acc-Norm, 0-shot)</td>
309
+ <td>35.23</td>
310
+ <td>34.98 (99.29%)</td>
311
+ <td>34.23 (97.14%)</td>
312
+ <td>34.23 (97.14%)</td>
313
+ </tr>
314
+ <tr>
315
+ <td>MUSR (Acc-Norm, 0-shot)</td>
316
+ <td>46.69</td>
317
+ <td>46.56 (99.72%)</td>
318
+ <td>45.77 (98.02%)</td>
319
+ <td>45.77 (98.02%)</td>
320
+ </tr>
321
+ <tr>
322
+ <td>MMLU-Pro (Acc, 5-shot)</td>
323
+ <td>47.99</td>
324
+ <td>47.63 (99.26%)</td>
325
+ <td>47.93 (99.88%)</td>
326
+ <td>47.58 (99.15%)</td>
327
+ </tr>
328
+ <tr>
329
+ <td><b>Average Score</b></td>
330
+ <td><b>54.20</b></td>
331
+ <td><b>53.56 (98.82%)</b></td>
332
+ <td><b>53.32 (98.38%)</b></td>
333
+ <td><b>52.99 (97.77%)</b></td>
334
+ </tr>
335
+ </tbody>
336
+ </table>
337
+
338
+