rewardhacker00 commited on
Commit
c4fe9e2
·
verified ·
1 Parent(s): 867eec8

Upload folder using huggingface_hub

Browse files
chat_template.jinja ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {% for message in messages %}{{'<|' + message['role'] + '|>' + '
2
+ ' + message['content'] + '<|end|>
3
+ ' }}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>
4
+ ' }}{% else %}{{ eos_token }}{% endif %}
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "PhiMoEForCausalLM"
4
+ ],
5
+ "attention_bias": true,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_slimmoe.PhiMoEConfig",
9
+ "AutoModelForCausalLM": "modeling_slimmoe.PhiMoEForCausalLM"
10
+ },
11
+ "bos_token_id": 1,
12
+ "dtype": "bfloat16",
13
+ "eos_token_id": 32000,
14
+ "expert_dropout": 0.0,
15
+ "head_dim": 128,
16
+ "hidden_act": "silu",
17
+ "hidden_dropout": 0.0,
18
+ "hidden_size": 4096,
19
+ "initializer_range": 0.02,
20
+ "input_jitter_noise": 0.01,
21
+ "intermediate_size": 960,
22
+ "lm_head_bias": true,
23
+ "max_position_embeddings": 4096,
24
+ "model_type": "phimoe",
25
+ "num_attention_heads": 32,
26
+ "num_experts_per_tok": 2,
27
+ "num_hidden_layers": 32,
28
+ "num_key_value_heads": 8,
29
+ "num_local_experts": 16,
30
+ "output_router_logits": false,
31
+ "rms_norm_eps": 1e-05,
32
+ "rope_scaling": null,
33
+ "rope_theta": 10000.0,
34
+ "router_aux_loss_coef": 0.0,
35
+ "router_jitter_noise": 0.01,
36
+ "sliding_window": 2047,
37
+ "tie_word_embeddings": false,
38
+ "transformers_version": "4.56.1",
39
+ "use_cache": false,
40
+ "use_grouped_mm": true,
41
+ "vocab_size": 32064
42
+ }
configuration_slimmoe.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 Microsoft and the HuggingFace Inc. 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
+
16
+ """ PyTorch Phi-MoE model."""
17
+
18
+
19
+ from transformers.configuration_utils import PretrainedConfig
20
+ from transformers.utils import logging
21
+
22
+
23
+ logger = logging.get_logger(__name__)
24
+
25
+
26
+ PHIMOE_PRETRAINED_CONFIG_ARCHIVE_MAP = {
27
+ "microsoft/Phi-3.5-MoE-instruct": "https://huggingface.co/microsoft/Phi-3.5-MoE-instruct/resolve/main/config.json",
28
+ }
29
+
30
+ class PhiMoEConfig(PretrainedConfig):
31
+ r"""
32
+ This is the configuration class to store the configuration of a [`PhiMoEModel`]. It is used to instantiate a Phi-MoE
33
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
34
+ defaults will yield a similar configuration to that of the
35
+ [microsoft/Phi-3.5-MoE-instruct](https://huggingface.co/microsoft/Phi-3.5-MoE-instruct).
36
+
37
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
38
+ documentation from [`PretrainedConfig`] for more information.
39
+
40
+
41
+ Args:
42
+ vocab_size (`int`, *optional*, defaults to 32064):
43
+ Vocabulary size of the PhiMoE model. Defines the number of different tokens that can be represented by the
44
+ `inputs_ids` passed when calling [`PhiMoEModel`]
45
+ hidden_size (`int`, *optional*, defaults to 4096):
46
+ Dimension of the hidden representations.
47
+ intermediate_size (`int`, *optional*, defaults to 6400):
48
+ Dimension of the MLP representations.
49
+ num_hidden_layers (`int`, *optional*, defaults to 32):
50
+ Number of hidden layers in the Transformer encoder.
51
+ num_attention_heads (`int`, *optional*, defaults to 32):
52
+ Number of attention heads for each attention layer in the Transformer encoder.
53
+ num_key_value_heads (`int`, *optional*, defaults to 8):
54
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
55
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
56
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
57
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
58
+ by meanpooling all the original heads within that group. For more details checkout [this
59
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `8`.
60
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
61
+ The non-linear activation function (function or string) in the decoder.
62
+ max_position_embeddings (`int`, *optional*, defaults to `4096*32`):
63
+ The maximum sequence length that this model might ever be used with. Mixtral's sliding window attention
64
+ allows sequence of up to 4096*32 tokens.
65
+ initializer_range (`float`, *optional*, defaults to 0.02):
66
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
67
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
68
+ The epsilon used by the rms normalization layers.
69
+ use_cache (`bool`, *optional*, defaults to `True`):
70
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
71
+ relevant if `config.is_decoder=True`.
72
+ pad_token_id (`int`, *optional*):
73
+ The id of the padding token.
74
+ bos_token_id (`int`, *optional*, defaults to 1):
75
+ The id of the "beginning-of-sequence" token.
76
+ eos_token_id (`int`, *optional*, defaults to 2):
77
+ The id of the "end-of-sequence" token.
78
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
79
+ Whether the model's input and output word embeddings should be tied.
80
+ rope_theta (`float`, *optional*, defaults to 10000.0):
81
+ The base period of the RoPE embeddings.
82
+ rope_scaling (`dict`, *optional*):
83
+ The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
84
+ contain the following keys: `type`, `short_factor`, `long_factor`, `short_mscale`, `long_mscale` and
85
+ `original_max_position_embeddings`. The `type` must be `longrope`, the `short_mscale` and `long_scale` must
86
+ be numbers, the `short_factor` and `long_factor` must be lists of numbers with the same length as half of
87
+ the attention head size and the `original_max_position_embeddings` must be an integer.
88
+ sliding_window (`int`, *optional*):
89
+ Sliding window attention window size. If not specified, will default to `262144`.
90
+ attention_dropout (`float`, *optional*, defaults to 0.0):
91
+ The dropout ratio for the attention probabilities.
92
+ num_experts_per_tok (`int`, *optional*, defaults to 2):
93
+ The number of experts to root per-token, can be also interpreted as the `top-p` routing
94
+ parameter
95
+ num_local_experts (`int`, *optional*, defaults to 16):
96
+ Number of experts per Sparse MLP layer.
97
+ output_router_logits (`bool`, *optional*, defaults to `False`):
98
+ Whether or not the router logits should be returned by the model. Enabeling this will also
99
+ allow the model to output the auxiliary loss. See [here]() for more details
100
+ router_aux_loss_coef (`float`, *optional*, defaults to 0.0):
101
+ The aux loss factor for the total loss.
102
+ router_jitter_noise (`float`, *optional*, defaults to 0.01):
103
+ Amount of noise to add to the router.
104
+
105
+ ```python
106
+ >>> from transformers import PhiMoEModel, PhiMoEConfig
107
+
108
+ >>> # Initializing a Phi-3 style configuration
109
+ >>> configuration = PhiMoEConfig.from_pretrained("microsoft/Phi-3.5-MoE-instruct")
110
+
111
+ >>> # Initializing a model from the configuration
112
+ >>> model = PhiMoEModel(configuration)
113
+
114
+ >>> # Accessing the model configuration
115
+ >>> configuration = model.config
116
+ ```"""
117
+
118
+ model_type = "phimoe"
119
+ keys_to_ignore_at_inference = ["past_key_values"]
120
+
121
+ def __init__(
122
+ self,
123
+ vocab_size=32064,
124
+ hidden_size=4096,
125
+ intermediate_size=6400,
126
+ num_hidden_layers=32,
127
+ num_attention_heads=32,
128
+ num_key_value_heads=8,
129
+ head_dim=None, # added to control head dimension
130
+ hidden_act="silu",
131
+ max_position_embeddings=4096 * 32,
132
+ initializer_range=0.02,
133
+ rms_norm_eps=1e-5,
134
+ use_cache=True,
135
+ pad_token_id=None,
136
+ bos_token_id=1,
137
+ eos_token_id=2,
138
+ tie_word_embeddings=False,
139
+ rope_theta=1e6,
140
+ rope_scaling=None,
141
+ sliding_window=None,
142
+ attention_dropout=0.0,
143
+ num_experts_per_tok=2,
144
+ num_local_experts=16,
145
+ output_router_logits=False,
146
+ router_aux_loss_coef=0.001,
147
+ router_jitter_noise=0.01,
148
+ input_jitter_noise=0.0,
149
+ attention_bias = False,
150
+ lm_head_bias = False,
151
+ **kwargs,
152
+ ):
153
+ self.vocab_size = vocab_size
154
+ self.max_position_embeddings = max_position_embeddings
155
+ self.hidden_size = hidden_size
156
+ self.intermediate_size = intermediate_size
157
+ self.num_hidden_layers = num_hidden_layers
158
+ self.num_attention_heads = num_attention_heads
159
+ self.sliding_window = sliding_window
160
+ self.attention_bias = attention_bias
161
+ self.lm_head_bias = lm_head_bias
162
+ # for backward compatibility
163
+ if num_key_value_heads is None:
164
+ num_key_value_heads = num_attention_heads
165
+ if head_dim is None:
166
+ head_dim = hidden_size // num_attention_heads
167
+
168
+ self.head_dim = head_dim
169
+ self.num_key_value_heads = num_key_value_heads
170
+ self.hidden_act = hidden_act
171
+ self.initializer_range = initializer_range
172
+ self.rms_norm_eps = rms_norm_eps
173
+ self.use_cache = use_cache
174
+ self.rope_theta = rope_theta
175
+ self.attention_dropout = attention_dropout
176
+
177
+ self.num_experts_per_tok = num_experts_per_tok
178
+ self.num_local_experts = num_local_experts
179
+ self.output_router_logits = output_router_logits
180
+ self.router_aux_loss_coef = router_aux_loss_coef
181
+ self.router_jitter_noise = router_jitter_noise
182
+ self.input_jitter_noise = input_jitter_noise
183
+
184
+ self.rope_scaling = rope_scaling
185
+ self._rope_scaling_validation()
186
+
187
+ super().__init__(
188
+ pad_token_id=pad_token_id,
189
+ bos_token_id=bos_token_id,
190
+ eos_token_id=eos_token_id,
191
+ tie_word_embeddings=tie_word_embeddings,
192
+ **kwargs,
193
+ )
194
+
195
+ def _rope_scaling_validation(self):
196
+ """
197
+ Validate the `rope_scaling` configuration.
198
+ """
199
+ if self.rope_scaling is None:
200
+ return
201
+
202
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 6:
203
+ raise ValueError(
204
+ "`rope_scaling` must be a dictionary with three fields, `type`, `short_factor`, `long_factor`, "
205
+ f"`short_mscale`, `long_mscale` and `original_max_position_embeddings`, got {self.rope_scaling}"
206
+ )
207
+ rope_scaling_type = self.rope_scaling.get("type", None)
208
+ rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
209
+ rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
210
+ rope_scaling_short_mscale = self.rope_scaling.get("short_mscale", None)
211
+ rope_scaling_long_mscale = self.rope_scaling.get("long_mscale", None)
212
+ original_max_position_embeddings = self.rope_scaling.get("original_max_position_embeddings", None)
213
+ if rope_scaling_type is None or rope_scaling_type not in ["longrope"]:
214
+ raise ValueError(f"`rope_scaling`'s type field must be one of ['longrope'], got {rope_scaling_type}")
215
+ if not (
216
+ isinstance(rope_scaling_short_factor, list)
217
+ and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
218
+ ):
219
+ raise ValueError(
220
+ f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
221
+ )
222
+ if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
223
+ raise ValueError(
224
+ f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
225
+ )
226
+ if not (
227
+ isinstance(rope_scaling_long_factor, list)
228
+ and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
229
+ ):
230
+ raise ValueError(
231
+ f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
232
+ )
233
+ if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
234
+ raise ValueError(
235
+ f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
236
+ )
237
+ if not isinstance(rope_scaling_short_mscale, (int, float)):
238
+ raise ValueError(
239
+ f"`rope_scaling`'s short_mscale field must be a number, got {rope_scaling_short_mscale}"
240
+ )
241
+ if not isinstance(rope_scaling_long_mscale, (int, float)):
242
+ raise ValueError(
243
+ f"`rope_scaling`'s long_mscale field must be a number, got {rope_scaling_long_mscale}"
244
+ )
245
+ if not isinstance(original_max_position_embeddings, int):
246
+ raise ValueError(
247
+ f"`rope_scaling`'s original_max_position_embeddings field must be an integer, got {original_max_position_embeddings}"
248
+ )
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": [
5
+ 32000,
6
+ 32001,
7
+ 32007
8
+ ],
9
+ "pad_token_id": 32000,
10
+ "transformers_version": "4.56.1"
11
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:997f35287bc5fac9290e044980d1aae7b588b9aa9d8b4a3bb116fbe088ac9b0b
3
+ size 15295942764
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "<|endoftext|>",
17
+ "unk_token": {
18
+ "content": "<unk>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
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": true,
27
+ "single_word": false,
28
+ "special": false
29
+ },
30
+ "32000": {
31
+ "content": "<|endoftext|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "32001": {
39
+ "content": "<|assistant|>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": true,
43
+ "single_word": false,
44
+ "special": true
45
+ },
46
+ "32002": {
47
+ "content": "<|placeholder1|>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": true,
51
+ "single_word": false,
52
+ "special": true
53
+ },
54
+ "32003": {
55
+ "content": "<|placeholder2|>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": true,
59
+ "single_word": false,
60
+ "special": true
61
+ },
62
+ "32004": {
63
+ "content": "<|placeholder3|>",
64
+ "lstrip": false,
65
+ "normalized": false,
66
+ "rstrip": true,
67
+ "single_word": false,
68
+ "special": true
69
+ },
70
+ "32005": {
71
+ "content": "<|placeholder4|>",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": true,
75
+ "single_word": false,
76
+ "special": true
77
+ },
78
+ "32006": {
79
+ "content": "<|system|>",
80
+ "lstrip": false,
81
+ "normalized": false,
82
+ "rstrip": true,
83
+ "single_word": false,
84
+ "special": true
85
+ },
86
+ "32007": {
87
+ "content": "<|end|>",
88
+ "lstrip": false,
89
+ "normalized": false,
90
+ "rstrip": true,
91
+ "single_word": false,
92
+ "special": true
93
+ },
94
+ "32008": {
95
+ "content": "<|placeholder5|>",
96
+ "lstrip": false,
97
+ "normalized": false,
98
+ "rstrip": true,
99
+ "single_word": false,
100
+ "special": true
101
+ },
102
+ "32009": {
103
+ "content": "<|placeholder6|>",
104
+ "lstrip": false,
105
+ "normalized": false,
106
+ "rstrip": true,
107
+ "single_word": false,
108
+ "special": true
109
+ },
110
+ "32010": {
111
+ "content": "<|user|>",
112
+ "lstrip": false,
113
+ "normalized": false,
114
+ "rstrip": true,
115
+ "single_word": false,
116
+ "special": true
117
+ }
118
+ },
119
+ "bos_token": "<s>",
120
+ "clean_up_tokenization_spaces": false,
121
+ "eos_token": "<|endoftext|>",
122
+ "extra_special_tokens": {},
123
+ "legacy": false,
124
+ "model_max_length": 4096,
125
+ "pad_token": "<|endoftext|>",
126
+ "padding_side": "left",
127
+ "sp_model_kwargs": {},
128
+ "tokenizer_class": "LlamaTokenizerFast",
129
+ "unk_token": "<unk>",
130
+ "use_default_system_prompt": false
131
+ }