lokinfey commited on
Commit
b119aa7
1 Parent(s): 80abfa5

init models

Browse files
added_tokens.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "<|assistant|>": 32001,
3
+ "<|endoftext|>": 32000,
4
+ "<|end|>": 32007,
5
+ "<|placeholder1|>": 32002,
6
+ "<|placeholder2|>": 32003,
7
+ "<|placeholder3|>": 32004,
8
+ "<|placeholder4|>": 32005,
9
+ "<|placeholder5|>": 32008,
10
+ "<|placeholder6|>": 32009,
11
+ "<|system|>": 32006,
12
+ "<|user|>": 32010
13
+ }
config.json ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "PhiMoEForCausalLM"
4
+ ],
5
+ "attention_bias": true,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_phimoe.PhiMoEConfig",
9
+ "AutoModelForCausalLM": "modeling_phimoe.PhiMoEForCausalLM"
10
+ },
11
+ "bos_token_id": 1,
12
+ "eos_token_id": 32000,
13
+ "hidden_act": "silu",
14
+ "hidden_dropout": 0.0,
15
+ "hidden_size": 4096,
16
+ "initializer_range": 0.02,
17
+ "input_jitter_noise": 0.01,
18
+ "intermediate_size": 6400,
19
+ "lm_head_bias": true,
20
+ "max_position_embeddings": 131072,
21
+ "model_type": "phimoe",
22
+ "num_attention_heads": 32,
23
+ "num_experts_per_tok": 2,
24
+ "num_hidden_layers": 32,
25
+ "num_key_value_heads": 8,
26
+ "num_local_experts": 16,
27
+ "original_max_position_embeddings": 4096,
28
+ "output_router_logits": false,
29
+ "quantization": {
30
+ "group_size": 64,
31
+ "bits": 4
32
+ },
33
+ "rms_norm_eps": 1e-05,
34
+ "rope_scaling": {
35
+ "long_factor": [
36
+ 1.0199999809265137,
37
+ 1.0299999713897705,
38
+ 1.0399999618530273,
39
+ 1.0499999523162842,
40
+ 1.0499999523162842,
41
+ 1.0499999523162842,
42
+ 1.059999942779541,
43
+ 1.059999942779541,
44
+ 1.059999942779541,
45
+ 1.059999942779541,
46
+ 1.059999942779541,
47
+ 1.059999942779541,
48
+ 1.0999999046325684,
49
+ 1.1799999475479126,
50
+ 1.1799999475479126,
51
+ 1.3700000047683716,
52
+ 1.4899998903274536,
53
+ 2.109999895095825,
54
+ 2.8899998664855957,
55
+ 3.9499998092651367,
56
+ 4.299999713897705,
57
+ 6.429999828338623,
58
+ 8.09000015258789,
59
+ 10.690000534057617,
60
+ 12.050000190734863,
61
+ 18.229999542236328,
62
+ 18.84000015258789,
63
+ 19.899999618530273,
64
+ 21.420000076293945,
65
+ 26.200000762939453,
66
+ 34.28000259399414,
67
+ 34.590003967285156,
68
+ 38.730003356933594,
69
+ 40.22000503540039,
70
+ 42.54000473022461,
71
+ 44.000003814697266,
72
+ 47.590003967285156,
73
+ 54.750003814697266,
74
+ 56.19000244140625,
75
+ 57.44000244140625,
76
+ 57.4900016784668,
77
+ 61.20000076293945,
78
+ 61.540000915527344,
79
+ 61.75,
80
+ 61.779998779296875,
81
+ 62.06999969482422,
82
+ 63.11000061035156,
83
+ 63.43000030517578,
84
+ 63.560001373291016,
85
+ 63.71000289916992,
86
+ 63.92000198364258,
87
+ 63.94000244140625,
88
+ 63.94000244140625,
89
+ 63.96000289916992,
90
+ 63.980003356933594,
91
+ 64.0300064086914,
92
+ 64.0300064086914,
93
+ 64.0300064086914,
94
+ 64.04000854492188,
95
+ 64.10000610351562,
96
+ 64.19000244140625,
97
+ 64.20999908447266,
98
+ 64.75,
99
+ 64.95999908447266
100
+ ],
101
+ "long_mscale": 1.243163121016122,
102
+ "original_max_position_embeddings": 4096,
103
+ "short_factor": [
104
+ 1.0,
105
+ 1.0399999618530273,
106
+ 1.0399999618530273,
107
+ 1.0399999618530273,
108
+ 1.0499999523162842,
109
+ 1.0499999523162842,
110
+ 1.0499999523162842,
111
+ 1.0499999523162842,
112
+ 1.0499999523162842,
113
+ 1.0499999523162842,
114
+ 1.0499999523162842,
115
+ 1.0499999523162842,
116
+ 1.0499999523162842,
117
+ 1.0499999523162842,
118
+ 1.059999942779541,
119
+ 1.059999942779541,
120
+ 1.0699999332427979,
121
+ 1.0699999332427979,
122
+ 1.0699999332427979,
123
+ 1.0699999332427979,
124
+ 1.1399999856948853,
125
+ 1.159999966621399,
126
+ 1.159999966621399,
127
+ 1.159999966621399,
128
+ 1.159999966621399,
129
+ 1.1799999475479126,
130
+ 1.1999999284744263,
131
+ 1.3199999332427979,
132
+ 1.3399999141693115,
133
+ 1.3499999046325684,
134
+ 1.3999998569488525,
135
+ 1.4799998998641968,
136
+ 1.4999998807907104,
137
+ 1.589999794960022,
138
+ 1.6499998569488525,
139
+ 1.71999990940094,
140
+ 1.8999998569488525,
141
+ 1.9099998474121094,
142
+ 1.9099998474121094,
143
+ 1.9899998903274536,
144
+ 1.9999998807907104,
145
+ 1.9999998807907104,
146
+ 2.009999990463257,
147
+ 2.009999990463257,
148
+ 2.009999990463257,
149
+ 2.009999990463257,
150
+ 2.009999990463257,
151
+ 2.009999990463257,
152
+ 2.009999990463257,
153
+ 2.009999990463257,
154
+ 2.009999990463257,
155
+ 2.009999990463257,
156
+ 2.009999990463257,
157
+ 2.009999990463257,
158
+ 2.009999990463257,
159
+ 2.009999990463257,
160
+ 2.009999990463257,
161
+ 2.009999990463257,
162
+ 2.009999990463257,
163
+ 2.0999999046325684,
164
+ 2.319999933242798,
165
+ 2.419999837875366,
166
+ 2.5899999141693115,
167
+ 2.7899999618530273
168
+ ],
169
+ "short_mscale": 1.243163121016122,
170
+ "type": "longrope"
171
+ },
172
+ "rope_theta": 10000.0,
173
+ "router_aux_loss_coef": 0.0,
174
+ "router_jitter_noise": 0.01,
175
+ "sliding_window": 131072,
176
+ "tie_word_embeddings": false,
177
+ "torch_dtype": "bfloat16",
178
+ "transformers_version": "4.43.3",
179
+ "use_cache": true,
180
+ "vocab_size": 32064
181
+ }
configuration_phimoe.py ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ hidden_act="silu",
130
+ max_position_embeddings=4096 * 32,
131
+ initializer_range=0.02,
132
+ rms_norm_eps=1e-5,
133
+ use_cache=True,
134
+ pad_token_id=None,
135
+ bos_token_id=1,
136
+ eos_token_id=2,
137
+ tie_word_embeddings=False,
138
+ rope_theta=1e6,
139
+ rope_scaling=None,
140
+ sliding_window=None,
141
+ attention_dropout=0.0,
142
+ num_experts_per_tok=2,
143
+ num_local_experts=16,
144
+ output_router_logits=False,
145
+ router_aux_loss_coef=0.001,
146
+ router_jitter_noise=0.01,
147
+ input_jitter_noise=0.0,
148
+ attention_bias = False,
149
+ lm_head_bias = False,
150
+ **kwargs,
151
+ ):
152
+ self.vocab_size = vocab_size
153
+ self.max_position_embeddings = max_position_embeddings
154
+ self.hidden_size = hidden_size
155
+ self.intermediate_size = intermediate_size
156
+ self.num_hidden_layers = num_hidden_layers
157
+ self.num_attention_heads = num_attention_heads
158
+ self.sliding_window = sliding_window
159
+ self.attention_bias = attention_bias
160
+ self.lm_head_bias = lm_head_bias
161
+ # for backward compatibility
162
+ if num_key_value_heads is None:
163
+ num_key_value_heads = num_attention_heads
164
+
165
+ self.num_key_value_heads = num_key_value_heads
166
+ self.hidden_act = hidden_act
167
+ self.initializer_range = initializer_range
168
+ self.rms_norm_eps = rms_norm_eps
169
+ self.use_cache = use_cache
170
+ self.rope_theta = rope_theta
171
+ self.attention_dropout = attention_dropout
172
+
173
+ self.num_experts_per_tok = num_experts_per_tok
174
+ self.num_local_experts = num_local_experts
175
+ self.output_router_logits = output_router_logits
176
+ self.router_aux_loss_coef = router_aux_loss_coef
177
+ self.router_jitter_noise = router_jitter_noise
178
+ self.input_jitter_noise = input_jitter_noise
179
+
180
+ self.rope_scaling = rope_scaling
181
+ self._rope_scaling_validation()
182
+
183
+ super().__init__(
184
+ pad_token_id=pad_token_id,
185
+ bos_token_id=bos_token_id,
186
+ eos_token_id=eos_token_id,
187
+ tie_word_embeddings=tie_word_embeddings,
188
+ **kwargs,
189
+ )
190
+
191
+ def _rope_scaling_validation(self):
192
+ """
193
+ Validate the `rope_scaling` configuration.
194
+ """
195
+ if self.rope_scaling is None:
196
+ return
197
+
198
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 6:
199
+ raise ValueError(
200
+ "`rope_scaling` must be a dictionary with three fields, `type`, `short_factor`, `long_factor`, "
201
+ f"`short_mscale`, `long_mscale` and `original_max_position_embeddings`, got {self.rope_scaling}"
202
+ )
203
+ rope_scaling_type = self.rope_scaling.get("type", None)
204
+ rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
205
+ rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
206
+ rope_scaling_short_mscale = self.rope_scaling.get("short_mscale", None)
207
+ rope_scaling_long_mscale = self.rope_scaling.get("long_mscale", None)
208
+ original_max_position_embeddings = self.rope_scaling.get("original_max_position_embeddings", None)
209
+ if rope_scaling_type is None or rope_scaling_type not in ["longrope"]:
210
+ raise ValueError(f"`rope_scaling`'s type field must be one of ['longrope'], got {rope_scaling_type}")
211
+ if not (
212
+ isinstance(rope_scaling_short_factor, list)
213
+ and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
214
+ ):
215
+ raise ValueError(
216
+ f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
217
+ )
218
+ if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
219
+ raise ValueError(
220
+ f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
221
+ )
222
+ if not (
223
+ isinstance(rope_scaling_long_factor, list)
224
+ and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
225
+ ):
226
+ raise ValueError(
227
+ f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
228
+ )
229
+ if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
230
+ raise ValueError(
231
+ f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
232
+ )
233
+ if not isinstance(rope_scaling_short_mscale, (int, float)):
234
+ raise ValueError(
235
+ f"`rope_scaling`'s short_mscale field must be a number, got {rope_scaling_short_mscale}"
236
+ )
237
+ if not isinstance(rope_scaling_long_mscale, (int, float)):
238
+ raise ValueError(
239
+ f"`rope_scaling`'s long_mscale field must be a number, got {rope_scaling_long_mscale}"
240
+ )
241
+ if not isinstance(original_max_position_embeddings, int):
242
+ raise ValueError(
243
+ f"`rope_scaling`'s original_max_position_embeddings field must be an integer, got {original_max_position_embeddings}"
244
+ )
model-00001-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34b37531ef187c724ddb77f80243029641a3ed9db07c439855a35c6d4356a5a9
3
+ size 5217858148
model-00002-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:775a0d0b64993cede54c7820b699c8ef5aa840a07e2e0466b43715c1376f33b4
3
+ size 5356260178
model-00003-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd6947b0d5e60b791b837bf977bff706346f95ca01da547e19928e44dfa106a1
3
+ size 5356260243
model-00004-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4724ee7ec2e004d848c29b77a99d81f6f74cec062ff900a8c0547d31412968d2
3
+ size 5368101097
model-00005-of-00005.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5e7be20f8e19d1962ea1b8b0b4d698f1d56a3557a60e6932f222f40858256a2
3
+ size 2256576091
model.safetensors.index.json ADDED
@@ -0,0 +1,1040 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 23554931328
4
+ },
5
+ "weight_map": {
6
+ "lm_head.bias": "model-00005-of-00005.safetensors",
7
+ "lm_head.biases": "model-00005-of-00005.safetensors",
8
+ "lm_head.scales": "model-00005-of-00005.safetensors",
9
+ "lm_head.weight": "model-00005-of-00005.safetensors",
10
+ "model.embed_tokens.biases": "model-00001-of-00005.safetensors",
11
+ "model.embed_tokens.scales": "model-00001-of-00005.safetensors",
12
+ "model.embed_tokens.weight": "model-00001-of-00005.safetensors",
13
+ "model.layers.0.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
14
+ "model.layers.0.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
15
+ "model.layers.0.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
16
+ "model.layers.0.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
17
+ "model.layers.0.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
18
+ "model.layers.0.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
19
+ "model.layers.0.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
20
+ "model.layers.0.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
21
+ "model.layers.0.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
22
+ "model.layers.0.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
23
+ "model.layers.0.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
24
+ "model.layers.0.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
25
+ "model.layers.0.input_layernorm.bias": "model-00001-of-00005.safetensors",
26
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00005.safetensors",
27
+ "model.layers.0.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
28
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
29
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
30
+ "model.layers.0.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
31
+ "model.layers.0.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
32
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
33
+ "model.layers.0.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
34
+ "model.layers.0.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
35
+ "model.layers.0.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
36
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
37
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
38
+ "model.layers.0.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
39
+ "model.layers.0.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
40
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
41
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
42
+ "model.layers.0.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
43
+ "model.layers.0.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
44
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
45
+ "model.layers.1.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
46
+ "model.layers.1.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
47
+ "model.layers.1.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
48
+ "model.layers.1.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
49
+ "model.layers.1.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
50
+ "model.layers.1.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
51
+ "model.layers.1.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
52
+ "model.layers.1.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
53
+ "model.layers.1.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
54
+ "model.layers.1.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
55
+ "model.layers.1.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
56
+ "model.layers.1.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
57
+ "model.layers.1.input_layernorm.bias": "model-00001-of-00005.safetensors",
58
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00005.safetensors",
59
+ "model.layers.1.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
60
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
61
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
62
+ "model.layers.1.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
63
+ "model.layers.1.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
64
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
65
+ "model.layers.1.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
66
+ "model.layers.1.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
67
+ "model.layers.1.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
68
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
69
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
70
+ "model.layers.1.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
71
+ "model.layers.1.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
72
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
73
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
74
+ "model.layers.1.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
75
+ "model.layers.1.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
76
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
77
+ "model.layers.10.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
78
+ "model.layers.10.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
79
+ "model.layers.10.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
80
+ "model.layers.10.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
81
+ "model.layers.10.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
82
+ "model.layers.10.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
83
+ "model.layers.10.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
84
+ "model.layers.10.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
85
+ "model.layers.10.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
86
+ "model.layers.10.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
87
+ "model.layers.10.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
88
+ "model.layers.10.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
89
+ "model.layers.10.input_layernorm.bias": "model-00002-of-00005.safetensors",
90
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00005.safetensors",
91
+ "model.layers.10.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
92
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
93
+ "model.layers.10.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
94
+ "model.layers.10.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
95
+ "model.layers.10.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
96
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
97
+ "model.layers.10.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
98
+ "model.layers.10.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
99
+ "model.layers.10.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
100
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
101
+ "model.layers.10.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
102
+ "model.layers.10.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
103
+ "model.layers.10.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
104
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
105
+ "model.layers.10.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
106
+ "model.layers.10.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
107
+ "model.layers.10.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
108
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
109
+ "model.layers.11.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
110
+ "model.layers.11.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
111
+ "model.layers.11.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
112
+ "model.layers.11.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
113
+ "model.layers.11.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
114
+ "model.layers.11.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
115
+ "model.layers.11.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
116
+ "model.layers.11.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
117
+ "model.layers.11.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
118
+ "model.layers.11.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
119
+ "model.layers.11.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
120
+ "model.layers.11.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
121
+ "model.layers.11.input_layernorm.bias": "model-00002-of-00005.safetensors",
122
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00005.safetensors",
123
+ "model.layers.11.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
124
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
125
+ "model.layers.11.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
126
+ "model.layers.11.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
127
+ "model.layers.11.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
128
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
129
+ "model.layers.11.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
130
+ "model.layers.11.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
131
+ "model.layers.11.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
132
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
133
+ "model.layers.11.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
134
+ "model.layers.11.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
135
+ "model.layers.11.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
136
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
137
+ "model.layers.11.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
138
+ "model.layers.11.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
139
+ "model.layers.11.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
140
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
141
+ "model.layers.12.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
142
+ "model.layers.12.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
143
+ "model.layers.12.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
144
+ "model.layers.12.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
145
+ "model.layers.12.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
146
+ "model.layers.12.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
147
+ "model.layers.12.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
148
+ "model.layers.12.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
149
+ "model.layers.12.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
150
+ "model.layers.12.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
151
+ "model.layers.12.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
152
+ "model.layers.12.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
153
+ "model.layers.12.input_layernorm.bias": "model-00002-of-00005.safetensors",
154
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00005.safetensors",
155
+ "model.layers.12.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
156
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
157
+ "model.layers.12.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
158
+ "model.layers.12.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
159
+ "model.layers.12.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
160
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
161
+ "model.layers.12.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
162
+ "model.layers.12.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
163
+ "model.layers.12.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
164
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
165
+ "model.layers.12.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
166
+ "model.layers.12.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
167
+ "model.layers.12.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
168
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
169
+ "model.layers.12.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
170
+ "model.layers.12.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
171
+ "model.layers.12.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
172
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
173
+ "model.layers.13.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
174
+ "model.layers.13.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
175
+ "model.layers.13.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
176
+ "model.layers.13.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
177
+ "model.layers.13.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
178
+ "model.layers.13.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
179
+ "model.layers.13.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
180
+ "model.layers.13.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
181
+ "model.layers.13.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
182
+ "model.layers.13.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
183
+ "model.layers.13.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
184
+ "model.layers.13.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
185
+ "model.layers.13.input_layernorm.bias": "model-00002-of-00005.safetensors",
186
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00005.safetensors",
187
+ "model.layers.13.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
188
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
189
+ "model.layers.13.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
190
+ "model.layers.13.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
191
+ "model.layers.13.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
192
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
193
+ "model.layers.13.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
194
+ "model.layers.13.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
195
+ "model.layers.13.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
196
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
197
+ "model.layers.13.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
198
+ "model.layers.13.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
199
+ "model.layers.13.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
200
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
201
+ "model.layers.13.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
202
+ "model.layers.13.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
203
+ "model.layers.13.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
204
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
205
+ "model.layers.14.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
206
+ "model.layers.14.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
207
+ "model.layers.14.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
208
+ "model.layers.14.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
209
+ "model.layers.14.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
210
+ "model.layers.14.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
211
+ "model.layers.14.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
212
+ "model.layers.14.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
213
+ "model.layers.14.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
214
+ "model.layers.14.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
215
+ "model.layers.14.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
216
+ "model.layers.14.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
217
+ "model.layers.14.input_layernorm.bias": "model-00003-of-00005.safetensors",
218
+ "model.layers.14.input_layernorm.weight": "model-00003-of-00005.safetensors",
219
+ "model.layers.14.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
220
+ "model.layers.14.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
221
+ "model.layers.14.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
222
+ "model.layers.14.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
223
+ "model.layers.14.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
224
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
225
+ "model.layers.14.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
226
+ "model.layers.14.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
227
+ "model.layers.14.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
228
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
229
+ "model.layers.14.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
230
+ "model.layers.14.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
231
+ "model.layers.14.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
232
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
233
+ "model.layers.14.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
234
+ "model.layers.14.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
235
+ "model.layers.14.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
236
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
237
+ "model.layers.15.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
238
+ "model.layers.15.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
239
+ "model.layers.15.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
240
+ "model.layers.15.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
241
+ "model.layers.15.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
242
+ "model.layers.15.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
243
+ "model.layers.15.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
244
+ "model.layers.15.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
245
+ "model.layers.15.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
246
+ "model.layers.15.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
247
+ "model.layers.15.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
248
+ "model.layers.15.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
249
+ "model.layers.15.input_layernorm.bias": "model-00003-of-00005.safetensors",
250
+ "model.layers.15.input_layernorm.weight": "model-00003-of-00005.safetensors",
251
+ "model.layers.15.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
252
+ "model.layers.15.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
253
+ "model.layers.15.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
254
+ "model.layers.15.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
255
+ "model.layers.15.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
256
+ "model.layers.15.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
257
+ "model.layers.15.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
258
+ "model.layers.15.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
259
+ "model.layers.15.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
260
+ "model.layers.15.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
261
+ "model.layers.15.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
262
+ "model.layers.15.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
263
+ "model.layers.15.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
264
+ "model.layers.15.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
265
+ "model.layers.15.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
266
+ "model.layers.15.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
267
+ "model.layers.15.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
268
+ "model.layers.15.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
269
+ "model.layers.16.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
270
+ "model.layers.16.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
271
+ "model.layers.16.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
272
+ "model.layers.16.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
273
+ "model.layers.16.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
274
+ "model.layers.16.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
275
+ "model.layers.16.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
276
+ "model.layers.16.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
277
+ "model.layers.16.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
278
+ "model.layers.16.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
279
+ "model.layers.16.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
280
+ "model.layers.16.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
281
+ "model.layers.16.input_layernorm.bias": "model-00003-of-00005.safetensors",
282
+ "model.layers.16.input_layernorm.weight": "model-00003-of-00005.safetensors",
283
+ "model.layers.16.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
284
+ "model.layers.16.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
285
+ "model.layers.16.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
286
+ "model.layers.16.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
287
+ "model.layers.16.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
288
+ "model.layers.16.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
289
+ "model.layers.16.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
290
+ "model.layers.16.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
291
+ "model.layers.16.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
292
+ "model.layers.16.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
293
+ "model.layers.16.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
294
+ "model.layers.16.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
295
+ "model.layers.16.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
296
+ "model.layers.16.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
297
+ "model.layers.16.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
298
+ "model.layers.16.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
299
+ "model.layers.16.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
300
+ "model.layers.16.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
301
+ "model.layers.17.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
302
+ "model.layers.17.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
303
+ "model.layers.17.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
304
+ "model.layers.17.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
305
+ "model.layers.17.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
306
+ "model.layers.17.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
307
+ "model.layers.17.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
308
+ "model.layers.17.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
309
+ "model.layers.17.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
310
+ "model.layers.17.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
311
+ "model.layers.17.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
312
+ "model.layers.17.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
313
+ "model.layers.17.input_layernorm.bias": "model-00003-of-00005.safetensors",
314
+ "model.layers.17.input_layernorm.weight": "model-00003-of-00005.safetensors",
315
+ "model.layers.17.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
316
+ "model.layers.17.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
317
+ "model.layers.17.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
318
+ "model.layers.17.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
319
+ "model.layers.17.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
320
+ "model.layers.17.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
321
+ "model.layers.17.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
322
+ "model.layers.17.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
323
+ "model.layers.17.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
324
+ "model.layers.17.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
325
+ "model.layers.17.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
326
+ "model.layers.17.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
327
+ "model.layers.17.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
328
+ "model.layers.17.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
329
+ "model.layers.17.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
330
+ "model.layers.17.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
331
+ "model.layers.17.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
332
+ "model.layers.17.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
333
+ "model.layers.18.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
334
+ "model.layers.18.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
335
+ "model.layers.18.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
336
+ "model.layers.18.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
337
+ "model.layers.18.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
338
+ "model.layers.18.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
339
+ "model.layers.18.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
340
+ "model.layers.18.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
341
+ "model.layers.18.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
342
+ "model.layers.18.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
343
+ "model.layers.18.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
344
+ "model.layers.18.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
345
+ "model.layers.18.input_layernorm.bias": "model-00003-of-00005.safetensors",
346
+ "model.layers.18.input_layernorm.weight": "model-00003-of-00005.safetensors",
347
+ "model.layers.18.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
348
+ "model.layers.18.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
349
+ "model.layers.18.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
350
+ "model.layers.18.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
351
+ "model.layers.18.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
352
+ "model.layers.18.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
353
+ "model.layers.18.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
354
+ "model.layers.18.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
355
+ "model.layers.18.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
356
+ "model.layers.18.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
357
+ "model.layers.18.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
358
+ "model.layers.18.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
359
+ "model.layers.18.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
360
+ "model.layers.18.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
361
+ "model.layers.18.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
362
+ "model.layers.18.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
363
+ "model.layers.18.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
364
+ "model.layers.18.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
365
+ "model.layers.19.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
366
+ "model.layers.19.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
367
+ "model.layers.19.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
368
+ "model.layers.19.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
369
+ "model.layers.19.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
370
+ "model.layers.19.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
371
+ "model.layers.19.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
372
+ "model.layers.19.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
373
+ "model.layers.19.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
374
+ "model.layers.19.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
375
+ "model.layers.19.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
376
+ "model.layers.19.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
377
+ "model.layers.19.input_layernorm.bias": "model-00003-of-00005.safetensors",
378
+ "model.layers.19.input_layernorm.weight": "model-00003-of-00005.safetensors",
379
+ "model.layers.19.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
380
+ "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
381
+ "model.layers.19.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
382
+ "model.layers.19.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
383
+ "model.layers.19.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
384
+ "model.layers.19.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
385
+ "model.layers.19.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
386
+ "model.layers.19.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
387
+ "model.layers.19.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
388
+ "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
389
+ "model.layers.19.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
390
+ "model.layers.19.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
391
+ "model.layers.19.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
392
+ "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
393
+ "model.layers.19.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
394
+ "model.layers.19.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
395
+ "model.layers.19.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
396
+ "model.layers.19.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
397
+ "model.layers.2.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
398
+ "model.layers.2.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
399
+ "model.layers.2.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
400
+ "model.layers.2.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
401
+ "model.layers.2.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
402
+ "model.layers.2.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
403
+ "model.layers.2.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
404
+ "model.layers.2.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
405
+ "model.layers.2.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
406
+ "model.layers.2.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
407
+ "model.layers.2.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
408
+ "model.layers.2.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
409
+ "model.layers.2.input_layernorm.bias": "model-00001-of-00005.safetensors",
410
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00005.safetensors",
411
+ "model.layers.2.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
412
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
413
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
414
+ "model.layers.2.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
415
+ "model.layers.2.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
416
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
417
+ "model.layers.2.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
418
+ "model.layers.2.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
419
+ "model.layers.2.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
420
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
421
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
422
+ "model.layers.2.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
423
+ "model.layers.2.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
424
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
425
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
426
+ "model.layers.2.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
427
+ "model.layers.2.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
428
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
429
+ "model.layers.20.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
430
+ "model.layers.20.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
431
+ "model.layers.20.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
432
+ "model.layers.20.block_sparse_moe.switch_mlp.down_proj.biases": "model-00003-of-00005.safetensors",
433
+ "model.layers.20.block_sparse_moe.switch_mlp.down_proj.scales": "model-00003-of-00005.safetensors",
434
+ "model.layers.20.block_sparse_moe.switch_mlp.down_proj.weight": "model-00003-of-00005.safetensors",
435
+ "model.layers.20.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
436
+ "model.layers.20.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
437
+ "model.layers.20.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
438
+ "model.layers.20.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
439
+ "model.layers.20.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
440
+ "model.layers.20.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
441
+ "model.layers.20.input_layernorm.bias": "model-00003-of-00005.safetensors",
442
+ "model.layers.20.input_layernorm.weight": "model-00003-of-00005.safetensors",
443
+ "model.layers.20.post_attention_layernorm.bias": "model-00003-of-00005.safetensors",
444
+ "model.layers.20.post_attention_layernorm.weight": "model-00003-of-00005.safetensors",
445
+ "model.layers.20.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
446
+ "model.layers.20.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
447
+ "model.layers.20.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
448
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
449
+ "model.layers.20.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
450
+ "model.layers.20.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
451
+ "model.layers.20.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
452
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
453
+ "model.layers.20.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
454
+ "model.layers.20.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
455
+ "model.layers.20.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
456
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
457
+ "model.layers.20.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
458
+ "model.layers.20.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
459
+ "model.layers.20.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
460
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
461
+ "model.layers.21.block_sparse_moe.gate.biases": "model-00003-of-00005.safetensors",
462
+ "model.layers.21.block_sparse_moe.gate.scales": "model-00003-of-00005.safetensors",
463
+ "model.layers.21.block_sparse_moe.gate.weight": "model-00003-of-00005.safetensors",
464
+ "model.layers.21.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
465
+ "model.layers.21.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
466
+ "model.layers.21.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
467
+ "model.layers.21.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00003-of-00005.safetensors",
468
+ "model.layers.21.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00003-of-00005.safetensors",
469
+ "model.layers.21.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00003-of-00005.safetensors",
470
+ "model.layers.21.block_sparse_moe.switch_mlp.up_proj.biases": "model-00003-of-00005.safetensors",
471
+ "model.layers.21.block_sparse_moe.switch_mlp.up_proj.scales": "model-00003-of-00005.safetensors",
472
+ "model.layers.21.block_sparse_moe.switch_mlp.up_proj.weight": "model-00003-of-00005.safetensors",
473
+ "model.layers.21.input_layernorm.bias": "model-00004-of-00005.safetensors",
474
+ "model.layers.21.input_layernorm.weight": "model-00004-of-00005.safetensors",
475
+ "model.layers.21.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
476
+ "model.layers.21.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
477
+ "model.layers.21.self_attn.k_proj.bias": "model-00003-of-00005.safetensors",
478
+ "model.layers.21.self_attn.k_proj.biases": "model-00003-of-00005.safetensors",
479
+ "model.layers.21.self_attn.k_proj.scales": "model-00003-of-00005.safetensors",
480
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00005.safetensors",
481
+ "model.layers.21.self_attn.o_proj.bias": "model-00003-of-00005.safetensors",
482
+ "model.layers.21.self_attn.o_proj.biases": "model-00003-of-00005.safetensors",
483
+ "model.layers.21.self_attn.o_proj.scales": "model-00003-of-00005.safetensors",
484
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00005.safetensors",
485
+ "model.layers.21.self_attn.q_proj.bias": "model-00003-of-00005.safetensors",
486
+ "model.layers.21.self_attn.q_proj.biases": "model-00003-of-00005.safetensors",
487
+ "model.layers.21.self_attn.q_proj.scales": "model-00003-of-00005.safetensors",
488
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00005.safetensors",
489
+ "model.layers.21.self_attn.v_proj.bias": "model-00003-of-00005.safetensors",
490
+ "model.layers.21.self_attn.v_proj.biases": "model-00003-of-00005.safetensors",
491
+ "model.layers.21.self_attn.v_proj.scales": "model-00003-of-00005.safetensors",
492
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00005.safetensors",
493
+ "model.layers.22.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
494
+ "model.layers.22.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
495
+ "model.layers.22.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
496
+ "model.layers.22.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
497
+ "model.layers.22.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
498
+ "model.layers.22.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
499
+ "model.layers.22.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
500
+ "model.layers.22.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
501
+ "model.layers.22.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
502
+ "model.layers.22.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
503
+ "model.layers.22.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
504
+ "model.layers.22.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
505
+ "model.layers.22.input_layernorm.bias": "model-00004-of-00005.safetensors",
506
+ "model.layers.22.input_layernorm.weight": "model-00004-of-00005.safetensors",
507
+ "model.layers.22.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
508
+ "model.layers.22.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
509
+ "model.layers.22.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
510
+ "model.layers.22.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
511
+ "model.layers.22.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
512
+ "model.layers.22.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
513
+ "model.layers.22.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
514
+ "model.layers.22.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
515
+ "model.layers.22.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
516
+ "model.layers.22.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
517
+ "model.layers.22.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
518
+ "model.layers.22.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
519
+ "model.layers.22.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
520
+ "model.layers.22.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
521
+ "model.layers.22.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
522
+ "model.layers.22.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
523
+ "model.layers.22.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
524
+ "model.layers.22.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
525
+ "model.layers.23.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
526
+ "model.layers.23.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
527
+ "model.layers.23.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
528
+ "model.layers.23.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
529
+ "model.layers.23.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
530
+ "model.layers.23.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
531
+ "model.layers.23.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
532
+ "model.layers.23.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
533
+ "model.layers.23.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
534
+ "model.layers.23.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
535
+ "model.layers.23.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
536
+ "model.layers.23.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
537
+ "model.layers.23.input_layernorm.bias": "model-00004-of-00005.safetensors",
538
+ "model.layers.23.input_layernorm.weight": "model-00004-of-00005.safetensors",
539
+ "model.layers.23.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
540
+ "model.layers.23.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
541
+ "model.layers.23.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
542
+ "model.layers.23.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
543
+ "model.layers.23.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
544
+ "model.layers.23.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
545
+ "model.layers.23.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
546
+ "model.layers.23.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
547
+ "model.layers.23.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
548
+ "model.layers.23.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
549
+ "model.layers.23.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
550
+ "model.layers.23.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
551
+ "model.layers.23.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
552
+ "model.layers.23.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
553
+ "model.layers.23.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
554
+ "model.layers.23.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
555
+ "model.layers.23.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
556
+ "model.layers.23.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
557
+ "model.layers.24.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
558
+ "model.layers.24.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
559
+ "model.layers.24.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
560
+ "model.layers.24.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
561
+ "model.layers.24.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
562
+ "model.layers.24.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
563
+ "model.layers.24.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
564
+ "model.layers.24.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
565
+ "model.layers.24.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
566
+ "model.layers.24.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
567
+ "model.layers.24.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
568
+ "model.layers.24.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
569
+ "model.layers.24.input_layernorm.bias": "model-00004-of-00005.safetensors",
570
+ "model.layers.24.input_layernorm.weight": "model-00004-of-00005.safetensors",
571
+ "model.layers.24.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
572
+ "model.layers.24.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
573
+ "model.layers.24.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
574
+ "model.layers.24.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
575
+ "model.layers.24.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
576
+ "model.layers.24.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
577
+ "model.layers.24.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
578
+ "model.layers.24.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
579
+ "model.layers.24.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
580
+ "model.layers.24.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
581
+ "model.layers.24.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
582
+ "model.layers.24.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
583
+ "model.layers.24.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
584
+ "model.layers.24.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
585
+ "model.layers.24.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
586
+ "model.layers.24.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
587
+ "model.layers.24.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
588
+ "model.layers.24.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
589
+ "model.layers.25.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
590
+ "model.layers.25.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
591
+ "model.layers.25.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
592
+ "model.layers.25.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
593
+ "model.layers.25.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
594
+ "model.layers.25.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
595
+ "model.layers.25.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
596
+ "model.layers.25.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
597
+ "model.layers.25.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
598
+ "model.layers.25.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
599
+ "model.layers.25.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
600
+ "model.layers.25.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
601
+ "model.layers.25.input_layernorm.bias": "model-00004-of-00005.safetensors",
602
+ "model.layers.25.input_layernorm.weight": "model-00004-of-00005.safetensors",
603
+ "model.layers.25.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
604
+ "model.layers.25.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
605
+ "model.layers.25.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
606
+ "model.layers.25.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
607
+ "model.layers.25.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
608
+ "model.layers.25.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
609
+ "model.layers.25.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
610
+ "model.layers.25.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
611
+ "model.layers.25.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
612
+ "model.layers.25.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
613
+ "model.layers.25.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
614
+ "model.layers.25.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
615
+ "model.layers.25.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
616
+ "model.layers.25.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
617
+ "model.layers.25.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
618
+ "model.layers.25.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
619
+ "model.layers.25.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
620
+ "model.layers.25.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
621
+ "model.layers.26.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
622
+ "model.layers.26.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
623
+ "model.layers.26.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
624
+ "model.layers.26.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
625
+ "model.layers.26.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
626
+ "model.layers.26.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
627
+ "model.layers.26.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
628
+ "model.layers.26.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
629
+ "model.layers.26.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
630
+ "model.layers.26.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
631
+ "model.layers.26.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
632
+ "model.layers.26.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
633
+ "model.layers.26.input_layernorm.bias": "model-00004-of-00005.safetensors",
634
+ "model.layers.26.input_layernorm.weight": "model-00004-of-00005.safetensors",
635
+ "model.layers.26.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
636
+ "model.layers.26.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
637
+ "model.layers.26.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
638
+ "model.layers.26.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
639
+ "model.layers.26.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
640
+ "model.layers.26.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
641
+ "model.layers.26.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
642
+ "model.layers.26.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
643
+ "model.layers.26.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
644
+ "model.layers.26.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
645
+ "model.layers.26.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
646
+ "model.layers.26.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
647
+ "model.layers.26.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
648
+ "model.layers.26.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
649
+ "model.layers.26.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
650
+ "model.layers.26.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
651
+ "model.layers.26.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
652
+ "model.layers.26.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
653
+ "model.layers.27.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
654
+ "model.layers.27.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
655
+ "model.layers.27.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
656
+ "model.layers.27.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
657
+ "model.layers.27.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
658
+ "model.layers.27.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
659
+ "model.layers.27.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
660
+ "model.layers.27.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
661
+ "model.layers.27.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
662
+ "model.layers.27.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
663
+ "model.layers.27.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
664
+ "model.layers.27.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
665
+ "model.layers.27.input_layernorm.bias": "model-00004-of-00005.safetensors",
666
+ "model.layers.27.input_layernorm.weight": "model-00004-of-00005.safetensors",
667
+ "model.layers.27.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
668
+ "model.layers.27.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
669
+ "model.layers.27.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
670
+ "model.layers.27.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
671
+ "model.layers.27.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
672
+ "model.layers.27.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
673
+ "model.layers.27.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
674
+ "model.layers.27.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
675
+ "model.layers.27.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
676
+ "model.layers.27.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
677
+ "model.layers.27.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
678
+ "model.layers.27.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
679
+ "model.layers.27.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
680
+ "model.layers.27.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
681
+ "model.layers.27.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
682
+ "model.layers.27.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
683
+ "model.layers.27.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
684
+ "model.layers.27.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
685
+ "model.layers.28.block_sparse_moe.gate.biases": "model-00004-of-00005.safetensors",
686
+ "model.layers.28.block_sparse_moe.gate.scales": "model-00004-of-00005.safetensors",
687
+ "model.layers.28.block_sparse_moe.gate.weight": "model-00004-of-00005.safetensors",
688
+ "model.layers.28.block_sparse_moe.switch_mlp.down_proj.biases": "model-00004-of-00005.safetensors",
689
+ "model.layers.28.block_sparse_moe.switch_mlp.down_proj.scales": "model-00004-of-00005.safetensors",
690
+ "model.layers.28.block_sparse_moe.switch_mlp.down_proj.weight": "model-00004-of-00005.safetensors",
691
+ "model.layers.28.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00004-of-00005.safetensors",
692
+ "model.layers.28.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00004-of-00005.safetensors",
693
+ "model.layers.28.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00004-of-00005.safetensors",
694
+ "model.layers.28.block_sparse_moe.switch_mlp.up_proj.biases": "model-00004-of-00005.safetensors",
695
+ "model.layers.28.block_sparse_moe.switch_mlp.up_proj.scales": "model-00004-of-00005.safetensors",
696
+ "model.layers.28.block_sparse_moe.switch_mlp.up_proj.weight": "model-00004-of-00005.safetensors",
697
+ "model.layers.28.input_layernorm.bias": "model-00004-of-00005.safetensors",
698
+ "model.layers.28.input_layernorm.weight": "model-00004-of-00005.safetensors",
699
+ "model.layers.28.post_attention_layernorm.bias": "model-00004-of-00005.safetensors",
700
+ "model.layers.28.post_attention_layernorm.weight": "model-00004-of-00005.safetensors",
701
+ "model.layers.28.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
702
+ "model.layers.28.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
703
+ "model.layers.28.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
704
+ "model.layers.28.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
705
+ "model.layers.28.self_attn.o_proj.bias": "model-00004-of-00005.safetensors",
706
+ "model.layers.28.self_attn.o_proj.biases": "model-00004-of-00005.safetensors",
707
+ "model.layers.28.self_attn.o_proj.scales": "model-00004-of-00005.safetensors",
708
+ "model.layers.28.self_attn.o_proj.weight": "model-00004-of-00005.safetensors",
709
+ "model.layers.28.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
710
+ "model.layers.28.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
711
+ "model.layers.28.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
712
+ "model.layers.28.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
713
+ "model.layers.28.self_attn.v_proj.bias": "model-00004-of-00005.safetensors",
714
+ "model.layers.28.self_attn.v_proj.biases": "model-00004-of-00005.safetensors",
715
+ "model.layers.28.self_attn.v_proj.scales": "model-00004-of-00005.safetensors",
716
+ "model.layers.28.self_attn.v_proj.weight": "model-00004-of-00005.safetensors",
717
+ "model.layers.29.block_sparse_moe.gate.biases": "model-00005-of-00005.safetensors",
718
+ "model.layers.29.block_sparse_moe.gate.scales": "model-00005-of-00005.safetensors",
719
+ "model.layers.29.block_sparse_moe.gate.weight": "model-00005-of-00005.safetensors",
720
+ "model.layers.29.block_sparse_moe.switch_mlp.down_proj.biases": "model-00005-of-00005.safetensors",
721
+ "model.layers.29.block_sparse_moe.switch_mlp.down_proj.scales": "model-00005-of-00005.safetensors",
722
+ "model.layers.29.block_sparse_moe.switch_mlp.down_proj.weight": "model-00005-of-00005.safetensors",
723
+ "model.layers.29.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00005-of-00005.safetensors",
724
+ "model.layers.29.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00005-of-00005.safetensors",
725
+ "model.layers.29.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00005-of-00005.safetensors",
726
+ "model.layers.29.block_sparse_moe.switch_mlp.up_proj.biases": "model-00005-of-00005.safetensors",
727
+ "model.layers.29.block_sparse_moe.switch_mlp.up_proj.scales": "model-00005-of-00005.safetensors",
728
+ "model.layers.29.block_sparse_moe.switch_mlp.up_proj.weight": "model-00005-of-00005.safetensors",
729
+ "model.layers.29.input_layernorm.bias": "model-00005-of-00005.safetensors",
730
+ "model.layers.29.input_layernorm.weight": "model-00005-of-00005.safetensors",
731
+ "model.layers.29.post_attention_layernorm.bias": "model-00005-of-00005.safetensors",
732
+ "model.layers.29.post_attention_layernorm.weight": "model-00005-of-00005.safetensors",
733
+ "model.layers.29.self_attn.k_proj.bias": "model-00004-of-00005.safetensors",
734
+ "model.layers.29.self_attn.k_proj.biases": "model-00004-of-00005.safetensors",
735
+ "model.layers.29.self_attn.k_proj.scales": "model-00004-of-00005.safetensors",
736
+ "model.layers.29.self_attn.k_proj.weight": "model-00004-of-00005.safetensors",
737
+ "model.layers.29.self_attn.o_proj.bias": "model-00005-of-00005.safetensors",
738
+ "model.layers.29.self_attn.o_proj.biases": "model-00005-of-00005.safetensors",
739
+ "model.layers.29.self_attn.o_proj.scales": "model-00005-of-00005.safetensors",
740
+ "model.layers.29.self_attn.o_proj.weight": "model-00005-of-00005.safetensors",
741
+ "model.layers.29.self_attn.q_proj.bias": "model-00004-of-00005.safetensors",
742
+ "model.layers.29.self_attn.q_proj.biases": "model-00004-of-00005.safetensors",
743
+ "model.layers.29.self_attn.q_proj.scales": "model-00004-of-00005.safetensors",
744
+ "model.layers.29.self_attn.q_proj.weight": "model-00004-of-00005.safetensors",
745
+ "model.layers.29.self_attn.v_proj.bias": "model-00005-of-00005.safetensors",
746
+ "model.layers.29.self_attn.v_proj.biases": "model-00005-of-00005.safetensors",
747
+ "model.layers.29.self_attn.v_proj.scales": "model-00005-of-00005.safetensors",
748
+ "model.layers.29.self_attn.v_proj.weight": "model-00005-of-00005.safetensors",
749
+ "model.layers.3.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
750
+ "model.layers.3.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
751
+ "model.layers.3.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
752
+ "model.layers.3.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
753
+ "model.layers.3.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
754
+ "model.layers.3.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
755
+ "model.layers.3.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
756
+ "model.layers.3.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
757
+ "model.layers.3.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
758
+ "model.layers.3.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
759
+ "model.layers.3.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
760
+ "model.layers.3.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
761
+ "model.layers.3.input_layernorm.bias": "model-00001-of-00005.safetensors",
762
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00005.safetensors",
763
+ "model.layers.3.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
764
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
765
+ "model.layers.3.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
766
+ "model.layers.3.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
767
+ "model.layers.3.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
768
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
769
+ "model.layers.3.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
770
+ "model.layers.3.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
771
+ "model.layers.3.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
772
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
773
+ "model.layers.3.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
774
+ "model.layers.3.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
775
+ "model.layers.3.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
776
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
777
+ "model.layers.3.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
778
+ "model.layers.3.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
779
+ "model.layers.3.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
780
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
781
+ "model.layers.30.block_sparse_moe.gate.biases": "model-00005-of-00005.safetensors",
782
+ "model.layers.30.block_sparse_moe.gate.scales": "model-00005-of-00005.safetensors",
783
+ "model.layers.30.block_sparse_moe.gate.weight": "model-00005-of-00005.safetensors",
784
+ "model.layers.30.block_sparse_moe.switch_mlp.down_proj.biases": "model-00005-of-00005.safetensors",
785
+ "model.layers.30.block_sparse_moe.switch_mlp.down_proj.scales": "model-00005-of-00005.safetensors",
786
+ "model.layers.30.block_sparse_moe.switch_mlp.down_proj.weight": "model-00005-of-00005.safetensors",
787
+ "model.layers.30.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00005-of-00005.safetensors",
788
+ "model.layers.30.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00005-of-00005.safetensors",
789
+ "model.layers.30.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00005-of-00005.safetensors",
790
+ "model.layers.30.block_sparse_moe.switch_mlp.up_proj.biases": "model-00005-of-00005.safetensors",
791
+ "model.layers.30.block_sparse_moe.switch_mlp.up_proj.scales": "model-00005-of-00005.safetensors",
792
+ "model.layers.30.block_sparse_moe.switch_mlp.up_proj.weight": "model-00005-of-00005.safetensors",
793
+ "model.layers.30.input_layernorm.bias": "model-00005-of-00005.safetensors",
794
+ "model.layers.30.input_layernorm.weight": "model-00005-of-00005.safetensors",
795
+ "model.layers.30.post_attention_layernorm.bias": "model-00005-of-00005.safetensors",
796
+ "model.layers.30.post_attention_layernorm.weight": "model-00005-of-00005.safetensors",
797
+ "model.layers.30.self_attn.k_proj.bias": "model-00005-of-00005.safetensors",
798
+ "model.layers.30.self_attn.k_proj.biases": "model-00005-of-00005.safetensors",
799
+ "model.layers.30.self_attn.k_proj.scales": "model-00005-of-00005.safetensors",
800
+ "model.layers.30.self_attn.k_proj.weight": "model-00005-of-00005.safetensors",
801
+ "model.layers.30.self_attn.o_proj.bias": "model-00005-of-00005.safetensors",
802
+ "model.layers.30.self_attn.o_proj.biases": "model-00005-of-00005.safetensors",
803
+ "model.layers.30.self_attn.o_proj.scales": "model-00005-of-00005.safetensors",
804
+ "model.layers.30.self_attn.o_proj.weight": "model-00005-of-00005.safetensors",
805
+ "model.layers.30.self_attn.q_proj.bias": "model-00005-of-00005.safetensors",
806
+ "model.layers.30.self_attn.q_proj.biases": "model-00005-of-00005.safetensors",
807
+ "model.layers.30.self_attn.q_proj.scales": "model-00005-of-00005.safetensors",
808
+ "model.layers.30.self_attn.q_proj.weight": "model-00005-of-00005.safetensors",
809
+ "model.layers.30.self_attn.v_proj.bias": "model-00005-of-00005.safetensors",
810
+ "model.layers.30.self_attn.v_proj.biases": "model-00005-of-00005.safetensors",
811
+ "model.layers.30.self_attn.v_proj.scales": "model-00005-of-00005.safetensors",
812
+ "model.layers.30.self_attn.v_proj.weight": "model-00005-of-00005.safetensors",
813
+ "model.layers.31.block_sparse_moe.gate.biases": "model-00005-of-00005.safetensors",
814
+ "model.layers.31.block_sparse_moe.gate.scales": "model-00005-of-00005.safetensors",
815
+ "model.layers.31.block_sparse_moe.gate.weight": "model-00005-of-00005.safetensors",
816
+ "model.layers.31.block_sparse_moe.switch_mlp.down_proj.biases": "model-00005-of-00005.safetensors",
817
+ "model.layers.31.block_sparse_moe.switch_mlp.down_proj.scales": "model-00005-of-00005.safetensors",
818
+ "model.layers.31.block_sparse_moe.switch_mlp.down_proj.weight": "model-00005-of-00005.safetensors",
819
+ "model.layers.31.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00005-of-00005.safetensors",
820
+ "model.layers.31.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00005-of-00005.safetensors",
821
+ "model.layers.31.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00005-of-00005.safetensors",
822
+ "model.layers.31.block_sparse_moe.switch_mlp.up_proj.biases": "model-00005-of-00005.safetensors",
823
+ "model.layers.31.block_sparse_moe.switch_mlp.up_proj.scales": "model-00005-of-00005.safetensors",
824
+ "model.layers.31.block_sparse_moe.switch_mlp.up_proj.weight": "model-00005-of-00005.safetensors",
825
+ "model.layers.31.input_layernorm.bias": "model-00005-of-00005.safetensors",
826
+ "model.layers.31.input_layernorm.weight": "model-00005-of-00005.safetensors",
827
+ "model.layers.31.post_attention_layernorm.bias": "model-00005-of-00005.safetensors",
828
+ "model.layers.31.post_attention_layernorm.weight": "model-00005-of-00005.safetensors",
829
+ "model.layers.31.self_attn.k_proj.bias": "model-00005-of-00005.safetensors",
830
+ "model.layers.31.self_attn.k_proj.biases": "model-00005-of-00005.safetensors",
831
+ "model.layers.31.self_attn.k_proj.scales": "model-00005-of-00005.safetensors",
832
+ "model.layers.31.self_attn.k_proj.weight": "model-00005-of-00005.safetensors",
833
+ "model.layers.31.self_attn.o_proj.bias": "model-00005-of-00005.safetensors",
834
+ "model.layers.31.self_attn.o_proj.biases": "model-00005-of-00005.safetensors",
835
+ "model.layers.31.self_attn.o_proj.scales": "model-00005-of-00005.safetensors",
836
+ "model.layers.31.self_attn.o_proj.weight": "model-00005-of-00005.safetensors",
837
+ "model.layers.31.self_attn.q_proj.bias": "model-00005-of-00005.safetensors",
838
+ "model.layers.31.self_attn.q_proj.biases": "model-00005-of-00005.safetensors",
839
+ "model.layers.31.self_attn.q_proj.scales": "model-00005-of-00005.safetensors",
840
+ "model.layers.31.self_attn.q_proj.weight": "model-00005-of-00005.safetensors",
841
+ "model.layers.31.self_attn.v_proj.bias": "model-00005-of-00005.safetensors",
842
+ "model.layers.31.self_attn.v_proj.biases": "model-00005-of-00005.safetensors",
843
+ "model.layers.31.self_attn.v_proj.scales": "model-00005-of-00005.safetensors",
844
+ "model.layers.31.self_attn.v_proj.weight": "model-00005-of-00005.safetensors",
845
+ "model.layers.4.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
846
+ "model.layers.4.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
847
+ "model.layers.4.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
848
+ "model.layers.4.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
849
+ "model.layers.4.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
850
+ "model.layers.4.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
851
+ "model.layers.4.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
852
+ "model.layers.4.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
853
+ "model.layers.4.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
854
+ "model.layers.4.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
855
+ "model.layers.4.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
856
+ "model.layers.4.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
857
+ "model.layers.4.input_layernorm.bias": "model-00001-of-00005.safetensors",
858
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00005.safetensors",
859
+ "model.layers.4.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
860
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
861
+ "model.layers.4.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
862
+ "model.layers.4.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
863
+ "model.layers.4.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
864
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
865
+ "model.layers.4.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
866
+ "model.layers.4.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
867
+ "model.layers.4.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
868
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
869
+ "model.layers.4.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
870
+ "model.layers.4.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
871
+ "model.layers.4.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
872
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
873
+ "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
874
+ "model.layers.4.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
875
+ "model.layers.4.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
876
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
877
+ "model.layers.5.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
878
+ "model.layers.5.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
879
+ "model.layers.5.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
880
+ "model.layers.5.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
881
+ "model.layers.5.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
882
+ "model.layers.5.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
883
+ "model.layers.5.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
884
+ "model.layers.5.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
885
+ "model.layers.5.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
886
+ "model.layers.5.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
887
+ "model.layers.5.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
888
+ "model.layers.5.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
889
+ "model.layers.5.input_layernorm.bias": "model-00001-of-00005.safetensors",
890
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00005.safetensors",
891
+ "model.layers.5.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
892
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
893
+ "model.layers.5.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
894
+ "model.layers.5.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
895
+ "model.layers.5.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
896
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
897
+ "model.layers.5.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
898
+ "model.layers.5.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
899
+ "model.layers.5.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
900
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
901
+ "model.layers.5.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
902
+ "model.layers.5.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
903
+ "model.layers.5.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
904
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
905
+ "model.layers.5.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
906
+ "model.layers.5.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
907
+ "model.layers.5.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
908
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
909
+ "model.layers.6.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
910
+ "model.layers.6.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
911
+ "model.layers.6.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
912
+ "model.layers.6.block_sparse_moe.switch_mlp.down_proj.biases": "model-00001-of-00005.safetensors",
913
+ "model.layers.6.block_sparse_moe.switch_mlp.down_proj.scales": "model-00001-of-00005.safetensors",
914
+ "model.layers.6.block_sparse_moe.switch_mlp.down_proj.weight": "model-00001-of-00005.safetensors",
915
+ "model.layers.6.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00001-of-00005.safetensors",
916
+ "model.layers.6.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00001-of-00005.safetensors",
917
+ "model.layers.6.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00001-of-00005.safetensors",
918
+ "model.layers.6.block_sparse_moe.switch_mlp.up_proj.biases": "model-00001-of-00005.safetensors",
919
+ "model.layers.6.block_sparse_moe.switch_mlp.up_proj.scales": "model-00001-of-00005.safetensors",
920
+ "model.layers.6.block_sparse_moe.switch_mlp.up_proj.weight": "model-00001-of-00005.safetensors",
921
+ "model.layers.6.input_layernorm.bias": "model-00001-of-00005.safetensors",
922
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00005.safetensors",
923
+ "model.layers.6.post_attention_layernorm.bias": "model-00001-of-00005.safetensors",
924
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00005.safetensors",
925
+ "model.layers.6.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
926
+ "model.layers.6.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
927
+ "model.layers.6.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
928
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
929
+ "model.layers.6.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
930
+ "model.layers.6.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
931
+ "model.layers.6.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
932
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
933
+ "model.layers.6.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
934
+ "model.layers.6.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
935
+ "model.layers.6.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
936
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
937
+ "model.layers.6.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
938
+ "model.layers.6.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
939
+ "model.layers.6.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
940
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
941
+ "model.layers.7.block_sparse_moe.gate.biases": "model-00001-of-00005.safetensors",
942
+ "model.layers.7.block_sparse_moe.gate.scales": "model-00001-of-00005.safetensors",
943
+ "model.layers.7.block_sparse_moe.gate.weight": "model-00001-of-00005.safetensors",
944
+ "model.layers.7.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
945
+ "model.layers.7.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
946
+ "model.layers.7.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
947
+ "model.layers.7.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
948
+ "model.layers.7.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
949
+ "model.layers.7.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
950
+ "model.layers.7.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
951
+ "model.layers.7.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
952
+ "model.layers.7.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
953
+ "model.layers.7.input_layernorm.bias": "model-00002-of-00005.safetensors",
954
+ "model.layers.7.input_layernorm.weight": "model-00002-of-00005.safetensors",
955
+ "model.layers.7.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
956
+ "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
957
+ "model.layers.7.self_attn.k_proj.bias": "model-00001-of-00005.safetensors",
958
+ "model.layers.7.self_attn.k_proj.biases": "model-00001-of-00005.safetensors",
959
+ "model.layers.7.self_attn.k_proj.scales": "model-00001-of-00005.safetensors",
960
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00005.safetensors",
961
+ "model.layers.7.self_attn.o_proj.bias": "model-00001-of-00005.safetensors",
962
+ "model.layers.7.self_attn.o_proj.biases": "model-00001-of-00005.safetensors",
963
+ "model.layers.7.self_attn.o_proj.scales": "model-00001-of-00005.safetensors",
964
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00005.safetensors",
965
+ "model.layers.7.self_attn.q_proj.bias": "model-00001-of-00005.safetensors",
966
+ "model.layers.7.self_attn.q_proj.biases": "model-00001-of-00005.safetensors",
967
+ "model.layers.7.self_attn.q_proj.scales": "model-00001-of-00005.safetensors",
968
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00005.safetensors",
969
+ "model.layers.7.self_attn.v_proj.bias": "model-00001-of-00005.safetensors",
970
+ "model.layers.7.self_attn.v_proj.biases": "model-00001-of-00005.safetensors",
971
+ "model.layers.7.self_attn.v_proj.scales": "model-00001-of-00005.safetensors",
972
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00005.safetensors",
973
+ "model.layers.8.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
974
+ "model.layers.8.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
975
+ "model.layers.8.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
976
+ "model.layers.8.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
977
+ "model.layers.8.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
978
+ "model.layers.8.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
979
+ "model.layers.8.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
980
+ "model.layers.8.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
981
+ "model.layers.8.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
982
+ "model.layers.8.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
983
+ "model.layers.8.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
984
+ "model.layers.8.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
985
+ "model.layers.8.input_layernorm.bias": "model-00002-of-00005.safetensors",
986
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00005.safetensors",
987
+ "model.layers.8.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
988
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
989
+ "model.layers.8.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
990
+ "model.layers.8.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
991
+ "model.layers.8.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
992
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
993
+ "model.layers.8.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
994
+ "model.layers.8.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
995
+ "model.layers.8.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
996
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
997
+ "model.layers.8.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
998
+ "model.layers.8.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
999
+ "model.layers.8.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
1000
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
1001
+ "model.layers.8.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
1002
+ "model.layers.8.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
1003
+ "model.layers.8.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
1004
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
1005
+ "model.layers.9.block_sparse_moe.gate.biases": "model-00002-of-00005.safetensors",
1006
+ "model.layers.9.block_sparse_moe.gate.scales": "model-00002-of-00005.safetensors",
1007
+ "model.layers.9.block_sparse_moe.gate.weight": "model-00002-of-00005.safetensors",
1008
+ "model.layers.9.block_sparse_moe.switch_mlp.down_proj.biases": "model-00002-of-00005.safetensors",
1009
+ "model.layers.9.block_sparse_moe.switch_mlp.down_proj.scales": "model-00002-of-00005.safetensors",
1010
+ "model.layers.9.block_sparse_moe.switch_mlp.down_proj.weight": "model-00002-of-00005.safetensors",
1011
+ "model.layers.9.block_sparse_moe.switch_mlp.gate_proj.biases": "model-00002-of-00005.safetensors",
1012
+ "model.layers.9.block_sparse_moe.switch_mlp.gate_proj.scales": "model-00002-of-00005.safetensors",
1013
+ "model.layers.9.block_sparse_moe.switch_mlp.gate_proj.weight": "model-00002-of-00005.safetensors",
1014
+ "model.layers.9.block_sparse_moe.switch_mlp.up_proj.biases": "model-00002-of-00005.safetensors",
1015
+ "model.layers.9.block_sparse_moe.switch_mlp.up_proj.scales": "model-00002-of-00005.safetensors",
1016
+ "model.layers.9.block_sparse_moe.switch_mlp.up_proj.weight": "model-00002-of-00005.safetensors",
1017
+ "model.layers.9.input_layernorm.bias": "model-00002-of-00005.safetensors",
1018
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00005.safetensors",
1019
+ "model.layers.9.post_attention_layernorm.bias": "model-00002-of-00005.safetensors",
1020
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00005.safetensors",
1021
+ "model.layers.9.self_attn.k_proj.bias": "model-00002-of-00005.safetensors",
1022
+ "model.layers.9.self_attn.k_proj.biases": "model-00002-of-00005.safetensors",
1023
+ "model.layers.9.self_attn.k_proj.scales": "model-00002-of-00005.safetensors",
1024
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00005.safetensors",
1025
+ "model.layers.9.self_attn.o_proj.bias": "model-00002-of-00005.safetensors",
1026
+ "model.layers.9.self_attn.o_proj.biases": "model-00002-of-00005.safetensors",
1027
+ "model.layers.9.self_attn.o_proj.scales": "model-00002-of-00005.safetensors",
1028
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00005.safetensors",
1029
+ "model.layers.9.self_attn.q_proj.bias": "model-00002-of-00005.safetensors",
1030
+ "model.layers.9.self_attn.q_proj.biases": "model-00002-of-00005.safetensors",
1031
+ "model.layers.9.self_attn.q_proj.scales": "model-00002-of-00005.safetensors",
1032
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00005.safetensors",
1033
+ "model.layers.9.self_attn.v_proj.bias": "model-00002-of-00005.safetensors",
1034
+ "model.layers.9.self_attn.v_proj.biases": "model-00002-of-00005.safetensors",
1035
+ "model.layers.9.self_attn.v_proj.scales": "model-00002-of-00005.safetensors",
1036
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00005.safetensors",
1037
+ "model.norm.bias": "model-00005-of-00005.safetensors",
1038
+ "model.norm.weight": "model-00005-of-00005.safetensors"
1039
+ }
1040
+ }
modeling_phimoe.py ADDED
@@ -0,0 +1,1800 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 PhiMoE model."""
17
+ import inspect
18
+ import math
19
+ import warnings
20
+ from typing import List, Optional, Tuple, Union
21
+
22
+ import torch
23
+ import torch.nn.functional as F
24
+ import torch.utils.checkpoint
25
+ from torch import nn
26
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
27
+
28
+ from transformers.activations import ACT2FN
29
+ from transformers.cache_utils import Cache, DynamicCache
30
+ from transformers.modeling_attn_mask_utils import (
31
+ _prepare_4d_causal_attention_mask,
32
+ _prepare_4d_causal_attention_mask_for_sdpa,
33
+ )
34
+ from transformers.modeling_outputs import (
35
+ MoeCausalLMOutputWithPast,
36
+ MoeModelOutputWithPast,
37
+ SequenceClassifierOutputWithPast,
38
+ )
39
+ from transformers.modeling_utils import PreTrainedModel
40
+ from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_13
41
+ from transformers.utils import (
42
+ add_start_docstrings,
43
+ add_start_docstrings_to_model_forward,
44
+ is_flash_attn_2_available,
45
+ is_flash_attn_greater_or_equal_2_10,
46
+ logging,
47
+ replace_return_docstrings,
48
+ )
49
+ from transformers.utils.import_utils import is_torch_fx_available
50
+ from .configuration_phimoe import PhiMoEConfig
51
+
52
+ from einops import rearrange
53
+ from flash_attn.layers.rotary import RotaryEmbedding as FlashRotaryEmbedding
54
+
55
+
56
+ if is_flash_attn_2_available():
57
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
58
+ from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
59
+
60
+ _flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
61
+
62
+ # This makes `_prepare_4d_causal_attention_mask` a leaf function in the FX graph.
63
+ # It means that the function will not be traced through and simply appear as a node in the graph.
64
+ if is_torch_fx_available():
65
+ if not is_torch_greater_or_equal_than_1_13:
66
+ import torch.fx
67
+
68
+ _prepare_4d_causal_attention_mask = torch.fx.wrap(_prepare_4d_causal_attention_mask)
69
+
70
+
71
+ logger = logging.get_logger(__name__)
72
+
73
+ _CONFIG_FOR_DOC = "PhiMoEConfig"
74
+
75
+
76
+ def load_balancing_loss_func(
77
+ gate_logits: torch.Tensor, num_experts: torch.Tensor = None, top_k=2, attention_mask: Optional[torch.Tensor] = None
78
+ ) -> float:
79
+ r"""
80
+ Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.
81
+
82
+ See Switch Transformer (https://arxiv.org/abs/2101.03961) for more details. This function implements the loss
83
+ function presented in equations (4) - (6) of the paper. It aims at penalizing cases where the routing between
84
+ experts is too unbalanced.
85
+
86
+ Args:
87
+ gate_logits (Union[`torch.Tensor`, Tuple[torch.Tensor]):
88
+ Logits from the `gate`, should be a tuple of model.config.num_hidden_layers tensors of
89
+ shape [batch_size X sequence_length, num_experts].
90
+ attention_mask (`torch.Tensor`, None):
91
+ The attention_mask used in forward function
92
+ shape [batch_size X sequence_length] if not None.
93
+ num_experts (`int`, *optional*):
94
+ Number of experts
95
+
96
+ Returns:
97
+ The auxiliary loss.
98
+ """
99
+ if gate_logits is None or not isinstance(gate_logits, tuple):
100
+ return 0
101
+
102
+ if isinstance(gate_logits, tuple):
103
+ compute_device = gate_logits[0].device
104
+ concatenated_gate_logits = torch.cat([layer_gate.to(compute_device) for layer_gate in gate_logits], dim=0)
105
+
106
+ routing_weights = torch.nn.functional.softmax(concatenated_gate_logits, dim=-1)
107
+
108
+ _, selected_experts = torch.topk(routing_weights, top_k, dim=-1)
109
+
110
+ expert_mask = torch.nn.functional.one_hot(selected_experts, num_experts)
111
+
112
+ if attention_mask is None:
113
+ # Compute the percentage of tokens routed to each experts
114
+ tokens_per_expert = torch.mean(expert_mask.float(), dim=0)
115
+
116
+ # Compute the average probability of routing to these experts
117
+ router_prob_per_expert = torch.mean(routing_weights, dim=0)
118
+ else:
119
+ batch_size, sequence_length = attention_mask.shape
120
+ num_hidden_layers = concatenated_gate_logits.shape[0] // (batch_size * sequence_length)
121
+
122
+ # Compute the mask that masks all padding tokens as 0 with the same shape of expert_mask
123
+ expert_attention_mask = (
124
+ attention_mask[None, :, :, None, None]
125
+ .expand((num_hidden_layers, batch_size, sequence_length, top_k, num_experts))
126
+ .reshape(-1, top_k, num_experts)
127
+ .to(compute_device)
128
+ )
129
+
130
+ # Compute the percentage of tokens routed to each experts
131
+ tokens_per_expert = torch.sum(expert_mask.float() * expert_attention_mask, dim=0) / torch.sum(
132
+ expert_attention_mask, dim=0
133
+ )
134
+
135
+ # Compute the mask that masks all padding tokens as 0 with the same shape of tokens_per_expert
136
+ router_per_expert_attention_mask = (
137
+ attention_mask[None, :, :, None]
138
+ .expand((num_hidden_layers, batch_size, sequence_length, num_experts))
139
+ .reshape(-1, num_experts)
140
+ .to(compute_device)
141
+ )
142
+
143
+ # Compute the average probability of routing to these experts
144
+ router_prob_per_expert = torch.sum(routing_weights * router_per_expert_attention_mask, dim=0) / torch.sum(
145
+ router_per_expert_attention_mask, dim=0
146
+ )
147
+
148
+ overall_loss = torch.sum(tokens_per_expert * router_prob_per_expert.unsqueeze(0))
149
+ return overall_loss * num_experts
150
+
151
+
152
+ # Copied from transformers.models.llama.modeling_llama._get_unpad_data
153
+ def _get_unpad_data(attention_mask):
154
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
155
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
156
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
157
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
158
+ return (
159
+ indices,
160
+ cu_seqlens,
161
+ max_seqlen_in_batch,
162
+ )
163
+
164
+
165
+ # Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->PhiMoE
166
+ ##https://dl.acm.org/doi/pdf/10.5555/3454287.3455397 The following is the implementation of layernorm
167
+
168
+
169
+ class PhiMoERotaryEmbedding(nn.Module):
170
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
171
+ super().__init__()
172
+
173
+ self.dim = dim
174
+ self.max_position_embeddings = max_position_embeddings
175
+ self.base = base
176
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64).float().to(device) / self.dim))
177
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
178
+
179
+ # Build here to make `torch.jit.trace` work.
180
+ self._set_cos_sin_cache(
181
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
182
+ )
183
+
184
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
185
+ self.max_seq_len_cached = seq_len
186
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.int64).type_as(self.inv_freq)
187
+
188
+ freqs = torch.outer(t, self.inv_freq)
189
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
190
+ emb = torch.cat((freqs, freqs), dim=-1)
191
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
192
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
193
+
194
+ def forward(self, x, seq_len=None):
195
+ # x: [bs, num_attention_heads, seq_len, head_size]
196
+ if seq_len > self.max_seq_len_cached:
197
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
198
+
199
+ return (
200
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
201
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
202
+ )
203
+
204
+
205
+ class Phi3LongRoPEScaledRotaryEmbedding(nn.Module):
206
+
207
+ def __init__(self, dim, config):
208
+ super().__init__()
209
+ self.dim = dim
210
+ self.max_position_embeddings = config.max_position_embeddings
211
+ self.base = config.rope_theta
212
+ self.short_factor = config.rope_scaling["short_factor"]
213
+ self.long_factor = config.rope_scaling["long_factor"]
214
+ self.short_mscale = config.rope_scaling["short_mscale"]
215
+ self.long_mscale = config.rope_scaling["long_mscale"]
216
+ self.original_max_position_embeddings = config.rope_scaling["original_max_position_embeddings"]
217
+
218
+ def forward(self, x, seq_len=None):
219
+ if seq_len is None:
220
+ seq_len = x.shape[-2]
221
+
222
+ if seq_len > self.original_max_position_embeddings:
223
+ rescale_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
224
+ mscale = self.long_mscale
225
+ else:
226
+ rescale_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
227
+ mscale = self.short_mscale
228
+ assert rescale_factors.shape == (self.dim // 2, ), \
229
+ f"misaligned shape for LongRoPE rescale factors: {rescale_factors.shape}"
230
+
231
+ inv_freq = 1.0 / (rescale_factors * (self.base ** (torch.arange(0, self.dim, 2).float().to(x.device) / self.dim)))
232
+
233
+ t = torch.arange(seq_len, device=x.device, dtype=torch.float32)
234
+ freqs = torch.outer(t, inv_freq)
235
+
236
+ emb = torch.cat((freqs, freqs), dim=-1)
237
+ return (emb.cos() * mscale).to(x.dtype), (emb.sin() * mscale).to(x.dtype)
238
+
239
+
240
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
241
+ def rotate_half(x):
242
+ """Rotates half the hidden dims of the input."""
243
+ x1 = x[..., : x.shape[-1] // 2]
244
+ x2 = x[..., x.shape[-1] // 2 :]
245
+ return torch.cat((-x2, x1), dim=-1)
246
+
247
+
248
+
249
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
250
+ """Applies Rotary Position Embedding to the query and key tensors.
251
+
252
+ Args:
253
+ q (`torch.Tensor`): The query tensor.
254
+ k (`torch.Tensor`): The key tensor.
255
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
256
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
257
+ position_ids (`torch.Tensor`):
258
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
259
+ used to pass offsetted position ids when working with a KV-cache.
260
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
261
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
262
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
263
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
264
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
265
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
266
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
267
+ Returns:
268
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
269
+ """
270
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim)
271
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim)
272
+ q_embed = (q * cos) + (rotate_half(q) * sin)
273
+ k_embed = (k * cos) + (rotate_half(k) * sin)
274
+ return q_embed, k_embed
275
+
276
+
277
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv
278
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
279
+ """
280
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
281
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
282
+ """
283
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
284
+ if n_rep == 1:
285
+ return hidden_states
286
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
287
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
288
+
289
+
290
+
291
+ class PhiMoEAttention(nn.Module):
292
+ """
293
+ Multi-headed attention from 'Attention Is All You Need' paper. Modified to use sliding window attention: Longformer
294
+ and "Generating Long Sequences with Sparse Transformers".
295
+ """
296
+
297
+ def __init__(self, config: PhiMoEConfig, layer_idx: Optional[int] = None):
298
+ super().__init__()
299
+ self.config = config
300
+ self.layer_idx = layer_idx
301
+ if layer_idx is None:
302
+ logger.warning_once(
303
+ f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
304
+ "lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
305
+ "when creating this class."
306
+ )
307
+
308
+ self.hidden_size = config.hidden_size
309
+ self.num_heads = config.num_attention_heads
310
+ self.head_dim = self.hidden_size // self.num_heads
311
+ self.num_key_value_heads = config.num_key_value_heads
312
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
313
+ self.max_position_embeddings = config.max_position_embeddings
314
+ self.rope_theta = config.rope_theta
315
+ self.is_causal = True
316
+ self.attention_dropout = config.attention_dropout
317
+
318
+ if (self.head_dim * self.num_heads) != self.hidden_size:
319
+ raise ValueError(
320
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
321
+ f" and `num_heads`: {self.num_heads})."
322
+ )
323
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=self.config.attention_bias)
324
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=self.config.attention_bias)
325
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=self.config.attention_bias)
326
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=self.config.attention_bias)
327
+
328
+ if getattr(config, 'rope_scaling', None) is None:
329
+ self.rotary_emb = PhiMoERotaryEmbedding(
330
+ self.head_dim,
331
+ max_position_embeddings=self.max_position_embeddings,
332
+ base=self.rope_theta,
333
+ )
334
+ else:
335
+ scaling_type = self.config.rope_scaling["type"]
336
+ if scaling_type == "longrope":
337
+ self.rotary_emb = Phi3LongRoPEScaledRotaryEmbedding(self.head_dim, self.config)
338
+ else:
339
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
340
+
341
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
342
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
343
+
344
+ def forward(
345
+ self,
346
+ hidden_states: torch.Tensor,
347
+ attention_mask: Optional[torch.Tensor] = None,
348
+ position_ids: Optional[torch.LongTensor] = None,
349
+ past_key_value: Optional[Cache] = None,
350
+ output_attentions: bool = False,
351
+ use_cache: bool = False,
352
+ **kwargs,
353
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
354
+ if "padding_mask" in kwargs:
355
+ warnings.warn(
356
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
357
+ )
358
+ bsz, q_len, _ = hidden_states.size()
359
+
360
+ query_states = self.q_proj(hidden_states)
361
+ key_states = self.k_proj(hidden_states)
362
+ value_states = self.v_proj(hidden_states)
363
+
364
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
365
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
366
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
367
+
368
+ kv_seq_len = key_states.shape[-2]
369
+ if past_key_value is not None:
370
+ if self.layer_idx is None:
371
+ raise ValueError(
372
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
373
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
374
+ "with a layer index."
375
+ )
376
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
377
+
378
+ # print ("before apply rotary pos_emb", len(kv_seq_len),torch.norm(value_states).items(),\
379
+ # torch.norm(query_states).items(), torch.norm(key_states).items(), position_ids)
380
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
381
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
382
+
383
+ # print ('after pos emb', torch.norm(query_states).item(), torch.norm(key_states).items())
384
+ if past_key_value is not None:
385
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
386
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
387
+
388
+ # repeat k/v heads if n_kv_heads < n_heads
389
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
390
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
391
+
392
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
393
+
394
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
395
+ raise ValueError(
396
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
397
+ f" {attn_weights.size()}"
398
+ )
399
+
400
+ if attention_mask is not None:
401
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
402
+ raise ValueError(
403
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
404
+ )
405
+
406
+ attn_weights = attn_weights + attention_mask
407
+
408
+ # upcast attention to fp32
409
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
410
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
411
+ attn_output = torch.matmul(attn_weights, value_states)
412
+
413
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
414
+ raise ValueError(
415
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
416
+ f" {attn_output.size()}"
417
+ )
418
+
419
+ attn_output = attn_output.transpose(1, 2).contiguous()
420
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
421
+
422
+ attn_output = self.o_proj(attn_output)
423
+
424
+ if not output_attentions:
425
+ attn_weights = None
426
+
427
+ return attn_output, attn_weights, past_key_value
428
+
429
+
430
+
431
+ class PhiMoEFlashAttention2(PhiMoEAttention):
432
+ """
433
+ PhiMoE flash attention module. This module inherits from `PhiMoEAttention` as the weights of the module stays
434
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
435
+ flash attention and deal with padding tokens in case the input contains any of them.
436
+ """
437
+
438
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
439
+ def __init__(self, *args, **kwargs):
440
+ super().__init__(*args, **kwargs)
441
+
442
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
443
+ # flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
444
+ # Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
445
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
446
+
447
+ def forward(
448
+ self,
449
+ hidden_states: torch.Tensor,
450
+ attention_mask: Optional[torch.Tensor] = None,
451
+ position_ids: Optional[torch.LongTensor] = None,
452
+ past_key_value: Optional[Cache] = None,
453
+ output_attentions: bool = False,
454
+ use_cache: bool = False,
455
+ **kwargs,
456
+ ):
457
+ if "padding_mask" in kwargs:
458
+ warnings.warn(
459
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
460
+ )
461
+
462
+ # overwrite attention_mask with padding_mask
463
+ attention_mask = kwargs.pop("padding_mask")
464
+ bsz, q_len, _ = hidden_states.size()
465
+
466
+ query_states = self.q_proj(hidden_states)
467
+ key_states = self.k_proj(hidden_states)
468
+ value_states = self.v_proj(hidden_states)
469
+
470
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
471
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
472
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
473
+
474
+ kv_seq_len = key_states.shape[-2]
475
+ if past_key_value is not None:
476
+ if self.layer_idx is None:
477
+ raise ValueError(
478
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
479
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
480
+ "with a layer index."
481
+ )
482
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
483
+
484
+ # Because the input can be padded, the absolute sequence length depends on the max position id.
485
+ rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item() + 1)
486
+ cos, sin = self.rotary_emb(value_states, seq_len=rotary_seq_len)
487
+
488
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
489
+
490
+ use_sliding_windows = (
491
+ _flash_supports_window_size
492
+ and getattr(self.config, "sliding_window", None) is not None
493
+ and kv_seq_len > self.config.sliding_window
494
+ )
495
+
496
+ if not _flash_supports_window_size:
497
+ logger.warning_once(
498
+ "The current flash attention version does not support sliding window attention, for a more memory efficient implementation"
499
+ " make sure to upgrade flash-attn library."
500
+ )
501
+
502
+ if past_key_value is not None:
503
+ # Activate slicing cache only if the config has a value `sliding_windows` attribute
504
+ cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
505
+ if (
506
+ getattr(self.config, "sliding_window", None) is not None
507
+ and kv_seq_len > self.config.sliding_window
508
+ and cache_has_contents
509
+ ):
510
+ slicing_tokens = 1 - self.config.sliding_window
511
+
512
+ past_key = past_key_value[self.layer_idx][0]
513
+ past_value = past_key_value[self.layer_idx][1]
514
+
515
+ past_key = past_key[:, :, slicing_tokens:, :].contiguous()
516
+ past_value = past_value[:, :, slicing_tokens:, :].contiguous()
517
+
518
+ if past_key.shape[-2] != self.config.sliding_window - 1:
519
+ raise ValueError(
520
+ f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
521
+ f" {past_key.shape}"
522
+ )
523
+
524
+ if attention_mask is not None:
525
+ attention_mask = attention_mask[:, slicing_tokens:]
526
+ attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
527
+
528
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
529
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
530
+
531
+ # repeat k/v heads if n_kv_heads < n_heads
532
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
533
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
534
+ dropout_rate = 0.0 if not self.training else self.attention_dropout
535
+
536
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
537
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
538
+ # cast them back in float16 just to be sure everything works as expected.
539
+ input_dtype = query_states.dtype
540
+ if input_dtype == torch.float32:
541
+ if torch.is_autocast_enabled():
542
+ target_dtype = torch.get_autocast_gpu_dtype()
543
+ # Handle the case where the model is quantized
544
+ elif hasattr(self.config, "_pre_quantization_dtype"):
545
+ target_dtype = self.config._pre_quantization_dtype
546
+ else:
547
+ target_dtype = self.q_proj.weight.dtype
548
+
549
+ logger.warning_once(
550
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
551
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
552
+ f" {target_dtype}."
553
+ )
554
+
555
+ query_states = query_states.to(target_dtype)
556
+ key_states = key_states.to(target_dtype)
557
+ value_states = value_states.to(target_dtype)
558
+
559
+ # Reashape to the expected shape for Flash Attention
560
+ query_states = query_states.transpose(1, 2)
561
+ key_states = key_states.transpose(1, 2)
562
+ value_states = value_states.transpose(1, 2)
563
+
564
+ attn_output = self._flash_attention_forward(
565
+ query_states,
566
+ key_states,
567
+ value_states,
568
+ attention_mask,
569
+ q_len,
570
+ dropout=dropout_rate,
571
+ use_sliding_windows=use_sliding_windows,
572
+ )
573
+
574
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
575
+ attn_output = self.o_proj(attn_output)
576
+
577
+ if not output_attentions:
578
+ attn_weights = None
579
+
580
+ return attn_output, attn_weights, past_key_value
581
+
582
+ def _flash_attention_forward(
583
+ self,
584
+ query_states,
585
+ key_states,
586
+ value_states,
587
+ attention_mask,
588
+ query_length,
589
+ dropout=0.0,
590
+ softmax_scale=None,
591
+ use_sliding_windows=False,
592
+ ):
593
+ """
594
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
595
+ first unpad the input, then computes the attention scores and pad the final attention scores.
596
+
597
+ Args:
598
+ query_states (`torch.Tensor`):
599
+ Input query states to be passed to Flash Attention API
600
+ key_states (`torch.Tensor`):
601
+ Input key states to be passed to Flash Attention API
602
+ value_states (`torch.Tensor`):
603
+ Input value states to be passed to Flash Attention API
604
+ attention_mask (`torch.Tensor`):
605
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
606
+ position of padding tokens and 1 for the position of non-padding tokens.
607
+ dropout (`float`):
608
+ Attention dropout
609
+ softmax_scale (`float`, *optional*):
610
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
611
+ use_sliding_windows (`bool`, *optional*):
612
+ Whether to activate sliding window attention.
613
+ """
614
+ if not self._flash_attn_uses_top_left_mask:
615
+ causal = self.is_causal
616
+ else:
617
+ # TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in LlamaFlashAttention2 __init__.
618
+ causal = self.is_causal and query_length != 1
619
+
620
+ # Contains at least one padding token in the sequence
621
+ if attention_mask is not None:
622
+ batch_size = query_states.shape[0]
623
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
624
+ query_states, key_states, value_states, attention_mask, query_length
625
+ )
626
+
627
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
628
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
629
+
630
+ if not use_sliding_windows:
631
+ attn_output_unpad = flash_attn_varlen_func(
632
+ query_states,
633
+ key_states,
634
+ value_states,
635
+ cu_seqlens_q=cu_seqlens_q,
636
+ cu_seqlens_k=cu_seqlens_k,
637
+ max_seqlen_q=max_seqlen_in_batch_q,
638
+ max_seqlen_k=max_seqlen_in_batch_k,
639
+ dropout_p=dropout,
640
+ softmax_scale=softmax_scale,
641
+ causal=causal,
642
+ )
643
+ else:
644
+ attn_output_unpad = flash_attn_varlen_func(
645
+ query_states,
646
+ key_states,
647
+ value_states,
648
+ cu_seqlens_q=cu_seqlens_q,
649
+ cu_seqlens_k=cu_seqlens_k,
650
+ max_seqlen_q=max_seqlen_in_batch_q,
651
+ max_seqlen_k=max_seqlen_in_batch_k,
652
+ dropout_p=dropout,
653
+ softmax_scale=softmax_scale,
654
+ causal=causal,
655
+ window_size=(self.config.sliding_window, 0),
656
+ )
657
+
658
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
659
+ else:
660
+ if not use_sliding_windows:
661
+ attn_output = flash_attn_func(
662
+ query_states,
663
+ key_states,
664
+ value_states,
665
+ dropout,
666
+ softmax_scale=softmax_scale,
667
+ causal=causal,
668
+ )
669
+ else:
670
+ attn_output = flash_attn_func(
671
+ query_states,
672
+ key_states,
673
+ value_states,
674
+ dropout,
675
+ softmax_scale=softmax_scale,
676
+ causal=causal,
677
+ window_size=(self.config.sliding_window, 0),
678
+ )
679
+
680
+ return attn_output
681
+
682
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
683
+ batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
684
+
685
+ # On the first iteration we need to properly re-create the padding mask
686
+ # by slicing it on the proper place
687
+ if kv_seq_len != attention_mask.shape[-1]:
688
+ attention_mask_num_tokens = attention_mask.shape[-1]
689
+ attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
690
+
691
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
692
+
693
+ key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
694
+ value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
695
+
696
+ if query_length == kv_seq_len:
697
+ query_layer = index_first_axis(
698
+ query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
699
+ )
700
+ cu_seqlens_q = cu_seqlens_k
701
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
702
+ indices_q = indices_k
703
+ elif query_length == 1:
704
+ max_seqlen_in_batch_q = 1
705
+ cu_seqlens_q = torch.arange(
706
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
707
+ ) # There is a memcpy here, that is very bad.
708
+ indices_q = cu_seqlens_q[:-1]
709
+ query_layer = query_layer.squeeze(1)
710
+ else:
711
+ # The -q_len: slice assumes left padding.
712
+ attention_mask = attention_mask[:, -query_length:]
713
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
714
+
715
+ return (
716
+ query_layer,
717
+ key_layer,
718
+ value_layer,
719
+ indices_q,
720
+ (cu_seqlens_q, cu_seqlens_k),
721
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
722
+ )
723
+
724
+
725
+
726
+ class PhiMoESdpaAttention(PhiMoEAttention):
727
+ """
728
+ PhiMoE attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
729
+ `PhiMoEAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
730
+ SDPA API.
731
+ """
732
+
733
+ # Adapted from PhiMoEAttention.forward
734
+ def forward(
735
+ self,
736
+ hidden_states: torch.Tensor,
737
+ attention_mask: Optional[torch.Tensor] = None,
738
+ position_ids: Optional[torch.LongTensor] = None,
739
+ past_key_value: Optional[Cache] = None,
740
+ output_attentions: bool = False,
741
+ use_cache: bool = False,
742
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
743
+ if output_attentions:
744
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
745
+ logger.warning_once(
746
+ "PhiMoEModel is using PhiMoESdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
747
+ 'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
748
+ )
749
+ return super().forward(
750
+ hidden_states=hidden_states,
751
+ attention_mask=attention_mask,
752
+ position_ids=position_ids,
753
+ past_key_value=past_key_value,
754
+ output_attentions=output_attentions,
755
+ use_cache=use_cache,
756
+ )
757
+
758
+ bsz, q_len, _ = hidden_states.size()
759
+
760
+ query_states = self.q_proj(hidden_states)
761
+ key_states = self.k_proj(hidden_states)
762
+ value_states = self.v_proj(hidden_states)
763
+
764
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
765
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
766
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
767
+
768
+ kv_seq_len = key_states.shape[-2]
769
+ if past_key_value is not None:
770
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
771
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
772
+
773
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
774
+
775
+ if past_key_value is not None:
776
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
777
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
778
+
779
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
780
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
781
+
782
+ if attention_mask is not None:
783
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
784
+ raise ValueError(
785
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
786
+ )
787
+
788
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
789
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
790
+ if query_states.device.type == "cuda" and attention_mask is not None:
791
+ query_states = query_states.contiguous()
792
+ key_states = key_states.contiguous()
793
+ value_states = value_states.contiguous()
794
+
795
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
796
+ query_states,
797
+ key_states,
798
+ value_states,
799
+ attn_mask=attention_mask,
800
+ dropout_p=self.attention_dropout if self.training else 0.0,
801
+ # The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
802
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
803
+ )
804
+
805
+ attn_output = attn_output.transpose(1, 2).contiguous()
806
+ attn_output = attn_output.view(bsz, q_len, self.hidden_size)
807
+
808
+ attn_output = self.o_proj(attn_output)
809
+
810
+ return attn_output, None, past_key_value
811
+
812
+
813
+ PHIMOE_ATTENTION_CLASSES = {
814
+ "eager": PhiMoEAttention,
815
+ "flash_attention_2": PhiMoEFlashAttention2,
816
+ "sdpa": PhiMoESdpaAttention,
817
+ }
818
+
819
+
820
+ class PhiMoEBlockSparseTop2MLP(nn.Module):
821
+ def __init__(self, config: PhiMoEConfig):
822
+ super().__init__()
823
+ self.ffn_dim = config.intermediate_size
824
+ self.hidden_dim = config.hidden_size
825
+
826
+ self.w1 = nn.Linear(self.hidden_dim, self.ffn_dim, bias=False)
827
+ self.w2 = nn.Linear(self.ffn_dim, self.hidden_dim, bias=False)
828
+ self.w3 = nn.Linear(self.hidden_dim, self.ffn_dim, bias=False)
829
+
830
+ self.act_fn = ACT2FN[config.hidden_act]
831
+
832
+ def forward(self, hidden_states):
833
+ current_hidden_states = self.act_fn(self.w1(hidden_states)) * self.w3(hidden_states)
834
+ current_hidden_states = self.w2(current_hidden_states)
835
+ return current_hidden_states
836
+
837
+
838
+ class PhiMoEBLockSparseTop2MLP(PhiMoEBlockSparseTop2MLP):
839
+ def __init__(self, *args, **kwargs):
840
+ logger.warning_once(
841
+ "PhiMoEBLockSparseTop2MLP is deprecated by PhiMoEBlockSparseTop2MLP and will be removed in v4.40."
842
+ )
843
+ super().__init__(*args, **kwargs)
844
+
845
+
846
+ class mp(torch.autograd.Function):
847
+ @staticmethod
848
+ def forward(
849
+ ctx,
850
+ scores: torch.Tensor,
851
+ multiplier: torch.Tensor,
852
+ selected_experts: torch.Tensor,
853
+ masked_gates: torch.Tensor,
854
+ mask_for_one: torch.Tensor,
855
+ ):
856
+ ctx.save_for_backward(multiplier, selected_experts, masked_gates)
857
+ return multiplier * mask_for_one
858
+
859
+ @staticmethod
860
+ def backward(
861
+ ctx,
862
+ grad_at_output: torch.Tensor,
863
+ ):
864
+ multiplier, selected_experts, masked_gates = ctx.saved_tensors
865
+
866
+ grad_at_output = grad_at_output * multiplier
867
+
868
+ grad_at_scores_expaned = masked_gates * grad_at_output.mul(-1)
869
+ grad_at_scores_expaned.scatter_add_(
870
+ dim=-1,
871
+ index=selected_experts,
872
+ src=grad_at_output,
873
+ )
874
+
875
+ return (
876
+ grad_at_scores_expaned,
877
+ None,
878
+ None,
879
+ None,
880
+ None,
881
+ )
882
+
883
+ def sparsemixer(scores, top_k, jitter_eps, training):
884
+ assert top_k == 2
885
+
886
+ ################ first expert ################
887
+
888
+ with torch.no_grad():
889
+ # compute mask for sparsity
890
+ mask_logits_threshold, max_ind = scores.max(dim=-1, keepdim=True)
891
+ factor = scores.abs().clamp(min=mask_logits_threshold)
892
+ mask_logits_threshold = (
893
+ (mask_logits_threshold - scores) / factor
894
+ ) > (2 * jitter_eps)
895
+
896
+ # apply mask
897
+ masked_gates = scores.masked_fill(mask_logits_threshold, float('-inf'))
898
+ if training:
899
+ selected_experts = (
900
+ masked_gates - torch.empty_like(masked_gates, memory_format=torch.legacy_contiguous_format).exponential_().log()
901
+ ).max(dim=-1)[1].unsqueeze(-1) # gumbel sampling, more robust than than the multinomial method
902
+ else:
903
+ selected_experts = max_ind
904
+
905
+ # compute scores for gradients
906
+ masked_gates = torch.softmax(masked_gates, dim=-1)
907
+ multiplier_o = masked_gates.gather(dim=-1, index=selected_experts)
908
+
909
+ if training:
910
+ # compute midpoint mask
911
+ max_scores, max_ind = masked_gates.max(dim=-1, keepdim=True)
912
+ mask_for_one = torch.logical_or(
913
+ selected_experts == max_ind,
914
+ torch.rand_like(max_scores) > 0.75 # Heun's third-order method: f(x) - f(0) = .25 f'(x) + .75 f'(x/3.)
915
+ )
916
+ # 1 -> 1.0 & 0 -> 1./3: lambda x: (x + 0.5) / 1.5
917
+ mask_for_one = torch.add(0.3333, mask_for_one, alpha=0.6667).type_as(masked_gates)
918
+
919
+ multiplier = mp.apply(
920
+ scores,
921
+ multiplier_o,
922
+ selected_experts,
923
+ masked_gates,
924
+ mask_for_one,
925
+ )
926
+ else:
927
+ multiplier = multiplier_o
928
+
929
+ # masked out first expert
930
+ masked_scores = torch.scatter(
931
+ scores,
932
+ -1,
933
+ selected_experts,
934
+ float('-inf'),
935
+ )
936
+ with torch.no_grad():
937
+ # compute mask for sparsity
938
+ mask_logits_threshold, max_ind = masked_scores.max(dim=-1, keepdim=True)
939
+ factor = scores.abs().clamp(min=mask_logits_threshold)
940
+ mask_logits_threshold = (
941
+ (mask_logits_threshold - scores) / factor
942
+ ) > (2 * jitter_eps)
943
+
944
+ # apply mask
945
+ masked_gates_top2 = masked_scores.masked_fill(mask_logits_threshold, float('-inf'))
946
+ if training:
947
+ selected_experts_top2 = (
948
+ masked_gates_top2 - torch.empty_like(masked_gates_top2, memory_format=torch.legacy_contiguous_format).exponential_().log()
949
+ ).max(dim=-1)[1].unsqueeze(-1) # gumbel sampling, more robust than than the multinomial method
950
+ else:
951
+ selected_experts_top2 = max_ind
952
+ # compute scores for gradients
953
+ masked_gates_top2 = torch.softmax(masked_gates_top2, dim=-1)
954
+ multiplier_top2_o = masked_gates_top2.gather(dim=-1, index=selected_experts_top2)
955
+
956
+ if training:
957
+ # compute midpoint mask
958
+ max_scores, max_ind = masked_gates_top2.max(dim=-1, keepdim=True)
959
+ mask_for_one_top2 = torch.logical_or(
960
+ selected_experts_top2 == max_ind,
961
+ torch.rand_like(max_scores).uniform_() > 0.75 # Heun's third-order method: f(x) - f(0) = .25 f'(x) + .75 f'(x/3.)
962
+ )
963
+ # 1 -> 1.0 & 0 -> 1./3: lambda x: (x + 0.5) / 1.5
964
+ mask_for_one_top2 = torch.add(0.3333, mask_for_one_top2, alpha=0.6667).type_as(masked_gates_top2)
965
+
966
+ multiplier_top2 = mp.apply(
967
+ scores,
968
+ multiplier_top2_o,
969
+ selected_experts_top2,
970
+ masked_gates_top2,
971
+ mask_for_one_top2,
972
+ )
973
+ else:
974
+ multiplier_top2 = multiplier_top2_o
975
+
976
+ multiplier = torch.concat((multiplier, multiplier_top2), dim=-1)
977
+ selected_experts = torch.concat((selected_experts, selected_experts_top2), dim=-1)
978
+
979
+ return (
980
+ multiplier,
981
+ selected_experts,
982
+ )
983
+
984
+ iterations = 0
985
+ class PhiMoESparseMoeBlock(nn.Module):
986
+ """
987
+ This implementation is
988
+ strictly equivalent to standard MoE with full capacity (no
989
+ dropped tokens). It's faster since it formulates MoE operations
990
+ in terms of block-sparse operations to accomodate imbalanced
991
+ assignments of tokens to experts, whereas standard MoE either
992
+ (1) drop tokens at the cost of reduced performance or (2) set
993
+ capacity factor to number of experts and thus waste computation
994
+ and memory on padding.
995
+ """
996
+
997
+ def __init__(self, config):
998
+ super().__init__()
999
+ self.hidden_dim = config.hidden_size
1000
+ self.ffn_dim = config.intermediate_size
1001
+ self.num_experts = config.num_local_experts
1002
+ self.top_k = config.num_experts_per_tok
1003
+ global iterations
1004
+ iterations +=1
1005
+ self.iter = iterations
1006
+ # gating
1007
+ self.gate = nn.Linear(self.hidden_dim, self.num_experts, bias=False)
1008
+
1009
+ self.experts = nn.ModuleList([PhiMoEBlockSparseTop2MLP(config) for _ in range(self.num_experts)])
1010
+
1011
+ # Jitter parameters
1012
+ self.router_jitter_noise = config.router_jitter_noise
1013
+ self.input_jitter_noise = config.input_jitter_noise
1014
+
1015
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
1016
+ """ """
1017
+ batch_size, sequence_length, hidden_dim = hidden_states.shape
1018
+ if self.training and self.input_jitter_noise > 0:
1019
+ hidden_states *= torch.empty_like(hidden_states).uniform_(1.0 - self.input_jitter_noise, 1.0 + self.input_jitter_noise)
1020
+ hidden_states = hidden_states.view(-1, hidden_dim)
1021
+ # router_logits: (batch * sequence_length, n_experts)
1022
+ # print ( 'moe', self.iter, torch.norm(hidden_states).item())
1023
+ router_logits = self.gate(hidden_states)
1024
+
1025
+ routing_weights, selected_experts = sparsemixer(
1026
+ router_logits,
1027
+ top_k=2,
1028
+ jitter_eps=self.router_jitter_noise,
1029
+ training=self.training,
1030
+ )
1031
+
1032
+ final_hidden_states = torch.zeros(
1033
+ (batch_size * sequence_length, hidden_dim), dtype=hidden_states.dtype, device=hidden_states.device
1034
+ )
1035
+
1036
+ # One hot encode the selected experts to create an expert mask
1037
+ # this will be used to easily index which expert is going to be sollicitated
1038
+ expert_mask = torch.nn.functional.one_hot(selected_experts, num_classes=self.num_experts).permute(2, 1, 0)
1039
+
1040
+ # Loop over all available experts in the model and perform the computation on each expert
1041
+ for expert_idx in range(self.num_experts):
1042
+ expert_layer = self.experts[expert_idx]
1043
+ idx, top_x = torch.where(expert_mask[expert_idx])
1044
+
1045
+ if top_x.shape[0] == 0:
1046
+ continue
1047
+
1048
+ # in torch it is faster to index using lists than torch tensors
1049
+ top_x_list = top_x.tolist()
1050
+ idx_list = idx.tolist()
1051
+
1052
+ # Index the correct hidden states and compute the expert hidden state for
1053
+ # the current expert. We need to make sure to multiply the output hidden
1054
+ # states by `routing_weights` on the corresponding tokens (top-1 and top-2)
1055
+ current_state = hidden_states[None, top_x_list].reshape(-1, hidden_dim)
1056
+ current_hidden_states = expert_layer(current_state) * routing_weights[top_x_list, idx_list, None]
1057
+
1058
+ # However `index_add_` only support torch tensors for indexing so we'll use
1059
+ # the `top_x` tensor here.
1060
+ final_hidden_states.index_add_(0, top_x, current_hidden_states.to(hidden_states.dtype))
1061
+ final_hidden_states = final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)
1062
+ # print ( 'moe', self.iter, torch.norm(final_hidden_states).item())
1063
+ return final_hidden_states, router_logits
1064
+
1065
+
1066
+ class PhiMoEDecoderLayer(nn.Module):
1067
+ def __init__(self, config: PhiMoEConfig, layer_idx: int):
1068
+ super().__init__()
1069
+ self.hidden_size = config.hidden_size
1070
+
1071
+ self.self_attn = PHIMOE_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx)
1072
+
1073
+ self.block_sparse_moe = PhiMoESparseMoeBlock(config)
1074
+ self.input_layernorm = nn.LayerNorm(config.hidden_size, eps=config.rms_norm_eps, elementwise_affine=True)
1075
+ self.post_attention_layernorm = nn.LayerNorm(config.hidden_size, eps=config.rms_norm_eps, elementwise_affine=True)
1076
+
1077
+ def forward(
1078
+ self,
1079
+ hidden_states: torch.Tensor,
1080
+ attention_mask: Optional[torch.Tensor] = None,
1081
+ position_ids: Optional[torch.LongTensor] = None,
1082
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
1083
+ output_attentions: Optional[bool] = False,
1084
+ output_router_logits: Optional[bool] = False,
1085
+ use_cache: Optional[bool] = False,
1086
+ **kwargs,
1087
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
1088
+ if "padding_mask" in kwargs:
1089
+ warnings.warn(
1090
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
1091
+ )
1092
+ """
1093
+ Args:
1094
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
1095
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
1096
+ `(batch, sequence_length)` where padding elements are indicated by 0.
1097
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
1098
+ output_attentions (`bool`, *optional*):
1099
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
1100
+ returned tensors for more detail.
1101
+ output_router_logits (`bool`, *optional*):
1102
+ Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
1103
+ should not be returned during inference.
1104
+ use_cache (`bool`, *optional*):
1105
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
1106
+ (see `past_key_values`).
1107
+ """
1108
+
1109
+ residual = hidden_states
1110
+
1111
+ hidden_states = self.input_layernorm(hidden_states)
1112
+
1113
+ # Self Attention
1114
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
1115
+ hidden_states=hidden_states,
1116
+ attention_mask=attention_mask,
1117
+ position_ids=position_ids,
1118
+ past_key_value=past_key_value,
1119
+ output_attentions=output_attentions,
1120
+ use_cache=use_cache,
1121
+ )
1122
+ hidden_states = residual + hidden_states
1123
+
1124
+ # Fully Connected
1125
+ residual = hidden_states
1126
+ hidden_states = self.post_attention_layernorm(hidden_states)
1127
+ hidden_states, router_logits = self.block_sparse_moe(hidden_states)
1128
+ hidden_states = residual + hidden_states
1129
+
1130
+ outputs = (hidden_states,)
1131
+
1132
+ if output_attentions:
1133
+ outputs += (self_attn_weights,)
1134
+
1135
+ if use_cache:
1136
+ outputs += (present_key_value,)
1137
+
1138
+ if output_router_logits:
1139
+ outputs += (router_logits,)
1140
+
1141
+ return outputs
1142
+
1143
+
1144
+ PHIMOE_START_DOCSTRING = r"""
1145
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
1146
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
1147
+ etc.)
1148
+
1149
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
1150
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
1151
+ and behavior.
1152
+
1153
+ Parameters:
1154
+ config ([`PhiMoEConfig`]):
1155
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
1156
+ load the weights associated with the model, only the configuration. Check out the
1157
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
1158
+ """
1159
+
1160
+
1161
+ @add_start_docstrings(
1162
+ "The bare PhiMoE Model outputting raw hidden-states without any specific head on top.",
1163
+ PHIMOE_START_DOCSTRING,
1164
+ )
1165
+
1166
+ class PhiMoEPreTrainedModel(PreTrainedModel):
1167
+ config_class = PhiMoEConfig
1168
+ base_model_prefix = "model"
1169
+ supports_gradient_checkpointing = True
1170
+ _no_split_modules = ["PhiMoEDecoderLayer"]
1171
+ _skip_keys_device_placement = "past_key_values"
1172
+ _supports_flash_attn_2 = True
1173
+ _supports_sdpa = True
1174
+ _supports_cache_class = True
1175
+
1176
+ def _init_weights(self, module):
1177
+ pass
1178
+ # std = self.config.initializer_range
1179
+ # if isinstance(module, nn.Linear):
1180
+ # module.weight.data.normal_(mean=0.0, std=std)
1181
+ # if module.bias is not None:
1182
+ # module.bias.data.zero_()
1183
+ # elif isinstance(module, nn.Embedding):
1184
+ # module.weight.data.normal_(mean=0.0, std=std)
1185
+ # if module.padding_idx is not None:
1186
+ # module.weight.data[module.padding_idx].zero_()
1187
+
1188
+
1189
+ PHIMOE_INPUTS_DOCSTRING = r"""
1190
+ Args:
1191
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
1192
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
1193
+ it.
1194
+
1195
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
1196
+ [`PreTrainedTokenizer.__call__`] for details.
1197
+
1198
+ [What are input IDs?](../glossary#input-ids)
1199
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
1200
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
1201
+
1202
+ - 1 for tokens that are **not masked**,
1203
+ - 0 for tokens that are **masked**.
1204
+
1205
+ [What are attention masks?](../glossary#attention-mask)
1206
+
1207
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
1208
+ [`PreTrainedTokenizer.__call__`] for details.
1209
+
1210
+ If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
1211
+ `past_key_values`).
1212
+
1213
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
1214
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
1215
+ information on the default strategy.
1216
+
1217
+ - 1 indicates the head is **not masked**,
1218
+ - 0 indicates the head is **masked**.
1219
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1220
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
1221
+ config.n_positions - 1]`.
1222
+
1223
+ [What are position IDs?](../glossary#position-ids)
1224
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
1225
+ Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
1226
+ `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
1227
+ `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.
1228
+
1229
+ Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
1230
+ blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.
1231
+
1232
+ If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
1233
+ don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
1234
+ `decoder_input_ids` of shape `(batch_size, sequence_length)`.
1235
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
1236
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
1237
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
1238
+ model's internal embedding lookup matrix.
1239
+ use_cache (`bool`, *optional*):
1240
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
1241
+ `past_key_values`).
1242
+ output_attentions (`bool`, *optional*):
1243
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
1244
+ tensors for more detail.
1245
+ output_hidden_states (`bool`, *optional*):
1246
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
1247
+ more detail.
1248
+ output_router_logits (`bool`, *optional*):
1249
+ Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
1250
+ should not be returned during inference.
1251
+ return_dict (`bool`, *optional*):
1252
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
1253
+ """
1254
+
1255
+
1256
+ @add_start_docstrings(
1257
+ "The bare PhiMoE Model outputting raw hidden-states without any specific head on top.",
1258
+ PHIMOE_START_DOCSTRING,
1259
+ )
1260
+
1261
+ class PhiMoEModel(PhiMoEPreTrainedModel):
1262
+ """
1263
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`PhiMoEDecoderLayer`]
1264
+
1265
+ Args:
1266
+ config: PhiMoEConfig
1267
+ """
1268
+
1269
+ def __init__(self, config: PhiMoEConfig):
1270
+ super().__init__(config)
1271
+ self.padding_idx = config.pad_token_id
1272
+ self.vocab_size = config.vocab_size
1273
+
1274
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
1275
+ self.layers = nn.ModuleList(
1276
+ [PhiMoEDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
1277
+ )
1278
+ self._attn_implementation = config._attn_implementation
1279
+ self.norm = nn.LayerNorm(config.hidden_size, eps=config.rms_norm_eps, elementwise_affine=True)
1280
+
1281
+ self.gradient_checkpointing = False
1282
+ # Initialize weights and apply final processing
1283
+ self.post_init()
1284
+
1285
+ def get_input_embeddings(self):
1286
+ return self.embed_tokens
1287
+
1288
+ def set_input_embeddings(self, value):
1289
+ self.embed_tokens = value
1290
+
1291
+ # Ignore copy
1292
+ @add_start_docstrings_to_model_forward(PHIMOE_INPUTS_DOCSTRING)
1293
+ def forward(
1294
+ self,
1295
+ input_ids: torch.LongTensor = None,
1296
+ attention_mask: Optional[torch.Tensor] = None,
1297
+ position_ids: Optional[torch.LongTensor] = None,
1298
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1299
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1300
+ use_cache: Optional[bool] = None,
1301
+ output_attentions: Optional[bool] = None,
1302
+ output_hidden_states: Optional[bool] = None,
1303
+ output_router_logits: Optional[bool] = None,
1304
+ return_dict: Optional[bool] = None,
1305
+ ) -> Union[Tuple, MoeModelOutputWithPast]:
1306
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1307
+ output_router_logits = (
1308
+ output_router_logits if output_router_logits is not None else self.config.output_router_logits
1309
+ )
1310
+ output_hidden_states = (
1311
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1312
+ )
1313
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
1314
+
1315
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1316
+
1317
+ # retrieve input_ids and inputs_embeds
1318
+ if input_ids is not None and inputs_embeds is not None:
1319
+ raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
1320
+ elif input_ids is not None:
1321
+ batch_size, seq_length = input_ids.shape
1322
+ elif inputs_embeds is not None:
1323
+ batch_size, seq_length, _ = inputs_embeds.shape
1324
+ else:
1325
+ raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
1326
+
1327
+ past_key_values_length = 0
1328
+
1329
+ if self.gradient_checkpointing and self.training:
1330
+ if use_cache:
1331
+ logger.warning_once(
1332
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`transformers."
1333
+ )
1334
+ use_cache = False
1335
+
1336
+ if use_cache:
1337
+ use_legacy_cache = not isinstance(past_key_values, Cache)
1338
+ if use_legacy_cache:
1339
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
1340
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
1341
+
1342
+ if position_ids is None:
1343
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
1344
+ position_ids = torch.arange(
1345
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
1346
+ )
1347
+ position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
1348
+ else:
1349
+ position_ids = position_ids.view(-1, seq_length).long()
1350
+
1351
+ if inputs_embeds is None:
1352
+ inputs_embeds = self.embed_tokens(input_ids)
1353
+
1354
+ if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
1355
+ is_padding_right = attention_mask[:, -1].sum().item() != batch_size
1356
+ if is_padding_right:
1357
+ raise ValueError(
1358
+ "You are attempting to perform batched generation with padding_side='right'"
1359
+ " this may lead to unexpected behaviour for Flash Attention version of PhiMoE. Make sure to "
1360
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
1361
+ )
1362
+
1363
+ if self._attn_implementation == "flash_attention_2":
1364
+ # 2d mask is passed through the layers
1365
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
1366
+ elif self._attn_implementation == "sdpa" and not output_attentions:
1367
+ # output_attentions=True can not be supported when using SDPA, and we fall back on
1368
+ # the manual implementation that requires a 4D causal mask in all cases.
1369
+ attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
1370
+ attention_mask,
1371
+ (batch_size, seq_length),
1372
+ inputs_embeds,
1373
+ past_key_values_length,
1374
+ )
1375
+ else:
1376
+ # 4d mask is passed through the layers
1377
+ attention_mask = _prepare_4d_causal_attention_mask(
1378
+ attention_mask,
1379
+ (batch_size, seq_length),
1380
+ inputs_embeds,
1381
+ past_key_values_length,
1382
+ sliding_window=self.config.sliding_window,
1383
+ )
1384
+
1385
+ hidden_states = inputs_embeds
1386
+
1387
+ # decoder layers
1388
+ all_hidden_states = () if output_hidden_states else None
1389
+ all_self_attns = () if output_attentions else None
1390
+ all_router_logits = () if output_router_logits else None
1391
+ next_decoder_cache = None
1392
+
1393
+ for decoder_layer in self.layers:
1394
+ if output_hidden_states:
1395
+ all_hidden_states += (hidden_states,)
1396
+
1397
+ if self.gradient_checkpointing and self.training:
1398
+ layer_outputs = self._gradient_checkpointing_func(
1399
+ decoder_layer.__call__,
1400
+ hidden_states,
1401
+ attention_mask,
1402
+ position_ids,
1403
+ past_key_values,
1404
+ output_attentions,
1405
+ output_router_logits,
1406
+ use_cache,
1407
+ )
1408
+ else:
1409
+ layer_outputs = decoder_layer(
1410
+ hidden_states,
1411
+ attention_mask=attention_mask,
1412
+ position_ids=position_ids,
1413
+ past_key_value=past_key_values,
1414
+ output_attentions=output_attentions,
1415
+ output_router_logits=output_router_logits,
1416
+ use_cache=use_cache,
1417
+ )
1418
+
1419
+ hidden_states = layer_outputs[0]
1420
+
1421
+ if use_cache:
1422
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
1423
+
1424
+ if output_attentions:
1425
+ all_self_attns += (layer_outputs[1],)
1426
+
1427
+ if output_router_logits:
1428
+ all_router_logits += (layer_outputs[-1],)
1429
+
1430
+ hidden_states = self.norm(hidden_states)
1431
+
1432
+ # add hidden states from the last decoder layer
1433
+ if output_hidden_states:
1434
+ all_hidden_states += (hidden_states,)
1435
+
1436
+ next_cache = None
1437
+ if use_cache:
1438
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
1439
+
1440
+ if not return_dict:
1441
+ return tuple(
1442
+ v
1443
+ for v in [hidden_states, next_cache, all_hidden_states, all_self_attns, all_router_logits]
1444
+ if v is not None
1445
+ )
1446
+ return MoeModelOutputWithPast(
1447
+ last_hidden_state=hidden_states,
1448
+ past_key_values=next_cache,
1449
+ hidden_states=all_hidden_states,
1450
+ attentions=all_self_attns,
1451
+ router_logits=all_router_logits,
1452
+ )
1453
+
1454
+
1455
+ class PhiMoEForCausalLM(PhiMoEPreTrainedModel):
1456
+ _tied_weights_keys = ["lm_head.weight"]
1457
+
1458
+ def __init__(self, config):
1459
+ super().__init__(config)
1460
+ self.model = PhiMoEModel(config)
1461
+ self.vocab_size = config.vocab_size
1462
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=self.config.lm_head_bias)
1463
+ self.router_aux_loss_coef = config.router_aux_loss_coef
1464
+ self.num_experts = config.num_local_experts
1465
+ self.num_experts_per_tok = config.num_experts_per_tok
1466
+ # Initialize weights and apply final processing
1467
+ self.post_init()
1468
+
1469
+ def get_input_embeddings(self):
1470
+ return self.model.embed_tokens
1471
+
1472
+ def set_input_embeddings(self, value):
1473
+ self.model.embed_tokens = value
1474
+
1475
+ def get_output_embeddings(self):
1476
+ return self.lm_head
1477
+
1478
+ def set_output_embeddings(self, new_embeddings):
1479
+ self.lm_head = new_embeddings
1480
+
1481
+ def set_decoder(self, decoder):
1482
+ self.model = decoder
1483
+
1484
+ def get_decoder(self):
1485
+ return self.model
1486
+
1487
+ @add_start_docstrings_to_model_forward(PHIMOE_INPUTS_DOCSTRING)
1488
+ @replace_return_docstrings(output_type=MoeCausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1489
+ # Ignore copy
1490
+ def forward(
1491
+ self,
1492
+ input_ids: torch.LongTensor = None,
1493
+ attention_mask: Optional[torch.Tensor] = None,
1494
+ position_ids: Optional[torch.LongTensor] = None,
1495
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1496
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1497
+ labels: Optional[torch.LongTensor] = None,
1498
+ use_cache: Optional[bool] = None,
1499
+ output_attentions: Optional[bool] = None,
1500
+ output_hidden_states: Optional[bool] = None,
1501
+ output_router_logits: Optional[bool] = None,
1502
+ return_dict: Optional[bool] = None,
1503
+ ) -> Union[Tuple, MoeCausalLMOutputWithPast]:
1504
+ r"""
1505
+ Args:
1506
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1507
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, transformers.,
1508
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1509
+ (masked), the loss is only computed for the tokens with labels in `[0, transformers., config.vocab_size]`.
1510
+
1511
+ Returns:
1512
+
1513
+ Example:
1514
+
1515
+ ```python
1516
+ >>> from transformers import AutoTokenizer, PhiMoEForCausalLM
1517
+
1518
+ >>> model = PhiMoEForCausalLM.from_pretrained("microsoft/Phi-3.5-moe-instruct")
1519
+ >>> tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3.5-moe-instruct")
1520
+
1521
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1522
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1523
+
1524
+ >>> # Generate
1525
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1526
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1527
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1528
+ ```"""
1529
+
1530
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1531
+ output_router_logits = (
1532
+ output_router_logits if output_router_logits is not None else self.config.output_router_logits
1533
+ )
1534
+
1535
+ output_hidden_states = (
1536
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1537
+ )
1538
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1539
+
1540
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1541
+ outputs = self.model(
1542
+ input_ids=input_ids,
1543
+ attention_mask=attention_mask,
1544
+ position_ids=position_ids,
1545
+ past_key_values=past_key_values,
1546
+ inputs_embeds=inputs_embeds,
1547
+ use_cache=use_cache,
1548
+ output_attentions=output_attentions,
1549
+ output_hidden_states=output_hidden_states,
1550
+ output_router_logits=output_router_logits,
1551
+ return_dict=return_dict,
1552
+ )
1553
+
1554
+ hidden_states = outputs[0]
1555
+ logits = self.lm_head(hidden_states)
1556
+ logits = logits.float()
1557
+
1558
+ loss = None
1559
+ if labels is not None:
1560
+ # Shift so that tokens < n predict n
1561
+ shift_logits = logits[..., :-1, :].contiguous()
1562
+ shift_labels = labels[..., 1:].contiguous()
1563
+ # Flatten the tokens
1564
+ loss_fct = CrossEntropyLoss()
1565
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1566
+ shift_labels = shift_labels.view(-1)
1567
+ # Enable model parallelism
1568
+ shift_labels = shift_labels.to(shift_logits.device)
1569
+ loss = loss_fct(shift_logits, shift_labels)
1570
+
1571
+ aux_loss = None
1572
+ if output_router_logits:
1573
+ aux_loss = load_balancing_loss_func(
1574
+ outputs.router_logits if return_dict else outputs[-1],
1575
+ self.num_experts,
1576
+ self.num_experts_per_tok,
1577
+ attention_mask,
1578
+ )
1579
+ if labels is not None:
1580
+ loss += self.router_aux_loss_coef * aux_loss.to(loss.device) # make sure to reside in the same device
1581
+
1582
+ if not return_dict:
1583
+ output = (logits,) + outputs[1:]
1584
+ if output_router_logits:
1585
+ output = (aux_loss,) + output
1586
+ return (loss,) + output if loss is not None else output
1587
+
1588
+ return MoeCausalLMOutputWithPast(
1589
+ loss=loss,
1590
+ aux_loss=aux_loss,
1591
+ logits=logits,
1592
+ past_key_values=outputs.past_key_values,
1593
+ hidden_states=outputs.hidden_states,
1594
+ attentions=outputs.attentions,
1595
+ router_logits=outputs.router_logits,
1596
+ )
1597
+
1598
+ def prepare_inputs_for_generation(
1599
+ self,
1600
+ input_ids,
1601
+ past_key_values=None,
1602
+ attention_mask=None,
1603
+ inputs_embeds=None,
1604
+ output_router_logits=False,
1605
+ **kwargs,
1606
+ ):
1607
+ # When the first time input length reached long and short factor switching point, enforce re-compute cache
1608
+ # It will cause downside of slower at this single token position, however, better than current failure.
1609
+ if past_key_values and self.config.rope_scaling and input_ids.shape[1] >= self.config.original_max_position_embeddings + 1:
1610
+ past_length = past_key_values.seen_tokens if isinstance(past_key_values, Cache) else past_key_values[0][0].shape[2]
1611
+ if past_length <= self.config.original_max_position_embeddings:
1612
+ past_key_values = None
1613
+
1614
+ # Omit tokens covered by past_key_values
1615
+ if past_key_values is not None:
1616
+ if isinstance(past_key_values, Cache):
1617
+ cache_length = past_key_values.get_seq_length()
1618
+ past_length = past_key_values.seen_tokens
1619
+ max_cache_length = past_key_values.get_max_length()
1620
+ else:
1621
+ cache_length = past_length = past_key_values[0][0].shape[2]
1622
+ max_cache_length = None
1623
+
1624
+ # Keep only the unprocessed tokens:
1625
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1626
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
1627
+ # input)
1628
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
1629
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1630
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1631
+ # input_ids based on the past_length.
1632
+ elif past_length < input_ids.shape[1]:
1633
+ input_ids = input_ids[:, past_length:]
1634
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1635
+
1636
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1637
+ if (
1638
+ max_cache_length is not None
1639
+ and attention_mask is not None
1640
+ and cache_length + input_ids.shape[1] > max_cache_length
1641
+ ):
1642
+ attention_mask = attention_mask[:, -max_cache_length:]
1643
+
1644
+ position_ids = kwargs.get("position_ids", None)
1645
+ if attention_mask is not None and position_ids is None:
1646
+ # create position_ids on the fly for batch generation
1647
+ position_ids = attention_mask.long().cumsum(-1) - 1
1648
+ position_ids.masked_fill_(attention_mask == 0, 1)
1649
+ if past_key_values:
1650
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1651
+
1652
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1653
+ if inputs_embeds is not None and past_key_values is None:
1654
+ model_inputs = {"inputs_embeds": inputs_embeds}
1655
+ else:
1656
+ model_inputs = {"input_ids": input_ids}
1657
+
1658
+ model_inputs.update(
1659
+ {
1660
+ "position_ids": position_ids,
1661
+ "past_key_values": past_key_values,
1662
+ "use_cache": kwargs.get("use_cache"),
1663
+ "attention_mask": attention_mask,
1664
+ "output_router_logits": output_router_logits,
1665
+ }
1666
+ )
1667
+ return model_inputs
1668
+
1669
+ @staticmethod
1670
+ def _reorder_cache(past_key_values, beam_idx):
1671
+ reordered_past = ()
1672
+ for layer_past in past_key_values:
1673
+ reordered_past += (
1674
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1675
+ )
1676
+ return reordered_past
1677
+
1678
+
1679
+ @add_start_docstrings(
1680
+ """
1681
+ The PhiMoE Model transformer with a sequence classification head on top (linear layer).
1682
+
1683
+ [`PhiMoEForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1684
+ (e.g. GPT-2) do.
1685
+
1686
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1687
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1688
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1689
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1690
+ each row of the batch).
1691
+ """,
1692
+ PHIMOE_START_DOCSTRING,
1693
+ )
1694
+ # Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->PhiMoE, LLAMA->PHIMOE
1695
+ class PhiMoEForSequenceClassification(PhiMoEPreTrainedModel):
1696
+ def __init__(self, config):
1697
+ super().__init__(config)
1698
+ self.num_labels = config.num_labels
1699
+ self.model = PhiMoEModel(config)
1700
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1701
+
1702
+ # Initialize weights and apply final processing
1703
+ self.post_init()
1704
+
1705
+ def get_input_embeddings(self):
1706
+ return self.model.embed_tokens
1707
+
1708
+ def set_input_embeddings(self, value):
1709
+ self.model.embed_tokens = value
1710
+
1711
+ @add_start_docstrings_to_model_forward(PHIMOE_INPUTS_DOCSTRING)
1712
+ def forward(
1713
+ self,
1714
+ input_ids: torch.LongTensor = None,
1715
+ attention_mask: Optional[torch.Tensor] = None,
1716
+ position_ids: Optional[torch.LongTensor] = None,
1717
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1718
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1719
+ labels: Optional[torch.LongTensor] = None,
1720
+ use_cache: Optional[bool] = None,
1721
+ output_attentions: Optional[bool] = None,
1722
+ output_hidden_states: Optional[bool] = None,
1723
+ return_dict: Optional[bool] = None,
1724
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1725
+ r"""
1726
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1727
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, transformers.,
1728
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1729
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1730
+ """
1731
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1732
+
1733
+ transformer_outputs = self.model(
1734
+ input_ids,
1735
+ attention_mask=attention_mask,
1736
+ position_ids=position_ids,
1737
+ past_key_values=past_key_values,
1738
+ inputs_embeds=inputs_embeds,
1739
+ use_cache=use_cache,
1740
+ output_attentions=output_attentions,
1741
+ output_hidden_states=output_hidden_states,
1742
+ return_dict=return_dict,
1743
+ )
1744
+ hidden_states = transformer_outputs[0]
1745
+ logits = self.score(hidden_states)
1746
+
1747
+ if input_ids is not None:
1748
+ batch_size = input_ids.shape[0]
1749
+ else:
1750
+ batch_size = inputs_embeds.shape[0]
1751
+
1752
+ if self.config.pad_token_id is None and batch_size != 1:
1753
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1754
+ if self.config.pad_token_id is None:
1755
+ sequence_lengths = -1
1756
+ else:
1757
+ if input_ids is not None:
1758
+ # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
1759
+ sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
1760
+ sequence_lengths = sequence_lengths % input_ids.shape[-1]
1761
+ sequence_lengths = sequence_lengths.to(logits.device)
1762
+ else:
1763
+ sequence_lengths = -1
1764
+
1765
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1766
+
1767
+ loss = None
1768
+ if labels is not None:
1769
+ labels = labels.to(logits.device)
1770
+ if self.config.problem_type is None:
1771
+ if self.num_labels == 1:
1772
+ self.config.problem_type = "regression"
1773
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1774
+ self.config.problem_type = "single_label_classification"
1775
+ else:
1776
+ self.config.problem_type = "multi_label_classification"
1777
+
1778
+ if self.config.problem_type == "regression":
1779
+ loss_fct = MSELoss()
1780
+ if self.num_labels == 1:
1781
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1782
+ else:
1783
+ loss = loss_fct(pooled_logits, labels)
1784
+ elif self.config.problem_type == "single_label_classification":
1785
+ loss_fct = CrossEntropyLoss()
1786
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1787
+ elif self.config.problem_type == "multi_label_classification":
1788
+ loss_fct = BCEWithLogitsLoss()
1789
+ loss = loss_fct(pooled_logits, labels)
1790
+ if not return_dict:
1791
+ output = (pooled_logits,) + transformer_outputs[1:]
1792
+ return ((loss,) + output) if loss is not None else output
1793
+
1794
+ return SequenceClassifierOutputWithPast(
1795
+ loss=loss,
1796
+ logits=pooled_logits,
1797
+ past_key_values=transformer_outputs.past_key_values,
1798
+ hidden_states=transformer_outputs.hidden_states,
1799
+ attentions=transformer_outputs.attentions,
1800
+ )
sample_finetune.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import logging
3
+
4
+ import deepspeed
5
+ import datasets
6
+ from datasets import load_dataset
7
+ from peft import LoraConfig
8
+ import torch
9
+ import transformers
10
+ from trl import SFTTrainer
11
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments
12
+
13
+ """
14
+ A simple example on using SFTTrainer and Accelerate to finetune Phi-3 models. For
15
+ a more advanced example, please follow HF alignment-handbook/scripts/run_sft.py.
16
+ This example has utilized DeepSpeed ZeRO3 offload to reduce the memory usage. The
17
+ script can be run on A100 or later generation GPUs. Here are some suggestions on
18
+ futher reducing memory consumption:
19
+ - reduce batch size
20
+ - decrease lora dimension
21
+ - restrict lora target modules
22
+ Please follow these steps to run the script:
23
+ 1. Install dependencies:
24
+ conda install -c conda-forge accelerate
25
+ pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
26
+ pip3 install -i https://pypi.org/simple/ bitsandbytes
27
+ pip3 install peft trl transformers datasets
28
+ pip3 install deepspeed
29
+ 2. Setup accelerate and deepspeed config based on the machine used:
30
+ accelerate config
31
+ Here is a sample config for deepspeed zero3:
32
+ compute_environment: LOCAL_MACHINE
33
+ debug: false
34
+ deepspeed_config:
35
+ gradient_accumulation_steps: 1
36
+ offload_optimizer_device: none
37
+ offload_param_device: none
38
+ zero3_init_flag: true
39
+ zero3_save_16bit_model: true
40
+ zero_stage: 3
41
+ distributed_type: DEEPSPEED
42
+ downcast_bf16: 'no'
43
+ enable_cpu_affinity: false
44
+ machine_rank: 0
45
+ main_training_function: main
46
+ mixed_precision: bf16
47
+ num_machines: 1
48
+ num_processes: 2
49
+ rdzv_backend: static
50
+ same_network: true
51
+ tpu_env: []
52
+ tpu_use_cluster: false
53
+ tpu_use_sudo: false
54
+ use_cpu: false
55
+ 3. check accelerate config:
56
+ accelerate env
57
+ 4. Run the code, and make sure to use accelerate launch alongside with
58
+ at least 2 A100 80GB GPUs:
59
+
60
+ accelerate launch sample_finetune.py
61
+ """
62
+
63
+ logger = logging.getLogger(__name__)
64
+
65
+
66
+ ###################
67
+ # Hyper-parameters
68
+ ###################
69
+ training_config = {
70
+ "bf16": True,
71
+ "do_eval": False,
72
+ "learning_rate": 5.0e-06,
73
+ "log_level": "info",
74
+ "logging_steps": 20,
75
+ "logging_strategy": "steps",
76
+ "lr_scheduler_type": "cosine",
77
+ "num_train_epochs": 1,
78
+ "max_steps": -1,
79
+ "output_dir": "./checkpoint_dir",
80
+ "overwrite_output_dir": True,
81
+ "per_device_eval_batch_size": 4,
82
+ "per_device_train_batch_size": 4,
83
+ "remove_unused_columns": True,
84
+ "save_steps": 100,
85
+ "save_total_limit": 1,
86
+ "seed": 0,
87
+ "gradient_checkpointing": True,
88
+ "gradient_checkpointing_kwargs":{"use_reentrant": False},
89
+ "gradient_accumulation_steps": 1,
90
+ "warmup_ratio": 0.2,
91
+ }
92
+
93
+ peft_config = {
94
+ "r": 16,
95
+ "lora_alpha": 32,
96
+ "lora_dropout": 0.05,
97
+ "bias": "none",
98
+ "task_type": "CAUSAL_LM",
99
+ "target_modules": "all-linear",
100
+ "modules_to_save": None,
101
+ }
102
+ train_conf = TrainingArguments(**training_config)
103
+ peft_conf = LoraConfig(**peft_config)
104
+
105
+
106
+ ###############
107
+ # Setup logging
108
+ ###############
109
+ logging.basicConfig(
110
+ format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
111
+ datefmt="%Y-%m-%d %H:%M:%S",
112
+ handlers=[logging.StreamHandler(sys.stdout)],
113
+ )
114
+ log_level = train_conf.get_process_log_level()
115
+ logger.setLevel(log_level)
116
+ datasets.utils.logging.set_verbosity(log_level)
117
+ transformers.utils.logging.set_verbosity(log_level)
118
+ transformers.utils.logging.enable_default_handler()
119
+ transformers.utils.logging.enable_explicit_format()
120
+
121
+ # Log on each process a small summary
122
+ logger.warning(
123
+ f"Process rank: {train_conf.local_rank}, device: {train_conf.device}, n_gpu: {train_conf.n_gpu}"
124
+ + f" distributed training: {bool(train_conf.local_rank != -1)}, 16-bits training: {train_conf.fp16}"
125
+ )
126
+ logger.info(f"Training/evaluation parameters {train_conf}")
127
+ logger.info(f"PEFT parameters {peft_conf}")
128
+
129
+
130
+ ################
131
+ # Model Loading
132
+ ################
133
+ checkpoint_path = "microsoft/Phi-3.5-MoE-instruct"
134
+ model_kwargs = dict(
135
+ use_cache=False,
136
+ trust_remote_code=True,
137
+ attn_implementation="flash_attention_2", # loading the model with flash-attenstion support
138
+ torch_dtype=torch.bfloat16,
139
+ device_map=None
140
+ )
141
+ model = AutoModelForCausalLM.from_pretrained(checkpoint_path, **model_kwargs)
142
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)
143
+ tokenizer.model_max_length = 2048
144
+ tokenizer.pad_token = tokenizer.unk_token # use unk rather than eos token to prevent endless generation
145
+ tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids(tokenizer.pad_token)
146
+ tokenizer.padding_side = 'right'
147
+
148
+ for m in model.modules():
149
+ # https://github.com/microsoft/DeepSpeed/pull/4966
150
+ if "PhiMoESparseMoeBlock" in m.__class__.__name__:
151
+ deepspeed.utils.set_z3_leaf_modules(model, [m.__class__])
152
+ logger.info(f"Setting zero3 leaf for model on class with name: {m.__class__.__name__}")
153
+ break
154
+
155
+
156
+ ##################
157
+ # Data Processing
158
+ ##################
159
+ def apply_chat_template(
160
+ example,
161
+ tokenizer,
162
+ ):
163
+ messages = example["messages"]
164
+ example["text"] = tokenizer.apply_chat_template(
165
+ messages, tokenize=False, add_generation_prompt=False)
166
+ return example
167
+
168
+ raw_dataset = load_dataset("HuggingFaceH4/ultrachat_200k")
169
+ train_dataset = raw_dataset["train_sft"]
170
+ test_dataset = raw_dataset["test_sft"]
171
+ column_names = list(train_dataset.features)
172
+
173
+ processed_train_dataset = train_dataset.map(
174
+ apply_chat_template,
175
+ fn_kwargs={"tokenizer": tokenizer},
176
+ num_proc=10,
177
+ remove_columns=column_names,
178
+ desc="Applying chat template to train_sft",
179
+ )
180
+
181
+ processed_test_dataset = test_dataset.map(
182
+ apply_chat_template,
183
+ fn_kwargs={"tokenizer": tokenizer},
184
+ num_proc=10,
185
+ remove_columns=column_names,
186
+ desc="Applying chat template to test_sft",
187
+ )
188
+
189
+
190
+ ###########
191
+ # Training
192
+ ###########
193
+ trainer = SFTTrainer(
194
+ model=model,
195
+ args=train_conf,
196
+ peft_config=peft_conf,
197
+ train_dataset=processed_train_dataset,
198
+ eval_dataset=processed_test_dataset,
199
+ max_seq_length=2048,
200
+ dataset_text_field="text",
201
+ tokenizer=tokenizer,
202
+ packing=True
203
+ )
204
+ train_result = trainer.train()
205
+ metrics = train_result.metrics
206
+ trainer.log_metrics("train", metrics)
207
+ trainer.save_metrics("train", metrics)
208
+ trainer.save_state()
209
+
210
+
211
+ #############
212
+ # Evaluation
213
+ #############
214
+ tokenizer.padding_side = 'left'
215
+ metrics = trainer.evaluate()
216
+ metrics["eval_samples"] = len(processed_test_dataset)
217
+ trainer.log_metrics("eval", metrics)
218
+ trainer.save_metrics("eval", metrics)
219
+
220
+
221
+ # ############
222
+ # # Save model
223
+ # ############
224
+ trainer.save_model(train_conf.output_dir)
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": {
17
+ "content": "<|endoftext|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
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:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": true,
26
+ "single_word": false,
27
+ "special": false
28
+ },
29
+ "32000": {
30
+ "content": "<|endoftext|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "32001": {
38
+ "content": "<|assistant|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": true,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "32002": {
46
+ "content": "<|placeholder1|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": true,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "32003": {
54
+ "content": "<|placeholder2|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": true,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "32004": {
62
+ "content": "<|placeholder3|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": true,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "32005": {
70
+ "content": "<|placeholder4|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": true,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "32006": {
78
+ "content": "<|system|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": true,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "32007": {
86
+ "content": "<|end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": true,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "32008": {
94
+ "content": "<|placeholder5|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": true,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "32009": {
102
+ "content": "<|placeholder6|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": true,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "32010": {
110
+ "content": "<|user|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": true,
114
+ "single_word": false,
115
+ "special": true
116
+ }
117
+ },
118
+ "bos_token": "<s>",
119
+ "chat_template": "{% for message in messages %}{% if message['role'] == 'system' and message['content'] %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
120
+ "clean_up_tokenization_spaces": false,
121
+ "eos_token": "<|endoftext|>",
122
+ "legacy": false,
123
+ "model_max_length": 131072,
124
+ "pad_token": "<|endoftext|>",
125
+ "padding_side": "left",
126
+ "sp_model_kwargs": {},
127
+ "tokenizer_class": "LlamaTokenizer",
128
+ "unk_token": "<unk>",
129
+ "use_default_system_prompt": false
130
+ }