Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
license_link: https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct/blob/main/LICENSE
|
5 |
+
pipeline_tag: text-generation
|
6 |
+
base_model:
|
7 |
+
- Qwen/Qwen3-Coder-30B-A3B-Instruct
|
8 |
+
---
|
9 |
+
|
10 |
+
# Qwen3-Coder-30B-A3B-Instruct
|
11 |
+
<a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
|
12 |
+
<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;"/>
|
13 |
+
</a>
|
14 |
+
|
15 |
+
## Highlights
|
16 |
+
|
17 |
+
**Qwen3-Coder** is available in multiple sizes. Today, we're excited to introduce **Qwen3-Coder-30B-A3B-Instruct**. This streamlined model maintains impressive performance and efficiency, featuring the following key enhancements:
|
18 |
+
|
19 |
+
- **Significant Performance** among open models on **Agentic Coding**, **Agentic Browser-Use**, and other foundational coding tasks.
|
20 |
+
- **Long-context Capabilities** with native support for **256K** tokens, extendable up to **1M** tokens using Yarn, optimized for repository-scale understanding.
|
21 |
+
- **Agentic Coding** supporting for most platform such as **Qwen Code**, **CLINE**, featuring a specially designed function call format.
|
22 |
+
|
23 |
+

|
24 |
+
|
25 |
+
## Model Overview
|
26 |
+
|
27 |
+
**Qwen3-Coder-30B-A3B-Instruct** has the following features:
|
28 |
+
- Type: Causal Language Models
|
29 |
+
- Training Stage: Pretraining & Post-training
|
30 |
+
- Number of Parameters: 30.5B in total and 3.3B activated
|
31 |
+
- Number of Layers: 48
|
32 |
+
- Number of Attention Heads (GQA): 32 for Q and 4 for KV
|
33 |
+
- Number of Experts: 128
|
34 |
+
- Number of Activated Experts: 8
|
35 |
+
- Context Length: **262,144 natively**.
|
36 |
+
|
37 |
+
**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.**
|
38 |
+
|
39 |
+
For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3-coder/), [GitHub](https://github.com/QwenLM/Qwen3-Coder), and [Documentation](https://qwen.readthedocs.io/en/latest/).
|
40 |
+
|
41 |
+
|
42 |
+
## Quickstart
|
43 |
+
|
44 |
+
We advise you to use the latest version of `transformers`.
|
45 |
+
|
46 |
+
With `transformers<4.51.0`, you will encounter the following error:
|
47 |
+
```
|
48 |
+
KeyError: 'qwen3_moe'
|
49 |
+
```
|
50 |
+
|
51 |
+
The following contains a code snippet illustrating how to use the model generate content based on given inputs.
|
52 |
+
```python
|
53 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
54 |
+
|
55 |
+
model_name = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
|
56 |
+
|
57 |
+
# load the tokenizer and the model
|
58 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
59 |
+
model = AutoModelForCausalLM.from_pretrained(
|
60 |
+
model_name,
|
61 |
+
torch_dtype="auto",
|
62 |
+
device_map="auto"
|
63 |
+
)
|
64 |
+
|
65 |
+
# prepare the model input
|
66 |
+
prompt = "Write a quick sort algorithm."
|
67 |
+
messages = [
|
68 |
+
{"role": "user", "content": prompt}
|
69 |
+
]
|
70 |
+
text = tokenizer.apply_chat_template(
|
71 |
+
messages,
|
72 |
+
tokenize=False,
|
73 |
+
add_generation_prompt=True,
|
74 |
+
)
|
75 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
76 |
+
|
77 |
+
# conduct text completion
|
78 |
+
generated_ids = model.generate(
|
79 |
+
**model_inputs,
|
80 |
+
max_new_tokens=65536
|
81 |
+
)
|
82 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
83 |
+
|
84 |
+
content = tokenizer.decode(output_ids, skip_special_tokens=True)
|
85 |
+
|
86 |
+
print("content:", content)
|
87 |
+
```
|
88 |
+
|
89 |
+
**Note: If you encounter out-of-memory (OOM) issues, consider reducing the context length to a shorter value, such as `32,768`.**
|
90 |
+
|
91 |
+
For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
|
92 |
+
|
93 |
+
## Agentic Coding
|
94 |
+
|
95 |
+
Qwen3-Coder excels in tool calling capabilities.
|
96 |
+
|
97 |
+
You can simply define or use any tools as following example.
|
98 |
+
```python
|
99 |
+
# Your tool implementation
|
100 |
+
def square_the_number(num: float) -> dict:
|
101 |
+
return num ** 2
|
102 |
+
|
103 |
+
# Define Tools
|
104 |
+
tools=[
|
105 |
+
{
|
106 |
+
"type":"function",
|
107 |
+
"function":{
|
108 |
+
"name": "square_the_number",
|
109 |
+
"description": "output the square of the number.",
|
110 |
+
"parameters": {
|
111 |
+
"type": "object",
|
112 |
+
"required": ["input_num"],
|
113 |
+
"properties": {
|
114 |
+
'input_num': {
|
115 |
+
'type': 'number',
|
116 |
+
'description': 'input_num is a number that will be squared'
|
117 |
+
}
|
118 |
+
},
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
]
|
123 |
+
|
124 |
+
import OpenAI
|
125 |
+
# Define LLM
|
126 |
+
client = OpenAI(
|
127 |
+
# Use a custom endpoint compatible with OpenAI API
|
128 |
+
base_url='http://localhost:8000/v1', # api_base
|
129 |
+
api_key="EMPTY"
|
130 |
+
)
|
131 |
+
|
132 |
+
messages = [{'role': 'user', 'content': 'square the number 1024'}]
|
133 |
+
|
134 |
+
completion = client.chat.completions.create(
|
135 |
+
messages=messages,
|
136 |
+
model="Qwen3-Coder-30B-A3B-Instruct",
|
137 |
+
max_tokens=65536,
|
138 |
+
tools=tools,
|
139 |
+
)
|
140 |
+
|
141 |
+
print(completion.choice[0])
|
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`, `top_p=0.8`, `top_k=20`, `repetition_penalty=1.05`.
|
150 |
+
|
151 |
+
2. **Adequate Output Length**: We recommend using an output length of 65,536 tokens for most queries, which is adequate for instruct models.
|
152 |
+
|
153 |
+
|
154 |
+
### Citation
|
155 |
+
|
156 |
+
If you find our work helpful, feel free to give us a cite.
|
157 |
+
|
158 |
+
```
|
159 |
+
@misc{qwen3technicalreport,
|
160 |
+
title={Qwen3 Technical Report},
|
161 |
+
author={Qwen Team},
|
162 |
+
year={2025},
|
163 |
+
eprint={2505.09388},
|
164 |
+
archivePrefix={arXiv},
|
165 |
+
primaryClass={cs.CL},
|
166 |
+
url={https://arxiv.org/abs/2505.09388},
|
167 |
+
}
|
168 |
+
```
|