semran1 commited on
Commit
416b744
·
verified ·
1 Parent(s): e7e47d9

Upload folder using huggingface_hub

Browse files
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,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLMQuant"
4
+ ],
5
+ "auto_map": {
6
+ "AutoModelForCausalLM": "modeling_qwen_quant.Qwen3ForCausalLMQuant"
7
+ },
8
+ "attention_bias": false,
9
+ "attention_dropout": 0.0,
10
+ "bos_token_id": 151643,
11
+ "eos_token_id": 151643,
12
+ "head_dim": 128,
13
+ "hidden_act": "silu",
14
+ "hidden_size": 2560,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 9728,
17
+ "max_position_embeddings": 32768,
18
+ "max_window_layers": 36,
19
+ "model_type": "qwen3",
20
+ "num_attention_heads": 32,
21
+ "num_hidden_layers": 36,
22
+ "num_key_value_heads": 8,
23
+ "rms_norm_eps": 1e-06,
24
+ "rope_scaling": null,
25
+ "rope_theta": 1000000,
26
+ "sliding_window": null,
27
+ "tie_word_embeddings": true,
28
+ "torch_dtype": "bfloat16",
29
+ "transformers_version": "4.52.4",
30
+ "use_cache": true,
31
+ "use_sliding_window": false,
32
+ "vocab_size": 151936
33
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "eos_token_id": 151643,
4
+ "max_new_tokens": 2048,
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-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9eb3fbdbfb1e62f00c7fc6e1c089f6579fed71f8a1b10146a8b5d87d306692a
3
+ size 4967215360
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:89de7c5f9d111d591e6814439ace578c2bde60124b9df5d3cd636722d82742fc
3
+ size 3077766632
model.safetensors.index.json ADDED
@@ -0,0 +1,405 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 8044936192
4
+ },
5
+ "weight_map": {
6
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
7
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.10.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.10.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
39
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.11.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.11.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
51
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
53
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.12.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.12.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
62
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.13.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
69
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.13.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
75
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.14.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
80
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.14.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.15.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
91
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.15.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.16.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.16.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
107
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
108
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
109
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
111
+ "model.layers.17.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.17.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
116
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.18.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
125
+ "model.layers.18.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
127
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
129
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
130
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
132
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.19.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
134
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
135
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.19.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
138
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
139
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
140
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
141
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
143
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
144
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
145
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
146
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
147
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
151
+ "model.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
152
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
153
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
154
+ "model.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
155
+ "model.layers.20.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
156
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
157
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
158
+ "model.layers.20.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
159
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
160
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
161
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
162
+ "model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
163
+ "model.layers.21.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
164
+ "model.layers.21.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
165
+ "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
166
+ "model.layers.21.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
167
+ "model.layers.21.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
168
+ "model.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
169
+ "model.layers.21.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
170
+ "model.layers.21.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
171
+ "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
172
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
173
+ "model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
174
+ "model.layers.22.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
175
+ "model.layers.22.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
176
+ "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
177
+ "model.layers.22.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
178
+ "model.layers.22.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
179
+ "model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
180
+ "model.layers.22.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
181
+ "model.layers.22.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
182
+ "model.layers.22.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
183
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
184
+ "model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
185
+ "model.layers.23.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
186
+ "model.layers.23.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
187
+ "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
188
+ "model.layers.23.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
189
+ "model.layers.23.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
190
+ "model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
191
+ "model.layers.23.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
192
+ "model.layers.23.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
193
+ "model.layers.23.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
194
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
195
+ "model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
196
+ "model.layers.24.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
197
+ "model.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
198
+ "model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
199
+ "model.layers.24.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
200
+ "model.layers.24.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
201
+ "model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
202
+ "model.layers.24.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
203
+ "model.layers.24.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
204
+ "model.layers.24.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
205
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
206
+ "model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
207
+ "model.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
208
+ "model.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
209
+ "model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
210
+ "model.layers.25.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
211
+ "model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
212
+ "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
213
+ "model.layers.25.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
214
+ "model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
215
+ "model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
216
+ "model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
217
+ "model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
218
+ "model.layers.26.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
219
+ "model.layers.26.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
220
+ "model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
221
+ "model.layers.26.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
222
+ "model.layers.26.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
223
+ "model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
224
+ "model.layers.26.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
225
+ "model.layers.26.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
226
+ "model.layers.26.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
227
+ "model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
228
+ "model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
229
+ "model.layers.27.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
230
+ "model.layers.27.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
231
+ "model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
232
+ "model.layers.27.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
233
+ "model.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
234
+ "model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
235
+ "model.layers.27.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
236
+ "model.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
237
+ "model.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
238
+ "model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
239
+ "model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
240
+ "model.layers.28.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
241
+ "model.layers.28.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
242
+ "model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
243
+ "model.layers.28.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
244
+ "model.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
245
+ "model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
246
+ "model.layers.28.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
247
+ "model.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
248
+ "model.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
249
+ "model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
250
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
251
+ "model.layers.29.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
252
+ "model.layers.29.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
253
+ "model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
254
+ "model.layers.29.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
255
+ "model.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
256
+ "model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
257
+ "model.layers.29.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
258
+ "model.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
259
+ "model.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
260
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
261
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
262
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
267
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
269
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
270
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
271
+ "model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
272
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
273
+ "model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
274
+ "model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
275
+ "model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
276
+ "model.layers.30.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
277
+ "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
278
+ "model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
279
+ "model.layers.30.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
280
+ "model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
281
+ "model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
282
+ "model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
283
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
284
+ "model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
285
+ "model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
286
+ "model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
287
+ "model.layers.31.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
288
+ "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
289
+ "model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
290
+ "model.layers.31.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
291
+ "model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
292
+ "model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
293
+ "model.layers.32.input_layernorm.weight": "model-00002-of-00002.safetensors",
294
+ "model.layers.32.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
295
+ "model.layers.32.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
296
+ "model.layers.32.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
297
+ "model.layers.32.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
298
+ "model.layers.32.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
299
+ "model.layers.32.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
300
+ "model.layers.32.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
301
+ "model.layers.32.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
302
+ "model.layers.32.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
303
+ "model.layers.32.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
304
+ "model.layers.33.input_layernorm.weight": "model-00002-of-00002.safetensors",
305
+ "model.layers.33.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
306
+ "model.layers.33.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
307
+ "model.layers.33.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
308
+ "model.layers.33.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
309
+ "model.layers.33.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
310
+ "model.layers.33.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
311
+ "model.layers.33.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
312
+ "model.layers.33.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
313
+ "model.layers.33.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
314
+ "model.layers.33.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
315
+ "model.layers.34.input_layernorm.weight": "model-00002-of-00002.safetensors",
316
+ "model.layers.34.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
317
+ "model.layers.34.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
318
+ "model.layers.34.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
319
+ "model.layers.34.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
320
+ "model.layers.34.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
321
+ "model.layers.34.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
322
+ "model.layers.34.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
323
+ "model.layers.34.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
324
+ "model.layers.34.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
325
+ "model.layers.34.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
326
+ "model.layers.35.input_layernorm.weight": "model-00002-of-00002.safetensors",
327
+ "model.layers.35.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
328
+ "model.layers.35.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
329
+ "model.layers.35.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
330
+ "model.layers.35.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
331
+ "model.layers.35.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
332
+ "model.layers.35.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
333
+ "model.layers.35.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
334
+ "model.layers.35.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
335
+ "model.layers.35.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
336
+ "model.layers.35.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
337
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
338
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
339
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
340
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
341
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
342
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
343
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
344
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
345
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
346
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
347
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
348
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
349
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
350
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
351
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
352
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
353
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
354
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
355
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
356
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
357
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
358
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
359
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
360
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
361
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
362
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
363
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
364
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
365
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
366
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
367
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
368
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
369
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
370
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
371
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
372
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
373
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
374
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
375
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
376
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
377
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
378
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
379
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
380
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
381
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
382
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
383
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
384
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
385
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
386
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
387
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
388
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
389
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
390
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
391
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
392
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
393
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
394
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
395
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
396
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
397
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
398
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
399
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
400
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
401
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
402
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
403
+ "model.norm.weight": "model-00002-of-00002.safetensors"
404
+ }
405
+ }
modeling_qwen_quant.py ADDED
@@ -0,0 +1,843 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
2
+ # This file was automatically generated from src/transformers/models/qwen3/modular_qwen3.py.
3
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
4
+ # the file from the modular. If any change should be done, please apply the change to the
5
+ # modular_qwen3.py file directly. One of our CI enforces this.
6
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7
+ # coding=utf-8
8
+ # Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+ from typing import Callable, Optional, Union
23
+
24
+ import torch
25
+ from torch import nn
26
+ from .quantized_linear import TWNLinear
27
+
28
+ from transformers.activations import ACT2FN
29
+ from transformers.cache_utils import Cache, DynamicCache
30
+ from transformers.generation import GenerationMixin
31
+ from transformers.integrations import use_kernel_forward_from_hub
32
+ from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
33
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
34
+ from transformers.modeling_layers import GradientCheckpointingLayer
35
+ from transformers.modeling_outputs import (
36
+ BaseModelOutputWithPast,
37
+ CausalLMOutputWithPast,
38
+ QuestionAnsweringModelOutput,
39
+ SequenceClassifierOutputWithPast,
40
+ TokenClassifierOutput,
41
+ )
42
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
43
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
44
+ from transformers.processing_utils import Unpack
45
+ from transformers.utils import LossKwargs, auto_docstring, can_return_tuple, logging
46
+ from transformers.models.qwen3.configuration_qwen3 import Qwen3Config
47
+
48
+
49
+ logger = logging.get_logger(__name__)
50
+
51
+
52
+ @use_kernel_forward_from_hub("RMSNorm")
53
+ class Qwen3RMSNorm(nn.Module):
54
+ def __init__(self, hidden_size, eps=1e-6):
55
+ """
56
+ Qwen3RMSNorm is equivalent to T5LayerNorm
57
+ """
58
+ super().__init__()
59
+ self.weight = nn.Parameter(torch.ones(hidden_size))
60
+ self.variance_epsilon = eps
61
+
62
+ def forward(self, hidden_states):
63
+ input_dtype = hidden_states.dtype
64
+ hidden_states = hidden_states.to(torch.float32)
65
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
66
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
67
+ return self.weight * hidden_states.to(input_dtype)
68
+
69
+ def extra_repr(self):
70
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
71
+
72
+
73
+ class Qwen3MLP(nn.Module):
74
+ def __init__(self, config):
75
+ super().__init__()
76
+ self.config = config
77
+ self.hidden_size = config.hidden_size
78
+ self.intermediate_size = config.intermediate_size
79
+ self.gate_proj = TWNLinear(self.hidden_size, self.intermediate_size, bias=False)
80
+ self.up_proj = TWNLinear(self.hidden_size, self.intermediate_size, bias=False)
81
+ self.down_proj = TWNLinear(self.intermediate_size, self.hidden_size, bias=False)
82
+ self.act_fn = ACT2FN[config.hidden_act]
83
+
84
+ def forward(self, x):
85
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
86
+ return down_proj
87
+
88
+
89
+ def rotate_half(x):
90
+ """Rotates half the hidden dims of the input."""
91
+ x1 = x[..., : x.shape[-1] // 2]
92
+ x2 = x[..., x.shape[-1] // 2 :]
93
+ return torch.cat((-x2, x1), dim=-1)
94
+
95
+
96
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
97
+ """Applies Rotary Position Embedding to the query and key tensors.
98
+
99
+ Args:
100
+ q (`torch.Tensor`): The query tensor.
101
+ k (`torch.Tensor`): The key tensor.
102
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
103
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
104
+ position_ids (`torch.Tensor`, *optional*):
105
+ Deprecated and unused.
106
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
107
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
108
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
109
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
110
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
111
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
112
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
113
+ Returns:
114
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
115
+ """
116
+ cos = cos.unsqueeze(unsqueeze_dim)
117
+ sin = sin.unsqueeze(unsqueeze_dim)
118
+ q_embed = (q * cos) + (rotate_half(q) * sin)
119
+ k_embed = (k * cos) + (rotate_half(k) * sin)
120
+ return q_embed, k_embed
121
+
122
+
123
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
124
+ """
125
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
126
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
127
+ """
128
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
129
+ if n_rep == 1:
130
+ return hidden_states
131
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
132
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
133
+
134
+
135
+ def eager_attention_forward(
136
+ module: nn.Module,
137
+ query: torch.Tensor,
138
+ key: torch.Tensor,
139
+ value: torch.Tensor,
140
+ attention_mask: Optional[torch.Tensor],
141
+ scaling: float,
142
+ dropout: float = 0.0,
143
+ **kwargs,
144
+ ):
145
+ key_states = repeat_kv(key, module.num_key_value_groups)
146
+ value_states = repeat_kv(value, module.num_key_value_groups)
147
+
148
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
149
+ if attention_mask is not None:
150
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
151
+ attn_weights = attn_weights + causal_mask
152
+
153
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
154
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
155
+ attn_output = torch.matmul(attn_weights, value_states)
156
+ attn_output = attn_output.transpose(1, 2).contiguous()
157
+
158
+ return attn_output, attn_weights
159
+
160
+
161
+ class Qwen3Attention(nn.Module):
162
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
163
+
164
+ def __init__(self, config: Qwen3Config, layer_idx: int):
165
+ super().__init__()
166
+ self.config = config
167
+ self.layer_idx = layer_idx
168
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
169
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
170
+ self.scaling = self.head_dim**-0.5
171
+ self.attention_dropout = config.attention_dropout
172
+ self.is_causal = True
173
+
174
+ self.q_proj = TWNLinear(
175
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
176
+ )
177
+ self.k_proj = TWNLinear(
178
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
179
+ )
180
+ self.v_proj = TWNLinear(
181
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
182
+ )
183
+ self.o_proj = TWNLinear(
184
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
185
+ )
186
+ self.q_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # unlike olmo, only on the head dim!
187
+ self.k_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # thus post q_norm does not need reshape
188
+ self.sliding_window = config.sliding_window if config.layer_types[layer_idx] == "sliding_attention" else None
189
+
190
+ def forward(
191
+ self,
192
+ hidden_states: torch.Tensor,
193
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
194
+ attention_mask: Optional[torch.Tensor],
195
+ past_key_value: Optional[Cache] = None,
196
+ cache_position: Optional[torch.LongTensor] = None,
197
+ **kwargs: Unpack[FlashAttentionKwargs],
198
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor], Optional[tuple[torch.Tensor]]]:
199
+ input_shape = hidden_states.shape[:-1]
200
+ hidden_shape = (*input_shape, -1, self.head_dim)
201
+
202
+ query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
203
+ key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
204
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
205
+
206
+ cos, sin = position_embeddings
207
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
208
+
209
+ if past_key_value is not None:
210
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
211
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
212
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
213
+
214
+ attention_interface: Callable = eager_attention_forward
215
+ if self.config._attn_implementation != "eager":
216
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
217
+
218
+ attn_output, attn_weights = attention_interface(
219
+ self,
220
+ query_states,
221
+ key_states,
222
+ value_states,
223
+ attention_mask,
224
+ dropout=0.0 if not self.training else self.attention_dropout,
225
+ scaling=self.scaling,
226
+ sliding_window=self.sliding_window, # diff with Llama
227
+ **kwargs,
228
+ )
229
+
230
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
231
+ attn_output = self.o_proj(attn_output)
232
+ return attn_output, attn_weights
233
+
234
+
235
+ class Qwen3DecoderLayer(GradientCheckpointingLayer):
236
+ def __init__(self, config: Qwen3Config, layer_idx: int):
237
+ super().__init__()
238
+ self.hidden_size = config.hidden_size
239
+
240
+ self.self_attn = Qwen3Attention(config=config, layer_idx=layer_idx)
241
+
242
+ self.mlp = Qwen3MLP(config)
243
+ self.input_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
244
+ self.post_attention_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
245
+ self.attention_type = config.layer_types[layer_idx]
246
+
247
+ def forward(
248
+ self,
249
+ hidden_states: torch.Tensor,
250
+ attention_mask: Optional[torch.Tensor] = None,
251
+ position_ids: Optional[torch.LongTensor] = None,
252
+ past_key_value: Optional[Cache] = None,
253
+ output_attentions: Optional[bool] = False,
254
+ use_cache: Optional[bool] = False,
255
+ cache_position: Optional[torch.LongTensor] = None,
256
+ position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
257
+ **kwargs: Unpack[FlashAttentionKwargs],
258
+ ) -> tuple[torch.FloatTensor, Optional[tuple[torch.FloatTensor, torch.FloatTensor]]]:
259
+ residual = hidden_states
260
+ hidden_states = self.input_layernorm(hidden_states)
261
+
262
+ # Self Attention
263
+ hidden_states, self_attn_weights = self.self_attn(
264
+ hidden_states=hidden_states,
265
+ attention_mask=attention_mask,
266
+ position_ids=position_ids,
267
+ past_key_value=past_key_value,
268
+ output_attentions=output_attentions,
269
+ use_cache=use_cache,
270
+ cache_position=cache_position,
271
+ position_embeddings=position_embeddings,
272
+ **kwargs,
273
+ )
274
+ hidden_states = residual + hidden_states
275
+
276
+ # Fully Connected
277
+ residual = hidden_states
278
+ hidden_states = self.post_attention_layernorm(hidden_states)
279
+ hidden_states = self.mlp(hidden_states)
280
+ hidden_states = residual + hidden_states
281
+
282
+ outputs = (hidden_states,)
283
+ if output_attentions:
284
+ outputs += (self_attn_weights,)
285
+
286
+ return outputs
287
+
288
+
289
+ @auto_docstring
290
+ class Qwen3PreTrainedModel(PreTrainedModel):
291
+ config_class = Qwen3Config
292
+ base_model_prefix = "model"
293
+ supports_gradient_checkpointing = True
294
+ _no_split_modules = ["Qwen3DecoderLayer"]
295
+ _skip_keys_device_placement = ["past_key_values"]
296
+ _supports_flash_attn_3 = True
297
+ _supports_flash_attn_2 = True
298
+ _supports_sdpa = True
299
+ _supports_flex_attn = True
300
+ _supports_cache_class = True
301
+ _supports_quantized_cache = True
302
+ _supports_static_cache = True
303
+ _supports_attention_backend = True
304
+
305
+ def _init_weights(self, module):
306
+ std = self.config.initializer_range
307
+ if isinstance(module, nn.Linear):
308
+ module.weight.data.normal_(mean=0.0, std=std)
309
+ if module.bias is not None:
310
+ module.bias.data.zero_()
311
+ elif isinstance(module, nn.Embedding):
312
+ module.weight.data.normal_(mean=0.0, std=std)
313
+ if module.padding_idx is not None:
314
+ module.weight.data[module.padding_idx].zero_()
315
+ elif isinstance(module, Qwen3RMSNorm):
316
+ module.weight.data.fill_(1.0)
317
+
318
+
319
+ class Qwen3RotaryEmbedding(nn.Module):
320
+ def __init__(self, config: Qwen3Config, device=None):
321
+ super().__init__()
322
+ # BC: "rope_type" was originally "type"
323
+ if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
324
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
325
+ else:
326
+ self.rope_type = "default"
327
+ self.max_seq_len_cached = config.max_position_embeddings
328
+ self.original_max_seq_len = config.max_position_embeddings
329
+
330
+ self.config = config
331
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
332
+
333
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
334
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
335
+ self.original_inv_freq = self.inv_freq
336
+
337
+ @torch.no_grad()
338
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
339
+ def forward(self, x, position_ids):
340
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
341
+ position_ids_expanded = position_ids[:, None, :].float()
342
+
343
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
344
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
345
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
346
+ emb = torch.cat((freqs, freqs), dim=-1)
347
+ cos = emb.cos() * self.attention_scaling
348
+ sin = emb.sin() * self.attention_scaling
349
+
350
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
351
+
352
+
353
+ @auto_docstring
354
+ class Qwen3Model(Qwen3PreTrainedModel):
355
+ def __init__(self, config: Qwen3Config):
356
+ super().__init__(config)
357
+ self.padding_idx = config.pad_token_id
358
+ self.vocab_size = config.vocab_size
359
+
360
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
361
+ self.layers = nn.ModuleList(
362
+ [Qwen3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
363
+ )
364
+ self.norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
365
+ self.rotary_emb = Qwen3RotaryEmbedding(config=config)
366
+ self.gradient_checkpointing = False
367
+ self.has_sliding_layers = "sliding_attention" in self.config.layer_types
368
+
369
+ # Initialize weights and apply final processing
370
+ self.post_init()
371
+
372
+ def get_input_embeddings(self):
373
+ return self.embed_tokens
374
+
375
+ def set_input_embeddings(self, value):
376
+ self.embed_tokens = value
377
+
378
+ @can_return_tuple
379
+ @auto_docstring
380
+ def forward(
381
+ self,
382
+ input_ids: Optional[torch.LongTensor] = None,
383
+ attention_mask: Optional[torch.Tensor] = None,
384
+ position_ids: Optional[torch.LongTensor] = None,
385
+ past_key_values: Optional[Cache] = None,
386
+ inputs_embeds: Optional[torch.FloatTensor] = None,
387
+ use_cache: Optional[bool] = None,
388
+ output_attentions: Optional[bool] = None,
389
+ output_hidden_states: Optional[bool] = None,
390
+ cache_position: Optional[torch.LongTensor] = None,
391
+ **flash_attn_kwargs: Unpack[FlashAttentionKwargs],
392
+ ) -> BaseModelOutputWithPast:
393
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
394
+ output_hidden_states = (
395
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
396
+ )
397
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
398
+
399
+ if (input_ids is None) ^ (inputs_embeds is not None):
400
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
401
+
402
+ if self.gradient_checkpointing and self.training and use_cache:
403
+ logger.warning_once(
404
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
405
+ )
406
+ use_cache = False
407
+
408
+ # TODO (joao): remove this exception in v4.56 -- it exists for users that try to pass a legacy cache
409
+ if not isinstance(past_key_values, (type(None), Cache)):
410
+ raise ValueError("The `past_key_values` should be either a `Cache` object or `None`.")
411
+
412
+ if inputs_embeds is None:
413
+ inputs_embeds = self.embed_tokens(input_ids)
414
+
415
+ if use_cache and past_key_values is None:
416
+ past_key_values = DynamicCache()
417
+
418
+ if cache_position is None:
419
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
420
+ cache_position = torch.arange(
421
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
422
+ )
423
+
424
+ if position_ids is None:
425
+ position_ids = cache_position.unsqueeze(0)
426
+
427
+ # It may already have been prepared by e.g. `generate`
428
+ if not isinstance(causal_mask_mapping := attention_mask, dict):
429
+ # Prepare mask arguments
430
+ mask_kwargs = {
431
+ "config": self.config,
432
+ "input_embeds": inputs_embeds,
433
+ "attention_mask": attention_mask,
434
+ "cache_position": cache_position,
435
+ "past_key_values": past_key_values,
436
+ "position_ids": position_ids,
437
+ }
438
+ # Create the masks
439
+ causal_mask_mapping = {
440
+ "full_attention": create_causal_mask(**mask_kwargs),
441
+ }
442
+ # The sliding window alternating layers are not always activated depending on the config
443
+ if self.has_sliding_layers:
444
+ causal_mask_mapping["sliding_attention"] = create_sliding_window_causal_mask(**mask_kwargs)
445
+
446
+ hidden_states = inputs_embeds
447
+
448
+ # create position embeddings to be shared across the decoder layers
449
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
450
+
451
+ # decoder layers
452
+ all_hidden_states = () if output_hidden_states else None
453
+ all_self_attns = () if output_attentions else None
454
+
455
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
456
+ if output_hidden_states:
457
+ all_hidden_states += (hidden_states,)
458
+
459
+ layer_outputs = decoder_layer(
460
+ hidden_states,
461
+ attention_mask=causal_mask_mapping[decoder_layer.attention_type],
462
+ position_ids=position_ids,
463
+ past_key_value=past_key_values,
464
+ output_attentions=output_attentions,
465
+ use_cache=use_cache,
466
+ cache_position=cache_position,
467
+ position_embeddings=position_embeddings,
468
+ **flash_attn_kwargs,
469
+ )
470
+
471
+ hidden_states = layer_outputs[0]
472
+
473
+ if output_attentions:
474
+ all_self_attns += (layer_outputs[1],)
475
+
476
+ hidden_states = self.norm(hidden_states)
477
+
478
+ # add hidden states from the last decoder layer
479
+ if output_hidden_states:
480
+ all_hidden_states += (hidden_states,)
481
+
482
+ return BaseModelOutputWithPast(
483
+ last_hidden_state=hidden_states,
484
+ past_key_values=past_key_values if use_cache else None,
485
+ hidden_states=all_hidden_states,
486
+ attentions=all_self_attns,
487
+ )
488
+
489
+
490
+ class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs): ...
491
+
492
+
493
+ @auto_docstring
494
+ class Qwen3ForCausalLMQuant(Qwen3PreTrainedModel, GenerationMixin):
495
+ _tied_weights_keys = ["lm_head.weight"]
496
+ _tp_plan = {"lm_head": "colwise_rep"}
497
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
498
+
499
+ def __init__(self, config):
500
+ super().__init__(config)
501
+ self.model = Qwen3Model(config)
502
+ self.vocab_size = config.vocab_size
503
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
504
+
505
+ # Initialize weights and apply final processing
506
+ self.post_init()
507
+
508
+ def get_input_embeddings(self):
509
+ return self.model.embed_tokens
510
+
511
+ def set_input_embeddings(self, value):
512
+ self.model.embed_tokens = value
513
+
514
+ def get_output_embeddings(self):
515
+ return self.lm_head
516
+
517
+ def set_output_embeddings(self, new_embeddings):
518
+ self.lm_head = new_embeddings
519
+
520
+ def set_decoder(self, decoder):
521
+ self.model = decoder
522
+
523
+ def get_decoder(self):
524
+ return self.model
525
+
526
+ @can_return_tuple
527
+ @auto_docstring
528
+ def forward(
529
+ self,
530
+ input_ids: Optional[torch.LongTensor] = None,
531
+ attention_mask: Optional[torch.Tensor] = None,
532
+ position_ids: Optional[torch.LongTensor] = None,
533
+ past_key_values: Optional[Cache] = None,
534
+ inputs_embeds: Optional[torch.FloatTensor] = None,
535
+ labels: Optional[torch.LongTensor] = None,
536
+ use_cache: Optional[bool] = None,
537
+ output_attentions: Optional[bool] = None,
538
+ output_hidden_states: Optional[bool] = None,
539
+ cache_position: Optional[torch.LongTensor] = None,
540
+ logits_to_keep: Union[int, torch.Tensor] = 0,
541
+ **kwargs: Unpack[KwargsForCausalLM],
542
+ ) -> CausalLMOutputWithPast:
543
+ r"""
544
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
545
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
546
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
547
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
548
+
549
+ Example:
550
+
551
+ ```python
552
+ >>> from transformers import AutoTokenizer, Qwen3ForCausalLM
553
+
554
+ >>> model = Qwen3ForCausalLM.from_pretrained("Qwen/Qwen3-8B")
555
+ >>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
556
+
557
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
558
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
559
+
560
+ >>> # Generate
561
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
562
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
563
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
564
+ ```"""
565
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
566
+ output_hidden_states = (
567
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
568
+ )
569
+
570
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
571
+ outputs: BaseModelOutputWithPast = self.model(
572
+ input_ids=input_ids,
573
+ attention_mask=attention_mask,
574
+ position_ids=position_ids,
575
+ past_key_values=past_key_values,
576
+ inputs_embeds=inputs_embeds,
577
+ use_cache=use_cache,
578
+ output_attentions=output_attentions,
579
+ output_hidden_states=output_hidden_states,
580
+ cache_position=cache_position,
581
+ **kwargs,
582
+ )
583
+
584
+ hidden_states = outputs.last_hidden_state
585
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
586
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
587
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
588
+
589
+ loss = None
590
+ if labels is not None:
591
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
592
+
593
+ return CausalLMOutputWithPast(
594
+ loss=loss,
595
+ logits=logits,
596
+ past_key_values=outputs.past_key_values,
597
+ hidden_states=outputs.hidden_states,
598
+ attentions=outputs.attentions,
599
+ )
600
+
601
+
602
+ @auto_docstring(
603
+ custom_intro="""
604
+ The Qwen3 Model transformer with a sequence classification head on top (linear layer).
605
+
606
+ [`Qwen3ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
607
+ (e.g. GPT-2) do.
608
+
609
+ Since it does classification on the last token, it requires to know the position of the last token. If a
610
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
611
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
612
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
613
+ each row of the batch).
614
+ """
615
+ )
616
+ class Qwen3ForSequenceClassification(Qwen3PreTrainedModel):
617
+ def __init__(self, config):
618
+ super().__init__(config)
619
+ self.num_labels = config.num_labels
620
+ self.model = Qwen3Model(config)
621
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
622
+
623
+ # Initialize weights and apply final processing
624
+ self.post_init()
625
+
626
+ def get_input_embeddings(self):
627
+ return self.model.embed_tokens
628
+
629
+ def set_input_embeddings(self, value):
630
+ self.model.embed_tokens = value
631
+
632
+ @can_return_tuple
633
+ @auto_docstring
634
+ def forward(
635
+ self,
636
+ input_ids: Optional[torch.LongTensor] = None,
637
+ attention_mask: Optional[torch.Tensor] = None,
638
+ position_ids: Optional[torch.LongTensor] = None,
639
+ past_key_values: Optional[Cache] = None,
640
+ inputs_embeds: Optional[torch.FloatTensor] = None,
641
+ labels: Optional[torch.LongTensor] = None,
642
+ use_cache: Optional[bool] = None,
643
+ output_attentions: Optional[bool] = None,
644
+ output_hidden_states: Optional[bool] = None,
645
+ ) -> SequenceClassifierOutputWithPast:
646
+ r"""
647
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
648
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
649
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
650
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
651
+ """
652
+
653
+ transformer_outputs: BaseModelOutputWithPast = self.model(
654
+ input_ids,
655
+ attention_mask=attention_mask,
656
+ position_ids=position_ids,
657
+ past_key_values=past_key_values,
658
+ inputs_embeds=inputs_embeds,
659
+ use_cache=use_cache,
660
+ output_attentions=output_attentions,
661
+ output_hidden_states=output_hidden_states,
662
+ )
663
+ hidden_states = transformer_outputs.last_hidden_state
664
+ logits = self.score(hidden_states)
665
+
666
+ if input_ids is not None:
667
+ batch_size = input_ids.shape[0]
668
+ else:
669
+ batch_size = inputs_embeds.shape[0]
670
+
671
+ if self.config.pad_token_id is None and batch_size != 1:
672
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
673
+ if self.config.pad_token_id is None:
674
+ last_non_pad_token = -1
675
+ elif input_ids is not None:
676
+ # To handle both left- and right- padding, we take the rightmost token that is not equal to pad_token_id
677
+ non_pad_mask = (input_ids != self.config.pad_token_id).to(logits.device, torch.int32)
678
+ token_indices = torch.arange(input_ids.shape[-1], device=logits.device, dtype=torch.int32)
679
+ last_non_pad_token = (token_indices * non_pad_mask).argmax(-1)
680
+ else:
681
+ last_non_pad_token = -1
682
+ logger.warning_once(
683
+ f"{self.__class__.__name__} will not detect padding tokens in `inputs_embeds`. Results may be "
684
+ "unexpected if using padding tokens in conjunction with `inputs_embeds.`"
685
+ )
686
+
687
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), last_non_pad_token]
688
+
689
+ loss = None
690
+ if labels is not None:
691
+ loss = self.loss_function(logits=logits, labels=labels, pooled_logits=pooled_logits, config=self.config)
692
+
693
+ return SequenceClassifierOutputWithPast(
694
+ loss=loss,
695
+ logits=pooled_logits,
696
+ past_key_values=transformer_outputs.past_key_values,
697
+ hidden_states=transformer_outputs.hidden_states,
698
+ attentions=transformer_outputs.attentions,
699
+ )
700
+
701
+
702
+ @auto_docstring
703
+ class Qwen3ForTokenClassification(Qwen3PreTrainedModel):
704
+ def __init__(self, config):
705
+ super().__init__(config)
706
+ self.num_labels = config.num_labels
707
+ self.model = Qwen3Model(config)
708
+ if getattr(config, "classifier_dropout", None) is not None:
709
+ classifier_dropout = config.classifier_dropout
710
+ elif getattr(config, "hidden_dropout", None) is not None:
711
+ classifier_dropout = config.hidden_dropout
712
+ else:
713
+ classifier_dropout = 0.1
714
+ self.dropout = nn.Dropout(classifier_dropout)
715
+ self.score = nn.Linear(config.hidden_size, config.num_labels)
716
+
717
+ # Initialize weights and apply final processing
718
+ self.post_init()
719
+
720
+ def get_input_embeddings(self):
721
+ return self.model.embed_tokens
722
+
723
+ def set_input_embeddings(self, value):
724
+ self.model.embed_tokens = value
725
+
726
+ @can_return_tuple
727
+ @auto_docstring
728
+ def forward(
729
+ self,
730
+ input_ids: Optional[torch.LongTensor] = None,
731
+ attention_mask: Optional[torch.Tensor] = None,
732
+ position_ids: Optional[torch.LongTensor] = None,
733
+ past_key_values: Optional[Cache] = None,
734
+ inputs_embeds: Optional[torch.FloatTensor] = None,
735
+ labels: Optional[torch.LongTensor] = None,
736
+ use_cache: Optional[bool] = None,
737
+ output_attentions: Optional[bool] = None,
738
+ output_hidden_states: Optional[bool] = None,
739
+ ) -> TokenClassifierOutput:
740
+ r"""
741
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
742
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
743
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
744
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
745
+ """
746
+
747
+ outputs: BaseModelOutputWithPast = self.model(
748
+ input_ids,
749
+ attention_mask=attention_mask,
750
+ position_ids=position_ids,
751
+ past_key_values=past_key_values,
752
+ inputs_embeds=inputs_embeds,
753
+ use_cache=use_cache,
754
+ output_attentions=output_attentions,
755
+ output_hidden_states=output_hidden_states,
756
+ )
757
+ sequence_output = outputs.last_hidden_state
758
+ sequence_output = self.dropout(sequence_output)
759
+ logits = self.score(sequence_output)
760
+
761
+ loss = None
762
+ if labels is not None:
763
+ loss = self.loss_function(logits, labels, self.config)
764
+
765
+ return TokenClassifierOutput(
766
+ loss=loss,
767
+ logits=logits,
768
+ hidden_states=outputs.hidden_states,
769
+ attentions=outputs.attentions,
770
+ )
771
+
772
+
773
+ @auto_docstring
774
+ class Qwen3ForQuestionAnswering(Qwen3PreTrainedModel):
775
+ base_model_prefix = "transformer"
776
+
777
+ def __init__(self, config):
778
+ super().__init__(config)
779
+ self.transformer = Qwen3Model(config)
780
+ self.qa_outputs = nn.Linear(config.hidden_size, 2)
781
+
782
+ # Initialize weights and apply final processing
783
+ self.post_init()
784
+
785
+ def get_input_embeddings(self):
786
+ return self.transformer.embed_tokens
787
+
788
+ def set_input_embeddings(self, value):
789
+ self.transformer.embed_tokens = value
790
+
791
+ @can_return_tuple
792
+ @auto_docstring
793
+ def forward(
794
+ self,
795
+ input_ids: Optional[torch.LongTensor] = None,
796
+ attention_mask: Optional[torch.Tensor] = None,
797
+ position_ids: Optional[torch.LongTensor] = None,
798
+ past_key_values: Optional[Cache] = None,
799
+ inputs_embeds: Optional[torch.FloatTensor] = None,
800
+ start_positions: Optional[torch.LongTensor] = None,
801
+ end_positions: Optional[torch.LongTensor] = None,
802
+ output_attentions: Optional[bool] = None,
803
+ output_hidden_states: Optional[bool] = None,
804
+ **kwargs,
805
+ ) -> QuestionAnsweringModelOutput:
806
+ outputs: BaseModelOutputWithPast = self.transformer(
807
+ input_ids,
808
+ attention_mask=attention_mask,
809
+ position_ids=position_ids,
810
+ past_key_values=past_key_values,
811
+ inputs_embeds=inputs_embeds,
812
+ output_attentions=output_attentions,
813
+ output_hidden_states=output_hidden_states,
814
+ )
815
+
816
+ sequence_output = outputs.last_hidden_state
817
+
818
+ logits = self.qa_outputs(sequence_output)
819
+ start_logits, end_logits = logits.split(1, dim=-1)
820
+ start_logits = start_logits.squeeze(-1).contiguous()
821
+ end_logits = end_logits.squeeze(-1).contiguous()
822
+
823
+ loss = None
824
+ if start_positions is not None and end_positions is not None:
825
+ loss = self.loss_function(start_logits, end_logits, start_positions, end_positions, **kwargs)
826
+
827
+ return QuestionAnsweringModelOutput(
828
+ loss=loss,
829
+ start_logits=start_logits,
830
+ end_logits=end_logits,
831
+ hidden_states=outputs.hidden_states,
832
+ attentions=outputs.attentions,
833
+ )
834
+
835
+
836
+ __all__ = [
837
+ "Qwen3ForCausalLM",
838
+ "Qwen3ForQuestionAnswering",
839
+ "Qwen3Model",
840
+ "Qwen3PreTrainedModel",
841
+ "Qwen3ForSequenceClassification",
842
+ "Qwen3ForTokenClassification",
843
+ ]
quantized_linear.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import copy
2
+ import functools
3
+ import math
4
+
5
+ import transformers
6
+ import torch
7
+ import torch.nn as nn
8
+
9
+ class TWNLinear(nn.Linear):
10
+ def __init__(self, in_features, out_features, bias=False):
11
+ super().__init__(in_features, out_features, bias=bias)
12
+
13
+ def forward(self, input: torch.Tensor) -> torch.Tensor:
14
+ x = self.weight
15
+ x = TwnQuantizer().apply(x)
16
+ output = torch.nn.functional.linear(input, x)
17
+ return output
18
+
19
+
20
+ class TwnQuantizer(torch.autograd.Function):
21
+ """Ternary Weight Networks (TWN)
22
+ Ref: https://arxiv.org/abs/1605.04711
23
+ """
24
+
25
+ @staticmethod
26
+ def forward(ctx, input, max_scale=0.7, clip = None, group_size= -1, per_tensor = False, max_scale_dummy=0.7):
27
+ """
28
+ :param input: tensor to be ternarized
29
+ :return: quantized tensor
30
+ """
31
+ ctx.save_for_backward(input)
32
+
33
+ org_w_shape = input.shape
34
+ q_group_size = group_size
35
+
36
+ if q_group_size > 0:
37
+ assert org_w_shape[-1] % q_group_size == 0
38
+ input = input.reshape(-1, q_group_size)
39
+ else:
40
+ input = input.reshape(-1, input.shape[-1])
41
+
42
+ if per_tensor: assert q_group_size == -1, "Conflict with Per Tensor and Per Group Quant!"
43
+
44
+ if clip != None:
45
+ if per_tensor:
46
+ m = input.norm(p=1).div(input.nelement())
47
+ # m = input.max()
48
+ clip_alpha = m * clip
49
+ else:
50
+ m = input.norm(p=1,dim=1).div(input[0].nelement())
51
+ m = m.expand(input.shape[1], -1).transpose(0,1)
52
+ clip_alpha = m * clip
53
+ input = torch.where(input <= clip_alpha, input, clip_alpha)
54
+ input = torch.where(input >= -1*clip_alpha, input, -1*clip_alpha)
55
+
56
+ if per_tensor:
57
+ # Per Tensor Quantizaiton
58
+ m = input.abs().mean()
59
+ thres = max_scale * m
60
+ pos = (input > thres).float()
61
+ neg = (input < -thres).float()
62
+ mask = (input.abs() > thres).float()
63
+ alpha = (mask * input).abs().sum() / mask.sum()
64
+ result = alpha * pos - alpha * neg
65
+ else:
66
+ # Per Channel/Group Quantization
67
+ n = input[0].nelement()
68
+ m = input.data.norm(p=1, dim=1).div(n)
69
+ thres = (max_scale * m).view(-1, 1).expand_as(input)
70
+ pos = (input > thres).float()
71
+ neg = (input < -thres).float()
72
+ mask = (input.abs() > thres).float()
73
+ alpha = ((mask * input).abs().sum(dim=1) / mask.sum(dim=1)).view(-1, 1)
74
+ result = alpha * pos - alpha * neg
75
+
76
+ result = result.reshape(org_w_shape) # for per-group quantization
77
+
78
+ return result
79
+
80
+ @staticmethod
81
+ def backward(ctx, grad_output):
82
+ """
83
+ :param ctx: saved non-clipped full-precision tensor and clip_val
84
+ :param grad_output: gradient ert the quantized tensor
85
+ :return: estimated gradient wrt the full-precision tensor
86
+ """
87
+ # input, clip_val = ctx.saved_tensors # unclipped input
88
+ input = ctx.saved_tensors # unclipped input
89
+ grad_input = grad_output.clone()
90
+ # grad_input[input.ge(clip_val[1])] = 0
91
+ # grad_input[input.le(clip_val[0])] = 0
92
+ return grad_input, None, None, None, None
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": "<|endoftext|>",
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_config.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "<|endoftext|>",
232
+ "errors": "replace",
233
+ "extra_special_tokens": {},
234
+ "legacy": false,
235
+ "model_max_length": 131072,
236
+ "pad_token": "<|endoftext|>",
237
+ "split_special_tokens": false,
238
+ "tokenizer_class": "Qwen2Tokenizer",
239
+ "unk_token": null
240
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff