onieth commited on
Commit
3607ceb
·
verified ·
1 Parent(s): 450a925

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +183 -3
README.md CHANGED
@@ -1,3 +1,183 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: mit
4
+ license_link: https://huggingface.co/Qwen/Qwen3-4B-Thinking-2507/blob/main/LICENSE
5
+ pipeline_tag: text-generation
6
+ base_model: Qwen/Qwen3-4B-Thinking-2507
7
+ ---
8
+
9
+ # chemAi2025
10
+
11
+ Meet chemAi2025, a fine tuned chemistry model that was based on the **Qwen3-4B-Thinking-2507** model.
12
+
13
+ It was trained on a custom dataset consisting of scientific chemistry papers from archivex from january to july of 2025. The created dataset was merged and shuffled with camel-ai/chemistry dataset and used for LoRa training.
14
+
15
+ The aim with this model was to create a chemistry model that was trained on current data from 2025. Of course, it will be a few months out of date since data processing and dataset creation takes significant time as a solo developer.
16
+
17
+ > The following sections are either copied as they were from the **Qwen3-4B-Thinking-2507** page or slightly modified. I didn't want to make it seem like I just ripped them off.
18
+ ## Model Overview
19
+
20
+ **chemAi2025** has the same model features as **Qwen3-4B-Thinking-2507**. Which are:
21
+ - Type: Causal Language Models
22
+ - Training Stage: Pretraining & Post-training
23
+ - Number of Parameters: 4.0B
24
+ - Number of Paramaters (Non-Embedding): 3.6B
25
+ - Number of Layers: 36
26
+ - Number of Attention Heads (GQA): 32 for Q and 8 for KV
27
+ - Context Length: **262,144 natively**.
28
+
29
+ **NOTE: This model supports only thinking mode. Meanwhile, specifying `enable_thinking=True` is no longer required.**
30
+
31
+ 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.
32
+
33
+ ## Quickstart
34
+
35
+ The code of Qwen3 has been in the latest Hugging Face `transformers` and we advise you to use the latest version of `transformers`.
36
+
37
+ With `transformers<4.51.0`, you will encounter the following error:
38
+ ```
39
+ KeyError: 'qwen3'
40
+ ```
41
+
42
+ The following contains a code snippet illustrating how to use the model generate content based on given inputs.
43
+ ```python
44
+ from transformers import AutoModelForCausalLM, AutoTokenizer
45
+
46
+ model_name = "onieth/chemAI2025"
47
+
48
+ # load the tokenizer and the model
49
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
50
+ model = AutoModelForCausalLM.from_pretrained(
51
+ model_name,
52
+ torch_dtype="auto",
53
+ device_map="auto"
54
+ )
55
+
56
+ # prepare the model input
57
+ prompt = "Give me a short introduction to large language model."
58
+ messages = [
59
+ {"role": "user", "content": prompt}
60
+ ]
61
+ text = tokenizer.apply_chat_template(
62
+ messages,
63
+ tokenize=False,
64
+ add_generation_prompt=True,
65
+ )
66
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
67
+
68
+ # conduct text completion
69
+ generated_ids = model.generate(
70
+ **model_inputs,
71
+ max_new_tokens=32768
72
+ )
73
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
74
+
75
+ # parsing thinking content
76
+ try:
77
+ # rindex finding 151668 (</think>)
78
+ index = len(output_ids) - output_ids[::-1].index(151668)
79
+ except ValueError:
80
+ index = 0
81
+
82
+ thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
83
+ content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
84
+
85
+ print("thinking content:", thinking_content) # no opening <think> tag
86
+ print("content:", content)
87
+
88
+ ```
89
+
90
+ For deployment, you can use `sglang>=0.4.6.post1` or `vllm>=0.8.5` or to create an OpenAI-compatible API endpoint:
91
+ - SGLang:
92
+ ```shell
93
+ python -m sglang.launch_server --model-path onieth/chemAI2025 --context-length 262144 --reasoning-parser deepseek-r1
94
+ ```
95
+ - vLLM:
96
+ ```shell
97
+ vllm serve onieth/chemAI2025 --max-model-len 262144 --enable-reasoning --reasoning-parser deepseek_r1
98
+ ```
99
+
100
+ **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.**
101
+
102
+ For local use, applications such as Ollama, LMStudio, MLX-LM, llama.cpp, and KTransformers have also supported Qwen3.
103
+
104
+ ## Agentic Use
105
+
106
+ 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.
107
+
108
+ 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.
109
+ ```python
110
+ from qwen_agent.agents import Assistant
111
+
112
+ # Define LLM
113
+ # Using OpenAI-compatible API endpoint. It is recommended to disable the reasoning and the tool call parsing
114
+ # functionality of the deployment frameworks and let Qwen-Agent automate the related operations. For example,
115
+ # `VLLM_USE_MODELSCOPE=true vllm serve Qwen/Qwen3-4B-Thinking-2507 --served-model-name Qwen3-4B-Thinking-2507 --max-model-len 262144`.
116
+ llm_cfg = {
117
+ 'model': 'Qwen3-4B-Thinking-2507',
118
+
119
+ # Use a custom endpoint compatible with OpenAI API:
120
+ 'model_server': 'http://localhost:8000/v1', # api_base without reasoning and tool call parsing
121
+ 'api_key': 'EMPTY',
122
+ 'generate_cfg': {
123
+ 'thought_in_content': True,
124
+ },
125
+ }
126
+
127
+ # Define Tools
128
+ tools = [
129
+ {'mcpServers': { # You can specify the MCP configuration file
130
+ 'time': {
131
+ 'command': 'uvx',
132
+ 'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
133
+ },
134
+ "fetch": {
135
+ "command": "uvx",
136
+ "args": ["mcp-server-fetch"]
137
+ }
138
+ }
139
+ },
140
+ 'code_interpreter', # Built-in tools
141
+ ]
142
+
143
+ # Define Agent
144
+ bot = Assistant(llm=llm_cfg, function_list=tools)
145
+
146
+ # Streaming generation
147
+ messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
148
+ for responses in bot.run(messages=messages):
149
+ pass
150
+ print(responses)
151
+ ```
152
+
153
+ ## Best Practices
154
+
155
+ To achieve optimal performance, we recommend the following settings:
156
+
157
+ 1. **Sampling Parameters**:
158
+ - We suggest using `Temperature=0.6`, `TopP=0.95`, `TopK=20`, and `MinP=0`.
159
+ - 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.
160
+
161
+ 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.
162
+
163
+ 3. **Standardize Output Format**: We recommend using prompts to standardize model outputs when benchmarking.
164
+ - **Math Problems**: Include "Please reason step by step, and put your final answer within \boxed{}." in the prompt.
165
+ - **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"`."
166
+
167
+ 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.
168
+
169
+
170
+ ### Citation
171
+
172
+ If you use this model or find it helpful, please cite the original Qwen3 work:
173
+
174
+ ```bibtex
175
+ @misc{qwen3technicalreport,
176
+ title={Qwen3 Technical Report},
177
+ author={Qwen Team},
178
+ year={2025},
179
+ eprint={2505.09388},
180
+ archivePrefix={arXiv},
181
+ primaryClass={cs.CL},
182
+ url={https://arxiv.org/abs/2505.09388},
183
+ }