nm-research commited on
Commit
2e50ac3
·
verified ·
1 Parent(s): 94a41e4

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +401 -0
README.md ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: llama3.1
16
+ base_model: meta-llama/Meta-Llama-3.1-70B-Instruct
17
+ ---
18
+
19
+ # Meta-Llama-3.1-70B-Instruct-NVFP4
20
+
21
+ ## Model Overview
22
+ - **Model Architecture:** Meta-Llama-3.1
23
+ - **Input:** Text
24
+ - **Output:** Text
25
+ - **Model Optimizations:**
26
+ - **Weight quantization:** FP4
27
+ - **Activation quantization:** FP4
28
+ - **Intended Use Cases:** Intended for commercial and research use in multiple languages. Similarly to [Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct), this models is intended for assistant-like chat.
29
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
30
+ - **Release Date:** 6/25/2025
31
+ - **Version:** 1.0
32
+ - **License(s):** [llama3.1](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE)
33
+ - **Model Developers:** RedHatAI
34
+
35
+ This model is a quantized version of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct).
36
+ It was evaluated on a several tasks to assess the its quality in comparison to the unquatized model.
37
+
38
+ ### Model Optimizations
39
+
40
+ This model was obtained by quantizing the weights and activations of [Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) to FP4 data type, ready for inference with vLLM>=0.9.1
41
+ This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 25%.
42
+
43
+ Only the weights and activations of the linear operators within transformers blocks are quantized using [LLM Compressor](https://github.com/vllm-project/llm-compressor).
44
+
45
+ ## Deployment
46
+
47
+ ### Use with vLLM
48
+
49
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
50
+
51
+ ```python
52
+ from vllm import LLM, SamplingParams
53
+ from transformers import AutoTokenizer
54
+
55
+ model_id = "RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4"
56
+ number_gpus = 2
57
+
58
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
59
+
60
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
61
+
62
+ messages = [
63
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
64
+ {"role": "user", "content": "Who are you?"},
65
+ ]
66
+
67
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
68
+
69
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
70
+
71
+ outputs = llm.generate(prompts, sampling_params)
72
+
73
+ generated_text = outputs[0].outputs[0].text
74
+ print(generated_text)
75
+ ```
76
+
77
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
78
+
79
+ ## Creation
80
+
81
+ 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.
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.utils import dispatch_for_generation
90
+
91
+ MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct"
92
+
93
+ # Load model.
94
+ model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
95
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
96
+
97
+ DATASET_ID = "HuggingFaceH4/ultrachat_200k"
98
+ DATASET_SPLIT = "train_sft"
99
+
100
+ # Select number of samples. 512 samples is a good place to start.
101
+ # Increasing the number of samples can improve accuracy.
102
+ NUM_CALIBRATION_SAMPLES = 512
103
+ MAX_SEQUENCE_LENGTH = 2048
104
+
105
+ # Load dataset and preprocess.
106
+ ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
107
+ ds = ds.shuffle(seed=42)
108
+
109
+ def preprocess(example):
110
+ return {
111
+ "text": tokenizer.apply_chat_template(
112
+ example["messages"],
113
+ tokenize=False,
114
+ )
115
+ }
116
+
117
+ ds = ds.map(preprocess)
118
+
119
+ # Tokenize inputs.
120
+ def tokenize(sample):
121
+ return tokenizer(
122
+ sample["text"],
123
+ padding=False,
124
+ max_length=MAX_SEQUENCE_LENGTH,
125
+ truncation=True,
126
+ add_special_tokens=False,
127
+ )
128
+
129
+ ds = ds.map(tokenize, remove_columns=ds.column_names)
130
+
131
+ # Configure the quantization algorithm and scheme.
132
+ # In this case, we:
133
+ # * quantize the weights to fp4 with per group 16 via ptq
134
+ # * calibrate a global_scale for activations, which will be used to
135
+ # quantize activations to fp4 on the fly
136
+ recipe = QuantizationModifier(targets="Linear", scheme="NVFP4", ignore=["lm_head"])
137
+
138
+ # Save to disk in compressed-tensors format.
139
+ SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
140
+
141
+ # Apply quantization.
142
+ oneshot(
143
+ model=model,
144
+ dataset=ds,
145
+ recipe=recipe,
146
+ max_seq_length=MAX_SEQUENCE_LENGTH,
147
+ num_calibration_samples=NUM_CALIBRATION_SAMPLES,
148
+ output_dir=SAVE_DIR,
149
+ )
150
+
151
+ print("\n\n")
152
+ print("========== SAMPLE GENERATION ==============")
153
+ dispatch_for_generation(model)
154
+ input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to("cuda")
155
+ output = model.generate(input_ids, max_new_tokens=100)
156
+ print(tokenizer.decode(output[0]))
157
+ print("==========================================\n\n")
158
+
159
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
160
+ tokenizer.save_pretrained(SAVE_DIR)
161
+
162
+ ```
163
+
164
+ ## Evaluation
165
+
166
+ 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).
167
+
168
+ ### Accuracy
169
+
170
+ <table>
171
+ <thead>
172
+ <tr>
173
+ <th>Category</th>
174
+ <th>Metric</th>
175
+ <th>Meta-Llama-3.1-70B-Instruct</th>
176
+ <th>RedHatAI/Llama-3.1-70B-Instruct-NVFP4 (this model)</th>
177
+ <th>Recovery (%)</th>
178
+ </tr>
179
+ </thead>
180
+ <tbody>
181
+ <tr>
182
+ <td rowspan="8"><b>OpenLLM V1</b></td>
183
+ <td>mmlu_llama</td>
184
+ <td></td>
185
+ <td></td>
186
+ <td></td>
187
+ </tr>
188
+ <tr>
189
+ <td>mmlu_cot_llama (0-shot)</td>
190
+ <td></td>
191
+ <td></td>
192
+ <td></td>
193
+ </tr>
194
+ <tr>
195
+ <td>arc_challenge_llama (0-shot)</td>
196
+ <td></td>
197
+ <td></td>
198
+ <td></td>
199
+ </tr>
200
+ <tr>
201
+ <td>gsm8k_llama (8-shot, strict-match)</td>
202
+ <td></td>
203
+ <td></td>
204
+ <td></td>
205
+ </tr>
206
+ <tr>
207
+ <td>hellaswag (10-shot)</td>
208
+ <td></td>
209
+ <td></td>
210
+ <td></td>
211
+ </tr>
212
+ <tr>
213
+ <td>winogrande (5-shot)</td>
214
+ <td></td>
215
+ <td></td>
216
+ <td></td>
217
+ </tr>
218
+ <tr>
219
+ <td>truthfulQA (0-shot, mc2)</td>
220
+ <td></td>
221
+ <td></td>
222
+ <td></td>
223
+ </tr>
224
+ <tr>
225
+ <td><b>Average</b></td>
226
+ <td><b></b></td>
227
+ <td><b></b></td>
228
+ <td><b>%</b></td>
229
+ </tr>
230
+ <tr>
231
+ <td rowspan="7"><b>OpenLLM V2</b></td>
232
+ <td>MMLU-Pro (5-shot)</td>
233
+ <td></td>
234
+ <td></td>
235
+ <td></td>
236
+ </tr>
237
+ <tr>
238
+ <td>IFEval (0-shot)</td>
239
+ <td></td>
240
+ <td></td>
241
+ <td></td>
242
+ </tr>
243
+ <tr>
244
+ <td>BBH (3-shot)</td>
245
+ <td></td>
246
+ <td></td>
247
+ <td></td>
248
+ </tr>
249
+ <tr>
250
+ <td>Math-|v|-5 (4-shot)</td>
251
+ <td></td>
252
+ <td></td>
253
+ <td></td>
254
+ </tr>
255
+ <tr>
256
+ <td>GPQA (0-shot)</td>
257
+ <td></td>
258
+ <td></td>
259
+ <td></td>
260
+ </tr>
261
+ <tr>
262
+ <td>MuSR (0-shot)</td>
263
+ <td></td>
264
+ <td></td>
265
+ <td></td>
266
+ </tr>
267
+ <tr>
268
+ <td><b>Average</b></td>
269
+ <td><b></b></td>
270
+ <td><b></b></td>
271
+ <td><b>%</b></td>
272
+ </tr>
273
+
274
+ <tr>
275
+ <td><b>Coding</b></td>
276
+ <td>HumanEval pass@1</td>
277
+ <td></td>
278
+ <td></td>
279
+ <td></td>
280
+ </tr>
281
+ <tr>
282
+ <td></td>
283
+ <td>HumanEval_64 pass@2</td>
284
+ <td></td>
285
+ <td></td>
286
+ <td></td>
287
+ </tr>
288
+ </tbody>
289
+ </table>
290
+
291
+
292
+ ### Reproduction
293
+
294
+ The results were obtained using the following commands:
295
+
296
+ #### MMLU_LLAMA
297
+ ```
298
+ lm_eval \
299
+ --model vllm \
300
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
301
+ --tasks mmlu_llama \
302
+ --apply_chat_template \
303
+ --fewshot_as_multiturn \
304
+ --batch_size auto
305
+ ```
306
+
307
+ #### MMLU_COT_LLAMA
308
+ ```
309
+ lm_eval \
310
+ --model vllm \
311
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
312
+ --tasks mmlu_cot_llama \
313
+ --apply_chat_template \
314
+ --fewshot_as_multiturn \
315
+ --batch_size auto
316
+ ```
317
+
318
+ #### ARC-Challenge
319
+ ```
320
+ lm_eval \
321
+ --model vllm \
322
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
323
+ --tasks arc_challenge_llama \
324
+ --apply_chat_template \
325
+ --batch_size auto
326
+ ```
327
+
328
+ #### GSM-8K
329
+ ```
330
+ lm_eval \
331
+ --model vllm \
332
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
333
+ --tasks gsm8k_llama \
334
+ --apply_chat_template \
335
+ --fewshot_as_multiturn \
336
+ --batch_size auto
337
+ ```
338
+
339
+ #### Hellaswag
340
+ ```
341
+ lm_eval \
342
+ --model vllm \
343
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
344
+ --tasks hellaswag \
345
+ --apply_chat_template \
346
+ --fewshot_as_multiturn \
347
+ --batch_size auto
348
+ ```
349
+
350
+ #### Winogrande
351
+ ```
352
+ lm_eval \
353
+ --model vllm \
354
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
355
+ --tasks winogrande \
356
+ --apply_chat_template \
357
+ --fewshot_as_multiturn \
358
+ --batch_size auto
359
+ ```
360
+
361
+ #### TruthfulQA
362
+ ```
363
+ lm_eval \
364
+ --model vllm \
365
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
366
+ --tasks truthfulqa \
367
+ --apply_chat_template \
368
+ --fewshot_as_multiturn \
369
+ --batch_size auto
370
+ ```
371
+
372
+ #### OpenLLM v2
373
+ ```
374
+ lm_eval \
375
+ --model vllm \
376
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
377
+ --apply_chat_template \
378
+ --fewshot_as_multiturn \
379
+ --tasks leaderboard \
380
+ --batch_size auto
381
+ ```
382
+
383
+ #### HumanEval and HumanEval_64
384
+ ```
385
+ lm_eval \
386
+ --model vllm \
387
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
388
+ --apply_chat_template \
389
+ --fewshot_as_multiturn \
390
+ --tasks humaneval_instruct \
391
+ --batch_size auto
392
+
393
+
394
+ lm_eval \
395
+ --model vllm \
396
+ --model_args pretrained="RedHatAI/Meta-Llama-3.1-70B-Instruct-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
397
+ --apply_chat_template \
398
+ --fewshot_as_multiturn \
399
+ --tasks humaneval_64_instruct \
400
+ --batch_size auto
401
+ ```