hyx21 commited on
Commit
e7effb7
·
verified ·
1 Parent(s): bbe7c17

Upload 5 files

Browse files
config.json ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/DATA/disk1/guanwenyu/models/minicpm4/0527-sft-8000/",
3
+ "architectures": [
4
+ "MiniCPMForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_minicpm.MiniCPMConfig",
10
+ "AutoModel": "modeling_minicpm.MiniCPMModel",
11
+ "AutoModelForCausalLM": "modeling_minicpm.MiniCPMLongRopeForCausalLM",
12
+ "AutoModelForSeq2SeqLM": "modeling_minicpm.MiniCPMLongRopeForCausalLM",
13
+ "AutoModelForSequenceClassification": "modeling_minicpm.MiniCPMForSequenceClassification"
14
+ },
15
+ "bias": false,
16
+ "bos_token_id": 1,
17
+ "dim_model_base": 256,
18
+ "eos_token_id": [
19
+ 2,
20
+ 73440
21
+ ],
22
+ "head_dim": 128,
23
+ "hidden_act": "silu",
24
+ "hidden_size": 4096,
25
+ "initializer_range": 0.1,
26
+ "intermediate_size": 16384,
27
+ "max_position_embeddings": 32768,
28
+ "model_type": "minicpm",
29
+ "num_attention_heads": 32,
30
+ "num_hidden_layers": 1,
31
+ "num_key_value_heads": 2,
32
+ "pad_token_id": 2,
33
+ "pretraining_tp": 1,
34
+ "quantization_config": {
35
+ "bits": 4,
36
+ "checkpoint_format": "gptq",
37
+ "damp_percent": 0.01,
38
+ "desc_act": false,
39
+ "group_size": 128,
40
+ "lm_head": false,
41
+ "model_file_base_name": null,
42
+ "model_name_or_path": null,
43
+ "quant_method": "gptq",
44
+ "static_groups": false,
45
+ "sym": true,
46
+ "true_sequential": true
47
+ },
48
+ "rms_norm_eps": 1e-06,
49
+ "rope_scaling": {
50
+ "long_factor": [
51
+ 0.9977997200264581,
52
+ 1.014658295992452,
53
+ 1.0349680404997148,
54
+ 1.059429246056193,
55
+ 1.0888815016813513,
56
+ 1.1243301355211495,
57
+ 1.166977103606075,
58
+ 1.2182568066927284,
59
+ 1.2798772354275727,
60
+ 1.3538666751582975,
61
+ 1.4426259039919596,
62
+ 1.5489853358570191,
63
+ 1.6762658237220625,
64
+ 1.8283407612492941,
65
+ 2.0096956085876183,
66
+ 2.225478927469756,
67
+ 2.481536379650452,
68
+ 2.784415934557119,
69
+ 3.1413289096347365,
70
+ 3.560047844772632,
71
+ 4.048719380066383,
72
+ 4.615569542115128,
73
+ 5.2684819496549835,
74
+ 6.014438591970396,
75
+ 6.858830049237097,
76
+ 7.804668263503327,
77
+ 8.851768731513417,
78
+ 9.99600492938444,
79
+ 11.228766118181639,
80
+ 12.536757560834843,
81
+ 13.902257701387796,
82
+ 15.303885189125953,
83
+ 16.717837610115794,
84
+ 18.119465097853947,
85
+ 19.484965238406907,
86
+ 20.792956681060105,
87
+ 22.02571786985731,
88
+ 23.16995406772833,
89
+ 24.217054535738416,
90
+ 25.16289275000465,
91
+ 26.007284207271347,
92
+ 26.753240849586767,
93
+ 27.40615325712662,
94
+ 27.973003419175363,
95
+ 28.461674954469114,
96
+ 28.880393889607006,
97
+ 29.237306864684626,
98
+ 29.540186419591297,
99
+ 29.79624387177199,
100
+ 30.01202719065413,
101
+ 30.193382037992453,
102
+ 30.34545697551969,
103
+ 30.47273746338473,
104
+ 30.579096895249787,
105
+ 30.66785612408345,
106
+ 30.741845563814174,
107
+ 30.80346599254902,
108
+ 30.85474569563567,
109
+ 30.897392663720595,
110
+ 30.932841297560394,
111
+ 30.962293553185553,
112
+ 30.986754758742034,
113
+ 31.007064503249293,
114
+ 31.02392307921529
115
+ ],
116
+ "original_max_position_embeddings": 32768,
117
+ "short_factor": [
118
+ 0.9977997200264581,
119
+ 1.014658295992452,
120
+ 1.0349680404997148,
121
+ 1.059429246056193,
122
+ 1.0888815016813513,
123
+ 1.1243301355211495,
124
+ 1.166977103606075,
125
+ 1.2182568066927284,
126
+ 1.2798772354275727,
127
+ 1.3538666751582975,
128
+ 1.4426259039919596,
129
+ 1.5489853358570191,
130
+ 1.6762658237220625,
131
+ 1.8283407612492941,
132
+ 2.0096956085876183,
133
+ 2.225478927469756,
134
+ 2.481536379650452,
135
+ 2.784415934557119,
136
+ 3.1413289096347365,
137
+ 3.560047844772632,
138
+ 4.048719380066383,
139
+ 4.615569542115128,
140
+ 5.2684819496549835,
141
+ 6.014438591970396,
142
+ 6.858830049237097,
143
+ 7.804668263503327,
144
+ 8.851768731513417,
145
+ 9.99600492938444,
146
+ 11.228766118181639,
147
+ 12.536757560834843,
148
+ 13.902257701387796,
149
+ 15.303885189125953,
150
+ 16.717837610115794,
151
+ 18.119465097853947,
152
+ 19.484965238406907,
153
+ 20.792956681060105,
154
+ 22.02571786985731,
155
+ 23.16995406772833,
156
+ 24.217054535738416,
157
+ 25.16289275000465,
158
+ 26.007284207271347,
159
+ 26.753240849586767,
160
+ 27.40615325712662,
161
+ 27.973003419175363,
162
+ 28.461674954469114,
163
+ 28.880393889607006,
164
+ 29.237306864684626,
165
+ 29.540186419591297,
166
+ 29.79624387177199,
167
+ 30.01202719065413,
168
+ 30.193382037992453,
169
+ 30.34545697551969,
170
+ 30.47273746338473,
171
+ 30.579096895249787,
172
+ 30.66785612408345,
173
+ 30.741845563814174,
174
+ 30.80346599254902,
175
+ 30.85474569563567,
176
+ 30.897392663720595,
177
+ 30.932841297560394,
178
+ 30.962293553185553,
179
+ 30.986754758742034,
180
+ 31.007064503249293,
181
+ 31.02392307921529
182
+ ],
183
+ "type": "longrope"
184
+ },
185
+ "rope_theta": 10000.0,
186
+ "scale_depth": 1.4,
187
+ "mup_denominator": 32,
188
+ "scale_emb": 12,
189
+ "tie_word_embeddings": false,
190
+ "torch_dtype": "float16",
191
+ "transformers_version": "4.40.2",
192
+ "use_cache": true,
193
+ "vocab_size": 73448
194
+ }
configuration_minicpm.py ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
4
+ # and OPT implementations in this library. It has been modified from its
5
+ # original forms to accommodate minor architectural differences compared
6
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ """ MiniCPM model configuration"""
20
+
21
+ from transformers.configuration_utils import PretrainedConfig
22
+ from transformers.utils import logging
23
+
24
+ logger = logging.get_logger(__name__)
25
+
26
+ MINICPM_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
27
+
28
+
29
+ class MiniCPMConfig(PretrainedConfig):
30
+ r"""
31
+ This is the configuration class to store the configuration of a [`MiniCPMModel`]. It is used to instantiate an MiniCPM
32
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
33
+ defaults will yield a similar configuration to that of the MiniCPM-7B.
34
+
35
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
36
+ documentation from [`PretrainedConfig`] for more information.
37
+
38
+
39
+ Args:
40
+ vocab_size (`int`, *optional*, defaults to 32000):
41
+ Vocabulary size of the MiniCPM model. Defines the number of different tokens that can be represented by the
42
+ `inputs_ids` passed when calling [`MiniCPMModel`]
43
+ hidden_size (`int`, *optional*, defaults to 4096):
44
+ Dimension of the hidden representations.
45
+ intermediate_size (`int`, *optional*, defaults to 11008):
46
+ Dimension of the MLP representations.
47
+ num_hidden_layers (`int`, *optional*, defaults to 32):
48
+ Number of hidden layers in the Transformer decoder.
49
+ num_attention_heads (`int`, *optional*, defaults to 32):
50
+ Number of attention heads for each attention layer in the Transformer decoder.
51
+ num_key_value_heads (`int`, *optional*):
52
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
53
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
54
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
55
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
56
+ by meanpooling all the original heads within that group. For more details checkout [this
57
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
58
+ `num_attention_heads`.
59
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
60
+ The non-linear activation function (function or string) in the decoder.
61
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
62
+ The maximum sequence length that this model might ever be used with. MiniCPM 1 supports up to 2048 tokens,
63
+ MiniCPM 2 up to 4096, CodeMiniCPM up to 16384.
64
+ initializer_range (`float`, *optional*, defaults to 0.02):
65
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
66
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
67
+ The epsilon used by the rms normalization layers.
68
+ use_cache (`bool`, *optional*, defaults to `True`):
69
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
70
+ relevant if `config.is_decoder=True`.
71
+ pad_token_id (`int`, *optional*):
72
+ Padding token id.
73
+ bos_token_id (`int`, *optional*, defaults to 1):
74
+ Beginning of stream token id.
75
+ eos_token_id (`int`, *optional*, defaults to 2):
76
+ End of stream token id.
77
+ pretraining_tp (`int`, *optional*, defaults to 1):
78
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
79
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
80
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
81
+ issue](https://github.com/pytorch/pytorch/issues/76232).
82
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
83
+ Whether to tie weight embeddings
84
+ rope_theta (`float`, *optional*, defaults to 10000.0):
85
+ The base period of the RoPE embeddings.
86
+ rope_scaling (`Dict`, *optional*):
87
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
88
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
89
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
90
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
91
+ these scaling strategies behave:
92
+ https://www.reddit.com/r/LocalMiniCPM/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
93
+ experimental feature, subject to breaking API changes in future versions.
94
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
95
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
96
+ attention_dropout (`float`, *optional*, defaults to 0.0):
97
+ The dropout ratio for the attention probabilities.
98
+
99
+ ```python
100
+ >>> from transformers import MiniCPMModel, MiniCPMConfig
101
+
102
+ >>> # Initializing a MiniCPM minicpm-7b style configuration
103
+ >>> configuration = MiniCPMConfig()
104
+
105
+ >>> # Initializing a model from the minicpm-7b style configuration
106
+ >>> model = MiniCPMModel(configuration)
107
+
108
+ >>> # Accessing the model configuration
109
+ >>> configuration = model.config
110
+ ```"""
111
+
112
+ model_type = 'minicpm'
113
+ keys_to_ignore_at_inference = ['past_key_values']
114
+
115
+ def __init__(
116
+ self,
117
+ vocab_size=32000,
118
+ hidden_size=4096,
119
+ intermediate_size=11008,
120
+ num_hidden_layers=32,
121
+ num_attention_heads=32,
122
+ num_key_value_heads=None,
123
+ hidden_act='silu',
124
+ max_position_embeddings=2048,
125
+ initializer_range=0.02,
126
+ rms_norm_eps=1e-6,
127
+ use_cache=True,
128
+ pad_token_id=None,
129
+ bos_token_id=1,
130
+ eos_token_id=2,
131
+ pretraining_tp=1,
132
+ tie_word_embeddings=True,
133
+ rope_theta=10000.0,
134
+ rope_scaling=None,
135
+ attention_bias=False,
136
+ attention_dropout=0.0,
137
+ scale_emb=1,
138
+ dim_model_base=1,
139
+ scale_depth=1,
140
+ mup_denominator=32,
141
+ sparse_config=None,
142
+ **kwargs):
143
+
144
+ self.vocab_size = vocab_size
145
+ self.max_position_embeddings = max_position_embeddings
146
+ self.hidden_size = hidden_size
147
+ self.intermediate_size = intermediate_size
148
+ self.num_hidden_layers = num_hidden_layers
149
+ self.num_attention_heads = num_attention_heads
150
+
151
+ # for backward compatibility
152
+ if num_key_value_heads is None:
153
+ num_key_value_heads = num_attention_heads
154
+
155
+ self.num_key_value_heads = num_key_value_heads
156
+ self.hidden_act = hidden_act
157
+ self.initializer_range = initializer_range
158
+ self.rms_norm_eps = rms_norm_eps
159
+ self.pretraining_tp = pretraining_tp
160
+ self.use_cache = use_cache
161
+ self.rope_theta = rope_theta
162
+ self.rope_scaling = rope_scaling
163
+ # self._rope_scaling_validation()
164
+ self.attention_bias = attention_bias
165
+ self.attention_dropout = attention_dropout
166
+ self.scale_emb = scale_emb
167
+ self.dim_model_base = dim_model_base
168
+ self.scale_depth = scale_depth
169
+ self.mup_denominator = mup_denominator
170
+
171
+ # sparse config
172
+ self.sparse_config = sparse_config
173
+
174
+ super().__init__(
175
+ pad_token_id=pad_token_id,
176
+ bos_token_id=bos_token_id,
177
+ eos_token_id=eos_token_id,
178
+ tie_word_embeddings=tie_word_embeddings,
179
+ **kwargs,
180
+ )
181
+ try:
182
+ import flash_attn
183
+ self._attn_implementation = 'flash_attention_2'
184
+ except:
185
+ pass
186
+
187
+ def _rope_scaling_validation(self):
188
+ """
189
+ Validate the `rope_scaling` configuration.
190
+ """
191
+ if self.rope_scaling is None:
192
+ return
193
+
194
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
195
+ raise ValueError(
196
+ '`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, '
197
+ f'got {self.rope_scaling}'
198
+ )
199
+ rope_scaling_type = self.rope_scaling.get('type', None)
200
+ rope_scaling_factor = self.rope_scaling.get('factor', None)
201
+ if rope_scaling_type is None or rope_scaling_type not in ['linear', 'dynamic']:
202
+ raise ValueError(
203
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
204
+ )
205
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
206
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
modeling_minicpm.py ADDED
The diff for this file is too large to render. See raw diff
 
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a029972ac8882aa8ccabadd718f647ae3da5dca8a0e48bc642f6cd15e7af4f4
3
+ size 1393815475
quantize_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bits": 4,
3
+ "group_size": 128,
4
+ "damp_percent": 0.01,
5
+ "desc_act": false,
6
+ "static_groups": false,
7
+ "sym": true,
8
+ "true_sequential": true,
9
+ "lm_head": false,
10
+ "model_name_or_path": null,
11
+ "model_file_base_name": null,
12
+ "quant_method": "gptq",
13
+ "checkpoint_format": "gptq"
14
+ }