erniesg commited on
Commit
1f40746
·
verified ·
1 Parent(s): 3576dd3

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: mit
5
+ tags:
6
+ - nlp
7
+ - code
8
+ - mlx
9
+ license_link: https://huggingface.co/microsoft/phi-2/resolve/main/LICENSE
10
+ pipeline_tag: text-generation
11
+ ---
12
+
13
+ # erniesg/boya
14
+ This model was converted to MLX format from [`microsoft/phi-2`]().
15
+ Refer to the [original model card](https://huggingface.co/microsoft/phi-2) for more details on the model.
16
+ ## Use with mlx
17
+
18
+ ```bash
19
+ pip install mlx-lm
20
+ ```
21
+
22
+ ```python
23
+ from mlx_lm import load, generate
24
+
25
+ model, tokenizer = load("erniesg/boya")
26
+ response = generate(model, tokenizer, prompt="hello", verbose=True)
27
+ ```
added_tokens.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\t\t": 50294,
3
+ "\t\t\t": 50293,
4
+ "\t\t\t\t": 50292,
5
+ "\t\t\t\t\t": 50291,
6
+ "\t\t\t\t\t\t": 50290,
7
+ "\t\t\t\t\t\t\t": 50289,
8
+ "\t\t\t\t\t\t\t\t": 50288,
9
+ "\t\t\t\t\t\t\t\t\t": 50287,
10
+ " ": 50286,
11
+ " ": 50285,
12
+ " ": 50284,
13
+ " ": 50283,
14
+ " ": 50282,
15
+ " ": 50281,
16
+ " ": 50280,
17
+ " ": 50279,
18
+ " ": 50278,
19
+ " ": 50277,
20
+ " ": 50276,
21
+ " ": 50275,
22
+ " ": 50274,
23
+ " ": 50273,
24
+ " ": 50272,
25
+ " ": 50271,
26
+ " ": 50270,
27
+ " ": 50269,
28
+ " ": 50268,
29
+ " ": 50267,
30
+ " ": 50266,
31
+ " ": 50265,
32
+ " ": 50264,
33
+ " ": 50263,
34
+ " ": 50262,
35
+ " ": 50261,
36
+ " ": 50260,
37
+ " ": 50259,
38
+ " ": 50258,
39
+ " ": 50257
40
+ }
config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/phi-2",
3
+ "architectures": [
4
+ "Phi2MoeForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_phi.PhiConfig",
8
+ "AutoModelForCausalLM": "modeling_phi.PhiForCausalLM"
9
+ },
10
+ "attention_dropout": 0.0,
11
+ "bos_token_id": 50256,
12
+ "embd_pdrop": 0.0,
13
+ "eos_token_id": 50256,
14
+ "hidden_act": "gelu_new",
15
+ "hidden_size": 2560,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 10240,
18
+ "layer_norm_eps": 1e-05,
19
+ "max_position_embeddings": 2048,
20
+ "model_type": "phi2moe",
21
+ "num_attention_heads": 32,
22
+ "num_hidden_layers": 32,
23
+ "num_key_value_heads": 32,
24
+ "partial_rotary_factor": 0.4,
25
+ "qk_layernorm": false,
26
+ "resid_pdrop": 0.1,
27
+ "rope_scaling": null,
28
+ "rope_theta": 10000.0,
29
+ "tie_word_embeddings": false,
30
+ "torch_dtype": "bfloat16",
31
+ "transformers_version": "4.37.0",
32
+ "use_cache": true,
33
+ "vocab_size": 51200,
34
+ "num_local_experts": 3,
35
+ "num_experts_per_tok": 2
36
+ }
configuration_phi.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 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
+ """ Phi model configuration"""
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
+ PHI_PRETRAINED_CONFIG_ARCHIVE_MAP = {
26
+ "microsoft/phi-2": "https://huggingface.co/microsoft/phi-2/resolve/main/config.json",
27
+ }
28
+
29
+
30
+ class PhiConfig(PretrainedConfig):
31
+ r"""
32
+ This is the configuration class to store the configuration of a [`PhiModel`]. It is used to instantiate an Phi
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 Phi
35
+ [microsoft/phi-1](https://huggingface.co/microsoft/phi-1).
36
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
37
+ documentation from [`PretrainedConfig`] for more information.
38
+ Args:
39
+ vocab_size (`int`, *optional*, defaults to 51200):
40
+ Vocabulary size of the Phi model. Defines the number of different tokens that can be represented by the
41
+ `inputs_ids` passed when calling [`PhiModel`].
42
+ hidden_size (`int`, *optional*, defaults to 2048):
43
+ Dimension of the hidden representations.
44
+ intermediate_size (`int`, *optional*, defaults to 8192):
45
+ Dimension of the MLP representations.
46
+ num_hidden_layers (`int`, *optional*, defaults to 24):
47
+ Number of hidden layers in the Transformer decoder.
48
+ num_attention_heads (`int`, *optional*, defaults to 32):
49
+ Number of attention heads for each attention layer in the Transformer decoder.
50
+ num_key_value_heads (`int`, *optional*):
51
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
52
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
53
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
54
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
55
+ by meanpooling all the original heads within that group. For more details checkout [this
56
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
57
+ `num_attention_heads`.
58
+ resid_pdrop (`float`, *optional*, defaults to 0.0):
59
+ Dropout probability for mlp outputs.
60
+ embd_pdrop (`int`, *optional*, defaults to 0.0):
61
+ The dropout ratio for the embeddings.
62
+ attention_dropout (`float`, *optional*, defaults to 0.0):
63
+ The dropout ratio after computing the attention scores.
64
+ hidden_act (`str` or `function`, *optional*, defaults to `"gelu_new"`):
65
+ The non-linear activation function (function or string) in the decoder.
66
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
67
+ The maximum sequence length that this model might ever be used with. Phi-1 and Phi-1.5 supports up to 2048
68
+ tokens.
69
+ initializer_range (`float`, *optional*, defaults to 0.02):
70
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
71
+ layer_norm_eps (`float`, *optional*, defaults to 1e-05):
72
+ The epsilon used by the rms normalization layers.
73
+ use_cache (`bool`, *optional*, defaults to `True`):
74
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
75
+ relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
76
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
77
+ Whether to tie weight embeddings
78
+ rope_theta (`float`, *optional*, defaults to 10000.0):
79
+ The base period of the RoPE embeddings.
80
+ rope_scaling (`Dict`, *optional*):
81
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
82
+ strategies: linear and dynamic. Their scaling factor must be an float greater than 1. The expected format
83
+ is `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
84
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
85
+ these scaling strategies behave:
86
+ https://www.reddit.com/r/LocalPersimmon/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This
87
+ is an experimental feature, subject to breaking API changes in future versions.
88
+ partial_rotary_factor (`float`, *optional*, defaults to 0.5):
89
+ Percentage of the query and keys which will have rotary embedding.
90
+ qk_layernorm (`bool`, *optional*, defaults to `False`):
91
+ Whether or not to normalize the Queries and Keys after projecting the hidden states.
92
+ bos_token_id (`int`, *optional*, defaults to 1):
93
+ Denotes beginning of sequences token id.
94
+ eos_token_id (`int`, *optional*, defaults to 2):
95
+ Denotes end of sequences token id.
96
+ Example:
97
+ ```python
98
+ >>> from transformers import PhiModel, PhiConfig
99
+ >>> # Initializing a Phi-1 style configuration
100
+ >>> configuration = PhiConfig.from_pretrained("microsoft/phi-1")
101
+ >>> # Initializing a model from the configuration
102
+ >>> model = PhiModel(configuration)
103
+ >>> # Accessing the model configuration
104
+ >>> configuration = model.config
105
+ ```"""
106
+
107
+ model_type = "phi"
108
+ keys_to_ignore_at_inference = ["past_key_values"]
109
+
110
+ def __init__(
111
+ self,
112
+ vocab_size=51200,
113
+ hidden_size=2048,
114
+ intermediate_size=8192,
115
+ num_hidden_layers=24,
116
+ num_attention_heads=32,
117
+ num_key_value_heads=None,
118
+ resid_pdrop=0.0,
119
+ embd_pdrop=0.0,
120
+ attention_dropout=0.0,
121
+ hidden_act="gelu_new",
122
+ max_position_embeddings=2048,
123
+ initializer_range=0.02,
124
+ layer_norm_eps=1e-5,
125
+ use_cache=True,
126
+ tie_word_embeddings=False,
127
+ rope_theta=10000.0,
128
+ rope_scaling=None,
129
+ partial_rotary_factor=0.5,
130
+ qk_layernorm=False,
131
+ bos_token_id=1,
132
+ eos_token_id=2,
133
+ num_local_experts= 3,
134
+ num_experts_per_tok= 2,
135
+ **kwargs,
136
+ ):
137
+ self.vocab_size = vocab_size
138
+ self.hidden_size = hidden_size
139
+ self.intermediate_size = intermediate_size
140
+ self.num_hidden_layers = num_hidden_layers
141
+ self.num_attention_heads = num_attention_heads
142
+
143
+ if num_key_value_heads is None:
144
+ num_key_value_heads = num_attention_heads
145
+
146
+ self.num_key_value_heads = num_key_value_heads
147
+ self.resid_pdrop = resid_pdrop
148
+ self.embd_pdrop = embd_pdrop
149
+ self.attention_dropout = attention_dropout
150
+ self.hidden_act = hidden_act
151
+ self.max_position_embeddings = max_position_embeddings
152
+ self.initializer_range = initializer_range
153
+ self.layer_norm_eps = layer_norm_eps
154
+ self.use_cache = use_cache
155
+ self.rope_theta = rope_theta
156
+ self.rope_scaling = rope_scaling
157
+ self.partial_rotary_factor = partial_rotary_factor
158
+ self.qk_layernorm = qk_layernorm
159
+ self._rope_scaling_validation()
160
+ self.num_local_experts =num_local_experts
161
+ self.num_experts_per_tok = num_experts_per_tok
162
+ super().__init__(
163
+ bos_token_id=bos_token_id,
164
+ eos_token_id=eos_token_id,
165
+ tie_word_embeddings=tie_word_embeddings,
166
+ **kwargs,
167
+ )
168
+
169
+ # Copied from transformers.models.llama.configuration_llama.LlamaConfig._rope_scaling_validation
170
+ def _rope_scaling_validation(self):
171
+ """
172
+ Validate the `rope_scaling` configuration.
173
+ """
174
+ if self.rope_scaling is None:
175
+ return
176
+
177
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
178
+ raise ValueError(
179
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
180
+ f"got {self.rope_scaling}"
181
+ )
182
+ rope_scaling_type = self.rope_scaling.get("type", None)
183
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
184
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
185
+ raise ValueError(
186
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
187
+ )
188
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
189
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1f4bb0d3be0a6bbff0bc0214e29d5f15b108541ca5c8a778d7fa71b36687a1b
3
+ size 5349481192
model-00002-of-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b77fbc45ce039e7e5fcc14b86dcba21be3e8da30e83b4e410548e8744188644
3
+ size 5349575944
model-00003-of-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:136e5ee25267ebe7f424909bc1f62cad615662e316e45173308e2f73309edd50
3
+ size 1573416720
model.safetensors.index.json ADDED
@@ -0,0 +1,748 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 12272875520
4
+ },
5
+ "weight_map": {
6
+ "lm_head.bias": "model-00003-of-00003.safetensors",
7
+ "lm_head.weight": "model-00003-of-00003.safetensors",
8
+ "model.embed_tokens.weight": "model-00001-of-00003.safetensors",
9
+ "model.final_layernorm.bias": "model-00003-of-00003.safetensors",
10
+ "model.final_layernorm.weight": "model-00003-of-00003.safetensors",
11
+ "model.layers.0.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
12
+ "model.layers.0.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
13
+ "model.layers.0.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
14
+ "model.layers.0.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
15
+ "model.layers.0.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
16
+ "model.layers.0.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
17
+ "model.layers.0.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
18
+ "model.layers.0.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
19
+ "model.layers.0.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
20
+ "model.layers.0.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
21
+ "model.layers.0.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
22
+ "model.layers.0.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
23
+ "model.layers.0.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
24
+ "model.layers.0.input_layernorm.bias": "model-00001-of-00003.safetensors",
25
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00003.safetensors",
26
+ "model.layers.0.self_attn.dense.bias": "model-00001-of-00003.safetensors",
27
+ "model.layers.0.self_attn.dense.weight": "model-00001-of-00003.safetensors",
28
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
29
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
30
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
31
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
32
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
33
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
34
+ "model.layers.1.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
35
+ "model.layers.1.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
36
+ "model.layers.1.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
37
+ "model.layers.1.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
38
+ "model.layers.1.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
39
+ "model.layers.1.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
40
+ "model.layers.1.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
41
+ "model.layers.1.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
42
+ "model.layers.1.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
43
+ "model.layers.1.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
44
+ "model.layers.1.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
45
+ "model.layers.1.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
46
+ "model.layers.1.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
47
+ "model.layers.1.input_layernorm.bias": "model-00001-of-00003.safetensors",
48
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00003.safetensors",
49
+ "model.layers.1.self_attn.dense.bias": "model-00001-of-00003.safetensors",
50
+ "model.layers.1.self_attn.dense.weight": "model-00001-of-00003.safetensors",
51
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
52
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
53
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
54
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
55
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
56
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
57
+ "model.layers.10.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
58
+ "model.layers.10.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
59
+ "model.layers.10.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
60
+ "model.layers.10.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
61
+ "model.layers.10.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
62
+ "model.layers.10.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
63
+ "model.layers.10.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
64
+ "model.layers.10.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
65
+ "model.layers.10.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
66
+ "model.layers.10.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
67
+ "model.layers.10.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
68
+ "model.layers.10.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
69
+ "model.layers.10.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
70
+ "model.layers.10.input_layernorm.bias": "model-00001-of-00003.safetensors",
71
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00003.safetensors",
72
+ "model.layers.10.self_attn.dense.bias": "model-00001-of-00003.safetensors",
73
+ "model.layers.10.self_attn.dense.weight": "model-00001-of-00003.safetensors",
74
+ "model.layers.10.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
75
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
76
+ "model.layers.10.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
77
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
78
+ "model.layers.10.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
79
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
80
+ "model.layers.11.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
81
+ "model.layers.11.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
82
+ "model.layers.11.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
83
+ "model.layers.11.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
84
+ "model.layers.11.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
85
+ "model.layers.11.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
86
+ "model.layers.11.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
87
+ "model.layers.11.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
88
+ "model.layers.11.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
89
+ "model.layers.11.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
90
+ "model.layers.11.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
91
+ "model.layers.11.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
92
+ "model.layers.11.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
93
+ "model.layers.11.input_layernorm.bias": "model-00001-of-00003.safetensors",
94
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00003.safetensors",
95
+ "model.layers.11.self_attn.dense.bias": "model-00001-of-00003.safetensors",
96
+ "model.layers.11.self_attn.dense.weight": "model-00001-of-00003.safetensors",
97
+ "model.layers.11.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
98
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
99
+ "model.layers.11.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
100
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
101
+ "model.layers.11.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
102
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
103
+ "model.layers.12.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
104
+ "model.layers.12.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
105
+ "model.layers.12.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
106
+ "model.layers.12.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
107
+ "model.layers.12.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
108
+ "model.layers.12.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
109
+ "model.layers.12.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
110
+ "model.layers.12.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
111
+ "model.layers.12.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
112
+ "model.layers.12.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
113
+ "model.layers.12.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
114
+ "model.layers.12.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
115
+ "model.layers.12.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
116
+ "model.layers.12.input_layernorm.bias": "model-00001-of-00003.safetensors",
117
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00003.safetensors",
118
+ "model.layers.12.self_attn.dense.bias": "model-00001-of-00003.safetensors",
119
+ "model.layers.12.self_attn.dense.weight": "model-00001-of-00003.safetensors",
120
+ "model.layers.12.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
121
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
122
+ "model.layers.12.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
123
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
124
+ "model.layers.12.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
125
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
126
+ "model.layers.13.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
127
+ "model.layers.13.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
128
+ "model.layers.13.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
129
+ "model.layers.13.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
130
+ "model.layers.13.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
131
+ "model.layers.13.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
132
+ "model.layers.13.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
133
+ "model.layers.13.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
134
+ "model.layers.13.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
135
+ "model.layers.13.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
136
+ "model.layers.13.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
137
+ "model.layers.13.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
138
+ "model.layers.13.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
139
+ "model.layers.13.input_layernorm.bias": "model-00002-of-00003.safetensors",
140
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00003.safetensors",
141
+ "model.layers.13.self_attn.dense.bias": "model-00001-of-00003.safetensors",
142
+ "model.layers.13.self_attn.dense.weight": "model-00001-of-00003.safetensors",
143
+ "model.layers.13.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
144
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
145
+ "model.layers.13.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
146
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
147
+ "model.layers.13.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
148
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
149
+ "model.layers.14.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
150
+ "model.layers.14.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
151
+ "model.layers.14.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
152
+ "model.layers.14.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
153
+ "model.layers.14.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
154
+ "model.layers.14.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
155
+ "model.layers.14.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
156
+ "model.layers.14.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
157
+ "model.layers.14.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
158
+ "model.layers.14.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
159
+ "model.layers.14.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
160
+ "model.layers.14.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
161
+ "model.layers.14.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
162
+ "model.layers.14.input_layernorm.bias": "model-00002-of-00003.safetensors",
163
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00003.safetensors",
164
+ "model.layers.14.self_attn.dense.bias": "model-00002-of-00003.safetensors",
165
+ "model.layers.14.self_attn.dense.weight": "model-00002-of-00003.safetensors",
166
+ "model.layers.14.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
167
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
168
+ "model.layers.14.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
169
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
170
+ "model.layers.14.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
171
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
172
+ "model.layers.15.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
173
+ "model.layers.15.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
174
+ "model.layers.15.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
175
+ "model.layers.15.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
176
+ "model.layers.15.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
177
+ "model.layers.15.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
178
+ "model.layers.15.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
179
+ "model.layers.15.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
180
+ "model.layers.15.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
181
+ "model.layers.15.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
182
+ "model.layers.15.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
183
+ "model.layers.15.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
184
+ "model.layers.15.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
185
+ "model.layers.15.input_layernorm.bias": "model-00002-of-00003.safetensors",
186
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00003.safetensors",
187
+ "model.layers.15.self_attn.dense.bias": "model-00002-of-00003.safetensors",
188
+ "model.layers.15.self_attn.dense.weight": "model-00002-of-00003.safetensors",
189
+ "model.layers.15.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
190
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
191
+ "model.layers.15.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
192
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
193
+ "model.layers.15.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
194
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
195
+ "model.layers.16.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
196
+ "model.layers.16.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
197
+ "model.layers.16.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
198
+ "model.layers.16.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
199
+ "model.layers.16.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
200
+ "model.layers.16.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
201
+ "model.layers.16.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
202
+ "model.layers.16.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
203
+ "model.layers.16.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
204
+ "model.layers.16.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
205
+ "model.layers.16.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
206
+ "model.layers.16.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
207
+ "model.layers.16.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
208
+ "model.layers.16.input_layernorm.bias": "model-00002-of-00003.safetensors",
209
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00003.safetensors",
210
+ "model.layers.16.self_attn.dense.bias": "model-00002-of-00003.safetensors",
211
+ "model.layers.16.self_attn.dense.weight": "model-00002-of-00003.safetensors",
212
+ "model.layers.16.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
213
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
214
+ "model.layers.16.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
215
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
216
+ "model.layers.16.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
217
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
218
+ "model.layers.17.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
219
+ "model.layers.17.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
220
+ "model.layers.17.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
221
+ "model.layers.17.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
222
+ "model.layers.17.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
223
+ "model.layers.17.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
224
+ "model.layers.17.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
225
+ "model.layers.17.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
226
+ "model.layers.17.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
227
+ "model.layers.17.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
228
+ "model.layers.17.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
229
+ "model.layers.17.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
230
+ "model.layers.17.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
231
+ "model.layers.17.input_layernorm.bias": "model-00002-of-00003.safetensors",
232
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00003.safetensors",
233
+ "model.layers.17.self_attn.dense.bias": "model-00002-of-00003.safetensors",
234
+ "model.layers.17.self_attn.dense.weight": "model-00002-of-00003.safetensors",
235
+ "model.layers.17.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
236
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
237
+ "model.layers.17.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
238
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
239
+ "model.layers.17.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
240
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
241
+ "model.layers.18.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
242
+ "model.layers.18.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
243
+ "model.layers.18.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
244
+ "model.layers.18.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
245
+ "model.layers.18.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
246
+ "model.layers.18.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
247
+ "model.layers.18.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
248
+ "model.layers.18.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
249
+ "model.layers.18.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
250
+ "model.layers.18.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
251
+ "model.layers.18.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
252
+ "model.layers.18.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
253
+ "model.layers.18.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
254
+ "model.layers.18.input_layernorm.bias": "model-00002-of-00003.safetensors",
255
+ "model.layers.18.input_layernorm.weight": "model-00002-of-00003.safetensors",
256
+ "model.layers.18.self_attn.dense.bias": "model-00002-of-00003.safetensors",
257
+ "model.layers.18.self_attn.dense.weight": "model-00002-of-00003.safetensors",
258
+ "model.layers.18.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
259
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
260
+ "model.layers.18.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
261
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
262
+ "model.layers.18.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
263
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
264
+ "model.layers.19.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
265
+ "model.layers.19.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
266
+ "model.layers.19.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
267
+ "model.layers.19.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
268
+ "model.layers.19.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
269
+ "model.layers.19.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
270
+ "model.layers.19.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
271
+ "model.layers.19.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
272
+ "model.layers.19.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
273
+ "model.layers.19.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
274
+ "model.layers.19.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
275
+ "model.layers.19.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
276
+ "model.layers.19.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
277
+ "model.layers.19.input_layernorm.bias": "model-00002-of-00003.safetensors",
278
+ "model.layers.19.input_layernorm.weight": "model-00002-of-00003.safetensors",
279
+ "model.layers.19.self_attn.dense.bias": "model-00002-of-00003.safetensors",
280
+ "model.layers.19.self_attn.dense.weight": "model-00002-of-00003.safetensors",
281
+ "model.layers.19.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
282
+ "model.layers.19.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
283
+ "model.layers.19.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
284
+ "model.layers.19.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
285
+ "model.layers.19.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
286
+ "model.layers.19.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
287
+ "model.layers.2.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
288
+ "model.layers.2.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
289
+ "model.layers.2.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
290
+ "model.layers.2.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
291
+ "model.layers.2.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
292
+ "model.layers.2.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
293
+ "model.layers.2.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
294
+ "model.layers.2.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
295
+ "model.layers.2.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
296
+ "model.layers.2.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
297
+ "model.layers.2.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
298
+ "model.layers.2.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
299
+ "model.layers.2.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
300
+ "model.layers.2.input_layernorm.bias": "model-00001-of-00003.safetensors",
301
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00003.safetensors",
302
+ "model.layers.2.self_attn.dense.bias": "model-00001-of-00003.safetensors",
303
+ "model.layers.2.self_attn.dense.weight": "model-00001-of-00003.safetensors",
304
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
305
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
306
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
307
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
308
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
309
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
310
+ "model.layers.20.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
311
+ "model.layers.20.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
312
+ "model.layers.20.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
313
+ "model.layers.20.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
314
+ "model.layers.20.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
315
+ "model.layers.20.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
316
+ "model.layers.20.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
317
+ "model.layers.20.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
318
+ "model.layers.20.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
319
+ "model.layers.20.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
320
+ "model.layers.20.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
321
+ "model.layers.20.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
322
+ "model.layers.20.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
323
+ "model.layers.20.input_layernorm.bias": "model-00002-of-00003.safetensors",
324
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00003.safetensors",
325
+ "model.layers.20.self_attn.dense.bias": "model-00002-of-00003.safetensors",
326
+ "model.layers.20.self_attn.dense.weight": "model-00002-of-00003.safetensors",
327
+ "model.layers.20.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
328
+ "model.layers.20.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
329
+ "model.layers.20.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
330
+ "model.layers.20.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
331
+ "model.layers.20.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
332
+ "model.layers.20.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
333
+ "model.layers.21.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
334
+ "model.layers.21.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
335
+ "model.layers.21.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
336
+ "model.layers.21.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
337
+ "model.layers.21.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
338
+ "model.layers.21.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
339
+ "model.layers.21.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
340
+ "model.layers.21.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
341
+ "model.layers.21.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
342
+ "model.layers.21.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
343
+ "model.layers.21.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
344
+ "model.layers.21.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
345
+ "model.layers.21.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
346
+ "model.layers.21.input_layernorm.bias": "model-00002-of-00003.safetensors",
347
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00003.safetensors",
348
+ "model.layers.21.self_attn.dense.bias": "model-00002-of-00003.safetensors",
349
+ "model.layers.21.self_attn.dense.weight": "model-00002-of-00003.safetensors",
350
+ "model.layers.21.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
351
+ "model.layers.21.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
352
+ "model.layers.21.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
353
+ "model.layers.21.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
354
+ "model.layers.21.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
355
+ "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
356
+ "model.layers.22.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
357
+ "model.layers.22.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
358
+ "model.layers.22.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
359
+ "model.layers.22.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
360
+ "model.layers.22.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
361
+ "model.layers.22.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
362
+ "model.layers.22.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
363
+ "model.layers.22.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
364
+ "model.layers.22.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
365
+ "model.layers.22.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
366
+ "model.layers.22.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
367
+ "model.layers.22.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
368
+ "model.layers.22.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
369
+ "model.layers.22.input_layernorm.bias": "model-00002-of-00003.safetensors",
370
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00003.safetensors",
371
+ "model.layers.22.self_attn.dense.bias": "model-00002-of-00003.safetensors",
372
+ "model.layers.22.self_attn.dense.weight": "model-00002-of-00003.safetensors",
373
+ "model.layers.22.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
374
+ "model.layers.22.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
375
+ "model.layers.22.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
376
+ "model.layers.22.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
377
+ "model.layers.22.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
378
+ "model.layers.22.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
379
+ "model.layers.23.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
380
+ "model.layers.23.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
381
+ "model.layers.23.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
382
+ "model.layers.23.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
383
+ "model.layers.23.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
384
+ "model.layers.23.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
385
+ "model.layers.23.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
386
+ "model.layers.23.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
387
+ "model.layers.23.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
388
+ "model.layers.23.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
389
+ "model.layers.23.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
390
+ "model.layers.23.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
391
+ "model.layers.23.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
392
+ "model.layers.23.input_layernorm.bias": "model-00002-of-00003.safetensors",
393
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00003.safetensors",
394
+ "model.layers.23.self_attn.dense.bias": "model-00002-of-00003.safetensors",
395
+ "model.layers.23.self_attn.dense.weight": "model-00002-of-00003.safetensors",
396
+ "model.layers.23.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
397
+ "model.layers.23.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
398
+ "model.layers.23.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
399
+ "model.layers.23.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
400
+ "model.layers.23.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
401
+ "model.layers.23.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
402
+ "model.layers.24.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
403
+ "model.layers.24.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
404
+ "model.layers.24.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
405
+ "model.layers.24.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
406
+ "model.layers.24.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
407
+ "model.layers.24.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
408
+ "model.layers.24.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
409
+ "model.layers.24.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
410
+ "model.layers.24.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
411
+ "model.layers.24.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
412
+ "model.layers.24.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
413
+ "model.layers.24.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
414
+ "model.layers.24.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
415
+ "model.layers.24.input_layernorm.bias": "model-00002-of-00003.safetensors",
416
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00003.safetensors",
417
+ "model.layers.24.self_attn.dense.bias": "model-00002-of-00003.safetensors",
418
+ "model.layers.24.self_attn.dense.weight": "model-00002-of-00003.safetensors",
419
+ "model.layers.24.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
420
+ "model.layers.24.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
421
+ "model.layers.24.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
422
+ "model.layers.24.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
423
+ "model.layers.24.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
424
+ "model.layers.24.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
425
+ "model.layers.25.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
426
+ "model.layers.25.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
427
+ "model.layers.25.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
428
+ "model.layers.25.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
429
+ "model.layers.25.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
430
+ "model.layers.25.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
431
+ "model.layers.25.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
432
+ "model.layers.25.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
433
+ "model.layers.25.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
434
+ "model.layers.25.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
435
+ "model.layers.25.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
436
+ "model.layers.25.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
437
+ "model.layers.25.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
438
+ "model.layers.25.input_layernorm.bias": "model-00002-of-00003.safetensors",
439
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00003.safetensors",
440
+ "model.layers.25.self_attn.dense.bias": "model-00002-of-00003.safetensors",
441
+ "model.layers.25.self_attn.dense.weight": "model-00002-of-00003.safetensors",
442
+ "model.layers.25.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
443
+ "model.layers.25.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
444
+ "model.layers.25.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
445
+ "model.layers.25.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
446
+ "model.layers.25.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
447
+ "model.layers.25.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
448
+ "model.layers.26.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
449
+ "model.layers.26.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
450
+ "model.layers.26.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
451
+ "model.layers.26.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
452
+ "model.layers.26.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
453
+ "model.layers.26.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
454
+ "model.layers.26.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
455
+ "model.layers.26.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
456
+ "model.layers.26.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
457
+ "model.layers.26.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
458
+ "model.layers.26.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
459
+ "model.layers.26.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
460
+ "model.layers.26.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
461
+ "model.layers.26.input_layernorm.bias": "model-00002-of-00003.safetensors",
462
+ "model.layers.26.input_layernorm.weight": "model-00002-of-00003.safetensors",
463
+ "model.layers.26.self_attn.dense.bias": "model-00002-of-00003.safetensors",
464
+ "model.layers.26.self_attn.dense.weight": "model-00002-of-00003.safetensors",
465
+ "model.layers.26.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
466
+ "model.layers.26.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
467
+ "model.layers.26.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
468
+ "model.layers.26.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
469
+ "model.layers.26.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
470
+ "model.layers.26.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
471
+ "model.layers.27.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
472
+ "model.layers.27.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
473
+ "model.layers.27.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
474
+ "model.layers.27.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
475
+ "model.layers.27.block_sparse_moe.experts.1.fc1.bias": "model-00002-of-00003.safetensors",
476
+ "model.layers.27.block_sparse_moe.experts.1.fc1.weight": "model-00002-of-00003.safetensors",
477
+ "model.layers.27.block_sparse_moe.experts.1.fc2.bias": "model-00002-of-00003.safetensors",
478
+ "model.layers.27.block_sparse_moe.experts.1.fc2.weight": "model-00002-of-00003.safetensors",
479
+ "model.layers.27.block_sparse_moe.experts.2.fc1.bias": "model-00002-of-00003.safetensors",
480
+ "model.layers.27.block_sparse_moe.experts.2.fc1.weight": "model-00002-of-00003.safetensors",
481
+ "model.layers.27.block_sparse_moe.experts.2.fc2.bias": "model-00002-of-00003.safetensors",
482
+ "model.layers.27.block_sparse_moe.experts.2.fc2.weight": "model-00002-of-00003.safetensors",
483
+ "model.layers.27.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
484
+ "model.layers.27.input_layernorm.bias": "model-00002-of-00003.safetensors",
485
+ "model.layers.27.input_layernorm.weight": "model-00002-of-00003.safetensors",
486
+ "model.layers.27.self_attn.dense.bias": "model-00002-of-00003.safetensors",
487
+ "model.layers.27.self_attn.dense.weight": "model-00002-of-00003.safetensors",
488
+ "model.layers.27.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
489
+ "model.layers.27.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
490
+ "model.layers.27.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
491
+ "model.layers.27.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
492
+ "model.layers.27.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
493
+ "model.layers.27.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
494
+ "model.layers.28.block_sparse_moe.experts.0.fc1.bias": "model-00002-of-00003.safetensors",
495
+ "model.layers.28.block_sparse_moe.experts.0.fc1.weight": "model-00002-of-00003.safetensors",
496
+ "model.layers.28.block_sparse_moe.experts.0.fc2.bias": "model-00002-of-00003.safetensors",
497
+ "model.layers.28.block_sparse_moe.experts.0.fc2.weight": "model-00002-of-00003.safetensors",
498
+ "model.layers.28.block_sparse_moe.experts.1.fc1.bias": "model-00003-of-00003.safetensors",
499
+ "model.layers.28.block_sparse_moe.experts.1.fc1.weight": "model-00003-of-00003.safetensors",
500
+ "model.layers.28.block_sparse_moe.experts.1.fc2.bias": "model-00003-of-00003.safetensors",
501
+ "model.layers.28.block_sparse_moe.experts.1.fc2.weight": "model-00003-of-00003.safetensors",
502
+ "model.layers.28.block_sparse_moe.experts.2.fc1.bias": "model-00003-of-00003.safetensors",
503
+ "model.layers.28.block_sparse_moe.experts.2.fc1.weight": "model-00003-of-00003.safetensors",
504
+ "model.layers.28.block_sparse_moe.experts.2.fc2.bias": "model-00003-of-00003.safetensors",
505
+ "model.layers.28.block_sparse_moe.experts.2.fc2.weight": "model-00003-of-00003.safetensors",
506
+ "model.layers.28.block_sparse_moe.gate.weight": "model-00002-of-00003.safetensors",
507
+ "model.layers.28.input_layernorm.bias": "model-00003-of-00003.safetensors",
508
+ "model.layers.28.input_layernorm.weight": "model-00003-of-00003.safetensors",
509
+ "model.layers.28.self_attn.dense.bias": "model-00002-of-00003.safetensors",
510
+ "model.layers.28.self_attn.dense.weight": "model-00002-of-00003.safetensors",
511
+ "model.layers.28.self_attn.k_proj.bias": "model-00002-of-00003.safetensors",
512
+ "model.layers.28.self_attn.k_proj.weight": "model-00002-of-00003.safetensors",
513
+ "model.layers.28.self_attn.q_proj.bias": "model-00002-of-00003.safetensors",
514
+ "model.layers.28.self_attn.q_proj.weight": "model-00002-of-00003.safetensors",
515
+ "model.layers.28.self_attn.v_proj.bias": "model-00002-of-00003.safetensors",
516
+ "model.layers.28.self_attn.v_proj.weight": "model-00002-of-00003.safetensors",
517
+ "model.layers.29.block_sparse_moe.experts.0.fc1.bias": "model-00003-of-00003.safetensors",
518
+ "model.layers.29.block_sparse_moe.experts.0.fc1.weight": "model-00003-of-00003.safetensors",
519
+ "model.layers.29.block_sparse_moe.experts.0.fc2.bias": "model-00003-of-00003.safetensors",
520
+ "model.layers.29.block_sparse_moe.experts.0.fc2.weight": "model-00003-of-00003.safetensors",
521
+ "model.layers.29.block_sparse_moe.experts.1.fc1.bias": "model-00003-of-00003.safetensors",
522
+ "model.layers.29.block_sparse_moe.experts.1.fc1.weight": "model-00003-of-00003.safetensors",
523
+ "model.layers.29.block_sparse_moe.experts.1.fc2.bias": "model-00003-of-00003.safetensors",
524
+ "model.layers.29.block_sparse_moe.experts.1.fc2.weight": "model-00003-of-00003.safetensors",
525
+ "model.layers.29.block_sparse_moe.experts.2.fc1.bias": "model-00003-of-00003.safetensors",
526
+ "model.layers.29.block_sparse_moe.experts.2.fc1.weight": "model-00003-of-00003.safetensors",
527
+ "model.layers.29.block_sparse_moe.experts.2.fc2.bias": "model-00003-of-00003.safetensors",
528
+ "model.layers.29.block_sparse_moe.experts.2.fc2.weight": "model-00003-of-00003.safetensors",
529
+ "model.layers.29.block_sparse_moe.gate.weight": "model-00003-of-00003.safetensors",
530
+ "model.layers.29.input_layernorm.bias": "model-00003-of-00003.safetensors",
531
+ "model.layers.29.input_layernorm.weight": "model-00003-of-00003.safetensors",
532
+ "model.layers.29.self_attn.dense.bias": "model-00003-of-00003.safetensors",
533
+ "model.layers.29.self_attn.dense.weight": "model-00003-of-00003.safetensors",
534
+ "model.layers.29.self_attn.k_proj.bias": "model-00003-of-00003.safetensors",
535
+ "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00003.safetensors",
536
+ "model.layers.29.self_attn.q_proj.bias": "model-00003-of-00003.safetensors",
537
+ "model.layers.29.self_attn.q_proj.weight": "model-00003-of-00003.safetensors",
538
+ "model.layers.29.self_attn.v_proj.bias": "model-00003-of-00003.safetensors",
539
+ "model.layers.29.self_attn.v_proj.weight": "model-00003-of-00003.safetensors",
540
+ "model.layers.3.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
541
+ "model.layers.3.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
542
+ "model.layers.3.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
543
+ "model.layers.3.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
544
+ "model.layers.3.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
545
+ "model.layers.3.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
546
+ "model.layers.3.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
547
+ "model.layers.3.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
548
+ "model.layers.3.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
549
+ "model.layers.3.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
550
+ "model.layers.3.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
551
+ "model.layers.3.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
552
+ "model.layers.3.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
553
+ "model.layers.3.input_layernorm.bias": "model-00001-of-00003.safetensors",
554
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00003.safetensors",
555
+ "model.layers.3.self_attn.dense.bias": "model-00001-of-00003.safetensors",
556
+ "model.layers.3.self_attn.dense.weight": "model-00001-of-00003.safetensors",
557
+ "model.layers.3.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
558
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
559
+ "model.layers.3.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
560
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
561
+ "model.layers.3.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
562
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
563
+ "model.layers.30.block_sparse_moe.experts.0.fc1.bias": "model-00003-of-00003.safetensors",
564
+ "model.layers.30.block_sparse_moe.experts.0.fc1.weight": "model-00003-of-00003.safetensors",
565
+ "model.layers.30.block_sparse_moe.experts.0.fc2.bias": "model-00003-of-00003.safetensors",
566
+ "model.layers.30.block_sparse_moe.experts.0.fc2.weight": "model-00003-of-00003.safetensors",
567
+ "model.layers.30.block_sparse_moe.experts.1.fc1.bias": "model-00003-of-00003.safetensors",
568
+ "model.layers.30.block_sparse_moe.experts.1.fc1.weight": "model-00003-of-00003.safetensors",
569
+ "model.layers.30.block_sparse_moe.experts.1.fc2.bias": "model-00003-of-00003.safetensors",
570
+ "model.layers.30.block_sparse_moe.experts.1.fc2.weight": "model-00003-of-00003.safetensors",
571
+ "model.layers.30.block_sparse_moe.experts.2.fc1.bias": "model-00003-of-00003.safetensors",
572
+ "model.layers.30.block_sparse_moe.experts.2.fc1.weight": "model-00003-of-00003.safetensors",
573
+ "model.layers.30.block_sparse_moe.experts.2.fc2.bias": "model-00003-of-00003.safetensors",
574
+ "model.layers.30.block_sparse_moe.experts.2.fc2.weight": "model-00003-of-00003.safetensors",
575
+ "model.layers.30.block_sparse_moe.gate.weight": "model-00003-of-00003.safetensors",
576
+ "model.layers.30.input_layernorm.bias": "model-00003-of-00003.safetensors",
577
+ "model.layers.30.input_layernorm.weight": "model-00003-of-00003.safetensors",
578
+ "model.layers.30.self_attn.dense.bias": "model-00003-of-00003.safetensors",
579
+ "model.layers.30.self_attn.dense.weight": "model-00003-of-00003.safetensors",
580
+ "model.layers.30.self_attn.k_proj.bias": "model-00003-of-00003.safetensors",
581
+ "model.layers.30.self_attn.k_proj.weight": "model-00003-of-00003.safetensors",
582
+ "model.layers.30.self_attn.q_proj.bias": "model-00003-of-00003.safetensors",
583
+ "model.layers.30.self_attn.q_proj.weight": "model-00003-of-00003.safetensors",
584
+ "model.layers.30.self_attn.v_proj.bias": "model-00003-of-00003.safetensors",
585
+ "model.layers.30.self_attn.v_proj.weight": "model-00003-of-00003.safetensors",
586
+ "model.layers.31.block_sparse_moe.experts.0.fc1.bias": "model-00003-of-00003.safetensors",
587
+ "model.layers.31.block_sparse_moe.experts.0.fc1.weight": "model-00003-of-00003.safetensors",
588
+ "model.layers.31.block_sparse_moe.experts.0.fc2.bias": "model-00003-of-00003.safetensors",
589
+ "model.layers.31.block_sparse_moe.experts.0.fc2.weight": "model-00003-of-00003.safetensors",
590
+ "model.layers.31.block_sparse_moe.experts.1.fc1.bias": "model-00003-of-00003.safetensors",
591
+ "model.layers.31.block_sparse_moe.experts.1.fc1.weight": "model-00003-of-00003.safetensors",
592
+ "model.layers.31.block_sparse_moe.experts.1.fc2.bias": "model-00003-of-00003.safetensors",
593
+ "model.layers.31.block_sparse_moe.experts.1.fc2.weight": "model-00003-of-00003.safetensors",
594
+ "model.layers.31.block_sparse_moe.experts.2.fc1.bias": "model-00003-of-00003.safetensors",
595
+ "model.layers.31.block_sparse_moe.experts.2.fc1.weight": "model-00003-of-00003.safetensors",
596
+ "model.layers.31.block_sparse_moe.experts.2.fc2.bias": "model-00003-of-00003.safetensors",
597
+ "model.layers.31.block_sparse_moe.experts.2.fc2.weight": "model-00003-of-00003.safetensors",
598
+ "model.layers.31.block_sparse_moe.gate.weight": "model-00003-of-00003.safetensors",
599
+ "model.layers.31.input_layernorm.bias": "model-00003-of-00003.safetensors",
600
+ "model.layers.31.input_layernorm.weight": "model-00003-of-00003.safetensors",
601
+ "model.layers.31.self_attn.dense.bias": "model-00003-of-00003.safetensors",
602
+ "model.layers.31.self_attn.dense.weight": "model-00003-of-00003.safetensors",
603
+ "model.layers.31.self_attn.k_proj.bias": "model-00003-of-00003.safetensors",
604
+ "model.layers.31.self_attn.k_proj.weight": "model-00003-of-00003.safetensors",
605
+ "model.layers.31.self_attn.q_proj.bias": "model-00003-of-00003.safetensors",
606
+ "model.layers.31.self_attn.q_proj.weight": "model-00003-of-00003.safetensors",
607
+ "model.layers.31.self_attn.v_proj.bias": "model-00003-of-00003.safetensors",
608
+ "model.layers.31.self_attn.v_proj.weight": "model-00003-of-00003.safetensors",
609
+ "model.layers.4.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
610
+ "model.layers.4.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
611
+ "model.layers.4.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
612
+ "model.layers.4.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
613
+ "model.layers.4.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
614
+ "model.layers.4.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
615
+ "model.layers.4.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
616
+ "model.layers.4.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
617
+ "model.layers.4.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
618
+ "model.layers.4.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
619
+ "model.layers.4.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
620
+ "model.layers.4.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
621
+ "model.layers.4.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
622
+ "model.layers.4.input_layernorm.bias": "model-00001-of-00003.safetensors",
623
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00003.safetensors",
624
+ "model.layers.4.self_attn.dense.bias": "model-00001-of-00003.safetensors",
625
+ "model.layers.4.self_attn.dense.weight": "model-00001-of-00003.safetensors",
626
+ "model.layers.4.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
627
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
628
+ "model.layers.4.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
629
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
630
+ "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
631
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
632
+ "model.layers.5.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
633
+ "model.layers.5.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
634
+ "model.layers.5.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
635
+ "model.layers.5.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
636
+ "model.layers.5.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
637
+ "model.layers.5.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
638
+ "model.layers.5.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
639
+ "model.layers.5.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
640
+ "model.layers.5.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
641
+ "model.layers.5.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
642
+ "model.layers.5.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
643
+ "model.layers.5.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
644
+ "model.layers.5.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
645
+ "model.layers.5.input_layernorm.bias": "model-00001-of-00003.safetensors",
646
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00003.safetensors",
647
+ "model.layers.5.self_attn.dense.bias": "model-00001-of-00003.safetensors",
648
+ "model.layers.5.self_attn.dense.weight": "model-00001-of-00003.safetensors",
649
+ "model.layers.5.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
650
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
651
+ "model.layers.5.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
652
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
653
+ "model.layers.5.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
654
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
655
+ "model.layers.6.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
656
+ "model.layers.6.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
657
+ "model.layers.6.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
658
+ "model.layers.6.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
659
+ "model.layers.6.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
660
+ "model.layers.6.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
661
+ "model.layers.6.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
662
+ "model.layers.6.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
663
+ "model.layers.6.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
664
+ "model.layers.6.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
665
+ "model.layers.6.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
666
+ "model.layers.6.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
667
+ "model.layers.6.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
668
+ "model.layers.6.input_layernorm.bias": "model-00001-of-00003.safetensors",
669
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00003.safetensors",
670
+ "model.layers.6.self_attn.dense.bias": "model-00001-of-00003.safetensors",
671
+ "model.layers.6.self_attn.dense.weight": "model-00001-of-00003.safetensors",
672
+ "model.layers.6.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
673
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
674
+ "model.layers.6.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
675
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
676
+ "model.layers.6.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
677
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
678
+ "model.layers.7.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
679
+ "model.layers.7.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
680
+ "model.layers.7.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
681
+ "model.layers.7.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
682
+ "model.layers.7.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
683
+ "model.layers.7.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
684
+ "model.layers.7.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
685
+ "model.layers.7.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
686
+ "model.layers.7.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
687
+ "model.layers.7.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
688
+ "model.layers.7.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
689
+ "model.layers.7.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
690
+ "model.layers.7.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
691
+ "model.layers.7.input_layernorm.bias": "model-00001-of-00003.safetensors",
692
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00003.safetensors",
693
+ "model.layers.7.self_attn.dense.bias": "model-00001-of-00003.safetensors",
694
+ "model.layers.7.self_attn.dense.weight": "model-00001-of-00003.safetensors",
695
+ "model.layers.7.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
696
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
697
+ "model.layers.7.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
698
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
699
+ "model.layers.7.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
700
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
701
+ "model.layers.8.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
702
+ "model.layers.8.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
703
+ "model.layers.8.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
704
+ "model.layers.8.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
705
+ "model.layers.8.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
706
+ "model.layers.8.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
707
+ "model.layers.8.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
708
+ "model.layers.8.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
709
+ "model.layers.8.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
710
+ "model.layers.8.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
711
+ "model.layers.8.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
712
+ "model.layers.8.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
713
+ "model.layers.8.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
714
+ "model.layers.8.input_layernorm.bias": "model-00001-of-00003.safetensors",
715
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00003.safetensors",
716
+ "model.layers.8.self_attn.dense.bias": "model-00001-of-00003.safetensors",
717
+ "model.layers.8.self_attn.dense.weight": "model-00001-of-00003.safetensors",
718
+ "model.layers.8.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
719
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
720
+ "model.layers.8.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
721
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
722
+ "model.layers.8.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
723
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00003.safetensors",
724
+ "model.layers.9.block_sparse_moe.experts.0.fc1.bias": "model-00001-of-00003.safetensors",
725
+ "model.layers.9.block_sparse_moe.experts.0.fc1.weight": "model-00001-of-00003.safetensors",
726
+ "model.layers.9.block_sparse_moe.experts.0.fc2.bias": "model-00001-of-00003.safetensors",
727
+ "model.layers.9.block_sparse_moe.experts.0.fc2.weight": "model-00001-of-00003.safetensors",
728
+ "model.layers.9.block_sparse_moe.experts.1.fc1.bias": "model-00001-of-00003.safetensors",
729
+ "model.layers.9.block_sparse_moe.experts.1.fc1.weight": "model-00001-of-00003.safetensors",
730
+ "model.layers.9.block_sparse_moe.experts.1.fc2.bias": "model-00001-of-00003.safetensors",
731
+ "model.layers.9.block_sparse_moe.experts.1.fc2.weight": "model-00001-of-00003.safetensors",
732
+ "model.layers.9.block_sparse_moe.experts.2.fc1.bias": "model-00001-of-00003.safetensors",
733
+ "model.layers.9.block_sparse_moe.experts.2.fc1.weight": "model-00001-of-00003.safetensors",
734
+ "model.layers.9.block_sparse_moe.experts.2.fc2.bias": "model-00001-of-00003.safetensors",
735
+ "model.layers.9.block_sparse_moe.experts.2.fc2.weight": "model-00001-of-00003.safetensors",
736
+ "model.layers.9.block_sparse_moe.gate.weight": "model-00001-of-00003.safetensors",
737
+ "model.layers.9.input_layernorm.bias": "model-00001-of-00003.safetensors",
738
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00003.safetensors",
739
+ "model.layers.9.self_attn.dense.bias": "model-00001-of-00003.safetensors",
740
+ "model.layers.9.self_attn.dense.weight": "model-00001-of-00003.safetensors",
741
+ "model.layers.9.self_attn.k_proj.bias": "model-00001-of-00003.safetensors",
742
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00003.safetensors",
743
+ "model.layers.9.self_attn.q_proj.bias": "model-00001-of-00003.safetensors",
744
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
745
+ "model.layers.9.self_attn.v_proj.bias": "model-00001-of-00003.safetensors",
746
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00003.safetensors"
747
+ }
748
+ }
modeling_phi.py ADDED
@@ -0,0 +1,1411 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 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 model."""
17
+
18
+
19
+ import math
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 _prepare_4d_causal_attention_mask
31
+ from transformers.modeling_outputs import (
32
+ BaseModelOutputWithPast,
33
+ CausalLMOutputWithPast,
34
+ SequenceClassifierOutputWithPast,
35
+ TokenClassifierOutput,
36
+ )
37
+ from transformers.modeling_utils import PreTrainedModel
38
+ from transformers.utils import (
39
+ add_code_sample_docstrings,
40
+ add_start_docstrings,
41
+ add_start_docstrings_to_model_forward,
42
+ is_flash_attn_2_available,
43
+ is_flash_attn_greater_or_equal_2_10,
44
+ logging,
45
+ replace_return_docstrings,
46
+ )
47
+ from .configuration_phi import PhiConfig
48
+
49
+
50
+ try:
51
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
52
+ from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
53
+ except:
54
+ pass
55
+
56
+
57
+ logger = logging.get_logger(__name__)
58
+
59
+ _CHECKPOINT_FOR_DOC = "microsoft/phi-2"
60
+ _CONFIG_FOR_DOC = "PhiConfig"
61
+
62
+ PHI_PRETRAINED_MODEL_ARCHIVE_LIST = [
63
+ "microsoft/phi-2",
64
+ # See all Phi models at https://huggingface.co/models?filter=phi
65
+ ]
66
+
67
+
68
+ # Copied from transformers.models.llama.modeling_llama._get_unpad_data
69
+ def _get_unpad_data(attention_mask):
70
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
71
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
72
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
73
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
74
+ return (
75
+ indices,
76
+ cu_seqlens,
77
+ max_seqlen_in_batch,
78
+ )
79
+
80
+
81
+ # Copied from transformers.models.llama.modeling_llama.LlamaRotaryEmbedding with Llama->Phi
82
+ class PhiRotaryEmbedding(nn.Module):
83
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
84
+ super().__init__()
85
+
86
+ self.dim = dim
87
+ self.max_position_embeddings = max_position_embeddings
88
+ self.base = base
89
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
90
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
91
+
92
+ # Build here to make `torch.jit.trace` work.
93
+ self._set_cos_sin_cache(
94
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
95
+ )
96
+
97
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
98
+ self.max_seq_len_cached = seq_len
99
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
100
+
101
+ freqs = torch.outer(t, self.inv_freq)
102
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
103
+ emb = torch.cat((freqs, freqs), dim=-1)
104
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
105
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
106
+
107
+ def forward(self, x, seq_len=None):
108
+ # x: [bs, num_attention_heads, seq_len, head_size]
109
+ if seq_len > self.max_seq_len_cached:
110
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
111
+
112
+ return (
113
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
114
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
115
+ )
116
+
117
+
118
+ # Copied from transformers.models.llama.modeling_llama.LlamaLinearScalingRotaryEmbedding with Llama->Phi
119
+ class PhiLinearScalingRotaryEmbedding(PhiRotaryEmbedding):
120
+ """PhiRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
121
+
122
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
123
+ self.scaling_factor = scaling_factor
124
+ super().__init__(dim, max_position_embeddings, base, device)
125
+
126
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
127
+ self.max_seq_len_cached = seq_len
128
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
129
+ t = t / self.scaling_factor
130
+
131
+ freqs = torch.outer(t, self.inv_freq)
132
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
133
+ emb = torch.cat((freqs, freqs), dim=-1)
134
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
135
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
136
+
137
+
138
+ # Copied from transformers.models.llama.modeling_llama.LlamaDynamicNTKScalingRotaryEmbedding with Llama->Phi
139
+ class PhiDynamicNTKScalingRotaryEmbedding(PhiRotaryEmbedding):
140
+ """PhiRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
141
+
142
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
143
+ self.scaling_factor = scaling_factor
144
+ super().__init__(dim, max_position_embeddings, base, device)
145
+
146
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
147
+ self.max_seq_len_cached = seq_len
148
+
149
+ if seq_len > self.max_position_embeddings:
150
+ base = self.base * (
151
+ (self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
152
+ ) ** (self.dim / (self.dim - 2))
153
+ inv_freq = 1.0 / (base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
154
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
155
+
156
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
157
+
158
+ freqs = torch.outer(t, self.inv_freq)
159
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
160
+ emb = torch.cat((freqs, freqs), dim=-1)
161
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
162
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
163
+
164
+
165
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
166
+ def rotate_half(x):
167
+ """Rotates half the hidden dims of the input."""
168
+ x1 = x[..., : x.shape[-1] // 2]
169
+ x2 = x[..., x.shape[-1] // 2 :]
170
+ return torch.cat((-x2, x1), dim=-1)
171
+
172
+
173
+ # Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
174
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
175
+ """Applies Rotary Position Embedding to the query and key tensors.
176
+ Args:
177
+ q (`torch.Tensor`): The query tensor.
178
+ k (`torch.Tensor`): The key tensor.
179
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
180
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
181
+ position_ids (`torch.Tensor`):
182
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
183
+ used to pass offsetted position ids when working with a KV-cache.
184
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
185
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
186
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
187
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
188
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
189
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
190
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
191
+ Returns:
192
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
193
+ """
194
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim)
195
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim)
196
+ q_embed = (q * cos) + (rotate_half(q) * sin)
197
+ k_embed = (k * cos) + (rotate_half(k) * sin)
198
+ return q_embed, k_embed
199
+
200
+
201
+ # Copied from transformers.models.clip.modeling_clip.CLIPMLP with CLIP->Phi
202
+ class PhiMLP(nn.Module):
203
+ def __init__(self, config):
204
+ super().__init__()
205
+ self.config = config
206
+ self.activation_fn = ACT2FN[config.hidden_act]
207
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
208
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
209
+
210
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
211
+ hidden_states = self.fc1(hidden_states)
212
+ hidden_states = self.activation_fn(hidden_states)
213
+ hidden_states = self.fc2(hidden_states)
214
+ return hidden_states
215
+
216
+
217
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
218
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
219
+ """
220
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
221
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
222
+ """
223
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
224
+ if n_rep == 1:
225
+ return hidden_states
226
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
227
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
228
+
229
+
230
+ class PhiAttention(nn.Module):
231
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
232
+
233
+ def __init__(self, config: PhiConfig, layer_idx: Optional[int] = None):
234
+ super().__init__()
235
+ self.config = config
236
+ self.layer_idx = layer_idx
237
+ if layer_idx is None:
238
+ logger.warning_once(
239
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
240
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
241
+ "when creating this class."
242
+ )
243
+
244
+ self.attention_dropout = config.attention_dropout
245
+ self.hidden_size = config.hidden_size
246
+ self.num_heads = config.num_attention_heads
247
+ self.head_dim = self.hidden_size // self.num_heads
248
+ self.num_key_value_heads = config.num_key_value_heads
249
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
250
+ self.max_position_embeddings = config.max_position_embeddings
251
+ self.rope_theta = config.rope_theta
252
+ self.partial_rotary_factor = config.partial_rotary_factor
253
+ self.is_causal = True
254
+
255
+ if (self.head_dim * self.num_heads) != self.hidden_size:
256
+ raise ValueError(
257
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
258
+ f" and `num_heads`: {self.num_heads})."
259
+ )
260
+
261
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=True)
262
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
263
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
264
+ self.dense = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=True)
265
+
266
+ self.qk_layernorm = config.qk_layernorm
267
+ if self.qk_layernorm:
268
+ self.q_layernorm = nn.LayerNorm(
269
+ config.hidden_size // self.num_heads, eps=config.layer_norm_eps, elementwise_affine=True
270
+ )
271
+ self.k_layernorm = nn.LayerNorm(
272
+ config.hidden_size // self.num_heads, eps=config.layer_norm_eps, elementwise_affine=True
273
+ )
274
+
275
+ self._init_rope()
276
+
277
+ def _init_rope(self):
278
+ if self.config.rope_scaling is None:
279
+ self.rotary_emb = PhiRotaryEmbedding(
280
+ int(self.partial_rotary_factor * self.head_dim),
281
+ max_position_embeddings=self.max_position_embeddings,
282
+ base=self.rope_theta,
283
+ )
284
+ else:
285
+ scaling_type = self.config.rope_scaling["type"]
286
+ scaling_factor = self.config.rope_scaling["factor"]
287
+ if scaling_type == "linear":
288
+ self.rotary_emb = PhiLinearScalingRotaryEmbedding(
289
+ int(self.partial_rotary_factor * self.head_dim),
290
+ max_position_embeddings=self.max_position_embeddings,
291
+ scaling_factor=scaling_factor,
292
+ base=self.rope_theta,
293
+ )
294
+ elif scaling_type == "dynamic":
295
+ self.rotary_emb = PhiDynamicNTKScalingRotaryEmbedding(
296
+ int(self.partial_rotary_factor * self.head_dim),
297
+ max_position_embeddings=self.max_position_embeddings,
298
+ scaling_factor=scaling_factor,
299
+ base=self.rope_theta,
300
+ )
301
+ else:
302
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
303
+
304
+ # Phi-2 has an attention overflow issue (with FP16) and requires autocast to be disabled
305
+ @torch.autocast("cpu", enabled=False)
306
+ @torch.autocast("cuda", enabled=False)
307
+ def forward(
308
+ self,
309
+ hidden_states: torch.Tensor,
310
+ attention_mask: Optional[torch.Tensor] = None,
311
+ position_ids: Optional[torch.LongTensor] = None,
312
+ past_key_value: Optional[Cache] = None,
313
+ output_attentions: bool = False,
314
+ use_cache: bool = False,
315
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
316
+ bsz, q_len, _ = hidden_states.size()
317
+
318
+ query_states = self.q_proj(hidden_states)
319
+ key_states = self.k_proj(hidden_states)
320
+ value_states = self.v_proj(hidden_states)
321
+
322
+ if self.qk_layernorm:
323
+ query_states = self.q_layernorm(query_states)
324
+ key_states = self.k_layernorm(key_states)
325
+
326
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
327
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
328
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
329
+
330
+ kv_seq_len = key_states.shape[-2]
331
+ if past_key_value is not None:
332
+ if self.layer_idx is None:
333
+ raise ValueError(
334
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
335
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
336
+ "with a layer index."
337
+ )
338
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
339
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
340
+
341
+ # Partial rotary embedding
342
+ query_rot, query_pass = (
343
+ query_states[..., : self.rotary_emb.dim],
344
+ query_states[..., self.rotary_emb.dim :],
345
+ )
346
+ key_rot, key_pass = (
347
+ key_states[..., : self.rotary_emb.dim],
348
+ key_states[..., self.rotary_emb.dim :],
349
+ )
350
+ # [batch_size, seq_length, num_heads, head_dim // config.partial_rotary_factor]
351
+ query_rot, key_rot = apply_rotary_pos_emb(query_rot, key_rot, cos, sin, position_ids)
352
+
353
+ # [batch_size, seq_length, num_heads, head_dim]
354
+ query_states = torch.cat((query_rot, query_pass), dim=-1)
355
+ key_states = torch.cat((key_rot, key_pass), dim=-1)
356
+
357
+ if past_key_value is not None:
358
+ cache_kwargs = {"sin": sin, "cos": cos, "partial_rotation_size": self.rotary_emb.dim}
359
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
360
+
361
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
362
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
363
+
364
+ # Queries and keys upcast to fp32 is required by Phi-2 to avoid overflow
365
+ attn_weights = torch.matmul(
366
+ query_states.to(torch.float32), key_states.to(torch.float32).transpose(2, 3)
367
+ ) / math.sqrt(self.head_dim)
368
+
369
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
370
+ raise ValueError(
371
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
372
+ f" {attn_weights.size()}"
373
+ )
374
+
375
+ if attention_mask is not None:
376
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
377
+ raise ValueError(
378
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
379
+ )
380
+ attn_weights = attn_weights + attention_mask
381
+
382
+ # upcast attention to fp32
383
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(value_states.dtype)
384
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
385
+
386
+ attn_output = torch.matmul(attn_weights, value_states)
387
+
388
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
389
+ raise ValueError(
390
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
391
+ f" {attn_output.size()}"
392
+ )
393
+
394
+ attn_output = attn_output.transpose(1, 2).contiguous()
395
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
396
+
397
+ attn_output = self.dense(attn_output)
398
+
399
+ if not output_attentions:
400
+ attn_weights = None
401
+
402
+ return attn_output, attn_weights, past_key_value
403
+
404
+
405
+ class PhiFlashAttention2(PhiAttention):
406
+ """
407
+ Phi flash attention module. This module inherits from `PhiAttention` as the weights of the module stays
408
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
409
+ flash attention and deal with padding tokens in case the input contains any of them.
410
+ """
411
+
412
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
413
+ def __init__(self, *args, **kwargs):
414
+ super().__init__(*args, **kwargs)
415
+
416
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
417
+ # 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.
418
+ # 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).
419
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
420
+
421
+ def forward(
422
+ self,
423
+ hidden_states: torch.Tensor,
424
+ attention_mask: Optional[torch.LongTensor] = None,
425
+ position_ids: Optional[torch.LongTensor] = None,
426
+ past_key_value: Optional[Cache] = None,
427
+ output_attentions: bool = False,
428
+ use_cache: bool = False,
429
+ **kwargs,
430
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
431
+ # PhiFlashAttention2 attention does not support output_attentions
432
+
433
+ output_attentions = False
434
+
435
+ bsz, q_len, _ = hidden_states.size()
436
+
437
+ query_states = self.q_proj(hidden_states)
438
+ key_states = self.k_proj(hidden_states)
439
+ value_states = self.v_proj(hidden_states)
440
+
441
+ if self.qk_layernorm:
442
+ query_states = self.q_layernorm(query_states)
443
+ key_states = self.k_layernorm(key_states)
444
+
445
+ # Flash attention requires the input to have the shape
446
+ # batch_size x seq_length x head_dim x hidden_dim
447
+ # therefore we just need to keep the original shape
448
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
449
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
450
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
451
+
452
+ kv_seq_len = key_states.shape[-2]
453
+ if past_key_value is not None:
454
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
455
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
456
+
457
+ # Partial rotary embedding
458
+ query_rot, query_pass = (
459
+ query_states[..., : self.rotary_emb.dim],
460
+ query_states[..., self.rotary_emb.dim :],
461
+ )
462
+ key_rot, key_pass = (
463
+ key_states[..., : self.rotary_emb.dim],
464
+ key_states[..., self.rotary_emb.dim :],
465
+ )
466
+ # [batch_size, seq_length, num_heads, head_dim // config.partial_rotary_factor]
467
+ query_rot, key_rot = apply_rotary_pos_emb(query_rot, key_rot, cos, sin, position_ids)
468
+
469
+ # [batch_size, seq_length, num_heads, head_dim]
470
+ query_states = torch.cat((query_rot, query_pass), dim=-1)
471
+ key_states = torch.cat((key_rot, key_pass), dim=-1)
472
+
473
+ if past_key_value is not None:
474
+ cache_kwargs = {"sin": sin, "cos": cos, "partial_rotation_size": self.rotary_emb.dim}
475
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
476
+
477
+ # TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
478
+ # to be able to avoid many of these transpose/reshape/view.
479
+ query_states = query_states.transpose(1, 2)
480
+ key_states = key_states.transpose(1, 2)
481
+ value_states = value_states.transpose(1, 2)
482
+
483
+ attn_dropout = self.attention_dropout if self.training else 0.0
484
+
485
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
486
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
487
+ # cast them back in the correct dtype just to be sure everything works as expected.
488
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
489
+ # in fp32.
490
+
491
+ if query_states.dtype == torch.float32:
492
+ if torch.is_autocast_enabled():
493
+ target_dtype = torch.get_autocast_gpu_dtype()
494
+ # Handle the case where the model is quantized
495
+ elif hasattr(self.config, "_pre_quantization_dtype"):
496
+ target_dtype = self.config._pre_quantization_dtype
497
+ else:
498
+ target_dtype = self.q_proj.weight.dtype
499
+
500
+ logger.warning_once(
501
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
502
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
503
+ f" {target_dtype}."
504
+ )
505
+
506
+ query_states = query_states.to(target_dtype)
507
+ key_states = key_states.to(target_dtype)
508
+ value_states = value_states.to(target_dtype)
509
+
510
+ attn_output = self._flash_attention_forward(
511
+ query_states, key_states, value_states, attention_mask, q_len, dropout=attn_dropout, softmax_scale=None
512
+ )
513
+
514
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
515
+ attn_output = self.dense(attn_output)
516
+
517
+ if not output_attentions:
518
+ attn_weights = None
519
+
520
+ return attn_output, attn_weights, past_key_value
521
+
522
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2._flash_attention_forward
523
+ def _flash_attention_forward(
524
+ self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
525
+ ):
526
+ """
527
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
528
+ first unpad the input, then computes the attention scores and pad the final attention scores.
529
+ Args:
530
+ query_states (`torch.Tensor`):
531
+ Input query states to be passed to Flash Attention API
532
+ key_states (`torch.Tensor`):
533
+ Input key states to be passed to Flash Attention API
534
+ value_states (`torch.Tensor`):
535
+ Input value states to be passed to Flash Attention API
536
+ attention_mask (`torch.Tensor`):
537
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
538
+ position of padding tokens and 1 for the position of non-padding tokens.
539
+ dropout (`int`, *optional*):
540
+ Attention dropout
541
+ softmax_scale (`float`, *optional*):
542
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
543
+ """
544
+ if not self._flash_attn_uses_top_left_mask:
545
+ causal = self.is_causal
546
+ else:
547
+ # 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__.
548
+ causal = self.is_causal and query_length != 1
549
+
550
+ # Contains at least one padding token in the sequence
551
+ if attention_mask is not None:
552
+ batch_size = query_states.shape[0]
553
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
554
+ query_states, key_states, value_states, attention_mask, query_length
555
+ )
556
+
557
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
558
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
559
+
560
+ attn_output_unpad = flash_attn_varlen_func(
561
+ query_states,
562
+ key_states,
563
+ value_states,
564
+ cu_seqlens_q=cu_seqlens_q,
565
+ cu_seqlens_k=cu_seqlens_k,
566
+ max_seqlen_q=max_seqlen_in_batch_q,
567
+ max_seqlen_k=max_seqlen_in_batch_k,
568
+ dropout_p=dropout,
569
+ softmax_scale=softmax_scale,
570
+ causal=causal,
571
+ )
572
+
573
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
574
+ else:
575
+ attn_output = flash_attn_func(
576
+ query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
577
+ )
578
+
579
+ return attn_output
580
+
581
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2._upad_input
582
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
583
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
584
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
585
+
586
+ key_layer = index_first_axis(
587
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
588
+ )
589
+ value_layer = index_first_axis(
590
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
591
+ )
592
+ if query_length == kv_seq_len:
593
+ query_layer = index_first_axis(
594
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
595
+ )
596
+ cu_seqlens_q = cu_seqlens_k
597
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
598
+ indices_q = indices_k
599
+ elif query_length == 1:
600
+ max_seqlen_in_batch_q = 1
601
+ cu_seqlens_q = torch.arange(
602
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
603
+ ) # There is a memcpy here, that is very bad.
604
+ indices_q = cu_seqlens_q[:-1]
605
+ query_layer = query_layer.squeeze(1)
606
+ else:
607
+ # The -q_len: slice assumes left padding.
608
+ attention_mask = attention_mask[:, -query_length:]
609
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
610
+
611
+ return (
612
+ query_layer,
613
+ key_layer,
614
+ value_layer,
615
+ indices_q,
616
+ (cu_seqlens_q, cu_seqlens_k),
617
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
618
+ )
619
+
620
+
621
+ PHI_ATTENTION_CLASSES = {
622
+ "eager": PhiAttention,
623
+ "flash_attention_2": PhiFlashAttention2,
624
+ }
625
+
626
+ class SparseMoeBlock(nn.Module):
627
+ """
628
+ This implementation is
629
+ strictly equivalent to standard MoE with full capacity (no
630
+ dropped tokens). It's faster since it formulates MoE operations
631
+ in terms of block-sparse operations to accomodate imbalanced
632
+ assignments of tokens to experts, whereas standard MoE either
633
+ (1) drop tokens at the cost of reduced performance or (2) set
634
+ capacity factor to number of experts and thus waste computation
635
+ and memory on padding.
636
+ """
637
+
638
+ def __init__(self, config):
639
+ super().__init__()
640
+ self.hidden_dim = config.hidden_size
641
+ self.ffn_dim = config.intermediate_size
642
+ self.num_experts = config.num_local_experts
643
+ self.top_k = config.num_experts_per_tok
644
+
645
+ # gating
646
+ self.gate = nn.Linear(self.hidden_dim, self.num_experts, bias=False)
647
+
648
+ self.experts = nn.ModuleList([PhiMLP(config) for _ in range(self.num_experts)])
649
+
650
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
651
+ """ """
652
+ batch_size, sequence_length, hidden_dim = hidden_states.shape
653
+ hidden_states = hidden_states.view(-1, hidden_dim)
654
+ # router_logits: (batch * sequence_length, n_experts)
655
+ router_logits = self.gate(hidden_states)
656
+
657
+ routing_weights = F.softmax(router_logits, dim=1, dtype=torch.float)
658
+ routing_weights, selected_experts = torch.topk(routing_weights, self.top_k, dim=-1)
659
+ routing_weights /= routing_weights.sum(dim=-1, keepdim=True)
660
+ # we cast back to the input dtype
661
+ routing_weights = routing_weights.to(hidden_states.dtype)
662
+
663
+ final_hidden_states = torch.zeros(
664
+ (batch_size * sequence_length, hidden_dim), dtype=hidden_states.dtype, device=hidden_states.device
665
+ )
666
+
667
+ # One hot encode the selected experts to create an expert mask
668
+ # this will be used to easily index which expert is going to be sollicitated
669
+ expert_mask = torch.nn.functional.one_hot(selected_experts, num_classes=self.num_experts).permute(2, 1, 0)
670
+
671
+ # Loop over all available experts in the model and perform the computation on each expert
672
+ for expert_idx in range(self.num_experts):
673
+ expert_layer = self.experts[expert_idx]
674
+ idx, top_x = torch.where(expert_mask[expert_idx])
675
+
676
+ if top_x.shape[0] == 0:
677
+ continue
678
+
679
+ # in torch it is faster to index using lists than torch tensors
680
+ top_x_list = top_x.tolist()
681
+ idx_list = idx.tolist()
682
+
683
+ # Index the correct hidden states and compute the expert hidden state for
684
+ # the current expert. We need to make sure to multiply the output hidden
685
+ # states by `routing_weights` on the corresponding tokens (top-1 and top-2)
686
+ current_state = hidden_states[None, top_x_list].reshape(-1, hidden_dim)
687
+ current_hidden_states = expert_layer(current_state) * routing_weights[top_x_list, idx_list, None]
688
+
689
+ # However `index_add_` only support torch tensors for indexing so we'll use
690
+ # the `top_x` tensor here.
691
+ final_hidden_states.index_add_(0, top_x, current_hidden_states.to(hidden_states.dtype))
692
+ final_hidden_states = final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)
693
+ return final_hidden_states, router_logits
694
+
695
+ class PhiDecoderLayer(nn.Module):
696
+ def __init__(self, config: PhiConfig, layer_idx: int):
697
+ super().__init__()
698
+ self.self_attn = PHI_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
699
+ self.block_sparse_moe = SparseMoeBlock(config)
700
+ self.input_layernorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
701
+ self.resid_dropout = nn.Dropout(config.resid_pdrop)
702
+
703
+ def forward(
704
+ self,
705
+ hidden_states: torch.Tensor,
706
+ attention_mask: Optional[torch.Tensor] = None,
707
+ position_ids: Optional[torch.LongTensor] = None,
708
+ output_attentions: Optional[bool] = False,
709
+ use_cache: Optional[bool] = False,
710
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
711
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
712
+ """
713
+ Args:
714
+ hidden_states (`torch.FloatTensor`):
715
+ input to the layer of shape `(batch, seq_len, embed_dim)`
716
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
717
+ `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
718
+ position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
719
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
720
+ `[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
721
+ output_attentions (`bool`, *optional*):
722
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
723
+ returned tensors for more detail.
724
+ use_cache (`bool`, *optional*):
725
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
726
+ (see `past_key_values`).
727
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
728
+ """
729
+
730
+ residual = hidden_states
731
+
732
+ hidden_states = self.input_layernorm(hidden_states)
733
+
734
+ # Self Attention
735
+ attn_outputs, self_attn_weights, present_key_value = self.self_attn(
736
+ hidden_states=hidden_states,
737
+ attention_mask=attention_mask,
738
+ position_ids=position_ids,
739
+ past_key_value=past_key_value,
740
+ output_attentions=output_attentions,
741
+ use_cache=use_cache,
742
+ )
743
+
744
+ feed_forward_hidden_states,_ = self.block_sparse_moe(hidden_states)
745
+ hidden_states = attn_outputs + feed_forward_hidden_states + residual
746
+ outputs = (hidden_states,)
747
+
748
+ if output_attentions:
749
+ outputs += (self_attn_weights,)
750
+
751
+ if use_cache:
752
+ outputs += (present_key_value,)
753
+
754
+ return outputs
755
+
756
+
757
+ PHI_START_DOCSTRING = r"""
758
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
759
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
760
+ etc.)
761
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
762
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
763
+ and behavior.
764
+ Parameters:
765
+ config ([`PhiConfig`]):
766
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
767
+ load the weights associated with the model, only the configuration. Check out the
768
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
769
+ """
770
+
771
+
772
+ @add_start_docstrings(
773
+ "The bare Phi Model outputting raw hidden-states without any specific head on top.",
774
+ PHI_START_DOCSTRING,
775
+ )
776
+ class PhiPreTrainedModel(PreTrainedModel):
777
+ config_class = PhiConfig
778
+ base_model_prefix = "model"
779
+ supports_gradient_checkpointing = True
780
+ _no_split_modules = ["PhiDecoderLayer"]
781
+ _skip_keys_device_placement = "past_key_values"
782
+ _supports_flash_attn_2 = True
783
+ _supports_cache_class = True
784
+
785
+ def _init_weights(self, module):
786
+ std = self.config.initializer_range
787
+ if isinstance(module, nn.Linear):
788
+ module.weight.data.normal_(mean=0.0, std=std)
789
+ if module.bias is not None:
790
+ module.bias.data.zero_()
791
+ elif isinstance(module, nn.Embedding):
792
+ module.weight.data.normal_(mean=0.0, std=std)
793
+ if module.padding_idx is not None:
794
+ module.weight.data[module.padding_idx].zero_()
795
+
796
+
797
+ PHI_INPUTS_DOCSTRING = r"""
798
+ Args:
799
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
800
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
801
+ it.
802
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
803
+ [`PreTrainedTokenizer.__call__`] for details.
804
+ [What are input IDs?](../glossary#input-ids)
805
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
806
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
807
+ - 1 for tokens that are **not masked**,
808
+ - 0 for tokens that are **masked**.
809
+ [What are attention masks?](../glossary#attention-mask)
810
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
811
+ [`PreTrainedTokenizer.__call__`] for details.
812
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
813
+ `past_key_values`).
814
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
815
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
816
+ information on the default strategy.
817
+ - 1 indicates the head is **not masked**,
818
+ - 0 indicates the head is **masked**.
819
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
820
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
821
+ config.n_positions - 1]`.
822
+ [What are position IDs?](../glossary#position-ids)
823
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
824
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
825
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
826
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
827
+ Two formats are allowed:
828
+ - a [`~cache_utils.Cache`] instance;
829
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
830
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
831
+ cache format.
832
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
833
+ legacy cache format will be returned.
834
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
835
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
836
+ of shape `(batch_size, sequence_length)`.
837
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
838
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
839
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
840
+ model's internal embedding lookup matrix.
841
+ use_cache (`bool`, *optional*):
842
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
843
+ `past_key_values`).
844
+ output_attentions (`bool`, *optional*):
845
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
846
+ tensors for more detail.
847
+ output_hidden_states (`bool`, *optional*):
848
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
849
+ more detail.
850
+ return_dict (`bool`, *optional*):
851
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
852
+ """
853
+
854
+
855
+ @add_start_docstrings(
856
+ "The bare Phi Model outputting raw hidden-states without any specific head on top.",
857
+ PHI_START_DOCSTRING,
858
+ )
859
+ class PhiModel(PhiPreTrainedModel):
860
+ """
861
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`PhiDecoderLayer`]
862
+ Args:
863
+ config: PhiConfig
864
+ """
865
+
866
+ def __init__(self, config: PhiConfig):
867
+ super().__init__(config)
868
+ self.padding_idx = config.pad_token_id
869
+ self.vocab_size = config.vocab_size
870
+
871
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
872
+ self.embed_dropout = nn.Dropout(config.embd_pdrop)
873
+ self.layers = nn.ModuleList(
874
+ [PhiDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
875
+ )
876
+ self.final_layernorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
877
+ self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
878
+
879
+ self.gradient_checkpointing = False
880
+ # Initialize weights and apply final processing
881
+ self.post_init()
882
+
883
+ def get_input_embeddings(self):
884
+ return self.embed_tokens
885
+
886
+ def set_input_embeddings(self, value):
887
+ self.embed_tokens = value
888
+
889
+ @add_start_docstrings_to_model_forward(PHI_INPUTS_DOCSTRING)
890
+ def forward(
891
+ self,
892
+ input_ids: torch.LongTensor = None,
893
+ attention_mask: Optional[torch.Tensor] = None,
894
+ position_ids: Optional[torch.LongTensor] = None,
895
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
896
+ inputs_embeds: Optional[torch.FloatTensor] = None,
897
+ use_cache: Optional[bool] = None,
898
+ output_attentions: Optional[bool] = None,
899
+ output_hidden_states: Optional[bool] = None,
900
+ return_dict: Optional[bool] = None,
901
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
902
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
903
+ output_hidden_states = (
904
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
905
+ )
906
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
907
+
908
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
909
+
910
+ # retrieve input_ids and inputs_embeds
911
+ if input_ids is not None and inputs_embeds is not None:
912
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
913
+ elif input_ids is not None:
914
+ batch_size, seq_length = input_ids.shape[:2]
915
+ elif inputs_embeds is not None:
916
+ batch_size, seq_length = inputs_embeds.shape[:2]
917
+ else:
918
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
919
+
920
+ past_key_values_length = 0
921
+
922
+ if self.gradient_checkpointing and self.training:
923
+ if use_cache:
924
+ logger.warning_once(
925
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
926
+ )
927
+ use_cache = False
928
+
929
+ if use_cache:
930
+ use_legacy_cache = not isinstance(past_key_values, Cache)
931
+ if use_legacy_cache:
932
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
933
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
934
+
935
+ if position_ids is None:
936
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
937
+ position_ids = torch.arange(
938
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
939
+ )
940
+ position_ids = position_ids.unsqueeze(0)
941
+
942
+ if inputs_embeds is None:
943
+ inputs_embeds = self.embed_tokens(input_ids)
944
+
945
+ inputs_embeds = self.embed_dropout(inputs_embeds)
946
+
947
+ # Attention mask.
948
+ if self._use_flash_attention_2:
949
+ # 2d mask is passed through the layers
950
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
951
+ else:
952
+ # 4d mask is passed through the layers
953
+ attention_mask = _prepare_4d_causal_attention_mask(
954
+ attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
955
+ )
956
+
957
+ hidden_states = inputs_embeds
958
+
959
+ # decoder layers
960
+ all_hidden_states = () if output_hidden_states else None
961
+ all_self_attns = () if output_attentions else None
962
+ next_decoder_cache = None
963
+
964
+ for decoder_layer in self.layers:
965
+ if output_hidden_states:
966
+ all_hidden_states += (hidden_states,)
967
+
968
+ if self.gradient_checkpointing and self.training:
969
+ layer_outputs = self._gradient_checkpointing_func(
970
+ decoder_layer.__call__,
971
+ hidden_states,
972
+ attention_mask,
973
+ position_ids,
974
+ past_key_values,
975
+ output_attentions,
976
+ )
977
+ else:
978
+ layer_outputs = decoder_layer(
979
+ hidden_states,
980
+ attention_mask=attention_mask,
981
+ position_ids=position_ids,
982
+ past_key_value=past_key_values,
983
+ output_attentions=output_attentions,
984
+ use_cache=use_cache,
985
+ )
986
+
987
+ hidden_states = layer_outputs[0]
988
+
989
+ if use_cache:
990
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
991
+
992
+ if output_attentions:
993
+ all_self_attns += (layer_outputs[1],)
994
+
995
+ hidden_states = self.final_layernorm(hidden_states)
996
+
997
+ # add hidden states from the last decoder layer
998
+ if output_hidden_states:
999
+ all_hidden_states += (hidden_states,)
1000
+
1001
+ next_cache = None
1002
+ if use_cache:
1003
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
1004
+ if not return_dict:
1005
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1006
+ return BaseModelOutputWithPast(
1007
+ last_hidden_state=hidden_states,
1008
+ past_key_values=next_cache,
1009
+ hidden_states=all_hidden_states,
1010
+ attentions=all_self_attns,
1011
+ )
1012
+
1013
+
1014
+ class PhiForCausalLM(PhiPreTrainedModel):
1015
+ _tied_weights_keys = ["lm_head.weight"]
1016
+
1017
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi,bias=False->bias=True
1018
+ def __init__(self, config):
1019
+ super().__init__(config)
1020
+ self.model = PhiModel(config)
1021
+ self.vocab_size = config.vocab_size
1022
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=True)
1023
+
1024
+ # Initialize weights and apply final processing
1025
+ self.post_init()
1026
+
1027
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
1028
+ def get_input_embeddings(self):
1029
+ return self.model.embed_tokens
1030
+
1031
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
1032
+ def set_input_embeddings(self, value):
1033
+ self.model.embed_tokens = value
1034
+
1035
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
1036
+ def get_output_embeddings(self):
1037
+ return self.lm_head
1038
+
1039
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
1040
+ def set_output_embeddings(self, new_embeddings):
1041
+ self.lm_head = new_embeddings
1042
+
1043
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
1044
+ def set_decoder(self, decoder):
1045
+ self.model = decoder
1046
+
1047
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
1048
+ def get_decoder(self):
1049
+ return self.model
1050
+
1051
+ @add_start_docstrings_to_model_forward(PHI_INPUTS_DOCSTRING)
1052
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1053
+ def forward(
1054
+ self,
1055
+ input_ids: torch.LongTensor = None,
1056
+ attention_mask: Optional[torch.Tensor] = None,
1057
+ position_ids: Optional[torch.LongTensor] = None,
1058
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1059
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1060
+ labels: Optional[torch.LongTensor] = None,
1061
+ use_cache: Optional[bool] = None,
1062
+ output_attentions: Optional[bool] = None,
1063
+ output_hidden_states: Optional[bool] = None,
1064
+ return_dict: Optional[bool] = None,
1065
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1066
+ r"""
1067
+ Args:
1068
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1069
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1070
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1071
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1072
+ Returns:
1073
+ Example:
1074
+ ```python
1075
+ >>> from transformers import AutoTokenizer, PhiForCausalLM
1076
+ >>> model = PhiForCausalLM.from_pretrained("microsoft/phi-1")
1077
+ >>> tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1")
1078
+ >>> prompt = "This is an example script ."
1079
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1080
+ >>> # Generate
1081
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1082
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1083
+ 'This is an example script .\n\n\n\nfrom typing import List\n\ndef find_most_common_letter(words: List[str'
1084
+ ```"""
1085
+
1086
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1087
+ output_hidden_states = (
1088
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1089
+ )
1090
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1091
+
1092
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1093
+ outputs = self.model(
1094
+ input_ids=input_ids,
1095
+ attention_mask=attention_mask,
1096
+ position_ids=position_ids,
1097
+ past_key_values=past_key_values,
1098
+ inputs_embeds=inputs_embeds,
1099
+ use_cache=use_cache,
1100
+ output_attentions=output_attentions,
1101
+ output_hidden_states=output_hidden_states,
1102
+ return_dict=return_dict,
1103
+ )
1104
+
1105
+ hidden_states = outputs[0]
1106
+ logits = self.lm_head(hidden_states)
1107
+ logits = logits.float()
1108
+
1109
+ loss = None
1110
+ if labels is not None:
1111
+ # Shift so that tokens < n predict n
1112
+ shift_logits = logits[..., :-1, :].contiguous()
1113
+ shift_labels = labels[..., 1:].contiguous()
1114
+ # Flatten the tokens
1115
+ loss_fct = CrossEntropyLoss()
1116
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1117
+ shift_labels = shift_labels.view(-1)
1118
+ # Enable model parallelism
1119
+ shift_labels = shift_labels.to(shift_logits.device)
1120
+ loss = loss_fct(shift_logits, shift_labels)
1121
+
1122
+ if not return_dict:
1123
+ output = (logits,) + outputs[1:]
1124
+ return (loss,) + output if loss is not None else output
1125
+
1126
+ return CausalLMOutputWithPast(
1127
+ loss=loss,
1128
+ logits=logits,
1129
+ past_key_values=outputs.past_key_values,
1130
+ hidden_states=outputs.hidden_states,
1131
+ attentions=outputs.attentions,
1132
+ )
1133
+
1134
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.prepare_inputs_for_generation
1135
+ def prepare_inputs_for_generation(
1136
+ self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
1137
+ ):
1138
+ if past_key_values is not None:
1139
+ if isinstance(past_key_values, Cache):
1140
+ cache_length = past_key_values.get_seq_length()
1141
+ past_length = past_key_values.seen_tokens
1142
+ max_cache_length = past_key_values.get_max_length()
1143
+ else:
1144
+ cache_length = past_length = past_key_values[0][0].shape[2]
1145
+ max_cache_length = None
1146
+
1147
+ # Keep only the unprocessed tokens:
1148
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1149
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
1150
+ # input)
1151
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
1152
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1153
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1154
+ # input_ids based on the past_length.
1155
+ elif past_length < input_ids.shape[1]:
1156
+ input_ids = input_ids[:, past_length:]
1157
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1158
+
1159
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1160
+ if (
1161
+ max_cache_length is not None
1162
+ and attention_mask is not None
1163
+ and cache_length + input_ids.shape[1] > max_cache_length
1164
+ ):
1165
+ attention_mask = attention_mask[:, -max_cache_length:]
1166
+
1167
+ position_ids = kwargs.get("position_ids", None)
1168
+ if attention_mask is not None and position_ids is None:
1169
+ # create position_ids on the fly for batch generation
1170
+ position_ids = attention_mask.long().cumsum(-1) - 1
1171
+ position_ids.masked_fill_(attention_mask == 0, 1)
1172
+ if past_key_values:
1173
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1174
+
1175
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1176
+ if inputs_embeds is not None and past_key_values is None:
1177
+ model_inputs = {"inputs_embeds": inputs_embeds}
1178
+ else:
1179
+ model_inputs = {"input_ids": input_ids}
1180
+
1181
+ model_inputs.update(
1182
+ {
1183
+ "position_ids": position_ids,
1184
+ "past_key_values": past_key_values,
1185
+ "use_cache": kwargs.get("use_cache"),
1186
+ "attention_mask": attention_mask,
1187
+ }
1188
+ )
1189
+ return model_inputs
1190
+
1191
+ @staticmethod
1192
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
1193
+ def _reorder_cache(past_key_values, beam_idx):
1194
+ reordered_past = ()
1195
+ for layer_past in past_key_values:
1196
+ reordered_past += (
1197
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1198
+ )
1199
+ return reordered_past
1200
+
1201
+
1202
+ @add_start_docstrings(
1203
+ """
1204
+ The PhiModel with a sequence classification head on top (linear layer).
1205
+ [`PhiForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1206
+ (e.g. GPT-2) do.
1207
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1208
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1209
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1210
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1211
+ each row of the batch).
1212
+ """,
1213
+ PHI_START_DOCSTRING,
1214
+ )
1215
+ # Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with LLAMA->PHI,Llama->Phi with self.transformer->self.model, transformer_outputs->model_outputs
1216
+ class PhiForSequenceClassification(PhiPreTrainedModel):
1217
+ def __init__(self, config):
1218
+ super().__init__(config)
1219
+ self.num_labels = config.num_labels
1220
+ self.model = PhiModel(config)
1221
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1222
+
1223
+ # Initialize weights and apply final processing
1224
+ self.post_init()
1225
+
1226
+ def get_input_embeddings(self):
1227
+ return self.model.embed_tokens
1228
+
1229
+ def set_input_embeddings(self, value):
1230
+ self.model.embed_tokens = value
1231
+
1232
+ @add_start_docstrings_to_model_forward(PHI_INPUTS_DOCSTRING)
1233
+ def forward(
1234
+ self,
1235
+ input_ids: torch.LongTensor = None,
1236
+ attention_mask: Optional[torch.Tensor] = None,
1237
+ position_ids: Optional[torch.LongTensor] = None,
1238
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1239
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1240
+ labels: Optional[torch.LongTensor] = None,
1241
+ use_cache: Optional[bool] = None,
1242
+ output_attentions: Optional[bool] = None,
1243
+ output_hidden_states: Optional[bool] = None,
1244
+ return_dict: Optional[bool] = None,
1245
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1246
+ r"""
1247
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1248
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1249
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1250
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1251
+ """
1252
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1253
+
1254
+ model_outputs = self.model(
1255
+ input_ids,
1256
+ attention_mask=attention_mask,
1257
+ position_ids=position_ids,
1258
+ past_key_values=past_key_values,
1259
+ inputs_embeds=inputs_embeds,
1260
+ use_cache=use_cache,
1261
+ output_attentions=output_attentions,
1262
+ output_hidden_states=output_hidden_states,
1263
+ return_dict=return_dict,
1264
+ )
1265
+ hidden_states = model_outputs[0]
1266
+ logits = self.score(hidden_states)
1267
+
1268
+ if input_ids is not None:
1269
+ batch_size = input_ids.shape[0]
1270
+ else:
1271
+ batch_size = inputs_embeds.shape[0]
1272
+
1273
+ if self.config.pad_token_id is None and batch_size != 1:
1274
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1275
+ if self.config.pad_token_id is None:
1276
+ sequence_lengths = -1
1277
+ else:
1278
+ if input_ids is not None:
1279
+ # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
1280
+ sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
1281
+ sequence_lengths = sequence_lengths % input_ids.shape[-1]
1282
+ sequence_lengths = sequence_lengths.to(logits.device)
1283
+ else:
1284
+ sequence_lengths = -1
1285
+
1286
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1287
+
1288
+ loss = None
1289
+ if labels is not None:
1290
+ labels = labels.to(logits.device)
1291
+ if self.config.problem_type is None:
1292
+ if self.num_labels == 1:
1293
+ self.config.problem_type = "regression"
1294
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1295
+ self.config.problem_type = "single_label_classification"
1296
+ else:
1297
+ self.config.problem_type = "multi_label_classification"
1298
+
1299
+ if self.config.problem_type == "regression":
1300
+ loss_fct = MSELoss()
1301
+ if self.num_labels == 1:
1302
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1303
+ else:
1304
+ loss = loss_fct(pooled_logits, labels)
1305
+ elif self.config.problem_type == "single_label_classification":
1306
+ loss_fct = CrossEntropyLoss()
1307
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1308
+ elif self.config.problem_type == "multi_label_classification":
1309
+ loss_fct = BCEWithLogitsLoss()
1310
+ loss = loss_fct(pooled_logits, labels)
1311
+ if not return_dict:
1312
+ output = (pooled_logits,) + model_outputs[1:]
1313
+ return ((loss,) + output) if loss is not None else output
1314
+
1315
+ return SequenceClassifierOutputWithPast(
1316
+ loss=loss,
1317
+ logits=pooled_logits,
1318
+ past_key_values=model_outputs.past_key_values,
1319
+ hidden_states=model_outputs.hidden_states,
1320
+ attentions=model_outputs.attentions,
1321
+ )
1322
+
1323
+
1324
+ @add_start_docstrings(
1325
+ """
1326
+ PhiModel with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
1327
+ Named-Entity-Recognition (NER) tasks.
1328
+ """,
1329
+ PHI_START_DOCSTRING,
1330
+ )
1331
+ # Copied from transformers.models.mpt.modeling_mpt.MptForTokenClassification with MPT->PHI,Mpt->Phi,self.transformer->self.model,transformer_outputs->model_outputs
1332
+ class PhiForTokenClassification(PhiPreTrainedModel):
1333
+ def __init__(self, config: PhiConfig):
1334
+ super().__init__(config)
1335
+ self.num_labels = config.num_labels
1336
+
1337
+ self.model = PhiModel(config)
1338
+ if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
1339
+ classifier_dropout = config.classifier_dropout
1340
+ elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
1341
+ classifier_dropout = config.hidden_dropout
1342
+ else:
1343
+ classifier_dropout = 0.1
1344
+ self.dropout = nn.Dropout(classifier_dropout)
1345
+ self.classifier = nn.Linear(config.hidden_size, config.num_labels)
1346
+
1347
+ # Initialize weights and apply final processing
1348
+ self.post_init()
1349
+
1350
+ @add_start_docstrings_to_model_forward(PHI_INPUTS_DOCSTRING)
1351
+ @add_code_sample_docstrings(
1352
+ checkpoint=_CHECKPOINT_FOR_DOC,
1353
+ output_type=TokenClassifierOutput,
1354
+ config_class=_CONFIG_FOR_DOC,
1355
+ )
1356
+ def forward(
1357
+ self,
1358
+ input_ids: Optional[torch.LongTensor] = None,
1359
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
1360
+ attention_mask: Optional[torch.Tensor] = None,
1361
+ inputs_embeds: Optional[torch.Tensor] = None,
1362
+ labels: Optional[torch.Tensor] = None,
1363
+ use_cache: Optional[bool] = None,
1364
+ output_attentions: Optional[bool] = None,
1365
+ output_hidden_states: Optional[bool] = None,
1366
+ return_dict: Optional[bool] = None,
1367
+ **deprecated_arguments,
1368
+ ) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
1369
+ r"""
1370
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1371
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1372
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1373
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1374
+ """
1375
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1376
+
1377
+ model_outputs = self.model(
1378
+ input_ids,
1379
+ past_key_values=past_key_values,
1380
+ attention_mask=attention_mask,
1381
+ inputs_embeds=inputs_embeds,
1382
+ use_cache=use_cache,
1383
+ output_attentions=output_attentions,
1384
+ output_hidden_states=output_hidden_states,
1385
+ return_dict=return_dict,
1386
+ )
1387
+
1388
+ hidden_states = model_outputs[0]
1389
+ hidden_states = self.dropout(hidden_states)
1390
+ logits = self.classifier(hidden_states)
1391
+
1392
+ loss = None
1393
+ if labels is not None:
1394
+ # move labels to correct device to enable model parallelism
1395
+ labels = labels.to(logits.device)
1396
+ batch_size, seq_length = labels.shape
1397
+ loss_fct = CrossEntropyLoss()
1398
+ loss = loss_fct(
1399
+ logits.view(batch_size * seq_length, self.num_labels), labels.view(batch_size * seq_length)
1400
+ )
1401
+
1402
+ if not return_dict:
1403
+ output = (logits,) + model_outputs[2:]
1404
+ return ((loss,) + output) if loss is not None else output
1405
+
1406
+ return TokenClassifierOutput(
1407
+ loss=loss,
1408
+ logits=logits,
1409
+ hidden_states=model_outputs.hidden_states,
1410
+ attentions=model_outputs.attentions,
1411
+ )
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|endoftext|>",
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
+ "unk_token": {
17
+ "content": "<|endoftext|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": " ",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": false
19
+ },
20
+ "50258": {
21
+ "content": " ",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ },
28
+ "50259": {
29
+ "content": " ",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": false
35
+ },
36
+ "50260": {
37
+ "content": " ",
38
+ "lstrip": false,
39
+ "normalized": true,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": false
43
+ },
44
+ "50261": {
45
+ "content": " ",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": false
51
+ },
52
+ "50262": {
53
+ "content": " ",
54
+ "lstrip": false,
55
+ "normalized": true,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": false
59
+ },
60
+ "50263": {
61
+ "content": " ",
62
+ "lstrip": false,
63
+ "normalized": true,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": false
67
+ },
68
+ "50264": {
69
+ "content": " ",
70
+ "lstrip": false,
71
+ "normalized": true,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": false
75
+ },
76
+ "50265": {
77
+ "content": " ",
78
+ "lstrip": false,
79
+ "normalized": true,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": false
83
+ },
84
+ "50266": {
85
+ "content": " ",
86
+ "lstrip": false,
87
+ "normalized": true,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": false
91
+ },
92
+ "50267": {
93
+ "content": " ",
94
+ "lstrip": false,
95
+ "normalized": true,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": false
99
+ },
100
+ "50268": {
101
+ "content": " ",
102
+ "lstrip": false,
103
+ "normalized": true,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": false
107
+ },
108
+ "50269": {
109
+ "content": " ",
110
+ "lstrip": false,
111
+ "normalized": true,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": false
115
+ },
116
+ "50270": {
117
+ "content": " ",
118
+ "lstrip": false,
119
+ "normalized": true,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "50271": {
125
+ "content": " ",
126
+ "lstrip": false,
127
+ "normalized": true,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "50272": {
133
+ "content": " ",
134
+ "lstrip": false,
135
+ "normalized": true,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "50273": {
141
+ "content": " ",
142
+ "lstrip": false,
143
+ "normalized": true,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "50274": {
149
+ "content": " ",
150
+ "lstrip": false,
151
+ "normalized": true,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "50275": {
157
+ "content": " ",
158
+ "lstrip": false,
159
+ "normalized": true,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "50276": {
165
+ "content": " ",
166
+ "lstrip": false,
167
+ "normalized": true,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "50277": {
173
+ "content": " ",
174
+ "lstrip": false,
175
+ "normalized": true,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "50278": {
181
+ "content": " ",
182
+ "lstrip": false,
183
+ "normalized": true,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "50279": {
189
+ "content": " ",
190
+ "lstrip": false,
191
+ "normalized": true,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "50280": {
197
+ "content": " ",
198
+ "lstrip": false,
199
+ "normalized": true,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "50281": {
205
+ "content": " ",
206
+ "lstrip": false,
207
+ "normalized": true,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "50282": {
213
+ "content": " ",
214
+ "lstrip": false,
215
+ "normalized": true,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": false
219
+ },
220
+ "50283": {
221
+ "content": " ",
222
+ "lstrip": false,
223
+ "normalized": true,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": false
227
+ },
228
+ "50284": {
229
+ "content": " ",
230
+ "lstrip": false,
231
+ "normalized": true,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": false
235
+ },
236
+ "50285": {
237
+ "content": " ",
238
+ "lstrip": false,
239
+ "normalized": true,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": false
243
+ },
244
+ "50286": {
245
+ "content": " ",
246
+ "lstrip": false,
247
+ "normalized": true,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": false
251
+ },
252
+ "50287": {
253
+ "content": "\t\t\t\t\t\t\t\t\t",
254
+ "lstrip": false,
255
+ "normalized": true,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": false
259
+ },
260
+ "50288": {
261
+ "content": "\t\t\t\t\t\t\t\t",
262
+ "lstrip": false,
263
+ "normalized": true,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": false
267
+ },
268
+ "50289": {
269
+ "content": "\t\t\t\t\t\t\t",
270
+ "lstrip": false,
271
+ "normalized": true,
272
+ "rstrip": false,
273
+ "single_word": false,
274
+ "special": false
275
+ },
276
+ "50290": {
277
+ "content": "\t\t\t\t\t\t",
278
+ "lstrip": false,
279
+ "normalized": true,
280
+ "rstrip": false,
281
+ "single_word": false,
282
+ "special": false
283
+ },
284
+ "50291": {
285
+ "content": "\t\t\t\t\t",
286
+ "lstrip": false,
287
+ "normalized": true,
288
+ "rstrip": false,
289
+ "single_word": false,
290
+ "special": false
291
+ },
292
+ "50292": {
293
+ "content": "\t\t\t\t",
294
+ "lstrip": false,
295
+ "normalized": true,
296
+ "rstrip": false,
297
+ "single_word": false,
298
+ "special": false
299
+ },
300
+ "50293": {
301
+ "content": "\t\t\t",
302
+ "lstrip": false,
303
+ "normalized": true,
304
+ "rstrip": false,
305
+ "single_word": false,
306
+ "special": false
307
+ },
308
+ "50294": {
309
+ "content": "\t\t",
310
+ "lstrip": false,
311
+ "normalized": true,
312
+ "rstrip": false,
313
+ "single_word": false,
314
+ "special": false
315
+ }
316
+ },
317
+ "bos_token": "<|endoftext|>",
318
+ "clean_up_tokenization_spaces": true,
319
+ "eos_token": "<|endoftext|>",
320
+ "model_max_length": 2048,
321
+ "tokenizer_class": "CodeGenTokenizer",
322
+ "unk_token": "<|endoftext|>"
323
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff