Abhaykoul commited on
Commit
5d67871
1 Parent(s): 5e4db97

Upload HelpingAIForCausalLM

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,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Abhaykoul/HelpingAI-3B-v2",
3
+ "architectures": [
4
+ "HelpingAIForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_HelpingAI.HelpingAIConfig",
10
+ "AutoModelForCausalLM": "modeling_HelpingAI.HelpingAIForCausalLM"
11
+ },
12
+ "bos_token_id": 50278,
13
+ "eos_token_id": 50279,
14
+ "head_dim": 256,
15
+ "hidden_act": "silu",
16
+ "hidden_activation": null,
17
+ "hidden_dropout": 0.0,
18
+ "hidden_size": 2560,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 6912,
21
+ "layer_norm_eps": 1e-05,
22
+ "max_position_embeddings": 4096,
23
+ "model_type": "HelpingAI",
24
+ "norm_eps": 1e-05,
25
+ "num_attention_heads": 32,
26
+ "num_experts_per_tok": 2,
27
+ "num_hidden_layers": 32,
28
+ "num_key_value_heads": 32,
29
+ "num_local_experts": 8,
30
+ "output_router_logits": false,
31
+ "pad_token_id": 50279,
32
+ "partial_rotary_factor": 0.25,
33
+ "rms_norm_eps": 1e-06,
34
+ "rope_pct": 0.25,
35
+ "rope_scaling": null,
36
+ "rope_theta": 10000,
37
+ "router_aux_loss_coef": 0.02,
38
+ "tie_word_embeddings": false,
39
+ "torch_dtype": "float16",
40
+ "transformers_version": "4.40.0",
41
+ "use_cache": false,
42
+ "use_qkv_bias": false,
43
+ "vocab_size": 50281
44
+ }
configuration_HelpingAI.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ HelpingAI model configuration"""
2
+
3
+ from transformers import PretrainedConfig
4
+ from transformers.utils import logging
5
+
6
+
7
+ logger = logging.get_logger(__name__)
8
+
9
+ class HelpingAIConfig(PretrainedConfig):
10
+ keys_to_ignore_at_inference = ["past_key_values"]
11
+ model_type = "HelpingAI"
12
+ def __init__(
13
+ self,
14
+ vocab_size=50304,
15
+ hidden_size=2560,
16
+ intermediate_size=6912,
17
+ num_hidden_layers=32,
18
+ num_attention_heads=32,
19
+ num_key_value_heads=32,
20
+ head_dim=256,
21
+ hidden_act="silu",
22
+ max_position_embeddings=4096,
23
+ initializer_range=0.02,
24
+ rms_norm_eps=1e-6,
25
+ use_cache=True,
26
+ hidden_activation=None,
27
+ rope_theta=10000,
28
+ rope_pct=0.25,
29
+ attention_bias=False,
30
+ attention_dropout=0.0,
31
+ num_experts_per_tok=2,
32
+ num_local_experts=8,
33
+ router_aux_loss_coef=0.02,
34
+ output_router_logits=False,
35
+ norm_eps=1.0e-5,
36
+ **kwargs,
37
+ ):
38
+ self.vocab_size = vocab_size
39
+ self.max_position_embeddings = max_position_embeddings
40
+ self.hidden_size = hidden_size
41
+ self.intermediate_size = intermediate_size
42
+ self.num_hidden_layers = num_hidden_layers
43
+ self.num_attention_heads = num_attention_heads
44
+ self.head_dim = head_dim
45
+ self.hidden_act = hidden_act
46
+ self.hidden_activation = hidden_activation
47
+ self.num_key_value_heads = num_key_value_heads
48
+ self.initializer_range = initializer_range
49
+ self.rms_norm_eps = rms_norm_eps
50
+ self.use_cache = use_cache
51
+ self.rope_theta = rope_theta
52
+ self.attention_bias = attention_bias
53
+ self.attention_dropout = attention_dropout
54
+ self.num_experts_per_tok = num_experts_per_tok
55
+ self.num_local_experts = num_local_experts
56
+ self.router_aux_loss_coef = router_aux_loss_coef
57
+ self.output_router_logits = output_router_logits
58
+ self.rope_pct = rope_pct
59
+ self.norm_eps = norm_eps
60
+ super().__init__(**kwargs)
generation_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50278,
4
+ "do_sample": true,
5
+ "eos_token_id": 50279,
6
+ "pad_token_id": 50279,
7
+ "transformers_version": "4.40.0"
8
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:78dad9c9cf3b623bcd2e9d94d219179555df4f3e8b1adbec21b409d2571c5c5d
3
+ size 4980594136
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fbb02a2d2167b01d47da5991821dbe923342727d01ab763ab7a72ec56c5a676b
3
+ size 610097432
model.safetensors.index.json ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 5590650880
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00002-of-00002.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.input_layernorm.bias": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
25
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.1.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.10.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
36
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.10.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.11.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
47
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.11.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
53
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.12.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
58
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.12.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
64
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.13.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
69
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.13.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
75
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.14.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
80
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.14.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
86
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.15.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
91
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.15.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
97
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.16.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
102
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.16.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
108
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
109
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
111
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.17.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
113
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.17.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
119
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.18.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
124
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
125
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.18.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
130
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
132
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
134
+ "model.layers.19.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
135
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.19.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
141
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
143
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
144
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
145
+ "model.layers.2.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
146
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
147
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.2.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
152
+ "model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
153
+ "model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
154
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
155
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
156
+ "model.layers.20.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
157
+ "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
158
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
159
+ "model.layers.20.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
163
+ "model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
164
+ "model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
165
+ "model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
166
+ "model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
167
+ "model.layers.21.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
168
+ "model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
169
+ "model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
170
+ "model.layers.21.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
174
+ "model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
175
+ "model.layers.22.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
176
+ "model.layers.22.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
177
+ "model.layers.22.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
178
+ "model.layers.22.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
179
+ "model.layers.22.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
180
+ "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
181
+ "model.layers.22.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
185
+ "model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
186
+ "model.layers.23.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
187
+ "model.layers.23.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
188
+ "model.layers.23.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
189
+ "model.layers.23.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
190
+ "model.layers.23.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
191
+ "model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.23.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
196
+ "model.layers.24.input_layernorm.weight": "model-00001-of-00002.safetensors",
197
+ "model.layers.24.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
198
+ "model.layers.24.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
199
+ "model.layers.24.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
200
+ "model.layers.24.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
201
+ "model.layers.24.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
202
+ "model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
203
+ "model.layers.24.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
207
+ "model.layers.25.input_layernorm.weight": "model-00001-of-00002.safetensors",
208
+ "model.layers.25.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
209
+ "model.layers.25.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
210
+ "model.layers.25.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
211
+ "model.layers.25.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
212
+ "model.layers.25.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
213
+ "model.layers.25.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
214
+ "model.layers.25.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
218
+ "model.layers.26.input_layernorm.weight": "model-00001-of-00002.safetensors",
219
+ "model.layers.26.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
220
+ "model.layers.26.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
221
+ "model.layers.26.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
222
+ "model.layers.26.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
223
+ "model.layers.26.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
224
+ "model.layers.26.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
225
+ "model.layers.26.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
229
+ "model.layers.27.input_layernorm.weight": "model-00001-of-00002.safetensors",
230
+ "model.layers.27.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
231
+ "model.layers.27.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
232
+ "model.layers.27.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
233
+ "model.layers.27.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
234
+ "model.layers.27.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
235
+ "model.layers.27.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
236
+ "model.layers.27.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
240
+ "model.layers.28.input_layernorm.weight": "model-00001-of-00002.safetensors",
241
+ "model.layers.28.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
242
+ "model.layers.28.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
243
+ "model.layers.28.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
244
+ "model.layers.28.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
245
+ "model.layers.28.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
246
+ "model.layers.28.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
247
+ "model.layers.28.self_attn.o_proj.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.input_layernorm.bias": "model-00002-of-00002.safetensors",
251
+ "model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
252
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
253
+ "model.layers.29.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
254
+ "model.layers.29.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
255
+ "model.layers.29.post_attention_layernorm.bias": "model-00002-of-00002.safetensors",
256
+ "model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
257
+ "model.layers.29.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
258
+ "model.layers.29.self_attn.o_proj.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.input_layernorm.bias": "model-00001-of-00002.safetensors",
262
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.3.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
267
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
269
+ "model.layers.3.self_attn.o_proj.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.input_layernorm.bias": "model-00002-of-00002.safetensors",
273
+ "model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
274
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
275
+ "model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
276
+ "model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
277
+ "model.layers.30.post_attention_layernorm.bias": "model-00002-of-00002.safetensors",
278
+ "model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
279
+ "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
280
+ "model.layers.30.self_attn.o_proj.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.input_layernorm.bias": "model-00002-of-00002.safetensors",
284
+ "model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
285
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
286
+ "model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
287
+ "model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
288
+ "model.layers.31.post_attention_layernorm.bias": "model-00002-of-00002.safetensors",
289
+ "model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
290
+ "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
291
+ "model.layers.31.self_attn.o_proj.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.4.input_layernorm.bias": "model-00001-of-00002.safetensors",
295
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
296
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
297
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
298
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
299
+ "model.layers.4.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
300
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
301
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
302
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
303
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
304
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
305
+ "model.layers.5.input_layernorm.bias": "model-00001-of-00002.safetensors",
306
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
307
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
308
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
309
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
310
+ "model.layers.5.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
311
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
312
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
313
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
314
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
315
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
316
+ "model.layers.6.input_layernorm.bias": "model-00001-of-00002.safetensors",
317
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
318
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
319
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
320
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
321
+ "model.layers.6.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
322
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
323
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
324
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
325
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
326
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
327
+ "model.layers.7.input_layernorm.bias": "model-00001-of-00002.safetensors",
328
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
329
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
330
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
331
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
332
+ "model.layers.7.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
333
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
334
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
335
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
336
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
337
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
338
+ "model.layers.8.input_layernorm.bias": "model-00001-of-00002.safetensors",
339
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
340
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
341
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
342
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
343
+ "model.layers.8.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
344
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
345
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
346
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
347
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
348
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
349
+ "model.layers.9.input_layernorm.bias": "model-00001-of-00002.safetensors",
350
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
351
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
352
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
353
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
354
+ "model.layers.9.post_attention_layernorm.bias": "model-00001-of-00002.safetensors",
355
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
356
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
357
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
358
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
359
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
360
+ "model.norm.bias": "model-00002-of-00002.safetensors",
361
+ "model.norm.weight": "model-00002-of-00002.safetensors"
362
+ }
363
+ }
modeling_HelpingAI.py ADDED
@@ -0,0 +1,670 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ HelpingAI model . """
2
+ from typing import Optional, Tuple, Union
3
+ import math
4
+
5
+ import torch
6
+ import torch.utils.checkpoint
7
+ from transformers import AutoModel, AutoModelForCausalLM
8
+ from torch import nn
9
+ from torch.nn import CrossEntropyLoss
10
+ from transformers.modeling_outputs import (
11
+ BaseModelOutputWithPast,
12
+ CausalLMOutputWithPast,
13
+ )
14
+ from transformers.modeling_utils import PreTrainedModel
15
+ from transformers.utils import logging
16
+ from .configuration_HelpingAI import HelpingAIConfig
17
+
18
+
19
+ logger = logging.get_logger(__name__)
20
+
21
+
22
+ # Copied from transformers.models.bart.modeling_bart._make_causal_mask
23
+ def _make_causal_mask(
24
+ input_ids_shape: torch.Size,
25
+ dtype: torch.dtype,
26
+ device: torch.device,
27
+ past_key_values_length: int = 0,
28
+ ):
29
+ """Make causal mask used for bi-directional self-attention."""
30
+ batch_size, tgt_len = input_ids_shape
31
+ mask = torch.full((tgt_len, tgt_len), torch.finfo(torch.float16).min, device=device)
32
+ mask_cond = torch.arange(mask.size(-1), device=device)
33
+ mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
34
+ mask = mask.to(dtype)
35
+ if past_key_values_length > 0:
36
+ mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype, device=device), mask], dim=-1)
37
+ return mask[None, None, :, :].expand(batch_size, 1, tgt_len, tgt_len + past_key_values_length)
38
+
39
+
40
+ # Copied from transformers.models.bart.modeling_bart._expand_mask
41
+ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
42
+ """Expands attention_mask from `[batch_size, seq_len]` to `[batch_size, 1, tgt_seq_len, src_seq_len]`."""
43
+ batch_size, src_len = mask.size()
44
+ tgt_len = tgt_len if tgt_len is not None else src_len
45
+
46
+ expanded_mask = mask[:, None, None, :].expand(batch_size, 1, tgt_len, src_len).to(dtype)
47
+ inverted_mask = 1.0 - expanded_mask
48
+
49
+ return inverted_mask.masked_fill(
50
+ inverted_mask.to(torch.bool), torch.finfo(dtype).min
51
+ )
52
+
53
+
54
+ class RotaryEmbedding(nn.Module):
55
+ def __init__(
56
+ self,
57
+ dim: int,
58
+ max_position_embeddings: int,
59
+ base: int = 10_000,
60
+ device: Optional[torch.device] = None,
61
+ ):
62
+ super().__init__()
63
+
64
+ self.dim = dim
65
+ self.max_position_embeddings = max_position_embeddings
66
+ self.base = base
67
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, device=device, dtype=torch.float32) / self.dim))
68
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
69
+
70
+ # Build here to make `torch.jit.trace` work.
71
+ self._set_cos_sin_cache(
72
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype(),
73
+ )
74
+
75
+ def _set_cos_sin_cache(self, seq_len: int, device: torch.device, dtype: torch.dtype):
76
+ self.max_seq_len_cached = seq_len
77
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.float32)
78
+
79
+ # Don't do einsum, it converts fp32 to fp16 under AMP
80
+ # freqs = torch.einsum("i,j->ij", t, self.inv_freq)
81
+ freqs = torch.outer(t, self.inv_freq)
82
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
83
+ emb = torch.cat((freqs, freqs), dim=-1)
84
+ self.register_buffer("cos_cached", emb.cos()[None, None, :, :].to(dtype), persistent=False)
85
+ self.register_buffer("sin_cached", emb.sin()[None, None, :, :].to(dtype), persistent=False)
86
+
87
+ def forward(self, x: torch.Tensor, seq_len: Optional[int] = None):
88
+ # x: [batch_size, num_heads, seq_len, head_size]
89
+ if seq_len > self.max_seq_len_cached:
90
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=torch.get_default_dtype())
91
+ return (
92
+ self.cos_cached[:, :, :seq_len, ...].to(dtype=x.dtype),
93
+ self.sin_cached[:, :, :seq_len, ...].to(dtype=x.dtype),
94
+ )
95
+
96
+
97
+ def rotate_half(x: torch.Tensor):
98
+ """Rotates half the hidden dims of the input."""
99
+ x1, x2 = torch.chunk(x, 2, dim=-1)
100
+ return torch.cat((-x2, x1), dim=-1)
101
+
102
+
103
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids):
104
+ # The first two dimensions of cos and sin are always 1, so we can `squeeze` them.
105
+ cos = cos.squeeze(1).squeeze(0) # [seq_len, dim]
106
+ sin = sin.squeeze(1).squeeze(0) # [seq_len, dim]
107
+ cos = cos[position_ids].unsqueeze(1) # [batch_size, 1, seq_len, dim]
108
+ sin = sin[position_ids].unsqueeze(1) # [batch_size, 1, seq_len, dim]
109
+ q_embed = (q * cos) + (rotate_half(q) * sin)
110
+ k_embed = (k * cos) + (rotate_half(k) * sin)
111
+ return q_embed, k_embed
112
+
113
+
114
+ class MLP(nn.Module):
115
+ def __init__(self, config: HelpingAIConfig):
116
+ super().__init__()
117
+ self.config = config
118
+ self.hidden_size = config.hidden_size
119
+ self.intermediate_size = config.intermediate_size
120
+ self.gate_proj = nn.Linear(config.hidden_size, config.intermediate_size, bias=False)
121
+ self.up_proj = nn.Linear(config.hidden_size, config.intermediate_size, bias=False)
122
+ self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
123
+ self.act_fn = nn.SiLU()
124
+
125
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
126
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
127
+
128
+
129
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
130
+ """
131
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
132
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
133
+ """
134
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
135
+ if n_rep == 1:
136
+ return hidden_states
137
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
138
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
139
+
140
+
141
+ class Attention(nn.Module):
142
+ def __init__(self, config: HelpingAIConfig):
143
+ super().__init__()
144
+ self.config = config
145
+ self.hidden_size = config.hidden_size
146
+ self.num_heads = config.num_attention_heads
147
+ self.head_dim = self.hidden_size // self.num_heads
148
+ self.num_key_value_heads = config.num_key_value_heads
149
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
150
+ self.max_position_embeddings = config.max_position_embeddings
151
+
152
+ if (self.head_dim * self.num_heads) != self.hidden_size:
153
+ raise ValueError(
154
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
155
+ f" and `num_heads`: {self.num_heads})."
156
+ )
157
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
158
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
159
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
160
+ self.o_proj = nn.Linear(self.hidden_size, self.hidden_size, bias=False)
161
+
162
+ self._init_rope()
163
+
164
+ def _init_rope(self):
165
+ self.rotary_ndims = int(self.head_dim * self.config.rope_pct)
166
+ self.rotary_emb = RotaryEmbedding(
167
+ self.rotary_ndims,
168
+ max_position_embeddings=self.config.max_position_embeddings,
169
+ base=self.config.rope_theta,
170
+ )
171
+
172
+ def forward(
173
+ self,
174
+ hidden_states: torch.FloatTensor,
175
+ attention_mask: torch.FloatTensor,
176
+ position_ids: torch.LongTensor,
177
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
178
+ output_attentions: Optional[bool] = False,
179
+ use_cache: Optional[bool] = False,
180
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
181
+ bsz, q_len, _ = hidden_states.size()
182
+
183
+ query_states = self.q_proj(hidden_states)
184
+ key_states = self.k_proj(hidden_states)
185
+ value_states = self.v_proj(hidden_states)
186
+
187
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
188
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
189
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
190
+
191
+ query_rot = query_states[..., : self.rotary_ndims]
192
+ query_pass = query_states[..., self.rotary_ndims :]
193
+ key_rot = key_states[..., : self.rotary_ndims]
194
+ key_pass = key_states[..., self.rotary_ndims :]
195
+
196
+ kv_seq_len = key_states.shape[-2]
197
+ if past_key_value is not None:
198
+ kv_seq_len += past_key_value[0].shape[-2]
199
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
200
+ query_states, key_states = apply_rotary_pos_emb(query_rot, key_rot, cos, sin, position_ids)
201
+
202
+ # [batch_size, num_heads, seq_len, head_dim]
203
+ query_states = torch.cat((query_states, query_pass), dim=-1)
204
+ key_states = torch.cat((key_states, key_pass), dim=-1)
205
+
206
+ if past_key_value is not None:
207
+ # Reuse k, v, self_attention
208
+ key_states = torch.cat((past_key_value[0], key_states), dim=2)
209
+ value_states = torch.cat((past_key_value[1], value_states), dim=2)
210
+
211
+ past_key_value = (key_states, value_states) if use_cache else None
212
+
213
+ # Repeat k/v heads if n_kv_heads < n_heads
214
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
215
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
216
+
217
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
218
+
219
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
220
+ raise ValueError(
221
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
222
+ f" {attn_weights.size()}"
223
+ )
224
+
225
+ if attention_mask is not None:
226
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
227
+ raise ValueError(
228
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
229
+ )
230
+ attn_weights = attn_weights + attention_mask
231
+
232
+ # Upcast attention to fp32
233
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
234
+ attn_output = torch.matmul(attn_weights, value_states)
235
+
236
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
237
+ raise ValueError(
238
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
239
+ f" {attn_output.size()}"
240
+ )
241
+
242
+ # Merge heads
243
+ attn_output = attn_output.transpose(1, 2).contiguous()
244
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
245
+
246
+ # Final linear projection
247
+ attn_output = self.o_proj(attn_output)
248
+
249
+ if not output_attentions:
250
+ attn_weights = None
251
+
252
+ return attn_output, attn_weights, past_key_value
253
+
254
+
255
+ class DecoderLayer(nn.Module):
256
+ def __init__(self, config: HelpingAIConfig):
257
+ super().__init__()
258
+ self.self_attn = Attention(config)
259
+ self.mlp = MLP(config)
260
+ self.input_layernorm = nn.LayerNorm(config.hidden_size, eps=config.norm_eps)
261
+ self.post_attention_layernorm = nn.LayerNorm(config.hidden_size, eps=config.norm_eps)
262
+
263
+ def forward(
264
+ self,
265
+ hidden_states: Optional[torch.FloatTensor],
266
+ attention_mask: Optional[torch.FloatTensor] = None,
267
+ position_ids: Optional[torch.LongTensor] = None,
268
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
269
+ output_attentions: Optional[bool] = False,
270
+ use_cache: Optional[bool] = False,
271
+ ) -> Union[Tuple[torch.Tensor], Optional[Tuple[torch.Tensor, Tuple[torch.FloatTensor, ...]]]]:
272
+ residual = hidden_states
273
+
274
+ hidden_states = self.input_layernorm(hidden_states)
275
+
276
+ # Self Attention
277
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
278
+ hidden_states=hidden_states,
279
+ attention_mask=attention_mask,
280
+ position_ids=position_ids,
281
+ past_key_value=past_key_value,
282
+ output_attentions=output_attentions,
283
+ use_cache=use_cache,
284
+ )
285
+ hidden_states = residual + hidden_states
286
+
287
+ # Fully Connected
288
+ residual = hidden_states
289
+ hidden_states = self.post_attention_layernorm(hidden_states)
290
+ hidden_states = self.mlp(hidden_states)
291
+ hidden_states = residual + hidden_states
292
+
293
+ outputs = (hidden_states,)
294
+
295
+ if output_attentions:
296
+ outputs += (self_attn_weights,)
297
+
298
+ if use_cache:
299
+ outputs += (present_key_value,)
300
+
301
+ return outputs
302
+
303
+
304
+ class HelpingAIPreTrainedModel(PreTrainedModel):
305
+ """An abstract class to handle weights initialization and a simple interface
306
+ for downloading and loading pretrained models.
307
+ """
308
+
309
+ config_class = HelpingAIConfig
310
+ base_model_prefix = "transformer"
311
+ supports_gradient_checkpointing = True
312
+ _no_split_modules = ["DecoderLayer"]
313
+ _skip_keys_device_placement = "past_key_values"
314
+
315
+ def _init_weights(self, module: nn.Module):
316
+ """Initialize the weights"""
317
+ if isinstance(module, nn.Linear):
318
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
319
+ if module.bias is not None:
320
+ module.bias.data.zero_()
321
+ elif isinstance(module, nn.Embedding):
322
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
323
+ if module.padding_idx is not None:
324
+ module.weight.data[module.padding_idx].zero_()
325
+ elif isinstance(module, nn.LayerNorm):
326
+ module.bias.data.zero_()
327
+ module.weight.data.fill_(1.0)
328
+
329
+ def _set_gradient_checkpointing(self, module: nn.Module, value=False):
330
+ if isinstance(module, HelpingAIModel):
331
+ module.gradient_checkpointing = value
332
+
333
+
334
+ class HelpingAIModel(HelpingAIPreTrainedModel):
335
+ def __init__(self, config: HelpingAIConfig):
336
+ super().__init__(config)
337
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, config.pad_token_id)
338
+ self.layers = nn.ModuleList([DecoderLayer(config) for _ in range(config.num_hidden_layers)])
339
+ self.norm = nn.LayerNorm(config.hidden_size, eps=config.norm_eps)
340
+
341
+ self.gradient_checkpointing = False
342
+ # Initialize weights and apply final processing
343
+ self.post_init()
344
+
345
+ def get_input_embeddings(self):
346
+ return self.embed_tokens
347
+
348
+ def set_input_embeddings(self, value: nn.Module):
349
+ self.embed_tokens = value
350
+
351
+ # Copied from transformers.models.bart.modeling_bart.BartDecoder._prepare_decoder_attention_mask
352
+ def _prepare_decoder_attention_mask(
353
+ self,
354
+ attention_mask: torch.Tensor,
355
+ input_shape: torch.Size,
356
+ inputs_embeds: torch.Tensor,
357
+ past_key_values_length: int,
358
+ ):
359
+ # Create causal mask
360
+ # [batch_size, seq_len] -> [batch_size, 1, tgt_seq_len, src_seq_len]
361
+ combined_attention_mask = None
362
+ if input_shape[-1] > 1:
363
+ combined_attention_mask = _make_causal_mask(
364
+ input_shape,
365
+ inputs_embeds.dtype,
366
+ device=inputs_embeds.device,
367
+ past_key_values_length=past_key_values_length,
368
+ )
369
+
370
+ if attention_mask is not None:
371
+ # [batch_size, seq_len] -> [batch_size, 1, tgt_seq_len, src_seq_len]
372
+ expanded_attn_mask = _expand_mask(
373
+ attention_mask, inputs_embeds.dtype, tgt_len=input_shape[-1]
374
+ ).to(inputs_embeds.device)
375
+ combined_attention_mask = expanded_attn_mask if combined_attention_mask is None else expanded_attn_mask + combined_attention_mask
376
+
377
+ return combined_attention_mask
378
+
379
+ def forward(
380
+ self,
381
+ input_ids: Optional[torch.LongTensor] = None,
382
+ attention_mask: Optional[torch.FloatTensor] = None,
383
+ position_ids: Optional[torch.LongTensor] = None,
384
+ past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
385
+ inputs_embeds: Optional[torch.FloatTensor] = None,
386
+ use_cache: Optional[bool] = None,
387
+ output_attentions: Optional[bool] = None,
388
+ output_hidden_states: Optional[bool] = None,
389
+ return_dict: Optional[bool] = None,
390
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
391
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
392
+ output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
393
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
394
+
395
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
396
+
397
+ # Retrieve input_ids and inputs_embeds
398
+ if input_ids is not None and inputs_embeds is not None:
399
+ raise ValueError(
400
+ "You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time"
401
+ )
402
+ elif input_ids is not None:
403
+ batch_size, seq_length = input_ids.shape
404
+ elif inputs_embeds is not None:
405
+ batch_size, seq_length, _ = inputs_embeds.shape
406
+ else:
407
+ raise ValueError(
408
+ "You have to specify either decoder_input_ids or decoder_inputs_embeds"
409
+ )
410
+
411
+ seq_length_with_past = seq_length
412
+ past_key_values_length = 0
413
+
414
+ if past_key_values is not None:
415
+ past_key_values_length = past_key_values[0][0].shape[2]
416
+ seq_length_with_past = seq_length_with_past + past_key_values_length
417
+
418
+ if position_ids is None:
419
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
420
+ position_ids = torch.arange(
421
+ past_key_values_length,
422
+ seq_length + past_key_values_length,
423
+ dtype=torch.long,
424
+ device=device,
425
+ )
426
+ position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
427
+ else:
428
+ position_ids = position_ids.view(-1, seq_length).long()
429
+
430
+ if inputs_embeds is None:
431
+ inputs_embeds = self.embed_tokens(input_ids)
432
+ # Embed positions
433
+ if attention_mask is None:
434
+ attention_mask = torch.ones(
435
+ (batch_size, seq_length_with_past),
436
+ dtype=torch.bool,
437
+ device=inputs_embeds.device,
438
+ )
439
+ attention_mask = self._prepare_decoder_attention_mask(
440
+ attention_mask,
441
+ (batch_size, seq_length),
442
+ inputs_embeds,
443
+ past_key_values_length,
444
+ )
445
+
446
+ hidden_states = inputs_embeds
447
+
448
+ if self.gradient_checkpointing and self.training:
449
+ if use_cache:
450
+ logger.warning(
451
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
452
+ )
453
+ use_cache = False
454
+
455
+ # Decoder layers
456
+ all_hidden_states = () if output_hidden_states else None
457
+ all_self_attns = () if output_attentions else None
458
+ next_decoder_cache = () if use_cache else None
459
+
460
+ for idx, decoder_layer in enumerate(self.layers):
461
+ if output_hidden_states:
462
+ all_hidden_states += (hidden_states,)
463
+
464
+ past_key_value = (
465
+ past_key_values[idx] if past_key_values is not None else None
466
+ )
467
+
468
+ if self.gradient_checkpointing and self.training:
469
+
470
+ def create_custom_forward(module):
471
+ def custom_forward(*inputs):
472
+ # None for past_key_value
473
+ return module(*inputs, past_key_value, output_attentions)
474
+
475
+ return custom_forward
476
+
477
+ layer_outputs = torch.utils.checkpoint.checkpoint(
478
+ create_custom_forward(decoder_layer),
479
+ hidden_states,
480
+ attention_mask,
481
+ position_ids,
482
+ )
483
+ else:
484
+ layer_outputs = decoder_layer(
485
+ hidden_states,
486
+ attention_mask=attention_mask,
487
+ position_ids=position_ids,
488
+ past_key_value=past_key_value,
489
+ output_attentions=output_attentions,
490
+ use_cache=use_cache,
491
+ )
492
+
493
+ hidden_states = layer_outputs[0]
494
+
495
+ if use_cache:
496
+ next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
497
+
498
+ if output_attentions:
499
+ all_self_attns += (layer_outputs[1],)
500
+
501
+ hidden_states = self.norm(hidden_states)
502
+
503
+ # Add hidden states from the last decoder layer
504
+ if output_hidden_states:
505
+ all_hidden_states += (hidden_states,)
506
+
507
+ next_cache = next_decoder_cache if use_cache else None
508
+ if not return_dict:
509
+ return tuple(
510
+ v
511
+ for v in [hidden_states, next_cache, all_hidden_states, all_self_attns]
512
+ if v is not None
513
+ )
514
+ return BaseModelOutputWithPast(
515
+ last_hidden_state=hidden_states,
516
+ past_key_values=next_cache,
517
+ hidden_states=all_hidden_states,
518
+ attentions=all_self_attns,
519
+ )
520
+
521
+
522
+ class HelpingAIForCausalLM(HelpingAIPreTrainedModel):
523
+ _tied_weights_keys = ["lm_head.weight"]
524
+
525
+ def __init__(self, config: HelpingAIConfig):
526
+ super().__init__(config)
527
+
528
+ self.model = HelpingAIModel(config)
529
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
530
+
531
+ # Initialize weights and apply final processing
532
+ self.post_init()
533
+
534
+ def get_input_embeddings(self):
535
+ return self.model.embed_tokens
536
+
537
+ def set_input_embeddings(self, value):
538
+ self.model.embed_tokens = value
539
+
540
+ def get_output_embeddings(self):
541
+ return self.lm_head
542
+
543
+ def set_output_embeddings(self, new_embeddings: nn.Module):
544
+ self.lm_head = new_embeddings
545
+
546
+ def get_decoder(self):
547
+ return self.transformer
548
+
549
+ def set_decoder(self, decoder):
550
+ self.transformer = decoder
551
+
552
+ def forward(
553
+ self,
554
+ input_ids: Optional[torch.LongTensor] = None,
555
+ attention_mask: Optional[torch.FloatTensor] = None,
556
+ position_ids: Optional[torch.LongTensor] = None,
557
+ past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
558
+ inputs_embeds: Optional[torch.FloatTensor] = None,
559
+ labels: Optional[torch.LongTensor] = None,
560
+ use_cache: Optional[bool] = None,
561
+ output_attentions: Optional[bool] = None,
562
+ output_hidden_states: Optional[bool] = None,
563
+ return_dict: Optional[bool] = None,
564
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
565
+ output_attentions = (
566
+ output_attentions
567
+ if output_attentions is not None
568
+ else self.config.output_attentions
569
+ )
570
+ output_hidden_states = (
571
+ output_hidden_states
572
+ if output_hidden_states is not None
573
+ else self.config.output_hidden_states
574
+ )
575
+ return_dict = (
576
+ return_dict if return_dict is not None else self.config.use_return_dict
577
+ )
578
+
579
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
580
+ outputs = self.model(
581
+ input_ids,
582
+ attention_mask=attention_mask,
583
+ position_ids=position_ids,
584
+ past_key_values=past_key_values,
585
+ inputs_embeds=inputs_embeds,
586
+ use_cache=use_cache,
587
+ output_attentions=output_attentions,
588
+ output_hidden_states=output_hidden_states,
589
+ return_dict=return_dict,
590
+ )
591
+
592
+ hidden_states = outputs[0]
593
+ logits = self.lm_head(hidden_states).float()
594
+
595
+ loss = None
596
+ if labels is not None:
597
+ # Shift so that tokens < n predict n
598
+ shift_logits = logits[..., :-1, :].contiguous()
599
+ shift_labels = labels[..., 1:].contiguous()
600
+ # Flatten the tokens
601
+ loss_fct = CrossEntropyLoss()
602
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
603
+ shift_labels = shift_labels.view(-1)
604
+ # Enable model parallelism
605
+ shift_labels = shift_labels.to(shift_logits.device)
606
+ loss = loss_fct(shift_logits, shift_labels)
607
+
608
+ if not return_dict:
609
+ output = (logits,) + outputs[1:]
610
+ return (loss,) + output if loss is not None else output
611
+
612
+ return CausalLMOutputWithPast(
613
+ loss=loss,
614
+ logits=logits,
615
+ past_key_values=outputs.past_key_values,
616
+ hidden_states=outputs.hidden_states,
617
+ attentions=outputs.attentions,
618
+ )
619
+
620
+ def prepare_inputs_for_generation(
621
+ self,
622
+ input_ids,
623
+ past_key_values: Optional[torch.Tensor] = None,
624
+ attention_mask: Optional[torch.Tensor] = None,
625
+ inputs_embeds: Optional[torch.Tensor] = None,
626
+ **kwargs,
627
+ ):
628
+ # Trim decoder_input_ids if past is used
629
+ if past_key_values and past_key_values[0] is not None:
630
+ input_ids = input_ids[:, -1:]
631
+
632
+ position_ids = kwargs.get("position_ids", None)
633
+ if attention_mask is not None and position_ids is None:
634
+ # Create position_ids on the fly for batch generation
635
+ position_ids = attention_mask.long().cumsum(-1) - 1
636
+ position_ids.masked_fill_(attention_mask == 0, 1)
637
+ if past_key_values:
638
+ position_ids = position_ids[:, -1].unsqueeze(-1)
639
+
640
+ # If `inputs_embeds` are passed, we only want to use them in the 1st generation step
641
+ if inputs_embeds is not None and past_key_values is None:
642
+ model_inputs = {"inputs_embeds": inputs_embeds}
643
+ else:
644
+ model_inputs = {"input_ids": input_ids}
645
+
646
+ model_inputs.update(
647
+ {
648
+ "attention_mask": attention_mask,
649
+ "past_key_values": past_key_values,
650
+ "use_cache": kwargs.get("use_cache"),
651
+ "position_ids": position_ids,
652
+ }
653
+ )
654
+ return model_inputs
655
+
656
+ @staticmethod
657
+ def _reorder_cache(past_key_values, beam_idx):
658
+ reordered_past = ()
659
+ for layer_past in past_key_values:
660
+ reordered_past += (
661
+ tuple(
662
+ past_state.index_select(0, beam_idx.to(past_state.device))
663
+ for past_state in layer_past
664
+ ),
665
+ )
666
+ return reordered_past
667
+
668
+
669
+ HelpingAIConfig.register_for_auto_class()
670
+ HelpingAIForCausalLM.register_for_auto_class("AutoModelForCausalLM")