Prakamya commited on
Commit
fc00151
·
verified ·
1 Parent(s): 43e8179

Upload InstellaForCausalLM

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "InstellaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "modeling_instella.InstellaConfig",
9
+ "AutoModelForCausalLM": "modeling_instella.InstellaForCausalLM"
10
+ },
11
+ "bos_token_id": 0,
12
+ "eos_token_id": 0,
13
+ "hidden_act": "silu",
14
+ "hidden_size": 2560,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 6912,
17
+ "max_position_embeddings": 4096,
18
+ "model_type": "instella",
19
+ "num_attention_heads": 32,
20
+ "num_hidden_layers": 36,
21
+ "num_key_value_heads": 32,
22
+ "pad_token_id": 1,
23
+ "rms_norm_eps": 1e-05,
24
+ "rope_scaling": null,
25
+ "rope_theta": 10000.0,
26
+ "tie_word_embeddings": false,
27
+ "torch_dtype": "bfloat16",
28
+ "transformers_version": "4.48.0",
29
+ "use_cache": true,
30
+ "vocab_size": 50304
31
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "eos_token_id": 0,
5
+ "pad_token_id": 1,
6
+ "transformers_version": "4.48.0"
7
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36c4376ac11e513036112983a4bc001fea6711f4b6b38efd50add5017dfe2106
3
+ size 4980722864
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5988369acdd4b5a7d5caab3eeab31bfa180f15398a199209b90178a45e80299b
3
+ size 1244675056
model.safetensors.index.json ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 6225351680
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.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.10.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.10.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.10.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
39
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.11.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.11.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.11.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.11.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
51
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
53
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.12.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.12.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.12.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.12.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
62
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.13.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.13.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.13.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
69
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.13.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
75
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.14.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.14.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.14.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
80
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.14.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.15.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.15.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.15.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
91
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.15.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.16.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.16.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.16.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.16.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
107
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
108
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
109
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.17.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
111
+ "model.layers.17.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.17.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.17.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
116
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.18.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.18.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.18.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
125
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.18.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
127
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
129
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
130
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
132
+ "model.layers.19.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.19.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
134
+ "model.layers.19.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
135
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.19.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
138
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
139
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
140
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
141
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
143
+ "model.layers.2.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
144
+ "model.layers.2.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
145
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
146
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
147
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
152
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
153
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
154
+ "model.layers.20.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
155
+ "model.layers.20.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
156
+ "model.layers.20.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
157
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
158
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
159
+ "model.layers.20.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
160
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
161
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
162
+ "model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
163
+ "model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
164
+ "model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
165
+ "model.layers.21.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
166
+ "model.layers.21.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
167
+ "model.layers.21.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
168
+ "model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
169
+ "model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
170
+ "model.layers.21.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
171
+ "model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
172
+ "model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
173
+ "model.layers.22.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
174
+ "model.layers.22.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
175
+ "model.layers.22.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
176
+ "model.layers.22.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
177
+ "model.layers.22.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
178
+ "model.layers.22.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
179
+ "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
180
+ "model.layers.22.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
181
+ "model.layers.22.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
182
+ "model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
183
+ "model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
184
+ "model.layers.23.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
185
+ "model.layers.23.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
186
+ "model.layers.23.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
187
+ "model.layers.23.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
188
+ "model.layers.23.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
189
+ "model.layers.23.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
190
+ "model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
191
+ "model.layers.23.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.23.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
193
+ "model.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
194
+ "model.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
195
+ "model.layers.24.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
196
+ "model.layers.24.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
197
+ "model.layers.24.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
198
+ "model.layers.24.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
199
+ "model.layers.24.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
200
+ "model.layers.24.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
201
+ "model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
202
+ "model.layers.24.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
203
+ "model.layers.24.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
204
+ "model.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
205
+ "model.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
206
+ "model.layers.25.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
207
+ "model.layers.25.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
208
+ "model.layers.25.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
209
+ "model.layers.25.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
210
+ "model.layers.25.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
211
+ "model.layers.25.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
212
+ "model.layers.25.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
213
+ "model.layers.25.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
214
+ "model.layers.25.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
215
+ "model.layers.25.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
216
+ "model.layers.25.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
217
+ "model.layers.26.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
218
+ "model.layers.26.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
219
+ "model.layers.26.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
220
+ "model.layers.26.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
221
+ "model.layers.26.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
222
+ "model.layers.26.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
223
+ "model.layers.26.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
224
+ "model.layers.26.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
225
+ "model.layers.26.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
226
+ "model.layers.26.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
227
+ "model.layers.26.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
228
+ "model.layers.27.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
229
+ "model.layers.27.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
230
+ "model.layers.27.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
231
+ "model.layers.27.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
232
+ "model.layers.27.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
233
+ "model.layers.27.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
234
+ "model.layers.27.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
235
+ "model.layers.27.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
236
+ "model.layers.27.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
237
+ "model.layers.27.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
238
+ "model.layers.27.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
239
+ "model.layers.28.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
240
+ "model.layers.28.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
241
+ "model.layers.28.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
242
+ "model.layers.28.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
243
+ "model.layers.28.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
244
+ "model.layers.28.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
245
+ "model.layers.28.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
246
+ "model.layers.28.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
247
+ "model.layers.28.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
248
+ "model.layers.28.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
249
+ "model.layers.28.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
250
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
251
+ "model.layers.29.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
252
+ "model.layers.29.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
253
+ "model.layers.29.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
254
+ "model.layers.29.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
255
+ "model.layers.29.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
256
+ "model.layers.29.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
257
+ "model.layers.29.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
258
+ "model.layers.29.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
259
+ "model.layers.29.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
260
+ "model.layers.29.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
261
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
262
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.3.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.3.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
267
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
269
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
270
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
271
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
272
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
273
+ "model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
274
+ "model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
275
+ "model.layers.30.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
276
+ "model.layers.30.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
277
+ "model.layers.30.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
278
+ "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
279
+ "model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
280
+ "model.layers.30.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
281
+ "model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
282
+ "model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
283
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
284
+ "model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
285
+ "model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
286
+ "model.layers.31.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
287
+ "model.layers.31.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
288
+ "model.layers.31.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
289
+ "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
290
+ "model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
291
+ "model.layers.31.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
292
+ "model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
293
+ "model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
294
+ "model.layers.32.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
295
+ "model.layers.32.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
296
+ "model.layers.32.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
297
+ "model.layers.32.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
298
+ "model.layers.32.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
299
+ "model.layers.32.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
300
+ "model.layers.32.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
301
+ "model.layers.32.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
302
+ "model.layers.32.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
303
+ "model.layers.32.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
304
+ "model.layers.32.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
305
+ "model.layers.33.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
306
+ "model.layers.33.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
307
+ "model.layers.33.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
308
+ "model.layers.33.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
309
+ "model.layers.33.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
310
+ "model.layers.33.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
311
+ "model.layers.33.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
312
+ "model.layers.33.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
313
+ "model.layers.33.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
314
+ "model.layers.33.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
315
+ "model.layers.33.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
316
+ "model.layers.34.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
317
+ "model.layers.34.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
318
+ "model.layers.34.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
319
+ "model.layers.34.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
320
+ "model.layers.34.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
321
+ "model.layers.34.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
322
+ "model.layers.34.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
323
+ "model.layers.34.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
324
+ "model.layers.34.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
325
+ "model.layers.34.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
326
+ "model.layers.34.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
327
+ "model.layers.35.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
328
+ "model.layers.35.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
329
+ "model.layers.35.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
330
+ "model.layers.35.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
331
+ "model.layers.35.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
332
+ "model.layers.35.self_attn.k_norm.weight": "model-00002-of-00002.safetensors",
333
+ "model.layers.35.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
334
+ "model.layers.35.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
335
+ "model.layers.35.self_attn.q_norm.weight": "model-00002-of-00002.safetensors",
336
+ "model.layers.35.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
337
+ "model.layers.35.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
338
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
339
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
340
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
341
+ "model.layers.4.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
342
+ "model.layers.4.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
343
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
344
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
345
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
346
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
347
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
348
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
349
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
350
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
351
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
352
+ "model.layers.5.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
353
+ "model.layers.5.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
354
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
355
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
356
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
357
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
358
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
359
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
360
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
361
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
362
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
363
+ "model.layers.6.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
364
+ "model.layers.6.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
365
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
366
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
367
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
368
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
369
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
370
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
371
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
372
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
373
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
374
+ "model.layers.7.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
375
+ "model.layers.7.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
376
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
377
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
378
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
379
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
380
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
381
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
382
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
383
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
384
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
385
+ "model.layers.8.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
386
+ "model.layers.8.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
387
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
388
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
389
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
390
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
391
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
392
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
393
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
394
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
395
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
396
+ "model.layers.9.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
397
+ "model.layers.9.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
398
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
399
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
400
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
401
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
402
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
403
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
404
+ "model.norm.weight": "model-00002-of-00002.safetensors"
405
+ }
406
+ }
modeling_instella.py ADDED
@@ -0,0 +1,1251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This code has been adapter from the Olmo2 codebase and updated to match the Instella model details.
2
+ # https://github.com/huggingface/transformers/tree/v4.47.1/src/transformers/models/olmo2
3
+
4
+ import math
5
+ from typing import List, Optional, Tuple, Union
6
+
7
+ import torch
8
+ from torch import nn
9
+
10
+ from transformers.activations import ACT2FN
11
+ from transformers.cache_utils import Cache, DynamicCache, StaticCache
12
+ from transformers.generation import GenerationMixin
13
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
14
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
15
+ from transformers.modeling_utils import PreTrainedModel
16
+ from transformers.utils import (
17
+ add_start_docstrings,
18
+ add_start_docstrings_to_model_forward,
19
+ is_flash_attn_2_available,
20
+ is_flash_attn_greater_or_equal_2_10,
21
+ logging,
22
+ replace_return_docstrings,
23
+ )
24
+
25
+ """
26
+ Instella configuration
27
+ """
28
+
29
+ from transformers import AutoConfig, PretrainedConfig
30
+
31
+ class InstellaConfig(PretrainedConfig):
32
+ r"""
33
+ This is the configuration class to store the configuration of a [`Instella2Model`]. It is used to instantiate an Instella2
34
+ model according to the specified arguments, defining the model architecture.
35
+
36
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
37
+ documentation from [`PretrainedConfig`] for more information.
38
+
39
+
40
+ Args:
41
+ vocab_size (`int`, *optional*, defaults to 50304):
42
+ Vocabulary size of the Instella2 model. Defines the number of different tokens that can be represented by the
43
+ `inputs_ids` passed when calling [`Instella2Model`]
44
+ hidden_size (`int`, *optional*, defaults to 4096):
45
+ Dimension of the hidden representations.
46
+ intermediate_size (`int`, *optional*, defaults to 11008):
47
+ Dimension of the MLP representations.
48
+ num_hidden_layers (`int`, *optional*, defaults to 32):
49
+ Number of hidden layers in the Transformer decoder.
50
+ num_attention_heads (`int`, *optional*, defaults to 32):
51
+ Number of attention heads for each attention layer in the Transformer decoder.
52
+ num_key_value_heads (`int`, *optional*):
53
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
54
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
55
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
56
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
57
+ by meanpooling all the original heads within that group. For more details checkout [this
58
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
59
+ `num_attention_heads`.
60
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
61
+ The non-linear activation function (function or string) in the decoder.
62
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
63
+ The maximum sequence length that this model might ever be used with.
64
+ initializer_range (`float`, *optional*, defaults to 0.02):
65
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
66
+ use_cache (`bool`, *optional*, defaults to `True`):
67
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
68
+ relevant if `config.is_decoder=True`.
69
+ pad_token_id (`int`, *optional*, defaults to 1):
70
+ Padding token id.
71
+ bos_token_id (`int`, *optional*):
72
+ Beginning of stream token id.
73
+ eos_token_id (`int`, *optional*, defaults to 50279):
74
+ End of stream token id.
75
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
76
+ Whether to tie weight embeddings
77
+ rope_theta (`float`, *optional*, defaults to 10000.0):
78
+ The base period of the RoPE embeddings.
79
+ rope_scaling (`Dict`, *optional*):
80
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
81
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
82
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
83
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
84
+ these scaling strategies behave:
85
+ https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
86
+ experimental feature, subject to breaking API changes in future versions.
87
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
88
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
89
+ attention_dropout (`float`, *optional*, defaults to 0.0):
90
+ The dropout ratio for the attention probabilities.
91
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
92
+ The epsilon used by the rms normalization layers.
93
+
94
+ ```python
95
+ >>> from transformers import Instella2Model, Instella2Config
96
+
97
+ >>> configuration = Instella2Config()
98
+ >>> model = Instella2Model(configuration)
99
+
100
+ >>> # Accessing the model configuration
101
+ >>> configuration = model.config
102
+ ```
103
+ """
104
+
105
+ model_type = "instella"
106
+ keys_to_ignore_at_inference = ["past_key_values"]
107
+
108
+ def __init__(
109
+ self,
110
+ vocab_size=50304,
111
+ hidden_size=4096,
112
+ intermediate_size=11008,
113
+ num_hidden_layers=32,
114
+ num_attention_heads=32,
115
+ num_key_value_heads=None,
116
+ hidden_act="silu",
117
+ max_position_embeddings=2048,
118
+ initializer_range=0.02,
119
+ use_cache=True,
120
+ pad_token_id=1,
121
+ bos_token_id=None,
122
+ eos_token_id=50279,
123
+ tie_word_embeddings=False,
124
+ rope_theta=10000.0,
125
+ rope_scaling=None,
126
+ attention_bias=False,
127
+ attention_dropout=0.0,
128
+ rms_norm_eps=1e-5,
129
+ **kwargs,
130
+ ):
131
+ super().__init__(
132
+ pad_token_id=pad_token_id,
133
+ bos_token_id=bos_token_id,
134
+ eos_token_id=eos_token_id,
135
+ tie_word_embeddings=tie_word_embeddings,
136
+ **kwargs,
137
+ )
138
+ self.vocab_size = vocab_size
139
+ self.max_position_embeddings = max_position_embeddings
140
+ self.hidden_size = hidden_size
141
+ self.intermediate_size = intermediate_size
142
+ self.num_hidden_layers = num_hidden_layers
143
+ self.num_attention_heads = num_attention_heads
144
+
145
+ # for backward compatibility
146
+ if num_key_value_heads is None:
147
+ num_key_value_heads = num_attention_heads
148
+
149
+ self.num_key_value_heads = num_key_value_heads
150
+ self.hidden_act = hidden_act
151
+ self.initializer_range = initializer_range
152
+ self.use_cache = use_cache
153
+ self.rope_theta = rope_theta
154
+ self.rope_scaling = rope_scaling
155
+ self._rope_scaling_validation()
156
+ self.attention_bias = attention_bias
157
+ self.attention_dropout = attention_dropout
158
+
159
+ self.rms_norm_eps = rms_norm_eps
160
+
161
+ def _rope_scaling_validation(self):
162
+ """
163
+ Validate the `rope_scaling` configuration.
164
+ """
165
+ if self.rope_scaling is None:
166
+ return
167
+
168
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
169
+ raise ValueError(
170
+ "`rope_scaling` must be a dictionary with two fields, `type` and `factor`, " f"got {self.rope_scaling}"
171
+ )
172
+ rope_scaling_type = self.rope_scaling.get("type", None)
173
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
174
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
175
+ raise ValueError(
176
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
177
+ )
178
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
179
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
180
+
181
+
182
+ if is_flash_attn_2_available():
183
+ from transformers.modeling_flash_attention_utils import _flash_attention_forward
184
+
185
+
186
+ logger = logging.get_logger(__name__)
187
+
188
+ _CONFIG_FOR_DOC = "InstellaConfig"
189
+
190
+
191
+ class InstellaRMSNorm(nn.Module):
192
+ def __init__(self, hidden_size, eps=1e-6):
193
+ """
194
+ InstellaRMSNorm is equivalent to T5LayerNorm
195
+ """
196
+ super().__init__()
197
+ self.weight = nn.Parameter(torch.ones(hidden_size))
198
+ self.variance_epsilon = eps
199
+
200
+ def forward(self, hidden_states):
201
+ input_dtype = hidden_states.dtype
202
+ hidden_states = hidden_states.to(torch.float32)
203
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
204
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
205
+ return self.weight * hidden_states.to(input_dtype)
206
+
207
+ def extra_repr(self):
208
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
209
+
210
+
211
+ # copied from transformers.models.llama.modeling_llama.LlamaRotaryEmbedding with Llama->Instella
212
+ # TODO(joao): add me back asap :)
213
+ class InstellaRotaryEmbedding(nn.Module):
214
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
215
+ super().__init__()
216
+ self.scaling_factor = scaling_factor
217
+ self.dim = dim
218
+ self.max_position_embeddings = max_position_embeddings
219
+ self.base = base
220
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64).float().to(device) / self.dim))
221
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
222
+ # For BC we register cos and sin cached
223
+ self.max_seq_len_cached = max_position_embeddings
224
+
225
+ @torch.no_grad()
226
+ def forward(self, x, position_ids):
227
+ # x: [bs, num_attention_heads, seq_len, head_size]
228
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
229
+ position_ids_expanded = position_ids[:, None, :].float()
230
+ # Force float32 since bfloat16 loses precision on long contexts
231
+ # See https://github.com/huggingface/transformers/pull/29285
232
+ device_type = x.device.type
233
+ device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
234
+ with torch.autocast(device_type=device_type, enabled=False):
235
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
236
+ emb = torch.cat((freqs, freqs), dim=-1)
237
+ cos = emb.cos()
238
+ sin = emb.sin()
239
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
240
+
241
+
242
+ # copied from transformers.models.llama.modeling_llama.LlamaLinearScalingRotaryEmbedding with Llama->Instella
243
+ # TODO(joao): add me back asap :)
244
+ class InstellaLinearScalingRotaryEmbedding(InstellaRotaryEmbedding):
245
+ """InstellaRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
246
+
247
+ def forward(self, x, position_ids):
248
+ # difference to the original RoPE: a scaling factor is aplied to the position ids
249
+ position_ids = position_ids.float() / self.scaling_factor
250
+ cos, sin = super().forward(x, position_ids)
251
+ return cos, sin
252
+
253
+
254
+ # copied from transformers.models.llama.modeling_llama.LlamaDynamicNTKScalingRotaryEmbedding with Llama->Instella
255
+ # TODO(joao): add me back asap :)
256
+ class InstellaDynamicNTKScalingRotaryEmbedding(InstellaRotaryEmbedding):
257
+ """InstellaRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
258
+
259
+ def forward(self, x, position_ids):
260
+ # difference to the original RoPE: inv_freq is recomputed when the sequence length > original length
261
+ seq_len = torch.max(position_ids) + 1
262
+ if seq_len > self.max_position_embeddings:
263
+ base = self.base * (
264
+ (self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
265
+ ) ** (self.dim / (self.dim - 2))
266
+ inv_freq = 1.0 / (
267
+ base ** (torch.arange(0, self.dim, 2, dtype=torch.int64).float().to(x.device) / self.dim)
268
+ )
269
+ self.register_buffer("inv_freq", inv_freq, persistent=False) # TODO joao: this may break with compilation
270
+
271
+ cos, sin = super().forward(x, position_ids)
272
+ return cos, sin
273
+
274
+
275
+ def rotate_half(x):
276
+ """Rotates half the hidden dims of the input."""
277
+ x1 = x[..., : x.shape[-1] // 2]
278
+ x2 = x[..., x.shape[-1] // 2 :]
279
+ return torch.cat((-x2, x1), dim=-1)
280
+
281
+
282
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
283
+ """Applies Rotary Position Embedding to the query and key tensors.
284
+
285
+ Args:
286
+ q (`torch.Tensor`): The query tensor.
287
+ k (`torch.Tensor`): The key tensor.
288
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
289
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
290
+ position_ids (`torch.Tensor`, *optional*):
291
+ Deprecated and unused.
292
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
293
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
294
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
295
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
296
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
297
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
298
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
299
+ Returns:
300
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
301
+ """
302
+ cos = cos.unsqueeze(unsqueeze_dim)
303
+ sin = sin.unsqueeze(unsqueeze_dim)
304
+ q_embed = (q * cos) + (rotate_half(q) * sin)
305
+ k_embed = (k * cos) + (rotate_half(k) * sin)
306
+ return q_embed, k_embed
307
+
308
+
309
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
310
+ """
311
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
312
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
313
+ """
314
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
315
+ if n_rep == 1:
316
+ return hidden_states
317
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
318
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
319
+
320
+
321
+ class InstellaAttention(nn.Module):
322
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
323
+
324
+ # copied from transformers.models.llama.modeling_llama.LlamaAttention.__init__ with Llama->Instella
325
+ # TODO(joao): add me back asap :)
326
+ def __init__(self, config: InstellaConfig, layer_idx: Optional[int] = None):
327
+ super().__init__()
328
+ self.config = config
329
+ self.layer_idx = layer_idx
330
+ if layer_idx is None:
331
+ logger.warning_once(
332
+ f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
333
+ "lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
334
+ "when creating this class."
335
+ )
336
+
337
+ self.attention_dropout = config.attention_dropout
338
+ self.hidden_size = config.hidden_size
339
+ self.num_heads = config.num_attention_heads
340
+ self.head_dim = self.hidden_size // self.num_heads
341
+ self.num_key_value_heads = config.num_key_value_heads
342
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
343
+ self.max_position_embeddings = config.max_position_embeddings
344
+ self.rope_theta = config.rope_theta
345
+ self.is_causal = True
346
+
347
+ if (self.head_dim * self.num_heads) != self.hidden_size:
348
+ raise ValueError(
349
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
350
+ f" and `num_heads`: {self.num_heads})."
351
+ )
352
+
353
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias)
354
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
355
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
356
+ self.o_proj = nn.Linear(self.hidden_size, self.hidden_size, bias=config.attention_bias)
357
+ self._init_rope()
358
+ self.q_norm = InstellaRMSNorm(self.num_heads * self.head_dim, config.rms_norm_eps)
359
+ self.k_norm = InstellaRMSNorm(self.num_key_value_heads * self.head_dim, config.rms_norm_eps)
360
+
361
+ def _init_rope(self):
362
+ if self.config.rope_scaling is None:
363
+ self.rotary_emb = InstellaRotaryEmbedding(
364
+ self.head_dim,
365
+ max_position_embeddings=self.max_position_embeddings,
366
+ base=self.rope_theta,
367
+ )
368
+ else:
369
+ scaling_type = self.config.rope_scaling["type"]
370
+ scaling_factor = self.config.rope_scaling["factor"]
371
+ if scaling_type == "linear":
372
+ self.rotary_emb = InstellaLinearScalingRotaryEmbedding(
373
+ self.head_dim,
374
+ max_position_embeddings=self.max_position_embeddings,
375
+ scaling_factor=scaling_factor,
376
+ base=self.rope_theta,
377
+ )
378
+ elif scaling_type == "dynamic":
379
+ self.rotary_emb = InstellaDynamicNTKScalingRotaryEmbedding(
380
+ self.head_dim,
381
+ max_position_embeddings=self.max_position_embeddings,
382
+ scaling_factor=scaling_factor,
383
+ base=self.rope_theta,
384
+ )
385
+ else:
386
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
387
+
388
+ def forward(
389
+ self,
390
+ hidden_states: torch.Tensor,
391
+ attention_mask: Optional[torch.Tensor] = None,
392
+ position_ids: Optional[torch.LongTensor] = None,
393
+ past_key_value: Optional[Cache] = None,
394
+ output_attentions: bool = False,
395
+ use_cache: bool = False,
396
+ cache_position: Optional[torch.LongTensor] = None,
397
+ **kwargs,
398
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
399
+ bsz, q_len, _ = hidden_states.size()
400
+
401
+ query_states = self.q_norm(self.q_proj(hidden_states))
402
+ key_states = self.k_norm(self.k_proj(hidden_states))
403
+ value_states = self.v_proj(hidden_states)
404
+
405
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
406
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
407
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
408
+
409
+ cos, sin = self.rotary_emb(value_states, position_ids)
410
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
411
+
412
+ if past_key_value is not None:
413
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
414
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
415
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
416
+
417
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
418
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
419
+
420
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
421
+
422
+ if attention_mask is not None: # no matter the length, we just slice it
423
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
424
+ attn_weights = attn_weights + causal_mask
425
+
426
+ # upcast attention to fp32
427
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
428
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
429
+ attn_output = torch.matmul(attn_weights, value_states)
430
+
431
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
432
+ raise ValueError(
433
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
434
+ f" {attn_output.size()}"
435
+ )
436
+
437
+ attn_output = attn_output.transpose(1, 2).contiguous()
438
+
439
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
440
+
441
+ attn_output = self.o_proj(attn_output)
442
+
443
+ if not output_attentions:
444
+ attn_weights = None
445
+
446
+ return attn_output, attn_weights, past_key_value
447
+
448
+
449
+ class InstellaFlashAttention2(InstellaAttention):
450
+ """
451
+ Instella flash attention module. This module inherits from `InstellaAttention` as the weights of the module stays
452
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
453
+ flash attention and deal with padding tokens in case the input contains any of them.
454
+
455
+ Instella flash attention module. This module inherits from `InstellaAttention` as the weights of the module stays
456
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
457
+ flash attention and deal with padding tokens in case the input contains any of them.
458
+ """
459
+
460
+ def __init__(self, *args, **kwargs):
461
+ super().__init__(*args, **kwargs)
462
+
463
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
464
+ # flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
465
+ # Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
466
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
467
+
468
+ def forward(
469
+ self,
470
+ hidden_states: torch.Tensor,
471
+ attention_mask: Optional[torch.LongTensor] = None,
472
+ position_ids: Optional[torch.LongTensor] = None,
473
+ past_key_value: Optional[Cache] = None,
474
+ output_attentions: bool = False,
475
+ use_cache: bool = False,
476
+ cache_position: Optional[torch.LongTensor] = None,
477
+ **kwargs,
478
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
479
+ output_attentions = False
480
+
481
+ bsz, q_len, _ = hidden_states.size()
482
+
483
+ query_states = self.q_norm(self.q_proj(hidden_states))
484
+ key_states = self.k_norm(self.k_proj(hidden_states))
485
+ value_states = self.v_proj(hidden_states)
486
+
487
+ # Flash attention requires the input to have the shape
488
+ # batch_size x seq_length x head_dim x hidden_dim
489
+ # therefore we just need to keep the original shape
490
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
491
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
492
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
493
+
494
+ cos, sin = self.rotary_emb(value_states, position_ids)
495
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
496
+
497
+ if past_key_value is not None:
498
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
499
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
500
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
501
+
502
+ # TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
503
+ # to be able to avoid many of these transpose/reshape/view.
504
+ query_states = query_states.transpose(1, 2)
505
+ key_states = key_states.transpose(1, 2)
506
+ value_states = value_states.transpose(1, 2)
507
+
508
+ dropout_rate = self.attention_dropout if self.training else 0.0
509
+
510
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
511
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
512
+ # cast them back in the correct dtype just to be sure everything works as expected.
513
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
514
+ # in fp32. (InstellaRMSNorm handles it correctly)
515
+
516
+ input_dtype = query_states.dtype
517
+ if input_dtype == torch.float32:
518
+ if torch.is_autocast_enabled():
519
+ target_dtype = torch.get_autocast_gpu_dtype()
520
+ # Handle the case where the model is quantized
521
+ elif hasattr(self.config, "_pre_quantization_dtype"):
522
+ target_dtype = self.config._pre_quantization_dtype
523
+ else:
524
+ target_dtype = self.q_proj.weight.dtype
525
+
526
+ logger.warning_once(
527
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
528
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
529
+ f" {target_dtype}."
530
+ )
531
+
532
+ query_states = query_states.to(target_dtype)
533
+ key_states = key_states.to(target_dtype)
534
+ value_states = value_states.to(target_dtype)
535
+
536
+ attn_output = _flash_attention_forward(
537
+ query_states,
538
+ key_states,
539
+ value_states,
540
+ attention_mask,
541
+ q_len,
542
+ position_ids=position_ids,
543
+ dropout=dropout_rate,
544
+ use_top_left_mask=self._flash_attn_uses_top_left_mask,
545
+ is_causal=self.is_causal,
546
+ )
547
+
548
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
549
+ attn_output = self.o_proj(attn_output)
550
+
551
+ if not output_attentions:
552
+ attn_weights = None
553
+
554
+ return attn_output, attn_weights, past_key_value
555
+
556
+
557
+ class InstellaSdpaAttention(InstellaAttention):
558
+ """
559
+ Instella attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
560
+ `InstellaAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
561
+ SDPA API.
562
+ """
563
+
564
+ # Adapted from InstellaAttention.forward
565
+ def forward(
566
+ self,
567
+ hidden_states: torch.Tensor,
568
+ attention_mask: Optional[torch.Tensor] = None,
569
+ position_ids: Optional[torch.LongTensor] = None,
570
+ past_key_value: Optional[Cache] = None,
571
+ output_attentions: bool = False,
572
+ use_cache: bool = False,
573
+ cache_position: Optional[torch.LongTensor] = None,
574
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
575
+ if output_attentions:
576
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
577
+ logger.warning_once(
578
+ "InstellaModel is using InstellaSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
579
+ '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.'
580
+ )
581
+ return super().forward(
582
+ hidden_states=hidden_states,
583
+ attention_mask=attention_mask,
584
+ position_ids=position_ids,
585
+ past_key_value=past_key_value,
586
+ output_attentions=output_attentions,
587
+ use_cache=use_cache,
588
+ cache_position=cache_position,
589
+ )
590
+ bsz, q_len, _ = hidden_states.size()
591
+ query_states = self.q_norm(self.q_proj(hidden_states))
592
+ key_states = self.k_norm(self.k_proj(hidden_states))
593
+ value_states = self.v_proj(hidden_states)
594
+
595
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
596
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
597
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
598
+ cos, sin = self.rotary_emb(value_states, position_ids)
599
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
600
+ if past_key_value is not None:
601
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
602
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
603
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
604
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
605
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
606
+ causal_mask = attention_mask
607
+ # if attention_mask is not None and cache_position is not None:
608
+ if attention_mask is not None:
609
+ causal_mask = causal_mask[:, :, :, : key_states.shape[-2]]
610
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
611
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
612
+ if query_states.device.type == "cuda" and causal_mask is not None:
613
+ query_states = query_states.contiguous()
614
+ key_states = key_states.contiguous()
615
+ value_states = value_states.contiguous()
616
+ # We dispatch to SDPA's Flash Attention or Efficient kernels via this `is_causal` if statement instead of an inline conditional assignment
617
+ # in SDPA to support both torch.compile's dynamic shapes and full graph options. An inline conditional prevents dynamic shapes from compiling.
618
+ is_causal = True if causal_mask is None and q_len > 1 else False
619
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
620
+ query_states,
621
+ key_states,
622
+ value_states,
623
+ attn_mask=causal_mask,
624
+ dropout_p=self.attention_dropout if self.training else 0.0,
625
+ is_causal=is_causal,
626
+ )
627
+ attn_output = attn_output.transpose(1, 2).contiguous()
628
+ attn_output = attn_output.view(bsz, q_len, self.hidden_size)
629
+ attn_output = self.o_proj(attn_output)
630
+ return attn_output, None, past_key_value
631
+
632
+
633
+ class InstellaMLP(nn.Module):
634
+ def __init__(self, config):
635
+ super().__init__()
636
+ self.config = config
637
+ self.hidden_size = config.hidden_size
638
+ self.intermediate_size = config.intermediate_size
639
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
640
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
641
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
642
+ self.act_fn = ACT2FN[config.hidden_act]
643
+
644
+ def forward(self, x):
645
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
646
+
647
+
648
+ Instella_ATTENTION_CLASSES = {
649
+ "eager": InstellaAttention,
650
+ "flash_attention_2": InstellaFlashAttention2,
651
+ "sdpa": InstellaSdpaAttention,
652
+ }
653
+
654
+
655
+ class InstellaDecoderLayer(nn.Module):
656
+ def __init__(self, config: InstellaConfig, layer_idx: int):
657
+ super().__init__()
658
+ self.hidden_size = config.hidden_size
659
+
660
+ self.self_attn = Instella_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
661
+
662
+ self.mlp = InstellaMLP(config)
663
+ self.pre_attention_layernorm = InstellaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
664
+ self.pre_feedforward_layernorm = InstellaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
665
+
666
+ # copied from transformers.models.llama.modeling_llama.LlamaDecoderLayer.forward
667
+ # TODO(joao): add me back asap :)
668
+ def forward(
669
+ self,
670
+ hidden_states: torch.Tensor,
671
+ attention_mask: Optional[torch.Tensor] = None,
672
+ position_ids: Optional[torch.LongTensor] = None,
673
+ past_key_value: Optional[Cache] = None,
674
+ output_attentions: Optional[bool] = False,
675
+ use_cache: Optional[bool] = False,
676
+ cache_position: Optional[torch.LongTensor] = None,
677
+ **kwargs,
678
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
679
+ """
680
+ Args:
681
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
682
+ attention_mask (`torch.FloatTensor`, *optional*):
683
+ attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
684
+ query_sequence_length, key_sequence_length)` if default attention is used.
685
+ output_attentions (`bool`, *optional*):
686
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
687
+ returned tensors for more detail.
688
+ use_cache (`bool`, *optional*):
689
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
690
+ (see `past_key_values`).
691
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
692
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
693
+ Indices depicting the position of the input sequence tokens in the sequence
694
+ kwargs (`dict`, *optional*):
695
+ Arbitrary kwargs to be ignored, used for FSDP and other methods that injects code
696
+ into the model
697
+ """
698
+ residual = hidden_states
699
+
700
+ # Self Attention
701
+ hidden_states = self.pre_attention_layernorm(hidden_states)
702
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
703
+ hidden_states=hidden_states,
704
+ attention_mask=attention_mask,
705
+ position_ids=position_ids,
706
+ past_key_value=past_key_value,
707
+ output_attentions=output_attentions,
708
+ use_cache=use_cache,
709
+ cache_position=cache_position,
710
+ **kwargs,
711
+ )
712
+ # hidden_states = self.post_attention_layernorm(hidden_states)
713
+ hidden_states = residual + hidden_states
714
+ # print(hidden_states)
715
+
716
+ # Fully Connected
717
+ residual = hidden_states
718
+ hidden_states = self.pre_feedforward_layernorm(hidden_states)
719
+ hidden_states = self.mlp(hidden_states)
720
+ # hidden_states = self.post_feedforward_layernorm(hidden_states)
721
+ hidden_states = residual + hidden_states
722
+ # print(hidden_states)
723
+
724
+ outputs = (hidden_states,)
725
+ if output_attentions:
726
+ outputs += (self_attn_weights,)
727
+ if use_cache:
728
+ outputs += (present_key_value,)
729
+ return outputs
730
+
731
+
732
+ Instella_START_DOCSTRING = r"""
733
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
734
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
735
+ etc.)
736
+
737
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
738
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
739
+ and behavior.
740
+
741
+ Parameters:
742
+ config ([`InstellaConfig`]):
743
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
744
+ load the weights associated with the model, only the configuration. Check out the
745
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
746
+ """
747
+
748
+
749
+ @add_start_docstrings(
750
+ "The bare Instella Model outputting raw hidden-states without any specific head on top.",
751
+ Instella_START_DOCSTRING,
752
+ )
753
+ class InstellaPreTrainedModel(PreTrainedModel):
754
+ config_class = InstellaConfig
755
+ base_model_prefix = "model"
756
+ supports_gradient_checkpointing = True
757
+ _no_split_modules = ["InstellaDecoderLayer"]
758
+ _skip_keys_device_placement = ["past_key_values"]
759
+ _supports_flash_attn_2 = True
760
+ _supports_sdpa = True
761
+ _supports_cache_class = True
762
+ _supports_quantized_cache = True
763
+ _supports_static_cache = True
764
+
765
+ def _init_weights(self, module):
766
+ std = self.config.initializer_range
767
+ if isinstance(module, nn.Linear):
768
+ module.weight.data.normal_(mean=0.0, std=std)
769
+ if module.bias is not None:
770
+ module.bias.data.zero_()
771
+ elif isinstance(module, nn.Embedding):
772
+ module.weight.data.normal_(mean=0.0, std=std)
773
+ if module.padding_idx is not None:
774
+ module.weight.data[module.padding_idx].zero_()
775
+
776
+
777
+ Instella_INPUTS_DOCSTRING = r"""
778
+ Args:
779
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
780
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
781
+ it.
782
+
783
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
784
+ [`PreTrainedTokenizer.__call__`] for details.
785
+
786
+ [What are input IDs?](../glossary#input-ids)
787
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
788
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
789
+
790
+ - 1 for tokens that are **not masked**,
791
+ - 0 for tokens that are **masked**.
792
+
793
+ [What are attention masks?](../glossary#attention-mask)
794
+
795
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
796
+ [`PreTrainedTokenizer.__call__`] for details.
797
+
798
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
799
+ `past_key_values`).
800
+
801
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
802
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
803
+ information on the default strategy.
804
+
805
+ - 1 indicates the head is **not masked**,
806
+ - 0 indicates the head is **masked**.
807
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
808
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
809
+ config.n_positions - 1]`.
810
+
811
+ [What are position IDs?](../glossary#position-ids)
812
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
813
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
814
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
815
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
816
+
817
+ Two formats are allowed:
818
+ - a [`~cache_utils.Cache`] instance, see our
819
+ [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache);
820
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
821
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
822
+ cache format.
823
+
824
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
825
+ legacy cache format will be returned.
826
+
827
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
828
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
829
+ of shape `(batch_size, sequence_length)`.
830
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
831
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
832
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
833
+ model's internal embedding lookup matrix.
834
+ use_cache (`bool`, *optional*):
835
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
836
+ `past_key_values`).
837
+ output_attentions (`bool`, *optional*):
838
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
839
+ tensors for more detail.
840
+ output_hidden_states (`bool`, *optional*):
841
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
842
+ more detail.
843
+ return_dict (`bool`, *optional*):
844
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
845
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
846
+ Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
847
+ this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
848
+ the complete sequence length.
849
+ """
850
+
851
+
852
+ @add_start_docstrings(
853
+ "The bare Instella Model outputting raw hidden-states without any specific head on top.",
854
+ Instella_START_DOCSTRING,
855
+ )
856
+ class InstellaModel(InstellaPreTrainedModel):
857
+ """
858
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`InstellaDecoderLayer`]
859
+
860
+ Args:
861
+ config: InstellaConfig
862
+ """
863
+
864
+ def __init__(self, config: InstellaConfig):
865
+ super().__init__(config)
866
+ self.padding_idx = config.pad_token_id
867
+ self.vocab_size = config.vocab_size
868
+
869
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
870
+ self.layers = nn.ModuleList(
871
+ [InstellaDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
872
+ )
873
+ # self.layers = self.layers[:5]
874
+ self.norm = InstellaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
875
+ self.gradient_checkpointing = False
876
+
877
+ # Initialize weights and apply final processing
878
+ self.post_init()
879
+
880
+ def get_input_embeddings(self):
881
+ return self.embed_tokens
882
+
883
+ def set_input_embeddings(self, value):
884
+ self.embed_tokens = value
885
+
886
+ @add_start_docstrings_to_model_forward(Instella_INPUTS_DOCSTRING)
887
+ # copied from transformers.models.llama.modeling_llama.LlamaModel.forward
888
+ # TODO(joao): add me back asap :)
889
+ def forward(
890
+ self,
891
+ input_ids: torch.LongTensor = None,
892
+ attention_mask: Optional[torch.Tensor] = None,
893
+ position_ids: Optional[torch.LongTensor] = None,
894
+ past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
895
+ inputs_embeds: Optional[torch.FloatTensor] = None,
896
+ use_cache: Optional[bool] = None,
897
+ output_attentions: Optional[bool] = None,
898
+ output_hidden_states: Optional[bool] = None,
899
+ return_dict: Optional[bool] = None,
900
+ cache_position: Optional[torch.LongTensor] = None,
901
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
902
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
903
+ output_hidden_states = (
904
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
905
+ )
906
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
907
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
908
+
909
+ if (input_ids is None) ^ (inputs_embeds is not None):
910
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
911
+
912
+ if self.gradient_checkpointing and self.training and use_cache:
913
+ logger.warning_once(
914
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
915
+ )
916
+ use_cache = False
917
+
918
+ if inputs_embeds is None:
919
+ inputs_embeds = self.embed_tokens(input_ids)
920
+ # print(inputs_embeds)
921
+
922
+ # kept for BC (non `Cache` `past_key_values` inputs)
923
+ return_legacy_cache = False
924
+ if use_cache and not isinstance(past_key_values, Cache):
925
+ return_legacy_cache = True
926
+ if past_key_values is None:
927
+ past_key_values = DynamicCache()
928
+ else:
929
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
930
+ logger.warning_once(
931
+ "We detected that you are passing `past_key_values` as a tuple of tuples. This is deprecated and "
932
+ "will be removed in v4.47. Please convert your cache or use an appropriate `Cache` class "
933
+ "(https://huggingface.co/docs/transformers/kv_cache#legacy-cache-format)"
934
+ )
935
+
936
+ if cache_position is None:
937
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
938
+ cache_position = torch.arange(
939
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
940
+ )
941
+ if position_ids is None:
942
+ position_ids = cache_position.unsqueeze(0)
943
+
944
+ causal_mask = self._update_causal_mask(
945
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
946
+ )
947
+
948
+ # embed positions
949
+ hidden_states = inputs_embeds
950
+
951
+ # decoder layers
952
+ all_hidden_states = () if output_hidden_states else None
953
+ all_self_attns = () if output_attentions else None
954
+ next_decoder_cache = None
955
+
956
+ for decoder_layer in self.layers:
957
+ if output_hidden_states:
958
+ all_hidden_states += (hidden_states,)
959
+
960
+ if self.gradient_checkpointing and self.training:
961
+ layer_outputs = self._gradient_checkpointing_func(
962
+ decoder_layer.__call__,
963
+ hidden_states,
964
+ causal_mask,
965
+ position_ids,
966
+ past_key_values,
967
+ output_attentions,
968
+ use_cache,
969
+ cache_position,
970
+ )
971
+ else:
972
+ layer_outputs = decoder_layer(
973
+ hidden_states,
974
+ attention_mask=causal_mask,
975
+ position_ids=position_ids,
976
+ past_key_value=past_key_values,
977
+ output_attentions=output_attentions,
978
+ use_cache=use_cache,
979
+ cache_position=cache_position,
980
+ )
981
+
982
+ hidden_states = layer_outputs[0]
983
+
984
+ if use_cache:
985
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
986
+
987
+ if output_attentions:
988
+ all_self_attns += (layer_outputs[1],)
989
+
990
+ hidden_states = self.norm(hidden_states)
991
+ # print(hidden_states)
992
+
993
+ # add hidden states from the last decoder layer
994
+ if output_hidden_states:
995
+ all_hidden_states += (hidden_states,)
996
+
997
+ next_cache = next_decoder_cache if use_cache else None
998
+ if return_legacy_cache:
999
+ next_cache = next_cache.to_legacy_cache()
1000
+
1001
+ if not return_dict:
1002
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1003
+ return BaseModelOutputWithPast(
1004
+ last_hidden_state=hidden_states,
1005
+ past_key_values=next_cache,
1006
+ hidden_states=all_hidden_states,
1007
+ attentions=all_self_attns,
1008
+ )
1009
+
1010
+ def _update_causal_mask(
1011
+ self,
1012
+ attention_mask: torch.Tensor,
1013
+ input_tensor: torch.Tensor,
1014
+ cache_position: torch.Tensor,
1015
+ past_key_values: Cache,
1016
+ output_attentions: bool,
1017
+ ):
1018
+ if self.config._attn_implementation == "flash_attention_2":
1019
+ if attention_mask is not None and 0.0 in attention_mask:
1020
+ return attention_mask
1021
+ return None
1022
+
1023
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
1024
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
1025
+ # to infer the attention mask.
1026
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
1027
+ using_static_cache = isinstance(past_key_values, StaticCache)
1028
+
1029
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
1030
+ if self.config._attn_implementation == "sdpa" and not using_static_cache and not output_attentions:
1031
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
1032
+ attention_mask,
1033
+ inputs_embeds=input_tensor,
1034
+ past_key_values_length=past_seen_tokens,
1035
+ is_training=self.training,
1036
+ ):
1037
+ return None
1038
+
1039
+ dtype, device = input_tensor.dtype, input_tensor.device
1040
+ sequence_length = input_tensor.shape[1]
1041
+ if using_static_cache:
1042
+ target_length = past_key_values.get_max_cache_shape()
1043
+ else:
1044
+ target_length = (
1045
+ attention_mask.shape[-1]
1046
+ if isinstance(attention_mask, torch.Tensor)
1047
+ else past_seen_tokens + sequence_length + 1
1048
+ )
1049
+
1050
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
1051
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
1052
+ attention_mask,
1053
+ sequence_length=sequence_length,
1054
+ target_length=target_length,
1055
+ dtype=dtype,
1056
+ device=device,
1057
+ cache_position=cache_position,
1058
+ batch_size=input_tensor.shape[0],
1059
+ )
1060
+
1061
+ if (
1062
+ self.config._attn_implementation == "sdpa"
1063
+ and attention_mask is not None
1064
+ and attention_mask.device.type == "cuda"
1065
+ and not output_attentions
1066
+ ):
1067
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
1068
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
1069
+ # Details: https://github.com/pytorch/pytorch/issues/110213
1070
+ min_dtype = torch.finfo(dtype).min
1071
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
1072
+
1073
+ return causal_mask
1074
+
1075
+ @staticmethod
1076
+ def _prepare_4d_causal_attention_mask_with_cache_position(
1077
+ attention_mask: torch.Tensor,
1078
+ sequence_length: int,
1079
+ target_length: int,
1080
+ dtype: torch.dtype,
1081
+ device: torch.device,
1082
+ cache_position: torch.Tensor,
1083
+ batch_size: int,
1084
+ **kwargs,
1085
+ ):
1086
+ """
1087
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
1088
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
1089
+
1090
+ Args:
1091
+ attention_mask (`torch.Tensor`):
1092
+ A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
1093
+ `(batch_size, 1, query_length, key_value_length)`.
1094
+ sequence_length (`int`):
1095
+ The sequence length being processed.
1096
+ target_length (`int`):
1097
+ The target length: when generating with static cache, the mask should be as long as the static cache,
1098
+ to account for the 0 padding, the part of the cache that is not filled yet.
1099
+ dtype (`torch.dtype`):
1100
+ The dtype to use for the 4D attention mask.
1101
+ device (`torch.device`):
1102
+ The device to plcae the 4D attention mask on.
1103
+ cache_position (`torch.Tensor`):
1104
+ Indices depicting the position of the input sequence tokens in the sequence.
1105
+ batch_size (`torch.Tensor`):
1106
+ Batch size.
1107
+ """
1108
+ if attention_mask is not None and attention_mask.dim() == 4:
1109
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
1110
+ causal_mask = attention_mask
1111
+ else:
1112
+ min_dtype = torch.finfo(dtype).min
1113
+ causal_mask = torch.full(
1114
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
1115
+ )
1116
+ if sequence_length != 1:
1117
+ causal_mask = torch.triu(causal_mask, diagonal=1)
1118
+ causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
1119
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
1120
+ if attention_mask is not None:
1121
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
1122
+ mask_length = attention_mask.shape[-1]
1123
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :]
1124
+ padding_mask = padding_mask == 0
1125
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
1126
+ padding_mask, min_dtype
1127
+ )
1128
+
1129
+ return causal_mask
1130
+
1131
+ # TODO: re-enable check: Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM with LLAMA->Instella,Llama->Instella
1132
+ class InstellaForCausalLM(InstellaPreTrainedModel, GenerationMixin):
1133
+ _tied_weights_keys = ["lm_head.weight"]
1134
+
1135
+ def __init__(self, config: InstellaConfig):
1136
+ super().__init__(config)
1137
+ self.model = InstellaModel(config)
1138
+ self.vocab_size = config.vocab_size
1139
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1140
+
1141
+ # Initialize weights and apply final processing
1142
+ self.post_init()
1143
+
1144
+ def get_input_embeddings(self):
1145
+ return self.model.embed_tokens
1146
+
1147
+ def set_input_embeddings(self, value):
1148
+ self.model.embed_tokens = value
1149
+
1150
+ def get_output_embeddings(self):
1151
+ return self.lm_head
1152
+
1153
+ def set_output_embeddings(self, new_embeddings):
1154
+ self.lm_head = new_embeddings
1155
+
1156
+ def set_decoder(self, decoder):
1157
+ self.model = decoder
1158
+
1159
+ def get_decoder(self):
1160
+ return self.model
1161
+
1162
+ @add_start_docstrings_to_model_forward(Instella_INPUTS_DOCSTRING)
1163
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1164
+ # Ignore copy
1165
+ def forward(
1166
+ self,
1167
+ input_ids: torch.LongTensor = None,
1168
+ attention_mask: Optional[torch.Tensor] = None,
1169
+ position_ids: Optional[torch.LongTensor] = None,
1170
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1171
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1172
+ labels: Optional[torch.LongTensor] = None,
1173
+ use_cache: Optional[bool] = None,
1174
+ output_attentions: Optional[bool] = None,
1175
+ output_hidden_states: Optional[bool] = None,
1176
+ return_dict: Optional[bool] = None,
1177
+ cache_position: Optional[torch.LongTensor] = None,
1178
+ num_logits_to_keep: int = 0,
1179
+ **loss_kwargs,
1180
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1181
+ r"""
1182
+ Args:
1183
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1184
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1185
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1186
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1187
+
1188
+ num_logits_to_keep (`int`, *optional*):
1189
+ Calculate logits for the last `num_logits_to_keep` tokens. If `0`, calculate logits for all
1190
+ `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
1191
+ token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
1192
+
1193
+ Returns:
1194
+
1195
+ Example:
1196
+
1197
+ ```python
1198
+ >>> from transformers import AutoTokenizer, InstellaForCausalLM
1199
+
1200
+ >>> model = InstellaForCausalLM.from_pretrained("allenai/Instella2-1B-hf")
1201
+ >>> tokenizer = AutoTokenizer.from_pretrained("allenai/Instella2-1B-hf")
1202
+
1203
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1204
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1205
+
1206
+ >>> # Generate
1207
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1208
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1209
+ 'Hey, are you conscious? Can you talk to me?\nI’m not sure if you’re conscious of this, but I’m'
1210
+ ```
1211
+ """
1212
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1213
+ output_hidden_states = (
1214
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1215
+ )
1216
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1217
+
1218
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1219
+ outputs = self.model(
1220
+ input_ids=input_ids,
1221
+ attention_mask=attention_mask,
1222
+ position_ids=position_ids,
1223
+ past_key_values=past_key_values,
1224
+ inputs_embeds=inputs_embeds,
1225
+ use_cache=use_cache,
1226
+ output_attentions=output_attentions,
1227
+ output_hidden_states=output_hidden_states,
1228
+ return_dict=return_dict,
1229
+ cache_position=cache_position,
1230
+ )
1231
+
1232
+ hidden_states = outputs[0]
1233
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
1234
+ logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
1235
+
1236
+ loss = None
1237
+ if labels is not None:
1238
+ loss = self.loss_function(logits, labels, self.vocab_size, **loss_kwargs)
1239
+
1240
+ if not return_dict:
1241
+ output = (logits,) + outputs[1:]
1242
+ return (loss,) + output if loss is not None else output
1243
+
1244
+ return CausalLMOutputWithPast(
1245
+ loss=loss,
1246
+ logits=logits,
1247
+ past_key_values=outputs.past_key_values,
1248
+ hidden_states=outputs.hidden_states,
1249
+ attentions=outputs.attentions,
1250
+ )
1251
+