huihui-ai commited on
Commit
b9cdb37
·
verified ·
1 Parent(s): 89db899

Add files using upload-large-folder tool

Browse files
.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,414 +1,3 @@
1
- ---
2
- license: apache-2.0
3
- base_model:
4
- - Qwen/Qwen3-4B
5
- - enlo/Jan-nano
6
- - ValiantLabs/Qwen3-4B-Esper3
7
- - prithivMLmods/Crux-Qwen3_OpenThinking-4B
8
- - XformAI-india/Qwen3-4B-medicaldataset
9
- - Tesslate/UIGEN-T3-4B-Preview
10
- - radm/prophet-qwen3-4b-sft
11
- - NiuTrans/GRAM-Qwen3-4B-RewardModel
12
- library_name: transformers
13
- license_link: https://huggingface.co/Qwen/Qwen3-4B/blob/main/LICENSE
14
- pipeline_tag: text-generation
15
- tags:
16
- - moe
17
- ---
18
- # huihui-ai/Huihui-MoE-23B-A4B
19
-
20
- ## Model Overview
21
- Huihui-MoE-23B-A4B is a **Mixture of Experts (MoE)** language model developed by **huihui.ai**, built upon the **[Qwen/Qwen3-4B](https://huggingface.co/Qwen/Qwen3-4B)** base model. It enhances the standard Transformer architecture by replacing MLP layers with MoE layers, each containing 8 experts, to achieve high performance with efficient inference. The model is designed for natural language processing tasks, including text generation, question answering, and conversational applications.
22
-
23
- **Note**:
24
- The activated expert can handle numbers from 1 to 8, and can complete normal conversations as well.
25
- You can change the activation parameters using `/num_experts_per_tok <number>`. After modifying the parameters, the model will be reloaded.
26
-
27
- - **Architecture**: Qwen3MoeForCausalLM model with 8 experts per layer (num_experts=8), activating 1-8 expert per token (num_experts_per_tok=1-8).
28
- - **Total Parameters**: ~23 billion (23B)
29
- - **Activated Parameters**: ~42 billion (4B) during inference, comparable to Qwen3-4B
30
- - **Developer**: huihui.ai
31
- - **Release Date**: June 2025
32
- - **License**: Inherits the license of the Qwen3 base model (apache-2.0)
33
-
34
- ## Expert Models:
35
-
36
- ### Expert 1:
37
- [Menlo/Jan-nano](https://huggingface.co/Menlo/Jan-nano)
38
-
39
- ### Expert 2:
40
- [ValiantLabs/Qwen3-4B-Esper3](https://huggingface.co/ValiantLabs/Qwen3-4B-Esper3)
41
-
42
- ### Expert 3:
43
- [prithivMLmods/Crux-Qwen3_OpenThinking-4B](https://huggingface.co/prithivMLmods/Crux-Qwen3_OpenThinking-4B)
44
-
45
- ### Expert 4:
46
- [XformAI-india/Qwen3-4B-medicaldataset](https://huggingface.co/XformAI-india/Qwen3-4B-medicaldataset)
47
-
48
- ### Expert 5:
49
- [Tesslate/UIGEN-T3-4B-Preview](https://huggingface.co/Tesslate/UIGEN-T3-4B-Preview)
50
-
51
- ### Expert 6:
52
- [radm/prophet-qwen3-4b-sft](https://huggingface.co/radm/prophet-qwen3-4b-sft)
53
-
54
- ### Expert 7:
55
- [NiuTrans/GRAM-Qwen3-4B-RewardModel](https://huggingface.co/NiuTrans/GRAM-Qwen3-4B-RewardModel)
56
-
57
- ### Expert 8:
58
- [Qwen/Qwen3-4B](https://huggingface.co/Qwen/Qwen3-4B)
59
-
60
- ### Instruction Following:
61
- [Qwen/Qwen3-4B](https://huggingface.co/Qwen/Qwen3-4B)
62
-
63
- `Qwen/Qwen3-4B` model was directly used for this expert, no fine-tune was applied.
64
-
65
- ## Training
66
-
67
- - **Base Model**: Qwen3-4B, pre-trained by the Qwen team.
68
- - **Conversion**: The model copies embeddings, self-attention, and normalization weights from Qwen3-4B, replacing MLP layers with MoE layers (8 experts). Gating weights are randomly initialized.
69
- - **Fine-Tuning**: Not fine-tuned; users are recommended to fine-tune for specific tasks to optimize expert routing.
70
- ## ollama
71
-
72
- You can use [huihui_ai/huihui-moe:23b](https://ollama.com/huihui_ai/huihui-moe:23b) directly,
73
- Switch the thinking toggle using /set think and /set nothink
74
- ```
75
- ollama run huihui_ai/huihui-moe:23b
76
- ```
77
-
78
- ## Usage
79
-
80
- ```
81
- from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig, BitsAndBytesConfig, TextStreamer
82
- import torch
83
- import os
84
- import signal
85
- import random
86
- import numpy as np
87
- import time
88
- from collections import Counter
89
-
90
- cpu_count = os.cpu_count()
91
- print(f"Number of CPU cores in the system: {cpu_count}")
92
- half_cpu_count = cpu_count // 2
93
- os.environ["MKL_NUM_THREADS"] = str(half_cpu_count)
94
- os.environ["OMP_NUM_THREADS"] = str(half_cpu_count)
95
- torch.set_num_threads(half_cpu_count)
96
-
97
- print(f"PyTorch threads: {torch.get_num_threads()}")
98
- print(f"MKL threads: {os.getenv('MKL_NUM_THREADS')}")
99
- print(f"OMP threads: {os.getenv('OMP_NUM_THREADS')}")
100
-
101
- # Load the model and tokenizer
102
- NEW_MODEL_ID = "huihui-ai/Huihui-MoE-23B-A4B"
103
- print(f"Load Model {NEW_MODEL_ID} ... ")
104
- quant_config_4 = BitsAndBytesConfig(
105
- load_in_4bit=True,
106
- bnb_4bit_compute_dtype=torch.bfloat16,
107
- bnb_4bit_use_double_quant=True,
108
- llm_int8_enable_fp32_cpu_offload=True,
109
- )
110
-
111
- config = AutoConfig.from_pretrained(
112
- NEW_MODEL_ID,
113
- trust_remote_code=True
114
- )
115
-
116
- config.num_experts_per_tok = 1
117
- print(f"num_experts_per_tok: {config.num_experts_per_tok}")
118
-
119
- model = AutoModelForCausalLM.from_pretrained(
120
- NEW_MODEL_ID,
121
- config=config,
122
- device_map="auto",
123
- trust_remote_code=True,
124
- quantization_config=quant_config_4,
125
- torch_dtype=torch.bfloat16
126
- )
127
- #print(model.config)
128
- tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True)
129
- if tokenizer.pad_token is None:
130
- tokenizer.pad_token = tokenizer.eos_token
131
- tokenizer.pad_token_id = tokenizer.eos_token_id
132
-
133
- tokenizer = AutoTokenizer.from_pretrained(NEW_MODEL_ID, trust_remote_code=True)
134
- if tokenizer.pad_token is None:
135
- tokenizer.pad_token = tokenizer.eos_token
136
- tokenizer.pad_token_id = tokenizer.eos_token_id
137
-
138
- messages = []
139
- nothink = False
140
- same_seed = False
141
- skip_prompt=True
142
- skip_special_tokens=True
143
- do_sample = True
144
-
145
- def set_random_seed(seed=None):
146
- """Set random seed for reproducibility. If seed is None, use int(time.time())."""
147
- if seed is None:
148
- seed = int(time.time()) # Convert float to int
149
- random.seed(seed)
150
- np.random.seed(seed)
151
- torch.manual_seed(seed)
152
- torch.cuda.manual_seed_all(seed) # If using CUDA
153
- torch.backends.cudnn.deterministic = True
154
- torch.backends.cudnn.benchmark = False
155
- return seed # Return seed for logging if needed
156
-
157
- class CustomTextStreamer(TextStreamer):
158
- def __init__(self, tokenizer, skip_prompt=True, skip_special_tokens=True):
159
- super().__init__(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
160
- self.generated_text = ""
161
- self.stop_flag = False
162
- self.init_time = time.time() # Record initialization time
163
- self.end_time = None # To store end time
164
- self.first_token_time = None # To store first token generation time
165
- self.token_count = 0 # To track total tokens
166
-
167
- def on_finalized_text(self, text: str, stream_end: bool = False):
168
- if self.first_token_time is None and text.strip(): # Set first token time on first non-empty text
169
- self.first_token_time = time.time()
170
- self.generated_text += text
171
- # Count tokens in the generated text
172
- tokens = self.tokenizer.encode(text, add_special_tokens=False)
173
- self.token_count += len(tokens)
174
- print(text, end="", flush=True)
175
- if stream_end:
176
- self.end_time = time.time() # Record end time when streaming ends
177
- if self.stop_flag:
178
- raise StopIteration
179
-
180
- def stop_generation(self):
181
- self.stop_flag = True
182
- self.end_time = time.time() # Record end time when generation is stopped
183
-
184
- def get_metrics(self):
185
- """Returns initialization time, first token time, first token latency, end time, total time, total tokens, and tokens per second."""
186
- if self.end_time is None:
187
- self.end_time = time.time() # Set end time if not already set
188
- total_time = self.end_time - self.init_time # Total time from init to end
189
- tokens_per_second = self.token_count / total_time if total_time > 0 else 0
190
- first_token_latency = (self.first_token_time - self.init_time) if self.first_token_time is not None else None
191
- metrics = {
192
- "init_time": self.init_time,
193
- "first_token_time": self.first_token_time,
194
- "first_token_latency": first_token_latency,
195
- "end_time": self.end_time,
196
- "total_time": total_time, # Total time in seconds
197
- "total_tokens": self.token_count,
198
- "tokens_per_second": tokens_per_second
199
- }
200
- return metrics
201
-
202
- def generate_stream(model, tokenizer, messages, nothink, skip_prompt, skip_special_tokens, do_sample, max_new_tokens):
203
- input_ids = tokenizer.apply_chat_template(
204
- messages,
205
- tokenize=True,
206
- enable_thinking = not nothink,
207
- add_generation_prompt=True,
208
- return_tensors="pt"
209
- )
210
- attention_mask = torch.ones_like(input_ids, dtype=torch.long)
211
- tokens = input_ids.to(model.device)
212
- attention_mask = attention_mask.to(model.device)
213
-
214
- streamer = CustomTextStreamer(tokenizer, skip_prompt=skip_prompt, skip_special_tokens=skip_special_tokens)
215
-
216
- def signal_handler(sig, frame):
217
- streamer.stop_generation()
218
- print("\n[Generation stopped by user with Ctrl+C]")
219
-
220
- signal.signal(signal.SIGINT, signal_handler)
221
-
222
- generate_kwargs = {}
223
- if do_sample:
224
- generate_kwargs = {
225
- "do_sample": do_sample,
226
- "max_length": max_new_tokens,
227
- "temperature": 0.6,
228
- "top_k": 20,
229
- "top_p": 0.95,
230
- "repetition_penalty": 1.2,
231
- "no_repeat_ngram_size": 2
232
- }
233
- else:
234
- generate_kwargs = {
235
- "do_sample": do_sample,
236
- "max_length": max_new_tokens,
237
- "repetition_penalty": 1.2,
238
- "no_repeat_ngram_size": 2
239
- }
240
-
241
-
242
- print("Response: ", end="", flush=True)
243
- try:
244
- generated_ids = model.generate(
245
- tokens,
246
- attention_mask=attention_mask,
247
- #use_cache=False,
248
- pad_token_id=tokenizer.pad_token_id,
249
- streamer=streamer,
250
- **generate_kwargs
251
- )
252
- del generated_ids
253
- except StopIteration:
254
- print("\n[Stopped by user]")
255
-
256
- del input_ids, attention_mask
257
- torch.cuda.empty_cache()
258
- signal.signal(signal.SIGINT, signal.SIG_DFL)
259
-
260
- return streamer.generated_text, streamer.stop_flag, streamer.get_metrics()
261
-
262
- init_seed = set_random_seed()
263
-
264
- activated_experts = []
265
-
266
- # Define hook function to capture gate_probs output
267
- def hook_fn(module, input, output):
268
- # output is gate_probs, shape: [batch_size, sequence_length, num_experts]
269
- gate_probs = output
270
- # Compute top-1 expert indices (since only one expert is activated)
271
- _, topk_indices = gate_probs.topk(config.num_experts_per_tok, dim=-1) # Take top-1
272
- # Flatten and store activated expert indices
273
- activated_experts.extend(topk_indices.squeeze(-1).view(-1).cpu().tolist())
274
-
275
- hooks = []
276
- for layer in model.model.layers:
277
- hooks.append(layer.mlp.gate.register_forward_hook(hook_fn))
278
-
279
-
280
- while True:
281
- # List to store activated expert indices
282
- activated_experts = []
283
-
284
- if same_seed:
285
- set_random_seed(init_seed)
286
- else:
287
- init_seed = set_random_seed()
288
-
289
- print(f"\nnothink: {nothink}")
290
- print(f"skip_prompt: {skip_prompt}")
291
- print(f"skip_special_tokens: {skip_special_tokens}")
292
- print(f"do_sample: {do_sample}")
293
- print(f"same_seed: {same_seed}, {init_seed}\n")
294
-
295
- user_input = input("User: ").strip()
296
- if user_input.lower() == "/exit":
297
- print("Exiting chat.")
298
- break
299
- if user_input.lower() == "/clear":
300
- messages = []
301
- print("Chat history cleared. Starting a new conversation.")
302
- continue
303
- if user_input.lower() == "/nothink":
304
- nothink = not nothink
305
- continue
306
- if user_input.lower() == "/skip_prompt":
307
- skip_prompt = not skip_prompt
308
- continue
309
- if user_input.lower() == "/skip_special_tokens":
310
- skip_special_tokens = not skip_special_tokens
311
- continue
312
- if user_input.lower().startswith("/same_seed"):
313
- parts = user_input.split()
314
- if len(parts) == 1: # /same_seed (no number)
315
- same_seed = not same_seed # Toggle switch
316
- elif len(parts) == 2: # /same_seed <number>
317
- try:
318
- init_seed = int(parts[1]) # Extract and convert number to int
319
- same_seed = True
320
- except ValueError:
321
- print("Error: Please provide a valid integer after /same_seed")
322
- continue
323
- if user_input.lower().startswith("/num_experts_per_tok"):
324
- parts = user_input.split()
325
- if len(parts) == 1: # /num_experts_per_tok (no number)
326
- config.num_experts_per_tok = 1 # set default 1
327
- elif len(parts) == 2: # /num_experts_per_tok
328
- try:
329
- num_experts_per_tok = int(parts[1]) # Extract and convert number to int
330
- if num_experts_per_tok < 0 or num_experts_per_tok > 8:
331
- num_experts_per_tok = 1
332
- config.num_experts_per_tok = num_experts_per_tok
333
- print(f"num_experts_per_tok: {config.num_experts_per_tok}")
334
-
335
- # Remove all hooks after inference
336
- for h in hooks: h.remove()
337
- del model
338
-
339
- model = AutoModelForCausalLM.from_pretrained(
340
- NEW_MODEL_ID,
341
- config=config,
342
- device_map="auto",
343
- trust_remote_code=True,
344
- quantization_config=quant_config_4,
345
- torch_dtype=torch.bfloat16
346
- )
347
- hooks = []
348
- for layer in model.model.layers:
349
- hooks.append(layer.mlp.gate.register_forward_hook(hook_fn))
350
-
351
- except ValueError:
352
- print("Error: Please provide a valid integer after /same_seed")
353
- continue
354
- if user_input.lower() == "/do_sample":
355
- do_sample = not do_sample
356
- continue
357
- if not user_input:
358
- print("Input cannot be empty. Please enter something.")
359
- continue
360
-
361
-
362
- messages.append({"role": "user", "content": user_input})
363
- activated_experts = []
364
- response, stop_flag, metrics = generate_stream(model, tokenizer, messages, nothink, skip_prompt, skip_special_tokens, do_sample, 40960)
365
- print("\n\nMetrics:")
366
- for key, value in metrics.items():
367
- print(f" {key}: {value}")
368
-
369
- # Count the frequency of each activated expert
370
- expert_counts = Counter(activated_experts)
371
-
372
- # Print activation statistics
373
- print("\nActivated Expert Statistics:")
374
- for expert_idx, count in sorted(expert_counts.items()):
375
- print(f"Expert {expert_idx}: {count} times")
376
-
377
- print("", flush=True)
378
- if stop_flag:
379
- continue
380
- messages.append({"role": "assistant", "content": response})
381
-
382
- # Remove all hooks after inference
383
- for h in hooks: h.remove()
384
- ```
385
-
386
- ## Applications
387
-
388
- - **Text Generation: Articles**, dialogues, and creative writing.
389
- - **Question Answering**: Information retrieval and query resolution.
390
- - **Conversational AI**: Multi-turn dialogues for chatbots.
391
- - **Research**: Exploration of MoE architectures and efficient model scaling.
392
-
393
- ## Limitations
394
-
395
- - **Fine-Tuning Required**: Randomly initialized gating weights may lead to suboptimal expert utilization without fine-tuning.
396
- - **Compatibility**: Developed with transformers 4.52.4; ensure matching versions to avoid loading issues.
397
- - **Inference Speed**: While efficient for an MoE model, performance depends on hardware (GPU recommended).
398
-
399
- ## Ethical Considerations
400
-
401
- - **Bias**: Inherits potential biases from the Qwen3-4B base model; users should evaluate outputs for fairness.
402
- - **Usage**: Intended for research and responsible applications; avoid generating harmful or misleading content.
403
-
404
- ## Contact
405
-
406
- - **Developer**: huihui.ai
407
- - **Repository**: huihui-ai/Huihui-MoE-23B-A4B (available locally or on Hugging Face)
408
- - **Issues**: Report bugs or request features via the repository or please send an email to [email protected]
409
-
410
- ## Acknowledgments
411
-
412
- - Built upon the Qwen3-4B model by the Qwen team.
413
- - Built upon the Experts model by the Suayptalha team.
414
- - Powered by the Hugging Face transformers library.
 
1
+ ---
2
+ license: mit
3
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
added_tokens.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 151668,
3
+ "</tool_call>": 151658,
4
+ "</tool_response>": 151666,
5
+ "<think>": 151667,
6
+ "<tool_call>": 151657,
7
+ "<tool_response>": 151665,
8
+ "<|box_end|>": 151649,
9
+ "<|box_start|>": 151648,
10
+ "<|endoftext|>": 151643,
11
+ "<|file_sep|>": 151664,
12
+ "<|fim_middle|>": 151660,
13
+ "<|fim_pad|>": 151662,
14
+ "<|fim_prefix|>": 151659,
15
+ "<|fim_suffix|>": 151661,
16
+ "<|im_end|>": 151645,
17
+ "<|im_start|>": 151644,
18
+ "<|image_pad|>": 151655,
19
+ "<|object_ref_end|>": 151647,
20
+ "<|object_ref_start|>": 151646,
21
+ "<|quad_end|>": 151651,
22
+ "<|quad_start|>": 151650,
23
+ "<|repo_name|>": 151663,
24
+ "<|video_pad|>": 151656,
25
+ "<|vision_end|>": 151653,
26
+ "<|vision_pad|>": 151654,
27
+ "<|vision_start|>": 151652
28
+ }
chat_template.jinja ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
+ {%- for message in messages[::-1] %}
19
+ {%- set index = (messages|length - 1) - loop.index0 %}
20
+ {%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
21
+ {%- set ns.multi_step_tool = false %}
22
+ {%- set ns.last_query_index = index %}
23
+ {%- endif %}
24
+ {%- endfor %}
25
+ {%- for message in messages %}
26
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
27
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
28
+ {%- elif message.role == "assistant" %}
29
+ {%- set content = message.content %}
30
+ {%- set reasoning_content = '' %}
31
+ {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
32
+ {%- set reasoning_content = message.reasoning_content %}
33
+ {%- else %}
34
+ {%- if '</think>' in message.content %}
35
+ {%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
36
+ {%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
37
+ {%- endif %}
38
+ {%- endif %}
39
+ {%- if loop.index0 > ns.last_query_index %}
40
+ {%- if loop.last or (not loop.last and reasoning_content) %}
41
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
42
+ {%- else %}
43
+ {{- '<|im_start|>' + message.role + '\n' + content }}
44
+ {%- endif %}
45
+ {%- else %}
46
+ {{- '<|im_start|>' + message.role + '\n' + content }}
47
+ {%- endif %}
48
+ {%- if message.tool_calls %}
49
+ {%- for tool_call in message.tool_calls %}
50
+ {%- if (loop.first and content) or (not loop.first) %}
51
+ {{- '\n' }}
52
+ {%- endif %}
53
+ {%- if tool_call.function %}
54
+ {%- set tool_call = tool_call.function %}
55
+ {%- endif %}
56
+ {{- '<tool_call>\n{"name": "' }}
57
+ {{- tool_call.name }}
58
+ {{- '", "arguments": ' }}
59
+ {%- if tool_call.arguments is string %}
60
+ {{- tool_call.arguments }}
61
+ {%- else %}
62
+ {{- tool_call.arguments | tojson }}
63
+ {%- endif %}
64
+ {{- '}\n</tool_call>' }}
65
+ {%- endfor %}
66
+ {%- endif %}
67
+ {{- '<|im_end|>\n' }}
68
+ {%- elif message.role == "tool" %}
69
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
70
+ {{- '<|im_start|>user' }}
71
+ {%- endif %}
72
+ {{- '\n<tool_response>\n' }}
73
+ {{- message.content }}
74
+ {{- '\n</tool_response>' }}
75
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
76
+ {{- '<|im_end|>\n' }}
77
+ {%- endif %}
78
+ {%- endif %}
79
+ {%- endfor %}
80
+ {%- if add_generation_prompt %}
81
+ {{- '<|im_start|>assistant\n' }}
82
+ {%- if enable_thinking is defined and enable_thinking is false %}
83
+ {{- '<think>\n\n</think>\n\n' }}
84
+ {%- endif %}
85
+ {%- endif %}
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": 2560,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 9728,
15
+ "max_position_embeddings": 40960,
16
+ "max_window_layers": 36,
17
+ "mlp_only_layers": [],
18
+ "model_type": "qwen3_moe",
19
+ "moe_intermediate_size": 9728,
20
+ "norm_topk_prob": true,
21
+ "num_attention_heads": 32,
22
+ "num_experts": 8,
23
+ "num_experts_per_tok": 1,
24
+ "num_hidden_layers": 36,
25
+ "num_key_value_heads": 8,
26
+ "output_router_logits": false,
27
+ "rms_norm_eps": 1e-06,
28
+ "rope_scaling": null,
29
+ "rope_theta": 1000000,
30
+ "router_aux_loss_coef": 0.001,
31
+ "sliding_window": null,
32
+ "tie_word_embeddings": false,
33
+ "torch_dtype": "bfloat16",
34
+ "transformers_version": "4.52.4",
35
+ "use_cache": true,
36
+ "use_sliding_window": false,
37
+ "vocab_size": 151936
38
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 151643,
4
+ "eos_token_id": 151645,
5
+ "transformers_version": "4.52.4"
6
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:108558a87411ffdf04ee2ae00f589e40c0264a287a5bf627394e0be55db8fb97
3
+ size 4972426800
model-00002-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:82d2f7305d4bcdeb481b89bbc07991ea8121ff8f9f63b07992a76aec6ac6fae2
3
+ size 4991444528
model-00003-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3e689f6cc9d214d357503857dd4c6973ba93a94122327e8aed1f2327041e5ef
3
+ size 4991444584
model-00004-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f4060dcb05cd9f3c30e928c2ec694fef66c7430db4cbd0759418316b3283237
3
+ size 4991444664
model-00005-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7579e21c2eaabe9abe22fe8136098e9c6cab3d18203ad1104daedf009924310
3
+ size 4991444664
model-00006-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab9f89892b62d88d364ae1fb342ff388c290c75724d87ce251aac59ff70fd82b
3
+ size 4991444664
model-00007-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b1e10317fc026397ee661e4fe83237a0d2ef8ec36731594b107c547eeff1549
3
+ size 4991444664
model-00008-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5835dc2c682d66f48d79b071ec356e253bd85da595a3b37742284ded47d85b7f
3
+ size 4991444664
model-00009-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e944a16a6a4af030af8622f4e21205d8166baa0f6b28e465d2d83c157bc224e2
3
+ size 4991444664
model-00010-of-00010.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02654f8a8de6074a0666d4ccc634ec208e997a56a7f016baf3696658f703b4a5
3
+ size 1574847872
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
3
+ size 11422654
tokenizer_config.json ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ }
213
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|vision_start|>",
224
+ "<|vision_end|>",
225
+ "<|vision_pad|>",
226
+ "<|image_pad|>",
227
+ "<|video_pad|>"
228
+ ],
229
+ "bos_token": null,
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|im_end|>",
232
+ "errors": "replace",
233
+ "extra_special_tokens": {},
234
+ "model_max_length": 131072,
235
+ "pad_token": "<|endoftext|>",
236
+ "split_special_tokens": false,
237
+ "tokenizer_class": "Qwen2Tokenizer",
238
+ "unk_token": null
239
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff