tpoisonooo commited on
Commit
d45dcce
·
verified ·
1 Parent(s): 7ae4a29

Upload folder using huggingface_hub

Browse files
added_tokens.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 73443,
3
+ "<tool_call>": 73442,
4
+ "<|fim_middle|>": 73446,
5
+ "<|fim_prefix|>": 73445,
6
+ "<|fim_suffix|>": 73447,
7
+ "<|im_end|>": 73440,
8
+ "<|im_sep|>": 73444,
9
+ "<|im_start|>": 73441
10
+ }
chat_template.jinja ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {%- set tool_definitions %}
3
+ {{- "# Tools\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
4
+ {%- for tool in tools %}
5
+ {{- "\n" }}
6
+ {{- tool | tojson(ensure_ascii=False) }}
7
+ {%- endfor %}
8
+ {{- '\n</tools>\n\nTool usage guidelines:\n- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.\n- When calling a function, return an XML object within <function ... </function> using:\n<function name="function-name"><param name="param-name">param-value</param></function>\n- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param>' }}
9
+ {%- endset %}
10
+
11
+ {{- '<|im_start|>system\n' }}
12
+ {%- if messages[0].role == 'system' %}
13
+ {%- if '<tool_def_sep>' in messages[0].content %}
14
+ {{- messages[0].content.replace('<tool_def_sep>', tool_definitions) }}
15
+ {%- else %}
16
+ {{- messages[0].content + '\n\n' + tool_definitions }}
17
+ {%- endif %}
18
+ {%- else %}
19
+ {{- tool_definitions.lstrip() }}
20
+ {%- endif %}
21
+ {{- '<|im_end|>\n' }}
22
+ {%- else %}
23
+ {%- if messages[0].role == 'system' %}
24
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
25
+ {%- endif %}
26
+ {%- endif %}
27
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
28
+ {%- for message in messages[::-1] %}
29
+ {%- set index = (messages|length - 1) - loop.index0 %}
30
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
31
+ {%- set ns.multi_step_tool = false %}
32
+ {%- set ns.last_query_index = index %}
33
+ {%- endif %}
34
+ {%- endfor %}
35
+ {%- for message in messages %}
36
+ {%- if message.content is string %}
37
+ {%- set content = message.content %}
38
+ {%- else %}
39
+ {%- set content = '' %}
40
+ {%- endif %}
41
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
42
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
43
+ {%- elif message.role == "assistant" %}
44
+ {%- set reasoning_content = '' %}
45
+ {%- if message.reasoning_content is string %}
46
+ {%- set reasoning_content = message.reasoning_content %}
47
+ {%- else %}
48
+ {%- if '</think>' in content %}
49
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
50
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
51
+ {%- endif %}
52
+ {%- endif %}
53
+
54
+ {%- if message.tool_calls %}
55
+ {%- set content_parts = content.split('<tool_sep>') %}
56
+ {%- set processed_content = content_parts[0] %}
57
+ {%- set tool_calls_count = message.tool_calls|length %}
58
+ {%- set tool_sep_count = content_parts|length - 1 %}
59
+ {%- set min_count = [tool_calls_count, tool_sep_count]|min %}
60
+
61
+ {%- for i in range(1, content_parts|length) %}
62
+ {%- set tool_index = i - 1 %}
63
+ {%- if tool_index < tool_calls_count %}
64
+ {%- set tool_call = message.tool_calls[tool_index] %}
65
+ {%- if tool_call.function %}
66
+ {%- set tool_call = tool_call.function %}
67
+ {%- endif %}
68
+ {%- set single_tool_xml %}
69
+ {{- '<function name="' ~ tool_call.name ~ '">' }}
70
+ {%- if tool_call.arguments %}
71
+ {%- set args_dict = tool_call.arguments %}
72
+ {%- for param_name, param_value in args_dict.items() %}
73
+ {{- '<param name="' ~ param_name ~ '">' }}
74
+ {%- if param_value is string and ('<' in param_value or '&' in param_value or '\n' in param_value) %}
75
+ {{- '<![CDATA[' + param_value + ']]>' }}
76
+ {%- else %}
77
+ {{- param_value }}
78
+ {%- endif %}
79
+ {{- '</param>' }}
80
+ {%- endfor %}
81
+ {%- endif %}
82
+ {{- '</function>' }}
83
+ {%- endset %}
84
+ {%- set processed_content = processed_content + single_tool_xml + content_parts[i] %}
85
+ {%- else %}
86
+ {%- set processed_content = processed_content + content_parts[i] %}
87
+ {%- endif %}
88
+ {%- endfor %}
89
+
90
+ {%- if tool_calls_count > tool_sep_count %}
91
+ {%- for remaining_index in range(tool_sep_count, tool_calls_count) %}
92
+ {%- set tool_call = message.tool_calls[remaining_index] %}
93
+ {%- if tool_call.function %}
94
+ {%- set tool_call = tool_call.function %}
95
+ {%- endif %}
96
+ {%- set remaining_tool_xml %}
97
+ {{- '<function name="' ~ tool_call.name ~ '">' }}
98
+ {%- if tool_call.arguments %}
99
+ {%- set args_dict = tool_call.arguments %}
100
+ {%- for param_name, param_value in args_dict.items() %}
101
+ {{- '<param name="' ~ param_name ~ '">' }}
102
+ {%- if param_value is string and ('<' in param_value or '&' in param_value or '\n' in param_value) %}
103
+ {{- '<![CDATA[' + param_value + ']]>' }}
104
+ {%- else %}
105
+ {{- param_value }}
106
+ {%- endif %}
107
+ {{- '</param>' }}
108
+ {%- endfor %}
109
+ {%- endif %}
110
+ {{- '</function>' }}
111
+ {%- endset %}
112
+ {%- set processed_content = processed_content + remaining_tool_xml %}
113
+ {%- endfor %}
114
+ {%- endif %}
115
+
116
+ {%- set content = processed_content %}
117
+ {%- endif %}
118
+
119
+ {%- if loop.index0 > ns.last_query_index %}
120
+ {%- if reasoning_content %}
121
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
122
+ {%- else %}
123
+ {{- '<|im_start|>' + message.role + '\n' + content }}
124
+ {%- endif %}
125
+ {%- else %}
126
+ {{- '<|im_start|>' + message.role + '\n' + content }}
127
+ {%- endif %}
128
+
129
+ {%- if message.tool_calls and not has_tool_sep %}
130
+ {%- for tool_call in message.tool_calls %}
131
+ {%- if (loop.first and content) or (not loop.first) %}
132
+ {{- '\n' }}
133
+ {%- endif %}
134
+ {%- if tool_call.function %}
135
+ {%- set tool_call = tool_call.function %}
136
+ {%- endif %}
137
+ {{- '<function name="' ~ tool_call.name ~ '">' }}
138
+ {%- if tool_call.arguments %}
139
+ {%- set args_dict = tool_call.arguments %}
140
+ {%- for param_name, param_value in args_dict.items() %}
141
+ {{- '<param name="' ~ param_name ~ '">' }}
142
+ {%- if param_value is string and ('<' in param_value or '&' in param_value or '\n' in param_value) %}
143
+ {{- '<![CDATA[' + param_value + ']]>' }}
144
+ {%- else %}
145
+ {{- param_value }}
146
+ {%- endif %}
147
+ {{- '</param>' }}
148
+ {%- endfor %}
149
+ {%- endif %}
150
+ {{- '</function>' }}
151
+ {%- endfor %}
152
+ {%- endif %}
153
+ {{- '<|im_end|>\n' }}
154
+ {%- elif message.role == "tool" %}
155
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
156
+ {{- '<|im_start|>user' }}
157
+ {%- endif %}
158
+ {{- '\n<tool_response>\n' }}
159
+ {%- if message.content is string %}
160
+ {{- content }}
161
+ {%- else %}
162
+ {{- message.content | tojson(ensure_ascii=False) }}
163
+ {%- endif %}
164
+ {{- '\n</tool_response>' }}
165
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
166
+ {{- '<|im_end|>\n' }}
167
+ {%- endif %}
168
+ {%- endif %}
169
+ {%- endfor %}
170
+ {%- if add_generation_prompt %}
171
+ {{- '<|im_start|>assistant\n' }}
172
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MiniCPMSALAForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "attn_use_output_gate": true,
8
+ "attn_use_rope": false,
9
+ "auto_map": {
10
+ "AutoConfig": "configuration_minicpm_sala.MiniCPMSALAConfig",
11
+ "AutoModel": "modeling_minicpm_sala.MiniCPMSALAModel",
12
+ "AutoModelForCausalLM": "modeling_minicpm_sala.MiniCPMSALAForCausalLM",
13
+ "AutoModelForSeq2SeqLM": "modeling_minicpm_sala.MiniCPMSALAForCausalLM",
14
+ "AutoModelForSequenceClassification": "modeling_minicpm_sala.MiniCPMSALAForSequenceClassification"
15
+ },
16
+ "bos_token_id": 1,
17
+ "dim_model_base": 256,
18
+ "dtype": "bfloat16",
19
+ "eos_token_id": [
20
+ 2,
21
+ 73440
22
+ ],
23
+ "head_dim": 128,
24
+ "hidden_act": "silu",
25
+ "hidden_size": 4096,
26
+ "initializer_range": 0.1,
27
+ "intermediate_size": 16384,
28
+ "lightning_head_dim": 128,
29
+ "lightning_nh": 32,
30
+ "lightning_nkv": 32,
31
+ "lightning_scale": "1/sqrt(d)",
32
+ "lightning_use_rope": true,
33
+ "max_position_embeddings": 524288,
34
+ "mixer_types": [
35
+ "minicpm4",
36
+ "lightning-attn",
37
+ "lightning-attn",
38
+ "lightning-attn",
39
+ "lightning-attn",
40
+ "lightning-attn",
41
+ "lightning-attn",
42
+ "lightning-attn",
43
+ "lightning-attn",
44
+ "minicpm4",
45
+ "lightning-attn",
46
+ "lightning-attn",
47
+ "lightning-attn",
48
+ "lightning-attn",
49
+ "lightning-attn",
50
+ "lightning-attn",
51
+ "minicpm4",
52
+ "minicpm4",
53
+ "lightning-attn",
54
+ "lightning-attn",
55
+ "lightning-attn",
56
+ "lightning-attn",
57
+ "minicpm4",
58
+ "lightning-attn",
59
+ "lightning-attn",
60
+ "lightning-attn",
61
+ "lightning-attn",
62
+ "lightning-attn",
63
+ "lightning-attn",
64
+ "minicpm4",
65
+ "minicpm4",
66
+ "minicpm4"
67
+ ],
68
+ "model_type": "minicpm_sala",
69
+ "mup_denominator": 32,
70
+ "num_attention_heads": 32,
71
+ "num_hidden_layers": 32,
72
+ "num_key_value_heads": 2,
73
+ "pad_token_id": 2,
74
+ "pretraining_tp": 1,
75
+ "qk_norm": true,
76
+ "rms_norm_eps": 1e-06,
77
+ "rope_scaling": null,
78
+ "rope_theta": 10000.0,
79
+ "scale_depth": 1.4,
80
+ "scale_emb": 12,
81
+ "shift_labels": true,
82
+ "sparse_config": {
83
+ "block_size": 64,
84
+ "dense_len": 8192,
85
+ "init_blocks": 1,
86
+ "kernel_size": 32,
87
+ "kernel_stride": 16,
88
+ "topk": 64,
89
+ "use_nope": false,
90
+ "window_size": 2048
91
+ },
92
+ "tie_word_embeddings": false,
93
+ "transformers_version": "4.57.1",
94
+ "use_cache": true,
95
+ "use_output_gate": true,
96
+ "use_output_norm": true,
97
+ "vocab_size": 73448,
98
+ "quantization_config": {
99
+ "config_groups": {
100
+ "group_0": {
101
+ "input_activations": {
102
+ "dynamic": false,
103
+ "num_bits": 4,
104
+ "type": "float",
105
+ "group_size": 16
106
+ },
107
+ "weights": {
108
+ "dynamic": false,
109
+ "num_bits": 4,
110
+ "type": "float",
111
+ "group_size": 16
112
+ },
113
+ "targets": [
114
+ "Linear"
115
+ ]
116
+ }
117
+ },
118
+ "ignore": [
119
+ "lm_head"
120
+ ],
121
+ "quant_algo": "NVFP4",
122
+ "producer": {
123
+ "name": "modelopt",
124
+ "version": "0.42.0"
125
+ },
126
+ "quant_method": "modelopt"
127
+ }
128
+ }
configuration_minicpm_sala.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 The OpenBMB Team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """MiniCPMSALA model configuration"""
16
+
17
+ from typing import List, Optional
18
+ from transformers.configuration_utils import PretrainedConfig
19
+ from transformers.utils import logging
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+ MINICPMSALA_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
24
+
25
+
26
+ class MiniCPMSALAConfig(PretrainedConfig):
27
+ r"""
28
+ This is the configuration class to store the configuration of a [`MiniCPMSALAModel`]. It is used to instantiate an MiniCPMSALA
29
+ model according to the specified arguments, defining the model architecture.
30
+
31
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
32
+ documentation from [`PretrainedConfig`] for more information.
33
+
34
+
35
+ Args:
36
+ vocab_size (`int`, *optional*, defaults to 32000):
37
+ Vocabulary size of the MiniCPMSALA model. Defines the number of different tokens that can be represented by the
38
+ `inputs_ids` passed when calling [`MiniCPMSALAModel`]
39
+ hidden_size (`int`, *optional*, defaults to 4096):
40
+ Dimension of the hidden representations.
41
+ intermediate_size (`int`, *optional*, defaults to 11008):
42
+ Dimension of the MLP representations.
43
+ num_hidden_layers (`int`, *optional*, defaults to 32):
44
+ Number of hidden layers in the Transformer decoder.
45
+ num_attention_heads (`int`, *optional*, defaults to 32):
46
+ Number of attention heads for each attention layer in the Transformer decoder.
47
+ num_key_value_heads (`int`, *optional*):
48
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
49
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
50
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
51
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
52
+ by meanpooling all the original heads within that group. For more details checkout [this
53
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
54
+ `num_attention_heads`.
55
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
56
+ The non-linear activation function (function or string) in the decoder.
57
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
58
+ The maximum sequence length that this model might ever be used with. MiniCPMSALA supports up to 524288 tokens.
59
+ initializer_range (`float`, *optional*, defaults to 0.02):
60
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
61
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
62
+ The epsilon used by the rms normalization layers.
63
+ use_cache (`bool`, *optional*, defaults to `True`):
64
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
65
+ relevant if `config.is_decoder=True`.
66
+ pad_token_id (`int`, *optional*):
67
+ Padding token id.
68
+ bos_token_id (`int`, *optional*, defaults to 1):
69
+ Beginning of stream token id.
70
+ eos_token_id (`int`, *optional*, defaults to 2):
71
+ End of stream token id.
72
+ pretraining_tp (`int`, *optional*, defaults to 1):
73
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
74
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
75
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
76
+ issue](https://github.com/pytorch/pytorch/issues/76232).
77
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
78
+ Whether to tie weight embeddings
79
+ rope_theta (`float`, *optional*, defaults to 10000.0):
80
+ The base period of the RoPE embeddings.
81
+ rope_scaling (`Dict`, *optional*):
82
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
83
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
84
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
85
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
86
+ these scaling strategies behave:
87
+ https://www.reddit.com/r/LocalMiniCPM/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
88
+ experimental feature, subject to breaking API changes in future versions.
89
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
90
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
91
+ attention_dropout (`float`, *optional*, defaults to 0.0):
92
+ The dropout ratio for the attention probabilities.
93
+
94
+ ```python
95
+ >>> from transformers import MiniCPMSALAModel, MiniCPMSALAConfig
96
+
97
+ >>> # Initializing a MiniCPMSALA style configuration
98
+ >>> configuration = MiniCPMSALAConfig()
99
+
100
+ >>> # Initializing a model from the minicpm_sala style configuration
101
+ >>> model = MiniCPMSALAModel(configuration)
102
+
103
+ >>> # Accessing the model configuration
104
+ >>> configuration = model.config
105
+ ```"""
106
+
107
+ model_type = "minicpm_sala"
108
+ keys_to_ignore_at_inference = ["past_key_values"]
109
+
110
+ def __init__(
111
+ self,
112
+ vocab_size=32000,
113
+ hidden_size=4096,
114
+ intermediate_size=11008,
115
+ num_hidden_layers=32,
116
+ num_attention_heads=32,
117
+ num_key_value_heads=None,
118
+ hidden_act="silu",
119
+ max_position_embeddings=2048,
120
+ initializer_range=0.02,
121
+ rms_norm_eps=1e-6,
122
+ use_cache=True,
123
+ pad_token_id=None,
124
+ bos_token_id=1,
125
+ eos_token_id=2,
126
+ pretraining_tp=1,
127
+ tie_word_embeddings=True,
128
+ rope_theta=10000.0,
129
+ rope_scaling=None,
130
+ attention_bias=False,
131
+ attention_dropout=0.0,
132
+ scale_emb=1,
133
+ dim_model_base=1,
134
+ scale_depth=1,
135
+ mup_denominator=32,
136
+ sparse_config=None,
137
+ mixer_types: List[str] = ["minicpm4"],
138
+ head_dim: Optional[int] = None,
139
+ use_output_gate: bool = False,
140
+ use_output_norm: bool = False,
141
+ lightning_use_rope: bool = True,
142
+ lightning_nkv: Optional[int] = None,
143
+ lightning_nh: Optional[int] = None,
144
+ qk_norm: bool = False,
145
+ lightning_head_dim: Optional[int] = None,
146
+ rand_init: bool = False,
147
+ train_mlp: bool = True,
148
+ attn_use_rope: bool = True,
149
+ lightning_scale: str = "1/sqrt(d)",
150
+ shift_labels: bool = True,
151
+ attn_use_output_gate: bool = False,
152
+ **kwargs,
153
+ ):
154
+
155
+ self.vocab_size = vocab_size
156
+ self.max_position_embeddings = max_position_embeddings
157
+ self.hidden_size = hidden_size
158
+ self.intermediate_size = intermediate_size
159
+ self.num_hidden_layers = num_hidden_layers
160
+ self.num_attention_heads = num_attention_heads
161
+
162
+ # for backward compatibility
163
+ if num_key_value_heads is None:
164
+ num_key_value_heads = num_attention_heads
165
+
166
+ self.num_key_value_heads = num_key_value_heads
167
+ self.hidden_act = hidden_act
168
+ self.initializer_range = initializer_range
169
+ self.rms_norm_eps = rms_norm_eps
170
+ self.pretraining_tp = pretraining_tp
171
+ self.use_cache = use_cache
172
+ self.rope_theta = rope_theta
173
+ self.rope_scaling = rope_scaling
174
+ self.attention_bias = attention_bias
175
+ self.attention_dropout = attention_dropout
176
+ self.scale_emb = scale_emb
177
+ self.dim_model_base = dim_model_base
178
+ self.scale_depth = scale_depth
179
+ # only used for Eagle Head
180
+ self.mup_denominator = mup_denominator
181
+
182
+ # sparse config
183
+ self.sparse_config = sparse_config
184
+
185
+ self.mixer_types = mixer_types
186
+ if self.mixer_types is None or len(self.mixer_types) == 0:
187
+ # Default to MiniCPMSALA4 (full attention) for all layers
188
+ self.mixer_types = ["minicpm4"] * self.num_hidden_layers
189
+ elif len(self.mixer_types) < self.num_hidden_layers:
190
+ self.mixer_types = (mixer_types * self.num_hidden_layers)[
191
+ : self.num_hidden_layers
192
+ ]
193
+ elif len(self.mixer_types) == self.num_hidden_layers:
194
+ self.mixer_types = mixer_types
195
+ else:
196
+ raise ValueError(f"Invalid number of mixer types: {len(self.mixer_types)}")
197
+ assert len(self.mixer_types) == self.num_hidden_layers
198
+
199
+ # for Lightning
200
+ if head_dim is None:
201
+ head_dim = self.hidden_size // self.num_attention_heads
202
+ self.head_dim = head_dim
203
+ self.use_output_norm = use_output_norm
204
+ self.use_output_gate = use_output_gate
205
+ self.lightning_use_rope = lightning_use_rope
206
+ self.qk_norm = qk_norm
207
+ self.lightning_nkv = (
208
+ lightning_nkv if lightning_nkv is not None else self.num_key_value_heads
209
+ )
210
+ self.lightning_nh = (
211
+ lightning_nh if lightning_nh is not None else self.num_attention_heads
212
+ )
213
+ self.lightning_head_dim = (
214
+ lightning_head_dim if lightning_head_dim is not None else self.head_dim
215
+ )
216
+ self.lightning_scale = lightning_scale
217
+ self.attn_use_rope = attn_use_rope
218
+ self.shift_labels = shift_labels
219
+ self.attn_use_output_gate = attn_use_output_gate
220
+
221
+ super().__init__(
222
+ pad_token_id=pad_token_id,
223
+ bos_token_id=bos_token_id,
224
+ eos_token_id=eos_token_id,
225
+ tie_word_embeddings=tie_word_embeddings,
226
+ **kwargs,
227
+ )
228
+ try:
229
+ import flash_attn
230
+
231
+ self._attn_implementation = "flash_attention_2"
232
+ except ImportError:
233
+ pass
234
+
235
+ def _rope_scaling_validation(self):
236
+ """
237
+ Validate the `rope_scaling` configuration.
238
+ """
239
+ if self.rope_scaling is None:
240
+ return
241
+
242
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
243
+ raise ValueError(
244
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
245
+ f"got {self.rope_scaling}"
246
+ )
247
+ rope_scaling_type = self.rope_scaling.get("type", None)
248
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
249
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
250
+ raise ValueError(
251
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
252
+ )
253
+ if (
254
+ rope_scaling_factor is None
255
+ or not isinstance(rope_scaling_factor, float)
256
+ or rope_scaling_factor <= 1.0
257
+ ):
258
+ raise ValueError(
259
+ f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}"
260
+ )
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": [
5
+ 2,
6
+ 73440
7
+ ],
8
+ "pad_token_id": 2,
9
+ "transformers_version": "4.57.1"
10
+ }
hf_quant_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "producer": {
3
+ "name": "modelopt",
4
+ "version": "0.42.0"
5
+ },
6
+ "quantization": {
7
+ "quant_algo": "NVFP4",
8
+ "kv_cache_quant_algo": null,
9
+ "group_size": 16,
10
+ "exclude_modules": [
11
+ "lm_head"
12
+ ]
13
+ }
14
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eba76f54613229c43c7b294965aa0e6c18a4f3bc57ad9b9d2d90d3bc0c48e895
3
+ size 4968318840
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c25bc7cba878fe4c437cfec01e05bcc753a9624b9afcc3697a47f5648dacb656
3
+ size 1228194160
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
modeling_minicpm_sala.py ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_end|>",
4
+ "<|im_start|>",
5
+ "<tool_call>",
6
+ "</tool_call>",
7
+ "<|im_sep|>",
8
+ "<|fim_prefix|>",
9
+ "<|fim_middle|>",
10
+ "<|fim_suffix|>",
11
+ "<tool_response>",
12
+ "</tool_response>",
13
+ "<tools>",
14
+ "</tools>",
15
+ "<arguments>",
16
+ "</arguments>",
17
+ "<parameters>",
18
+ "</parameters>",
19
+ "<function",
20
+ "</function>",
21
+ "<param",
22
+ "</param>"
23
+ ],
24
+ "bos_token": {
25
+ "content": "<s>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ },
31
+ "eos_token": {
32
+ "content": "<|im_end|>",
33
+ "lstrip": false,
34
+ "normalized": false,
35
+ "rstrip": false,
36
+ "single_word": false
37
+ },
38
+ "pad_token": {
39
+ "content": "</s>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": false,
43
+ "single_word": false
44
+ },
45
+ "unk_token": {
46
+ "content": "<unk>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false
51
+ }
52
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb74d51116831c3bf65db812c553f94ab0c88dcf97a5bbb37e3504f6d359c530
3
+ size 1181204
tokenizer_config.json ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "101": {
31
+ "content": "<think>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": false
37
+ },
38
+ "102": {
39
+ "content": "</think>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": false,
43
+ "single_word": false,
44
+ "special": false
45
+ },
46
+ "103": {
47
+ "content": "<tool_response>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": false,
51
+ "single_word": false,
52
+ "special": true
53
+ },
54
+ "104": {
55
+ "content": "</tool_response>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": false,
59
+ "single_word": false,
60
+ "special": true
61
+ },
62
+ "105": {
63
+ "content": "<tools>",
64
+ "lstrip": false,
65
+ "normalized": false,
66
+ "rstrip": false,
67
+ "single_word": false,
68
+ "special": true
69
+ },
70
+ "106": {
71
+ "content": "</tools>",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": false,
75
+ "single_word": false,
76
+ "special": true
77
+ },
78
+ "107": {
79
+ "content": "<parameters>",
80
+ "lstrip": false,
81
+ "normalized": false,
82
+ "rstrip": false,
83
+ "single_word": false,
84
+ "special": true
85
+ },
86
+ "108": {
87
+ "content": "</parameters>",
88
+ "lstrip": false,
89
+ "normalized": false,
90
+ "rstrip": false,
91
+ "single_word": false,
92
+ "special": true
93
+ },
94
+ "109": {
95
+ "content": "<arguments>",
96
+ "lstrip": false,
97
+ "normalized": false,
98
+ "rstrip": false,
99
+ "single_word": false,
100
+ "special": true
101
+ },
102
+ "110": {
103
+ "content": "</arguments>",
104
+ "lstrip": false,
105
+ "normalized": false,
106
+ "rstrip": false,
107
+ "single_word": false,
108
+ "special": true
109
+ },
110
+ "111": {
111
+ "content": "<function",
112
+ "lstrip": false,
113
+ "normalized": false,
114
+ "rstrip": false,
115
+ "single_word": false,
116
+ "special": true
117
+ },
118
+ "112": {
119
+ "content": "</function>",
120
+ "lstrip": false,
121
+ "normalized": false,
122
+ "rstrip": false,
123
+ "single_word": false,
124
+ "special": true
125
+ },
126
+ "113": {
127
+ "content": "<param",
128
+ "lstrip": false,
129
+ "normalized": false,
130
+ "rstrip": false,
131
+ "single_word": false,
132
+ "special": true
133
+ },
134
+ "114": {
135
+ "content": "</param>",
136
+ "lstrip": false,
137
+ "normalized": false,
138
+ "rstrip": false,
139
+ "single_word": false,
140
+ "special": true
141
+ },
142
+ "73440": {
143
+ "content": "<|im_end|>",
144
+ "lstrip": false,
145
+ "normalized": false,
146
+ "rstrip": false,
147
+ "single_word": false,
148
+ "special": true
149
+ },
150
+ "73441": {
151
+ "content": "<|im_start|>",
152
+ "lstrip": false,
153
+ "normalized": false,
154
+ "rstrip": false,
155
+ "single_word": false,
156
+ "special": true
157
+ },
158
+ "73442": {
159
+ "content": "<tool_call>",
160
+ "lstrip": false,
161
+ "normalized": false,
162
+ "rstrip": false,
163
+ "single_word": false,
164
+ "special": true
165
+ },
166
+ "73443": {
167
+ "content": "</tool_call>",
168
+ "lstrip": false,
169
+ "normalized": false,
170
+ "rstrip": false,
171
+ "single_word": false,
172
+ "special": true
173
+ },
174
+ "73444": {
175
+ "content": "<|im_sep|>",
176
+ "lstrip": false,
177
+ "normalized": false,
178
+ "rstrip": false,
179
+ "single_word": false,
180
+ "special": true
181
+ },
182
+ "73445": {
183
+ "content": "<|fim_prefix|>",
184
+ "lstrip": false,
185
+ "normalized": false,
186
+ "rstrip": false,
187
+ "single_word": false,
188
+ "special": true
189
+ },
190
+ "73446": {
191
+ "content": "<|fim_middle|>",
192
+ "lstrip": false,
193
+ "normalized": false,
194
+ "rstrip": false,
195
+ "single_word": false,
196
+ "special": true
197
+ },
198
+ "73447": {
199
+ "content": "<|fim_suffix|>",
200
+ "lstrip": false,
201
+ "normalized": false,
202
+ "rstrip": false,
203
+ "single_word": false,
204
+ "special": true
205
+ }
206
+ },
207
+ "additional_special_tokens": [
208
+ "<|im_end|>",
209
+ "<|im_start|>",
210
+ "<tool_call>",
211
+ "</tool_call>",
212
+ "<|im_sep|>",
213
+ "<|fim_prefix|>",
214
+ "<|fim_middle|>",
215
+ "<|fim_suffix|>",
216
+ "<tool_response>",
217
+ "</tool_response>",
218
+ "<tools>",
219
+ "</tools>",
220
+ "<arguments>",
221
+ "</arguments>",
222
+ "<parameters>",
223
+ "</parameters>",
224
+ "<function",
225
+ "</function>",
226
+ "<param",
227
+ "</param>"
228
+ ],
229
+ "bos_token": "<s>",
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|im_end|>",
232
+ "extra_special_tokens": {},
233
+ "legacy": true,
234
+ "model_max_length": 262144,
235
+ "pad_token": "</s>",
236
+ "sp_model_kwargs": {},
237
+ "spaces_between_special_tokens": false,
238
+ "tokenizer_class": "LlamaTokenizer",
239
+ "unk_token": "<unk>",
240
+ "use_default_system_prompt": false
241
+ }