nm-research commited on
Commit
f657419
·
verified ·
1 Parent(s): 7aace88

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +348 -3
README.md CHANGED
@@ -1,3 +1,348 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - fp4
4
+ - vllm
5
+ language:
6
+ - en
7
+ - de
8
+ - fr
9
+ - it
10
+ - pt
11
+ - hi
12
+ - es
13
+ - th
14
+ pipeline_tag: text-generation
15
+ license: apache-2.0
16
+ base_model: unsloth/Mistral-Small-3.2-24B-Instruct-2506
17
+ ---
18
+
19
+ # Mistral-Small-3.2-24B-Instruct-2506-NVFP4
20
+
21
+ ## Model Overview
22
+ - **Model Architecture:** unsloth/Mistral-Small-3.2-24B-Instruct-2506
23
+ - **Input:** Text
24
+ - **Output:** Text
25
+ - **Model Optimizations:**
26
+ - **Weight quantization:** FP4
27
+ - **Activation quantization:** FP4
28
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
29
+ - **Release Date:** 10/29/2025
30
+ - **Version:** 1.0
31
+ - **Model Developers:** RedHatAI
32
+
33
+ This model is a quantized version of [unsloth/Mistral-Small-3.2-24B-Instruct-2506](https://huggingface.co/unsloth/Mistral-Small-3.2-24B-Instruct-2506).
34
+ It was evaluated on a several tasks to assess the its quality in comparison to the unquatized model.
35
+
36
+ ### Model Optimizations
37
+
38
+ This model was obtained by quantizing the weights and activations of [unsloth/Mistral-Small-3.2-24B-Instruct-2506](https://huggingface.co/unsloth/Mistral-Small-3.2-24B-Instruct-2506) to FP4 data type, ready for inference with vLLM>=0.9.1
39
+ This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 25%.
40
+
41
+ Only the weights and activations of the linear operators within transformers blocks are quantized using [LLM Compressor](https://github.com/vllm-project/llm-compressor).
42
+
43
+ ## Deployment
44
+
45
+ ### Use with vLLM
46
+
47
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
48
+
49
+ ```python
50
+ from vllm import LLM, SamplingParams
51
+ from transformers import AutoTokenizer
52
+
53
+ model_id = "RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4"
54
+ number_gpus = 1
55
+
56
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
57
+
58
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
59
+
60
+ messages = [
61
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
62
+ {"role": "user", "content": "Who are you?"},
63
+ ]
64
+
65
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
66
+
67
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
68
+
69
+ outputs = llm.generate(prompts, sampling_params)
70
+
71
+ generated_text = outputs[0].outputs[0].text
72
+ print(generated_text)
73
+ ```
74
+
75
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
76
+
77
+ ## Creation
78
+
79
+ This model was created by applying [LLM Compressor with calibration samples from UltraChat](https://github.com/vllm-project/llm-compressor/blob/main/examples/quantization_w4a4_fp4/llama3_example.py), as presented in the code snipet below.
80
+
81
+ <details>
82
+
83
+ ```python
84
+ from datasets import load_dataset
85
+ from transformers import AutoModelForCausalLM, AutoTokenizer
86
+
87
+ from llmcompressor import oneshot
88
+ from llmcompressor.modifiers.quantization import QuantizationModifier
89
+ from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
90
+ from llmcompressor.utils import dispatch_for_generation
91
+
92
+ MODEL_ID = "unsloth/Mistral-Small-3.2-24B-Instruct-2506"
93
+
94
+ # Load model.
95
+ model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
96
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
97
+
98
+ DATASET_ID = "HuggingFaceH4/ultrachat_200k"
99
+ DATASET_SPLIT = "train_sft"
100
+
101
+ # Select number of samples. 512 samples is a good place to start.
102
+ # Increasing the number of samples can improve accuracy.
103
+ NUM_CALIBRATION_SAMPLES = 512
104
+ MAX_SEQUENCE_LENGTH = 2048
105
+
106
+ # Load dataset and preprocess.
107
+ ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
108
+ ds = ds.shuffle(seed=42)
109
+
110
+ def preprocess(example):
111
+ return {
112
+ "text": tokenizer.apply_chat_template(
113
+ example["messages"],
114
+ tokenize=False,
115
+ )
116
+ }
117
+
118
+ ds = ds.map(preprocess)
119
+
120
+ # Tokenize inputs.
121
+ def tokenize(sample):
122
+ return tokenizer(
123
+ sample["text"],
124
+ padding=False,
125
+ max_length=MAX_SEQUENCE_LENGTH,
126
+ truncation=True,
127
+ add_special_tokens=False,
128
+ )
129
+
130
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
131
+
132
+ # Configure the quantization algorithm and scheme.
133
+ # In this case, we:
134
+ # * quantize the weights to fp4 with per group 16 via ptq
135
+ # * calibrate a global_scale for activations, which will be used to
136
+ # quantize activations to fp4 on the fly
137
+ smoothing_strength = 0.9
138
+ recipe = [
139
+ SmoothQuantModifier(smoothing_strength=smoothing_strength),
140
+ QuantizationModifier(
141
+ ignore=["re:.*lm_head.*"],
142
+ config_groups={
143
+ "group_0": {
144
+ "targets": ["Linear"],
145
+ "weights": {
146
+ "num_bits": 4,
147
+ "type": "float",
148
+ "strategy": "tensor_group",
149
+ "group_size": 16,
150
+ "symmetric": True,
151
+ "observer": "mse",
152
+ },
153
+ "input_activations": {
154
+ "num_bits": 4,
155
+ "type": "float",
156
+ "strategy": "tensor_group",
157
+ "group_size": 16,
158
+ "symmetric": True,
159
+ "dynamic": "local",
160
+ "observer": "minmax",
161
+ },
162
+ }
163
+ },
164
+ )
165
+ ]
166
+
167
+ # Save to disk in compressed-tensors format.
168
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
169
+
170
+ # Apply quantization.
171
+ oneshot(
172
+ model=model,
173
+ dataset=ds,
174
+ recipe=recipe,
175
+ max_seq_length=MAX_SEQUENCE_LENGTH,
176
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
177
+ output_dir=SAVE_DIR,
178
+ )
179
+
180
+ print("\n\n")
181
+ print("========== SAMPLE GENERATION ==============")
182
+ dispatch_for_generation(model)
183
+ input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to("cuda")
184
+ output = model.generate(input_ids, max_new_tokens=100)
185
+ print(tokenizer.decode(output[0]))
186
+ print("==========================================\n\n")
187
+
188
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
189
+ tokenizer.save_pretrained(SAVE_DIR)
190
+ ```
191
+ </details>
192
+
193
+ ## Evaluation
194
+
195
+ This model was evaluated on the well-known OpenLLM v1, OpenLLM v2 and HumanEval_64 benchmarks using [lm-evaluation-harness](https://github.com/neuralmagic/lm-evaluation-harness).
196
+
197
+ ### Accuracy
198
+ <table>
199
+ <thead>
200
+ <tr>
201
+ <th>Category</th>
202
+ <th>Metric</th>
203
+ <th>unsloth/Mistral-Small-3.2-24B-Instruct-2506</th>
204
+ <th>RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4</th>
205
+ <th>Recovery</th>
206
+ </tr>
207
+ </thead>
208
+ <tbody>
209
+ <!-- OpenLLM V1 -->
210
+ <tr>
211
+ <td rowspan="7"><b>OpenLLM V1</b></td>
212
+ <td>arc_challenge</td>
213
+ <td>68.52</td>
214
+ <td>66.98</td>
215
+ <td>97.75</td>
216
+ </tr>
217
+ <tr>
218
+ <td>gsm8k</td>
219
+ <td>89.61</td>
220
+ <td>87.11</td>
221
+ <td>97.21</td>
222
+ </tr>
223
+ <tr>
224
+ <td>hellaswag</td>
225
+ <td>85.70</td>
226
+ <td>85.11</td>
227
+ <td>99.31</td>
228
+ </tr>
229
+ <tr>
230
+ <td>mmlu</td>
231
+ <td>81.06</td>
232
+ <td>79.43</td>
233
+ <td>97.99</td>
234
+ </tr>
235
+ <tr>
236
+ <td>truthfulqa_mc2</td>
237
+ <td>61.35</td>
238
+ <td>60.34</td>
239
+ <td>98.35</td>
240
+ </tr>
241
+ <tr>
242
+ <td>winogrande</td>
243
+ <td>83.27</td>
244
+ <td>81.61</td>
245
+ <td>98.01</td>
246
+ </tr>
247
+ <tr>
248
+ <td><b>Average</b></td>
249
+ <td><b>78.25</b></td>
250
+ <td><b>76.76</b></td>
251
+ <td><b>98.10</b></td>
252
+ </tr>
253
+ <tr>
254
+ <td rowspan="7"><b>OpenLLM V2</b></td>
255
+ <td>BBH (3-shot)</td>
256
+ <td>65.86</td>
257
+ <td>64.05</td>
258
+ <td>97.25</td>
259
+ </tr>
260
+ <tr>
261
+ <td>MMLU-Pro (5-shot)</td>
262
+ <td>50.84</td>
263
+ <td>48.45</td>
264
+ <td>95.30</td>
265
+ </tr>
266
+ <tr>
267
+ <td>MuSR (0-shot)</td>
268
+ <td>39.15</td>
269
+ <td>40.21</td>
270
+ <td>102.71</td>
271
+ </tr>
272
+ <tr>
273
+ <td>IFEval (0-shot)</td>
274
+ <td>84.05</td>
275
+ <td>84.41</td>
276
+ <td>100.43</td>
277
+ </tr>
278
+ <tr>
279
+ <td>GPQA (0-shot)</td>
280
+ <td>33.14</td>
281
+ <td>32.55</td>
282
+ <td>98.22</td>
283
+ </tr>
284
+ <tr>
285
+ <td>Math-|v|-5 (4-shot)</td>
286
+ <td>41.69</td>
287
+ <td>37.76</td>
288
+ <td>90.57</td>
289
+ </tr>
290
+ <tr>
291
+ <td><b>Average</b></td>
292
+ <td><b>52.46</b></td>
293
+ <td><b>51.24</b></td>
294
+ <td><b>97.68</b></td>
295
+ </tr>
296
+ <tr>
297
+ <td rowspan="2"><b>Coding</b></td>
298
+ <td>HumanEval_64 pass@2</td>
299
+ <td>88.88</td>
300
+ <td>88.84</td>
301
+ <td>99.95</td>
302
+ </tr>
303
+ </tbody>
304
+ </table>
305
+
306
+
307
+
308
+
309
+ ### Reproduction
310
+
311
+ The results were obtained using the following commands:
312
+
313
+ <details>
314
+
315
+ ```
316
+ lm_eval \
317
+ --model vllm \
318
+ --model_args pretrained="RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
319
+ --apply_chat_template \
320
+ --fewshot_as_multiturn \
321
+ --tasks openllm \
322
+ --batch_size auto
323
+ ```
324
+
325
+
326
+ #### OpenLLM v2
327
+ ```
328
+ lm_eval \
329
+ --model vllm \
330
+ --model_args pretrained="RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
331
+ --apply_chat_template \
332
+ --fewshot_as_multiturn \
333
+ --tasks leaderboard \
334
+ --batch_size auto
335
+ ```
336
+
337
+ #### HumanEval_64
338
+ ```
339
+ lm_eval \
340
+ --model vllm \
341
+ --model_args pretrained="RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
342
+ --apply_chat_template \
343
+ --fewshot_as_multiturn \
344
+ --tasks humaneval_64_instruct \
345
+ --batch_size auto
346
+
347
+ ```
348
+ </details>