nm-research commited on
Commit
4ba3f1e
·
verified ·
1 Parent(s): 7c41804

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +335 -0
README.md ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: Qwen/Qwen3-32B
17
+ ---
18
+
19
+ # Qwen3-32B-NVFP4
20
+
21
+ ## Model Overview
22
+ - **Model Architecture:** Qwen/Qwen3-32B
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:** 6/25/2025
30
+ - **Version:** 1.0
31
+ - **Model Developers:** RedHatAI
32
+
33
+ This model is a quantized version of [Qwen/Qwen3-32B](https://huggingface.co/Qwen/Qwen3-32B).
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 [Qwen/Qwen3-32B](https://huggingface.co/Qwen/Qwen3-32B) 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/Qwen3-32B-NVFP4"
54
+ number_gpus = 2
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
+ ```python
82
+ from datasets import load_dataset
83
+ from transformers import AutoModelForCausalLM, AutoTokenizer
84
+
85
+ from llmcompressor import oneshot
86
+ from llmcompressor.modifiers.quantization import QuantizationModifier
87
+ from llmcompressor.utils import dispatch_for_generation
88
+
89
+ MODEL_ID = "Qwen/Qwen3-32B"
90
+
91
+ # Load model.
92
+ model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
93
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
94
+
95
+ DATASET_ID = "HuggingFaceH4/ultrachat_200k"
96
+ DATASET_SPLIT = "train_sft"
97
+
98
+ # Select number of samples. 512 samples is a good place to start.
99
+ # Increasing the number of samples can improve accuracy.
100
+ NUM_CALIBRATION_SAMPLES = 512
101
+ MAX_SEQUENCE_LENGTH = 2048
102
+
103
+ # Load dataset and preprocess.
104
+ ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
105
+ ds = ds.shuffle(seed=42)
106
+
107
+ def preprocess(example):
108
+ return {
109
+ "text": tokenizer.apply_chat_template(
110
+ example["messages"],
111
+ tokenize=False,
112
+ )
113
+ }
114
+
115
+ ds = ds.map(preprocess)
116
+
117
+ # Tokenize inputs.
118
+ def tokenize(sample):
119
+ return tokenizer(
120
+ sample["text"],
121
+ padding=False,
122
+ max_length=MAX_SEQUENCE_LENGTH,
123
+ truncation=True,
124
+ add_special_tokens=False,
125
+ )
126
+
127
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
128
+
129
+ # Configure the quantization algorithm and scheme.
130
+ # In this case, we:
131
+ # * quantize the weights to fp4 with per group 16 via ptq
132
+ # * calibrate a global_scale for activations, which will be used to
133
+ # quantize activations to fp4 on the fly
134
+ recipe = QuantizationModifier(targets="Linear", scheme="NVFP4", ignore=["lm_head"])
135
+
136
+ # Save to disk in compressed-tensors format.
137
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
138
+
139
+ # Apply quantization.
140
+ oneshot(
141
+ model=model,
142
+ dataset=ds,
143
+ recipe=recipe,
144
+ max_seq_length=MAX_SEQUENCE_LENGTH,
145
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
146
+ output_dir=SAVE_DIR,
147
+ )
148
+
149
+ print("\n\n")
150
+ print("========== SAMPLE GENERATION ==============")
151
+ dispatch_for_generation(model)
152
+ input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to("cuda")
153
+ output = model.generate(input_ids, max_new_tokens=100)
154
+ print(tokenizer.decode(output[0]))
155
+ print("==========================================\n\n")
156
+
157
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
158
+ tokenizer.save_pretrained(SAVE_DIR)
159
+
160
+ ```
161
+
162
+ ## Evaluation
163
+
164
+ This model was evaluated on the well-known OpenLLM v1, OpenLLM v2, HumanEval, and HumanEval_64 benchmarks. All evaluations were conducted using [lm-evaluation-harness](https://github.com/neuralmagic/lm-evaluation-harness).
165
+
166
+ ### Accuracy
167
+
168
+ <table>
169
+ <thead>
170
+ <tr>
171
+ <th>Category</th>
172
+ <th>Metric</th>
173
+ <th>Qwen/Qwen3-32B</th>
174
+ <th>RedHatAI/Qwen3-32B-NVFP4 (this model)</th>
175
+ <th>Recovery (%)</th>
176
+ </tr>
177
+ </thead>
178
+ <tbody>
179
+ <tr>
180
+ <td rowspan="7"><b>OpenLLM V1</b></td>
181
+ <td>mmlu</td>
182
+ <td></td>
183
+ <td></td>
184
+ <td></td>
185
+ </tr>
186
+ <tr>
187
+ <td>MMLU</td>
188
+ <td></td>
189
+ <td></td>
190
+ <td></td>
191
+ </tr>
192
+ <tr>
193
+ <td>ARC Challenge (0-shot)</td>
194
+ <td></td>
195
+ <td></td>
196
+ <td></td>
197
+ </tr>
198
+ <tr>
199
+ <td>GSM8K (8-shot, strict-match)</td>
200
+ <td></td>
201
+ <td></td>
202
+ <td></td>
203
+ </tr>
204
+ <tr>
205
+ <td>Hellaswag (10-shot)</td>
206
+ <td></td>
207
+ <td></td>
208
+ <td></td>
209
+ </tr>
210
+ <tr>
211
+ <td>Winogrande (5-shot)</td>
212
+ <td></td>
213
+ <td></td>
214
+ <td></td>
215
+ </tr>
216
+ <tr>
217
+ <td>TruthfulQA (0-shot, mc2)</td>
218
+ <td></td>
219
+ <td></td>
220
+ <td></td>
221
+ </tr>
222
+ <tr>
223
+ <td><b>Average</b></td>
224
+ <td><b></b></td>
225
+ <td><b></b></td>
226
+ <td><b>%</b></td>
227
+ </tr>
228
+ <tr>
229
+ <td rowspan="7"><b>OpenLLM V2</b></td>
230
+ <td>MMLU-Pro (5-shot)</td>
231
+ <td></td>
232
+ <td></td>
233
+ <td></td>
234
+ </tr>
235
+ <tr>
236
+ <td>IFEval (0-shot)</td>
237
+ <td></td>
238
+ <td></td>
239
+ <td></td>
240
+ </tr>
241
+ <tr>
242
+ <td>BBH (3-shot)</td>
243
+ <td></td>
244
+ <td></td>
245
+ <td></td>
246
+ </tr>
247
+ <tr>
248
+ <td>Math-|v|-5 (4-shot)</td>
249
+ <td></td>
250
+ <td></td>
251
+ <td></td>
252
+ </tr>
253
+ <tr>
254
+ <td>GPQA (0-shot)</td>
255
+ <td></td>
256
+ <td></td>
257
+ <td></td>
258
+ </tr>
259
+ <tr>
260
+ <td>MuSR (0-shot)</td>
261
+ <td></td>
262
+ <td></td>
263
+ <td></td>
264
+ </tr>
265
+ <tr>
266
+ <td><b>Average</b></td>
267
+ <td><b></b></td>
268
+ <td><b></b></td>
269
+ <td><b>%</b></td>
270
+ </tr>
271
+
272
+ <tr>
273
+ <td><b>Coding</b></td>
274
+ <td>HumanEval pass@1</td>
275
+ <td></td>
276
+ <td></td>
277
+ <td></td>
278
+ </tr>
279
+ <tr>
280
+ <td></td>
281
+ <td>HumanEval_64 pass@2</td>
282
+ <td></td>
283
+ <td></td>
284
+ <td></td>
285
+ </tr>
286
+ </tbody>
287
+ </table>
288
+
289
+
290
+ ### Reproduction
291
+
292
+ The results were obtained using the following commands:
293
+
294
+ #### OpenLLM v1
295
+ ```
296
+ lm_eval \
297
+ --model vllm \
298
+ --model_args pretrained="RedHatAI/Qwen3-32B-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
299
+ --apply_chat_template \
300
+ --fewshot_as_multiturn \
301
+ --tasks openllm \
302
+ --batch_size auto
303
+ ```
304
+
305
+
306
+ #### OpenLLM v2
307
+ ```
308
+ lm_eval \
309
+ --model vllm \
310
+ --model_args pretrained="RedHatAI/Qwen3-32B-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
311
+ --apply_chat_template \
312
+ --fewshot_as_multiturn \
313
+ --tasks leaderboard \
314
+ --batch_size auto
315
+ ```
316
+
317
+ #### HumanEval and HumanEval_64
318
+ ```
319
+ lm_eval \
320
+ --model vllm \
321
+ --model_args pretrained="RedHatAI/Qwen3-32B-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
322
+ --apply_chat_template \
323
+ --fewshot_as_multiturn \
324
+ --tasks humaneval_instruct \
325
+ --batch_size auto
326
+
327
+
328
+ lm_eval \
329
+ --model vllm \
330
+ --model_args pretrained="RedHatAI/Qwen3-32B-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 humaneval_64_instruct \
334
+ --batch_size auto
335
+ ```