abdoelsayed commited on
Commit
f1c59c2
·
verified ·
1 Parent(s): f8e36b5

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: meta-llama/Llama-3.1-8B
3
+ library_name: peft
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
200
+ ### Framework versions
201
+
202
+ - PEFT 0.13.2
adapter_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "meta-llama/Llama-3.1-8B",
5
+ "bias": "none",
6
+ "fan_in_fan_out": false,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layer_replication": null,
10
+ "layers_pattern": null,
11
+ "layers_to_transform": null,
12
+ "loftq_config": {},
13
+ "lora_alpha": 64,
14
+ "lora_dropout": 0.1,
15
+ "megatron_config": null,
16
+ "megatron_core": "megatron.core",
17
+ "modules_to_save": [
18
+ "classifier",
19
+ "score"
20
+ ],
21
+ "peft_type": "LORA",
22
+ "r": 32,
23
+ "rank_pattern": {},
24
+ "revision": null,
25
+ "target_modules": [
26
+ "gate_proj",
27
+ "down_proj",
28
+ "q_proj",
29
+ "up_proj",
30
+ "v_proj",
31
+ "o_proj"
32
+ ],
33
+ "task_type": "SEQ_CLS",
34
+ "use_dora": false,
35
+ "use_rslora": false
36
+ }
adapter_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f52fd3fd3df18dd00c06b077f84d09a1b77d968cf47b6416083b8ce63023f6a5
3
+ size 157428238
latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step1000
rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cae35d58c6f0a96413f50b5f6df11c4603e5055bfae9395f74b37d830c668519
3
+ size 15024
rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbcbe4dffbaae5e4c54a83d5b216d144936bc304cd200ea4d9bef91915c2411f
3
+ size 14960
rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f2fefd72a6fe9c258605b37db501943def18c128791b5b17ff7b07509e1dfb8
3
+ size 15024
rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4af83f1b60de97151e3a69400730cfdb7045fdca693d7cbbc3c825d5b5c882ed
3
+ size 14960
trainer_state.json ADDED
@@ -0,0 +1,733 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.6387225548902196,
5
+ "eval_steps": 500,
6
+ "global_step": 1000,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 0.006387225548902195,
13
+ "grad_norm": 3.5834698688009654,
14
+ "learning_rate": 4.007141788485205e-05,
15
+ "loss": 0.8162,
16
+ "step": 10
17
+ },
18
+ {
19
+ "epoch": 0.01277445109780439,
20
+ "grad_norm": 3.7982361966359415,
21
+ "learning_rate": 5.213411663697864e-05,
22
+ "loss": 0.4857,
23
+ "step": 20
24
+ },
25
+ {
26
+ "epoch": 0.019161676646706587,
27
+ "grad_norm": 3.3097747900168066,
28
+ "learning_rate": 5.919034306446858e-05,
29
+ "loss": 0.1919,
30
+ "step": 30
31
+ },
32
+ {
33
+ "epoch": 0.02554890219560878,
34
+ "grad_norm": 1.6554650990460391,
35
+ "learning_rate": 6.419681538910523e-05,
36
+ "loss": 0.1177,
37
+ "step": 40
38
+ },
39
+ {
40
+ "epoch": 0.031936127744510975,
41
+ "grad_norm": 1.0526158883209893,
42
+ "learning_rate": 6.80801370175775e-05,
43
+ "loss": 0.0997,
44
+ "step": 50
45
+ },
46
+ {
47
+ "epoch": 0.03832335329341317,
48
+ "grad_norm": 1.322844958779453,
49
+ "learning_rate": 7.125304181659517e-05,
50
+ "loss": 0.0987,
51
+ "step": 60
52
+ },
53
+ {
54
+ "epoch": 0.04471057884231537,
55
+ "grad_norm": 0.906098163414632,
56
+ "learning_rate": 7.393569459993276e-05,
57
+ "loss": 0.0902,
58
+ "step": 70
59
+ },
60
+ {
61
+ "epoch": 0.05109780439121756,
62
+ "grad_norm": 0.9742791206427208,
63
+ "learning_rate": 7.625951414123182e-05,
64
+ "loss": 0.08,
65
+ "step": 80
66
+ },
67
+ {
68
+ "epoch": 0.05748502994011976,
69
+ "grad_norm": 0.7369633538190276,
70
+ "learning_rate": 7.83092682440851e-05,
71
+ "loss": 0.0598,
72
+ "step": 90
73
+ },
74
+ {
75
+ "epoch": 0.06387225548902195,
76
+ "grad_norm": 0.6187428023320575,
77
+ "learning_rate": 8.01428357697041e-05,
78
+ "loss": 0.0836,
79
+ "step": 100
80
+ },
81
+ {
82
+ "epoch": 0.07025948103792415,
83
+ "grad_norm": 0.7404818716311581,
84
+ "learning_rate": 8.180149935405545e-05,
85
+ "loss": 0.0758,
86
+ "step": 110
87
+ },
88
+ {
89
+ "epoch": 0.07664670658682635,
90
+ "grad_norm": 0.4603749462575225,
91
+ "learning_rate": 8.331574056872175e-05,
92
+ "loss": 0.0698,
93
+ "step": 120
94
+ },
95
+ {
96
+ "epoch": 0.08303393213572854,
97
+ "grad_norm": 0.5780703019259222,
98
+ "learning_rate": 8.470870745519228e-05,
99
+ "loss": 0.0771,
100
+ "step": 130
101
+ },
102
+ {
103
+ "epoch": 0.08942115768463074,
104
+ "grad_norm": 0.7869338127501012,
105
+ "learning_rate": 8.599839335205934e-05,
106
+ "loss": 0.0741,
107
+ "step": 140
108
+ },
109
+ {
110
+ "epoch": 0.09580838323353294,
111
+ "grad_norm": 0.5085534390538137,
112
+ "learning_rate": 8.719906219719403e-05,
113
+ "loss": 0.0637,
114
+ "step": 150
115
+ },
116
+ {
117
+ "epoch": 0.10219560878243512,
118
+ "grad_norm": 0.6419093548122555,
119
+ "learning_rate": 8.83222128933584e-05,
120
+ "loss": 0.0683,
121
+ "step": 160
122
+ },
123
+ {
124
+ "epoch": 0.10858283433133732,
125
+ "grad_norm": 0.4014377657568054,
126
+ "learning_rate": 8.937725079936634e-05,
127
+ "loss": 0.0732,
128
+ "step": 170
129
+ },
130
+ {
131
+ "epoch": 0.11497005988023952,
132
+ "grad_norm": 0.4686184226271436,
133
+ "learning_rate": 9.03719669962117e-05,
134
+ "loss": 0.0727,
135
+ "step": 180
136
+ },
137
+ {
138
+ "epoch": 0.12135728542914172,
139
+ "grad_norm": 0.3553126799550481,
140
+ "learning_rate": 9.13128878003922e-05,
141
+ "loss": 0.0642,
142
+ "step": 190
143
+ },
144
+ {
145
+ "epoch": 0.1277445109780439,
146
+ "grad_norm": 0.2308342524288462,
147
+ "learning_rate": 9.220553452183068e-05,
148
+ "loss": 0.0662,
149
+ "step": 200
150
+ },
151
+ {
152
+ "epoch": 0.1341317365269461,
153
+ "grad_norm": 0.4244978948516096,
154
+ "learning_rate": 9.305461977954928e-05,
155
+ "loss": 0.0653,
156
+ "step": 210
157
+ },
158
+ {
159
+ "epoch": 0.1405189620758483,
160
+ "grad_norm": 0.6491159925885343,
161
+ "learning_rate": 9.386419810618205e-05,
162
+ "loss": 0.0692,
163
+ "step": 220
164
+ },
165
+ {
166
+ "epoch": 0.1469061876247505,
167
+ "grad_norm": 0.6586709935585672,
168
+ "learning_rate": 9.46377830473483e-05,
169
+ "loss": 0.0603,
170
+ "step": 230
171
+ },
172
+ {
173
+ "epoch": 0.1532934131736527,
174
+ "grad_norm": 0.4334717142812121,
175
+ "learning_rate": 9.537843932084834e-05,
176
+ "loss": 0.075,
177
+ "step": 240
178
+ },
179
+ {
180
+ "epoch": 0.1596806387225549,
181
+ "grad_norm": 0.31119556502835766,
182
+ "learning_rate": 9.608885615030295e-05,
183
+ "loss": 0.0646,
184
+ "step": 250
185
+ },
186
+ {
187
+ "epoch": 0.1660678642714571,
188
+ "grad_norm": 0.3201297094259269,
189
+ "learning_rate": 9.677140620731887e-05,
190
+ "loss": 0.0687,
191
+ "step": 260
192
+ },
193
+ {
194
+ "epoch": 0.1724550898203593,
195
+ "grad_norm": 0.3607671741835552,
196
+ "learning_rate": 9.742819342370165e-05,
197
+ "loss": 0.0611,
198
+ "step": 270
199
+ },
200
+ {
201
+ "epoch": 0.17884231536926148,
202
+ "grad_norm": 0.2599965595224881,
203
+ "learning_rate": 9.806109210418593e-05,
204
+ "loss": 0.0682,
205
+ "step": 280
206
+ },
207
+ {
208
+ "epoch": 0.18522954091816368,
209
+ "grad_norm": 0.32241547083298766,
210
+ "learning_rate": 9.86717791726321e-05,
211
+ "loss": 0.0612,
212
+ "step": 290
213
+ },
214
+ {
215
+ "epoch": 0.19161676646706588,
216
+ "grad_norm": 0.48624224094653656,
217
+ "learning_rate": 9.926176094932063e-05,
218
+ "loss": 0.0569,
219
+ "step": 300
220
+ },
221
+ {
222
+ "epoch": 0.19800399201596808,
223
+ "grad_norm": 0.3035297139442493,
224
+ "learning_rate": 9.983239553594597e-05,
225
+ "loss": 0.0581,
226
+ "step": 310
227
+ },
228
+ {
229
+ "epoch": 0.20439121756487025,
230
+ "grad_norm": 0.2209458722911404,
231
+ "learning_rate": 9.97870074547391e-05,
232
+ "loss": 0.0579,
233
+ "step": 320
234
+ },
235
+ {
236
+ "epoch": 0.21077844311377245,
237
+ "grad_norm": 0.32849509401911653,
238
+ "learning_rate": 9.943201987930422e-05,
239
+ "loss": 0.0594,
240
+ "step": 330
241
+ },
242
+ {
243
+ "epoch": 0.21716566866267464,
244
+ "grad_norm": 0.3121594199523004,
245
+ "learning_rate": 9.907703230386936e-05,
246
+ "loss": 0.0689,
247
+ "step": 340
248
+ },
249
+ {
250
+ "epoch": 0.22355289421157684,
251
+ "grad_norm": 0.37282218523682487,
252
+ "learning_rate": 9.87220447284345e-05,
253
+ "loss": 0.0591,
254
+ "step": 350
255
+ },
256
+ {
257
+ "epoch": 0.22994011976047904,
258
+ "grad_norm": 0.21932185059016668,
259
+ "learning_rate": 9.836705715299965e-05,
260
+ "loss": 0.0561,
261
+ "step": 360
262
+ },
263
+ {
264
+ "epoch": 0.23632734530938124,
265
+ "grad_norm": 0.40431591808333317,
266
+ "learning_rate": 9.801206957756479e-05,
267
+ "loss": 0.0547,
268
+ "step": 370
269
+ },
270
+ {
271
+ "epoch": 0.24271457085828343,
272
+ "grad_norm": 0.3545382413148979,
273
+ "learning_rate": 9.765708200212993e-05,
274
+ "loss": 0.068,
275
+ "step": 380
276
+ },
277
+ {
278
+ "epoch": 0.24910179640718563,
279
+ "grad_norm": 0.3708116952070532,
280
+ "learning_rate": 9.730209442669507e-05,
281
+ "loss": 0.0644,
282
+ "step": 390
283
+ },
284
+ {
285
+ "epoch": 0.2554890219560878,
286
+ "grad_norm": 0.2933151282788518,
287
+ "learning_rate": 9.69471068512602e-05,
288
+ "loss": 0.0554,
289
+ "step": 400
290
+ },
291
+ {
292
+ "epoch": 0.26187624750499,
293
+ "grad_norm": 0.2701122564574567,
294
+ "learning_rate": 9.659211927582535e-05,
295
+ "loss": 0.0669,
296
+ "step": 410
297
+ },
298
+ {
299
+ "epoch": 0.2682634730538922,
300
+ "grad_norm": 0.43233913171276295,
301
+ "learning_rate": 9.62371317003905e-05,
302
+ "loss": 0.0696,
303
+ "step": 420
304
+ },
305
+ {
306
+ "epoch": 0.2746506986027944,
307
+ "grad_norm": 0.29840407730897334,
308
+ "learning_rate": 9.588214412495564e-05,
309
+ "loss": 0.0583,
310
+ "step": 430
311
+ },
312
+ {
313
+ "epoch": 0.2810379241516966,
314
+ "grad_norm": 0.347519310387429,
315
+ "learning_rate": 9.552715654952076e-05,
316
+ "loss": 0.0675,
317
+ "step": 440
318
+ },
319
+ {
320
+ "epoch": 0.2874251497005988,
321
+ "grad_norm": 0.23159546291731048,
322
+ "learning_rate": 9.51721689740859e-05,
323
+ "loss": 0.0595,
324
+ "step": 450
325
+ },
326
+ {
327
+ "epoch": 0.293812375249501,
328
+ "grad_norm": 0.19539165396565417,
329
+ "learning_rate": 9.481718139865106e-05,
330
+ "loss": 0.0593,
331
+ "step": 460
332
+ },
333
+ {
334
+ "epoch": 0.3001996007984032,
335
+ "grad_norm": 0.3711679298627976,
336
+ "learning_rate": 9.446219382321619e-05,
337
+ "loss": 0.0576,
338
+ "step": 470
339
+ },
340
+ {
341
+ "epoch": 0.3065868263473054,
342
+ "grad_norm": 0.21594608036662566,
343
+ "learning_rate": 9.410720624778133e-05,
344
+ "loss": 0.0612,
345
+ "step": 480
346
+ },
347
+ {
348
+ "epoch": 0.3129740518962076,
349
+ "grad_norm": 0.38847976792533884,
350
+ "learning_rate": 9.375221867234647e-05,
351
+ "loss": 0.0558,
352
+ "step": 490
353
+ },
354
+ {
355
+ "epoch": 0.3193612774451098,
356
+ "grad_norm": 0.48499489939381346,
357
+ "learning_rate": 9.339723109691161e-05,
358
+ "loss": 0.0598,
359
+ "step": 500
360
+ },
361
+ {
362
+ "epoch": 0.325748502994012,
363
+ "grad_norm": 0.26871455217005846,
364
+ "learning_rate": 9.304224352147675e-05,
365
+ "loss": 0.0599,
366
+ "step": 510
367
+ },
368
+ {
369
+ "epoch": 0.3321357285429142,
370
+ "grad_norm": 0.3006779859330303,
371
+ "learning_rate": 9.26872559460419e-05,
372
+ "loss": 0.0533,
373
+ "step": 520
374
+ },
375
+ {
376
+ "epoch": 0.3385229540918164,
377
+ "grad_norm": 0.252910708387006,
378
+ "learning_rate": 9.233226837060704e-05,
379
+ "loss": 0.0609,
380
+ "step": 530
381
+ },
382
+ {
383
+ "epoch": 0.3449101796407186,
384
+ "grad_norm": 0.28615902583412134,
385
+ "learning_rate": 9.197728079517217e-05,
386
+ "loss": 0.0632,
387
+ "step": 540
388
+ },
389
+ {
390
+ "epoch": 0.35129740518962077,
391
+ "grad_norm": 0.3309472244637015,
392
+ "learning_rate": 9.162229321973731e-05,
393
+ "loss": 0.0657,
394
+ "step": 550
395
+ },
396
+ {
397
+ "epoch": 0.35768463073852297,
398
+ "grad_norm": 0.3181277078140241,
399
+ "learning_rate": 9.126730564430246e-05,
400
+ "loss": 0.0589,
401
+ "step": 560
402
+ },
403
+ {
404
+ "epoch": 0.36407185628742517,
405
+ "grad_norm": 0.5196112858300266,
406
+ "learning_rate": 9.09123180688676e-05,
407
+ "loss": 0.0645,
408
+ "step": 570
409
+ },
410
+ {
411
+ "epoch": 0.37045908183632736,
412
+ "grad_norm": 0.4316495610405202,
413
+ "learning_rate": 9.055733049343273e-05,
414
+ "loss": 0.0659,
415
+ "step": 580
416
+ },
417
+ {
418
+ "epoch": 0.37684630738522956,
419
+ "grad_norm": 0.25853510285529524,
420
+ "learning_rate": 9.020234291799787e-05,
421
+ "loss": 0.0582,
422
+ "step": 590
423
+ },
424
+ {
425
+ "epoch": 0.38323353293413176,
426
+ "grad_norm": 0.28576780733983087,
427
+ "learning_rate": 8.984735534256301e-05,
428
+ "loss": 0.0531,
429
+ "step": 600
430
+ },
431
+ {
432
+ "epoch": 0.38962075848303396,
433
+ "grad_norm": 0.30628185946436504,
434
+ "learning_rate": 8.949236776712816e-05,
435
+ "loss": 0.0577,
436
+ "step": 610
437
+ },
438
+ {
439
+ "epoch": 0.39600798403193616,
440
+ "grad_norm": 0.22146965371135377,
441
+ "learning_rate": 8.91373801916933e-05,
442
+ "loss": 0.0571,
443
+ "step": 620
444
+ },
445
+ {
446
+ "epoch": 0.4023952095808383,
447
+ "grad_norm": 0.2720642528700885,
448
+ "learning_rate": 8.878239261625844e-05,
449
+ "loss": 0.059,
450
+ "step": 630
451
+ },
452
+ {
453
+ "epoch": 0.4087824351297405,
454
+ "grad_norm": 0.35619962554831525,
455
+ "learning_rate": 8.842740504082358e-05,
456
+ "loss": 0.0614,
457
+ "step": 640
458
+ },
459
+ {
460
+ "epoch": 0.4151696606786427,
461
+ "grad_norm": 0.28668258535201413,
462
+ "learning_rate": 8.807241746538871e-05,
463
+ "loss": 0.0699,
464
+ "step": 650
465
+ },
466
+ {
467
+ "epoch": 0.4215568862275449,
468
+ "grad_norm": 0.35772133791366534,
469
+ "learning_rate": 8.771742988995385e-05,
470
+ "loss": 0.0599,
471
+ "step": 660
472
+ },
473
+ {
474
+ "epoch": 0.4279441117764471,
475
+ "grad_norm": 0.3547047177760543,
476
+ "learning_rate": 8.7362442314519e-05,
477
+ "loss": 0.0563,
478
+ "step": 670
479
+ },
480
+ {
481
+ "epoch": 0.4343313373253493,
482
+ "grad_norm": 0.24898549550006935,
483
+ "learning_rate": 8.700745473908413e-05,
484
+ "loss": 0.0553,
485
+ "step": 680
486
+ },
487
+ {
488
+ "epoch": 0.4407185628742515,
489
+ "grad_norm": 0.34439451125458864,
490
+ "learning_rate": 8.665246716364927e-05,
491
+ "loss": 0.0525,
492
+ "step": 690
493
+ },
494
+ {
495
+ "epoch": 0.4471057884231537,
496
+ "grad_norm": 0.27788279819961054,
497
+ "learning_rate": 8.629747958821441e-05,
498
+ "loss": 0.0559,
499
+ "step": 700
500
+ },
501
+ {
502
+ "epoch": 0.4534930139720559,
503
+ "grad_norm": 0.358392882540888,
504
+ "learning_rate": 8.594249201277956e-05,
505
+ "loss": 0.0657,
506
+ "step": 710
507
+ },
508
+ {
509
+ "epoch": 0.4598802395209581,
510
+ "grad_norm": 0.3111624222426367,
511
+ "learning_rate": 8.55875044373447e-05,
512
+ "loss": 0.0472,
513
+ "step": 720
514
+ },
515
+ {
516
+ "epoch": 0.4662674650698603,
517
+ "grad_norm": 0.26806713373994445,
518
+ "learning_rate": 8.523251686190984e-05,
519
+ "loss": 0.0696,
520
+ "step": 730
521
+ },
522
+ {
523
+ "epoch": 0.4726546906187625,
524
+ "grad_norm": 0.2748488176683564,
525
+ "learning_rate": 8.487752928647498e-05,
526
+ "loss": 0.063,
527
+ "step": 740
528
+ },
529
+ {
530
+ "epoch": 0.47904191616766467,
531
+ "grad_norm": 0.18592617627322836,
532
+ "learning_rate": 8.452254171104012e-05,
533
+ "loss": 0.0609,
534
+ "step": 750
535
+ },
536
+ {
537
+ "epoch": 0.48542914171656687,
538
+ "grad_norm": 0.38695621265068386,
539
+ "learning_rate": 8.416755413560525e-05,
540
+ "loss": 0.062,
541
+ "step": 760
542
+ },
543
+ {
544
+ "epoch": 0.49181636726546907,
545
+ "grad_norm": 0.3158810203428474,
546
+ "learning_rate": 8.38125665601704e-05,
547
+ "loss": 0.0592,
548
+ "step": 770
549
+ },
550
+ {
551
+ "epoch": 0.49820359281437127,
552
+ "grad_norm": 0.3362065389804566,
553
+ "learning_rate": 8.345757898473555e-05,
554
+ "loss": 0.0613,
555
+ "step": 780
556
+ },
557
+ {
558
+ "epoch": 0.5045908183632735,
559
+ "grad_norm": 0.25748557706326924,
560
+ "learning_rate": 8.310259140930067e-05,
561
+ "loss": 0.0529,
562
+ "step": 790
563
+ },
564
+ {
565
+ "epoch": 0.5109780439121756,
566
+ "grad_norm": 0.29455626027596066,
567
+ "learning_rate": 8.274760383386582e-05,
568
+ "loss": 0.065,
569
+ "step": 800
570
+ },
571
+ {
572
+ "epoch": 0.5173652694610779,
573
+ "grad_norm": 0.2564019757489936,
574
+ "learning_rate": 8.239261625843096e-05,
575
+ "loss": 0.0579,
576
+ "step": 810
577
+ },
578
+ {
579
+ "epoch": 0.52375249500998,
580
+ "grad_norm": 0.228508320126866,
581
+ "learning_rate": 8.20376286829961e-05,
582
+ "loss": 0.0618,
583
+ "step": 820
584
+ },
585
+ {
586
+ "epoch": 0.5301397205588823,
587
+ "grad_norm": 0.17395934565113735,
588
+ "learning_rate": 8.168264110756124e-05,
589
+ "loss": 0.0601,
590
+ "step": 830
591
+ },
592
+ {
593
+ "epoch": 0.5365269461077844,
594
+ "grad_norm": 0.1845587781224566,
595
+ "learning_rate": 8.132765353212638e-05,
596
+ "loss": 0.0646,
597
+ "step": 840
598
+ },
599
+ {
600
+ "epoch": 0.5429141716566867,
601
+ "grad_norm": 0.219121974587572,
602
+ "learning_rate": 8.097266595669152e-05,
603
+ "loss": 0.0602,
604
+ "step": 850
605
+ },
606
+ {
607
+ "epoch": 0.5493013972055888,
608
+ "grad_norm": 0.3134533264569832,
609
+ "learning_rate": 8.061767838125665e-05,
610
+ "loss": 0.0593,
611
+ "step": 860
612
+ },
613
+ {
614
+ "epoch": 0.555688622754491,
615
+ "grad_norm": 0.36630204830289737,
616
+ "learning_rate": 8.02626908058218e-05,
617
+ "loss": 0.0606,
618
+ "step": 870
619
+ },
620
+ {
621
+ "epoch": 0.5620758483033932,
622
+ "grad_norm": 0.2390442131459619,
623
+ "learning_rate": 7.990770323038695e-05,
624
+ "loss": 0.0572,
625
+ "step": 880
626
+ },
627
+ {
628
+ "epoch": 0.5684630738522954,
629
+ "grad_norm": 0.2906363057717337,
630
+ "learning_rate": 7.955271565495209e-05,
631
+ "loss": 0.0687,
632
+ "step": 890
633
+ },
634
+ {
635
+ "epoch": 0.5748502994011976,
636
+ "grad_norm": 0.2853917682780398,
637
+ "learning_rate": 7.919772807951722e-05,
638
+ "loss": 0.0643,
639
+ "step": 900
640
+ },
641
+ {
642
+ "epoch": 0.5812375249500998,
643
+ "grad_norm": 0.3544408088733472,
644
+ "learning_rate": 7.884274050408236e-05,
645
+ "loss": 0.0574,
646
+ "step": 910
647
+ },
648
+ {
649
+ "epoch": 0.587624750499002,
650
+ "grad_norm": 0.24181631469575632,
651
+ "learning_rate": 7.848775292864751e-05,
652
+ "loss": 0.0697,
653
+ "step": 920
654
+ },
655
+ {
656
+ "epoch": 0.5940119760479042,
657
+ "grad_norm": 0.28668164498739,
658
+ "learning_rate": 7.813276535321264e-05,
659
+ "loss": 0.0641,
660
+ "step": 930
661
+ },
662
+ {
663
+ "epoch": 0.6003992015968064,
664
+ "grad_norm": 0.29519716447463473,
665
+ "learning_rate": 7.777777777777778e-05,
666
+ "loss": 0.0547,
667
+ "step": 940
668
+ },
669
+ {
670
+ "epoch": 0.6067864271457086,
671
+ "grad_norm": 0.2797455777496235,
672
+ "learning_rate": 7.742279020234292e-05,
673
+ "loss": 0.0622,
674
+ "step": 950
675
+ },
676
+ {
677
+ "epoch": 0.6131736526946108,
678
+ "grad_norm": 0.20698136186718125,
679
+ "learning_rate": 7.706780262690806e-05,
680
+ "loss": 0.0538,
681
+ "step": 960
682
+ },
683
+ {
684
+ "epoch": 0.619560878243513,
685
+ "grad_norm": 0.3029284687538603,
686
+ "learning_rate": 7.671281505147319e-05,
687
+ "loss": 0.0553,
688
+ "step": 970
689
+ },
690
+ {
691
+ "epoch": 0.6259481037924152,
692
+ "grad_norm": 0.3308461091763622,
693
+ "learning_rate": 7.635782747603835e-05,
694
+ "loss": 0.0592,
695
+ "step": 980
696
+ },
697
+ {
698
+ "epoch": 0.6323353293413174,
699
+ "grad_norm": 0.2652350297520287,
700
+ "learning_rate": 7.600283990060349e-05,
701
+ "loss": 0.0611,
702
+ "step": 990
703
+ },
704
+ {
705
+ "epoch": 0.6387225548902196,
706
+ "grad_norm": 0.20354784105739357,
707
+ "learning_rate": 7.564785232516862e-05,
708
+ "loss": 0.059,
709
+ "step": 1000
710
+ }
711
+ ],
712
+ "logging_steps": 10,
713
+ "max_steps": 3130,
714
+ "num_input_tokens_seen": 0,
715
+ "num_train_epochs": 2,
716
+ "save_steps": 200,
717
+ "stateful_callbacks": {
718
+ "TrainerControl": {
719
+ "args": {
720
+ "should_epoch_stop": false,
721
+ "should_evaluate": false,
722
+ "should_log": false,
723
+ "should_save": true,
724
+ "should_training_stop": false
725
+ },
726
+ "attributes": {}
727
+ }
728
+ },
729
+ "total_flos": 0.0,
730
+ "train_batch_size": 8,
731
+ "trial_name": null,
732
+ "trial_params": null
733
+ }
zero_to_fp32.py ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example:
14
+ # python zero_to_fp32.py . output_dir/
15
+ # or
16
+ # python zero_to_fp32.py . output_dir/ --safe_serialization
17
+
18
+ import argparse
19
+ import torch
20
+ import glob
21
+ import math
22
+ import os
23
+ import re
24
+ import json
25
+ from tqdm import tqdm
26
+ from collections import OrderedDict
27
+ from dataclasses import dataclass
28
+
29
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
30
+ # DeepSpeed data structures it has to be available in the current python environment.
31
+ from deepspeed.utils import logger
32
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
33
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
34
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
35
+
36
+
37
+ @dataclass
38
+ class zero_model_state:
39
+ buffers: dict()
40
+ param_shapes: dict()
41
+ shared_params: list
42
+ ds_version: int
43
+ frozen_param_shapes: dict()
44
+ frozen_param_fragments: dict()
45
+
46
+
47
+ debug = 0
48
+
49
+ # load to cpu
50
+ device = torch.device('cpu')
51
+
52
+
53
+ def atoi(text):
54
+ return int(text) if text.isdigit() else text
55
+
56
+
57
+ def natural_keys(text):
58
+ '''
59
+ alist.sort(key=natural_keys) sorts in human order
60
+ http://nedbatchelder.com/blog/200712/human_sorting.html
61
+ (See Toothy's implementation in the comments)
62
+ '''
63
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
64
+
65
+
66
+ def get_model_state_file(checkpoint_dir, zero_stage):
67
+ if not os.path.isdir(checkpoint_dir):
68
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
69
+
70
+ # there should be only one file
71
+ if zero_stage <= 2:
72
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
73
+ elif zero_stage == 3:
74
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
75
+
76
+ if not os.path.exists(file):
77
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
78
+
79
+ return file
80
+
81
+
82
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
83
+ # XXX: need to test that this simple glob rule works for multi-node setup too
84
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
85
+
86
+ if len(ckpt_files) == 0:
87
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
88
+
89
+ return ckpt_files
90
+
91
+
92
+ def get_optim_files(checkpoint_dir):
93
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
94
+
95
+
96
+ def get_model_state_files(checkpoint_dir):
97
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
98
+
99
+
100
+ def parse_model_states(files):
101
+ zero_model_states = []
102
+ for file in files:
103
+ state_dict = torch.load(file, map_location=device)
104
+
105
+ if BUFFER_NAMES not in state_dict:
106
+ raise ValueError(f"{file} is not a model state checkpoint")
107
+ buffer_names = state_dict[BUFFER_NAMES]
108
+ if debug:
109
+ print("Found buffers:", buffer_names)
110
+
111
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
112
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
113
+ param_shapes = state_dict[PARAM_SHAPES]
114
+
115
+ # collect parameters that are included in param_shapes
116
+ param_names = []
117
+ for s in param_shapes:
118
+ for name in s.keys():
119
+ param_names.append(name)
120
+
121
+ # update with frozen parameters
122
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
123
+ if frozen_param_shapes is not None:
124
+ if debug:
125
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
126
+ param_names += list(frozen_param_shapes.keys())
127
+
128
+ # handle shared params
129
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
130
+
131
+ ds_version = state_dict.get(DS_VERSION, None)
132
+
133
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
134
+
135
+ z_model_state = zero_model_state(buffers=buffers,
136
+ param_shapes=param_shapes,
137
+ shared_params=shared_params,
138
+ ds_version=ds_version,
139
+ frozen_param_shapes=frozen_param_shapes,
140
+ frozen_param_fragments=frozen_param_fragments)
141
+ zero_model_states.append(z_model_state)
142
+
143
+ return zero_model_states
144
+
145
+
146
+ def parse_optim_states(files, ds_checkpoint_dir):
147
+ total_files = len(files)
148
+ state_dicts = []
149
+ for f in files:
150
+ state_dict = torch.load(f, map_location=device)
151
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
152
+ # and also handle the case where it was already removed by another helper script
153
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
154
+ state_dicts.append(state_dict)
155
+
156
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
157
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
158
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
159
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
160
+
161
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
162
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
163
+ # use the max of the partition_count to get the dp world_size.
164
+
165
+ if type(world_size) is list:
166
+ world_size = max(world_size)
167
+
168
+ if world_size != total_files:
169
+ raise ValueError(
170
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
171
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
172
+ )
173
+
174
+ # the groups are named differently in each stage
175
+ if zero_stage <= 2:
176
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
177
+ elif zero_stage == 3:
178
+ fp32_groups_key = FP32_FLAT_GROUPS
179
+ else:
180
+ raise ValueError(f"unknown zero stage {zero_stage}")
181
+
182
+ if zero_stage <= 2:
183
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
184
+ elif zero_stage == 3:
185
+ # if there is more than one param group, there will be multiple flattened tensors - one
186
+ # flattened tensor per group - for simplicity merge them into a single tensor
187
+ #
188
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
189
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
190
+
191
+ fp32_flat_groups = [
192
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
193
+ ]
194
+
195
+ return zero_stage, world_size, fp32_flat_groups
196
+
197
+
198
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
199
+ """
200
+ Returns fp32 state_dict reconstructed from ds checkpoint
201
+
202
+ Args:
203
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
204
+
205
+ """
206
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
207
+
208
+ optim_files = get_optim_files(ds_checkpoint_dir)
209
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
210
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
211
+
212
+ model_files = get_model_state_files(ds_checkpoint_dir)
213
+
214
+ zero_model_states = parse_model_states(model_files)
215
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
216
+
217
+ if zero_stage <= 2:
218
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
219
+ exclude_frozen_parameters)
220
+ elif zero_stage == 3:
221
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
222
+ exclude_frozen_parameters)
223
+
224
+
225
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
226
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
227
+ return
228
+
229
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
230
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
231
+
232
+ if debug:
233
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
234
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
235
+
236
+ wanted_params = len(frozen_param_shapes)
237
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
238
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
239
+ print(f'Frozen params: Have {avail_numel} numels to process.')
240
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
241
+
242
+ total_params = 0
243
+ total_numel = 0
244
+ for name, shape in frozen_param_shapes.items():
245
+ total_params += 1
246
+ unpartitioned_numel = shape.numel()
247
+ total_numel += unpartitioned_numel
248
+
249
+ state_dict[name] = frozen_param_fragments[name]
250
+
251
+ if debug:
252
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
253
+
254
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
255
+
256
+
257
+ def _has_callable(obj, fn):
258
+ attr = getattr(obj, fn, None)
259
+ return callable(attr)
260
+
261
+
262
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
263
+ param_shapes = zero_model_states[0].param_shapes
264
+
265
+ # Reconstruction protocol:
266
+ #
267
+ # XXX: document this
268
+
269
+ if debug:
270
+ for i in range(world_size):
271
+ for j in range(len(fp32_flat_groups[0])):
272
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
273
+
274
+ # XXX: memory usage doubles here (zero2)
275
+ num_param_groups = len(fp32_flat_groups[0])
276
+ merged_single_partition_of_fp32_groups = []
277
+ for i in range(num_param_groups):
278
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
279
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
280
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
281
+ avail_numel = sum(
282
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
283
+
284
+ if debug:
285
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
286
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
287
+ # not asserting if there is a mismatch due to possible padding
288
+ print(f"Have {avail_numel} numels to process.")
289
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
290
+
291
+ # params
292
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
293
+ # out-of-core computing solution
294
+ total_numel = 0
295
+ total_params = 0
296
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
297
+ offset = 0
298
+ avail_numel = full_single_fp32_vector.numel()
299
+ for name, shape in shapes.items():
300
+
301
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
302
+ total_numel += unpartitioned_numel
303
+ total_params += 1
304
+
305
+ if debug:
306
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
307
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
308
+ offset += unpartitioned_numel
309
+
310
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
311
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
312
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
313
+ # live optimizer object, so we are checking that the numbers are within the right range
314
+ align_to = 2 * world_size
315
+
316
+ def zero2_align(x):
317
+ return align_to * math.ceil(x / align_to)
318
+
319
+ if debug:
320
+ print(f"original offset={offset}, avail_numel={avail_numel}")
321
+
322
+ offset = zero2_align(offset)
323
+ avail_numel = zero2_align(avail_numel)
324
+
325
+ if debug:
326
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
327
+
328
+ # Sanity check
329
+ if offset != avail_numel:
330
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
331
+
332
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
333
+
334
+
335
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
336
+ exclude_frozen_parameters):
337
+ state_dict = OrderedDict()
338
+
339
+ # buffers
340
+ buffers = zero_model_states[0].buffers
341
+ state_dict.update(buffers)
342
+ if debug:
343
+ print(f"added {len(buffers)} buffers")
344
+
345
+ if not exclude_frozen_parameters:
346
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
347
+
348
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
349
+
350
+ # recover shared parameters
351
+ for pair in zero_model_states[0].shared_params:
352
+ if pair[1] in state_dict:
353
+ state_dict[pair[0]] = state_dict[pair[1]]
354
+
355
+ return state_dict
356
+
357
+
358
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
359
+ remainder = unpartitioned_numel % world_size
360
+ padding_numel = (world_size - remainder) if remainder else 0
361
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
362
+ return partitioned_numel, padding_numel
363
+
364
+
365
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
366
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
367
+ return
368
+
369
+ if debug:
370
+ for i in range(world_size):
371
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
372
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
373
+
374
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
375
+ wanted_params = len(frozen_param_shapes)
376
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
377
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
378
+ print(f'Frozen params: Have {avail_numel} numels to process.')
379
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
380
+
381
+ total_params = 0
382
+ total_numel = 0
383
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
384
+ total_params += 1
385
+ unpartitioned_numel = shape.numel()
386
+ total_numel += unpartitioned_numel
387
+
388
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
389
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
390
+
391
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
392
+
393
+ if debug:
394
+ print(
395
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
396
+ )
397
+
398
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
399
+
400
+
401
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
402
+ param_shapes = zero_model_states[0].param_shapes
403
+ avail_numel = fp32_flat_groups[0].numel() * world_size
404
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
405
+ # param, re-consolidating each param, while dealing with padding if any
406
+
407
+ # merge list of dicts, preserving order
408
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
409
+
410
+ if debug:
411
+ for i in range(world_size):
412
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
413
+
414
+ wanted_params = len(param_shapes)
415
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
416
+ # not asserting if there is a mismatch due to possible padding
417
+ avail_numel = fp32_flat_groups[0].numel() * world_size
418
+ print(f"Trainable params: Have {avail_numel} numels to process.")
419
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
420
+
421
+ # params
422
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
423
+ # out-of-core computing solution
424
+ offset = 0
425
+ total_numel = 0
426
+ total_params = 0
427
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering Sharded Weights'):
428
+ unpartitioned_numel = shape.numel()
429
+ total_numel += unpartitioned_numel
430
+ total_params += 1
431
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
432
+
433
+ if debug:
434
+ print(
435
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
436
+ )
437
+
438
+ # XXX: memory usage doubles here
439
+ state_dict[name] = torch.cat(
440
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
441
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
442
+ offset += partitioned_numel
443
+
444
+ offset *= world_size
445
+
446
+ # Sanity check
447
+ if offset != avail_numel:
448
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
449
+
450
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
451
+
452
+
453
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
454
+ exclude_frozen_parameters):
455
+ state_dict = OrderedDict()
456
+
457
+ # buffers
458
+ buffers = zero_model_states[0].buffers
459
+ state_dict.update(buffers)
460
+ if debug:
461
+ print(f"added {len(buffers)} buffers")
462
+
463
+ if not exclude_frozen_parameters:
464
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
465
+
466
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
467
+
468
+ # recover shared parameters
469
+ for pair in zero_model_states[0].shared_params:
470
+ if pair[1] in state_dict:
471
+ state_dict[pair[0]] = state_dict[pair[1]]
472
+
473
+ return state_dict
474
+
475
+
476
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
477
+ """
478
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
479
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
480
+ via a model hub.
481
+
482
+ Args:
483
+ - ``checkpoint_dir``: path to the desired checkpoint folder
484
+ - ``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``
485
+ - ``exclude_frozen_parameters``: exclude frozen parameters
486
+
487
+ Returns:
488
+ - pytorch ``state_dict``
489
+
490
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
491
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
492
+ the checkpoint.
493
+
494
+ A typical usage might be ::
495
+
496
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
497
+ # do the training and checkpoint saving
498
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
499
+ model = model.cpu() # move to cpu
500
+ model.load_state_dict(state_dict)
501
+ # submit to model hub or save the model to share with others
502
+
503
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
504
+ application. i.e. you will need to re-initialize the deepspeed engine, since
505
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
506
+
507
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
508
+
509
+ """
510
+ if tag is None:
511
+ latest_path = os.path.join(checkpoint_dir, 'latest')
512
+ if os.path.isfile(latest_path):
513
+ with open(latest_path, 'r') as fd:
514
+ tag = fd.read().strip()
515
+ else:
516
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
517
+
518
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
519
+
520
+ if not os.path.isdir(ds_checkpoint_dir):
521
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
522
+
523
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
524
+
525
+
526
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
527
+ output_dir,
528
+ max_shard_size="5GB",
529
+ safe_serialization=False,
530
+ tag=None,
531
+ exclude_frozen_parameters=False):
532
+ """
533
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
534
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
535
+
536
+ Args:
537
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
538
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
539
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
540
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
541
+ - ``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``
542
+ - ``exclude_frozen_parameters``: exclude frozen parameters
543
+ """
544
+ # Dependency pre-check
545
+ if safe_serialization:
546
+ try:
547
+ from safetensors.torch import save_file
548
+ except ImportError:
549
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
550
+ raise
551
+ if max_shard_size is not None:
552
+ try:
553
+ from huggingface_hub import split_torch_state_dict_into_shards
554
+ except ImportError:
555
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
556
+ raise
557
+
558
+ # Convert zero checkpoint to state_dict
559
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
560
+
561
+ # Shard the model if it is too big.
562
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
563
+ if max_shard_size is not None:
564
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
565
+ state_dict_split = split_torch_state_dict_into_shards(state_dict,
566
+ filename_pattern=filename_pattern,
567
+ max_shard_size=max_shard_size)
568
+ else:
569
+ from collections import namedtuple
570
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
571
+ state_dict_split = StateDictSplit(is_sharded=False,
572
+ filename_to_tensors={weights_name: list(state_dict.keys())})
573
+
574
+ # Save the model
575
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
576
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
577
+ shard = {tensor: state_dict[tensor].contiguous() for tensor in tensors}
578
+ output_path = os.path.join(output_dir, shard_file)
579
+ if safe_serialization:
580
+ save_file(shard, output_path, metadata={"format": "pt"})
581
+ else:
582
+ torch.save(shard, output_path)
583
+
584
+ # Save index if sharded
585
+ if state_dict_split.is_sharded:
586
+ index = {
587
+ "metadata": state_dict_split.metadata,
588
+ "weight_map": state_dict_split.tensor_to_filename,
589
+ }
590
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
591
+ save_index_file = os.path.join(output_dir, save_index_file)
592
+ with open(save_index_file, "w", encoding="utf-8") as f:
593
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
594
+ f.write(content)
595
+
596
+
597
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
598
+ """
599
+ 1. Put the provided model to cpu
600
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
601
+ 3. Load it into the provided model
602
+
603
+ Args:
604
+ - ``model``: the model object to update
605
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
606
+ - ``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``
607
+
608
+ Returns:
609
+ - ``model`: modified model
610
+
611
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
612
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
613
+ conveniently placed for you in the checkpoint folder.
614
+
615
+ A typical usage might be ::
616
+
617
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
618
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
619
+ # submit to model hub or save the model to share with others
620
+
621
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
622
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
623
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
624
+
625
+ """
626
+ logger.info(f"Extracting fp32 weights")
627
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
628
+
629
+ logger.info(f"Overwriting model with fp32 weights")
630
+ model = model.cpu()
631
+ model.load_state_dict(state_dict, strict=False)
632
+
633
+ return model
634
+
635
+
636
+ if __name__ == "__main__":
637
+ parser = argparse.ArgumentParser()
638
+ parser.add_argument("checkpoint_dir",
639
+ type=str,
640
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
641
+ parser.add_argument("output_dir",
642
+ type=str,
643
+ help="directory to the pytorch fp32 state_dict output files"
644
+ "(e.g. path/checkpoint-12-output/)")
645
+ parser.add_argument(
646
+ "--max_shard_size",
647
+ type=str,
648
+ default="5GB",
649
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
650
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
651
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
652
+ "without CPU OOM issues.")
653
+ parser.add_argument(
654
+ "--safe_serialization",
655
+ default=False,
656
+ action='store_true',
657
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
658
+ parser.add_argument("-t",
659
+ "--tag",
660
+ type=str,
661
+ default=None,
662
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
663
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
664
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
665
+ args = parser.parse_args()
666
+
667
+ debug = args.debug
668
+
669
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
670
+ args.output_dir,
671
+ max_shard_size=args.max_shard_size,
672
+ safe_serialization=args.safe_serialization,
673
+ tag=args.tag,
674
+ exclude_frozen_parameters=args.exclude_frozen_parameters)