Delta-Vector commited on
Commit
5817a52
·
verified ·
1 Parent(s): 12b9fa5

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. README.md +333 -102
  3. config.json +38 -0
  4. generation_config.json +13 -0
  5. merges.txt +0 -0
  6. model-model-00001-of-00118.safetensors-of-00118.safetensors +3 -0
  7. model-model-00002-of-00118.safetensors-of-00118.safetensors +3 -0
  8. model-model-00003-of-00118.safetensors-of-00118.safetensors +3 -0
  9. model-model-00004-of-00118.safetensors-of-00118.safetensors +3 -0
  10. model-model-00005-of-00118.safetensors-of-00118.safetensors +3 -0
  11. model-model-00006-of-00118.safetensors-of-00118.safetensors +3 -0
  12. model-model-00007-of-00118.safetensors-of-00118.safetensors +3 -0
  13. model-model-00008-of-00118.safetensors-of-00118.safetensors +3 -0
  14. model-model-00009-of-00118.safetensors-of-00118.safetensors +3 -0
  15. model-model-00010-of-00118.safetensors-of-00118.safetensors +3 -0
  16. model-model-00011-of-00118.safetensors-of-00118.safetensors +3 -0
  17. model-model-00012-of-00118.safetensors-of-00118.safetensors +3 -0
  18. model-model-00013-of-00118.safetensors-of-00118.safetensors +3 -0
  19. model-model-00014-of-00118.safetensors-of-00118.safetensors +3 -0
  20. model-model-00015-of-00118.safetensors-of-00118.safetensors +3 -0
  21. model-model-00016-of-00118.safetensors-of-00118.safetensors +3 -0
  22. model-model-00017-of-00118.safetensors-of-00118.safetensors +3 -0
  23. model-model-00018-of-00118.safetensors-of-00118.safetensors +3 -0
  24. model-model-00019-of-00118.safetensors-of-00118.safetensors +3 -0
  25. model-model-00020-of-00118.safetensors-of-00118.safetensors +3 -0
  26. model-model-00021-of-00118.safetensors-of-00118.safetensors +3 -0
  27. model-model-00022-of-00118.safetensors-of-00118.safetensors +3 -0
  28. model-model-00023-of-00118.safetensors-of-00118.safetensors +3 -0
  29. model-model-00024-of-00118.safetensors-of-00118.safetensors +3 -0
  30. model-model-00025-of-00118.safetensors-of-00118.safetensors +3 -0
  31. model-model-00026-of-00118.safetensors-of-00118.safetensors +3 -0
  32. model-model-00027-of-00118.safetensors-of-00118.safetensors +3 -0
  33. model-model-00028-of-00118.safetensors-of-00118.safetensors +3 -0
  34. model-model-00029-of-00118.safetensors-of-00118.safetensors +3 -0
  35. model-model-00030-of-00118.safetensors-of-00118.safetensors +3 -0
  36. model-model-00031-of-00118.safetensors-of-00118.safetensors +3 -0
  37. model-model-00032-of-00118.safetensors-of-00118.safetensors +3 -0
  38. model-model-00033-of-00118.safetensors-of-00118.safetensors +3 -0
  39. model-model-00034-of-00118.safetensors-of-00118.safetensors +3 -0
  40. model-model-00035-of-00118.safetensors-of-00118.safetensors +3 -0
  41. model-model-00036-of-00118.safetensors-of-00118.safetensors +3 -0
  42. model-model-00037-of-00118.safetensors-of-00118.safetensors +3 -0
  43. model-model-00038-of-00118.safetensors-of-00118.safetensors +3 -0
  44. model-model-00039-of-00118.safetensors-of-00118.safetensors +3 -0
  45. model-model-00040-of-00118.safetensors-of-00118.safetensors +3 -0
  46. model-model-00041-of-00118.safetensors-of-00118.safetensors +3 -0
  47. model-model-00042-of-00118.safetensors-of-00118.safetensors +3 -0
  48. model-model-00043-of-00118.safetensors-of-00118.safetensors +3 -0
  49. model-model-00044-of-00118.safetensors-of-00118.safetensors +3 -0
  50. model-model-00045-of-00118.safetensors-of-00118.safetensors +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,122 +1,353 @@
1
  ---
2
- tags:
3
- - chat
4
- - roleplay
5
- - storywriting
6
- - qwen3
7
- - finetune
8
- Language:
9
- - En
10
- Pipeline_tag: text-generation
11
- Tags:
12
- - Chat
13
- base_model:
14
- - Qwen/Qwen3-235B-A22B
15
  ---
16
 
17
- It's an SFT ontop of the largest Qwen which nobody seems to have done yet, Trained with a collection of normal Austral(Books, RP Logs, LNs, etc) datasets. I do not totally endorse the model yet and i think there's much work to be done in trying to make a decensored and well-writing finetune of this model but I just released this to give everyone a slight taste of a qwen3 finetune.
 
 
 
18
 
19
- It was also a way for us to test out some Optims to actually get this model to train, Thanks to Intervitens <3
20
- We used torchtune & an experimental hacky pytorch build: https://github.com/pytorch/pytorch/pull/156203
21
- We trained this model over 24 Hours on 8xB200s. Graciously provided by Deepinfra & Cognitive Computations.
22
- Speeds were similar to a 70B trained with roughly the same data.
23
 
 
24
 
25
- ## Prompting
26
- Model has been tuned with the ChatML formatting. A typical input would look like this:
 
 
 
27
 
28
- ```py
29
- <|im_start|>system
30
- system-prompt<|im_end|>
31
- <|im_start|>user
32
- user-prompt<|im_end|>
33
- <|im_start|>assistant
34
- <think>
35
 
36
- </think>
 
 
 
 
 
 
 
 
 
37
 
38
- assistant-prompt<|im_end|>
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  ```
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- ## Torchtune config
44
-
45
- Thank you so much for Intervitens for helping train this model:
46
-
47
- <details><summary>See Torchtune Trainer config</summary>
48
-
49
- ```yaml
50
- output_dir: ./qwen3_235B_A22B_austral/full
51
- tokenizer:
52
- _component_: torchtune.models.qwen3.qwen3_tokenizer
53
- path: ./Qwen3-235B-A22B-tt/vocab.json
54
- merges_file: ./Qwen3-235B-A22B-tt/merges.txt
55
- max_seq_len: 32768
56
- dataset:
57
- _component_: torchtune.datasets.pretokenized_dataset
58
- source: IntervitensInc/test_235B_2-pack
59
- split: train
60
- packed: true
61
- seed: 42
62
- shuffle: false
63
- model:
64
- _component_: torchtune.models.qwen3.qwen3_moe_235b_a22b
65
- checkpointer:
66
- _component_: torchtune.training.FullModelTorchTuneCheckpointer
67
- checkpoint_dir: ./Qwen3-235B-A22B-tt
68
- checkpoint_files:
69
- - model-00001-of-00001.bin
70
- recipe_checkpoint: null
71
- output_dir: ${output_dir}
72
- model_type: QWEN3_MOE
73
- resume_from_checkpoint: false
74
- enable_async_checkpointing: false
75
- batch_size: 1
76
- epochs: 4
77
- optimizer:
78
- _component_: torchao.optim.AdamW8bit
79
- lr: 3.0e-06
80
- lr_scheduler:
81
- _component_: torchtune.training.lr_schedulers.get_rex_scheduler
82
- num_warmup_steps: 100
83
- loss:
84
- _component_: torchtune.modules.loss.LinearCrossEntropyLoss
85
- max_steps_per_epoch: null
86
- gradient_accumulation_steps: 1
87
- clip_grad_norm: null
88
- compile:
89
- model: true
90
- loss: true
91
- scale_grads: true
92
- optimizer_step: false
93
- optimizer_in_bwd: true
94
- device: cuda
95
- enable_activation_checkpointing: true
96
- enable_activation_offloading: true
97
- custom_sharded_layers:
98
- - tok_embeddings
99
- - output
100
- fsdp_cpu_offload: false
101
- dtype: bf16
102
- metric_logger:
103
- _component_: torchtune.training.metric_logging.WandBLogger
104
- project: qwen3-235-a22b-austral
105
- log_every_n_steps: 1
106
- log_peak_memory_stats: true
107
- log_level: INFO
108
  ```
109
 
110
- </details><br>
111
 
112
- ## Credits
 
113
 
114
- Thank you to [Lucy Knada](https://huggingface.co/lucyknada), [Auri](https://huggingface.co/Auri), [Intervitens](https://huggingface.co/intervitens), [Deepinfra](https://deepinfra.com/), [Cognitive Computations](https://huggingface.co/cognitivecomputations) and the rest of [Anthracite](https://huggingface.co/anthracite-org) &
115
 
 
116
 
117
- ## Training
118
- The training was done for 4 epochs. We used 8 x [B200s](https://www.nvidia.com/en-us/data-center/dgx-b200/) GPUs graciously provided by [Deepinfra](https://deepinfra.com/) for the full-parameter fine-tuning of the model, Tuning was done all thanks to Intervitens.
119
 
120
- ## Safety
121
- It's still aligned to the beliefs of the Chinese Communist Party:
122
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/66c26b6fb01b19d8c3c2467b/0zqE9Wo2DsQT6ucxWfcSd.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ license_link: https://huggingface.co/Qwen/Qwen3-235B-A22B/blob/main/LICENSE
5
+ pipeline_tag: text-generation
 
 
 
 
 
 
 
 
 
6
  ---
7
 
8
+ # Qwen3-235B-A22B
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
+ ## Qwen3 Highlights
 
 
 
14
 
15
+ Qwen3 is the latest generation of large language models in Qwen series, offering a comprehensive suite of dense and mixture-of-experts (MoE) models. Built upon extensive training, Qwen3 delivers groundbreaking advancements in reasoning, instruction-following, agent capabilities, and multilingual support, with the following key features:
16
 
17
+ - **Uniquely support of seamless switching between thinking mode** (for complex logical reasoning, math, and coding) and **non-thinking mode** (for efficient, general-purpose dialogue) **within single model**, ensuring optimal performance across various scenarios.
18
+ - **Significantly enhancement in its reasoning capabilities**, surpassing previous QwQ (in thinking mode) and Qwen2.5 instruct models (in non-thinking mode) on mathematics, code generation, and commonsense logical reasoning.
19
+ - **Superior human preference alignment**, excelling in creative writing, role-playing, multi-turn dialogues, and instruction following, to deliver a more natural, engaging, and immersive conversational experience.
20
+ - **Expertise in agent capabilities**, enabling precise integration with external tools in both thinking and unthinking modes and achieving leading performance among open-source models in complex agent-based tasks.
21
+ - **Support of 100+ languages and dialects** with strong capabilities for **multilingual instruction following** and **translation**.
22
 
23
+ ## Model Overview
 
 
 
 
 
 
24
 
25
+ **Qwen3-235B-A22B** has the following features:
26
+ - Type: Causal Language Models
27
+ - Training Stage: Pretraining & Post-training
28
+ - Number of Parameters: 235B in total and 22B activated
29
+ - Number of Paramaters (Non-Embedding): 234B
30
+ - Number of Layers: 94
31
+ - Number of Attention Heads (GQA): 64 for Q and 4 for KV
32
+ - Number of Experts: 128
33
+ - Number of Activated Experts: 8
34
+ - Context Length: 32,768 natively and [131,072 tokens with YaRN](#processing-long-texts).
35
 
36
+ 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/).
37
 
38
+ ## Quickstart
39
+
40
+ The code of Qwen3-MoE has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
41
+
42
+ With `transformers<4.51.0`, you will encounter the following error:
43
+ ```
44
+ KeyError: 'qwen3_moe'
45
+ ```
46
+
47
+ The following contains a code snippet illustrating how to use the model generate content based on given inputs.
48
+ ```python
49
+ from transformers import AutoModelForCausalLM, AutoTokenizer
50
+
51
+ model_name = "Qwen/Qwen3-235B-A22B"
52
+
53
+ # load the tokenizer and the model
54
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
55
+ model = AutoModelForCausalLM.from_pretrained(
56
+ model_name,
57
+ torch_dtype="auto",
58
+ device_map="auto"
59
+ )
60
+
61
+ # prepare the model input
62
+ prompt = "Give me a short introduction to large language model."
63
+ messages = [
64
+ {"role": "user", "content": prompt}
65
+ ]
66
+ text = tokenizer.apply_chat_template(
67
+ messages,
68
+ tokenize=False,
69
+ add_generation_prompt=True,
70
+ enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
71
+ )
72
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
73
+
74
+ # conduct text completion
75
+ generated_ids = model.generate(
76
+ **model_inputs,
77
+ max_new_tokens=32768
78
+ )
79
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
80
+
81
+ # parsing thinking content
82
+ try:
83
+ # rindex finding 151668 (</think>)
84
+ index = len(output_ids) - output_ids[::-1].index(151668)
85
+ except ValueError:
86
+ index = 0
87
+
88
+ thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
89
+ content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
90
+
91
+ print("thinking content:", thinking_content)
92
+ print("content:", content)
93
  ```
94
 
95
+ For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
96
+ - SGLang:
97
+ ```shell
98
+ python -m sglang.launch_server --model-path Qwen/Qwen3-235B-A22B --reasoning-parser qwen3 --tp 8
99
+ ```
100
+ - vLLM:
101
+ ```shell
102
+ vllm serve Qwen/Qwen3-235B-A22B --enable-reasoning --reasoning-parser deepseek_r1
103
+ ```
104
+
105
+ For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
106
+
107
+ ## Switching Between Thinking and Non-Thinking Mode
108
 
109
+ > [!TIP]
110
+ > The `enable_thinking` switch is also available in APIs created by SGLang and vLLM.
111
+ > Please refer to our documentation for [SGLang](https://qwen.readthedocs.io/en/latest/deployment/sglang.html#thinking-non-thinking-modes) and [vLLM](https://qwen.readthedocs.io/en/latest/deployment/vllm.html#thinking-non-thinking-modes) users.
112
+
113
+ ### `enable_thinking=True`
114
+
115
+ By default, Qwen3 has thinking capabilities enabled, similar to QwQ-32B. This means the model will use its reasoning abilities to enhance the quality of generated responses. For example, when explicitly setting `enable_thinking=True` or leaving it as the default value in `tokenizer.apply_chat_template`, the model will engage its thinking mode.
116
+
117
+ ```python
118
+ text = tokenizer.apply_chat_template(
119
+ messages,
120
+ tokenize=False,
121
+ add_generation_prompt=True,
122
+ enable_thinking=True # True is the default value for enable_thinking
123
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ```
125
 
126
+ In this mode, the model will generate think content wrapped in a `<think>...</think>` block, followed by the final response.
127
 
128
+ > [!NOTE]
129
+ > For thinking mode, use `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0` (the default setting in `generation_config.json`). **DO NOT use greedy decoding**, as it can lead to performance degradation and endless repetitions. For more detailed guidance, please refer to the [Best Practices](#best-practices) section.
130
 
 
131
 
132
+ ### `enable_thinking=False`
133
 
134
+ We provide a hard switch to strictly disable the model's thinking behavior, aligning its functionality with the previous Qwen2.5-Instruct models. This mode is particularly useful in scenarios where disabling thinking is essential for enhancing efficiency.
 
135
 
136
+ ```python
137
+ text = tokenizer.apply_chat_template(
138
+ messages,
139
+ tokenize=False,
140
+ add_generation_prompt=True,
141
+ enable_thinking=False # Setting enable_thinking=False disables thinking mode
142
+ )
143
+ ```
144
+
145
+ In this mode, the model will not generate any think content and will not include a `<think>...</think>` block.
146
+
147
+ > [!NOTE]
148
+ > For non-thinking mode, we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`. For more detailed guidance, please refer to the [Best Practices](#best-practices) section.
149
+
150
+ ### Advanced Usage: Switching Between Thinking and Non-Thinking Modes via User Input
151
+
152
+ We provide a soft switch mechanism that allows users to dynamically control the model's behavior when `enable_thinking=True`. Specifically, you can add `/think` and `/no_think` to user prompts or system messages to switch the model's thinking mode from turn to turn. The model will follow the most recent instruction in multi-turn conversations.
153
+
154
+ Here is an example of a multi-turn conversation:
155
+
156
+ ```python
157
+ from transformers import AutoModelForCausalLM, AutoTokenizer
158
+
159
+ class QwenChatbot:
160
+ def __init__(self, model_name="Qwen/Qwen3-235B-A22B"):
161
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name)
162
+ self.model = AutoModelForCausalLM.from_pretrained(model_name)
163
+ self.history = []
164
+
165
+ def generate_response(self, user_input):
166
+ messages = self.history + [{"role": "user", "content": user_input}]
167
+
168
+ text = self.tokenizer.apply_chat_template(
169
+ messages,
170
+ tokenize=False,
171
+ add_generation_prompt=True
172
+ )
173
+
174
+ inputs = self.tokenizer(text, return_tensors="pt")
175
+ response_ids = self.model.generate(**inputs, max_new_tokens=32768)[0][len(inputs.input_ids[0]):].tolist()
176
+ response = self.tokenizer.decode(response_ids, skip_special_tokens=True)
177
+
178
+ # Update history
179
+ self.history.append({"role": "user", "content": user_input})
180
+ self.history.append({"role": "assistant", "content": response})
181
+
182
+ return response
183
+
184
+ # Example Usage
185
+ if __name__ == "__main__":
186
+ chatbot = QwenChatbot()
187
+
188
+ # First input (without /think or /no_think tags, thinking mode is enabled by default)
189
+ user_input_1 = "How many r's in strawberries?"
190
+ print(f"User: {user_input_1}")
191
+ response_1 = chatbot.generate_response(user_input_1)
192
+ print(f"Bot: {response_1}")
193
+ print("----------------------")
194
+
195
+ # Second input with /no_think
196
+ user_input_2 = "Then, how many r's in blueberries? /no_think"
197
+ print(f"User: {user_input_2}")
198
+ response_2 = chatbot.generate_response(user_input_2)
199
+ print(f"Bot: {response_2}")
200
+ print("----------------------")
201
+
202
+ # Third input with /think
203
+ user_input_3 = "Really? /think"
204
+ print(f"User: {user_input_3}")
205
+ response_3 = chatbot.generate_response(user_input_3)
206
+ print(f"Bot: {response_3}")
207
+ ```
208
+
209
+ > [!NOTE]
210
+ > For API compatibility, when `enable_thinking=True`, regardless of whether the user uses `/think` or `/no_think`, the model will always output a block wrapped in `<think>...</think>`. However, the content inside this block may be empty if thinking is disabled.
211
+ > When `enable_thinking=False`, the soft switches are not valid. Regardless of any `/think` or `/no_think` tags input by the user, the model will not generate think content and will not include a `<think>...</think>` block.
212
+
213
+ ## Agentic Use
214
+
215
+ 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.
216
+
217
+ 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.
218
+ ```python
219
+ from qwen_agent.agents import Assistant
220
+
221
+ # Define LLM
222
+ llm_cfg = {
223
+ 'model': 'Qwen3-235B-A22B',
224
+
225
+ # Use the endpoint provided by Alibaba Model Studio:
226
+ # 'model_type': 'qwen_dashscope',
227
+ # 'api_key': os.getenv('DASHSCOPE_API_KEY'),
228
+
229
+ # Use a custom endpoint compatible with OpenAI API:
230
+ 'model_server': 'http://localhost:8000/v1', # api_base
231
+ 'api_key': 'EMPTY',
232
+
233
+ # Other parameters:
234
+ # 'generate_cfg': {
235
+ # # Add: When the response content is `<think>this is the thought</think>this is the answer;
236
+ # # Do not add: When the response has been separated by reasoning_content and content.
237
+ # 'thought_in_content': True,
238
+ # },
239
+ }
240
+
241
+ # Define Tools
242
+ tools = [
243
+ {'mcpServers': { # You can specify the MCP configuration file
244
+ 'time': {
245
+ 'command': 'uvx',
246
+ 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
247
+ },
248
+ "fetch": {
249
+ "command": "uvx",
250
+ "args": ["mcp-server-fetch"]
251
+ }
252
+ }
253
+ },
254
+ 'code_interpreter', # Built-in tools
255
+ ]
256
+
257
+ # Define Agent
258
+ bot = Assistant(llm=llm_cfg, function_list=tools)
259
+
260
+ # Streaming generation
261
+ messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
262
+ for responses in bot.run(messages=messages):
263
+ pass
264
+ print(responses)
265
+ ```
266
+
267
+ ## Processing Long Texts
268
+
269
+ Qwen3 natively supports context lengths of up to 32,768 tokens. For conversations where the total length (including both input and output) significantly exceeds this limit, we recommend using RoPE scaling techniques to handle long texts effectively. We have validated the model's performance on context lengths of up to 131,072 tokens using the [YaRN](https://arxiv.org/abs/2309.00071) method.
270
+
271
+ YaRN is currently supported by several inference frameworks, e.g., `transformers` and `llama.cpp` for local use, `vllm` and `sglang` for deployment. In general, there are two approaches to enabling YaRN for supported frameworks:
272
+
273
+ - Modifying the model files:
274
+ In the `config.json` file, add the `rope_scaling` fields:
275
+ ```json
276
+ {
277
+ ...,
278
+ "rope_scaling": {
279
+ "rope_type": "yarn",
280
+ "factor": 4.0,
281
+ "original_max_position_embeddings": 32768
282
+ }
283
+ }
284
+ ```
285
+ For `llama.cpp`, you need to regenerate the GGUF file after the modification.
286
+
287
+ - Passing command line arguments:
288
+
289
+ For `vllm`, you can use
290
+ ```shell
291
+ vllm serve ... --rope-scaling '{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}' --max-model-len 131072
292
+ ```
293
+
294
+ For `sglang`, you can use
295
+ ```shell
296
+ python -m sglang.launch_server ... --json-model-override-args '{"rope_scaling":{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}}'
297
+ ```
298
+
299
+ For `llama-server` from `llama.cpp`, you can use
300
+ ```shell
301
+ llama-server ... --rope-scaling yarn --rope-scale 4 --yarn-orig-ctx 32768
302
+ ```
303
+
304
+ > [!IMPORTANT]
305
+ > If you encounter the following warning
306
+ > ```
307
+ > Unrecognized keys in `rope_scaling` for 'rope_type'='yarn': {'original_max_position_embeddings'}
308
+ > ```
309
+ > please upgrade `transformers>=4.51.0`.
310
+
311
+ > [!NOTE]
312
+ > All the notable open-source frameworks implement static YaRN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts.**
313
+ > We advise adding the `rope_scaling` configuration only when processing long contexts is required.
314
+ > It is also recommended to modify the `factor` as needed. For example, if the typical context length for your application is 65,536 tokens, it would be better to set `factor` as 2.0.
315
+
316
+ > [!NOTE]
317
+ > The default `max_position_embeddings` in `config.json` is set to 40,960. This allocation includes reserving 32,768 tokens for outputs and 8,192 tokens for typical prompts, which is sufficient for most scenarios involving short text processing. If the average context length does not exceed 32,768 tokens, we do not recommend enabling YaRN in this scenario, as it may potentially degrade model performance.
318
+
319
+ > [!TIP]
320
+ > The endpoint provided by Alibaba Model Studio supports dynamic YaRN by default and no extra configuration is needed.
321
+
322
+ ## Best Practices
323
+
324
+ To achieve optimal performance, we recommend the following settings:
325
+
326
+ 1. **Sampling Parameters**:
327
+ - For thinking mode (`enable_thinking=True`), use `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0`. **DO NOT use greedy decoding**, as it can lead to performance degradation and endless repetitions.
328
+ - For non-thinking mode (`enable_thinking=False`), we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`.
329
+ - 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.
330
+
331
+ 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 38,912 tokens. This provides the model with sufficient space to generate detailed and comprehensive responses, thereby enhancing its overall performance.
332
+
333
+ 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
334
+ - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
335
+ - **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"`."
336
+
337
+ 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.
338
+
339
+ ### Citation
340
+
341
+ If you find our work helpful, feel free to give us a cite.
342
+
343
+ ```
344
+ @misc{qwen3technicalreport,
345
+ title={Qwen3 Technical Report},
346
+ author={Qwen Team},
347
+ year={2025},
348
+ eprint={2505.09388},
349
+ archivePrefix={arXiv},
350
+ primaryClass={cs.CL},
351
+ url={https://arxiv.org/abs/2505.09388},
352
+ }
353
+ ```
config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3MoeForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "decoder_sparse_step": 1,
9
+ "eos_token_id": 151645,
10
+ "head_dim": 128,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 4096,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 12288,
15
+ "max_position_embeddings": 40960,
16
+ "max_window_layers": 94,
17
+ "mlp_only_layers": [],
18
+ "model_type": "qwen3_moe",
19
+ "moe_intermediate_size": 1536,
20
+ "norm_topk_prob": true,
21
+ "num_attention_heads": 64,
22
+ "num_experts": 128,
23
+ "num_experts_per_tok": 8,
24
+ "num_hidden_layers": 94,
25
+ "num_key_value_heads": 4,
26
+ "output_router_logits": false,
27
+ "rms_norm_eps": 1e-06,
28
+ "rope_scaling": null,
29
+ "rope_theta": 1000000.0,
30
+ "router_aux_loss_coef": 0.001,
31
+ "sliding_window": null,
32
+ "tie_word_embeddings": false,
33
+ "torch_dtype": "bfloat16",
34
+ "transformers_version": "4.51.0",
35
+ "use_cache": true,
36
+ "use_sliding_window": false,
37
+ "vocab_size": 151936
38
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.6,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "4.51.0"
13
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-model-00001-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64b878133d805a7e5e9edf348768112627de266b18d553e942b57d7c9d032912
3
+ size 3993004560
model-model-00002-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:848277993a3ba04e8c3117c4811448d87aec22f38de370689f1f313297fdd0a9
3
+ size 3994081856
model-model-00003-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae032ddc9ca2221738fff28c88bb9dbd57cca52dd22d342125ba5b0083a47f14
3
+ size 3994081856
model-model-00004-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01e50c055b68f40206f0848f5396c700539ed1e1fb52a495a86820898bffa098
3
+ size 3988822448
model-model-00005-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4e9bff50ab828ffffcc414d1626b285ec4af5985321b912cad6dd9f14ab5442
3
+ size 3994081784
model-model-00006-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3faeb1f3ae0db90e58bff868606f4b89211bf1943b6b522d6349ad37525e97a
3
+ size 3994081856
model-model-00007-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f0e12a6d0fa1830f7b8fff20d6c887d528a36ef8612d3ed2215c49d31a117b4
3
+ size 3994081856
model-model-00008-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d94579c2c8f75d34d872d699a8c03c6903b3d3e47877310c8aa5e0f9affee951
3
+ size 3994081856
model-model-00009-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2bb7ed011f6aeeaa9eb1f0af406ad39e4f4eb02b394b69fed84444d7f40d57d2
3
+ size 3988822456
model-model-00010-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e10f37e03ad77419cc965a26294418c53e534afc32714e16041920f450979cdc
3
+ size 3994081784
model-model-00011-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16bc43521df6e6ce96537980881518857b40cf667841f4ea7022b083e7a10e35
3
+ size 3994081856
model-model-00012-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb82fe4d6ba5766b135dfad6be05eaae9a5c7a8dcfc4ed91c429e4bb627a164f
3
+ size 3994081856
model-model-00013-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28c08554704b51a920bc940c159b721de02bb90034a1dbd93a7fef0a2b4be4e7
3
+ size 3994081944
model-model-00014-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bf3ea0ab14f45e1debdbdf43632c8d9d06e7959d22f3acf2fb20e46f56cec8c2
3
+ size 3988822776
model-model-00015-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c260cc200f2bca73fc1a95f4e76ae2b0f1365a80189033cbbd380491d6f6e53
3
+ size 3994082088
model-model-00016-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:561c67d29f46d9369dae38dbaf6eb3a803f14f8ccb7371a6141285420d554672
3
+ size 3994082176
model-model-00017-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f0944f94f93dcc01945cd5eb16eea83e71f342741b109fd9965e1ee7c2973c2
3
+ size 3994082176
model-model-00018-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fedee8a9c87cadab654d70c7bf457545ea837d193c1718ddda1d2661884cd91
3
+ size 3994082176
model-model-00019-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc8d7127bcdcfc8f951aace4980ed30cdeb8d473b83a88d43ed7ae6440e48517
3
+ size 3988822776
model-model-00020-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:671a8e521b34c148e597fcbadf1b86ac626a91cd9a558461471a5452e00ace56
3
+ size 3994082088
model-model-00021-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5772464f617f8a9d2ba94ceeb91cb64d783e2c9b30d8fc64c1f6896404050489
3
+ size 3994082168
model-model-00022-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:692e6c4c5de445fd949336a2fe0c90d8578a7921c3ffdcd95e90721de4e573c2
3
+ size 3994082176
model-model-00023-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:691cecc2d1ca2f87062f20745cdc1248a4cf5a4d5ec78bcd29c044dd9cee730a
3
+ size 3994082176
model-model-00024-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9472bfad29a43aa465b130455941c4635cb37351c2b89f7848b59f2ac01d18f
3
+ size 3938507240
model-model-00025-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fae0b9a1c7fb05f68176f0f7d733d982cf28413b009e244aa94d017bc501c1b2
3
+ size 3994065488
model-model-00026-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cc8ecb9e247200beba7301b09979734019b110758bb99b004874243c4347f77
3
+ size 3994082168
model-model-00027-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88af2b728602fb3dbfc8d9761c2890099cd107b0766db2633d33238d9e75fff6
3
+ size 3994082176
model-model-00028-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:326b4d2d3fdbdfbaeee78bf1e2b075a73dba3889dda4bb1f2992292ac740bbff
3
+ size 3994082176
model-model-00029-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d6954add66f831dc33e9272b65af886e9013efe9957db482081a34effd9b26f
3
+ size 3997227600
model-model-00030-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:76965baa26ac5a681ee7a283c4a26c073aa35223741822a24a78b34be3128249
3
+ size 3998260320
model-model-00031-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df8d51c6568e502cc2214ef4404863386340e2ea703e1f9e090293427d350753
3
+ size 3994082160
model-model-00032-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a533b561b77b363625b221274a5a8004ce55ae848acac00e88cb741ae18e4b06
3
+ size 3994082176
model-model-00033-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:191f87ed4b9aaf559ade38986e8deca976c7761ac61a280feefbed5c945b9f05
3
+ size 3994082176
model-model-00034-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f75bf1281c9d3c04c95cc999dca333fe5642e2ccd37fd0580ecf145542fabdb
3
+ size 3994082200
model-model-00035-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99135fba4bd118ddd76ae498e7140d7f981988ff8b2640c9927bfb8f79b519b5
3
+ size 3988822680
model-model-00036-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91ef5d8f7642fbf9526dea2d90dd1e86a7d53764028f1e08883d12761a2a367d
3
+ size 3994082152
model-model-00037-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce6cdcda7776b429a67ed1a36e6573dd9113d2ecbd40ab34473a655e9aba55e1
3
+ size 3994082176
model-model-00038-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb3e7943249a55731db5504e6c39ee97a721173765ea8db4aeaf194f6b827d94
3
+ size 3994082176
model-model-00039-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8e634cdd2e5d8b8b9b235403e2a2844224599aeab0d5e6fbbfb03de8d414916
3
+ size 3994082200
model-model-00040-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f153090a88563cee77aacf41af46ff5a753b8f7c1bb982e548188e46a9541bc
3
+ size 3988822696
model-model-00041-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f5d7145bb946b31e0d8bcb05a8df27f9da040f776407d54c2ee750915340c2b
3
+ size 3994082152
model-model-00042-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e4fccb0b7eb470f926ef0cf1c81aa453ddaa7322771ee1bb34d6923ebc947cf2
3
+ size 3994082176
model-model-00043-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa71a87f3d6a6245e7c38a6c32796140b104924c7ae9b6a1b8d1431904de01e6
3
+ size 3994082176
model-model-00044-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a2b43e25e391a7a2fb7c69faf67618e577e55ab65fa2f937681f305f58d0642
3
+ size 3994082192
model-model-00045-of-00118.safetensors-of-00118.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90d13e908e6009df37db86be76819921413915183dfd884695d525cf6204d34c
3
+ size 3988822704