ybelkada HF Staff commited on
Commit
1603ade
·
verified ·
1 Parent(s): 4fc6921

Upload Qwen4ExpForConditionalGeneration

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 ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - trl
5
+ ---
6
+
7
+ # Tiny Qwen4ExpForConditionalGeneration
8
+
9
+ This is a minimal model built for unit tests in the [TRL](https://github.com/huggingface/trl) library.
chat_template.jinja ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {%- set reasoning_instructions = '' %}
46
+ {%- if enable_thinking is undefined or enable_thinking is true %}
47
+ {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
48
+ {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
49
+ {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
50
+ {%- endif %}
51
+ {%- if resolved_reasoning_effort == 'xhigh' %}
52
+ {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
53
+ {%- elif resolved_reasoning_effort == 'low' %}
54
+ {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
55
+ {%- endif %}
56
+ {%- endif %}
57
+ {%- if tools and tools is iterable and tools is not mapping %}
58
+ {{- '<|im_start|>system\n' }}
59
+ {%- if reasoning_instructions %}
60
+ {{- reasoning_instructions + '\n\n' }}
61
+ {%- endif %}
62
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
63
+ {%- for tool in tools %}
64
+ {{- "\n" }}
65
+ {{- tool | tojson }}
66
+ {%- endfor %}
67
+ {{- "\n</tools>" }}
68
+ {{- '\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>' }}
69
+ {%- if messages[0].role == 'system' %}
70
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
71
+ {%- if content %}
72
+ {{- '\n\n' + content }}
73
+ {%- endif %}
74
+ {%- endif %}
75
+ {{- '<|im_end|>\n' }}
76
+ {%- else %}
77
+ {%- if messages[0].role == 'system' %}
78
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
79
+ {%- if content %}
80
+ {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
81
+ {%- elif reasoning_instructions %}
82
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
83
+ {%- endif %}
84
+ {%- elif reasoning_instructions %}
85
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
86
+ {%- endif %}
87
+ {%- endif %}
88
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
89
+ {%- for message in messages[::-1] %}
90
+ {%- set index = (messages|length - 1) - loop.index0 %}
91
+ {%- if ns.multi_step_tool and message.role == "user" %}
92
+ {%- set content = render_content(message.content, false)|trim %}
93
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
94
+ {%- set ns.multi_step_tool = false %}
95
+ {%- set ns.last_query_index = index %}
96
+ {%- endif %}
97
+ {%- endif %}
98
+ {%- endfor %}
99
+ {%- if ns.multi_step_tool %}
100
+ {{- raise_exception('No user query found in messages.') }}
101
+ {%- endif %}
102
+ {%- for message in messages %}
103
+ {%- set content = render_content(message.content, true)|trim %}
104
+ {%- if message.role == "system" %}
105
+ {%- if not loop.first %}
106
+ {{- raise_exception('System message must be at the beginning.') }}
107
+ {%- endif %}
108
+ {%- elif message.role == "user" %}
109
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
110
+ {%- elif message.role == "assistant" %}
111
+ {%- set reasoning_content = '' %}
112
+ {%- if message.reasoning_content is string %}
113
+ {%- set reasoning_content = message.reasoning_content %}
114
+ {%- endif %}
115
+ {%- set reasoning_content = reasoning_content|trim %}
116
+ {{- '<|im_start|>' + message.role + '\n' }}
117
+ {%- generation %}
118
+ {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
119
+ {{- '<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
120
+ {%- else %}
121
+ {{- content }}
122
+ {%- endif %}
123
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
124
+ {%- for tool_call in message.tool_calls %}
125
+ {%- if tool_call.function is defined %}
126
+ {%- set tool_call = tool_call.function %}
127
+ {%- endif %}
128
+ {%- if loop.first %}
129
+ {%- if content|trim %}
130
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
131
+ {%- else %}
132
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
133
+ {%- endif %}
134
+ {%- else %}
135
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
136
+ {%- endif %}
137
+ {%- if tool_call.arguments is defined and tool_call.arguments != '' %}
138
+ {%- for args_name, args_value in tool_call.arguments|items %}
139
+ {{- '<parameter=' + args_name + '>\n' }}
140
+ {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
141
+ {{- args_value }}
142
+ {{- '\n</parameter>\n' }}
143
+ {%- endfor %}
144
+ {%- endif %}
145
+ {{- '</function>\n</tool_call>' }}
146
+ {%- endfor %}
147
+ {%- endif %}
148
+ {{- '<|im_end|>' }}
149
+ {%- endgeneration %}
150
+ {{- '\n' }}
151
+ {%- elif message.role == "tool" %}
152
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
153
+ {{- '<|im_start|>user' }}
154
+ {%- endif %}
155
+ {{- '\n<tool_response>\n' }}
156
+ {{- content }}
157
+ {{- '\n</tool_response>' }}
158
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
159
+ {{- '<|im_end|>\n' }}
160
+ {%- elif loop.last %}
161
+ {{- '<|im_end|>\n' }}
162
+ {%- endif %}
163
+ {%- else %}
164
+ {{- raise_exception('Unexpected message role.') }}
165
+ {%- endif %}
166
+ {%- endfor %}
167
+ {%- if add_generation_prompt %}
168
+ {{- '<|im_start|>assistant\n' }}
169
+ {%- if enable_thinking is defined and enable_thinking is false %}
170
+ {{- '<think>\n\n</think>\n\n' }}
171
+ {%- else %}
172
+ {{- '<think>\n' }}
173
+ {%- endif %}
174
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen4ExpForConditionalGeneration"
4
+ ],
5
+ "dtype": "bfloat16",
6
+ "image_token_id": 248056,
7
+ "language_model_only": false,
8
+ "model_type": "qwen4_exp",
9
+ "text_config": {
10
+ "attention_bias": false,
11
+ "attention_dropout": 0.0,
12
+ "bos_token_id": 248044,
13
+ "dtype": "bfloat16",
14
+ "eos_token_id": 248044,
15
+ "full_attention_interval": 4,
16
+ "hc_count": 4,
17
+ "hc_lowrank": 8,
18
+ "head_dim": 256,
19
+ "heads_per_ngram": 2,
20
+ "hidden_act": "silu",
21
+ "hidden_size": 16,
22
+ "indexer_budget": 128,
23
+ "indexer_compress_ratio": 4,
24
+ "indexer_head_dim": 64,
25
+ "indexer_kv_heads": 1,
26
+ "indexer_n_heads": 2,
27
+ "initializer_range": 0.02,
28
+ "layer_types": [
29
+ "linear_attention",
30
+ "linear_attention",
31
+ "linear_attention",
32
+ "indexed_attention"
33
+ ],
34
+ "linear_conv_kernel_dim": 4,
35
+ "linear_key_head_dim": 128,
36
+ "linear_num_key_heads": 16,
37
+ "linear_num_value_heads": 48,
38
+ "linear_value_head_dim": 128,
39
+ "make_ngram_vocab_size_divisible_by": 8,
40
+ "mamba_ssm_dtype": "float32",
41
+ "max_position_embeddings": 262144,
42
+ "model_type": "qwen4_exp_text",
43
+ "moe_intermediate_size": 32,
44
+ "mtp": {
45
+ "hybrid": true,
46
+ "layer_types": [
47
+ "full_attention"
48
+ ],
49
+ "mtp_use_hidden_state_from_layer": null,
50
+ "num_hidden_layers": 1,
51
+ "rope_theta": 10000000
52
+ },
53
+ "mtp_num_hidden_layers": 1,
54
+ "mtp_use_dedicated_embeddings": false,
55
+ "ngram_size": 3,
56
+ "ngram_vocab_size_base": 1000,
57
+ "norm_topk_prob": true,
58
+ "num_attention_heads": 4,
59
+ "num_experts": 4,
60
+ "num_experts_per_tok": 2,
61
+ "num_hidden_layers": 4,
62
+ "num_key_value_heads": 2,
63
+ "number_of_conv_states": 3,
64
+ "output_gate_type": "sigmoid",
65
+ "output_router_logits": false,
66
+ "pad_token_id": null,
67
+ "ple_conv_kernel_size": 4,
68
+ "ple_embed_dim": 16,
69
+ "ple_layer_ids": [
70
+ 2
71
+ ],
72
+ "rms_norm_eps": 1e-06,
73
+ "rope_parameters": {
74
+ "mrope_interleaved": true,
75
+ "mrope_section": [
76
+ 11,
77
+ 11,
78
+ 10
79
+ ],
80
+ "partial_rotary_factor": 0.25,
81
+ "rope_theta": 10000000,
82
+ "rope_type": "default"
83
+ },
84
+ "router_aux_loss_coef": 0.001,
85
+ "seed": 1234,
86
+ "shared_expert_intermediate_size": 32,
87
+ "split_ngram_parts": 1,
88
+ "tie_word_embeddings": false,
89
+ "use_cache": true,
90
+ "vocab_size": 248320
91
+ },
92
+ "tie_word_embeddings": false,
93
+ "transformers_version": "5.23.0.dev0",
94
+ "video_token_id": 248057,
95
+ "vision_config": {
96
+ "deepstack_visual_indexes": [],
97
+ "depth": 2,
98
+ "hidden_act": "gelu_pytorch_tanh",
99
+ "hidden_size": 16,
100
+ "in_channels": 3,
101
+ "initializer_range": 0.02,
102
+ "intermediate_size": 32,
103
+ "model_type": "qwen4_exp_vision",
104
+ "num_heads": 4,
105
+ "num_position_embeddings": 2304,
106
+ "out_hidden_size": 16,
107
+ "patch_size": 16,
108
+ "rope_parameters": {
109
+ "rope_theta": 10000.0,
110
+ "rope_type": "axial"
111
+ },
112
+ "spatial_merge_size": 2,
113
+ "temporal_patch_size": 2
114
+ },
115
+ "vision_end_token_id": 248054,
116
+ "vision_start_token_id": 248053
117
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.23.0.dev0"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2eb493a6c6269217c1506755f7ab042f619c2fe9ab57ee399d78a14475a2b06
3
+ size 18737464
processor_config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "max_video_tokens": 768,
48
+ "merge_size": 2,
49
+ "min_frames": 4,
50
+ "patch_size": 16,
51
+ "resample": 3,
52
+ "rescale_factor": 0.00392156862745098,
53
+ "return_metadata": false,
54
+ "size": {
55
+ "longest_edge": 25165824,
56
+ "shortest_edge": 4096
57
+ },
58
+ "temporal_patch_size": 2,
59
+ "video_processor_type": "Qwen3VLVideoProcessor"
60
+ }
61
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a41e6e9d92018a0d3b5dcdfc626e6563d993cef9c506928add7929b54a47e73
3
+ size 19989507
tokenizer_config.json ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": [
12
+ "<|im_start|>",
13
+ "<|im_end|>",
14
+ "<|object_ref_start|>",
15
+ "<|object_ref_end|>",
16
+ "<|box_start|>",
17
+ "<|box_end|>",
18
+ "<|quad_start|>",
19
+ "<|quad_end|>",
20
+ "<|vision_start|>",
21
+ "<|vision_end|>",
22
+ "<|vision_pad|>",
23
+ "<|image_pad|>",
24
+ "<|video_pad|>"
25
+ ],
26
+ "image_token": "<|image_pad|>",
27
+ "is_local": false,
28
+ "local_files_only": false,
29
+ "merges_file": null,
30
+ "model_max_length": 262144,
31
+ "model_specific_special_tokens": {
32
+ "audio_bos_token": "<|audio_start|>",
33
+ "audio_eos_token": "<|audio_end|>",
34
+ "audio_token": "<|audio_pad|>",
35
+ "image_token": "<|image_pad|>",
36
+ "video_token": "<|video_pad|>",
37
+ "vision_bos_token": "<|vision_start|>",
38
+ "vision_eos_token": "<|vision_end|>"
39
+ },
40
+ "pad_token": "<|endoftext|>",
41
+ "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+",
42
+ "processor_class": "Qwen3VLProcessor",
43
+ "response_template": {
44
+ "defaults": {
45
+ "role": "assistant"
46
+ },
47
+ "fields": {
48
+ "content": {
49
+ "close": [
50
+ "<|im_end|>",
51
+ "<|endoftext|>"
52
+ ],
53
+ "content": "text",
54
+ "join": "",
55
+ "repeats": true
56
+ },
57
+ "reasoning_content": {
58
+ "close_pattern": "</think>|(?=<tool_call>)",
59
+ "content": "text",
60
+ "open": "<think>"
61
+ },
62
+ "tool_calls": {
63
+ "close_pattern": "</tool_call>|(?=<tool_call>)",
64
+ "content": "xml-inline",
65
+ "content_args": {
66
+ "tag_pattern": "<parameter=(?P<key>[^>\\n]+)>\\n?(?P<value>.*?)\\n?(?:</parameter>|(?=<parameter=)|(?=</function>))"
67
+ },
68
+ "open_pattern": "<tool_call>\\s*<function=(?P<name>[^>\\n]+)>",
69
+ "repeats": true,
70
+ "transform": {
71
+ "function": {
72
+ "arguments": "{content}",
73
+ "name": "{name}"
74
+ },
75
+ "type": "function"
76
+ }
77
+ }
78
+ },
79
+ "start_anchor": "<|im_start|>assistant\n"
80
+ },
81
+ "split_special_tokens": false,
82
+ "tokenizer_class": "Qwen3_5Tokenizer",
83
+ "unk_token": null,
84
+ "video_token": "<|video_pad|>",
85
+ "vision_bos_token": "<|vision_start|>",
86
+ "vision_eos_token": "<|vision_end|>"
87
+ }