yujiepan commited on
Commit
d05a7d9
·
verified ·
1 Parent(s): 04fefd1

Upload folder using huggingface_hub

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
.meta.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "torch": "2.11.0",
3
+ "transformers": "5.5.0"
4
+ }
README.md ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - Qwen/Qwen3.6-35B-A3B
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [Qwen/Qwen3.6-35B-A3B](https://huggingface.co/Qwen/Qwen3.6-35B-A3B).
8
+
9
+ | File path | Size |
10
+ |------|------|
11
+ | model.safetensors | 12.3MB |
12
+
13
+
14
+ ### Example usage:
15
+
16
+ - vLLM
17
+
18
+ ```bash
19
+ # Multi-token prediction is supported
20
+ model_id=tiny-random/qwen3.6-moe
21
+ vllm serve $model_id \
22
+ --tensor-parallel-size 2 \
23
+ --speculative-config.method qwen3_next_mtp \
24
+ --speculative-config.num_speculative_tokens 2 \
25
+ --reasoning-parser qwen3 \
26
+ --tool-call-parser qwen3_coder \
27
+ --enable-auto-tool-choice \
28
+ --max-cudagraph-capture-size 8
29
+ ```
30
+
31
+ - SGLang
32
+
33
+ ```bash
34
+ # Multi-token prediction is supported
35
+ model_id=tiny-random/qwen3.6-moe
36
+ python3 -m sglang.launch_server \
37
+ --model-path $model_id \
38
+ --tp-size 2 \
39
+ --tool-call-parser qwen3_coder \
40
+ --reasoning-parser qwen3 \
41
+ --speculative-algo NEXTN \
42
+ --speculative-num-steps 3 \
43
+ --speculative-eagle-topk 1 \
44
+ --speculative-num-draft-tokens 4
45
+ ```
46
+
47
+ - Transformers
48
+
49
+ ```python
50
+ import numpy as np
51
+ import torch
52
+ import transformers
53
+ from PIL import Image
54
+ from transformers import (
55
+ AutoModel,
56
+ AutoModelForCausalLM,
57
+ AutoProcessor,
58
+ AutoTokenizer,
59
+ Qwen3_5MoeForConditionalGeneration,
60
+ )
61
+
62
+ model_id = "tiny-random/qwen3.6-moe"
63
+ model = Qwen3_5MoeForConditionalGeneration.from_pretrained(
64
+ model_id, dtype=torch.bfloat16, device_map="auto",
65
+ )
66
+ processor = AutoProcessor.from_pretrained(model_id)
67
+ messages = [
68
+ {
69
+ "role": "user",
70
+ "content": [
71
+ {
72
+ "type": "image",
73
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
74
+ },
75
+ {"type": "text", "text": "Describe this image."},
76
+ ],
77
+ }
78
+ ]
79
+
80
+ inputs = processor.apply_chat_template(
81
+ messages,
82
+ tokenize=True,
83
+ add_generation_prompt=True,
84
+ return_dict=True,
85
+ return_tensors="pt"
86
+ ).to(model.device)
87
+
88
+ generated_ids = model.generate(**inputs, max_new_tokens=32)
89
+ output_text = processor.batch_decode(generated_ids[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
90
+ print(output_text)
91
+ ```
92
+
93
+ ### Codes to create this repo:
94
+
95
+ <details>
96
+ <summary>Click to expand</summary>
97
+
98
+ ```python
99
+ import json
100
+ from copy import deepcopy
101
+ from pathlib import Path
102
+
103
+ import torch
104
+ from huggingface_hub import file_exists, hf_hub_download
105
+ from transformers import (
106
+ AutoConfig,
107
+ AutoModelForCausalLM,
108
+ AutoProcessor,
109
+ GenerationConfig,
110
+ Qwen3_5MoeForConditionalGeneration,
111
+ set_seed,
112
+ )
113
+
114
+ source_model_id = "Qwen/Qwen3.6-35B-A3B"
115
+ save_folder = "/tmp/tiny-random/qwen36-moe"
116
+
117
+ processor = AutoProcessor.from_pretrained(source_model_id, trust_remote_code=True)
118
+ processor.save_pretrained(save_folder)
119
+
120
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
121
+ config_json = json.load(f)
122
+
123
+ config_json['text_config'].update({
124
+ 'head_dim': 32,
125
+ 'hidden_size': 8,
126
+ "layer_types": ['linear_attention'] * 3 + ['full_attention'],
127
+ 'intermediate_size': 32,
128
+ 'moe_intermediate_size': 32,
129
+ 'num_hidden_layers': 4,
130
+ 'num_attention_heads': 8,
131
+ 'num_key_value_heads': 4,
132
+ 'shared_expert_intermediate_size': 32,
133
+ # 3.6 has higher dim for linear attention vs 3.5
134
+ })
135
+ config_json['text_config']['rope_parameters']['mrope_section'] = [1, 1, 2]
136
+ config_json["tie_word_embeddings"] = False
137
+ config_json['vision_config'].update(
138
+ {
139
+ 'hidden_size': 64,
140
+ 'intermediate_size': 128,
141
+ 'num_heads': 2,
142
+ 'out_hidden_size': 8,
143
+ 'depth': 2,
144
+ }
145
+ )
146
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
147
+ json.dump(config_json, f, indent=2)
148
+
149
+ config = AutoConfig.from_pretrained(
150
+ save_folder,
151
+ trust_remote_code=True,
152
+ )
153
+ print(config)
154
+ torch.set_default_dtype(torch.bfloat16)
155
+ model = Qwen3_5MoeForConditionalGeneration(config)
156
+ # with torch.no_grad():
157
+ # for i in range(3):
158
+ # attn = model.model.language_model.layers[i].linear_attn
159
+ # attn.A_log = torch.nn.Parameter(attn.A_log.float())
160
+ # attn.norm.float()
161
+
162
+ print(model.state_dict()['model.language_model.layers.0.linear_attn.A_log'].dtype)
163
+ print(model.state_dict()['model.language_model.layers.0.linear_attn.norm.weight'].dtype)
164
+
165
+ model.mtp = torch.nn.ModuleDict({
166
+ "pre_fc_norm_embedding": torch.nn.RMSNorm(config.text_config.hidden_size),
167
+ "fc": torch.nn.Linear(config.text_config.hidden_size * 2, config.text_config.hidden_size, bias=False),
168
+ "layers": torch.nn.ModuleList([deepcopy(model.model.language_model.layers[3])]),
169
+ "norm": torch.nn.RMSNorm(config.text_config.hidden_size),
170
+ "pre_fc_norm_hidden": torch.nn.RMSNorm(config.text_config.hidden_size),
171
+ })
172
+ torch.set_default_dtype(torch.float32)
173
+ if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'):
174
+ model.generation_config = GenerationConfig.from_pretrained(
175
+ source_model_id, trust_remote_code=True,
176
+ )
177
+ model.generation_config.do_sample = True
178
+ print(model.generation_config)
179
+ model = model.cpu()
180
+ with torch.no_grad():
181
+ for name, p in sorted(model.named_parameters()):
182
+ torch.nn.init.normal_(p, 0, 0.2)
183
+ print(name, p.shape)
184
+ model.save_pretrained(save_folder)
185
+ ```
186
+
187
+ </details>
188
+
189
+ ### Printing the model:
190
+
191
+ <details><summary>Click to expand</summary>
192
+
193
+ ```text
194
+ Qwen3_5MoeForConditionalGeneration(
195
+ (model): Qwen3_5MoeModel(
196
+ (visual): Qwen3_5MoeVisionModel(
197
+ (patch_embed): Qwen3_5MoeVisionPatchEmbed(
198
+ (proj): Conv3d(3, 64, kernel_size=(2, 16, 16), stride=(2, 16, 16))
199
+ )
200
+ (pos_embed): Embedding(2304, 64)
201
+ (rotary_pos_emb): Qwen3_5MoeVisionRotaryEmbedding()
202
+ (blocks): ModuleList(
203
+ (0-1): 2 x Qwen3_5MoeVisionBlock(
204
+ (norm1): LayerNorm((64,), eps=1e-06, elementwise_affine=True)
205
+ (norm2): LayerNorm((64,), eps=1e-06, elementwise_affine=True)
206
+ (attn): Qwen3_5MoeVisionAttention(
207
+ (qkv): Linear(in_features=64, out_features=192, bias=True)
208
+ (proj): Linear(in_features=64, out_features=64, bias=True)
209
+ )
210
+ (mlp): Qwen3_5MoeVisionMLP(
211
+ (linear_fc1): Linear(in_features=64, out_features=128, bias=True)
212
+ (linear_fc2): Linear(in_features=128, out_features=64, bias=True)
213
+ (act_fn): GELUTanh()
214
+ )
215
+ )
216
+ )
217
+ (merger): Qwen3_5MoeVisionPatchMerger(
218
+ (norm): LayerNorm((64,), eps=1e-06, elementwise_affine=True)
219
+ (linear_fc1): Linear(in_features=256, out_features=256, bias=True)
220
+ (act_fn): GELU(approximate='none')
221
+ (linear_fc2): Linear(in_features=256, out_features=8, bias=True)
222
+ )
223
+ )
224
+ (language_model): Qwen3_5MoeTextModel(
225
+ (embed_tokens): Embedding(248320, 8)
226
+ (layers): ModuleList(
227
+ (0-2): 3 x Qwen3_5MoeDecoderLayer(
228
+ (linear_attn): Qwen3_5MoeGatedDeltaNet(
229
+ (act): SiLUActivation()
230
+ (conv1d): Conv1d(8192, 8192, kernel_size=(4,), stride=(1,), padding=(3,), groups=8192, bias=False)
231
+ (norm): Qwen3_5MoeRMSNormGated()
232
+ (out_proj): Linear(in_features=4096, out_features=8, bias=False)
233
+ (in_proj_qkv): Linear(in_features=8, out_features=8192, bias=False)
234
+ (in_proj_z): Linear(in_features=8, out_features=4096, bias=False)
235
+ (in_proj_b): Linear(in_features=8, out_features=32, bias=False)
236
+ (in_proj_a): Linear(in_features=8, out_features=32, bias=False)
237
+ )
238
+ (mlp): Qwen3_5MoeSparseMoeBlock(
239
+ (gate): Qwen3_5MoeTopKRouter()
240
+ (experts): Qwen3_5MoeExperts(
241
+ (act_fn): SiLUActivation()
242
+ )
243
+ (shared_expert): Qwen3_5MoeMLP(
244
+ (gate_proj): Linear(in_features=8, out_features=32, bias=False)
245
+ (up_proj): Linear(in_features=8, out_features=32, bias=False)
246
+ (down_proj): Linear(in_features=32, out_features=8, bias=False)
247
+ (act_fn): SiLUActivation()
248
+ )
249
+ (shared_expert_gate): Linear(in_features=8, out_features=1, bias=False)
250
+ )
251
+ (input_layernorm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
252
+ (post_attention_layernorm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
253
+ )
254
+ (3): Qwen3_5MoeDecoderLayer(
255
+ (self_attn): Qwen3_5MoeAttention(
256
+ (q_proj): Linear(in_features=8, out_features=512, bias=False)
257
+ (k_proj): Linear(in_features=8, out_features=128, bias=False)
258
+ (v_proj): Linear(in_features=8, out_features=128, bias=False)
259
+ (o_proj): Linear(in_features=256, out_features=8, bias=False)
260
+ (q_norm): Qwen3_5MoeRMSNorm((32,), eps=1e-06)
261
+ (k_norm): Qwen3_5MoeRMSNorm((32,), eps=1e-06)
262
+ )
263
+ (mlp): Qwen3_5MoeSparseMoeBlock(
264
+ (gate): Qwen3_5MoeTopKRouter()
265
+ (experts): Qwen3_5MoeExperts(
266
+ (act_fn): SiLUActivation()
267
+ )
268
+ (shared_expert): Qwen3_5MoeMLP(
269
+ (gate_proj): Linear(in_features=8, out_features=32, bias=False)
270
+ (up_proj): Linear(in_features=8, out_features=32, bias=False)
271
+ (down_proj): Linear(in_features=32, out_features=8, bias=False)
272
+ (act_fn): SiLUActivation()
273
+ )
274
+ (shared_expert_gate): Linear(in_features=8, out_features=1, bias=False)
275
+ )
276
+ (input_layernorm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
277
+ (post_attention_layernorm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
278
+ )
279
+ )
280
+ (norm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
281
+ (rotary_emb): Qwen3_5MoeTextRotaryEmbedding()
282
+ )
283
+ )
284
+ (lm_head): Linear(in_features=8, out_features=248320, bias=False)
285
+ (mtp): ModuleDict(
286
+ (pre_fc_norm_embedding): RMSNorm((8,), eps=None, elementwise_affine=True)
287
+ (fc): Linear(in_features=16, out_features=8, bias=False)
288
+ (layers): ModuleList(
289
+ (0): Qwen3_5MoeDecoderLayer(
290
+ (self_attn): Qwen3_5MoeAttention(
291
+ (q_proj): Linear(in_features=8, out_features=512, bias=False)
292
+ (k_proj): Linear(in_features=8, out_features=128, bias=False)
293
+ (v_proj): Linear(in_features=8, out_features=128, bias=False)
294
+ (o_proj): Linear(in_features=256, out_features=8, bias=False)
295
+ (q_norm): Qwen3_5MoeRMSNorm((32,), eps=1e-06)
296
+ (k_norm): Qwen3_5MoeRMSNorm((32,), eps=1e-06)
297
+ )
298
+ (mlp): Qwen3_5MoeSparseMoeBlock(
299
+ (gate): Qwen3_5MoeTopKRouter()
300
+ (experts): Qwen3_5MoeExperts(
301
+ (act_fn): SiLUActivation()
302
+ )
303
+ (shared_expert): Qwen3_5MoeMLP(
304
+ (gate_proj): Linear(in_features=8, out_features=32, bias=False)
305
+ (up_proj): Linear(in_features=8, out_features=32, bias=False)
306
+ (down_proj): Linear(in_features=32, out_features=8, bias=False)
307
+ (act_fn): SiLUActivation()
308
+ )
309
+ (shared_expert_gate): Linear(in_features=8, out_features=1, bias=False)
310
+ )
311
+ (input_layernorm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
312
+ (post_attention_layernorm): Qwen3_5MoeRMSNorm((8,), eps=1e-06)
313
+ )
314
+ )
315
+ (norm): RMSNorm((8,), eps=None, elementwise_affine=True)
316
+ (pre_fc_norm_hidden): RMSNorm((8,), eps=None, elementwise_affine=True)
317
+ )
318
+ )
319
+ ```
320
+
321
+ </details>
322
+
323
+ ### Test environment:
324
+
325
+ - torch: 2.11.0
326
+ - transformers: 5.5.0
chat_template.jinja ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- if tools and tools is iterable and tools is not mapping %}
46
+ {{- '<|im_start|>system\n' }}
47
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
48
+ {%- for tool in tools %}
49
+ {{- "\n" }}
50
+ {{- tool | tojson }}
51
+ {%- endfor %}
52
+ {{- "\n</tools>" }}
53
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
56
+ {%- if content %}
57
+ {{- '\n\n' + content }}
58
+ {%- endif %}
59
+ {%- endif %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- else %}
62
+ {%- if messages[0].role == 'system' %}
63
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
64
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
65
+ {%- endif %}
66
+ {%- endif %}
67
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
68
+ {%- for message in messages[::-1] %}
69
+ {%- set index = (messages|length - 1) - loop.index0 %}
70
+ {%- if ns.multi_step_tool and message.role == "user" %}
71
+ {%- set content = render_content(message.content, false)|trim %}
72
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
73
+ {%- set ns.multi_step_tool = false %}
74
+ {%- set ns.last_query_index = index %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- if ns.multi_step_tool %}
79
+ {{- raise_exception('No user query found in messages.') }}
80
+ {%- endif %}
81
+ {%- for message in messages %}
82
+ {%- set content = render_content(message.content, true)|trim %}
83
+ {%- if message.role == "system" %}
84
+ {%- if not loop.first %}
85
+ {{- raise_exception('System message must be at the beginning.') }}
86
+ {%- endif %}
87
+ {%- elif message.role == "user" %}
88
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
89
+ {%- elif message.role == "assistant" %}
90
+ {%- set reasoning_content = '' %}
91
+ {%- if message.reasoning_content is string %}
92
+ {%- set reasoning_content = message.reasoning_content %}
93
+ {%- else %}
94
+ {%- if '</think>' in content %}
95
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
96
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
97
+ {%- endif %}
98
+ {%- endif %}
99
+ {%- set reasoning_content = reasoning_content|trim %}
100
+ {%- if (preserve_thinking is defined and preserve_thinking is true) or (loop.index0 > ns.last_query_index) %}
101
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
102
+ {%- else %}
103
+ {{- '<|im_start|>' + message.role + '\n' + content }}
104
+ {%- endif %}
105
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
106
+ {%- for tool_call in message.tool_calls %}
107
+ {%- if tool_call.function is defined %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {%- if loop.first %}
111
+ {%- if content|trim %}
112
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
113
+ {%- else %}
114
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
115
+ {%- endif %}
116
+ {%- else %}
117
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
118
+ {%- endif %}
119
+ {%- if tool_call.arguments is defined %}
120
+ {%- for args_name, args_value in tool_call.arguments|items %}
121
+ {{- '<parameter=' + args_name + '>\n' }}
122
+ {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
123
+ {{- args_value }}
124
+ {{- '\n</parameter>\n' }}
125
+ {%- endfor %}
126
+ {%- endif %}
127
+ {{- '</function>\n</tool_call>' }}
128
+ {%- endfor %}
129
+ {%- endif %}
130
+ {{- '<|im_end|>\n' }}
131
+ {%- elif message.role == "tool" %}
132
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
133
+ {{- '<|im_start|>user' }}
134
+ {%- endif %}
135
+ {{- '\n<tool_response>\n' }}
136
+ {{- content }}
137
+ {{- '\n</tool_response>' }}
138
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
139
+ {{- '<|im_end|>\n' }}
140
+ {%- elif loop.last %}
141
+ {{- '<|im_end|>\n' }}
142
+ {%- endif %}
143
+ {%- else %}
144
+ {{- raise_exception('Unexpected message role.') }}
145
+ {%- endif %}
146
+ {%- endfor %}
147
+ {%- if add_generation_prompt %}
148
+ {{- '<|im_start|>assistant\n' }}
149
+ {%- if enable_thinking is defined and enable_thinking is false %}
150
+ {{- '<think>\n\n</think>\n\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5MoeForConditionalGeneration"
4
+ ],
5
+ "dtype": "bfloat16",
6
+ "image_token_id": 248056,
7
+ "model_type": "qwen3_5_moe",
8
+ "text_config": {
9
+ "attention_bias": false,
10
+ "attention_dropout": 0.0,
11
+ "attn_output_gate": true,
12
+ "bos_token_id": 248044,
13
+ "dtype": "bfloat16",
14
+ "eos_token_id": 248044,
15
+ "full_attention_interval": 4,
16
+ "head_dim": 32,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 8,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 32,
21
+ "layer_types": [
22
+ "linear_attention",
23
+ "linear_attention",
24
+ "linear_attention",
25
+ "full_attention"
26
+ ],
27
+ "linear_conv_kernel_dim": 4,
28
+ "linear_key_head_dim": 128,
29
+ "linear_num_key_heads": 16,
30
+ "linear_num_value_heads": 32,
31
+ "linear_value_head_dim": 128,
32
+ "mamba_ssm_dtype": "float32",
33
+ "max_position_embeddings": 262144,
34
+ "model_type": "qwen3_5_moe_text",
35
+ "moe_intermediate_size": 32,
36
+ "mtp_num_hidden_layers": 1,
37
+ "mtp_use_dedicated_embeddings": false,
38
+ "num_attention_heads": 8,
39
+ "num_experts": 256,
40
+ "num_experts_per_tok": 8,
41
+ "num_hidden_layers": 4,
42
+ "num_key_value_heads": 4,
43
+ "output_router_logits": false,
44
+ "pad_token_id": null,
45
+ "partial_rotary_factor": 0.25,
46
+ "rms_norm_eps": 1e-06,
47
+ "rope_parameters": {
48
+ "mrope_interleaved": true,
49
+ "mrope_section": [
50
+ 1,
51
+ 1,
52
+ 2
53
+ ],
54
+ "partial_rotary_factor": 0.25,
55
+ "rope_theta": 10000000,
56
+ "rope_type": "default"
57
+ },
58
+ "router_aux_loss_coef": 0.001,
59
+ "shared_expert_intermediate_size": 32,
60
+ "tie_word_embeddings": false,
61
+ "use_cache": true,
62
+ "vocab_size": 248320
63
+ },
64
+ "tie_word_embeddings": false,
65
+ "transformers_version": "5.5.0",
66
+ "video_token_id": 248057,
67
+ "vision_config": {
68
+ "deepstack_visual_indexes": [],
69
+ "depth": 2,
70
+ "hidden_act": "gelu_pytorch_tanh",
71
+ "hidden_size": 64,
72
+ "in_channels": 3,
73
+ "initializer_range": 0.02,
74
+ "intermediate_size": 128,
75
+ "model_type": "qwen3_5_moe",
76
+ "num_heads": 2,
77
+ "num_position_embeddings": 2304,
78
+ "out_hidden_size": 8,
79
+ "patch_size": 16,
80
+ "spatial_merge_size": 2,
81
+ "temporal_patch_size": 2
82
+ },
83
+ "vision_end_token_id": 248054,
84
+ "vision_start_token_id": 248053
85
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 248044,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 248046,
6
+ 248044
7
+ ],
8
+ "pad_token_id": 248044,
9
+ "temperature": 1.0,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "5.5.0",
13
+ "trust_remote_code": true
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d984f270764a6d6c2ea524466931d6fc62593dce3014bfe51f01c5f21d6b370f
3
+ size 12316064
processor_config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "do_convert_rgb": true,
4
+ "do_normalize": true,
5
+ "do_rescale": true,
6
+ "do_resize": true,
7
+ "image_mean": [
8
+ 0.5,
9
+ 0.5,
10
+ 0.5
11
+ ],
12
+ "image_processor_type": "Qwen2VLImageProcessor",
13
+ "image_std": [
14
+ 0.5,
15
+ 0.5,
16
+ 0.5
17
+ ],
18
+ "merge_size": 2,
19
+ "patch_size": 16,
20
+ "resample": 3,
21
+ "rescale_factor": 0.00392156862745098,
22
+ "size": {
23
+ "longest_edge": 16777216,
24
+ "shortest_edge": 65536
25
+ },
26
+ "temporal_patch_size": 2
27
+ },
28
+ "processor_class": "Qwen3VLProcessor",
29
+ "video_processor": {
30
+ "do_convert_rgb": true,
31
+ "do_normalize": true,
32
+ "do_rescale": true,
33
+ "do_resize": true,
34
+ "do_sample_frames": true,
35
+ "fps": 2,
36
+ "image_mean": [
37
+ 0.5,
38
+ 0.5,
39
+ 0.5
40
+ ],
41
+ "image_std": [
42
+ 0.5,
43
+ 0.5,
44
+ 0.5
45
+ ],
46
+ "max_frames": 768,
47
+ "merge_size": 2,
48
+ "min_frames": 4,
49
+ "patch_size": 16,
50
+ "resample": 3,
51
+ "rescale_factor": 0.00392156862745098,
52
+ "return_metadata": false,
53
+ "size": {
54
+ "longest_edge": 25165824,
55
+ "shortest_edge": 4096
56
+ },
57
+ "temporal_patch_size": 2,
58
+ "video_processor_type": "Qwen3VLVideoProcessor"
59
+ }
60
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87a7830d63fcf43bf241c3c5242e96e62dd3fdc29224ca26fed8ea333db72de4
3
+ size 19989343
tokenizer_config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "audio_bos_token": "<|audio_start|>",
4
+ "audio_eos_token": "<|audio_end|>",
5
+ "audio_token": "<|audio_pad|>",
6
+ "backend": "tokenizers",
7
+ "bos_token": null,
8
+ "clean_up_tokenization_spaces": false,
9
+ "eos_token": "<|im_end|>",
10
+ "errors": "replace",
11
+ "image_token": "<|image_pad|>",
12
+ "is_local": false,
13
+ "model_max_length": 262144,
14
+ "model_specific_special_tokens": {
15
+ "audio_bos_token": "<|audio_start|>",
16
+ "audio_eos_token": "<|audio_end|>",
17
+ "audio_token": "<|audio_pad|>",
18
+ "image_token": "<|image_pad|>",
19
+ "video_token": "<|video_pad|>",
20
+ "vision_bos_token": "<|vision_start|>",
21
+ "vision_eos_token": "<|vision_end|>"
22
+ },
23
+ "pad_token": "<|endoftext|>",
24
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
25
+ "processor_class": "Qwen3VLProcessor",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "TokenizersBackend",
28
+ "unk_token": null,
29
+ "video_token": "<|video_pad|>",
30
+ "vision_bos_token": "<|vision_start|>",
31
+ "vision_eos_token": "<|vision_end|>"
32
+ }