kmfoda commited on
Commit
5d99280
·
1 Parent(s): efaf414

Epoch 0. Batch Size 0. Peers 0.

Browse files
config.json CHANGED
@@ -1,32 +1,32 @@
1
  {
2
- "_name_or_path": "distributed/optimized-gpt2-1b",
3
  "activation_function": "gelu_new",
4
  "all_reduce_scores": {
5
  "0": "NON_PARTICIPATING",
6
  "1": "NON_PARTICIPATING",
7
  "10": "NON_PARTICIPATING",
8
  "100": "NON_PARTICIPATING",
9
- "101": "SUCCESS",
10
  "102": "NON_PARTICIPATING",
11
  "103": "NON_PARTICIPATING",
12
- "104": "SUCCESS",
13
- "105": "SUCCESS",
14
- "106": "SUCCESS",
15
  "107": "NON_PARTICIPATING",
16
  "108": "NON_PARTICIPATING",
17
  "109": "NON_PARTICIPATING",
18
- "11": "SUCCESS",
19
  "110": "NON_PARTICIPATING",
20
  "111": "NON_PARTICIPATING",
21
  "112": "NON_PARTICIPATING",
22
  "113": "NON_PARTICIPATING",
23
- "114": "SUCCESS",
24
- "115": "SUCCESS",
25
  "116": "NON_PARTICIPATING",
26
- "117": "SUCCESS",
27
  "118": "NON_PARTICIPATING",
28
- "119": "SUCCESS",
29
- "12": "SUCCESS",
30
  "120": "NON_PARTICIPATING",
31
  "121": "NON_PARTICIPATING",
32
  "122": "NON_PARTICIPATING",
@@ -37,12 +37,12 @@
37
  "127": "NON_PARTICIPATING",
38
  "128": "NON_PARTICIPATING",
39
  "129": "NON_PARTICIPATING",
40
- "13": "SUCCESS",
41
  "130": "NON_PARTICIPATING",
42
  "131": "NON_PARTICIPATING",
43
  "132": "NON_PARTICIPATING",
44
  "133": "NON_PARTICIPATING",
45
- "134": "SUCCESS",
46
  "135": "NON_PARTICIPATING",
47
  "136": "NON_PARTICIPATING",
48
  "137": "NON_PARTICIPATING",
@@ -50,9 +50,9 @@
50
  "139": "NON_PARTICIPATING",
51
  "14": "NON_PARTICIPATING",
52
  "140": "NON_PARTICIPATING",
53
- "141": "SUCCESS",
54
  "142": "NON_PARTICIPATING",
55
- "143": "SUCCESS",
56
  "144": "NON_PARTICIPATING",
57
  "145": "NON_PARTICIPATING",
58
  "146": "NON_PARTICIPATING",
@@ -61,16 +61,16 @@
61
  "149": "NON_PARTICIPATING",
62
  "15": "NON_PARTICIPATING",
63
  "150": "NON_PARTICIPATING",
64
- "151": "SUCCESS",
65
  "152": "NON_PARTICIPATING",
66
  "153": "NON_PARTICIPATING",
67
- "154": "SUCCESS",
68
  "155": "NON_PARTICIPATING",
69
- "156": "SUCCESS",
70
  "157": "NON_PARTICIPATING",
71
  "158": "NON_PARTICIPATING",
72
- "159": "SUCCESS",
73
- "16": "SUCCESS",
74
  "160": "NON_PARTICIPATING",
75
  "161": "NON_PARTICIPATING",
76
  "162": "NON_PARTICIPATING",
@@ -90,8 +90,8 @@
90
  "175": "NON_PARTICIPATING",
91
  "176": "NON_PARTICIPATING",
92
  "177": "NON_PARTICIPATING",
93
- "178": "SUCCESS",
94
- "179": "SUCCESS",
95
  "18": "NON_PARTICIPATING",
96
  "180": "NON_PARTICIPATING",
97
  "181": "NON_PARTICIPATING",
@@ -109,7 +109,7 @@
109
  "192": "NON_PARTICIPATING",
110
  "193": "NON_PARTICIPATING",
111
  "194": "NON_PARTICIPATING",
112
- "195": "SUCCESS",
113
  "196": "NON_PARTICIPATING",
114
  "197": "NON_PARTICIPATING",
115
  "198": "NON_PARTICIPATING",
@@ -117,27 +117,27 @@
117
  "2": "NON_PARTICIPATING",
118
  "20": "NON_PARTICIPATING",
119
  "200": "NON_PARTICIPATING",
120
- "201": "SUCCESS",
121
- "202": "SUCCESS",
122
  "203": "NON_PARTICIPATING",
123
- "204": "SUCCESS",
124
  "205": "NON_PARTICIPATING",
125
  "206": "NON_PARTICIPATING",
126
  "207": "NON_PARTICIPATING",
127
  "208": "NON_PARTICIPATING",
128
- "209": "SUCCESS",
129
  "21": "NON_PARTICIPATING",
130
  "210": "NON_PARTICIPATING",
131
  "211": "NON_PARTICIPATING",
132
  "212": "NON_PARTICIPATING",
133
- "213": "SUCCESS",
134
  "214": "NON_PARTICIPATING",
135
  "215": "NON_PARTICIPATING",
136
- "216": "SUCCESS",
137
  "217": "NON_PARTICIPATING",
138
  "218": "NON_PARTICIPATING",
139
  "219": "NON_PARTICIPATING",
140
- "22": "SUCCESS",
141
  "220": "NON_PARTICIPATING",
142
  "221": "NON_PARTICIPATING",
143
  "222": "NON_PARTICIPATING",
@@ -147,20 +147,20 @@
147
  "226": "NON_PARTICIPATING",
148
  "227": "NON_PARTICIPATING",
149
  "228": "NON_PARTICIPATING",
150
- "229": "SUCCESS",
151
  "23": "NON_PARTICIPATING",
152
  "230": "NON_PARTICIPATING",
153
  "231": "NON_PARTICIPATING",
154
  "232": "NON_PARTICIPATING",
155
  "233": "NON_PARTICIPATING",
156
  "234": "NON_PARTICIPATING",
157
- "235": "SUCCESS",
158
- "236": "SUCCESS",
159
  "237": "NON_PARTICIPATING",
160
- "238": "SUCCESS",
161
- "239": "SUCCESS",
162
  "24": "NON_PARTICIPATING",
163
- "240": "SUCCESS",
164
  "241": "NON_PARTICIPATING",
165
  "242": "NON_PARTICIPATING",
166
  "243": "NON_PARTICIPATING",
@@ -170,7 +170,7 @@
170
  "247": "NON_PARTICIPATING",
171
  "248": "NON_PARTICIPATING",
172
  "249": "NON_PARTICIPATING",
173
- "25": "SUCCESS",
174
  "250": "NON_PARTICIPATING",
175
  "251": "NON_PARTICIPATING",
176
  "252": "NON_PARTICIPATING",
@@ -192,71 +192,71 @@
192
  "37": "NON_PARTICIPATING",
193
  "38": "NON_PARTICIPATING",
194
  "39": "NON_PARTICIPATING",
195
- "4": "SUCCESS",
196
  "40": "NON_PARTICIPATING",
197
  "41": "NON_PARTICIPATING",
198
  "42": "NON_PARTICIPATING",
199
  "43": "NON_PARTICIPATING",
200
  "44": "NON_PARTICIPATING",
201
- "45": "SUCCESS",
202
  "46": "NON_PARTICIPATING",
203
  "47": "NON_PARTICIPATING",
204
- "48": "SUCCESS",
205
  "49": "NON_PARTICIPATING",
206
  "5": "NON_PARTICIPATING",
207
  "50": "NON_PARTICIPATING",
208
  "51": "NON_PARTICIPATING",
209
- "52": "SUCCESS",
210
  "53": "NON_PARTICIPATING",
211
  "54": "NON_PARTICIPATING",
212
  "55": "NON_PARTICIPATING",
213
- "56": "SUCCESS",
214
  "57": "NON_PARTICIPATING",
215
  "58": "NON_PARTICIPATING",
216
  "59": "NON_PARTICIPATING",
217
- "6": "SUCCESS",
218
  "60": "NON_PARTICIPATING",
219
  "61": "NON_PARTICIPATING",
220
- "62": "SUCCESS",
221
- "63": "SUCCESS",
222
  "64": "NON_PARTICIPATING",
223
- "65": "SUCCESS",
224
- "66": "SUCCESS",
225
  "67": "NON_PARTICIPATING",
226
  "68": "NON_PARTICIPATING",
227
  "69": "NON_PARTICIPATING",
228
- "7": "SUCCESS",
229
  "70": "NON_PARTICIPATING",
230
  "71": "NON_PARTICIPATING",
231
  "72": "NON_PARTICIPATING",
232
  "73": "NON_PARTICIPATING",
233
- "74": "SUCCESS",
234
- "75": "SUCCESS",
235
  "76": "NON_PARTICIPATING",
236
- "77": "SUCCESS",
237
  "78": "NON_PARTICIPATING",
238
  "79": "NON_PARTICIPATING",
239
  "8": "NON_PARTICIPATING",
240
- "80": "SUCCESS",
241
  "81": "NON_PARTICIPATING",
242
  "82": "NON_PARTICIPATING",
243
  "83": "NON_PARTICIPATING",
244
- "84": "SUCCESS",
245
- "85": "SUCCESS",
246
- "86": "SUCCESS",
247
  "87": "NON_PARTICIPATING",
248
- "88": "SUCCESS",
249
  "89": "NON_PARTICIPATING",
250
- "9": "SUCCESS",
251
  "90": "NON_PARTICIPATING",
252
  "91": "NON_PARTICIPATING",
253
  "92": "NON_PARTICIPATING",
254
  "93": "NON_PARTICIPATING",
255
  "94": "NON_PARTICIPATING",
256
  "95": "NON_PARTICIPATING",
257
- "96": "SUCCESS",
258
  "97": "NON_PARTICIPATING",
259
- "98": "SUCCESS",
260
  "99": "NON_PARTICIPATING"
261
  },
262
  "architectures": [
@@ -264,8 +264,8 @@
264
  ],
265
  "attn_pdrop": 0.1,
266
  "auto_map": {
267
- "AutoConfig": "distributed/optimized-gpt2-500m--configuration_gpt_optimized.GPTOptimConfig",
268
- "AutoModelForCausalLM": "distributed/optimized-gpt2-500m--modeling_gpt_optimized.GPTOptim"
269
  },
270
  "block_size": 1024,
271
  "bos_token_id": 50256,
 
1
  {
2
+ "_name_or_path": "/root/optimized-gpt2-2b",
3
  "activation_function": "gelu_new",
4
  "all_reduce_scores": {
5
  "0": "NON_PARTICIPATING",
6
  "1": "NON_PARTICIPATING",
7
  "10": "NON_PARTICIPATING",
8
  "100": "NON_PARTICIPATING",
9
+ "101": "NON_PARTICIPATING",
10
  "102": "NON_PARTICIPATING",
11
  "103": "NON_PARTICIPATING",
12
+ "104": "NON_PARTICIPATING",
13
+ "105": "NON_PARTICIPATING",
14
+ "106": "NON_PARTICIPATING",
15
  "107": "NON_PARTICIPATING",
16
  "108": "NON_PARTICIPATING",
17
  "109": "NON_PARTICIPATING",
18
+ "11": "NON_PARTICIPATING",
19
  "110": "NON_PARTICIPATING",
20
  "111": "NON_PARTICIPATING",
21
  "112": "NON_PARTICIPATING",
22
  "113": "NON_PARTICIPATING",
23
+ "114": "NON_PARTICIPATING",
24
+ "115": "NON_PARTICIPATING",
25
  "116": "NON_PARTICIPATING",
26
+ "117": "NON_PARTICIPATING",
27
  "118": "NON_PARTICIPATING",
28
+ "119": "NON_PARTICIPATING",
29
+ "12": "NON_PARTICIPATING",
30
  "120": "NON_PARTICIPATING",
31
  "121": "NON_PARTICIPATING",
32
  "122": "NON_PARTICIPATING",
 
37
  "127": "NON_PARTICIPATING",
38
  "128": "NON_PARTICIPATING",
39
  "129": "NON_PARTICIPATING",
40
+ "13": "NON_PARTICIPATING",
41
  "130": "NON_PARTICIPATING",
42
  "131": "NON_PARTICIPATING",
43
  "132": "NON_PARTICIPATING",
44
  "133": "NON_PARTICIPATING",
45
+ "134": "NON_PARTICIPATING",
46
  "135": "NON_PARTICIPATING",
47
  "136": "NON_PARTICIPATING",
48
  "137": "NON_PARTICIPATING",
 
50
  "139": "NON_PARTICIPATING",
51
  "14": "NON_PARTICIPATING",
52
  "140": "NON_PARTICIPATING",
53
+ "141": "NON_PARTICIPATING",
54
  "142": "NON_PARTICIPATING",
55
+ "143": "NON_PARTICIPATING",
56
  "144": "NON_PARTICIPATING",
57
  "145": "NON_PARTICIPATING",
58
  "146": "NON_PARTICIPATING",
 
61
  "149": "NON_PARTICIPATING",
62
  "15": "NON_PARTICIPATING",
63
  "150": "NON_PARTICIPATING",
64
+ "151": "NON_PARTICIPATING",
65
  "152": "NON_PARTICIPATING",
66
  "153": "NON_PARTICIPATING",
67
+ "154": "NON_PARTICIPATING",
68
  "155": "NON_PARTICIPATING",
69
+ "156": "NON_PARTICIPATING",
70
  "157": "NON_PARTICIPATING",
71
  "158": "NON_PARTICIPATING",
72
+ "159": "NON_PARTICIPATING",
73
+ "16": "NON_PARTICIPATING",
74
  "160": "NON_PARTICIPATING",
75
  "161": "NON_PARTICIPATING",
76
  "162": "NON_PARTICIPATING",
 
90
  "175": "NON_PARTICIPATING",
91
  "176": "NON_PARTICIPATING",
92
  "177": "NON_PARTICIPATING",
93
+ "178": "NON_PARTICIPATING",
94
+ "179": "NON_PARTICIPATING",
95
  "18": "NON_PARTICIPATING",
96
  "180": "NON_PARTICIPATING",
97
  "181": "NON_PARTICIPATING",
 
109
  "192": "NON_PARTICIPATING",
110
  "193": "NON_PARTICIPATING",
111
  "194": "NON_PARTICIPATING",
112
+ "195": "NON_PARTICIPATING",
113
  "196": "NON_PARTICIPATING",
114
  "197": "NON_PARTICIPATING",
115
  "198": "NON_PARTICIPATING",
 
117
  "2": "NON_PARTICIPATING",
118
  "20": "NON_PARTICIPATING",
119
  "200": "NON_PARTICIPATING",
120
+ "201": "NON_PARTICIPATING",
121
+ "202": "NON_PARTICIPATING",
122
  "203": "NON_PARTICIPATING",
123
+ "204": "NON_PARTICIPATING",
124
  "205": "NON_PARTICIPATING",
125
  "206": "NON_PARTICIPATING",
126
  "207": "NON_PARTICIPATING",
127
  "208": "NON_PARTICIPATING",
128
+ "209": "NON_PARTICIPATING",
129
  "21": "NON_PARTICIPATING",
130
  "210": "NON_PARTICIPATING",
131
  "211": "NON_PARTICIPATING",
132
  "212": "NON_PARTICIPATING",
133
+ "213": "NON_PARTICIPATING",
134
  "214": "NON_PARTICIPATING",
135
  "215": "NON_PARTICIPATING",
136
+ "216": "NON_PARTICIPATING",
137
  "217": "NON_PARTICIPATING",
138
  "218": "NON_PARTICIPATING",
139
  "219": "NON_PARTICIPATING",
140
+ "22": "NON_PARTICIPATING",
141
  "220": "NON_PARTICIPATING",
142
  "221": "NON_PARTICIPATING",
143
  "222": "NON_PARTICIPATING",
 
147
  "226": "NON_PARTICIPATING",
148
  "227": "NON_PARTICIPATING",
149
  "228": "NON_PARTICIPATING",
150
+ "229": "NON_PARTICIPATING",
151
  "23": "NON_PARTICIPATING",
152
  "230": "NON_PARTICIPATING",
153
  "231": "NON_PARTICIPATING",
154
  "232": "NON_PARTICIPATING",
155
  "233": "NON_PARTICIPATING",
156
  "234": "NON_PARTICIPATING",
157
+ "235": "NON_PARTICIPATING",
158
+ "236": "NON_PARTICIPATING",
159
  "237": "NON_PARTICIPATING",
160
+ "238": "NON_PARTICIPATING",
161
+ "239": "NON_PARTICIPATING",
162
  "24": "NON_PARTICIPATING",
163
+ "240": "NON_PARTICIPATING",
164
  "241": "NON_PARTICIPATING",
165
  "242": "NON_PARTICIPATING",
166
  "243": "NON_PARTICIPATING",
 
170
  "247": "NON_PARTICIPATING",
171
  "248": "NON_PARTICIPATING",
172
  "249": "NON_PARTICIPATING",
173
+ "25": "NON_PARTICIPATING",
174
  "250": "NON_PARTICIPATING",
175
  "251": "NON_PARTICIPATING",
176
  "252": "NON_PARTICIPATING",
 
192
  "37": "NON_PARTICIPATING",
193
  "38": "NON_PARTICIPATING",
194
  "39": "NON_PARTICIPATING",
195
+ "4": "NON_PARTICIPATING",
196
  "40": "NON_PARTICIPATING",
197
  "41": "NON_PARTICIPATING",
198
  "42": "NON_PARTICIPATING",
199
  "43": "NON_PARTICIPATING",
200
  "44": "NON_PARTICIPATING",
201
+ "45": "NON_PARTICIPATING",
202
  "46": "NON_PARTICIPATING",
203
  "47": "NON_PARTICIPATING",
204
+ "48": "NON_PARTICIPATING",
205
  "49": "NON_PARTICIPATING",
206
  "5": "NON_PARTICIPATING",
207
  "50": "NON_PARTICIPATING",
208
  "51": "NON_PARTICIPATING",
209
+ "52": "NON_PARTICIPATING",
210
  "53": "NON_PARTICIPATING",
211
  "54": "NON_PARTICIPATING",
212
  "55": "NON_PARTICIPATING",
213
+ "56": "NON_PARTICIPATING",
214
  "57": "NON_PARTICIPATING",
215
  "58": "NON_PARTICIPATING",
216
  "59": "NON_PARTICIPATING",
217
+ "6": "NON_PARTICIPATING",
218
  "60": "NON_PARTICIPATING",
219
  "61": "NON_PARTICIPATING",
220
+ "62": "NON_PARTICIPATING",
221
+ "63": "NON_PARTICIPATING",
222
  "64": "NON_PARTICIPATING",
223
+ "65": "NON_PARTICIPATING",
224
+ "66": "NON_PARTICIPATING",
225
  "67": "NON_PARTICIPATING",
226
  "68": "NON_PARTICIPATING",
227
  "69": "NON_PARTICIPATING",
228
+ "7": "NON_PARTICIPATING",
229
  "70": "NON_PARTICIPATING",
230
  "71": "NON_PARTICIPATING",
231
  "72": "NON_PARTICIPATING",
232
  "73": "NON_PARTICIPATING",
233
+ "74": "NON_PARTICIPATING",
234
+ "75": "NON_PARTICIPATING",
235
  "76": "NON_PARTICIPATING",
236
+ "77": "NON_PARTICIPATING",
237
  "78": "NON_PARTICIPATING",
238
  "79": "NON_PARTICIPATING",
239
  "8": "NON_PARTICIPATING",
240
+ "80": "NON_PARTICIPATING",
241
  "81": "NON_PARTICIPATING",
242
  "82": "NON_PARTICIPATING",
243
  "83": "NON_PARTICIPATING",
244
+ "84": "NON_PARTICIPATING",
245
+ "85": "NON_PARTICIPATING",
246
+ "86": "NON_PARTICIPATING",
247
  "87": "NON_PARTICIPATING",
248
+ "88": "NON_PARTICIPATING",
249
  "89": "NON_PARTICIPATING",
250
+ "9": "NON_PARTICIPATING",
251
  "90": "NON_PARTICIPATING",
252
  "91": "NON_PARTICIPATING",
253
  "92": "NON_PARTICIPATING",
254
  "93": "NON_PARTICIPATING",
255
  "94": "NON_PARTICIPATING",
256
  "95": "NON_PARTICIPATING",
257
+ "96": "NON_PARTICIPATING",
258
  "97": "NON_PARTICIPATING",
259
+ "98": "NON_PARTICIPATING",
260
  "99": "NON_PARTICIPATING"
261
  },
262
  "architectures": [
 
264
  ],
265
  "attn_pdrop": 0.1,
266
  "auto_map": {
267
+ "AutoConfig": "configuration_gpt_optimized.GPTOptimConfig",
268
+ "AutoModelForCausalLM": "modeling_gpt_optimized.GPTOptim"
269
  },
270
  "block_size": 1024,
271
  "bos_token_id": 50256,
configuration_gpt_optimized.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig, GPT2Config
2
+ from typing import List
3
+
4
+
5
+ class GPTOptimConfig(GPT2Config):
6
+ model_type = "gpt_optimized"
7
+
8
+ def __init__(
9
+ self,
10
+ block_size: int = 1024, # max sequence length
11
+ vocab_size: int = 50257, # number of tokens: 50,000 BPE merges + 256 bytes tokens + 1 <|endoftext|> token
12
+ n_layer: int = 16, # number of layers
13
+ n_head: int = 16, # number of heads
14
+ n_embd: int = 1024, # embedding dimension
15
+ **kwargs,
16
+ ):
17
+ super().__init__(**kwargs)
18
+ self.block_size = block_size
19
+ self.vocab_size = vocab_size
20
+ self.n_layer = n_layer
21
+ self.n_head = n_head
22
+ self.n_embd = n_embd
model-00001-of-00002.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3f5ff5109f97698ac245ba95aec86c313a4f1315f0c25be9733303d0f747f8ea
3
- size 4975499944
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da60df4383c9d634d7cc53c50054860a25201fca04b7ba2222154c341c81cb64
3
+ size 4975530824
model-00002-of-00002.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:82a11e07e82a54f91eddc7995fab9375336871b8701cc500ef6590e4a6f6faf4
3
  size 3075942944
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40f5cead8254114a990ff56a6870ab9b539eab67512e449d110dffba8fd755c0
3
  size 3075942944
model.safetensors.index.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "metadata": {
3
- "total_size": 8051383872
4
  },
5
  "weight_map": {
6
  "model.transformer.h.0.attn.c_attn.bias": "model-00001-of-00002.safetensors",
@@ -533,7 +533,11 @@
533
  "model.transformer.h.9.mlp.c_proj.weight": "model-00001-of-00002.safetensors",
534
  "model.transformer.ln_f.bias": "model-00002-of-00002.safetensors",
535
  "model.transformer.ln_f.weight": "model-00002-of-00002.safetensors",
 
 
536
  "model.transformer.wpe.weight": "model-00001-of-00002.safetensors",
 
 
537
  "model.transformer.wte.weight": "model-00001-of-00002.safetensors"
538
  }
539
  }
 
1
  {
2
  "metadata": {
3
+ "total_size": 8051414336
4
  },
5
  "weight_map": {
6
  "model.transformer.h.0.attn.c_attn.bias": "model-00001-of-00002.safetensors",
 
533
  "model.transformer.h.9.mlp.c_proj.weight": "model-00001-of-00002.safetensors",
534
  "model.transformer.ln_f.bias": "model-00002-of-00002.safetensors",
535
  "model.transformer.ln_f.weight": "model-00002-of-00002.safetensors",
536
+ "model.transformer.wpe.norm.bias": "model-00001-of-00002.safetensors",
537
+ "model.transformer.wpe.norm.weight": "model-00001-of-00002.safetensors",
538
  "model.transformer.wpe.weight": "model-00001-of-00002.safetensors",
539
+ "model.transformer.wte.norm.bias": "model-00001-of-00002.safetensors",
540
+ "model.transformer.wte.norm.weight": "model-00001-of-00002.safetensors",
541
  "model.transformer.wte.weight": "model-00001-of-00002.safetensors"
542
  }
543
  }
modeling_gpt_optimized.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import bitsandbytes
4
+ from torch.nn import CrossEntropyLoss, functional as F
5
+ from transformers import PreTrainedModel, GPT2PreTrainedModel
6
+ from .configuration_gpt_optimized import GPTOptimConfig
7
+ from transformers.modeling_outputs import CausalLMOutputWithCrossAttentions, BaseModelOutputWithPastAndCrossAttentions
8
+ from transformers.utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
9
+ from transformers.modeling_attn_mask_utils import _prepare_4d_attention_mask_for_sdpa, _prepare_4d_causal_attention_mask_for_sdpa
10
+ from typing import Optional, Tuple, Union
11
+
12
+ _CHECKPOINT_FOR_DOC = "openai-community/gpt2"
13
+ _CONFIG_FOR_DOC = "GPT2Config"
14
+
15
+ GPT2_INPUTS_DOCSTRING = r"""
16
+ Args:
17
+ input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
18
+ `input_ids_length` = `sequence_length` if `past_key_values` is `None` else
19
+ `past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of input
20
+ sequence tokens in the vocabulary.
21
+ If `past_key_values` is used, only `input_ids` that do not have their past calculated should be passed as
22
+ `input_ids`.
23
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
24
+ [`PreTrainedTokenizer.__call__`] for details.
25
+ [What are input IDs?](../glossary#input-ids)
26
+ past_key_values (`Tuple[Tuple[torch.Tensor]]` of length `config.n_layers`):
27
+ Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see
28
+ `past_key_values` output below). Can be used to speed up sequential decoding. The `input_ids` which have
29
+ their past given to this model should not be passed as `input_ids` as they have already been computed.
30
+ attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
31
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
32
+ - 1 for tokens that are **not masked**,
33
+ - 0 for tokens that are **masked**.
34
+ If `past_key_values` is used, `attention_mask` needs to contain the masking strategy that was used for
35
+ `past_key_values`. In other words, the `attention_mask` always has to have the length:
36
+ `len(past_key_values) + len(input_ids)`
37
+ [What are attention masks?](../glossary#attention-mask)
38
+ token_type_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`, *optional*):
39
+ Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
40
+ 1]`:
41
+ - 0 corresponds to a *sentence A* token,
42
+ - 1 corresponds to a *sentence B* token.
43
+ [What are token type IDs?](../glossary#token-type-ids)
44
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
45
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
46
+ config.max_position_embeddings - 1]`.
47
+ [What are position IDs?](../glossary#position-ids)
48
+ head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
49
+ Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:
50
+ - 1 indicates the head is **not masked**,
51
+ - 0 indicates the head is **masked**.
52
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
53
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
54
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
55
+ model's internal embedding lookup matrix.
56
+ If `past_key_values` is used, optionally only the last `inputs_embeds` have to be input (see
57
+ `past_key_values`).
58
+ use_cache (`bool`, *optional*):
59
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
60
+ `past_key_values`).
61
+ output_attentions (`bool`, *optional*):
62
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
63
+ tensors for more detail.
64
+ output_hidden_states (`bool`, *optional*):
65
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
66
+ more detail.
67
+ return_dict (`bool`, *optional*):
68
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
69
+ """
70
+
71
+ class CausalSelfAttention(nn.Module):
72
+
73
+ def __init__(self, config):
74
+ super().__init__()
75
+ assert config.n_embd % config.n_head == 0
76
+ # key, query, value projections for all heads, but in a batch
77
+ self.c_attn = nn.Linear(config.n_embd, 3 * config.n_embd)
78
+ # output projection
79
+ self.c_proj = nn.Linear(config.n_embd, config.n_embd)
80
+ self.c_proj.NANOGPT_SCALE_INIT = 1
81
+ # regularization
82
+ self.n_head = config.n_head
83
+ self.n_embd = config.n_embd
84
+
85
+ def forward(self, x):
86
+ B, T, C = x.size() # batch size, sequence length, embedding dimensionality (n_embd)
87
+ # calculate query, key, values for all heads in batch and move head forward to be the batch dim
88
+ # nh is "number of heads", hs is "head size", and C (number of channels) = nh * hs
89
+ # e.g. in GPT-2 (124M), n_head=12, hs=64, so nh*hs=C=768 channels in the Transformer
90
+ qkv = self.c_attn(x)
91
+ q, k, v = qkv.split(self.n_embd, dim=2)
92
+ k = k.view(B, T, self.n_head, C // self.n_head).transpose(1, 2) # (B, nh, T, hs)
93
+ q = q.view(B, T, self.n_head, C // self.n_head).transpose(1, 2) # (B, nh, T, hs)
94
+ v = v.view(B, T, self.n_head, C // self.n_head).transpose(1, 2) # (B, nh, T, hs)
95
+ y = F.scaled_dot_product_attention(q, k, v, is_causal=True) # flash attention
96
+ y = y.transpose(1, 2).contiguous().view(B, T, C) # re-assemble all head outputs side by side
97
+ # output projection
98
+ y = self.c_proj(y)
99
+ return y
100
+
101
+ class MLP(nn.Module):
102
+
103
+ def __init__(self, config):
104
+ super().__init__()
105
+ self.c_fc = nn.Linear(config.n_embd, 4 * config.n_embd)
106
+ self.gelu = nn.GELU(approximate='tanh')
107
+ self.c_proj = nn.Linear(4 * config.n_embd, config.n_embd)
108
+ self.c_proj.NANOGPT_SCALE_INIT = 1
109
+
110
+ def forward(self, x):
111
+ x = self.c_fc(x)
112
+ x = self.gelu(x)
113
+ x = self.c_proj(x)
114
+ return x
115
+
116
+ class Block(nn.Module):
117
+
118
+ def __init__(self, config):
119
+ super().__init__()
120
+ self.ln_1 = nn.LayerNorm(config.n_embd)
121
+ self.attn = CausalSelfAttention(config)
122
+ self.ln_2 = nn.LayerNorm(config.n_embd)
123
+ self.mlp = MLP(config)
124
+
125
+ def forward(self, x):
126
+ x = x + self.attn(self.ln_1(x))
127
+ x = x + self.mlp(self.ln_2(x))
128
+ return x
129
+
130
+ class GPT(nn.Module):
131
+
132
+ def __init__(self, config):
133
+ super().__init__()
134
+ self.config = config
135
+
136
+ self.transformer = nn.ModuleDict(dict(
137
+ wte = bitsandbytes.nn.StableEmbedding(config.vocab_size, config.n_embd),
138
+ wpe = bitsandbytes.nn.StableEmbedding(config.block_size, config.n_embd),
139
+ h = nn.ModuleList([Block(config) for _ in range(config.n_layer)]),
140
+ ln_f = nn.LayerNorm(config.n_embd),
141
+ ))
142
+ self.lm_head = nn.Linear(config.n_embd, config.vocab_size, bias=False)
143
+
144
+ # weight sharing scheme
145
+ self.transformer.wte.weight = self.lm_head.weight
146
+
147
+ # init params
148
+ self.apply(self._init_weights)
149
+
150
+ def _init_weights(self, module):
151
+ if isinstance(module, nn.Linear):
152
+ std = 0.02
153
+ if hasattr(module, 'NANOGPT_SCALE_INIT'):
154
+ std *= (2 * self.config.n_layer) ** -0.5
155
+ torch.nn.init.normal_(module.weight, mean=0.0, std=std)
156
+ if module.bias is not None:
157
+ torch.nn.init.zeros_(module.bias)
158
+ elif isinstance(module, nn.Embedding):
159
+ torch.nn.init.normal_(module.weight, mean=0.0, std=0.02)
160
+
161
+ class GPTOptim(GPT2PreTrainedModel):
162
+ config_class = GPTOptimConfig
163
+
164
+ def __init__(self, config):
165
+ super().__init__(config)
166
+ self.model = GPT(
167
+ config
168
+ )
169
+ self.config = config
170
+
171
+ def forward(self, input_ids, labels=None):
172
+ # input_ids is of shape (B, T)
173
+ B, T = input_ids.size()
174
+ assert T <= self.config.block_size, f"Cannot forward sequence of length {T}, block size is only {self.config.block_size}"
175
+ # forward the token and posisition embeddings
176
+ pos = torch.arange(0, T, dtype=torch.long, device=input_ids.device) # shape (T)
177
+ pos_emb = self.model.transformer.wpe(pos) # position embeddings of shape (T, n_embd)
178
+ tok_emb = self.model.transformer.wte(input_ids) # token embeddings of shape (B, T, n_embd)
179
+ x = tok_emb + pos_emb
180
+ # forward the blocks of the transformer
181
+ for block in self.model.transformer.h:
182
+ x = block(x)
183
+ # forward the final layernorm and the classifier
184
+ x = self.model.transformer.ln_f(x)
185
+ logits = self.model.lm_head(x) # (B, T, vocab_size)
186
+ loss = None
187
+ if labels is not None:
188
+ loss = F.cross_entropy(logits.view(-1, logits.size(-1)), labels.view(-1), ignore_index=self.config.eos_token_id)
189
+ return logits, loss
optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c1c3e9b7f72886b3928354c660c77cc64217de83bab4aece73321c1d91dfecc
3
+ size 2536