gabriellarson commited on
Commit
de641d6
·
verified ·
1 Parent(s): bc73cd8

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +207 -0
README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ base_model:
7
+ - Qwen/Qwen3-4B-Thinking-2507
8
+ ---
9
+ # Qwen3-4B-Thinking-2507
10
+ <a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
11
+ <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;"/>
12
+ </a>
13
+ ## Highlights
14
+
15
+ 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:
16
+
17
+ - **Significantly improved performance** on reasoning tasks, including logical reasoning, mathematics, science, coding, and academic benchmarks that typically require human expertise.
18
+ - **Markedly better general capabilities**, such as instruction following, tool usage, text generation, and alignment with human preferences.
19
+ - **Enhanced 256K long-context understanding** capabilities.
20
+
21
+ **NOTE**: This version has an increased thinking length. We strongly recommend its use in highly complex reasoning tasks.
22
+
23
+ ![image/jpeg](https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3-2507/Qwen3-4B-Instruct.001.jpeg)
24
+
25
+ ## Model Overview
26
+
27
+ **Qwen3-4B-Thinking-2507** has the following features:
28
+ - Type: Causal Language Models
29
+ - Training Stage: Pretraining & Post-training
30
+ - Number of Parameters: 4.0B
31
+ - Number of Paramaters (Non-Embedding): 3.6B
32
+ - Number of Layers: 36
33
+ - Number of Attention Heads (GQA): 32 for Q and 8 for KV
34
+ - Context Length: **262,144 natively**.
35
+
36
+ **NOTE: This model supports only thinking mode. Meanwhile, specifying `enable_thinking=True` is no longer required.**
37
+ 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.
38
+ 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/).
39
+ ## Performance
40
+ | | Qwen3-30B-A3B Thinking | Qwen3-4B Thinking | Qwen3-4B-Thinking-2507 |
41
+ |--- | --- | --- | --- |
42
+ | **Knowledge** | | |
43
+ | MMLU-Pro | **78.5** | 70.4 | 74.0 |
44
+ | MMLU-Redux | **89.5** | 83.7 | 86.1 |
45
+ | GPQA | **65.8** | 55.9 | **65.8** |
46
+ | SuperGPQA | **51.8** | 42.7 | 47.8 |
47
+ | **Reasoning** | | |
48
+ | AIME25 | 70.9 | 65.6 | **81.3** |
49
+ | HMMT25 | 49.8 | 42.1 | **55.5** |
50
+ | LiveBench 20241125 | **74.3** | 63.6 | 71.8 |
51
+ | **Coding** | | |
52
+ | LiveCodeBench v6 (25.02-25.05) | **57.4** | 48.4 | 55.2 |
53
+ | CFEval | **1940** | 1671 | 1852 |
54
+ | OJBench | **20.7** | 16.1 | 17.9 |
55
+ | **Alignment** | | |
56
+ | IFEval | 86.5 | 81.9 | **87.4** |
57
+ | Arena-Hard v2$ | **36.3** | 13.7 | 34.9 |
58
+ | Creative Writing v3 | **79.1** | 61.1 | 75.6 |
59
+ | WritingBench | 77.0 | 73.5 | **83.3** |
60
+ | **Agent** | | |
61
+ | BFCL-v3 | 69.1 | 65.9 | **71.2** |
62
+ | TAU1-Retail | 61.7 | 33.9 | **66.1** |
63
+ | TAU1-Airline | 32.0 | 32.0 | **48.0** |
64
+ | TAU2-Retail | 34.2 | 38.6 | **53.5** |
65
+ | TAU2-Airline | 36.0 | 28.0 | **58.0** |
66
+ | TAU2-Telecom | 22.8 | 17.5 | **27.2** |
67
+ | **Multilingualism** | | |
68
+ | MultiIF | 72.2 | 66.3 | **77.3** |
69
+ | MMLU-ProX | **73.1** | 61.0 | 64.2 |
70
+ | INCLUDE | **71.9** | 61.8 | 64.4 |
71
+ | PolyMATH | 46.1 | 40.0 | **46.2** |
72
+ $ For reproducibility, we report the win rates evaluated by GPT-4.1.
73
+ \& 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.
74
+ ## Quickstart
75
+ The code of Qwen3 has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
76
+ With `transformers<4.51.0`, you will encounter the following error:
77
+ ```
78
+ KeyError: 'qwen3'
79
+ ```
80
+ The following contains a code snippet illustrating how to use the model generate content based on given inputs.
81
+ ```python
82
+ from transformers import AutoModelForCausalLM, AutoTokenizer
83
+ model_name = "Qwen/Qwen3-4B-Thinking-2507"
84
+ # load the tokenizer and the model
85
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
86
+ model = AutoModelForCausalLM.from_pretrained(
87
+ model_name,
88
+ torch_dtype="auto",
89
+ device_map="auto"
90
+ )
91
+ # prepare the model input
92
+ prompt = "Give me a short introduction to large language model."
93
+ messages = [
94
+ {"role": "user", "content": prompt}
95
+ ]
96
+ text = tokenizer.apply_chat_template(
97
+ messages,
98
+ tokenize=False,
99
+ add_generation_prompt=True,
100
+ )
101
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
102
+ # conduct text completion
103
+ generated_ids = model.generate(
104
+ **model_inputs,
105
+ max_new_tokens=32768
106
+ )
107
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
108
+ # parsing thinking content
109
+ try:
110
+ # rindex finding 151668 (</think>)
111
+ index = len(output_ids) - output_ids[::-1].index(151668)
112
+ except ValueError:
113
+ index = 0
114
+ thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
115
+ content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
116
+ print("thinking content:", thinking_content) # no opening <think> tag
117
+ print("content:", content)
118
+ ```
119
+ For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
120
+ - SGLang:
121
+ ```shell
122
+ python -m sglang.launch_server --model-path Qwen/Qwen3-4B-Thinking-2507 --context-length 262144 --reasoning-parser deepseek-r1
123
+ ```
124
+ - vLLM:
125
+ ```shell
126
+ vllm serve Qwen/Qwen3-4B-Thinking-2507 --max-model-len 262144 --enable-reasoning --reasoning-parser deepseek_r1
127
+ ```
128
+ **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.**
129
+
130
+ For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
131
+
132
+ ## Agentic Use
133
+
134
+ 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.
135
+
136
+ 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.
137
+ ```python
138
+ from qwen_agent.agents import Assistant
139
+ # Define LLM
140
+ # Using OpenAI-compatible API endpoint. It is recommended to disable the reasoning and the tool call parsing
141
+ # functionality of the deployment frameworks and let Qwen-Agent automate the related operations. For example,
142
+ # `VLLM_USE_MODELSCOPE=true vllm serve Qwen/Qwen3-4B-Thinking-2507 --served-model-name Qwen3-4B-Thinking-2507 --max-model-len 262144`.
143
+ llm_cfg = {
144
+ 'model': 'Qwen3-4B-Thinking-2507',
145
+ # Use a custom endpoint compatible with OpenAI API:
146
+ 'model_server': 'http://localhost:8000/v1', # api_base without reasoning and tool call parsing
147
+ 'api_key': 'EMPTY',
148
+ 'generate_cfg': {
149
+ 'thought_in_content': True,
150
+ },
151
+ }
152
+ # Define Tools
153
+ tools = [
154
+ {'mcpServers': { # You can specify the MCP configuration file
155
+ 'time': {
156
+ 'command': 'uvx',
157
+ 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
158
+ },
159
+ "fetch": {
160
+ "command": "uvx",
161
+ "args": ["mcp-server-fetch"]
162
+ }
163
+ }
164
+ },
165
+ 'code_interpreter', # Built-in tools
166
+ ]
167
+ # Define Agent
168
+ bot = Assistant(llm=llm_cfg, function_list=tools)
169
+ # Streaming generation
170
+ messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
171
+ for responses in bot.run(messages=messages):
172
+ pass
173
+ print(responses)
174
+ ```
175
+
176
+ ## Best Practices
177
+
178
+ To achieve optimal performance, we recommend the following settings:
179
+
180
+ 1. **Sampling Parameters**:
181
+ - We suggest using `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0`.
182
+ - 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.
183
+
184
+ 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.
185
+
186
+ 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
187
+ - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
188
+ - **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"`."
189
+
190
+ 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.
191
+
192
+
193
+ ### Citation
194
+
195
+ If you find our work helpful, feel free to give us a cite.
196
+
197
+ ```
198
+ @misc{qwen3technicalreport,
199
+ title={Qwen3 Technical Report},
200
+ author={Qwen Team},
201
+ year={2025},
202
+ eprint={2505.09388},
203
+ archivePrefix={arXiv},
204
+ primaryClass={cs.CL},
205
+ url={https://arxiv.org/abs/2505.09388},
206
+ }
207
+ ```