Create README.md
Browse files
README.md
CHANGED
@@ -1,4 +1,150 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: mit
|
3 |
+
tags:
|
4 |
+
- qwen
|
5 |
+
- qwq
|
6 |
+
- fp8
|
7 |
+
- vllm
|
8 |
+
base_model: Qwen/QwQ-32B
|
9 |
+
library_name: transformers
|
10 |
+
---
|
11 |
+
|
12 |
+
# QwQ-32B-FP8-dynamic
|
13 |
+
|
14 |
+
## Model Overview
|
15 |
+
- **Model Architecture:** Qwen2ForCausalLM
|
16 |
+
- **Input:** Text
|
17 |
+
- **Output:** Text
|
18 |
+
- **Model Optimizations:**
|
19 |
+
- **Weight quantization:** FP8
|
20 |
+
- **Activation quantization:** FP8
|
21 |
+
- **Release Date:** 3/6/2025
|
22 |
+
- **Version:** 1.0
|
23 |
+
- **Model Developers:** Neural Magic
|
24 |
+
|
25 |
+
Quantized version of [Qwen/QwQ-32B](https://huggingface.co/Qwen/QwQ-32B).
|
26 |
+
|
27 |
+
|
28 |
+
### Model Optimizations
|
29 |
+
|
30 |
+
This model was obtained by quantizing the weights and activations of [Qwen/QwQ-32B](https://huggingface.co/Qwen/QwQ-32B) to FP8 data type.
|
31 |
+
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
|
32 |
+
|
33 |
+
Only the weights and activations of the linear operators within transformers blocks are quantized.
|
34 |
+
Weights are quantized using a symmetric per-channel scheme, whereas quantizations are quantized using a symmetric per-token scheme.
|
35 |
+
[LLM Compressor](https://github.com/vllm-project/llm-compressor) is used for quantization.
|
36 |
+
|
37 |
+
|
38 |
+
## Use with vLLM
|
39 |
+
|
40 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
41 |
+
|
42 |
+
```python
|
43 |
+
from transformers import AutoTokenizer
|
44 |
+
from vllm import LLM, SamplingParams
|
45 |
+
|
46 |
+
number_gpus = 1
|
47 |
+
model_name = "neuralmagic/QwQ-32B-FP8-dynamic"
|
48 |
+
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
50 |
+
sampling_params = SamplingParams(temperature=0.6, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
|
51 |
+
llm = LLM(model=model_name, tensor_parallel_size=number_gpus, trust_remote_code=True)
|
52 |
+
|
53 |
+
messages_list = [
|
54 |
+
[{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
|
55 |
+
]
|
56 |
+
|
57 |
+
prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
|
58 |
+
|
59 |
+
outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
|
60 |
+
|
61 |
+
generated_text = [output.outputs[0].text for output in outputs]
|
62 |
+
print(generated_text)
|
63 |
+
```
|
64 |
+
|
65 |
+
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
66 |
+
|
67 |
+
## Creation
|
68 |
+
|
69 |
+
This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.
|
70 |
+
|
71 |
+
|
72 |
+
```python
|
73 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
74 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
75 |
+
from llmcompressor.transformers import oneshot
|
76 |
+
import os
|
77 |
+
|
78 |
+
# Load model
|
79 |
+
model_stub = "Qwen/QwQ-32B"
|
80 |
+
model_name = model_stub.split("/")[-1]
|
81 |
+
|
82 |
+
model = AutoModelForCausalLM.from_pretrained(
|
83 |
+
model_stub,
|
84 |
+
torch_dtype="auto",
|
85 |
+
)
|
86 |
+
|
87 |
+
tokenizer = AutoTokenizer.from_pretrained(model_stub)
|
88 |
+
|
89 |
+
# Configure the quantization algorithm and scheme
|
90 |
+
recipe = QuantizationModifier(
|
91 |
+
targets="Linear",
|
92 |
+
scheme="FP8_DYNAMIC",
|
93 |
+
ignore=["lm_head"],
|
94 |
+
)
|
95 |
+
|
96 |
+
# Apply quantization
|
97 |
+
oneshot(
|
98 |
+
model=model,
|
99 |
+
recipe=recipe,
|
100 |
+
)
|
101 |
+
|
102 |
+
# Save to disk in compressed-tensors format
|
103 |
+
save_path = model_name + "-FP8-dynamic
|
104 |
+
model.save_pretrained(save_path)
|
105 |
+
tokenizer.save_pretrained(save_path)
|
106 |
+
print(f"Model and tokenizer saved to: {save_path}")
|
107 |
+
```
|
108 |
+
|
109 |
+
|
110 |
+
### Accuracy
|
111 |
+
|
112 |
+
<table>
|
113 |
+
<thead>
|
114 |
+
<tr>
|
115 |
+
<th>Category</th>
|
116 |
+
<th>Metric</th>
|
117 |
+
<th>Qwen/QwQ-32B</th>
|
118 |
+
<th>neuralmagic/QwQ-32B-FP8-dynamic</th>
|
119 |
+
<th>Recovery</th>
|
120 |
+
</tr>
|
121 |
+
</thead>
|
122 |
+
<tbody>
|
123 |
+
<tr>
|
124 |
+
<td rowspan="4"><b>Reasoning</b></td>
|
125 |
+
<td>AIME 2024 (pass@1)</td> 78.66, 97.39, 64.72; 79.50, 97.44, 63.21
|
126 |
+
<td>78.66</td>
|
127 |
+
<td>79.40</td>
|
128 |
+
<td>100.94%</td>
|
129 |
+
</tr>
|
130 |
+
<tr>
|
131 |
+
<td>MATH-500 (pass@1)</td>
|
132 |
+
<td>97.39</td>
|
133 |
+
<td>97.44</td>
|
134 |
+
<td>100.05%</td>
|
135 |
+
</tr>
|
136 |
+
<tr>
|
137 |
+
<td>GPQA Diamond (pass@1)</td>
|
138 |
+
<td>64.72</td>
|
139 |
+
<td>63.21</td>
|
140 |
+
<td>97.66%</td>
|
141 |
+
</tr>
|
142 |
+
<tr>
|
143 |
+
<td><b>Average Score</b></td>
|
144 |
+
<td><b>80.25</b></td>
|
145 |
+
<td><b>80.05</b></td>
|
146 |
+
<td><b>99.75%</b></td>
|
147 |
+
</tr>
|
148 |
+
|
149 |
+
</tbody>
|
150 |
+
</table>
|