s1ghhh commited on
Commit
3c6f94b
1 Parent(s): 8ce3dfe
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MistralForCausalLM"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_dropped_mistral.MistralConfig",
7
+ "AutoModelForCausalLM": "modeling_dropped_mistral.MistralForCausalLM"
8
+ },
9
+ "drop_mlp_list": [26, 27, 25, 24, 23, 22, 29, 28],
10
+ "drop_attn_list": null,
11
+ "bos_token_id": 1,
12
+ "eos_token_id": 2,
13
+ "hidden_act": "silu",
14
+ "hidden_size": 4096,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 14336,
17
+ "max_position_embeddings": 32768,
18
+ "model_type": "mistral",
19
+ "num_attention_heads": 32,
20
+ "num_hidden_layers": 32,
21
+ "num_key_value_heads": 8,
22
+ "rms_norm_eps": 1e-05,
23
+ "rope_theta": 10000.0,
24
+ "sliding_window": 4096,
25
+ "tie_word_embeddings": false,
26
+ "torch_dtype": "bfloat16",
27
+ "transformers_version": "4.34.0.dev0",
28
+ "use_cache": true,
29
+ "vocab_size": 32000
30
+ }
configuration_dropped_mistral.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 Mistral AI 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
+ """ transformers==4.38.1"""
16
+ """ Mistral model configuration"""
17
+ from transformers.configuration_utils import PretrainedConfig
18
+ from transformers.utils import logging
19
+
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+ MISTRAL_PRETRAINED_CONFIG_ARCHIVE_MAP = {
24
+ "mistralai/Mistral-7B-v0.1": "https://huggingface.co/mistralai/Mistral-7B-v0.1/resolve/main/config.json",
25
+ "mistralai/Mistral-7B-Instruct-v0.1": "https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1/resolve/main/config.json",
26
+ }
27
+
28
+
29
+ class MistralConfig(PretrainedConfig):
30
+ r"""
31
+ This is the configuration class to store the configuration of a [`MistralModel`]. It is used to instantiate an
32
+ Mistral model according to the specified arguments, defining the model architecture. Instantiating a configuration
33
+ with the defaults will yield a similar configuration to that of the Mistral-7B-v0.1 or Mistral-7B-Instruct-v0.1.
34
+
35
+ [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
36
+ [mistralai/Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1)
37
+
38
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
39
+ documentation from [`PretrainedConfig`] for more information.
40
+
41
+
42
+ Args:
43
+ vocab_size (`int`, *optional*, defaults to 32000):
44
+ Vocabulary size of the Mistral model. Defines the number of different tokens that can be represented by the
45
+ `inputs_ids` passed when calling [`MistralModel`]
46
+ hidden_size (`int`, *optional*, defaults to 4096):
47
+ Dimension of the hidden representations.
48
+ intermediate_size (`int`, *optional*, defaults to 14336):
49
+ Dimension of the MLP representations.
50
+ num_hidden_layers (`int`, *optional*, defaults to 32):
51
+ Number of hidden layers in the Transformer encoder.
52
+ num_attention_heads (`int`, *optional*, defaults to 32):
53
+ Number of attention heads for each attention layer in the Transformer encoder.
54
+ num_key_value_heads (`int`, *optional*, defaults to 8):
55
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
56
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
57
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
58
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
59
+ by meanpooling all the original heads within that group. For more details checkout [this
60
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `8`.
61
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
62
+ The non-linear activation function (function or string) in the decoder.
63
+ max_position_embeddings (`int`, *optional*, defaults to `4096*32`):
64
+ The maximum sequence length that this model might ever be used with. Mistral's sliding window attention
65
+ allows sequence of up to 4096*32 tokens.
66
+ initializer_range (`float`, *optional*, defaults to 0.02):
67
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
68
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
69
+ The epsilon used by the rms normalization layers.
70
+ use_cache (`bool`, *optional*, defaults to `True`):
71
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
72
+ relevant if `config.is_decoder=True`.
73
+ pad_token_id (`int`, *optional*):
74
+ The id of the padding token.
75
+ bos_token_id (`int`, *optional*, defaults to 1):
76
+ The id of the "beginning-of-sequence" token.
77
+ eos_token_id (`int`, *optional*, defaults to 2):
78
+ The id of the "end-of-sequence" token.
79
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
80
+ Whether the model's input and output word embeddings should be tied.
81
+ rope_theta (`float`, *optional*, defaults to 10000.0):
82
+ The base period of the RoPE embeddings.
83
+ sliding_window (`int`, *optional*, defaults to 4096):
84
+ Sliding window attention window size. If not specified, will default to `4096`.
85
+ attention_dropout (`float`, *optional*, defaults to 0.0):
86
+ The dropout ratio for the attention probabilities.
87
+
88
+ ```python
89
+ >>> from transformers import MistralModel, MistralConfig
90
+
91
+ >>> # Initializing a Mistral 7B style configuration
92
+ >>> configuration = MistralConfig()
93
+
94
+ >>> # Initializing a model from the Mistral 7B style configuration
95
+ >>> model = MistralModel(configuration)
96
+
97
+ >>> # Accessing the model configuration
98
+ >>> configuration = model.config
99
+ ```"""
100
+
101
+ model_type = "mistral"
102
+ keys_to_ignore_at_inference = ["past_key_values"]
103
+
104
+ def __init__(
105
+ self,
106
+ vocab_size=32000,
107
+ hidden_size=4096,
108
+ intermediate_size=14336,
109
+ num_hidden_layers=32,
110
+ num_attention_heads=32,
111
+ num_key_value_heads=8,
112
+ hidden_act="silu",
113
+ max_position_embeddings=4096 * 32,
114
+ initializer_range=0.02,
115
+ rms_norm_eps=1e-6,
116
+ use_cache=True,
117
+ pad_token_id=None,
118
+ bos_token_id=1,
119
+ eos_token_id=2,
120
+ tie_word_embeddings=False,
121
+ rope_theta=10000.0,
122
+ sliding_window=4096,
123
+ attention_dropout=0.0,
124
+ drop_mlp_list=None,
125
+ drop_attn_list=None,
126
+ **kwargs,
127
+ ):
128
+ self.vocab_size = vocab_size
129
+ self.max_position_embeddings = max_position_embeddings
130
+ self.hidden_size = hidden_size
131
+ self.intermediate_size = intermediate_size
132
+ self.num_hidden_layers = num_hidden_layers
133
+ self.num_attention_heads = num_attention_heads
134
+ self.sliding_window = sliding_window
135
+
136
+ #####################################################################################################################
137
+
138
+ # ✨ trans bool into int
139
+ new_drop_attn_list = []
140
+ if drop_attn_list is not None:
141
+ for idx in range(len(drop_attn_list)):
142
+ if isinstance(drop_attn_list[idx], bool):
143
+ if drop_attn_list[idx] == True:
144
+ new_drop_attn_list.append(idx)
145
+ elif isinstance(drop_attn_list[idx], int):
146
+ new_drop_attn_list.append(drop_attn_list[idx])
147
+
148
+ new_drop_mlp_list = []
149
+ if drop_mlp_list is not None:
150
+ for idx in range(len(drop_mlp_list)):
151
+ if isinstance(drop_mlp_list[idx], bool):
152
+ if drop_mlp_list[idx] == True:
153
+ new_drop_mlp_list.append(idx)
154
+ elif isinstance(drop_mlp_list[idx], int):
155
+ new_drop_mlp_list.append(drop_mlp_list[idx])
156
+
157
+ #####################################################################################################################
158
+
159
+ if new_drop_mlp_list:
160
+ self.drop_mlp_list = []
161
+ for idx in range(self.num_hidden_layers):
162
+ self.drop_mlp_list.append(True if idx in new_drop_mlp_list else False)
163
+ else:
164
+ self.drop_mlp_list = [False] * self.num_hidden_layers
165
+
166
+ if new_drop_attn_list:
167
+ self.drop_attn_list = []
168
+ for idx in range(self.num_hidden_layers):
169
+ self.drop_attn_list.append(True if idx in new_drop_attn_list else False)
170
+ else:
171
+ self.drop_attn_list = [False] * self.num_hidden_layers
172
+
173
+ #####################################################################################################################
174
+
175
+ # for backward compatibility
176
+ if num_key_value_heads is None:
177
+ num_key_value_heads = num_attention_heads
178
+
179
+ self.num_key_value_heads = num_key_value_heads
180
+ self.hidden_act = hidden_act
181
+ self.initializer_range = initializer_range
182
+ self.rms_norm_eps = rms_norm_eps
183
+ self.use_cache = use_cache
184
+ self.rope_theta = rope_theta
185
+ self.attention_dropout = attention_dropout
186
+
187
+ super().__init__(
188
+ pad_token_id=pad_token_id,
189
+ bos_token_id=bos_token_id,
190
+ eos_token_id=eos_token_id,
191
+ tie_word_embeddings=tie_word_embeddings,
192
+ **kwargs,
193
+ )
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.36.0"
6
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9742cb4764964155b7a5f35eefad651f590006091ddeb536863d6c5865cca1b9
3
+ size 9942981696
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9bcf56354ec0c68b5f8e97b4f3b02d16af899a65b0868d6dba5a51c1b30f01cb
3
+ size 4540516344
model.safetensors.index.json ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 14483464192
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00002-of-00002.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
39
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
51
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
53
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
62
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
69
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
75
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
80
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
91
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
107
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
108
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
109
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
111
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
116
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
125
+ "model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
127
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
129
+ "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
130
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
132
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
134
+ "model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
135
+ "model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
138
+ "model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
139
+ "model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
140
+ "model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
141
+ "model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
143
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
144
+ "model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
145
+ "model.layers.22.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
146
+ "model.layers.22.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
147
+ "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
148
+ "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.22.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
152
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
153
+ "model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
154
+ "model.layers.23.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
155
+ "model.layers.23.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
156
+ "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
157
+ "model.layers.23.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
158
+ "model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
159
+ "model.layers.23.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
160
+ "model.layers.23.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
161
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
162
+ "model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
163
+ "model.layers.24.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
164
+ "model.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
165
+ "model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
166
+ "model.layers.24.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
167
+ "model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
168
+ "model.layers.24.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
169
+ "model.layers.24.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
170
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
171
+ "model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
172
+ "model.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
173
+ "model.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
174
+ "model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
175
+ "model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
176
+ "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
177
+ "model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
178
+ "model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
179
+ "model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
180
+ "model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
181
+ "model.layers.26.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
182
+ "model.layers.26.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
183
+ "model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
184
+ "model.layers.26.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
185
+ "model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
186
+ "model.layers.26.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
187
+ "model.layers.26.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
188
+ "model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
189
+ "model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
190
+ "model.layers.27.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
191
+ "model.layers.27.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
192
+ "model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
193
+ "model.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
194
+ "model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
195
+ "model.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
196
+ "model.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
197
+ "model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
198
+ "model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
199
+ "model.layers.28.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
200
+ "model.layers.28.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
201
+ "model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
202
+ "model.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
203
+ "model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
204
+ "model.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
205
+ "model.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
206
+ "model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
207
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
208
+ "model.layers.29.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
209
+ "model.layers.29.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
210
+ "model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
211
+ "model.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
212
+ "model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
213
+ "model.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
214
+ "model.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
215
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
216
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
217
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
218
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
219
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
220
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
221
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
222
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
223
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
224
+ "model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
225
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
226
+ "model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
227
+ "model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
228
+ "model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
229
+ "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
230
+ "model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
231
+ "model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
232
+ "model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
233
+ "model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
234
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
235
+ "model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
236
+ "model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
237
+ "model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
238
+ "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
239
+ "model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
240
+ "model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
241
+ "model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
242
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
243
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
244
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
245
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
246
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
247
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
248
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
249
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
250
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
251
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
252
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
253
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
254
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
255
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
256
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
257
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
258
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
259
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
260
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
261
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
262
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
267
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
269
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
270
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
271
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
272
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
273
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
274
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
275
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
276
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
277
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
278
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
279
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
280
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
281
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
282
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
283
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
284
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
285
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
286
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
287
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
288
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
289
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
290
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
291
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
292
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
293
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
294
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
295
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
296
+ "model.norm.weight": "model-00002-of-00002.safetensors"
297
+ }
298
+ }
modeling_dropped_mistral.py ADDED
@@ -0,0 +1,1105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 Mistral AI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """ transformers==4.38.1"""
21
+ """ PyTorch Mistral model."""
22
+ import inspect
23
+ import math
24
+ import warnings
25
+ from typing import List, Optional, Tuple, Union
26
+
27
+ import torch
28
+ import torch.nn.functional as F
29
+ import torch.utils.checkpoint
30
+ from torch import nn
31
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
32
+
33
+ from transformers.activations import ACT2FN
34
+ from transformers.cache_utils import Cache, DynamicCache
35
+ from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask, _prepare_4d_causal_attention_mask_for_sdpa
36
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
37
+ from transformers.modeling_utils import PreTrainedModel
38
+ from transformers.utils import (
39
+ add_start_docstrings,
40
+ add_start_docstrings_to_model_forward,
41
+ logging,
42
+ replace_return_docstrings,
43
+ )
44
+ from .configuration_dropped_mistral import MistralConfig
45
+
46
+
47
+
48
+ logger = logging.get_logger(__name__)
49
+
50
+ _CONFIG_FOR_DOC = "MistralConfig"
51
+
52
+
53
+ # Copied from transformers.models.llama.modeling_llama._get_unpad_data
54
+ def _get_unpad_data(attention_mask):
55
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
56
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
57
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
58
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
59
+ return (
60
+ indices,
61
+ cu_seqlens,
62
+ max_seqlen_in_batch,
63
+ )
64
+
65
+
66
+ # Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Mistral
67
+ class MistralRMSNorm(nn.Module):
68
+ def __init__(self, hidden_size, eps=1e-6):
69
+ """
70
+ MistralRMSNorm is equivalent to T5LayerNorm
71
+ """
72
+ super().__init__()
73
+ self.weight = nn.Parameter(torch.ones(hidden_size))
74
+ self.variance_epsilon = eps
75
+
76
+ def forward(self, hidden_states):
77
+ input_dtype = hidden_states.dtype
78
+ hidden_states = hidden_states.to(torch.float32)
79
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
80
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
81
+ return self.weight * hidden_states.to(input_dtype)
82
+
83
+
84
+ # Copied from transformers.models.llama.modeling_llama.LlamaRotaryEmbedding with Llama->Mistral
85
+ class MistralRotaryEmbedding(nn.Module):
86
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
87
+ super().__init__()
88
+
89
+ self.dim = dim
90
+ self.max_position_embeddings = max_position_embeddings
91
+ self.base = base
92
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
93
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
94
+
95
+ # Build here to make `torch.jit.trace` work.
96
+ self._set_cos_sin_cache(
97
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
98
+ )
99
+
100
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
101
+ self.max_seq_len_cached = seq_len
102
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
103
+
104
+ freqs = torch.outer(t, self.inv_freq)
105
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
106
+ emb = torch.cat((freqs, freqs), dim=-1)
107
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
108
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
109
+
110
+ def forward(self, x, seq_len=None):
111
+ # x: [bs, num_attention_heads, seq_len, head_size]
112
+ if seq_len > self.max_seq_len_cached:
113
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
114
+
115
+ return (
116
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
117
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
118
+ )
119
+
120
+
121
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
122
+ def rotate_half(x):
123
+ """Rotates half the hidden dims of the input."""
124
+ x1 = x[..., : x.shape[-1] // 2]
125
+ x2 = x[..., x.shape[-1] // 2 :]
126
+ return torch.cat((-x2, x1), dim=-1)
127
+
128
+
129
+ # Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
130
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
131
+ """Applies Rotary Position Embedding to the query and key tensors.
132
+
133
+ Args:
134
+ q (`torch.Tensor`): The query tensor.
135
+ k (`torch.Tensor`): The key tensor.
136
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
137
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
138
+ position_ids (`torch.Tensor`):
139
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
140
+ used to pass offsetted position ids when working with a KV-cache.
141
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
142
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
143
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
144
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
145
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
146
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
147
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
148
+ Returns:
149
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
150
+ """
151
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim)
152
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim)
153
+ q_embed = (q * cos) + (rotate_half(q) * sin)
154
+ k_embed = (k * cos) + (rotate_half(k) * sin)
155
+ return q_embed, k_embed
156
+
157
+
158
+ class MistralMLP(nn.Module):
159
+ def __init__(self, config):
160
+ super().__init__()
161
+ self.config = config
162
+ self.hidden_size = config.hidden_size
163
+ self.intermediate_size = config.intermediate_size
164
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
165
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
166
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
167
+ self.act_fn = ACT2FN[config.hidden_act]
168
+
169
+ def forward(self, x):
170
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
171
+
172
+
173
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv
174
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
175
+ """
176
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
177
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
178
+ """
179
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
180
+ if n_rep == 1:
181
+ return hidden_states
182
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
183
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
184
+
185
+
186
+ class MistralAttention(nn.Module):
187
+ """
188
+ Multi-headed attention from 'Attention Is All You Need' paper. Modified to use sliding window attention: Longformer
189
+ and "Generating Long Sequences with Sparse Transformers".
190
+ """
191
+
192
+ def __init__(self, config: MistralConfig, layer_idx: Optional[int] = None, kv_cache_idx: Optional[int] = None):
193
+ super().__init__()
194
+ self.config = config
195
+ self.layer_idx = layer_idx
196
+ self.kv_cache_idx = kv_cache_idx
197
+ if layer_idx is None:
198
+ logger.warning_once(
199
+ f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
200
+ "lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
201
+ "when creating this class."
202
+ )
203
+
204
+ self.hidden_size = config.hidden_size
205
+ self.num_heads = config.num_attention_heads
206
+ self.head_dim = self.hidden_size // self.num_heads
207
+ self.num_key_value_heads = config.num_key_value_heads
208
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
209
+ self.max_position_embeddings = config.max_position_embeddings
210
+ self.rope_theta = config.rope_theta
211
+ self.is_causal = True
212
+ self.attention_dropout = config.attention_dropout
213
+
214
+ if (self.head_dim * self.num_heads) != self.hidden_size:
215
+ raise ValueError(
216
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
217
+ f" and `num_heads`: {self.num_heads})."
218
+ )
219
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
220
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
221
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
222
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
223
+
224
+ self.rotary_emb = MistralRotaryEmbedding(
225
+ self.head_dim,
226
+ max_position_embeddings=self.max_position_embeddings,
227
+ base=self.rope_theta,
228
+ )
229
+
230
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
231
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
232
+
233
+ def forward(
234
+ self,
235
+ hidden_states: torch.Tensor,
236
+ attention_mask: Optional[torch.Tensor] = None,
237
+ position_ids: Optional[torch.LongTensor] = None,
238
+ past_key_value: Optional[Cache] = None,
239
+ output_attentions: bool = False,
240
+ use_cache: bool = False,
241
+ **kwargs,
242
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
243
+ if "padding_mask" in kwargs:
244
+ warnings.warn(
245
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
246
+ )
247
+ bsz, q_len, _ = hidden_states.size()
248
+
249
+ query_states = self.q_proj(hidden_states)
250
+ key_states = self.k_proj(hidden_states)
251
+ value_states = self.v_proj(hidden_states)
252
+
253
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
254
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
255
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
256
+
257
+ kv_seq_len = key_states.shape[-2]
258
+ if past_key_value is not None:
259
+ if self.kv_cache_idx is None:
260
+ raise ValueError(
261
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
262
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
263
+ "with a layer index."
264
+ )
265
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.kv_cache_idx)
266
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
267
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
268
+
269
+ if past_key_value is not None:
270
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
271
+ key_states, value_states = past_key_value.update(key_states, value_states, self.kv_cache_idx, cache_kwargs)
272
+
273
+ # repeat k/v heads if n_kv_heads < n_heads
274
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
275
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
276
+
277
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
278
+
279
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
280
+ raise ValueError(
281
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
282
+ f" {attn_weights.size()}"
283
+ )
284
+
285
+ if attention_mask is not None:
286
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
287
+ raise ValueError(
288
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
289
+ )
290
+
291
+ attn_weights = attn_weights + attention_mask
292
+
293
+ # upcast attention to fp32
294
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
295
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
296
+ attn_output = torch.matmul(attn_weights, value_states)
297
+
298
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
299
+ raise ValueError(
300
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
301
+ f" {attn_output.size()}"
302
+ )
303
+
304
+ attn_output = attn_output.transpose(1, 2).contiguous()
305
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
306
+
307
+ attn_output = self.o_proj(attn_output)
308
+
309
+ if not output_attentions:
310
+ attn_weights = None
311
+
312
+ return attn_output, attn_weights, past_key_value
313
+
314
+
315
+
316
+ # Copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->Mistral
317
+ class MistralSdpaAttention(MistralAttention):
318
+ """
319
+ Mistral attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
320
+ `MistralAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
321
+ SDPA API.
322
+ """
323
+
324
+ # Adapted from MistralAttention.forward
325
+ def forward(
326
+ self,
327
+ hidden_states: torch.Tensor,
328
+ attention_mask: Optional[torch.Tensor] = None,
329
+ position_ids: Optional[torch.LongTensor] = None,
330
+ past_key_value: Optional[Cache] = None,
331
+ output_attentions: bool = False,
332
+ use_cache: bool = False,
333
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
334
+ if output_attentions:
335
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
336
+ logger.warning_once(
337
+ "MistralModel is using MistralSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
338
+ 'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
339
+ )
340
+ return super().forward(
341
+ hidden_states=hidden_states,
342
+ attention_mask=attention_mask,
343
+ position_ids=position_ids,
344
+ past_key_value=past_key_value,
345
+ output_attentions=output_attentions,
346
+ use_cache=use_cache,
347
+ )
348
+
349
+ bsz, q_len, _ = hidden_states.size()
350
+
351
+ query_states = self.q_proj(hidden_states)
352
+ key_states = self.k_proj(hidden_states)
353
+ value_states = self.v_proj(hidden_states)
354
+
355
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
356
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
357
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
358
+
359
+ kv_seq_len = key_states.shape[-2]
360
+ if past_key_value is not None:
361
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.kv_cache_idx)
362
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
363
+
364
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
365
+
366
+ if past_key_value is not None:
367
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
368
+ key_states, value_states = past_key_value.update(key_states, value_states, self.kv_cache_idx, cache_kwargs)
369
+
370
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
371
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
372
+
373
+ if attention_mask is not None:
374
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
375
+ raise ValueError(
376
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
377
+ )
378
+
379
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
380
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
381
+ if query_states.device.type == "cuda" and attention_mask is not None:
382
+ query_states = query_states.contiguous()
383
+ key_states = key_states.contiguous()
384
+ value_states = value_states.contiguous()
385
+
386
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
387
+ query_states,
388
+ key_states,
389
+ value_states,
390
+ attn_mask=attention_mask,
391
+ dropout_p=self.attention_dropout if self.training else 0.0,
392
+ # The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
393
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
394
+ )
395
+
396
+ attn_output = attn_output.transpose(1, 2).contiguous()
397
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
398
+
399
+ attn_output = self.o_proj(attn_output)
400
+
401
+ return attn_output, None, past_key_value
402
+
403
+
404
+ MISTRAL_ATTENTION_CLASSES = {
405
+ "eager": MistralAttention,
406
+ "sdpa": MistralSdpaAttention,
407
+ }
408
+
409
+
410
+ class MistralDecoderLayer(nn.Module):
411
+ def __init__(self, config: MistralConfig, layer_idx: int):
412
+ super().__init__()
413
+ self.hidden_size = config.hidden_size
414
+ self.layer_idx = layer_idx
415
+
416
+ self.kv_cache_idx = 0
417
+ for i in range(self.layer_idx):
418
+ if not config.drop_attn_list[i]:
419
+ self.kv_cache_idx += 1
420
+
421
+ self.drop_attn = config.drop_attn_list[layer_idx]
422
+ if self.drop_attn:
423
+ self.self_attn = None
424
+ self.input_layernorm = None
425
+ else:
426
+ self.self_attn = MISTRAL_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx, self.kv_cache_idx)
427
+ self.input_layernorm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
428
+ self.drop_mlp = config.drop_mlp_list[layer_idx]
429
+ if self.drop_mlp:
430
+ self.mlp = None
431
+ self.post_attention_layernorm = None
432
+ else:
433
+ self.mlp = MistralMLP(config)
434
+ self.post_attention_layernorm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
435
+
436
+
437
+
438
+
439
+ def forward(
440
+ self,
441
+ hidden_states: torch.Tensor,
442
+ attention_mask: Optional[torch.Tensor] = None,
443
+ position_ids: Optional[torch.LongTensor] = None,
444
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
445
+ output_attentions: Optional[bool] = False,
446
+ use_cache: Optional[bool] = False,
447
+ **kwargs,
448
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
449
+ if "padding_mask" in kwargs:
450
+ warnings.warn(
451
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
452
+ )
453
+ """
454
+ Args:
455
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
456
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
457
+ `(batch, sequence_length)` where padding elements are indicated by 0.
458
+ output_attentions (`bool`, *optional*):
459
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
460
+ returned tensors for more detail.
461
+ use_cache (`bool`, *optional*):
462
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
463
+ (see `past_key_values`).
464
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
465
+ """
466
+ # use_cache = False
467
+ if not self.drop_attn:
468
+ residual = hidden_states
469
+
470
+ hidden_states = self.input_layernorm(hidden_states)
471
+
472
+ # Self Attention
473
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
474
+ hidden_states=hidden_states,
475
+ attention_mask=attention_mask,
476
+ position_ids=position_ids,
477
+ past_key_value=past_key_value,
478
+ output_attentions=output_attentions,
479
+ use_cache=use_cache,
480
+ )
481
+ hidden_states = residual + hidden_states
482
+
483
+ if not self.drop_mlp:
484
+ # Fully Connected
485
+ residual = hidden_states
486
+ hidden_states = self.post_attention_layernorm(hidden_states)
487
+ hidden_states = self.mlp(hidden_states)
488
+ hidden_states = residual + hidden_states
489
+
490
+ outputs = (hidden_states,)
491
+
492
+ if output_attentions:
493
+ outputs += (self_attn_weights,)
494
+
495
+ if use_cache and not self.drop_attn:
496
+ outputs += (present_key_value,)
497
+
498
+ return outputs
499
+
500
+
501
+ MISTRAL_START_DOCSTRING = r"""
502
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
503
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
504
+ etc.)
505
+
506
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
507
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
508
+ and behavior.
509
+
510
+ Parameters:
511
+ config ([`MistralConfig`]):
512
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
513
+ load the weights associated with the model, only the configuration. Check out the
514
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
515
+ """
516
+
517
+
518
+ @add_start_docstrings(
519
+ "The bare Mistral Model outputting raw hidden-states without any specific head on top.",
520
+ MISTRAL_START_DOCSTRING,
521
+ )
522
+ class MistralPreTrainedModel(PreTrainedModel):
523
+ config_class = MistralConfig
524
+ base_model_prefix = "model"
525
+ supports_gradient_checkpointing = True
526
+ _no_split_modules = ["MistralDecoderLayer"]
527
+ _skip_keys_device_placement = "past_key_values"
528
+ _supports_flash_attn_2 = True
529
+ _supports_sdpa = True
530
+ _supports_cache_class = True
531
+
532
+ def _init_weights(self, module):
533
+ std = self.config.initializer_range
534
+ if isinstance(module, nn.Linear):
535
+ module.weight.data.normal_(mean=0.0, std=std)
536
+ if module.bias is not None:
537
+ module.bias.data.zero_()
538
+ elif isinstance(module, nn.Embedding):
539
+ module.weight.data.normal_(mean=0.0, std=std)
540
+ if module.padding_idx is not None:
541
+ module.weight.data[module.padding_idx].zero_()
542
+
543
+
544
+ MISTRAL_INPUTS_DOCSTRING = r"""
545
+ Args:
546
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
547
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
548
+ it.
549
+
550
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
551
+ [`PreTrainedTokenizer.__call__`] for details.
552
+
553
+ [What are input IDs?](../glossary#input-ids)
554
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
555
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
556
+
557
+ - 1 for tokens that are **not masked**,
558
+ - 0 for tokens that are **masked**.
559
+
560
+ [What are attention masks?](../glossary#attention-mask)
561
+
562
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
563
+ [`PreTrainedTokenizer.__call__`] for details.
564
+
565
+ If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
566
+ `past_key_values`).
567
+
568
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
569
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
570
+ information on the default strategy.
571
+
572
+ - 1 indicates the head is **not masked**,
573
+ - 0 indicates the head is **masked**.
574
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
575
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
576
+ config.n_positions - 1]`.
577
+
578
+ [What are position IDs?](../glossary#position-ids)
579
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
580
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
581
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
582
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
583
+
584
+ Two formats are allowed:
585
+ - a [`~cache_utils.Cache`] instance;
586
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
587
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
588
+ cache format.
589
+
590
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
591
+ legacy cache format will be returned.
592
+
593
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
594
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
595
+ of shape `(batch_size, sequence_length)`.
596
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
597
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
598
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
599
+ model's internal embedding lookup matrix.
600
+ use_cache (`bool`, *optional*):
601
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
602
+ `past_key_values`).
603
+ output_attentions (`bool`, *optional*):
604
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
605
+ tensors for more detail.
606
+ output_hidden_states (`bool`, *optional*):
607
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
608
+ more detail.
609
+ return_dict (`bool`, *optional*):
610
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
611
+ """
612
+
613
+
614
+ @add_start_docstrings(
615
+ "The bare Mistral Model outputting raw hidden-states without any specific head on top.",
616
+ MISTRAL_START_DOCSTRING,
617
+ )
618
+ class MistralModel(MistralPreTrainedModel):
619
+ """
620
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`MistralDecoderLayer`]
621
+
622
+ Args:
623
+ config: MistralConfig
624
+ """
625
+
626
+ def __init__(self, config: MistralConfig):
627
+ super().__init__(config)
628
+ self.padding_idx = config.pad_token_id
629
+ self.vocab_size = config.vocab_size
630
+
631
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
632
+ self.layers = nn.ModuleList(
633
+ [MistralDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
634
+ )
635
+ self._attn_implementation = config._attn_implementation
636
+ self.norm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
637
+
638
+ self.gradient_checkpointing = False
639
+ # Initialize weights and apply final processing
640
+ self.post_init()
641
+
642
+ def get_input_embeddings(self):
643
+ return self.embed_tokens
644
+
645
+ def set_input_embeddings(self, value):
646
+ self.embed_tokens = value
647
+
648
+ @add_start_docstrings_to_model_forward(MISTRAL_INPUTS_DOCSTRING)
649
+ def forward(
650
+ self,
651
+ input_ids: torch.LongTensor = None,
652
+ attention_mask: Optional[torch.Tensor] = None,
653
+ position_ids: Optional[torch.LongTensor] = None,
654
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
655
+ inputs_embeds: Optional[torch.FloatTensor] = None,
656
+ use_cache: Optional[bool] = None,
657
+ output_attentions: Optional[bool] = None,
658
+ output_hidden_states: Optional[bool] = None,
659
+ return_dict: Optional[bool] = None,
660
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
661
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
662
+ output_hidden_states = (
663
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
664
+ )
665
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
666
+
667
+ # use_cache = False
668
+
669
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
670
+
671
+ # retrieve input_ids and inputs_embeds
672
+ if input_ids is not None and inputs_embeds is not None:
673
+ raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
674
+ elif input_ids is not None:
675
+ batch_size, seq_length = input_ids.shape
676
+ elif inputs_embeds is not None:
677
+ batch_size, seq_length, _ = inputs_embeds.shape
678
+ else:
679
+ raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
680
+
681
+ if self.gradient_checkpointing and self.training:
682
+ if use_cache:
683
+ logger.warning_once(
684
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
685
+ )
686
+ use_cache = False
687
+
688
+ past_key_values_length = 0
689
+
690
+ if use_cache:
691
+ use_legacy_cache = not isinstance(past_key_values, Cache)
692
+ if use_legacy_cache:
693
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
694
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
695
+
696
+ if position_ids is None:
697
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
698
+ position_ids = torch.arange(
699
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
700
+ )
701
+ position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
702
+ else:
703
+ position_ids = position_ids.view(-1, seq_length).long()
704
+
705
+ if inputs_embeds is None:
706
+ inputs_embeds = self.embed_tokens(input_ids)
707
+
708
+ if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
709
+ is_padding_right = attention_mask[:, -1].sum().item() != batch_size
710
+ if is_padding_right:
711
+ raise ValueError(
712
+ "You are attempting to perform batched generation with padding_side='right'"
713
+ " this may lead to unexpected behaviour for Flash Attention version of Mistral. Make sure to "
714
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
715
+ )
716
+
717
+ if self._attn_implementation == "flash_attention_2":
718
+ # 2d mask is passed through the layers
719
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
720
+ elif self._attn_implementation == "sdpa" and not output_attentions:
721
+ # output_attentions=True can not be supported when using SDPA, and we fall back on
722
+ # the manual implementation that requires a 4D causal mask in all cases.
723
+ attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
724
+ attention_mask,
725
+ (batch_size, seq_length),
726
+ inputs_embeds,
727
+ past_key_values_length,
728
+ )
729
+ else:
730
+ # 4d mask is passed through the layers
731
+ attention_mask = _prepare_4d_causal_attention_mask(
732
+ attention_mask,
733
+ (batch_size, seq_length),
734
+ inputs_embeds,
735
+ past_key_values_length,
736
+ sliding_window=self.config.sliding_window,
737
+ )
738
+
739
+ hidden_states = inputs_embeds
740
+
741
+ # decoder layers
742
+ all_hidden_states = () if output_hidden_states else None
743
+ all_self_attns = () if output_attentions else None
744
+ next_decoder_cache = None
745
+
746
+ for decoder_layer in self.layers:
747
+ if output_hidden_states:
748
+ all_hidden_states += (hidden_states,)
749
+
750
+ if self.gradient_checkpointing and self.training:
751
+ layer_outputs = self._gradient_checkpointing_func(
752
+ decoder_layer.__call__,
753
+ hidden_states,
754
+ attention_mask,
755
+ position_ids,
756
+ past_key_values,
757
+ output_attentions,
758
+ use_cache,
759
+ )
760
+ else:
761
+ layer_outputs = decoder_layer(
762
+ hidden_states,
763
+ attention_mask=attention_mask,
764
+ position_ids=position_ids,
765
+ past_key_value=past_key_values,
766
+ output_attentions=output_attentions,
767
+ use_cache=use_cache,
768
+ )
769
+
770
+ hidden_states = layer_outputs[0]
771
+
772
+ if use_cache and not decoder_layer.drop_attn:
773
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
774
+
775
+ if output_attentions:
776
+ all_self_attns += (layer_outputs[1],)
777
+
778
+ hidden_states = self.norm(hidden_states)
779
+
780
+ # add hidden states from the last decoder layer
781
+ if output_hidden_states:
782
+ all_hidden_states += (hidden_states,)
783
+
784
+ next_cache = None
785
+ if use_cache:
786
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
787
+
788
+ if not return_dict:
789
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
790
+ return BaseModelOutputWithPast(
791
+ last_hidden_state=hidden_states,
792
+ past_key_values=next_cache,
793
+ hidden_states=all_hidden_states,
794
+ attentions=all_self_attns,
795
+ )
796
+
797
+
798
+ class MistralForCausalLM(MistralPreTrainedModel):
799
+ _tied_weights_keys = ["lm_head.weight"]
800
+
801
+ def __init__(self, config):
802
+ super().__init__(config)
803
+ self.model = MistralModel(config)
804
+ self.vocab_size = config.vocab_size
805
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
806
+
807
+ # Initialize weights and apply final processing
808
+ self.post_init()
809
+
810
+ def get_input_embeddings(self):
811
+ return self.model.embed_tokens
812
+
813
+ def set_input_embeddings(self, value):
814
+ self.model.embed_tokens = value
815
+
816
+ def get_output_embeddings(self):
817
+ return self.lm_head
818
+
819
+ def set_output_embeddings(self, new_embeddings):
820
+ self.lm_head = new_embeddings
821
+
822
+ def set_decoder(self, decoder):
823
+ self.model = decoder
824
+
825
+ def get_decoder(self):
826
+ return self.model
827
+
828
+ @add_start_docstrings_to_model_forward(MISTRAL_INPUTS_DOCSTRING)
829
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
830
+ def forward(
831
+ self,
832
+ input_ids: torch.LongTensor = None,
833
+ attention_mask: Optional[torch.Tensor] = None,
834
+ position_ids: Optional[torch.LongTensor] = None,
835
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
836
+ inputs_embeds: Optional[torch.FloatTensor] = None,
837
+ labels: Optional[torch.LongTensor] = None,
838
+ use_cache: Optional[bool] = None,
839
+ output_attentions: Optional[bool] = None,
840
+ output_hidden_states: Optional[bool] = None,
841
+ return_dict: Optional[bool] = None,
842
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
843
+ r"""
844
+ Args:
845
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
846
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
847
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
848
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
849
+
850
+ Returns:
851
+
852
+ Example:
853
+
854
+ ```python
855
+ >>> from transformers import AutoTokenizer, MistralForCausalLM
856
+
857
+ >>> model = MistralForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1")
858
+ >>> tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1")
859
+
860
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
861
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
862
+
863
+ >>> # Generate
864
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
865
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
866
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
867
+ ```"""
868
+
869
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
870
+ output_hidden_states = (
871
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
872
+ )
873
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
874
+
875
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
876
+ outputs = self.model(
877
+ input_ids=input_ids,
878
+ attention_mask=attention_mask,
879
+ position_ids=position_ids,
880
+ past_key_values=past_key_values,
881
+ inputs_embeds=inputs_embeds,
882
+ use_cache=use_cache,
883
+ output_attentions=output_attentions,
884
+ output_hidden_states=output_hidden_states,
885
+ return_dict=return_dict,
886
+ )
887
+
888
+ hidden_states = outputs[0]
889
+ logits = self.lm_head(hidden_states)
890
+ logits = logits.float()
891
+
892
+ loss = None
893
+ if labels is not None:
894
+ # Shift so that tokens < n predict n
895
+ shift_logits = logits[..., :-1, :].contiguous()
896
+ shift_labels = labels[..., 1:].contiguous()
897
+ # Flatten the tokens
898
+ loss_fct = CrossEntropyLoss()
899
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
900
+ shift_labels = shift_labels.view(-1)
901
+ # Enable model parallelism
902
+ shift_labels = shift_labels.to(shift_logits.device)
903
+ loss = loss_fct(shift_logits, shift_labels)
904
+
905
+ if not return_dict:
906
+ output = (logits,) + outputs[1:]
907
+ return (loss,) + output if loss is not None else output
908
+
909
+ return CausalLMOutputWithPast(
910
+ loss=loss,
911
+ logits=logits,
912
+ past_key_values=outputs.past_key_values,
913
+ hidden_states=outputs.hidden_states,
914
+ attentions=outputs.attentions,
915
+ )
916
+
917
+ def prepare_inputs_for_generation(
918
+ self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
919
+ ):
920
+ # Omit tokens covered by past_key_values
921
+ if past_key_values is not None:
922
+ if isinstance(past_key_values, Cache):
923
+ cache_length = past_key_values.get_seq_length()
924
+ past_length = past_key_values.seen_tokens
925
+ max_cache_length = past_key_values.get_max_length()
926
+ else:
927
+ cache_length = past_length = past_key_values[0][0].shape[2]
928
+ max_cache_length = None
929
+
930
+ # Keep only the unprocessed tokens:
931
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
932
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
933
+ # input)
934
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
935
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
936
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
937
+ # input_ids based on the past_length.
938
+ elif past_length < input_ids.shape[1]:
939
+ input_ids = input_ids[:, past_length:]
940
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
941
+
942
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
943
+ if (
944
+ max_cache_length is not None
945
+ and attention_mask is not None
946
+ and cache_length + input_ids.shape[1] > max_cache_length
947
+ ):
948
+ attention_mask = attention_mask[:, -max_cache_length:]
949
+
950
+ position_ids = kwargs.get("position_ids", None)
951
+ if attention_mask is not None and position_ids is None:
952
+ # create position_ids on the fly for batch generation
953
+ position_ids = attention_mask.long().cumsum(-1) - 1
954
+ position_ids.masked_fill_(attention_mask == 0, 1)
955
+ if past_key_values:
956
+ position_ids = position_ids[:, -input_ids.shape[1] :]
957
+
958
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
959
+ if inputs_embeds is not None and past_key_values is None:
960
+ model_inputs = {"inputs_embeds": inputs_embeds}
961
+ else:
962
+ model_inputs = {"input_ids": input_ids}
963
+
964
+ model_inputs.update(
965
+ {
966
+ "position_ids": position_ids,
967
+ "past_key_values": past_key_values,
968
+ "use_cache": kwargs.get("use_cache"),
969
+ "attention_mask": attention_mask,
970
+ }
971
+ )
972
+ return model_inputs
973
+
974
+ @staticmethod
975
+ def _reorder_cache(past_key_values, beam_idx):
976
+ reordered_past = ()
977
+ for layer_past in past_key_values:
978
+ reordered_past += (
979
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
980
+ )
981
+ return reordered_past
982
+
983
+
984
+ @add_start_docstrings(
985
+ """
986
+ The Mistral Model transformer with a sequence classification head on top (linear layer).
987
+
988
+ [`MistralForSequenceClassification`] uses the last token in order to do the classification, as other causal models
989
+ (e.g. GPT-2) do.
990
+
991
+ Since it does classification on the last token, it requires to know the position of the last token. If a
992
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
993
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
994
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
995
+ each row of the batch).
996
+ """,
997
+ MISTRAL_START_DOCSTRING,
998
+ )
999
+ # Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->Mistral, LLAMA->MISTRAL
1000
+ class MistralForSequenceClassification(MistralPreTrainedModel):
1001
+ def __init__(self, config):
1002
+ super().__init__(config)
1003
+ self.num_labels = config.num_labels
1004
+ self.model = MistralModel(config)
1005
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1006
+
1007
+ # Initialize weights and apply final processing
1008
+ self.post_init()
1009
+
1010
+ def get_input_embeddings(self):
1011
+ return self.model.embed_tokens
1012
+
1013
+ def set_input_embeddings(self, value):
1014
+ self.model.embed_tokens = value
1015
+
1016
+ @add_start_docstrings_to_model_forward(MISTRAL_INPUTS_DOCSTRING)
1017
+ def forward(
1018
+ self,
1019
+ input_ids: torch.LongTensor = None,
1020
+ attention_mask: Optional[torch.Tensor] = None,
1021
+ position_ids: Optional[torch.LongTensor] = None,
1022
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1023
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1024
+ labels: Optional[torch.LongTensor] = None,
1025
+ use_cache: Optional[bool] = None,
1026
+ output_attentions: Optional[bool] = None,
1027
+ output_hidden_states: Optional[bool] = None,
1028
+ return_dict: Optional[bool] = None,
1029
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1030
+ r"""
1031
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1032
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1033
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1034
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1035
+ """
1036
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1037
+
1038
+ transformer_outputs = self.model(
1039
+ input_ids,
1040
+ attention_mask=attention_mask,
1041
+ position_ids=position_ids,
1042
+ past_key_values=past_key_values,
1043
+ inputs_embeds=inputs_embeds,
1044
+ use_cache=use_cache,
1045
+ output_attentions=output_attentions,
1046
+ output_hidden_states=output_hidden_states,
1047
+ return_dict=return_dict,
1048
+ )
1049
+ hidden_states = transformer_outputs[0]
1050
+ logits = self.score(hidden_states)
1051
+
1052
+ if input_ids is not None:
1053
+ batch_size = input_ids.shape[0]
1054
+ else:
1055
+ batch_size = inputs_embeds.shape[0]
1056
+
1057
+ if self.config.pad_token_id is None and batch_size != 1:
1058
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1059
+ if self.config.pad_token_id is None:
1060
+ sequence_lengths = -1
1061
+ else:
1062
+ if input_ids is not None:
1063
+ # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
1064
+ sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
1065
+ sequence_lengths = sequence_lengths % input_ids.shape[-1]
1066
+ sequence_lengths = sequence_lengths.to(logits.device)
1067
+ else:
1068
+ sequence_lengths = -1
1069
+
1070
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1071
+
1072
+ loss = None
1073
+ if labels is not None:
1074
+ labels = labels.to(logits.device)
1075
+ if self.config.problem_type is None:
1076
+ if self.num_labels == 1:
1077
+ self.config.problem_type = "regression"
1078
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1079
+ self.config.problem_type = "single_label_classification"
1080
+ else:
1081
+ self.config.problem_type = "multi_label_classification"
1082
+
1083
+ if self.config.problem_type == "regression":
1084
+ loss_fct = MSELoss()
1085
+ if self.num_labels == 1:
1086
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1087
+ else:
1088
+ loss = loss_fct(pooled_logits, labels)
1089
+ elif self.config.problem_type == "single_label_classification":
1090
+ loss_fct = CrossEntropyLoss()
1091
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1092
+ elif self.config.problem_type == "multi_label_classification":
1093
+ loss_fct = BCEWithLogitsLoss()
1094
+ loss = loss_fct(pooled_logits, labels)
1095
+ if not return_dict:
1096
+ output = (pooled_logits,) + transformer_outputs[1:]
1097
+ return ((loss,) + output) if loss is not None else output
1098
+
1099
+ return SequenceClassifierOutputWithPast(
1100
+ loss=loss,
1101
+ logits=pooled_logits,
1102
+ past_key_values=transformer_outputs.past_key_values,
1103
+ hidden_states=transformer_outputs.hidden_states,
1104
+ attentions=transformer_outputs.attentions,
1105
+ )
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 14483464192
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00002-of-00002.bin",
7
+ "model.embed_tokens.weight": "pytorch_model-00001-of-00002.bin",
8
+ "model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
9
+ "model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
10
+ "model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
11
+ "model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
12
+ "model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
13
+ "model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
14
+ "model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
15
+ "model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
16
+ "model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
17
+ "model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
18
+ "model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
19
+ "model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
20
+ "model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
21
+ "model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
22
+ "model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
23
+ "model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
24
+ "model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
25
+ "model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
26
+ "model.layers.10.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
27
+ "model.layers.10.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
28
+ "model.layers.10.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
29
+ "model.layers.10.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
30
+ "model.layers.10.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
31
+ "model.layers.10.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
32
+ "model.layers.10.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
33
+ "model.layers.10.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
34
+ "model.layers.10.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
35
+ "model.layers.11.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
36
+ "model.layers.11.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
37
+ "model.layers.11.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
38
+ "model.layers.11.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
39
+ "model.layers.11.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
40
+ "model.layers.11.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
41
+ "model.layers.11.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
42
+ "model.layers.11.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
43
+ "model.layers.11.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
44
+ "model.layers.12.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
45
+ "model.layers.12.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
46
+ "model.layers.12.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
47
+ "model.layers.12.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
48
+ "model.layers.12.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
49
+ "model.layers.12.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
50
+ "model.layers.12.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
51
+ "model.layers.12.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
52
+ "model.layers.12.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
53
+ "model.layers.13.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
54
+ "model.layers.13.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
55
+ "model.layers.13.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
56
+ "model.layers.13.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
57
+ "model.layers.13.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
58
+ "model.layers.13.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
59
+ "model.layers.13.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
60
+ "model.layers.13.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
61
+ "model.layers.13.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
62
+ "model.layers.14.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
63
+ "model.layers.14.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
64
+ "model.layers.14.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
65
+ "model.layers.14.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
66
+ "model.layers.14.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
67
+ "model.layers.14.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
68
+ "model.layers.14.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
69
+ "model.layers.14.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
70
+ "model.layers.14.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
71
+ "model.layers.15.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
72
+ "model.layers.15.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
73
+ "model.layers.15.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
74
+ "model.layers.15.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
75
+ "model.layers.15.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
76
+ "model.layers.15.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
77
+ "model.layers.15.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
78
+ "model.layers.15.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
79
+ "model.layers.15.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
80
+ "model.layers.16.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
81
+ "model.layers.16.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
82
+ "model.layers.16.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
83
+ "model.layers.16.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
84
+ "model.layers.16.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
85
+ "model.layers.16.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
86
+ "model.layers.16.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
87
+ "model.layers.16.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
88
+ "model.layers.16.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
89
+ "model.layers.17.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
90
+ "model.layers.17.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
91
+ "model.layers.17.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
92
+ "model.layers.17.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
93
+ "model.layers.17.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
94
+ "model.layers.17.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
95
+ "model.layers.17.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
96
+ "model.layers.17.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
97
+ "model.layers.17.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
98
+ "model.layers.18.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
99
+ "model.layers.18.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
100
+ "model.layers.18.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
101
+ "model.layers.18.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
102
+ "model.layers.18.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
103
+ "model.layers.18.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
104
+ "model.layers.18.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
105
+ "model.layers.18.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
106
+ "model.layers.18.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
107
+ "model.layers.19.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
108
+ "model.layers.19.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
109
+ "model.layers.19.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
110
+ "model.layers.19.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
111
+ "model.layers.19.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
112
+ "model.layers.19.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
113
+ "model.layers.19.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
114
+ "model.layers.19.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
115
+ "model.layers.19.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
116
+ "model.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
117
+ "model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
118
+ "model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
119
+ "model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
120
+ "model.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
121
+ "model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
122
+ "model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
123
+ "model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
124
+ "model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
125
+ "model.layers.20.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
126
+ "model.layers.20.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
127
+ "model.layers.20.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
128
+ "model.layers.20.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
129
+ "model.layers.20.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
130
+ "model.layers.20.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
131
+ "model.layers.20.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
132
+ "model.layers.20.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
133
+ "model.layers.20.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
134
+ "model.layers.21.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
135
+ "model.layers.21.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
136
+ "model.layers.21.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
137
+ "model.layers.21.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
138
+ "model.layers.21.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
139
+ "model.layers.21.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
140
+ "model.layers.21.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
141
+ "model.layers.21.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
142
+ "model.layers.21.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
143
+ "model.layers.22.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
144
+ "model.layers.22.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
145
+ "model.layers.22.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
146
+ "model.layers.22.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
147
+ "model.layers.22.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
148
+ "model.layers.22.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
149
+ "model.layers.22.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
150
+ "model.layers.22.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
151
+ "model.layers.22.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
152
+ "model.layers.23.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
153
+ "model.layers.23.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
154
+ "model.layers.23.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
155
+ "model.layers.23.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
156
+ "model.layers.23.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
157
+ "model.layers.23.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
158
+ "model.layers.23.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
159
+ "model.layers.23.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
160
+ "model.layers.23.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
161
+ "model.layers.24.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
162
+ "model.layers.24.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
163
+ "model.layers.24.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
164
+ "model.layers.24.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
165
+ "model.layers.24.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
166
+ "model.layers.24.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
167
+ "model.layers.24.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
168
+ "model.layers.24.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
169
+ "model.layers.24.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
170
+ "model.layers.25.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
171
+ "model.layers.25.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
172
+ "model.layers.25.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
173
+ "model.layers.25.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
174
+ "model.layers.25.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
175
+ "model.layers.25.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
176
+ "model.layers.25.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
177
+ "model.layers.25.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
178
+ "model.layers.25.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
179
+ "model.layers.26.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
180
+ "model.layers.26.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
181
+ "model.layers.26.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
182
+ "model.layers.26.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
183
+ "model.layers.26.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
184
+ "model.layers.26.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
185
+ "model.layers.26.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
186
+ "model.layers.26.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
187
+ "model.layers.26.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
188
+ "model.layers.27.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
189
+ "model.layers.27.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
190
+ "model.layers.27.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
191
+ "model.layers.27.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
192
+ "model.layers.27.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
193
+ "model.layers.27.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
194
+ "model.layers.27.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
195
+ "model.layers.27.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
196
+ "model.layers.27.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
197
+ "model.layers.28.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
198
+ "model.layers.28.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
199
+ "model.layers.28.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
200
+ "model.layers.28.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
201
+ "model.layers.28.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
202
+ "model.layers.28.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
203
+ "model.layers.28.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
204
+ "model.layers.28.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
205
+ "model.layers.28.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
206
+ "model.layers.29.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
207
+ "model.layers.29.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
208
+ "model.layers.29.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
209
+ "model.layers.29.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
210
+ "model.layers.29.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
211
+ "model.layers.29.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
212
+ "model.layers.29.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
213
+ "model.layers.29.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
214
+ "model.layers.29.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
215
+ "model.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
216
+ "model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
217
+ "model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
218
+ "model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
219
+ "model.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
220
+ "model.layers.3.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
221
+ "model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
222
+ "model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
223
+ "model.layers.3.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
224
+ "model.layers.30.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
225
+ "model.layers.30.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
226
+ "model.layers.30.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
227
+ "model.layers.30.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
228
+ "model.layers.30.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
229
+ "model.layers.30.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
230
+ "model.layers.30.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
231
+ "model.layers.30.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
232
+ "model.layers.30.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
233
+ "model.layers.31.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
234
+ "model.layers.31.mlp.down_proj.weight": "pytorch_model-00002-of-00002.bin",
235
+ "model.layers.31.mlp.gate_proj.weight": "pytorch_model-00002-of-00002.bin",
236
+ "model.layers.31.mlp.up_proj.weight": "pytorch_model-00002-of-00002.bin",
237
+ "model.layers.31.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
238
+ "model.layers.31.self_attn.k_proj.weight": "pytorch_model-00002-of-00002.bin",
239
+ "model.layers.31.self_attn.o_proj.weight": "pytorch_model-00002-of-00002.bin",
240
+ "model.layers.31.self_attn.q_proj.weight": "pytorch_model-00002-of-00002.bin",
241
+ "model.layers.31.self_attn.v_proj.weight": "pytorch_model-00002-of-00002.bin",
242
+ "model.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
243
+ "model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
244
+ "model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
245
+ "model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
246
+ "model.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
247
+ "model.layers.4.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
248
+ "model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
249
+ "model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
250
+ "model.layers.4.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
251
+ "model.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
252
+ "model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
253
+ "model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
254
+ "model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
255
+ "model.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
256
+ "model.layers.5.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
257
+ "model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
258
+ "model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
259
+ "model.layers.5.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
260
+ "model.layers.6.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
261
+ "model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
262
+ "model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
263
+ "model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
264
+ "model.layers.6.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
265
+ "model.layers.6.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
266
+ "model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
267
+ "model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
268
+ "model.layers.6.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
269
+ "model.layers.7.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
270
+ "model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
271
+ "model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
272
+ "model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
273
+ "model.layers.7.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
274
+ "model.layers.7.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
275
+ "model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
276
+ "model.layers.7.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
277
+ "model.layers.7.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
278
+ "model.layers.8.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
279
+ "model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
280
+ "model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
281
+ "model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
282
+ "model.layers.8.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
283
+ "model.layers.8.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
284
+ "model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
285
+ "model.layers.8.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
286
+ "model.layers.8.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
287
+ "model.layers.9.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
288
+ "model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
289
+ "model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
290
+ "model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
291
+ "model.layers.9.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
292
+ "model.layers.9.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
293
+ "model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
294
+ "model.layers.9.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
295
+ "model.layers.9.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
296
+ "model.norm.weight": "pytorch_model-00002-of-00002.bin"
297
+ }
298
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "unk_token": "<unk>"
5
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
3
+ size 493443
tokenizer_config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "additional_special_tokens": [],
31
+ "bos_token": "<s>",
32
+ "clean_up_tokenization_spaces": false,
33
+ "eos_token": "</s>",
34
+ "legacy": true,
35
+ "model_max_length": 1000000000000000019884624838656,
36
+ "pad_token": null,
37
+ "sp_model_kwargs": {},
38
+ "spaces_between_special_tokens": false,
39
+ "tokenizer_class": "LlamaTokenizer",
40
+ "unk_token": "<unk>",
41
+ "use_default_system_prompt": false,
42
+ "chat_template": "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"
43
+ }