ekurtic commited on
Commit
b5b4ceb
·
verified ·
1 Parent(s): 2ff4418

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +241 -0
README.md ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: text-generation
4
+ base_model:
5
+ - nvidia/NVIDIA-Nemotron-Nano-9B-v2
6
+ tags:
7
+ - neuralmagic
8
+ - redhat
9
+ - llmcompressor
10
+ - quantized
11
+ - INT4
12
+ ---
13
+
14
+ # NVIDIA-Nemotron-Nano-9B-v2-quantized.w4a16
15
+
16
+ ## Model Overview
17
+ - **Model Architecture:** NemotronHForCausalLM
18
+ - **Input:** Text
19
+ - **Output:** Text
20
+ - **Model Optimizations:**
21
+ - **Weight quantization:** INT4
22
+ - **Release Date:** 10/22/2025
23
+ - **Version:** 1.0
24
+ - **Model Developers:** RedHat (Neural Magic)
25
+
26
+ ### Model Optimizations
27
+
28
+ This model was obtained by quantizing the weights of [NVIDIA-Nemotron-Nano-9B-v2](https://huggingface.co/nvidia/NVIDIA-Nemotron-Nano-9B-v2) to INT4 data type.
29
+ This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.
30
+
31
+ Only the weights of the linear operators within transformers blocks are quantized.
32
+ Weights are quantized using a symmetric per-group scheme, with group size 64.
33
+ The [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization, as implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library.
34
+
35
+
36
+ ## Deployment
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 transformers import AutoTokenizer
43
+
44
+ model_id = "RedHatAI/NVIDIA-Nemotron-Nano-9B-v2-quantized.w4a16"
45
+ number_gpus = 1
46
+ sampling_params = SamplingParams(temperature=0.6, top_p=0.95, top_k=20, min_p=0, max_tokens=256)
47
+
48
+ messages = [
49
+ {"role": "user", "content": prompt}
50
+ ]
51
+
52
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
53
+
54
+ messages = [{"role": "user", "content": "Give me a short introduction to large language model."}]
55
+
56
+ prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
57
+
58
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
59
+
60
+ outputs = llm.generate(prompts, sampling_params)
61
+
62
+ generated_text = outputs[0].outputs[0].text
63
+ print(generated_text)
64
+ ```
65
+
66
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
67
+
68
+ ## Creation
69
+
70
+ <details>
71
+ <summary>Creation details</summary>
72
+ This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.
73
+
74
+
75
+ ```python
76
+ from compressed_tensors.quantization import QuantizationScheme, QuantizationArgs, QuantizationType, QuantizationStrategy
77
+ from llmcompressor.modifiers.quantization import GPTQModifier
78
+ from llmcompressor.transformers import oneshot
79
+ from transformers import AutoModelForCausalLM, AutoTokenizer
80
+
81
+ # Load model
82
+ model_stub = "nvidia/NVIDIA-Nemotron-Nano-9B-v2"
83
+ model_name = model_stub.split("/")[-1]
84
+
85
+ num_samples = 1024
86
+ max_seq_len = 8192
87
+
88
+ model = AutoModelForCausalLM.from_pretrained(model_stub)
89
+
90
+ tokenizer = AutoTokenizer.from_pretrained(model_stub)
91
+
92
+ def preprocess_fn(example):
93
+ return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
94
+
95
+ ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
96
+ ds = ds.map(preprocess_fn)
97
+
98
+ # Configure the quantization algorithm and scheme
99
+ quant_scheme = QuantizationScheme(
100
+ targets=["Linear"],
101
+ weights=QuantizationArgs(
102
+ num_bits=4,
103
+ type=QuantizationType.INT,
104
+ symmetric=True,
105
+ group_size=64,
106
+ strategy=QuantizationStrategy.GROUP,
107
+ observer="mse",
108
+ actorder="weight"
109
+ ),
110
+ input_activations=None,
111
+ output_activations=None,
112
+ )
113
+
114
+ recipe = [
115
+ GPTQModifier(
116
+ ignore=["lm_head", "NemotronHMamba2Mixer"],
117
+ dampening_frac=0.07,
118
+ config_groups={"group_0": quant_scheme},
119
+ )
120
+ ]
121
+
122
+ # Apply quantization
123
+ oneshot(
124
+ model=model,
125
+ dataset=ds,
126
+ recipe=recipe,
127
+ max_seq_length=max_seq_len,
128
+ num_calibration_samples=num_samples,
129
+ )
130
+
131
+ # Save to disk in compressed-tensors format
132
+ save_path = model_name + "-quantized.w4a16"
133
+ model.save_pretrained(save_path)
134
+ tokenizer.save_pretrained(save_path)
135
+ print(f"Model and tokenizer saved to: {save_path}")
136
+ ```
137
+ </details>
138
+
139
+
140
+
141
+ ## Evaluation
142
+
143
+ The model was evaluated on the set of popular reasoning tasks AIME25, Math-500, and GPQA-Diamond, using [lighteval](https://github.com/huggingface/lighteval) `v0.11.1.dev0`.
144
+ [vLLM](https://docs.vllm.ai/en/stable/) `v0.11.1rc2.dev191+g80e945298.precompiled` was used as the inference engine for all evaluations.
145
+
146
+ <details>
147
+ <summary>Evaluation details</summary>
148
+
149
+ **lighteval**
150
+
151
+ lighteval_model_arguments.yaml
152
+ ```yaml
153
+ model_parameters:
154
+ model_name: "hosted_vllm/RedHatAI/NVIDIA-Nemotron-Nano-9B-v2-quantized.w4a16"
155
+ base_url: "http://0.0.0.0:8000/v1"
156
+ generation_parameters:
157
+ temperature: 0.6
158
+ min_p: 0.0
159
+ max_new_tokens: 65536
160
+ top_p: 0.95
161
+ seed: 0
162
+ ```
163
+
164
+ ```
165
+ lighteval endpoint litellm lighteval_model_arguments.yaml \
166
+ "lighteval|aime25|0,lighteval|math_500|0,lighteval|gpqa:diamond|0" \
167
+ --output-dir $OUTPUT_DIR \
168
+ --save-details
169
+ ```
170
+
171
+ ```
172
+ vllm serve RedHatAI/NVIDIA-Nemotron-Nano-9B-v2-quantized.w4a16 \
173
+ --trust-remote-code \
174
+ --mamba_ssm_cache_dtype float32 \
175
+ -tp 1 \
176
+ --port 8000 \
177
+ --gpu-memory-utilization 0.9
178
+ ```
179
+
180
+ </details>
181
+
182
+ ### Accuracy
183
+
184
+ <table>
185
+ <tr>
186
+ <th>Category
187
+ </th>
188
+ <th>Benchmark
189
+ </th>
190
+ <th>NVIDIA-Nemotron-Nano-9B-v2
191
+ </th>
192
+ <th>NVIDIA-Nemotron-Nano-9B-v2-quantized.w4a16<br>(this model)
193
+ </th>
194
+ <th>Recovery
195
+ </th>
196
+ </tr>
197
+ <tr>
198
+ <td rowspan="6" ><strong>Reasoning<br>(generation)</strong>
199
+ </td>
200
+ </tr>
201
+ <tr>
202
+ <td>AIME 2025
203
+ </td>
204
+ <td>61.33
205
+ </td>
206
+ <td>58.00
207
+ </td>
208
+ <td>94.6%
209
+ </td>
210
+ </tr>
211
+ <tr>
212
+ <td>GPQA diamond
213
+ </td>
214
+ <td>56.26
215
+ </td>
216
+ <td>56.16
217
+ </td>
218
+ <td>99.8%
219
+ </td>
220
+ </tr>
221
+ <tr>
222
+ <td>Math-lvl-5
223
+ </td>
224
+ <td>96.08
225
+ </td>
226
+ <td>96.16
227
+ </td>
228
+ <td>100.0%
229
+ </td>
230
+ </tr>
231
+ <tr>
232
+ <td>Average Score
233
+ </td>
234
+ <td>71.22
235
+ </td>
236
+ <td>70.11
237
+ </td>
238
+ <td>98.44%
239
+ </td>
240
+ </tr>
241
+ </table>