dmayhem93 commited on
Commit
dd98158
1 Parent(s): 0fbc32d

Upload with huggingface_hub

Browse files
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "EleutherAI/pythia-125m-deduped",
3
+ "architectures": [
4
+ "GPTNeoXForCausalLM"
5
+ ],
6
+ "bos_token_id": 0,
7
+ "eos_token_id": 0,
8
+ "hidden_act": "gelu",
9
+ "hidden_size": 768,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 3072,
12
+ "layer_norm_eps": 1e-05,
13
+ "max_position_embeddings": 2048,
14
+ "model_type": "gpt_neox",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 12,
17
+ "rotary_emb_base": 10000,
18
+ "rotary_pct": 0.25,
19
+ "tie_word_embeddings": false,
20
+ "torch_dtype": "float16",
21
+ "transformers_version": "4.26.0.dev0",
22
+ "use_cache": true,
23
+ "use_parallel_residual": true,
24
+ "vocab_size": 50304
25
+ }
global_step14299/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65f3e1388c1910f8300c6f1506f030b0990d48973d43a9fa46f64373d023d037
3
+ size 375032614
global_step14299/zero_pp_rank_0_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0646ae5d67d19f2dc6f2aa1069bd3d67daed322175d8e73468e7ec16c30831d
3
+ size 243487614
global_step14299/zero_pp_rank_1_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6cd397b71061ba43d3ebc80172c71db8ca3d42d8d3b3d30e63eed3fbe9dc2f4
3
+ size 243488190
global_step14299/zero_pp_rank_2_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d1f6c0c029b5be6344a050913a0f1901dd77d4b9fa892674ffa665b1c2923f4
3
+ size 243490174
global_step14299/zero_pp_rank_3_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f0ce3404a510dd659dc779aae11a57827723615aa791340ee55f6f8ca046bdc
3
+ size 243490046
global_step14299/zero_pp_rank_4_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cac902664a41e18c2d1d9375b722fcc91f66606cd3dff694e992806abd0796eb
3
+ size 243490110
global_step14299/zero_pp_rank_5_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd2258f43bd6efc51c74e3a25d2ce05a74bb6ff16b7f149c718c3d83cf67edcf
3
+ size 243490366
global_step14299/zero_pp_rank_6_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52862fcaa4e3a8924e72ed3f7e558dbe32dc7dc1310bd36c6c0916e6fcc9deef
3
+ size 243487934
global_step14299/zero_pp_rank_7_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3358f0c6d163e936078596147ae30e4d1c054b61a709222c10d1ed89664afa66
3
+ size 243487614
latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step14299
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2338087afffad511f3542a2906678c21b1f6db0846eecd1247065b8fd9f57be4
3
+ size 375009696
rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a961c7aa8293531040f379f129f1930093670f11c91d3736bf6d8518af2b1507
3
+ size 14583
rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbc4475e8615a434844642d2b6db8c82a3eb4d1532c0358142650af35982f7d4
3
+ size 14583
rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:881eb4ea22a97cf8b6f92b147ff4c6e2ae57dcc7e36f52b570b5be3eeb7887b6
3
+ size 14583
rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b494daea51340989a686bc325649dfd2d62f65af56b0d25143e33790c8a957a
3
+ size 14583
rng_state_4.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a88b3a9b9d34f9c56a628c06043f3d84338d75c0f6730bf31d21d05f60a24e7
3
+ size 14583
rng_state_5.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e1556e939ee7eca3367a22108d1bd8653197711d2ab29b9fc7633bec21b96125
3
+ size 14583
rng_state_6.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86e9ed27d35f586c7ec30600373ad7abf89086510211847110cb4a979365cfa0
3
+ size 14583
rng_state_7.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1828f5f1b78bdfd59c65a849162815831fbce941a063f6c4056e93648685a2ec
3
+ size 14583
trainer_state.json ADDED
@@ -0,0 +1,876 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 1.0,
5
+ "global_step": 14299,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 0.01,
12
+ "learning_rate": 9.488135456452206e-05,
13
+ "loss": 3.4925,
14
+ "step": 100
15
+ },
16
+ {
17
+ "epoch": 0.01,
18
+ "learning_rate": 0.0001,
19
+ "loss": 1.9277,
20
+ "step": 200
21
+ },
22
+ {
23
+ "epoch": 0.02,
24
+ "learning_rate": 0.0001,
25
+ "loss": 1.9662,
26
+ "step": 300
27
+ },
28
+ {
29
+ "epoch": 0.03,
30
+ "learning_rate": 0.0001,
31
+ "loss": 1.9422,
32
+ "step": 400
33
+ },
34
+ {
35
+ "epoch": 0.03,
36
+ "learning_rate": 0.0001,
37
+ "loss": 1.9676,
38
+ "step": 500
39
+ },
40
+ {
41
+ "epoch": 0.04,
42
+ "learning_rate": 0.0001,
43
+ "loss": 1.9137,
44
+ "step": 600
45
+ },
46
+ {
47
+ "epoch": 0.05,
48
+ "learning_rate": 0.0001,
49
+ "loss": 1.9491,
50
+ "step": 700
51
+ },
52
+ {
53
+ "epoch": 0.06,
54
+ "learning_rate": 0.0001,
55
+ "loss": 1.9413,
56
+ "step": 800
57
+ },
58
+ {
59
+ "epoch": 0.06,
60
+ "learning_rate": 0.0001,
61
+ "loss": 1.9424,
62
+ "step": 900
63
+ },
64
+ {
65
+ "epoch": 0.07,
66
+ "learning_rate": 0.0001,
67
+ "loss": 1.916,
68
+ "step": 1000
69
+ },
70
+ {
71
+ "epoch": 0.08,
72
+ "learning_rate": 0.0001,
73
+ "loss": 1.8919,
74
+ "step": 1100
75
+ },
76
+ {
77
+ "epoch": 0.08,
78
+ "learning_rate": 0.0001,
79
+ "loss": 1.9228,
80
+ "step": 1200
81
+ },
82
+ {
83
+ "epoch": 0.09,
84
+ "learning_rate": 0.0001,
85
+ "loss": 1.9008,
86
+ "step": 1300
87
+ },
88
+ {
89
+ "epoch": 0.1,
90
+ "learning_rate": 0.0001,
91
+ "loss": 1.9189,
92
+ "step": 1400
93
+ },
94
+ {
95
+ "epoch": 0.1,
96
+ "learning_rate": 0.0001,
97
+ "loss": 1.8898,
98
+ "step": 1500
99
+ },
100
+ {
101
+ "epoch": 0.11,
102
+ "learning_rate": 0.0001,
103
+ "loss": 1.8724,
104
+ "step": 1600
105
+ },
106
+ {
107
+ "epoch": 0.12,
108
+ "learning_rate": 0.0001,
109
+ "loss": 1.9123,
110
+ "step": 1700
111
+ },
112
+ {
113
+ "epoch": 0.13,
114
+ "learning_rate": 0.0001,
115
+ "loss": 1.934,
116
+ "step": 1800
117
+ },
118
+ {
119
+ "epoch": 0.13,
120
+ "learning_rate": 0.0001,
121
+ "loss": 1.904,
122
+ "step": 1900
123
+ },
124
+ {
125
+ "epoch": 0.14,
126
+ "learning_rate": 0.0001,
127
+ "loss": 1.9295,
128
+ "step": 2000
129
+ },
130
+ {
131
+ "epoch": 0.15,
132
+ "learning_rate": 0.0001,
133
+ "loss": 1.926,
134
+ "step": 2100
135
+ },
136
+ {
137
+ "epoch": 0.15,
138
+ "learning_rate": 0.0001,
139
+ "loss": 1.8874,
140
+ "step": 2200
141
+ },
142
+ {
143
+ "epoch": 0.16,
144
+ "learning_rate": 0.0001,
145
+ "loss": 1.9097,
146
+ "step": 2300
147
+ },
148
+ {
149
+ "epoch": 0.17,
150
+ "learning_rate": 0.0001,
151
+ "loss": 1.9119,
152
+ "step": 2400
153
+ },
154
+ {
155
+ "epoch": 0.17,
156
+ "learning_rate": 0.0001,
157
+ "loss": 1.8833,
158
+ "step": 2500
159
+ },
160
+ {
161
+ "epoch": 0.18,
162
+ "learning_rate": 0.0001,
163
+ "loss": 1.894,
164
+ "step": 2600
165
+ },
166
+ {
167
+ "epoch": 0.19,
168
+ "learning_rate": 0.0001,
169
+ "loss": 1.9345,
170
+ "step": 2700
171
+ },
172
+ {
173
+ "epoch": 0.2,
174
+ "learning_rate": 0.0001,
175
+ "loss": 1.8902,
176
+ "step": 2800
177
+ },
178
+ {
179
+ "epoch": 0.2,
180
+ "learning_rate": 0.0001,
181
+ "loss": 1.8798,
182
+ "step": 2900
183
+ },
184
+ {
185
+ "epoch": 0.21,
186
+ "learning_rate": 0.0001,
187
+ "loss": 1.8891,
188
+ "step": 3000
189
+ },
190
+ {
191
+ "epoch": 0.22,
192
+ "learning_rate": 0.0001,
193
+ "loss": 1.8853,
194
+ "step": 3100
195
+ },
196
+ {
197
+ "epoch": 0.22,
198
+ "learning_rate": 0.0001,
199
+ "loss": 1.865,
200
+ "step": 3200
201
+ },
202
+ {
203
+ "epoch": 0.23,
204
+ "learning_rate": 0.0001,
205
+ "loss": 1.9037,
206
+ "step": 3300
207
+ },
208
+ {
209
+ "epoch": 0.24,
210
+ "learning_rate": 0.0001,
211
+ "loss": 1.8672,
212
+ "step": 3400
213
+ },
214
+ {
215
+ "epoch": 0.24,
216
+ "learning_rate": 0.0001,
217
+ "loss": 1.868,
218
+ "step": 3500
219
+ },
220
+ {
221
+ "epoch": 0.25,
222
+ "learning_rate": 0.0001,
223
+ "loss": 1.8933,
224
+ "step": 3600
225
+ },
226
+ {
227
+ "epoch": 0.26,
228
+ "learning_rate": 0.0001,
229
+ "loss": 1.8709,
230
+ "step": 3700
231
+ },
232
+ {
233
+ "epoch": 0.27,
234
+ "learning_rate": 0.0001,
235
+ "loss": 1.8901,
236
+ "step": 3800
237
+ },
238
+ {
239
+ "epoch": 0.27,
240
+ "learning_rate": 0.0001,
241
+ "loss": 1.87,
242
+ "step": 3900
243
+ },
244
+ {
245
+ "epoch": 0.28,
246
+ "learning_rate": 0.0001,
247
+ "loss": 1.9241,
248
+ "step": 4000
249
+ },
250
+ {
251
+ "epoch": 0.29,
252
+ "learning_rate": 0.0001,
253
+ "loss": 1.8981,
254
+ "step": 4100
255
+ },
256
+ {
257
+ "epoch": 0.29,
258
+ "learning_rate": 0.0001,
259
+ "loss": 1.8564,
260
+ "step": 4200
261
+ },
262
+ {
263
+ "epoch": 0.3,
264
+ "learning_rate": 0.0001,
265
+ "loss": 1.8906,
266
+ "step": 4300
267
+ },
268
+ {
269
+ "epoch": 0.31,
270
+ "learning_rate": 0.0001,
271
+ "loss": 1.8751,
272
+ "step": 4400
273
+ },
274
+ {
275
+ "epoch": 0.31,
276
+ "learning_rate": 0.0001,
277
+ "loss": 1.8649,
278
+ "step": 4500
279
+ },
280
+ {
281
+ "epoch": 0.32,
282
+ "learning_rate": 0.0001,
283
+ "loss": 1.8901,
284
+ "step": 4600
285
+ },
286
+ {
287
+ "epoch": 0.33,
288
+ "learning_rate": 0.0001,
289
+ "loss": 1.8843,
290
+ "step": 4700
291
+ },
292
+ {
293
+ "epoch": 0.34,
294
+ "learning_rate": 0.0001,
295
+ "loss": 1.876,
296
+ "step": 4800
297
+ },
298
+ {
299
+ "epoch": 0.34,
300
+ "learning_rate": 0.0001,
301
+ "loss": 1.8486,
302
+ "step": 4900
303
+ },
304
+ {
305
+ "epoch": 0.35,
306
+ "learning_rate": 0.0001,
307
+ "loss": 1.8679,
308
+ "step": 5000
309
+ },
310
+ {
311
+ "epoch": 0.36,
312
+ "learning_rate": 0.0001,
313
+ "loss": 1.8295,
314
+ "step": 5100
315
+ },
316
+ {
317
+ "epoch": 0.36,
318
+ "learning_rate": 0.0001,
319
+ "loss": 1.8675,
320
+ "step": 5200
321
+ },
322
+ {
323
+ "epoch": 0.37,
324
+ "learning_rate": 0.0001,
325
+ "loss": 1.8501,
326
+ "step": 5300
327
+ },
328
+ {
329
+ "epoch": 0.38,
330
+ "learning_rate": 0.0001,
331
+ "loss": 1.861,
332
+ "step": 5400
333
+ },
334
+ {
335
+ "epoch": 0.38,
336
+ "learning_rate": 0.0001,
337
+ "loss": 1.8825,
338
+ "step": 5500
339
+ },
340
+ {
341
+ "epoch": 0.39,
342
+ "learning_rate": 0.0001,
343
+ "loss": 1.8431,
344
+ "step": 5600
345
+ },
346
+ {
347
+ "epoch": 0.4,
348
+ "learning_rate": 0.0001,
349
+ "loss": 1.8278,
350
+ "step": 5700
351
+ },
352
+ {
353
+ "epoch": 0.41,
354
+ "learning_rate": 0.0001,
355
+ "loss": 1.8671,
356
+ "step": 5800
357
+ },
358
+ {
359
+ "epoch": 0.41,
360
+ "learning_rate": 0.0001,
361
+ "loss": 1.8763,
362
+ "step": 5900
363
+ },
364
+ {
365
+ "epoch": 0.42,
366
+ "learning_rate": 0.0001,
367
+ "loss": 1.8645,
368
+ "step": 6000
369
+ },
370
+ {
371
+ "epoch": 0.43,
372
+ "learning_rate": 0.0001,
373
+ "loss": 1.8367,
374
+ "step": 6100
375
+ },
376
+ {
377
+ "epoch": 0.43,
378
+ "learning_rate": 0.0001,
379
+ "loss": 1.8838,
380
+ "step": 6200
381
+ },
382
+ {
383
+ "epoch": 0.44,
384
+ "learning_rate": 0.0001,
385
+ "loss": 1.8699,
386
+ "step": 6300
387
+ },
388
+ {
389
+ "epoch": 0.45,
390
+ "learning_rate": 0.0001,
391
+ "loss": 1.87,
392
+ "step": 6400
393
+ },
394
+ {
395
+ "epoch": 0.45,
396
+ "learning_rate": 0.0001,
397
+ "loss": 1.843,
398
+ "step": 6500
399
+ },
400
+ {
401
+ "epoch": 0.46,
402
+ "learning_rate": 0.0001,
403
+ "loss": 1.8441,
404
+ "step": 6600
405
+ },
406
+ {
407
+ "epoch": 0.47,
408
+ "learning_rate": 0.0001,
409
+ "loss": 1.8656,
410
+ "step": 6700
411
+ },
412
+ {
413
+ "epoch": 0.48,
414
+ "learning_rate": 0.0001,
415
+ "loss": 1.8527,
416
+ "step": 6800
417
+ },
418
+ {
419
+ "epoch": 0.48,
420
+ "learning_rate": 0.0001,
421
+ "loss": 1.8294,
422
+ "step": 6900
423
+ },
424
+ {
425
+ "epoch": 0.49,
426
+ "learning_rate": 0.0001,
427
+ "loss": 1.871,
428
+ "step": 7000
429
+ },
430
+ {
431
+ "epoch": 0.5,
432
+ "learning_rate": 0.0001,
433
+ "loss": 1.8634,
434
+ "step": 7100
435
+ },
436
+ {
437
+ "epoch": 0.5,
438
+ "learning_rate": 0.0001,
439
+ "loss": 1.8614,
440
+ "step": 7200
441
+ },
442
+ {
443
+ "epoch": 0.51,
444
+ "learning_rate": 0.0001,
445
+ "loss": 1.8229,
446
+ "step": 7300
447
+ },
448
+ {
449
+ "epoch": 0.52,
450
+ "learning_rate": 0.0001,
451
+ "loss": 1.8955,
452
+ "step": 7400
453
+ },
454
+ {
455
+ "epoch": 0.52,
456
+ "learning_rate": 0.0001,
457
+ "loss": 1.8379,
458
+ "step": 7500
459
+ },
460
+ {
461
+ "epoch": 0.53,
462
+ "learning_rate": 0.0001,
463
+ "loss": 1.8533,
464
+ "step": 7600
465
+ },
466
+ {
467
+ "epoch": 0.54,
468
+ "learning_rate": 0.0001,
469
+ "loss": 1.8454,
470
+ "step": 7700
471
+ },
472
+ {
473
+ "epoch": 0.55,
474
+ "learning_rate": 0.0001,
475
+ "loss": 1.8168,
476
+ "step": 7800
477
+ },
478
+ {
479
+ "epoch": 0.55,
480
+ "learning_rate": 0.0001,
481
+ "loss": 1.8283,
482
+ "step": 7900
483
+ },
484
+ {
485
+ "epoch": 0.56,
486
+ "learning_rate": 0.0001,
487
+ "loss": 1.8545,
488
+ "step": 8000
489
+ },
490
+ {
491
+ "epoch": 0.57,
492
+ "learning_rate": 0.0001,
493
+ "loss": 1.8133,
494
+ "step": 8100
495
+ },
496
+ {
497
+ "epoch": 0.57,
498
+ "learning_rate": 0.0001,
499
+ "loss": 1.8389,
500
+ "step": 8200
501
+ },
502
+ {
503
+ "epoch": 0.58,
504
+ "learning_rate": 0.0001,
505
+ "loss": 1.8246,
506
+ "step": 8300
507
+ },
508
+ {
509
+ "epoch": 0.59,
510
+ "learning_rate": 0.0001,
511
+ "loss": 1.8351,
512
+ "step": 8400
513
+ },
514
+ {
515
+ "epoch": 0.59,
516
+ "learning_rate": 0.0001,
517
+ "loss": 1.8244,
518
+ "step": 8500
519
+ },
520
+ {
521
+ "epoch": 0.6,
522
+ "learning_rate": 0.0001,
523
+ "loss": 1.8137,
524
+ "step": 8600
525
+ },
526
+ {
527
+ "epoch": 0.61,
528
+ "learning_rate": 0.0001,
529
+ "loss": 1.8016,
530
+ "step": 8700
531
+ },
532
+ {
533
+ "epoch": 0.62,
534
+ "learning_rate": 0.0001,
535
+ "loss": 1.8237,
536
+ "step": 8800
537
+ },
538
+ {
539
+ "epoch": 0.62,
540
+ "learning_rate": 0.0001,
541
+ "loss": 1.812,
542
+ "step": 8900
543
+ },
544
+ {
545
+ "epoch": 0.63,
546
+ "learning_rate": 0.0001,
547
+ "loss": 1.8345,
548
+ "step": 9000
549
+ },
550
+ {
551
+ "epoch": 0.64,
552
+ "learning_rate": 0.0001,
553
+ "loss": 1.8411,
554
+ "step": 9100
555
+ },
556
+ {
557
+ "epoch": 0.64,
558
+ "learning_rate": 0.0001,
559
+ "loss": 1.8077,
560
+ "step": 9200
561
+ },
562
+ {
563
+ "epoch": 0.65,
564
+ "learning_rate": 0.0001,
565
+ "loss": 1.8581,
566
+ "step": 9300
567
+ },
568
+ {
569
+ "epoch": 0.66,
570
+ "learning_rate": 0.0001,
571
+ "loss": 1.8242,
572
+ "step": 9400
573
+ },
574
+ {
575
+ "epoch": 0.66,
576
+ "learning_rate": 0.0001,
577
+ "loss": 1.8166,
578
+ "step": 9500
579
+ },
580
+ {
581
+ "epoch": 0.67,
582
+ "learning_rate": 0.0001,
583
+ "loss": 1.8227,
584
+ "step": 9600
585
+ },
586
+ {
587
+ "epoch": 0.68,
588
+ "learning_rate": 0.0001,
589
+ "loss": 1.8011,
590
+ "step": 9700
591
+ },
592
+ {
593
+ "epoch": 0.69,
594
+ "learning_rate": 0.0001,
595
+ "loss": 1.8253,
596
+ "step": 9800
597
+ },
598
+ {
599
+ "epoch": 0.69,
600
+ "learning_rate": 0.0001,
601
+ "loss": 1.7924,
602
+ "step": 9900
603
+ },
604
+ {
605
+ "epoch": 0.7,
606
+ "learning_rate": 0.0001,
607
+ "loss": 1.8091,
608
+ "step": 10000
609
+ },
610
+ {
611
+ "epoch": 0.71,
612
+ "learning_rate": 0.0001,
613
+ "loss": 1.8178,
614
+ "step": 10100
615
+ },
616
+ {
617
+ "epoch": 0.71,
618
+ "learning_rate": 0.0001,
619
+ "loss": 1.811,
620
+ "step": 10200
621
+ },
622
+ {
623
+ "epoch": 0.72,
624
+ "learning_rate": 0.0001,
625
+ "loss": 1.8134,
626
+ "step": 10300
627
+ },
628
+ {
629
+ "epoch": 0.73,
630
+ "learning_rate": 0.0001,
631
+ "loss": 1.8311,
632
+ "step": 10400
633
+ },
634
+ {
635
+ "epoch": 0.73,
636
+ "learning_rate": 0.0001,
637
+ "loss": 1.8269,
638
+ "step": 10500
639
+ },
640
+ {
641
+ "epoch": 0.74,
642
+ "learning_rate": 0.0001,
643
+ "loss": 1.8286,
644
+ "step": 10600
645
+ },
646
+ {
647
+ "epoch": 0.75,
648
+ "learning_rate": 0.0001,
649
+ "loss": 1.805,
650
+ "step": 10700
651
+ },
652
+ {
653
+ "epoch": 0.76,
654
+ "learning_rate": 0.0001,
655
+ "loss": 1.7735,
656
+ "step": 10800
657
+ },
658
+ {
659
+ "epoch": 0.76,
660
+ "learning_rate": 0.0001,
661
+ "loss": 1.761,
662
+ "step": 10900
663
+ },
664
+ {
665
+ "epoch": 0.77,
666
+ "learning_rate": 0.0001,
667
+ "loss": 1.7869,
668
+ "step": 11000
669
+ },
670
+ {
671
+ "epoch": 0.78,
672
+ "learning_rate": 0.0001,
673
+ "loss": 1.8054,
674
+ "step": 11100
675
+ },
676
+ {
677
+ "epoch": 0.78,
678
+ "learning_rate": 0.0001,
679
+ "loss": 1.7958,
680
+ "step": 11200
681
+ },
682
+ {
683
+ "epoch": 0.79,
684
+ "learning_rate": 0.0001,
685
+ "loss": 1.8049,
686
+ "step": 11300
687
+ },
688
+ {
689
+ "epoch": 0.8,
690
+ "learning_rate": 0.0001,
691
+ "loss": 1.7943,
692
+ "step": 11400
693
+ },
694
+ {
695
+ "epoch": 0.8,
696
+ "learning_rate": 0.0001,
697
+ "loss": 1.7771,
698
+ "step": 11500
699
+ },
700
+ {
701
+ "epoch": 0.81,
702
+ "learning_rate": 0.0001,
703
+ "loss": 1.7981,
704
+ "step": 11600
705
+ },
706
+ {
707
+ "epoch": 0.82,
708
+ "learning_rate": 0.0001,
709
+ "loss": 1.8178,
710
+ "step": 11700
711
+ },
712
+ {
713
+ "epoch": 0.83,
714
+ "learning_rate": 0.0001,
715
+ "loss": 1.7732,
716
+ "step": 11800
717
+ },
718
+ {
719
+ "epoch": 0.83,
720
+ "learning_rate": 0.0001,
721
+ "loss": 1.7991,
722
+ "step": 11900
723
+ },
724
+ {
725
+ "epoch": 0.84,
726
+ "learning_rate": 0.0001,
727
+ "loss": 1.7949,
728
+ "step": 12000
729
+ },
730
+ {
731
+ "epoch": 0.85,
732
+ "learning_rate": 0.0001,
733
+ "loss": 1.7829,
734
+ "step": 12100
735
+ },
736
+ {
737
+ "epoch": 0.85,
738
+ "learning_rate": 0.0001,
739
+ "loss": 1.7816,
740
+ "step": 12200
741
+ },
742
+ {
743
+ "epoch": 0.86,
744
+ "learning_rate": 0.0001,
745
+ "loss": 1.7896,
746
+ "step": 12300
747
+ },
748
+ {
749
+ "epoch": 0.87,
750
+ "learning_rate": 0.0001,
751
+ "loss": 1.7797,
752
+ "step": 12400
753
+ },
754
+ {
755
+ "epoch": 0.87,
756
+ "learning_rate": 0.0001,
757
+ "loss": 1.7965,
758
+ "step": 12500
759
+ },
760
+ {
761
+ "epoch": 0.88,
762
+ "learning_rate": 0.0001,
763
+ "loss": 1.7855,
764
+ "step": 12600
765
+ },
766
+ {
767
+ "epoch": 0.89,
768
+ "learning_rate": 0.0001,
769
+ "loss": 1.7883,
770
+ "step": 12700
771
+ },
772
+ {
773
+ "epoch": 0.9,
774
+ "learning_rate": 0.0001,
775
+ "loss": 1.7606,
776
+ "step": 12800
777
+ },
778
+ {
779
+ "epoch": 0.9,
780
+ "learning_rate": 0.0001,
781
+ "loss": 1.7792,
782
+ "step": 12900
783
+ },
784
+ {
785
+ "epoch": 0.91,
786
+ "learning_rate": 0.0001,
787
+ "loss": 1.7773,
788
+ "step": 13000
789
+ },
790
+ {
791
+ "epoch": 0.92,
792
+ "learning_rate": 0.0001,
793
+ "loss": 1.7914,
794
+ "step": 13100
795
+ },
796
+ {
797
+ "epoch": 0.92,
798
+ "learning_rate": 0.0001,
799
+ "loss": 1.787,
800
+ "step": 13200
801
+ },
802
+ {
803
+ "epoch": 0.93,
804
+ "learning_rate": 0.0001,
805
+ "loss": 1.7892,
806
+ "step": 13300
807
+ },
808
+ {
809
+ "epoch": 0.94,
810
+ "learning_rate": 0.0001,
811
+ "loss": 1.7676,
812
+ "step": 13400
813
+ },
814
+ {
815
+ "epoch": 0.94,
816
+ "learning_rate": 0.0001,
817
+ "loss": 1.7775,
818
+ "step": 13500
819
+ },
820
+ {
821
+ "epoch": 0.95,
822
+ "learning_rate": 0.0001,
823
+ "loss": 1.7874,
824
+ "step": 13600
825
+ },
826
+ {
827
+ "epoch": 0.96,
828
+ "learning_rate": 0.0001,
829
+ "loss": 1.7517,
830
+ "step": 13700
831
+ },
832
+ {
833
+ "epoch": 0.97,
834
+ "learning_rate": 0.0001,
835
+ "loss": 1.7669,
836
+ "step": 13800
837
+ },
838
+ {
839
+ "epoch": 0.97,
840
+ "learning_rate": 0.0001,
841
+ "loss": 1.7647,
842
+ "step": 13900
843
+ },
844
+ {
845
+ "epoch": 0.98,
846
+ "learning_rate": 0.0001,
847
+ "loss": 1.7818,
848
+ "step": 14000
849
+ },
850
+ {
851
+ "epoch": 0.99,
852
+ "learning_rate": 0.0001,
853
+ "loss": 1.7826,
854
+ "step": 14100
855
+ },
856
+ {
857
+ "epoch": 0.99,
858
+ "learning_rate": 0.0001,
859
+ "loss": 1.7929,
860
+ "step": 14200
861
+ },
862
+ {
863
+ "epoch": 1.0,
864
+ "eval_loss": 1.7685546875,
865
+ "eval_runtime": 3.0679,
866
+ "eval_samples_per_second": 761.101,
867
+ "eval_steps_per_second": 95.178,
868
+ "step": 14299
869
+ }
870
+ ],
871
+ "max_steps": 14299,
872
+ "num_train_epochs": 1,
873
+ "total_flos": 4.847476972453888e+16,
874
+ "trial_name": null,
875
+ "trial_params": null
876
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8322db256e84b969591d3b4f264ac692df836629441824bc6ceee156e244871
3
+ size 4347
zero_to_fp32.py ADDED
@@ -0,0 +1,482 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import re
16
+ from collections import OrderedDict
17
+
18
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
19
+ # DeepSpeed data structures it has to be available in the current python environment.
20
+ from deepspeed.utils import logger
21
+ from deepspeed.checkpoint.constants import (DS_VERSION,
22
+ OPTIMIZER_STATE_DICT,
23
+ SINGLE_PARTITION_OF_FP32_GROUPS,
24
+ FP32_FLAT_GROUPS,
25
+ ZERO_STAGE,
26
+ PARTITION_COUNT,
27
+ PARAM_SHAPES,
28
+ BUFFER_NAMES)
29
+
30
+ debug = 0
31
+
32
+ # load to cpu
33
+ device = torch.device('cpu')
34
+
35
+
36
+ def atoi(text):
37
+ return int(text) if text.isdigit() else text
38
+
39
+
40
+ def natural_keys(text):
41
+ '''
42
+ alist.sort(key=natural_keys) sorts in human order
43
+ http://nedbatchelder.com/blog/200712/human_sorting.html
44
+ (See Toothy's implementation in the comments)
45
+ '''
46
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
47
+
48
+
49
+ def get_model_state_file(checkpoint_dir, zero_stage):
50
+ if not os.path.isdir(checkpoint_dir):
51
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
52
+
53
+ # there should be only one file
54
+ if zero_stage == 2:
55
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
56
+ elif zero_stage == 3:
57
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
58
+
59
+ if not os.path.exists(file):
60
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
61
+
62
+ return file
63
+
64
+
65
+ def get_optim_files(checkpoint_dir):
66
+ # XXX: need to test that this simple glob rule works for multi-node setup too
67
+ optim_files = sorted(glob.glob(os.path.join(checkpoint_dir,
68
+ "*_optim_states.pt")),
69
+ key=natural_keys)
70
+
71
+ if len(optim_files) == 0:
72
+ raise FileNotFoundError(
73
+ f"can't find '*_optim_states.pt' files in directory '{checkpoint_dir}'")
74
+
75
+ return optim_files
76
+
77
+
78
+ def parse_model_state(file):
79
+ state_dict = torch.load(file, map_location=device)
80
+
81
+ if BUFFER_NAMES not in state_dict:
82
+ raise ValueError(f"{file} is not a model state checkpoint")
83
+ buffer_names = state_dict[BUFFER_NAMES]
84
+ if debug:
85
+ print("Found buffers:", buffer_names)
86
+
87
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
88
+ buffers = {
89
+ k: v.float()
90
+ for k,
91
+ v in state_dict["module"].items() if k in buffer_names
92
+ }
93
+ param_shapes = state_dict[PARAM_SHAPES]
94
+
95
+ ds_version = state_dict.get(DS_VERSION, None)
96
+
97
+ return buffers, param_shapes, ds_version
98
+
99
+
100
+ def parse_optim_states(files, ds_checkpoint_dir):
101
+
102
+ total_files = len(files)
103
+ state_dicts = []
104
+ for f in files:
105
+ state_dicts.append(torch.load(f, map_location=device))
106
+
107
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
108
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
109
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
110
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
111
+
112
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
113
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
114
+ # use the max of the partition_count to get the dp world_size.
115
+
116
+ if type(world_size) is list:
117
+ world_size = max(world_size)
118
+
119
+ if world_size != total_files:
120
+ raise ValueError(
121
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
122
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
123
+ )
124
+
125
+ # the groups are named differently in each stage
126
+ if zero_stage == 2:
127
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
128
+ elif zero_stage == 3:
129
+ fp32_groups_key = FP32_FLAT_GROUPS
130
+ else:
131
+ raise ValueError(f"unknown zero stage {zero_stage}")
132
+
133
+ if zero_stage == 2:
134
+ fp32_flat_groups = [
135
+ state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key]
136
+ for i in range(len(state_dicts))
137
+ ]
138
+ elif zero_stage == 3:
139
+ # if there is more than one param group, there will be multiple flattened tensors - one
140
+ # flattened tensor per group - for simplicity merge them into a single tensor
141
+ #
142
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
143
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
144
+
145
+ fp32_flat_groups = [
146
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key],
147
+ 0) for i in range(len(state_dicts))
148
+ ]
149
+
150
+ return zero_stage, world_size, fp32_flat_groups
151
+
152
+
153
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
154
+ """
155
+ Returns fp32 state_dict reconstructed from ds checkpoint
156
+
157
+ Args:
158
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
159
+
160
+ """
161
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
162
+
163
+ optim_files = get_optim_files(ds_checkpoint_dir)
164
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
165
+ print(
166
+ f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
167
+
168
+ model_file = get_model_state_file(ds_checkpoint_dir, zero_stage)
169
+ buffers, param_shapes, ds_version = parse_model_state(model_file)
170
+ print(f'Parsing checkpoint created by deepspeed=={ds_version}')
171
+
172
+ if zero_stage == 2:
173
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size,
174
+ param_shapes,
175
+ fp32_flat_groups,
176
+ buffers)
177
+ elif zero_stage == 3:
178
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size,
179
+ param_shapes,
180
+ fp32_flat_groups,
181
+ buffers)
182
+
183
+
184
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size,
185
+ param_shapes,
186
+ fp32_flat_groups,
187
+ buffers):
188
+
189
+ # Reconstruction protocol:
190
+ #
191
+ # XXX: document this
192
+
193
+ if debug:
194
+ for i in range(world_size):
195
+ for j in range(len(fp32_flat_groups[0])):
196
+ print(
197
+ f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
198
+
199
+ # XXX: memory usage doubles here (zero2)
200
+ num_param_groups = len(fp32_flat_groups[0])
201
+ merged_single_partition_of_fp32_groups = []
202
+ for i in range(num_param_groups):
203
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
204
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
205
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
206
+ avail_numel = sum([
207
+ full_single_fp32_vector.numel()
208
+ for full_single_fp32_vector in merged_single_partition_of_fp32_groups
209
+ ])
210
+
211
+ if debug:
212
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
213
+ wanted_numel = sum(
214
+ [sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
215
+ # not asserting if there is a mismatch due to possible padding
216
+ print(f"Have {avail_numel} numels to process.")
217
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
218
+
219
+ state_dict = OrderedDict()
220
+
221
+ # buffers
222
+ state_dict.update(buffers)
223
+ if debug:
224
+ print(f"added {len(buffers)} buffers")
225
+
226
+ # params
227
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
228
+ # out-of-core computing solution
229
+ total_numel = 0
230
+ total_params = 0
231
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
232
+ offset = 0
233
+ avail_numel = full_single_fp32_vector.numel()
234
+ for name, shape in shapes.items():
235
+
236
+ unpartitioned_numel = shape.numel()
237
+ total_numel += unpartitioned_numel
238
+ total_params += 1
239
+
240
+ if debug:
241
+ print(
242
+ f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} "
243
+ )
244
+ state_dict[name] = full_single_fp32_vector.narrow(
245
+ 0,
246
+ offset,
247
+ unpartitioned_numel).view(shape)
248
+ offset += unpartitioned_numel
249
+
250
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
251
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
252
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
253
+ # live optimizer object, so we are checking that the numbers are within the right range
254
+ align_to = 2 * world_size
255
+
256
+ def zero2_align(x):
257
+ return align_to * math.ceil(x / align_to)
258
+
259
+ if debug:
260
+ print(f"original offset={offset}, avail_numel={avail_numel}")
261
+
262
+ offset = zero2_align(offset)
263
+ avail_numel = zero2_align(avail_numel)
264
+
265
+ if debug:
266
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
267
+
268
+ # Sanity check
269
+ if offset != avail_numel:
270
+ raise ValueError(
271
+ f"consumed {offset} numels out of {avail_numel} - something is wrong")
272
+
273
+ print(
274
+ f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
275
+ )
276
+
277
+ return state_dict
278
+
279
+
280
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
281
+ remainder = unpartitioned_numel % world_size
282
+ padding_numel = (world_size - remainder) if remainder else 0
283
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
284
+ return partitioned_numel, padding_numel
285
+
286
+
287
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size,
288
+ param_shapes,
289
+ fp32_flat_groups,
290
+ buffers):
291
+
292
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
293
+ # param, re-consolidating each param, while dealing with padding if any
294
+
295
+ avail_numel = fp32_flat_groups[0].numel() * world_size
296
+ # merge list of dicts, preserving order
297
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
298
+
299
+ if debug:
300
+ for i in range(world_size):
301
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
302
+
303
+ wanted_params = len(param_shapes)
304
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
305
+ # not asserting if there is a mismatch due to possible padding
306
+ print(f"Have {avail_numel} numels to process.")
307
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
308
+
309
+ state_dict = OrderedDict()
310
+
311
+ # buffers
312
+ state_dict.update(buffers)
313
+ if debug:
314
+ print(f"added {len(buffers)} buffers")
315
+
316
+ # params
317
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
318
+ # out-of-core computing solution
319
+ offset = 0
320
+ total_numel = 0
321
+ total_params = 0
322
+ for name, shape in param_shapes.items():
323
+
324
+ unpartitioned_numel = shape.numel()
325
+ total_numel += unpartitioned_numel
326
+ total_params += 1
327
+
328
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
329
+
330
+ if debug:
331
+ print(
332
+ f"{total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
333
+ )
334
+
335
+ # XXX: memory usage doubles here
336
+ state_dict[name] = torch.cat(
337
+ tuple(fp32_flat_groups[i].narrow(0,
338
+ offset,
339
+ partitioned_numel)
340
+ for i in range(world_size)),
341
+ 0).narrow(0,
342
+ 0,
343
+ unpartitioned_numel).view(shape)
344
+ offset += partitioned_numel
345
+
346
+ offset *= world_size
347
+
348
+ # Sanity check
349
+ if offset != avail_numel:
350
+ raise ValueError(
351
+ f"consumed {offset} numels out of {avail_numel} - something is wrong")
352
+
353
+ print(
354
+ f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements"
355
+ )
356
+
357
+ return state_dict
358
+
359
+
360
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
361
+ """
362
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
363
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
364
+ via a model hub.
365
+
366
+ Args:
367
+ - ``checkpoint_dir``: path to the desired checkpoint folder
368
+ - ``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``
369
+
370
+ Returns:
371
+ - pytorch ``state_dict``
372
+
373
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
374
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
375
+ the checkpoint.
376
+
377
+ A typical usage might be ::
378
+
379
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
380
+ # do the training and checkpoint saving
381
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
382
+ model = model.cpu() # move to cpu
383
+ model.load_state_dict(state_dict)
384
+ # submit to model hub or save the model to share with others
385
+
386
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
387
+ application. i.e. you will need to re-initialize the deepspeed engine, since
388
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
389
+
390
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
391
+
392
+ """
393
+ if tag is None:
394
+ latest_path = os.path.join(checkpoint_dir, 'latest')
395
+ if os.path.isfile(latest_path):
396
+ with open(latest_path, 'r') as fd:
397
+ tag = fd.read().strip()
398
+ else:
399
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
400
+
401
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
402
+
403
+ if not os.path.isdir(ds_checkpoint_dir):
404
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
405
+
406
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
407
+
408
+
409
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
410
+ """
411
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
412
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
413
+
414
+ Args:
415
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
416
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
417
+ - ``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``
418
+ """
419
+
420
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
421
+ print(f"Saving fp32 state dict to {output_file}")
422
+ torch.save(state_dict, output_file)
423
+
424
+
425
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
426
+ """
427
+ 1. Put the provided model to cpu
428
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
429
+ 3. Load it into the provided model
430
+
431
+ Args:
432
+ - ``model``: the model object to update
433
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
434
+ - ``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``
435
+
436
+ Returns:
437
+ - ``model`: modified model
438
+
439
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
440
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
441
+ conveniently placed for you in the checkpoint folder.
442
+
443
+ A typical usage might be ::
444
+
445
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
446
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
447
+ # submit to model hub or save the model to share with others
448
+
449
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
450
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
451
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
452
+
453
+ """
454
+ logger.info(f"Extracting fp32 weights")
455
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
456
+
457
+ logger.info(f"Overwriting model with fp32 weights")
458
+ model = model.cpu()
459
+ model.load_state_dict(state_dict, strict=False)
460
+
461
+ return model
462
+
463
+
464
+ if __name__ == "__main__":
465
+
466
+ parser = argparse.ArgumentParser()
467
+ parser.add_argument(
468
+ "checkpoint_dir",
469
+ type=str,
470
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
471
+ parser.add_argument(
472
+ "output_file",
473
+ type=str,
474
+ help=
475
+ "path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)"
476
+ )
477
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
478
+ args = parser.parse_args()
479
+
480
+ debug = args.debug
481
+
482
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)