JunHowie commited on
Commit
05a155f
·
verified ·
1 Parent(s): 6bc2785

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +264 -0
README.md ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ license_link: https://huggingface.co/Qwen/Qwen3-4B-Thinking-2507/blob/main/LICENSE
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - Qwen3
8
+ - GPTQ
9
+ - Int4
10
+ - 量化修复
11
+ - vLLM
12
+ base_model:
13
+ - Qwen/Qwen3-4B-Thinking-2507
14
+ base_model_relation: quantized
15
+ ---
16
+ # Qwen3-4B-Thinking-2507-GPTQ-Int4
17
+ Base model: [Qwen/Qwen3-4B-Thinking-2507](https://huggingface.co/Qwen/Qwen3-4B-Thinking-2507)
18
+
19
+ <i>This model is quantized to 4-bit with a group size of 128.</i>
20
+
21
+ ```
22
+ vllm serve JunHowie/Qwen3-4B-Thinking-2507-GPTQ-Int4
23
+ ```
24
+
25
+ ### 【Dependencies】
26
+ ```
27
+ vllm>=0.9.2
28
+ ```
29
+
30
+ ### 【Model Download】
31
+
32
+ ```python
33
+ from huggingface_hub import snapshot_download
34
+ snapshot_download('JunHowie/Qwen3-4B-Thinking-2507-GPTQ-Int4', cache_dir="your_local_path")
35
+ ```
36
+
37
+ ### 【Overview】
38
+ # Qwen3-4B-Thinking-2507
39
+ <a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
40
+ <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;"/>
41
+ </a>
42
+
43
+ ## Highlights
44
+
45
+ Over the past three months, we have continued to scale the **thinking capability** of Qwen3-4B, improving both the **quality and depth** of reasoning. We are pleased to introduce **Qwen3-4B-Thinking-2507**, featuring the following key enhancements:
46
+
47
+ - **Significantly improved performance** on reasoning tasks, including logical reasoning, mathematics, science, coding, and academic benchmarks that typically require human expertise.
48
+ - **Markedly better general capabilities**, such as instruction following, tool usage, text generation, and alignment with human preferences.
49
+ - **Enhanced 256K long-context understanding** capabilities.
50
+
51
+ **NOTE**: This version has an increased thinking length. We strongly recommend its use in highly complex reasoning tasks.
52
+
53
+ ![image/jpeg](https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-2507/Qwen3-4B-Instruct.001.jpeg)
54
+
55
+ ## Model Overview
56
+
57
+ **Qwen3-4B-Thinking-2507** has the following features:
58
+ - Type: Causal Language Models
59
+ - Training Stage: Pretraining & Post-training
60
+ - Number of Parameters: 4.0B
61
+ - Number of Paramaters (Non-Embedding): 3.6B
62
+ - Number of Layers: 36
63
+ - Number of Attention Heads (GQA): 32 for Q and 8 for KV
64
+ - Context Length: **262,144 natively**.
65
+
66
+ **NOTE: This model supports only thinking mode. Meanwhile, specifying `enable_thinking=True` is no longer required.**
67
+
68
+ Additionally, to enforce model thinking, the default chat template automatically includes `<think>`. Therefore, it is normal for the model's output to contain only `</think>` without an explicit opening `<think>` tag.
69
+
70
+ For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3/), [GitHub](https://github.com/QwenLM/Qwen3), and [Documentation](https://qwen.readthedocs.io/en/latest/).
71
+
72
+
73
+ ## Performance
74
+
75
+
76
+ | | Qwen3-30B-A3B Thinking | Qwen3-4B Thinking | Qwen3-4B-Thinking-2507 |
77
+ |--- | --- | --- | --- |
78
+ | **Knowledge** | | |
79
+ | MMLU-Pro | **78.5** | 70.4 | 74.0 |
80
+ | MMLU-Redux | **89.5** | 83.7 | 86.1 |
81
+ | GPQA | **65.8** | 55.9 | **65.8** |
82
+ | SuperGPQA | **51.8** | 42.7 | 47.8 |
83
+ | **Reasoning** | | |
84
+ | AIME25 | 70.9 | 65.6 | **81.3** |
85
+ | HMMT25 | 49.8 | 42.1 | **55.5** |
86
+ | LiveBench 20241125 | **74.3** | 63.6 | 71.8 |
87
+ | **Coding** | | |
88
+ | LiveCodeBench v6 (25.02-25.05) | **57.4** | 48.4 | 55.2 |
89
+ | CFEval | **1940** | 1671 | 1852 |
90
+ | OJBench | **20.7** | 16.1 | 17.9 |
91
+ | **Alignment** | | |
92
+ | IFEval | 86.5 | 81.9 | **87.4** |
93
+ | Arena-Hard v2$ | **36.3** | 13.7 | 34.9 |
94
+ | Creative Writing v3 | **79.1** | 61.1 | 75.6 |
95
+ | WritingBench | 77.0 | 73.5 | **83.3** |
96
+ | **Agent** | | |
97
+ | BFCL-v3 | 69.1 | 65.9 | **71.2** |
98
+ | TAU1-Retail | 61.7 | 33.9 | **66.1** |
99
+ | TAU1-Airline | 32.0 | 32.0 | **48.0** |
100
+ | TAU2-Retail | 34.2 | 38.6 | **53.5** |
101
+ | TAU2-Airline | 36.0 | 28.0 | **58.0** |
102
+ | TAU2-Telecom | 22.8 | 17.5 | **27.2** |
103
+ | **Multilingualism** | | |
104
+ | MultiIF | 72.2 | 66.3 | **77.3** |
105
+ | MMLU-ProX | **73.1** | 61.0 | 64.2 |
106
+ | INCLUDE | **71.9** | 61.8 | 64.4 |
107
+ | PolyMATH | 46.1 | 40.0 | **46.2** |
108
+
109
+ $ For reproducibility, we report the win rates evaluated by GPT-4.1.
110
+
111
+ \& For highly challenging tasks (including PolyMATH and all reasoning and coding tasks), we use an output length of 81,920 tokens. For all other tasks, we set the output length to 32,768.
112
+
113
+ ## Quickstart
114
+
115
+ The code of Qwen3 has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
116
+
117
+ With `transformers<4.51.0`, you will encounter the following error:
118
+ ```
119
+ KeyError: 'qwen3'
120
+ ```
121
+
122
+ The following contains a code snippet illustrating how to use the model generate content based on given inputs.
123
+ ```python
124
+ from transformers import AutoModelForCausalLM, AutoTokenizer
125
+
126
+ model_name = "Qwen/Qwen3-4B-Thinking-2507"
127
+
128
+ # load the tokenizer and the model
129
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
130
+ model = AutoModelForCausalLM.from_pretrained(
131
+ model_name,
132
+ torch_dtype="auto",
133
+ device_map="auto"
134
+ )
135
+
136
+ # prepare the model input
137
+ prompt = "Give me a short introduction to large language model."
138
+ messages = [
139
+ {"role": "user", "content": prompt}
140
+ ]
141
+ text = tokenizer.apply_chat_template(
142
+ messages,
143
+ tokenize=False,
144
+ add_generation_prompt=True,
145
+ )
146
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
147
+
148
+ # conduct text completion
149
+ generated_ids = model.generate(
150
+ **model_inputs,
151
+ max_new_tokens=32768
152
+ )
153
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
154
+
155
+ # parsing thinking content
156
+ try:
157
+ # rindex finding 151668 (</think>)
158
+ index = len(output_ids) - output_ids[::-1].index(151668)
159
+ except ValueError:
160
+ index = 0
161
+
162
+ thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
163
+ content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
164
+
165
+ print("thinking content:", thinking_content) # no opening <think> tag
166
+ print("content:", content)
167
+
168
+ ```
169
+
170
+ For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
171
+ - SGLang:
172
+ ```shell
173
+ python -m sglang.launch_server --model-path Qwen/Qwen3-4B-Thinking-2507 --context-length 262144 --reasoning-parser deepseek-r1
174
+ ```
175
+ - vLLM:
176
+ ```shell
177
+ vllm serve Qwen/Qwen3-4B-Thinking-2507 --max-model-len 262144 --enable-reasoning --reasoning-parser deepseek_r1
178
+ ```
179
+
180
+ **Note: If you encounter out-of-memory (OOM) issues, you may consider reducing the context length to a smaller value. However, since the model may require longer token sequences for reasoning, we strongly recommend using a context length greater than 131,072 when possible.**
181
+
182
+ For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
183
+
184
+ ## Agentic Use
185
+
186
+ Qwen3 excels in tool calling capabilities. We recommend using [Qwen-Agent](https://github.com/QwenLM/Qwen-Agent) to make the best use of agentic ability of Qwen3. Qwen-Agent encapsulates tool-calling templates and tool-calling parsers internally, greatly reducing coding complexity.
187
+
188
+ To define the available tools, you can use the MCP configuration file, use the integrated tool of Qwen-Agent, or integrate other tools by yourself.
189
+ ```python
190
+ from qwen_agent.agents import Assistant
191
+
192
+ # Define LLM
193
+ # Using OpenAI-compatible API endpoint. It is recommended to disable the reasoning and the tool call parsing
194
+ # functionality of the deployment frameworks and let Qwen-Agent automate the related operations. For example,
195
+ # `VLLM_USE_MODELSCOPE=true vllm serve Qwen/Qwen3-4B-Thinking-2507 --served-model-name Qwen3-4B-Thinking-2507 --max-model-len 262144`.
196
+ llm_cfg = {
197
+ 'model': 'Qwen3-4B-Thinking-2507',
198
+
199
+ # Use a custom endpoint compatible with OpenAI API:
200
+ 'model_server': 'http://localhost:8000/v1', # api_base without reasoning and tool call parsing
201
+ 'api_key': 'EMPTY',
202
+ 'generate_cfg': {
203
+ 'thought_in_content': True,
204
+ },
205
+ }
206
+
207
+ # Define Tools
208
+ tools = [
209
+ {'mcpServers': { # You can specify the MCP configuration file
210
+ 'time': {
211
+ 'command': 'uvx',
212
+ 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
213
+ },
214
+ "fetch": {
215
+ "command": "uvx",
216
+ "args": ["mcp-server-fetch"]
217
+ }
218
+ }
219
+ },
220
+ 'code_interpreter', # Built-in tools
221
+ ]
222
+
223
+ # Define Agent
224
+ bot = Assistant(llm=llm_cfg, function_list=tools)
225
+
226
+ # Streaming generation
227
+ messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
228
+ for responses in bot.run(messages=messages):
229
+ pass
230
+ print(responses)
231
+ ```
232
+
233
+ ## Best Practices
234
+
235
+ To achieve optimal performance, we recommend the following settings:
236
+
237
+ 1. **Sampling Parameters**:
238
+ - We suggest using `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0`.
239
+ - For supported frameworks, you can adjust the `presence_penalty` parameter between 0 and 2 to reduce endless repetitions. However, using a higher value may occasionally result in language mixing and a slight decrease in model performance.
240
+
241
+ 2. **Adequate Output Length**: We recommend using an output length of 32,768 tokens for most queries. For benchmarking on highly complex problems, such as those found in math and programming competitions, we suggest setting the max output length to 81,920 tokens. This provides the model with sufficient space to generate detailed and comprehensive responses, thereby enhancing its overall performance.
242
+
243
+ 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
244
+ - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
245
+ - **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"`."
246
+
247
+ 4. **No Thinking Content in History**: In multi-turn conversations, the historical model output should only include the final output part and does not need to include the thinking content. It is implemented in the provided chat template in Jinja2. However, for frameworks that do not directly use the Jinja2 chat template, it is up to the developers to ensure that the best practice is followed.
248
+
249
+
250
+ ### Citation
251
+
252
+ If you find our work helpful, feel free to give us a cite.
253
+
254
+ ```
255
+ @misc{qwen3technicalreport,
256
+ title={Qwen3 Technical Report},
257
+ author={Qwen Team},
258
+ year={2025},
259
+ eprint={2505.09388},
260
+ archivePrefix={arXiv},
261
+ primaryClass={cs.CL},
262
+ url={https://arxiv.org/abs/2505.09388},
263
+ }
264
+ ```