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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
license_link: https://huggingface.co/Qwen/Qwen3-30B-A3B-Instruct-2507/blob/main/LICENSE
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# Qwen3-30B-A3B-Instruct-2507
|
| 9 |
+
<a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
|
| 10 |
+
<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;"/>
|
| 11 |
+
</a>
|
| 12 |
+
|
| 13 |
+
## Highlights
|
| 14 |
+
|
| 15 |
+
We introduce the updated version of the **Qwen3-30B-A3B non-thinking mode**, named **Qwen3-30B-A3B-Instruct-2507**, featuring the following key enhancements:
|
| 16 |
+
|
| 17 |
+
- **Significant improvements** in general capabilities, including **instruction following, logical reasoning, text comprehension, mathematics, science, coding and tool usage**.
|
| 18 |
+
- **Substantial gains** in long-tail knowledge coverage across **multiple languages**.
|
| 19 |
+
- **Markedly better alignment** with user preferences in **subjective and open-ended tasks**, enabling more helpful responses and higher-quality text generation.
|
| 20 |
+
- **Enhanced capabilities** in **256K long-context understanding**.
|
| 21 |
+
|
| 22 |
+
## Model Overview
|
| 23 |
+
|
| 24 |
+
**Qwen3-30B-A3B-Instruct-2507** has the following features:
|
| 25 |
+
- Type: Causal Language Models
|
| 26 |
+
- Training Stage: Pretraining & Post-training
|
| 27 |
+
- Number of Parameters: 30.5B in total and 3.3B activated
|
| 28 |
+
- Number of Paramaters (Non-Embedding): 29.9B
|
| 29 |
+
- Number of Layers: 48
|
| 30 |
+
- Number of Attention Heads (GQA): 32 for Q and 4 for KV
|
| 31 |
+
- Number of Experts: 128
|
| 32 |
+
- Number of Activated Experts: 8
|
| 33 |
+
- Context Length: **262,144 natively**.
|
| 34 |
+
|
| 35 |
+
**NOTE: This model supports only non-thinking mode and does not generate ``<think></think>`` blocks in its output. Meanwhile, specifying `enable_thinking=False` is no longer required.**
|
| 36 |
+
|
| 37 |
+
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/).
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## Quickstart
|
| 41 |
+
|
| 42 |
+
The code of Qwen3-MoE has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
|
| 43 |
+
|
| 44 |
+
With `transformers<4.51.0`, you will encounter the following error:
|
| 45 |
+
```
|
| 46 |
+
KeyError: 'qwen3_moe'
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
The following contains a code snippet illustrating how to use the model generate content based on given inputs.
|
| 50 |
+
```python
|
| 51 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 52 |
+
|
| 53 |
+
model_name = "Qwen/Qwen3-30B-A3B-Instruct-2507"
|
| 54 |
+
|
| 55 |
+
# load the tokenizer and the model
|
| 56 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 57 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 58 |
+
model_name,
|
| 59 |
+
torch_dtype="auto",
|
| 60 |
+
device_map="auto"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# prepare the model input
|
| 64 |
+
prompt = "Give me a short introduction to large language model."
|
| 65 |
+
messages = [
|
| 66 |
+
{"role": "user", "content": prompt}
|
| 67 |
+
]
|
| 68 |
+
text = tokenizer.apply_chat_template(
|
| 69 |
+
messages,
|
| 70 |
+
tokenize=False,
|
| 71 |
+
add_generation_prompt=True,
|
| 72 |
+
)
|
| 73 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 74 |
+
|
| 75 |
+
# conduct text completion
|
| 76 |
+
generated_ids = model.generate(
|
| 77 |
+
**model_inputs,
|
| 78 |
+
max_new_tokens=16384
|
| 79 |
+
)
|
| 80 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 81 |
+
|
| 82 |
+
content = tokenizer.decode(output_ids, skip_special_tokens=True)
|
| 83 |
+
|
| 84 |
+
print("content:", content)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
|
| 88 |
+
- SGLang:
|
| 89 |
+
```shell
|
| 90 |
+
python -m sglang.launch_server --model-path Qwen/Qwen3-30B-A3B-Instruct-2507 --tp 8 --context-length 262144
|
| 91 |
+
```
|
| 92 |
+
- vLLM:
|
| 93 |
+
```shell
|
| 94 |
+
vllm serve Qwen/Qwen3-30B-A3B-Instruct-2507 --tensor-parallel-size 8 --max-model-len 262144
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
**Note: If you encounter out-of-memory (OOM) issues, consider reducing the context length to a shorter value, such as `32,768`.**
|
| 98 |
+
|
| 99 |
+
For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
|
| 100 |
+
|
| 101 |
+
## Agentic Use
|
| 102 |
+
|
| 103 |
+
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.
|
| 104 |
+
|
| 105 |
+
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.
|
| 106 |
+
```python
|
| 107 |
+
from qwen_agent.agents import Assistant
|
| 108 |
+
|
| 109 |
+
# Define LLM
|
| 110 |
+
llm_cfg = {
|
| 111 |
+
'model': 'Qwen3-30B-A3B-Instruct-2507',
|
| 112 |
+
|
| 113 |
+
# Use a custom endpoint compatible with OpenAI API:
|
| 114 |
+
'model_server': 'http://localhost:8000/v1', # api_base
|
| 115 |
+
'api_key': 'EMPTY',
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
# Define Tools
|
| 119 |
+
tools = [
|
| 120 |
+
{'mcpServers': { # You can specify the MCP configuration file
|
| 121 |
+
'time': {
|
| 122 |
+
'command': 'uvx',
|
| 123 |
+
'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
|
| 124 |
+
},
|
| 125 |
+
"fetch": {
|
| 126 |
+
"command": "uvx",
|
| 127 |
+
"args": ["mcp-server-fetch"]
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
},
|
| 131 |
+
'code_interpreter', # Built-in tools
|
| 132 |
+
]
|
| 133 |
+
|
| 134 |
+
# Define Agent
|
| 135 |
+
bot = Assistant(llm=llm_cfg, function_list=tools)
|
| 136 |
+
|
| 137 |
+
# Streaming generation
|
| 138 |
+
messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
|
| 139 |
+
for responses in bot.run(messages=messages):
|
| 140 |
+
pass
|
| 141 |
+
print(responses)
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## Best Practices
|
| 145 |
+
|
| 146 |
+
To achieve optimal performance, we recommend the following settings:
|
| 147 |
+
|
| 148 |
+
1. **Sampling Parameters**:
|
| 149 |
+
- We suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`.
|
| 150 |
+
- 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.
|
| 151 |
+
|
| 152 |
+
2. **Adequate Output Length**: We recommend using an output length of 16,384 tokens for most queries, which is adequate for instruct models.
|
| 153 |
+
|
| 154 |
+
3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
|
| 155 |
+
- **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
|
| 156 |
+
- **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"`."
|
| 157 |
+
|
| 158 |
+
### Citation
|
| 159 |
+
|
| 160 |
+
If you find our work helpful, feel free to give us a cite.
|
| 161 |
+
|
| 162 |
+
```
|
| 163 |
+
@misc{qwen3technicalreport,
|
| 164 |
+
title={Qwen3 Technical Report},
|
| 165 |
+
author={Qwen Team},
|
| 166 |
+
year={2025},
|
| 167 |
+
eprint={2505.09388},
|
| 168 |
+
archivePrefix={arXiv},
|
| 169 |
+
primaryClass={cs.CL},
|
| 170 |
+
url={https://arxiv.org/abs/2505.09388},
|
| 171 |
+
}
|
| 172 |
+
```
|