Text Generation
Safetensors
qwen2
chat
conversational
4-bit precision
gptq
GSJL lbourdois commited on
Commit
256be90
·
verified ·
1 Parent(s): 96cfdac

Improve language tag (#2)

Browse files

- Improve language tag (e95938cb4c2115d8bd14c0f24035250c9cb296eb)


Co-authored-by: Loïck BOURDOIS <lbourdois@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +239 -227
README.md CHANGED
@@ -1,228 +1,240 @@
1
- ---
2
- license: apache-2.0
3
- license_link: https://huggingface.co/Qwen/QWQ-32B/blob/main/LICENSE
4
- language:
5
- - en
6
- pipeline_tag: text-generation
7
- base_model: Qwen/Qwen2.5-32B
8
- tags:
9
- - chat
10
- ---
11
-
12
- # QwQ-32B-GPTQ_4bit-128g
13
-
14
- ## Thanks to the Qwen team!
15
-
16
- <a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;">
17
- <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
18
- </a>
19
-
20
- #
21
- # Replication
22
-
23
- ### Install gptqmodel:
24
- ```bash
25
- !pip install -v gptqmodel --no-build-isolation
26
- ```
27
-
28
- ### Quantise:
29
- ```python
30
- import torch
31
- from datasets import load_dataset
32
- from gptqmodel import GPTQModel, QuantizeConfig
33
- from transformers import AutoTokenizer
34
-
35
- def get_wikitext2(tokenizer, nsamples, seqlen):
36
- traindata = load_dataset("wikitext", "wikitext-2-v1", split="train").filter(
37
- lambda x: len(x["text"]) >= seqlen)
38
-
39
- return [tokenizer(example["text"]) for example in traindata.select(range(nsamples))]
40
-
41
-
42
- @torch.no_grad()
43
- def calculate_avg_ppl(model, tokenizer):
44
- from gptqmodel.utils import Perplexity
45
-
46
- ppl = Perplexity(
47
- model=model,
48
- tokenizer=tokenizer,
49
- dataset_path="wikitext",
50
- dataset_name="wikitext-2-raw-v1",
51
- split="train",
52
- text_column="text",
53
- )
54
-
55
- all = ppl.calculate(n_ctx=512, n_batch=512)
56
-
57
- # average ppl
58
- avg = sum(all) / len(all)
59
-
60
- return avg
61
-
62
- pretrained_model_id = "Qwen/QwQ-32B"
63
- quantized_model_id = "QwQ-32B-GPTQ_4bit-128g"
64
-
65
- tokenizer = AutoTokenizer.from_pretrained(pretrained_model_id, use_fast=True)
66
-
67
- traindataset = get_wikitext2(tokenizer, nsamples=512, seqlen=1024)
68
-
69
- quant_config = QuantizeConfig(
70
- bits=4,
71
- group_size=128,
72
- desc_act=False,
73
- damp_percent=0.01,
74
- )
75
-
76
- # load un-quantized model, the model will always be force loaded into cpu
77
- model = GPTQModel.load(pretrained_model_id, quant_config)
78
-
79
- # quantize model, the calibration_dataset should be list of dict whose keys can only be "input_ids" and "attention_mask"
80
- # with value under torch.LongTensor type.
81
- model.quantize(traindataset)
82
-
83
- # save quantized model using safetensors
84
- model.save(quantized_model_id)
85
- ```
86
-
87
- ### Push to hub (Optional)
88
- ```python
89
- # Define the repository name where the model will be saved
90
- repo = f"GSJL/{quantized_model_id}"
91
-
92
- # Push the quantized model and tokenizer to the Hugging Face Hub
93
- GPTQModel.push_to_hub(repo, quantized_model_id)
94
- ```
95
-
96
-
97
- ## Introduction
98
-
99
- QwQ is the reasoning model of the Qwen series. Compared with conventional instruction-tuned models, QwQ, which is capable of thinking and reasoning, can achieve significantly enhanced performance in downstream tasks, especially hard problems. QwQ-32B is the medium-sized reasoning model, which is capable of achieving competitive performance against state-of-the-art reasoning models, e.g., DeepSeek-R1, o1-mini.
100
-
101
- <p align="center">
102
- <img width="100%" src="figures/benchmark.jpg">
103
- </p>
104
-
105
-
106
- **This repo contains the QwQ 32B model**, which has the following features:
107
- - Type: Causal Language Models
108
- - Training Stage: Pretraining & Post-training (Supervised Finetuning and Reinforcement Learning)
109
- - Architecture: transformers with RoPE, SwiGLU, RMSNorm, and Attention QKV bias
110
- - Number of Parameters: 32.5B
111
- - Number of Paramaters (Non-Embedding): 31.0B
112
- - Number of Layers: 64
113
- - Number of Attention Heads (GQA): 40 for Q and 8 for KV
114
- - Context Length: Full 131,072 tokens
115
-
116
- **Note:** For the best experience, please review the [usage guidelines](#usage-guidelines) before deploying QwQ models.
117
-
118
- You can try our [demo](https://huggingface.co/spaces/Qwen/QwQ-32B-Demo) or access QwQ models via [QwenChat](https://chat.qwen.ai).
119
-
120
- For more details, please refer to our [blog](https://qwenlm.github.io/blog/qwq-32b/), [GitHub](https://github.com/QwenLM/Qwen2.5), and [Documentation](https://qwen.readthedocs.io/en/latest/).
121
-
122
- ## Requirements
123
-
124
- QwQ is based on Qwen2.5, whose code has been in the latest Hugging face `transformers`. We advise you to use the latest version of `transformers`.
125
-
126
- With `transformers<4.37.0`, you will encounter the following error:
127
- ```
128
- KeyError: 'qwen2'
129
- ```
130
-
131
- ## Quickstart
132
-
133
- Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
134
-
135
- ```python
136
- from transformers import AutoModelForCausalLM, AutoTokenizer
137
-
138
- model_name = "Qwen/QwQ-32B"
139
-
140
- model = AutoModelForCausalLM.from_pretrained(
141
- model_name,
142
- torch_dtype="auto",
143
- device_map="auto"
144
- )
145
- tokenizer = AutoTokenizer.from_pretrained(model_name)
146
-
147
- prompt = "How many r's are in the word \"strawberry\""
148
- messages = [
149
- {"role": "user", "content": prompt}
150
- ]
151
- text = tokenizer.apply_chat_template(
152
- messages,
153
- tokenize=False,
154
- add_generation_prompt=True
155
- )
156
-
157
- model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
158
-
159
- generated_ids = model.generate(
160
- **model_inputs,
161
- max_new_tokens=32768
162
- )
163
- generated_ids = [
164
- output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
165
- ]
166
-
167
- response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
168
- print(response)
169
- ```
170
-
171
- ### Usage Guidelines
172
-
173
- To achieve optimal performance, we recommend the following settings:
174
-
175
- 1. **Enforce Thoughtful Output**: Ensure the model starts with "\<think\>\n" to prevent generating empty thinking content, which can degrade output quality. If you use `apply_chat_template` and set `add_generation_prompt=True`, this is already automatically implemented, but it may cause the response to lack the \<think\> tag at the beginning. This is normal behavior.
176
-
177
- 2. **Sampling Parameters**:
178
- - Use Temperature=0.6 and TopP=0.95 instead of Greedy decoding to avoid endless repetitions.
179
- - Use TopK between 20 and 40 to filter out rare token occurrences while maintaining the diversity of the generated output.
180
-
181
- 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
182
- - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
183
- - **Multiple-Choice Questions**: Add the following JSON structure to the prompt to standardize responses: "Please show your choice in the `answer` field with only the choice letter, e.g.,`\"answer\": \"C\"`." in the prompt.
184
-
185
- 4. **Handle Long Inputs**: For inputs exceeding 32,768 tokens, enable [YaRN](https://arxiv.org/abs/2309.00071) to improve the model's ability to capture long-sequence information effectively.
186
-
187
- For supported frameworks, you could add the following to `config.json` to enable YaRN:
188
- ```json
189
- {
190
- ...,
191
- "rope_scaling": {
192
- "factor": 4.0,
193
- "original_max_position_embeddings": 32768,
194
- "type": "yarn"
195
- }
196
- }
197
- ```
198
-
199
- For deployment, we recommend using vLLM. Please refer to our [Documentation](https://qwen.readthedocs.io/en/latest/deployment/vllm.html) for usage if you are not familar with vLLM.
200
- Presently, vLLM only supports static YARN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts**.
201
- We advise adding the `rope_scaling` configuration only when processing long contexts is required.
202
-
203
- ## Evaluation & Performance
204
-
205
- Detailed evaluation results are reported in this [📑 blog](https://qwenlm.github.io/blog/qwq-32b/).
206
-
207
- For requirements on GPU memory and the respective throughput, see results [here](https://qwen.readthedocs.io/en/latest/benchmark/speed_benchmark.html).
208
-
209
- ## Citation
210
-
211
- If you find our work helpful, feel free to give us a cite.
212
-
213
- ```
214
- @misc{qwq32b,
215
- title = {QwQ-32B: The Power of Scaling RL},
216
- url = {https://qwenlm.github.io/blog/qwq-32b/},
217
- author = {Qwen Team},
218
- month = {March},
219
- year = {2025}
220
- }
221
-
222
- @article{qwen2,
223
- title={Qwen2 Technical Report},
224
- author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
225
- journal={arXiv preprint arXiv:2407.10671},
226
- year={2024}
227
- }
 
 
 
 
 
 
 
 
 
 
 
 
228
  ```
 
1
+ ---
2
+ license: apache-2.0
3
+ license_link: https://huggingface.co/Qwen/QWQ-32B/blob/main/LICENSE
4
+ language:
5
+ - zho
6
+ - eng
7
+ - fra
8
+ - spa
9
+ - por
10
+ - deu
11
+ - ita
12
+ - rus
13
+ - jpn
14
+ - kor
15
+ - vie
16
+ - tha
17
+ - ara
18
+ pipeline_tag: text-generation
19
+ base_model: Qwen/Qwen2.5-32B
20
+ tags:
21
+ - chat
22
+ ---
23
+
24
+ # QwQ-32B-GPTQ_4bit-128g
25
+
26
+ ## Thanks to the Qwen team!
27
+
28
+ <a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;">
29
+ <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/>
30
+ </a>
31
+
32
+ #
33
+ # Replication
34
+
35
+ ### Install gptqmodel:
36
+ ```bash
37
+ !pip install -v gptqmodel --no-build-isolation
38
+ ```
39
+
40
+ ### Quantise:
41
+ ```python
42
+ import torch
43
+ from datasets import load_dataset
44
+ from gptqmodel import GPTQModel, QuantizeConfig
45
+ from transformers import AutoTokenizer
46
+
47
+ def get_wikitext2(tokenizer, nsamples, seqlen):
48
+ traindata = load_dataset("wikitext", "wikitext-2-v1", split="train").filter(
49
+ lambda x: len(x["text"]) >= seqlen)
50
+
51
+ return [tokenizer(example["text"]) for example in traindata.select(range(nsamples))]
52
+
53
+
54
+ @torch.no_grad()
55
+ def calculate_avg_ppl(model, tokenizer):
56
+ from gptqmodel.utils import Perplexity
57
+
58
+ ppl = Perplexity(
59
+ model=model,
60
+ tokenizer=tokenizer,
61
+ dataset_path="wikitext",
62
+ dataset_name="wikitext-2-raw-v1",
63
+ split="train",
64
+ text_column="text",
65
+ )
66
+
67
+ all = ppl.calculate(n_ctx=512, n_batch=512)
68
+
69
+ # average ppl
70
+ avg = sum(all) / len(all)
71
+
72
+ return avg
73
+
74
+ pretrained_model_id = "Qwen/QwQ-32B"
75
+ quantized_model_id = "QwQ-32B-GPTQ_4bit-128g"
76
+
77
+ tokenizer = AutoTokenizer.from_pretrained(pretrained_model_id, use_fast=True)
78
+
79
+ traindataset = get_wikitext2(tokenizer, nsamples=512, seqlen=1024)
80
+
81
+ quant_config = QuantizeConfig(
82
+ bits=4,
83
+ group_size=128,
84
+ desc_act=False,
85
+ damp_percent=0.01,
86
+ )
87
+
88
+ # load un-quantized model, the model will always be force loaded into cpu
89
+ model = GPTQModel.load(pretrained_model_id, quant_config)
90
+
91
+ # quantize model, the calibration_dataset should be list of dict whose keys can only be "input_ids" and "attention_mask"
92
+ # with value under torch.LongTensor type.
93
+ model.quantize(traindataset)
94
+
95
+ # save quantized model using safetensors
96
+ model.save(quantized_model_id)
97
+ ```
98
+
99
+ ### Push to hub (Optional)
100
+ ```python
101
+ # Define the repository name where the model will be saved
102
+ repo = f"GSJL/{quantized_model_id}"
103
+
104
+ # Push the quantized model and tokenizer to the Hugging Face Hub
105
+ GPTQModel.push_to_hub(repo, quantized_model_id)
106
+ ```
107
+
108
+
109
+ ## Introduction
110
+
111
+ QwQ is the reasoning model of the Qwen series. Compared with conventional instruction-tuned models, QwQ, which is capable of thinking and reasoning, can achieve significantly enhanced performance in downstream tasks, especially hard problems. QwQ-32B is the medium-sized reasoning model, which is capable of achieving competitive performance against state-of-the-art reasoning models, e.g., DeepSeek-R1, o1-mini.
112
+
113
+ <p align="center">
114
+ <img width="100%" src="figures/benchmark.jpg">
115
+ </p>
116
+
117
+
118
+ **This repo contains the QwQ 32B model**, which has the following features:
119
+ - Type: Causal Language Models
120
+ - Training Stage: Pretraining & Post-training (Supervised Finetuning and Reinforcement Learning)
121
+ - Architecture: transformers with RoPE, SwiGLU, RMSNorm, and Attention QKV bias
122
+ - Number of Parameters: 32.5B
123
+ - Number of Paramaters (Non-Embedding): 31.0B
124
+ - Number of Layers: 64
125
+ - Number of Attention Heads (GQA): 40 for Q and 8 for KV
126
+ - Context Length: Full 131,072 tokens
127
+
128
+ **Note:** For the best experience, please review the [usage guidelines](#usage-guidelines) before deploying QwQ models.
129
+
130
+ You can try our [demo](https://huggingface.co/spaces/Qwen/QwQ-32B-Demo) or access QwQ models via [QwenChat](https://chat.qwen.ai).
131
+
132
+ For more details, please refer to our [blog](https://qwenlm.github.io/blog/qwq-32b/), [GitHub](https://github.com/QwenLM/Qwen2.5), and [Documentation](https://qwen.readthedocs.io/en/latest/).
133
+
134
+ ## Requirements
135
+
136
+ QwQ is based on Qwen2.5, whose code has been in the latest Hugging face `transformers`. We advise you to use the latest version of `transformers`.
137
+
138
+ With `transformers<4.37.0`, you will encounter the following error:
139
+ ```
140
+ KeyError: 'qwen2'
141
+ ```
142
+
143
+ ## Quickstart
144
+
145
+ Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
146
+
147
+ ```python
148
+ from transformers import AutoModelForCausalLM, AutoTokenizer
149
+
150
+ model_name = "Qwen/QwQ-32B"
151
+
152
+ model = AutoModelForCausalLM.from_pretrained(
153
+ model_name,
154
+ torch_dtype="auto",
155
+ device_map="auto"
156
+ )
157
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
158
+
159
+ prompt = "How many r's are in the word \"strawberry\""
160
+ messages = [
161
+ {"role": "user", "content": prompt}
162
+ ]
163
+ text = tokenizer.apply_chat_template(
164
+ messages,
165
+ tokenize=False,
166
+ add_generation_prompt=True
167
+ )
168
+
169
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
170
+
171
+ generated_ids = model.generate(
172
+ **model_inputs,
173
+ max_new_tokens=32768
174
+ )
175
+ generated_ids = [
176
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
177
+ ]
178
+
179
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
180
+ print(response)
181
+ ```
182
+
183
+ ### Usage Guidelines
184
+
185
+ To achieve optimal performance, we recommend the following settings:
186
+
187
+ 1. **Enforce Thoughtful Output**: Ensure the model starts with "\<think\>\n" to prevent generating empty thinking content, which can degrade output quality. If you use `apply_chat_template` and set `add_generation_prompt=True`, this is already automatically implemented, but it may cause the response to lack the \<think\> tag at the beginning. This is normal behavior.
188
+
189
+ 2. **Sampling Parameters**:
190
+ - Use Temperature=0.6 and TopP=0.95 instead of Greedy decoding to avoid endless repetitions.
191
+ - Use TopK between 20 and 40 to filter out rare token occurrences while maintaining the diversity of the generated output.
192
+
193
+ 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
194
+ - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
195
+ - **Multiple-Choice Questions**: Add the following JSON structure to the prompt to standardize responses: "Please show your choice in the `answer` field with only the choice letter, e.g.,`\"answer\": \"C\"`." in the prompt.
196
+
197
+ 4. **Handle Long Inputs**: For inputs exceeding 32,768 tokens, enable [YaRN](https://arxiv.org/abs/2309.00071) to improve the model's ability to capture long-sequence information effectively.
198
+
199
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
200
+ ```json
201
+ {
202
+ ...,
203
+ "rope_scaling": {
204
+ "factor": 4.0,
205
+ "original_max_position_embeddings": 32768,
206
+ "type": "yarn"
207
+ }
208
+ }
209
+ ```
210
+
211
+ For deployment, we recommend using vLLM. Please refer to our [Documentation](https://qwen.readthedocs.io/en/latest/deployment/vllm.html) for usage if you are not familar with vLLM.
212
+ Presently, vLLM only supports static YARN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts**.
213
+ We advise adding the `rope_scaling` configuration only when processing long contexts is required.
214
+
215
+ ## Evaluation & Performance
216
+
217
+ Detailed evaluation results are reported in this [📑 blog](https://qwenlm.github.io/blog/qwq-32b/).
218
+
219
+ For requirements on GPU memory and the respective throughput, see results [here](https://qwen.readthedocs.io/en/latest/benchmark/speed_benchmark.html).
220
+
221
+ ## Citation
222
+
223
+ If you find our work helpful, feel free to give us a cite.
224
+
225
+ ```
226
+ @misc{qwq32b,
227
+ title = {QwQ-32B: The Power of Scaling RL},
228
+ url = {https://qwenlm.github.io/blog/qwq-32b/},
229
+ author = {Qwen Team},
230
+ month = {March},
231
+ year = {2025}
232
+ }
233
+
234
+ @article{qwen2,
235
+ title={Qwen2 Technical Report},
236
+ author={An Yang and Baosong Yang and Binyuan Hui and Bo Zheng and Bowen Yu and Chang Zhou and Chengpeng Li and Chengyuan Li and Dayiheng Liu and Fei Huang and Guanting Dong and Haoran Wei and Huan Lin and Jialong Tang and Jialin Wang and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Ma and Jin Xu and Jingren Zhou and Jinze Bai and Jinzheng He and Junyang Lin and Kai Dang and Keming Lu and Keqin Chen and Kexin Yang and Mei Li and Mingfeng Xue and Na Ni and Pei Zhang and Peng Wang and Ru Peng and Rui Men and Ruize Gao and Runji Lin and Shijie Wang and Shuai Bai and Sinan Tan and Tianhang Zhu and Tianhao Li and Tianyu Liu and Wenbin Ge and Xiaodong Deng and Xiaohuan Zhou and Xingzhang Ren and Xinyu Zhang and Xipin Wei and Xuancheng Ren and Yang Fan and Yang Yao and Yichang Zhang and Yu Wan and Yunfei Chu and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zhihao Fan},
237
+ journal={arXiv preprint arXiv:2407.10671},
238
+ year={2024}
239
+ }
240
  ```