Jacqkues commited on
Commit
f2fe4ea
·
verified ·
1 Parent(s): 4bfd9aa

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +322 -190
README.md CHANGED
@@ -1,199 +1,331 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
4
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # Model Card for Model ID
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
 
 
 
 
 
 
 
 
 
 
9
 
 
 
10
 
 
 
 
11
 
12
- ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ license: apache-2.0
4
+ license_link: https://huggingface.co/Qwen/Qwen3-0.6B/blob/main/LICENSE
5
+ pipeline_tag: text-generation
6
+ base_model:
7
+ - Qwen/Qwen3-0.6B-Base
8
+ tags:
9
+ - heretic
10
+ - uncensored
11
+ - decensored
12
+ - abliterated
13
  ---
14
+ # This is a decensored version of [Qwen/Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B), made using [Heretic](https://github.com/p-e-w/heretic) v1.1.0
15
+
16
+ ## Abliteration parameters
17
+
18
+ | Parameter | Value |
19
+ | :-------- | :---: |
20
+ | **direction_index** | 18.08 |
21
+ | **attn.o_proj.max_weight** | 1.11 |
22
+ | **attn.o_proj.max_weight_position** | 19.07 |
23
+ | **attn.o_proj.min_weight** | 0.29 |
24
+ | **attn.o_proj.min_weight_distance** | 14.25 |
25
+ | **mlp.down_proj.max_weight** | 1.27 |
26
+ | **mlp.down_proj.max_weight_position** | 17.47 |
27
+ | **mlp.down_proj.min_weight** | 1.22 |
28
+ | **mlp.down_proj.min_weight_distance** | 15.54 |
29
+
30
+ ## Performance
31
+
32
+ | Metric | This model | Original model ([Qwen/Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B)) |
33
+ | :----- | :--------: | :---------------------------: |
34
+ | **KL divergence** | 0.0015 | 0 *(by definition)* |
35
+ | **Refusals** | 6/100 | 55/100 |
36
+
37
+ -----
38
+
39
+
40
+ # Qwen3-0.6B
41
+ <a href="https://chat.qwen.ai/" target="_blank" style="margin: 2px;">
42
+ <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;"/>
43
+ </a>
44
+
45
+ ## Qwen3 Highlights
46
+
47
+ 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:
48
+
49
+ - **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.
50
+ - **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.
51
+ - **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.
52
+ - **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.
53
+ - **Support of 100+ languages and dialects** with strong capabilities for **multilingual instruction following** and **translation**.
54
+
55
+ ## Model Overview
56
+
57
+ **Qwen3-0.6B** has the following features:
58
+ - Type: Causal Language Models
59
+ - Training Stage: Pretraining & Post-training
60
+ - Number of Parameters: 0.6B
61
+ - Number of Paramaters (Non-Embedding): 0.44B
62
+ - Number of Layers: 28
63
+ - Number of Attention Heads (GQA): 16 for Q and 8 for KV
64
+ - Context Length: 32,768
65
+
66
+ 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/).
67
+
68
+ > [!TIP]
69
+ > If you encounter significant endless repetitions, please refer to the [Best Practices](#best-practices) section for optimal sampling parameters, and set the ``presence_penalty`` to 1.5.
70
+
71
+ ## Quickstart
72
+
73
+ The code of Qwen3 has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
74
+
75
+ With `transformers<4.51.0`, you will encounter the following error:
76
+ ```
77
+ KeyError: 'qwen3'
78
+ ```
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
+
84
+ model_name = "Qwen/Qwen3-0.6B"
85
+
86
+ # load the tokenizer and the model
87
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
88
+ model = AutoModelForCausalLM.from_pretrained(
89
+ model_name,
90
+ torch_dtype="auto",
91
+ device_map="auto"
92
+ )
93
 
94
+ # prepare the model input
95
+ prompt = "Give me a short introduction to large language model."
96
+ messages = [
97
+ {"role": "user", "content": prompt}
98
+ ]
99
+ text = tokenizer.apply_chat_template(
100
+ messages,
101
+ tokenize=False,
102
+ add_generation_prompt=True,
103
+ enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
104
+ )
105
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
106
 
107
+ # conduct text completion
108
+ generated_ids = model.generate(
109
+ **model_inputs,
110
+ max_new_tokens=32768
111
+ )
112
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
113
+
114
+ # parsing thinking content
115
+ try:
116
+ # rindex finding 151668 (</think>)
117
+ index = len(output_ids) - output_ids[::-1].index(151668)
118
+ except ValueError:
119
+ index = 0
120
 
121
+ thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
122
+ content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
123
 
124
+ print("thinking content:", thinking_content)
125
+ print("content:", content)
126
+ ```
127
 
128
+ For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
129
+ - SGLang:
130
+ ```shell
131
+ python -m sglang.launch_server --model-path Qwen/Qwen3-0.6B --reasoning-parser qwen3
132
+ ```
133
+ - vLLM:
134
+ ```shell
135
+ vllm serve Qwen/Qwen3-0.6B --enable-reasoning --reasoning-parser deepseek_r1
136
+ ```
137
+
138
+ For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
139
+
140
+ ## Switching Between Thinking and Non-Thinking Mode
141
+
142
+ > [!TIP]
143
+ > The `enable_thinking` switch is also available in APIs created by SGLang and vLLM.
144
+ > 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.
145
+
146
+ ### `enable_thinking=True`
147
+
148
+ 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.
149
+
150
+ ```python
151
+ text = tokenizer.apply_chat_template(
152
+ messages,
153
+ tokenize=False,
154
+ add_generation_prompt=True,
155
+ enable_thinking=True # True is the default value for enable_thinking
156
+ )
157
+ ```
158
+
159
+ In this mode, the model will generate think content wrapped in a `<think>...</think>` block, followed by the final response.
160
+
161
+ > [!NOTE]
162
+ > 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.
163
+
164
+
165
+ ### `enable_thinking=False`
166
+
167
+ 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.
168
+
169
+ ```python
170
+ text = tokenizer.apply_chat_template(
171
+ messages,
172
+ tokenize=False,
173
+ add_generation_prompt=True,
174
+ enable_thinking=False # Setting enable_thinking=False disables thinking mode
175
+ )
176
+ ```
177
+
178
+ In this mode, the model will not generate any think content and will not include a `<think>...</think>` block.
179
+
180
+ > [!NOTE]
181
+ > 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.
182
+
183
+ ### Advanced Usage: Switching Between Thinking and Non-Thinking Modes via User Input
184
+
185
+ 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.
186
+
187
+ Here is an example of a multi-turn conversation:
188
+
189
+ ```python
190
+ from transformers import AutoModelForCausalLM, AutoTokenizer
191
+
192
+ class QwenChatbot:
193
+ def __init__(self, model_name="Qwen/Qwen3-0.6B"):
194
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name)
195
+ self.model = AutoModelForCausalLM.from_pretrained(model_name)
196
+ self.history = []
197
+
198
+ def generate_response(self, user_input):
199
+ messages = self.history + [{"role": "user", "content": user_input}]
200
+
201
+ text = self.tokenizer.apply_chat_template(
202
+ messages,
203
+ tokenize=False,
204
+ add_generation_prompt=True
205
+ )
206
+
207
+ inputs = self.tokenizer(text, return_tensors="pt")
208
+ response_ids = self.model.generate(**inputs, max_new_tokens=32768)[0][len(inputs.input_ids[0]):].tolist()
209
+ response = self.tokenizer.decode(response_ids, skip_special_tokens=True)
210
+
211
+ # Update history
212
+ self.history.append({"role": "user", "content": user_input})
213
+ self.history.append({"role": "assistant", "content": response})
214
+
215
+ return response
216
+
217
+ # Example Usage
218
+ if __name__ == "__main__":
219
+ chatbot = QwenChatbot()
220
 
221
+ # First input (without /think or /no_think tags, thinking mode is enabled by default)
222
+ user_input_1 = "How many r's in strawberries?"
223
+ print(f"User: {user_input_1}")
224
+ response_1 = chatbot.generate_response(user_input_1)
225
+ print(f"Bot: {response_1}")
226
+ print("----------------------")
227
+
228
+ # Second input with /no_think
229
+ user_input_2 = "Then, how many r's in blueberries? /no_think"
230
+ print(f"User: {user_input_2}")
231
+ response_2 = chatbot.generate_response(user_input_2)
232
+ print(f"Bot: {response_2}")
233
+ print("----------------------")
234
+
235
+ # Third input with /think
236
+ user_input_3 = "Really? /think"
237
+ print(f"User: {user_input_3}")
238
+ response_3 = chatbot.generate_response(user_input_3)
239
+ print(f"Bot: {response_3}")
240
+ ```
241
+
242
+ > [!NOTE]
243
+ > 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.
244
+ > 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.
245
+
246
+ ## Agentic Use
247
+
248
+ 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.
249
+
250
+ 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.
251
+ ```python
252
+ from qwen_agent.agents import Assistant
253
+
254
+ # Define LLM
255
+ llm_cfg = {
256
+ 'model': 'Qwen3-0.6B',
257
+
258
+ # Use the endpoint provided by Alibaba Model Studio:
259
+ # 'model_type': 'qwen_dashscope',
260
+ # 'api_key': os.getenv('DASHSCOPE_API_KEY'),
261
+
262
+ # Use a custom endpoint compatible with OpenAI API:
263
+ 'model_server': 'http://localhost:8000/v1', # api_base
264
+ 'api_key': 'EMPTY',
265
+
266
+ # Other parameters:
267
+ # 'generate_cfg': {
268
+ # # Add: When the response content is `<think>this is the thought</think>this is the answer;
269
+ # # Do not add: When the response has been separated by reasoning_content and content.
270
+ # 'thought_in_content': True,
271
+ # },
272
+ }
273
+
274
+ # Define Tools
275
+ tools = [
276
+ {'mcpServers': { # You can specify the MCP configuration file
277
+ 'time': {
278
+ 'command': 'uvx',
279
+ 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
280
+ },
281
+ "fetch": {
282
+ "command": "uvx",
283
+ "args": ["mcp-server-fetch"]
284
+ }
285
+ }
286
+ },
287
+ 'code_interpreter', # Built-in tools
288
+ ]
289
+
290
+ # Define Agent
291
+ bot = Assistant(llm=llm_cfg, function_list=tools)
292
+
293
+ # Streaming generation
294
+ messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
295
+ for responses in bot.run(messages=messages):
296
+ pass
297
+ print(responses)
298
+ ```
299
+
300
+ ## Best Practices
301
+
302
+ To achieve optimal performance, we recommend the following settings:
303
+
304
+ 1. **Sampling Parameters**:
305
+ - 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.
306
+ - For non-thinking mode (`enable_thinking=False`), we suggest using `Temperature=0.7`, `TopP=0.8`, `TopK=20`, and `MinP=0`.
307
+ - 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.
308
+
309
+ 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.
310
+
311
+ 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
312
+ - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
313
+ - **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"`."
314
+
315
+ 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.
316
+
317
+ ### Citation
318
+
319
+ If you find our work helpful, feel free to give us a cite.
320
+
321
+ ```
322
+ @misc{qwen3technicalreport,
323
+ title={Qwen3 Technical Report},
324
+ author={Qwen Team},
325
+ year={2025},
326
+ eprint={2505.09388},
327
+ archivePrefix={arXiv},
328
+ primaryClass={cs.CL},
329
+ url={https://arxiv.org/abs/2505.09388},
330
+ }
331
+ ```