louis030195 commited on
Commit
fe556ee
1 Parent(s): f263a51

first commit

Browse files
all_results.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 400.0,
3
+ "eval_loss": 4.94140625,
4
+ "eval_runtime": 3.7873,
5
+ "eval_samples": 258,
6
+ "eval_samples_per_second": 68.123,
7
+ "eval_steps_per_second": 8.713,
8
+ "perplexity": 139.96693973881514,
9
+ "train_loss": 0.4328666927939967,
10
+ "train_runtime": 22235.2418,
11
+ "train_samples": 603,
12
+ "train_samples_per_second": 10.848,
13
+ "train_steps_per_second": 0.684
14
+ }
config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.13.0",
37
+ "use_cache": false,
38
+ "vocab_size": 50257
39
+ }
eval_results.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 400.0,
3
+ "eval_loss": 4.94140625,
4
+ "eval_runtime": 3.7873,
5
+ "eval_samples": 258,
6
+ "eval_samples_per_second": 68.123,
7
+ "eval_steps_per_second": 8.713,
8
+ "perplexity": 139.96693973881514
9
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5bd85b148ef6d5f2ea91cf65ea6ac8daaa7d88454616d84e7ba068352ca9c48b
3
+ size 261495703
runs/Dec18_17-45-49_louis-gpu/1639845963.6867917/events.out.tfevents.1639845963.louis-gpu.3745350.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d948efad1252c97027797802079c99099782cae89c1630fcb9004ec4f17b291
3
+ size 4679
runs/Dec18_17-45-49_louis-gpu/events.out.tfevents.1639845963.louis-gpu.3745350.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ca8ac72d52221b7613f16a8a090f22d5822ba7f69420f5a31134d69cb07eb5e
3
+ size 29150
runs/Dec18_17-45-49_louis-gpu/events.out.tfevents.1639868204.louis-gpu.3745350.2 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7036de84b16ccde7834779e0940820e8d4fa71b7f79ad177f33011d5a1307c75
3
+ size 311
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<|endoftext|>", "eos_token": "<|endoftext|>", "unk_token": "<|endoftext|>"}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"unk_token": "<|endoftext|>", "bos_token": "<|endoftext|>", "eos_token": "<|endoftext|>", "add_prefix_space": false, "model_max_length": 1024, "special_tokens_map_file": null, "name_or_path": "gpt2", "tokenizer_class": "GPT2Tokenizer"}
train_results.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 400.0,
3
+ "train_loss": 0.4328666927939967,
4
+ "train_runtime": 22235.2418,
5
+ "train_samples": 603,
6
+ "train_samples_per_second": 10.848,
7
+ "train_steps_per_second": 0.684
8
+ }
trainer_state.json ADDED
@@ -0,0 +1,813 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 400.0,
5
+ "global_step": 15200,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 5.26,
12
+ "eval_loss": 1.7080078125,
13
+ "eval_runtime": 3.7763,
14
+ "eval_samples_per_second": 68.321,
15
+ "eval_steps_per_second": 8.739,
16
+ "step": 200
17
+ },
18
+ {
19
+ "epoch": 10.53,
20
+ "eval_loss": 1.7001953125,
21
+ "eval_runtime": 3.7858,
22
+ "eval_samples_per_second": 68.149,
23
+ "eval_steps_per_second": 8.717,
24
+ "step": 400
25
+ },
26
+ {
27
+ "epoch": 13.16,
28
+ "learning_rate": 5e-05,
29
+ "loss": 1.671,
30
+ "step": 500
31
+ },
32
+ {
33
+ "epoch": 15.79,
34
+ "eval_loss": 1.7138671875,
35
+ "eval_runtime": 3.7865,
36
+ "eval_samples_per_second": 68.137,
37
+ "eval_steps_per_second": 8.715,
38
+ "step": 600
39
+ },
40
+ {
41
+ "epoch": 21.05,
42
+ "eval_loss": 1.744140625,
43
+ "eval_runtime": 3.7879,
44
+ "eval_samples_per_second": 68.112,
45
+ "eval_steps_per_second": 8.712,
46
+ "step": 800
47
+ },
48
+ {
49
+ "epoch": 26.32,
50
+ "learning_rate": 5e-05,
51
+ "loss": 1.4438,
52
+ "step": 1000
53
+ },
54
+ {
55
+ "epoch": 26.32,
56
+ "eval_loss": 1.794921875,
57
+ "eval_runtime": 3.7869,
58
+ "eval_samples_per_second": 68.13,
59
+ "eval_steps_per_second": 8.714,
60
+ "step": 1000
61
+ },
62
+ {
63
+ "epoch": 31.58,
64
+ "eval_loss": 1.84375,
65
+ "eval_runtime": 3.7879,
66
+ "eval_samples_per_second": 68.112,
67
+ "eval_steps_per_second": 8.712,
68
+ "step": 1200
69
+ },
70
+ {
71
+ "epoch": 36.84,
72
+ "eval_loss": 1.896484375,
73
+ "eval_runtime": 3.7905,
74
+ "eval_samples_per_second": 68.066,
75
+ "eval_steps_per_second": 8.706,
76
+ "step": 1400
77
+ },
78
+ {
79
+ "epoch": 39.47,
80
+ "learning_rate": 5e-05,
81
+ "loss": 1.2806,
82
+ "step": 1500
83
+ },
84
+ {
85
+ "epoch": 42.11,
86
+ "eval_loss": 1.9619140625,
87
+ "eval_runtime": 3.7916,
88
+ "eval_samples_per_second": 68.044,
89
+ "eval_steps_per_second": 8.703,
90
+ "step": 1600
91
+ },
92
+ {
93
+ "epoch": 47.37,
94
+ "eval_loss": 2.01953125,
95
+ "eval_runtime": 3.7897,
96
+ "eval_samples_per_second": 68.08,
97
+ "eval_steps_per_second": 8.708,
98
+ "step": 1800
99
+ },
100
+ {
101
+ "epoch": 52.63,
102
+ "learning_rate": 5e-05,
103
+ "loss": 1.1433,
104
+ "step": 2000
105
+ },
106
+ {
107
+ "epoch": 52.63,
108
+ "eval_loss": 2.068359375,
109
+ "eval_runtime": 3.7891,
110
+ "eval_samples_per_second": 68.091,
111
+ "eval_steps_per_second": 8.709,
112
+ "step": 2000
113
+ },
114
+ {
115
+ "epoch": 57.89,
116
+ "eval_loss": 2.1171875,
117
+ "eval_runtime": 3.7902,
118
+ "eval_samples_per_second": 68.069,
119
+ "eval_steps_per_second": 8.707,
120
+ "step": 2200
121
+ },
122
+ {
123
+ "epoch": 63.16,
124
+ "eval_loss": 2.1953125,
125
+ "eval_runtime": 3.7898,
126
+ "eval_samples_per_second": 68.077,
127
+ "eval_steps_per_second": 8.708,
128
+ "step": 2400
129
+ },
130
+ {
131
+ "epoch": 65.79,
132
+ "learning_rate": 5e-05,
133
+ "loss": 1.027,
134
+ "step": 2500
135
+ },
136
+ {
137
+ "epoch": 68.42,
138
+ "eval_loss": 2.25,
139
+ "eval_runtime": 3.7881,
140
+ "eval_samples_per_second": 68.108,
141
+ "eval_steps_per_second": 8.711,
142
+ "step": 2600
143
+ },
144
+ {
145
+ "epoch": 73.68,
146
+ "eval_loss": 2.291015625,
147
+ "eval_runtime": 3.7876,
148
+ "eval_samples_per_second": 68.118,
149
+ "eval_steps_per_second": 8.713,
150
+ "step": 2800
151
+ },
152
+ {
153
+ "epoch": 78.95,
154
+ "learning_rate": 5e-05,
155
+ "loss": 0.9216,
156
+ "step": 3000
157
+ },
158
+ {
159
+ "epoch": 78.95,
160
+ "eval_loss": 2.34765625,
161
+ "eval_runtime": 3.7885,
162
+ "eval_samples_per_second": 68.101,
163
+ "eval_steps_per_second": 8.711,
164
+ "step": 3000
165
+ },
166
+ {
167
+ "epoch": 84.21,
168
+ "eval_loss": 2.423828125,
169
+ "eval_runtime": 3.7907,
170
+ "eval_samples_per_second": 68.062,
171
+ "eval_steps_per_second": 8.706,
172
+ "step": 3200
173
+ },
174
+ {
175
+ "epoch": 89.47,
176
+ "eval_loss": 2.482421875,
177
+ "eval_runtime": 3.7903,
178
+ "eval_samples_per_second": 68.068,
179
+ "eval_steps_per_second": 8.706,
180
+ "step": 3400
181
+ },
182
+ {
183
+ "epoch": 92.11,
184
+ "learning_rate": 5e-05,
185
+ "loss": 0.8209,
186
+ "step": 3500
187
+ },
188
+ {
189
+ "epoch": 94.74,
190
+ "eval_loss": 2.529296875,
191
+ "eval_runtime": 3.7863,
192
+ "eval_samples_per_second": 68.14,
193
+ "eval_steps_per_second": 8.716,
194
+ "step": 3600
195
+ },
196
+ {
197
+ "epoch": 100.0,
198
+ "eval_loss": 2.5859375,
199
+ "eval_runtime": 3.785,
200
+ "eval_samples_per_second": 68.164,
201
+ "eval_steps_per_second": 8.719,
202
+ "step": 3800
203
+ },
204
+ {
205
+ "epoch": 105.26,
206
+ "learning_rate": 5e-05,
207
+ "loss": 0.7231,
208
+ "step": 4000
209
+ },
210
+ {
211
+ "epoch": 105.26,
212
+ "eval_loss": 2.6640625,
213
+ "eval_runtime": 3.7856,
214
+ "eval_samples_per_second": 68.153,
215
+ "eval_steps_per_second": 8.717,
216
+ "step": 4000
217
+ },
218
+ {
219
+ "epoch": 110.53,
220
+ "eval_loss": 2.703125,
221
+ "eval_runtime": 3.7862,
222
+ "eval_samples_per_second": 68.142,
223
+ "eval_steps_per_second": 8.716,
224
+ "step": 4200
225
+ },
226
+ {
227
+ "epoch": 115.79,
228
+ "eval_loss": 2.78515625,
229
+ "eval_runtime": 3.7894,
230
+ "eval_samples_per_second": 68.084,
231
+ "eval_steps_per_second": 8.708,
232
+ "step": 4400
233
+ },
234
+ {
235
+ "epoch": 118.42,
236
+ "learning_rate": 5e-05,
237
+ "loss": 0.6281,
238
+ "step": 4500
239
+ },
240
+ {
241
+ "epoch": 121.05,
242
+ "eval_loss": 2.84375,
243
+ "eval_runtime": 3.7883,
244
+ "eval_samples_per_second": 68.105,
245
+ "eval_steps_per_second": 8.711,
246
+ "step": 4600
247
+ },
248
+ {
249
+ "epoch": 126.32,
250
+ "eval_loss": 2.921875,
251
+ "eval_runtime": 3.79,
252
+ "eval_samples_per_second": 68.074,
253
+ "eval_steps_per_second": 8.707,
254
+ "step": 4800
255
+ },
256
+ {
257
+ "epoch": 131.58,
258
+ "learning_rate": 5e-05,
259
+ "loss": 0.5384,
260
+ "step": 5000
261
+ },
262
+ {
263
+ "epoch": 131.58,
264
+ "eval_loss": 2.994140625,
265
+ "eval_runtime": 3.7895,
266
+ "eval_samples_per_second": 68.082,
267
+ "eval_steps_per_second": 8.708,
268
+ "step": 5000
269
+ },
270
+ {
271
+ "epoch": 136.84,
272
+ "eval_loss": 3.048828125,
273
+ "eval_runtime": 3.7912,
274
+ "eval_samples_per_second": 68.053,
275
+ "eval_steps_per_second": 8.704,
276
+ "step": 5200
277
+ },
278
+ {
279
+ "epoch": 142.11,
280
+ "eval_loss": 3.107421875,
281
+ "eval_runtime": 3.7872,
282
+ "eval_samples_per_second": 68.123,
283
+ "eval_steps_per_second": 8.713,
284
+ "step": 5400
285
+ },
286
+ {
287
+ "epoch": 144.74,
288
+ "learning_rate": 5e-05,
289
+ "loss": 0.4574,
290
+ "step": 5500
291
+ },
292
+ {
293
+ "epoch": 147.37,
294
+ "eval_loss": 3.169921875,
295
+ "eval_runtime": 3.7886,
296
+ "eval_samples_per_second": 68.1,
297
+ "eval_steps_per_second": 8.71,
298
+ "step": 5600
299
+ },
300
+ {
301
+ "epoch": 152.63,
302
+ "eval_loss": 3.2265625,
303
+ "eval_runtime": 3.7924,
304
+ "eval_samples_per_second": 68.03,
305
+ "eval_steps_per_second": 8.702,
306
+ "step": 5800
307
+ },
308
+ {
309
+ "epoch": 157.89,
310
+ "learning_rate": 5e-05,
311
+ "loss": 0.3848,
312
+ "step": 6000
313
+ },
314
+ {
315
+ "epoch": 157.89,
316
+ "eval_loss": 3.291015625,
317
+ "eval_runtime": 3.7859,
318
+ "eval_samples_per_second": 68.148,
319
+ "eval_steps_per_second": 8.717,
320
+ "step": 6000
321
+ },
322
+ {
323
+ "epoch": 163.16,
324
+ "eval_loss": 3.376953125,
325
+ "eval_runtime": 3.7886,
326
+ "eval_samples_per_second": 68.099,
327
+ "eval_steps_per_second": 8.71,
328
+ "step": 6200
329
+ },
330
+ {
331
+ "epoch": 168.42,
332
+ "eval_loss": 3.408203125,
333
+ "eval_runtime": 3.7885,
334
+ "eval_samples_per_second": 68.1,
335
+ "eval_steps_per_second": 8.71,
336
+ "step": 6400
337
+ },
338
+ {
339
+ "epoch": 171.05,
340
+ "learning_rate": 5e-05,
341
+ "loss": 0.3224,
342
+ "step": 6500
343
+ },
344
+ {
345
+ "epoch": 173.68,
346
+ "eval_loss": 3.4765625,
347
+ "eval_runtime": 3.7922,
348
+ "eval_samples_per_second": 68.034,
349
+ "eval_steps_per_second": 8.702,
350
+ "step": 6600
351
+ },
352
+ {
353
+ "epoch": 178.95,
354
+ "eval_loss": 3.529296875,
355
+ "eval_runtime": 3.7898,
356
+ "eval_samples_per_second": 68.077,
357
+ "eval_steps_per_second": 8.708,
358
+ "step": 6800
359
+ },
360
+ {
361
+ "epoch": 184.21,
362
+ "learning_rate": 5e-05,
363
+ "loss": 0.2697,
364
+ "step": 7000
365
+ },
366
+ {
367
+ "epoch": 184.21,
368
+ "eval_loss": 3.591796875,
369
+ "eval_runtime": 3.7854,
370
+ "eval_samples_per_second": 68.157,
371
+ "eval_steps_per_second": 8.718,
372
+ "step": 7000
373
+ },
374
+ {
375
+ "epoch": 189.47,
376
+ "eval_loss": 3.634765625,
377
+ "eval_runtime": 3.7918,
378
+ "eval_samples_per_second": 68.041,
379
+ "eval_steps_per_second": 8.703,
380
+ "step": 7200
381
+ },
382
+ {
383
+ "epoch": 194.74,
384
+ "eval_loss": 3.68359375,
385
+ "eval_runtime": 3.7891,
386
+ "eval_samples_per_second": 68.09,
387
+ "eval_steps_per_second": 8.709,
388
+ "step": 7400
389
+ },
390
+ {
391
+ "epoch": 197.37,
392
+ "learning_rate": 5e-05,
393
+ "loss": 0.2258,
394
+ "step": 7500
395
+ },
396
+ {
397
+ "epoch": 200.0,
398
+ "eval_loss": 3.7265625,
399
+ "eval_runtime": 3.7895,
400
+ "eval_samples_per_second": 68.083,
401
+ "eval_steps_per_second": 8.708,
402
+ "step": 7600
403
+ },
404
+ {
405
+ "epoch": 205.26,
406
+ "eval_loss": 3.79296875,
407
+ "eval_runtime": 3.7901,
408
+ "eval_samples_per_second": 68.073,
409
+ "eval_steps_per_second": 8.707,
410
+ "step": 7800
411
+ },
412
+ {
413
+ "epoch": 210.53,
414
+ "learning_rate": 5e-05,
415
+ "loss": 0.1893,
416
+ "step": 8000
417
+ },
418
+ {
419
+ "epoch": 210.53,
420
+ "eval_loss": 3.828125,
421
+ "eval_runtime": 3.7891,
422
+ "eval_samples_per_second": 68.09,
423
+ "eval_steps_per_second": 8.709,
424
+ "step": 8000
425
+ },
426
+ {
427
+ "epoch": 215.79,
428
+ "eval_loss": 3.880859375,
429
+ "eval_runtime": 3.7907,
430
+ "eval_samples_per_second": 68.062,
431
+ "eval_steps_per_second": 8.706,
432
+ "step": 8200
433
+ },
434
+ {
435
+ "epoch": 221.05,
436
+ "eval_loss": 3.923828125,
437
+ "eval_runtime": 3.7895,
438
+ "eval_samples_per_second": 68.082,
439
+ "eval_steps_per_second": 8.708,
440
+ "step": 8400
441
+ },
442
+ {
443
+ "epoch": 223.68,
444
+ "learning_rate": 5e-05,
445
+ "loss": 0.1602,
446
+ "step": 8500
447
+ },
448
+ {
449
+ "epoch": 226.32,
450
+ "eval_loss": 3.974609375,
451
+ "eval_runtime": 3.7894,
452
+ "eval_samples_per_second": 68.084,
453
+ "eval_steps_per_second": 8.708,
454
+ "step": 8600
455
+ },
456
+ {
457
+ "epoch": 231.58,
458
+ "eval_loss": 4.00390625,
459
+ "eval_runtime": 3.7923,
460
+ "eval_samples_per_second": 68.032,
461
+ "eval_steps_per_second": 8.702,
462
+ "step": 8800
463
+ },
464
+ {
465
+ "epoch": 236.84,
466
+ "learning_rate": 5e-05,
467
+ "loss": 0.137,
468
+ "step": 9000
469
+ },
470
+ {
471
+ "epoch": 236.84,
472
+ "eval_loss": 4.046875,
473
+ "eval_runtime": 3.7922,
474
+ "eval_samples_per_second": 68.034,
475
+ "eval_steps_per_second": 8.702,
476
+ "step": 9000
477
+ },
478
+ {
479
+ "epoch": 242.11,
480
+ "eval_loss": 4.07421875,
481
+ "eval_runtime": 3.7901,
482
+ "eval_samples_per_second": 68.072,
483
+ "eval_steps_per_second": 8.707,
484
+ "step": 9200
485
+ },
486
+ {
487
+ "epoch": 247.37,
488
+ "eval_loss": 4.12109375,
489
+ "eval_runtime": 3.7896,
490
+ "eval_samples_per_second": 68.08,
491
+ "eval_steps_per_second": 8.708,
492
+ "step": 9400
493
+ },
494
+ {
495
+ "epoch": 250.0,
496
+ "learning_rate": 5e-05,
497
+ "loss": 0.1179,
498
+ "step": 9500
499
+ },
500
+ {
501
+ "epoch": 252.63,
502
+ "eval_loss": 4.15625,
503
+ "eval_runtime": 3.7912,
504
+ "eval_samples_per_second": 68.053,
505
+ "eval_steps_per_second": 8.704,
506
+ "step": 9600
507
+ },
508
+ {
509
+ "epoch": 257.89,
510
+ "eval_loss": 4.203125,
511
+ "eval_runtime": 3.7923,
512
+ "eval_samples_per_second": 68.032,
513
+ "eval_steps_per_second": 8.702,
514
+ "step": 9800
515
+ },
516
+ {
517
+ "epoch": 263.16,
518
+ "learning_rate": 5e-05,
519
+ "loss": 0.1024,
520
+ "step": 10000
521
+ },
522
+ {
523
+ "epoch": 263.16,
524
+ "eval_loss": 4.234375,
525
+ "eval_runtime": 3.7852,
526
+ "eval_samples_per_second": 68.159,
527
+ "eval_steps_per_second": 8.718,
528
+ "step": 10000
529
+ },
530
+ {
531
+ "epoch": 268.42,
532
+ "eval_loss": 4.2734375,
533
+ "eval_runtime": 3.7869,
534
+ "eval_samples_per_second": 68.129,
535
+ "eval_steps_per_second": 8.714,
536
+ "step": 10200
537
+ },
538
+ {
539
+ "epoch": 273.68,
540
+ "eval_loss": 4.3046875,
541
+ "eval_runtime": 3.7892,
542
+ "eval_samples_per_second": 68.088,
543
+ "eval_steps_per_second": 8.709,
544
+ "step": 10400
545
+ },
546
+ {
547
+ "epoch": 276.32,
548
+ "learning_rate": 5e-05,
549
+ "loss": 0.0901,
550
+ "step": 10500
551
+ },
552
+ {
553
+ "epoch": 278.95,
554
+ "eval_loss": 4.3125,
555
+ "eval_runtime": 3.7869,
556
+ "eval_samples_per_second": 68.129,
557
+ "eval_steps_per_second": 8.714,
558
+ "step": 10600
559
+ },
560
+ {
561
+ "epoch": 284.21,
562
+ "eval_loss": 4.375,
563
+ "eval_runtime": 3.7872,
564
+ "eval_samples_per_second": 68.125,
565
+ "eval_steps_per_second": 8.714,
566
+ "step": 10800
567
+ },
568
+ {
569
+ "epoch": 289.47,
570
+ "learning_rate": 5e-05,
571
+ "loss": 0.0796,
572
+ "step": 11000
573
+ },
574
+ {
575
+ "epoch": 289.47,
576
+ "eval_loss": 4.390625,
577
+ "eval_runtime": 3.7843,
578
+ "eval_samples_per_second": 68.177,
579
+ "eval_steps_per_second": 8.72,
580
+ "step": 11000
581
+ },
582
+ {
583
+ "epoch": 294.74,
584
+ "eval_loss": 4.4375,
585
+ "eval_runtime": 3.7881,
586
+ "eval_samples_per_second": 68.107,
587
+ "eval_steps_per_second": 8.711,
588
+ "step": 11200
589
+ },
590
+ {
591
+ "epoch": 300.0,
592
+ "eval_loss": 4.453125,
593
+ "eval_runtime": 3.7869,
594
+ "eval_samples_per_second": 68.129,
595
+ "eval_steps_per_second": 8.714,
596
+ "step": 11400
597
+ },
598
+ {
599
+ "epoch": 302.63,
600
+ "learning_rate": 5e-05,
601
+ "loss": 0.0706,
602
+ "step": 11500
603
+ },
604
+ {
605
+ "epoch": 305.26,
606
+ "eval_loss": 4.5078125,
607
+ "eval_runtime": 3.7854,
608
+ "eval_samples_per_second": 68.156,
609
+ "eval_steps_per_second": 8.718,
610
+ "step": 11600
611
+ },
612
+ {
613
+ "epoch": 310.53,
614
+ "eval_loss": 4.515625,
615
+ "eval_runtime": 3.787,
616
+ "eval_samples_per_second": 68.128,
617
+ "eval_steps_per_second": 8.714,
618
+ "step": 11800
619
+ },
620
+ {
621
+ "epoch": 315.79,
622
+ "learning_rate": 5e-05,
623
+ "loss": 0.0631,
624
+ "step": 12000
625
+ },
626
+ {
627
+ "epoch": 315.79,
628
+ "eval_loss": 4.53515625,
629
+ "eval_runtime": 3.7837,
630
+ "eval_samples_per_second": 68.187,
631
+ "eval_steps_per_second": 8.722,
632
+ "step": 12000
633
+ },
634
+ {
635
+ "epoch": 321.05,
636
+ "eval_loss": 4.5859375,
637
+ "eval_runtime": 3.7869,
638
+ "eval_samples_per_second": 68.13,
639
+ "eval_steps_per_second": 8.714,
640
+ "step": 12200
641
+ },
642
+ {
643
+ "epoch": 326.32,
644
+ "eval_loss": 4.609375,
645
+ "eval_runtime": 3.788,
646
+ "eval_samples_per_second": 68.11,
647
+ "eval_steps_per_second": 8.712,
648
+ "step": 12400
649
+ },
650
+ {
651
+ "epoch": 328.95,
652
+ "learning_rate": 5e-05,
653
+ "loss": 0.0573,
654
+ "step": 12500
655
+ },
656
+ {
657
+ "epoch": 331.58,
658
+ "eval_loss": 4.63671875,
659
+ "eval_runtime": 3.7891,
660
+ "eval_samples_per_second": 68.09,
661
+ "eval_steps_per_second": 8.709,
662
+ "step": 12600
663
+ },
664
+ {
665
+ "epoch": 336.84,
666
+ "eval_loss": 4.63671875,
667
+ "eval_runtime": 3.7855,
668
+ "eval_samples_per_second": 68.154,
669
+ "eval_steps_per_second": 8.717,
670
+ "step": 12800
671
+ },
672
+ {
673
+ "epoch": 342.11,
674
+ "learning_rate": 5e-05,
675
+ "loss": 0.0521,
676
+ "step": 13000
677
+ },
678
+ {
679
+ "epoch": 342.11,
680
+ "eval_loss": 4.6640625,
681
+ "eval_runtime": 3.7838,
682
+ "eval_samples_per_second": 68.185,
683
+ "eval_steps_per_second": 8.721,
684
+ "step": 13000
685
+ },
686
+ {
687
+ "epoch": 347.37,
688
+ "eval_loss": 4.70703125,
689
+ "eval_runtime": 3.7834,
690
+ "eval_samples_per_second": 68.192,
691
+ "eval_steps_per_second": 8.722,
692
+ "step": 13200
693
+ },
694
+ {
695
+ "epoch": 352.63,
696
+ "eval_loss": 4.69921875,
697
+ "eval_runtime": 3.789,
698
+ "eval_samples_per_second": 68.092,
699
+ "eval_steps_per_second": 8.709,
700
+ "step": 13400
701
+ },
702
+ {
703
+ "epoch": 355.26,
704
+ "learning_rate": 5e-05,
705
+ "loss": 0.0475,
706
+ "step": 13500
707
+ },
708
+ {
709
+ "epoch": 357.89,
710
+ "eval_loss": 4.75390625,
711
+ "eval_runtime": 3.7901,
712
+ "eval_samples_per_second": 68.073,
713
+ "eval_steps_per_second": 8.707,
714
+ "step": 13600
715
+ },
716
+ {
717
+ "epoch": 363.16,
718
+ "eval_loss": 4.765625,
719
+ "eval_runtime": 3.7877,
720
+ "eval_samples_per_second": 68.116,
721
+ "eval_steps_per_second": 8.712,
722
+ "step": 13800
723
+ },
724
+ {
725
+ "epoch": 368.42,
726
+ "learning_rate": 5e-05,
727
+ "loss": 0.0437,
728
+ "step": 14000
729
+ },
730
+ {
731
+ "epoch": 368.42,
732
+ "eval_loss": 4.80078125,
733
+ "eval_runtime": 3.7858,
734
+ "eval_samples_per_second": 68.15,
735
+ "eval_steps_per_second": 8.717,
736
+ "step": 14000
737
+ },
738
+ {
739
+ "epoch": 373.68,
740
+ "eval_loss": 4.83203125,
741
+ "eval_runtime": 3.7888,
742
+ "eval_samples_per_second": 68.095,
743
+ "eval_steps_per_second": 8.71,
744
+ "step": 14200
745
+ },
746
+ {
747
+ "epoch": 378.95,
748
+ "eval_loss": 4.8515625,
749
+ "eval_runtime": 3.7901,
750
+ "eval_samples_per_second": 68.073,
751
+ "eval_steps_per_second": 8.707,
752
+ "step": 14400
753
+ },
754
+ {
755
+ "epoch": 381.58,
756
+ "learning_rate": 5e-05,
757
+ "loss": 0.0399,
758
+ "step": 14500
759
+ },
760
+ {
761
+ "epoch": 384.21,
762
+ "eval_loss": 4.86328125,
763
+ "eval_runtime": 3.7938,
764
+ "eval_samples_per_second": 68.006,
765
+ "eval_steps_per_second": 8.698,
766
+ "step": 14600
767
+ },
768
+ {
769
+ "epoch": 389.47,
770
+ "eval_loss": 4.89453125,
771
+ "eval_runtime": 3.7887,
772
+ "eval_samples_per_second": 68.098,
773
+ "eval_steps_per_second": 8.71,
774
+ "step": 14800
775
+ },
776
+ {
777
+ "epoch": 394.74,
778
+ "learning_rate": 5e-05,
779
+ "loss": 0.0367,
780
+ "step": 15000
781
+ },
782
+ {
783
+ "epoch": 394.74,
784
+ "eval_loss": 4.90625,
785
+ "eval_runtime": 3.7864,
786
+ "eval_samples_per_second": 68.138,
787
+ "eval_steps_per_second": 8.715,
788
+ "step": 15000
789
+ },
790
+ {
791
+ "epoch": 400.0,
792
+ "eval_loss": 4.94140625,
793
+ "eval_runtime": 3.791,
794
+ "eval_samples_per_second": 68.057,
795
+ "eval_steps_per_second": 8.705,
796
+ "step": 15200
797
+ },
798
+ {
799
+ "epoch": 400.0,
800
+ "step": 15200,
801
+ "total_flos": 1.2604727427386573e+17,
802
+ "train_loss": 0.4328666927939967,
803
+ "train_runtime": 22235.2418,
804
+ "train_samples_per_second": 10.848,
805
+ "train_steps_per_second": 0.684
806
+ }
807
+ ],
808
+ "max_steps": 15200,
809
+ "num_train_epochs": 400,
810
+ "total_flos": 1.2604727427386573e+17,
811
+ "trial_name": null,
812
+ "trial_params": null
813
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a669d4b7a2fb08f2edacbf4cd42cf41502c9f9b962efa190cdc49ccce3537cef
3
+ size 3823
vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
zero_to_fp32.py ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # This script extracts fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints. It gets
4
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
5
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
6
+ # application.
7
+ #
8
+ # example: python zero_to_fp32.py . pytorch_model.bin
9
+
10
+ import argparse
11
+ import torch
12
+ import glob
13
+ import math
14
+ import os
15
+ from collections import OrderedDict
16
+
17
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
18
+ # DeepSpeed data structures it has to be available in the current python environment.
19
+ import deepspeed
20
+ from deepspeed.utils import logger
21
+
22
+ debug = 0
23
+
24
+ # load to cpu
25
+ device = torch.device('cpu')
26
+
27
+
28
+ def get_model_state_file(checkpoint_dir, zero_stage):
29
+ if not os.path.isdir(checkpoint_dir):
30
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
31
+
32
+ # there should be only one file
33
+ if zero_stage == 2:
34
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
35
+ elif zero_stage == 3:
36
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
37
+
38
+ if not os.path.exists(file):
39
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
40
+
41
+ return file
42
+
43
+
44
+ def get_optim_files(checkpoint_dir):
45
+ # XXX: need to test that this simple glob rule works for multi-node setup too
46
+ optim_files = sorted(glob.glob(os.path.join(checkpoint_dir, "*_optim_states.pt")))
47
+
48
+ if len(optim_files) == 0:
49
+ raise FileNotFoundError(
50
+ f"can't find '*_optim_states.pt' files in directory '{checkpoint_dir}'")
51
+
52
+ return optim_files
53
+
54
+
55
+ def parse_model_state(file):
56
+ state_dict = torch.load(file, map_location=device)
57
+
58
+ if "buffer_names" not in state_dict:
59
+ raise ValueError(f"{file} is not a model state checkpoint")
60
+ buffer_names = state_dict["buffer_names"]
61
+ if debug:
62
+ print("Found buffers:", buffer_names)
63
+
64
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
65
+ buffers = {
66
+ k: v.float()
67
+ for k,
68
+ v in state_dict["module"].items() if k in buffer_names
69
+ }
70
+ return buffers
71
+
72
+
73
+ def parse_optim_states(files, ds_checkpoint_dir):
74
+
75
+ total_files = len(files)
76
+ state_dicts = []
77
+ for f in files:
78
+ state_dicts.append(torch.load(f, map_location=device))
79
+
80
+ if not "zero_stage" in state_dicts[0]['optimizer_state_dict']:
81
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
82
+ zero_stage = state_dicts[0]['optimizer_state_dict']["zero_stage"]
83
+ world_size = state_dicts[0]['optimizer_state_dict']["partition_count"]
84
+ param_shapes = state_dicts[0]["param_shapes"]
85
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
86
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
87
+ # use the max of the partition_count to get the dp world_size.
88
+
89
+ if type(world_size) is list:
90
+ world_size = max(world_size)
91
+
92
+ if world_size != total_files:
93
+ raise ValueError(
94
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
95
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
96
+ )
97
+
98
+ # the groups are named differently in each stage
99
+ if zero_stage == 2:
100
+ fp32_groups_key = "single_partition_of_fp32_groups"
101
+ elif zero_stage == 3:
102
+ fp32_groups_key = "fp32_flat_groups"
103
+ else:
104
+ raise ValueError(f"unknown zero stage {zero_stage}")
105
+
106
+ if zero_stage == 2:
107
+ fp32_flat_groups = [
108
+ state_dicts[i]['optimizer_state_dict'][fp32_groups_key]
109
+ for i in range(len(state_dicts))
110
+ ]
111
+ elif zero_stage == 3:
112
+ # if there is more than one param group, there will be multiple flattened tensors - one
113
+ # flattened tensor per group - for simplicity merge them into a single tensor
114
+ #
115
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
116
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
117
+
118
+ fp32_flat_groups = [
119
+ torch.cat(state_dicts[i]['optimizer_state_dict'][fp32_groups_key],
120
+ 0) for i in range(len(state_dicts))
121
+ ]
122
+
123
+ return zero_stage, world_size, param_shapes, fp32_flat_groups
124
+
125
+
126
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
127
+ """
128
+ Returns fp32 state_dict reconstructed from ds checkpoint
129
+
130
+ Args:
131
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
132
+
133
+ """
134
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
135
+
136
+ optim_files = get_optim_files(ds_checkpoint_dir)
137
+ zero_stage, world_size, param_shapes, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
138
+ print(
139
+ f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
140
+
141
+ model_file = get_model_state_file(ds_checkpoint_dir, zero_stage)
142
+ buffers = parse_model_state(model_file)
143
+
144
+ if zero_stage == 2:
145
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size,
146
+ param_shapes,
147
+ fp32_flat_groups,
148
+ buffers)
149
+ elif zero_stage == 3:
150
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size,
151
+ param_shapes,
152
+ fp32_flat_groups,
153
+ buffers)
154
+
155
+
156
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size,
157
+ param_shapes,
158
+ fp32_flat_groups,
159
+ buffers):
160
+
161
+ # Reconstruction protocol:
162
+ #
163
+ # XXX: document this
164
+
165
+ if debug:
166
+ for i in range(world_size):
167
+ for j in range(len(fp32_flat_groups[0])):
168
+ print(f"fp32_flat_groups[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
169
+
170
+ # XXX: memory usage doubles here (zero2)
171
+ num_param_groups = len(fp32_flat_groups[0])
172
+ merged_single_partition_of_fp32_groups = []
173
+ for i in range(num_param_groups):
174
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
175
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
176
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
177
+ avail_numel = sum([
178
+ full_single_fp32_vector.numel()
179
+ for full_single_fp32_vector in merged_single_partition_of_fp32_groups
180
+ ])
181
+
182
+ if debug:
183
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
184
+ wanted_numel = sum(
185
+ [sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
186
+ # not asserting if there is a mismatch due to possible padding
187
+ print(f"Have {avail_numel} numels to process.")
188
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
189
+
190
+ state_dict = OrderedDict()
191
+
192
+ # buffers
193
+ state_dict.update(buffers)
194
+ if debug:
195
+ print(f"added {len(buffers)} buffers")
196
+
197
+ # params
198
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
199
+ # out-of-core computing solution
200
+ total_numel = 0
201
+ total_params = 0
202
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
203
+ offset = 0
204
+ avail_numel = full_single_fp32_vector.numel()
205
+ for name, shape in shapes.items():
206
+
207
+ unpartitioned_numel = shape.numel()
208
+ total_numel += unpartitioned_numel
209
+ total_params += 1
210
+
211
+ if debug:
212
+ print(
213
+ f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} "
214
+ )
215
+ state_dict[name] = full_single_fp32_vector.narrow(
216
+ 0,
217
+ offset,
218
+ unpartitioned_numel).view(shape)
219
+ offset += unpartitioned_numel
220
+
221
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
222
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
223
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
224
+ # live optimizer object, so we are checking that the numbers are within the right range
225
+ align_to = 2 * world_size
226
+
227
+ def zero2_align(x):
228
+ return align_to * math.ceil(x / align_to)
229
+
230
+ if debug:
231
+ print(f"original offset={offset}, avail_numel={avail_numel}")
232
+
233
+ offset = zero2_align(offset)
234
+ avail_numel = zero2_align(avail_numel)
235
+
236
+ if debug:
237
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
238
+
239
+ # Sanity check
240
+ if offset != avail_numel:
241
+ raise ValueError(
242
+ f"consumed {offset} numels out of {avail_numel} - something is wrong")
243
+
244
+ print(
245
+ f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
246
+ )
247
+
248
+ return state_dict
249
+
250
+
251
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
252
+ remainder = unpartitioned_numel % world_size
253
+ padding_numel = (world_size - remainder) if remainder else 0
254
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
255
+ return partitioned_numel, padding_numel
256
+
257
+
258
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size,
259
+ param_shapes,
260
+ fp32_flat_groups,
261
+ buffers):
262
+
263
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
264
+ # param, re-consolidating each param, while dealing with padding if any
265
+
266
+ avail_numel = fp32_flat_groups[0].numel() * world_size
267
+ # merge list of dicts, preserving order
268
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
269
+
270
+ if debug:
271
+ for i in range(world_size):
272
+ print(f"fp32_flat_groups[{i}].shape={fp32_flat_groups[i].shape}")
273
+
274
+ wanted_params = len(param_shapes)
275
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
276
+ # not asserting if there is a mismatch due to possible padding
277
+ print(f"Have {avail_numel} numels to process.")
278
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
279
+
280
+ state_dict = OrderedDict()
281
+
282
+ # buffers
283
+ state_dict.update(buffers)
284
+ if debug:
285
+ print(f"added {len(buffers)} buffers")
286
+
287
+ # params
288
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
289
+ # out-of-core computing solution
290
+ offset = 0
291
+ total_numel = 0
292
+ total_params = 0
293
+ for name, shape in param_shapes.items():
294
+
295
+ unpartitioned_numel = shape.numel()
296
+ total_numel += unpartitioned_numel
297
+ total_params += 1
298
+
299
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
300
+
301
+ if debug:
302
+ print(
303
+ f"{total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
304
+ )
305
+
306
+ # XXX: memory usage doubles here
307
+ state_dict[name] = torch.cat(
308
+ tuple(fp32_flat_groups[i].narrow(0,
309
+ offset,
310
+ partitioned_numel)
311
+ for i in range(world_size)),
312
+ 0).narrow(0,
313
+ 0,
314
+ unpartitioned_numel).view(shape)
315
+ offset += partitioned_numel
316
+
317
+ offset *= world_size
318
+
319
+ # Sanity check
320
+ if offset != avail_numel:
321
+ raise ValueError(
322
+ f"consumed {offset} numels out of {avail_numel} - something is wrong")
323
+
324
+ print(
325
+ f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
326
+ )
327
+
328
+ return state_dict
329
+
330
+
331
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
332
+ """
333
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
334
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
335
+ via a model hub.
336
+
337
+ Args:
338
+ - ``checkpoint_dir``: path to the desired checkpoint folder
339
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
340
+
341
+ Returns:
342
+ - pytorch ``state_dict``
343
+
344
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
345
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
346
+ the checkpoint.
347
+
348
+ A typical usage might be ::
349
+
350
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
351
+ # do the training and checkpoint saving
352
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
353
+ model = model.cpu() # move to cpu
354
+ model.load_state_dict(state_dict)
355
+ # submit to model hub or save the model to share with others
356
+
357
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
358
+ application. i.e. you will need to re-initialize the deepspeed engine, since
359
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
360
+
361
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
362
+
363
+ """
364
+ if tag is None:
365
+ latest_path = os.path.join(checkpoint_dir, 'latest')
366
+ if os.path.isfile(latest_path):
367
+ with open(latest_path, 'r') as fd:
368
+ tag = fd.read().strip()
369
+ else:
370
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
371
+
372
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
373
+
374
+ if not os.path.isdir(ds_checkpoint_dir):
375
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
376
+
377
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
378
+
379
+
380
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
381
+ """
382
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
383
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
384
+
385
+ Args:
386
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
387
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
388
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
389
+ """
390
+
391
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
392
+ print(f"Saving fp32 state dict to {output_file}")
393
+ torch.save(state_dict, output_file)
394
+
395
+
396
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
397
+ """
398
+ 1. Put the provided model to cpu
399
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
400
+ 3. Load it into the provided model
401
+
402
+ Args:
403
+ - ``model``: the model object to update
404
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
405
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
406
+
407
+ Returns:
408
+ - ``model`: modified model
409
+
410
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
411
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
412
+ conveniently placed for you in the checkpoint folder.
413
+
414
+ A typical usage might be ::
415
+
416
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
417
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
418
+ # submit to model hub or save the model to share with others
419
+
420
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
421
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
422
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
423
+
424
+ """
425
+ logger.info(f"Extracting fp32 weights")
426
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
427
+
428
+ logger.info(f"Overwriting model with fp32 weights")
429
+ model = model.cpu()
430
+ model.load_state_dict(state_dict, strict=False)
431
+
432
+ return model
433
+
434
+
435
+ if __name__ == "__main__":
436
+
437
+ parser = argparse.ArgumentParser()
438
+ parser.add_argument(
439
+ "checkpoint_dir",
440
+ type=str,
441
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
442
+ parser.add_argument(
443
+ "output_file",
444
+ type=str,
445
+ help=
446
+ "path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)"
447
+ )
448
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
449
+ args = parser.parse_args()
450
+
451
+ debug = args.debug
452
+
453
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)