g4rg commited on
Commit
b07c260
·
verified ·
1 Parent(s): b025c49

Training in progress, step 66, checkpoint

Browse files
Files changed (36) hide show
  1. last-checkpoint/README.md +202 -0
  2. last-checkpoint/adapter_config.json +34 -0
  3. last-checkpoint/adapter_model.safetensors +3 -0
  4. last-checkpoint/global_step66/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
  5. last-checkpoint/global_step66/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt +3 -0
  6. last-checkpoint/global_step66/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt +3 -0
  7. last-checkpoint/global_step66/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt +3 -0
  8. last-checkpoint/global_step66/bf16_zero_pp_rank_4_mp_rank_00_optim_states.pt +3 -0
  9. last-checkpoint/global_step66/bf16_zero_pp_rank_5_mp_rank_00_optim_states.pt +3 -0
  10. last-checkpoint/global_step66/bf16_zero_pp_rank_6_mp_rank_00_optim_states.pt +3 -0
  11. last-checkpoint/global_step66/bf16_zero_pp_rank_7_mp_rank_00_optim_states.pt +3 -0
  12. last-checkpoint/global_step66/zero_pp_rank_0_mp_rank_00_model_states.pt +3 -0
  13. last-checkpoint/global_step66/zero_pp_rank_1_mp_rank_00_model_states.pt +3 -0
  14. last-checkpoint/global_step66/zero_pp_rank_2_mp_rank_00_model_states.pt +3 -0
  15. last-checkpoint/global_step66/zero_pp_rank_3_mp_rank_00_model_states.pt +3 -0
  16. last-checkpoint/global_step66/zero_pp_rank_4_mp_rank_00_model_states.pt +3 -0
  17. last-checkpoint/global_step66/zero_pp_rank_5_mp_rank_00_model_states.pt +3 -0
  18. last-checkpoint/global_step66/zero_pp_rank_6_mp_rank_00_model_states.pt +3 -0
  19. last-checkpoint/global_step66/zero_pp_rank_7_mp_rank_00_model_states.pt +3 -0
  20. last-checkpoint/latest +1 -0
  21. last-checkpoint/rng_state_0.pth +3 -0
  22. last-checkpoint/rng_state_1.pth +3 -0
  23. last-checkpoint/rng_state_2.pth +3 -0
  24. last-checkpoint/rng_state_3.pth +3 -0
  25. last-checkpoint/rng_state_4.pth +3 -0
  26. last-checkpoint/rng_state_5.pth +3 -0
  27. last-checkpoint/rng_state_6.pth +3 -0
  28. last-checkpoint/rng_state_7.pth +3 -0
  29. last-checkpoint/scheduler.pt +3 -0
  30. last-checkpoint/special_tokens_map.json +30 -0
  31. last-checkpoint/tokenizer.json +0 -0
  32. last-checkpoint/tokenizer.model +3 -0
  33. last-checkpoint/tokenizer_config.json +0 -0
  34. last-checkpoint/trainer_state.json +511 -0
  35. last-checkpoint/training_args.bin +3 -0
  36. last-checkpoint/zero_to_fp32.py +604 -0
last-checkpoint/README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: unsloth/Mistral-Small-Instruct-2409
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.0
last-checkpoint/adapter_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "unsloth/Mistral-Small-Instruct-2409",
5
+ "bias": "none",
6
+ "fan_in_fan_out": null,
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": 128,
14
+ "lora_dropout": 0.125,
15
+ "megatron_config": null,
16
+ "megatron_core": "megatron.core",
17
+ "modules_to_save": null,
18
+ "peft_type": "LORA",
19
+ "r": 64,
20
+ "rank_pattern": {},
21
+ "revision": null,
22
+ "target_modules": [
23
+ "up_proj",
24
+ "down_proj",
25
+ "q_proj",
26
+ "k_proj",
27
+ "gate_proj",
28
+ "o_proj",
29
+ "v_proj"
30
+ ],
31
+ "task_type": "CAUSAL_LM",
32
+ "use_dora": false,
33
+ "use_rslora": false
34
+ }
last-checkpoint/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d57f3636e2133ab27cbaef1d146c062bbf8047122ac16b770bdafd4bf8302618
3
+ size 763470136
last-checkpoint/global_step66/bf16_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:05d925bd275a804385265819262d1a84eff377f920a44e985cb9ee58810c0b7e
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:025283c4a1b2a98c4c67a14e76aa0e78ae970d099fd43392d9694fef490b0198
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:d7649d324563a02310f6c3f5f12273d4a8d2bed580278bcfab66fb75a442da89
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:89d23306dca8c84ae69d0bbc9e7e502a59e474abd1f09c7dc3f64ac12d79f3e4
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:ca9075c7ca19e86e1ed65f8c466966791f9e32a91a73393fdc305c6dcc5b2694
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:1c8de2810a40762114166aaac27caa7862c9d8c567a4313c5754e3262962dac7
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:bb939367bf3fef598ede269d94fba135a5a6a404d910e0b9975cceedd3214a12
3
+ size 289064656
last-checkpoint/global_step66/bf16_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:84f55d7c62ff6b146e916ded57f2a79aa09eefbe2310a7ce8921a704aad7df49
3
+ size 289064656
last-checkpoint/global_step66/zero_pp_rank_0_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a6c977b5d5f9c66ee6db2bd8d5b9e2b2b88ad840dac6d2413eb547a35537075
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_1_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8882aec7f02bd893978cd44e040ce759fd05b02752ed9f985b80df3b5e75f954
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_2_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d680c922dceea2f0785a6dbc2951117cd7a79715753469d6c790d14743b54aa
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_3_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf14c08df5c11b1784536ad560edb51364d579f27f836a26ee8466a91ddb3527
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_4_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb6e912b5973c332168adab81722dec35ccd7429d09fd6801dc8707380885939
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_5_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:07685172fd27452dab986dc18506fef46e8a338fb1b93654aba933207197b7d9
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_6_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:abc403215e9de5c040f6ad74e14c77e5a940a58e3d3acbedc75e1395fdf3bfbc
3
+ size 348711830
last-checkpoint/global_step66/zero_pp_rank_7_mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:583359030777daa4d8dc602466cd4a75ad4a649319fae570547488b2a2492f4c
3
+ size 348711830
last-checkpoint/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step66
last-checkpoint/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff29b0b9a1886460050faf8cc16c464a4f189b7dcd65a7cde30b46da44d6228f
3
+ size 15920
last-checkpoint/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf1abdcb348481efb333566df593e0f69e86fd80b5dca2a3d86c8552f818218d
3
+ size 15920
last-checkpoint/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dcbe91bb7cc47195243800eac6fd566b03cdc366455749c9fb5966ac2ca4d206
3
+ size 15920
last-checkpoint/rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2cdeeaceac1d49cfdd526d2175a7ba3804fcf744ded87807419eacaf668fd6cf
3
+ size 15920
last-checkpoint/rng_state_4.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b96b1f659b748768c17d18f35f1502233265533c6be86242403d45cd4e61a70a
3
+ size 15920
last-checkpoint/rng_state_5.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a85f1df64c01db3268103f2293d5522fcefbd7286a53242806262b2f56ab1daa
3
+ size 15920
last-checkpoint/rng_state_6.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a004480513796572b56d3fe300079c0320b47f357442f63e3cc44ee43b32331
3
+ size 15920
last-checkpoint/rng_state_7.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4039c20df906b36c492158121503325a0c00c0b5ef67b1e7950b92b1bb850f34
3
+ size 15920
last-checkpoint/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3018a92e2fcc609e72188b18b74340d0320b4a8c0f2e108928930852ee099d99
3
+ size 1064
last-checkpoint/special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[control_748]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
last-checkpoint/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
last-checkpoint/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59f95e28944c062244741268596badc900df86c7f5ded05088d2da22a7379e06
3
+ size 587583
last-checkpoint/tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff
 
last-checkpoint/trainer_state.json ADDED
@@ -0,0 +1,511 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.20245398773006135,
5
+ "eval_steps": 66,
6
+ "global_step": 66,
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.003067484662576687,
13
+ "grad_norm": 0.9395559024527919,
14
+ "learning_rate": 2.5e-06,
15
+ "loss": 1.9557,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.003067484662576687,
20
+ "eval_loss": 2.6437082290649414,
21
+ "eval_runtime": 55.8191,
22
+ "eval_samples_per_second": 1.792,
23
+ "eval_steps_per_second": 0.125,
24
+ "step": 1
25
+ },
26
+ {
27
+ "epoch": 0.006134969325153374,
28
+ "grad_norm": 0.5082114608415543,
29
+ "learning_rate": 5e-06,
30
+ "loss": 1.9268,
31
+ "step": 2
32
+ },
33
+ {
34
+ "epoch": 0.009202453987730062,
35
+ "grad_norm": 0.545523617822875,
36
+ "learning_rate": 7.5e-06,
37
+ "loss": 1.9672,
38
+ "step": 3
39
+ },
40
+ {
41
+ "epoch": 0.012269938650306749,
42
+ "grad_norm": 0.5931869038518968,
43
+ "learning_rate": 1e-05,
44
+ "loss": 1.9192,
45
+ "step": 4
46
+ },
47
+ {
48
+ "epoch": 0.015337423312883436,
49
+ "grad_norm": 0.498556696377154,
50
+ "learning_rate": 1.25e-05,
51
+ "loss": 1.9185,
52
+ "step": 5
53
+ },
54
+ {
55
+ "epoch": 0.018404907975460124,
56
+ "grad_norm": 0.5501689457090166,
57
+ "learning_rate": 1.5e-05,
58
+ "loss": 1.9038,
59
+ "step": 6
60
+ },
61
+ {
62
+ "epoch": 0.02147239263803681,
63
+ "grad_norm": 0.43641501566976315,
64
+ "learning_rate": 1.75e-05,
65
+ "loss": 1.9735,
66
+ "step": 7
67
+ },
68
+ {
69
+ "epoch": 0.024539877300613498,
70
+ "grad_norm": 0.7151973611497675,
71
+ "learning_rate": 2e-05,
72
+ "loss": 1.9135,
73
+ "step": 8
74
+ },
75
+ {
76
+ "epoch": 0.027607361963190184,
77
+ "grad_norm": 0.5158517925776626,
78
+ "learning_rate": 2.25e-05,
79
+ "loss": 1.9379,
80
+ "step": 9
81
+ },
82
+ {
83
+ "epoch": 0.03067484662576687,
84
+ "grad_norm": 0.5301495295200299,
85
+ "learning_rate": 2.5e-05,
86
+ "loss": 1.9386,
87
+ "step": 10
88
+ },
89
+ {
90
+ "epoch": 0.03374233128834356,
91
+ "grad_norm": 0.4205339050197659,
92
+ "learning_rate": 2.7500000000000004e-05,
93
+ "loss": 1.9029,
94
+ "step": 11
95
+ },
96
+ {
97
+ "epoch": 0.03680981595092025,
98
+ "grad_norm": 0.5599178839825415,
99
+ "learning_rate": 3e-05,
100
+ "loss": 1.9246,
101
+ "step": 12
102
+ },
103
+ {
104
+ "epoch": 0.03987730061349693,
105
+ "grad_norm": 0.5333810020316109,
106
+ "learning_rate": 3.2500000000000004e-05,
107
+ "loss": 1.8621,
108
+ "step": 13
109
+ },
110
+ {
111
+ "epoch": 0.04294478527607362,
112
+ "grad_norm": 0.5151180815653086,
113
+ "learning_rate": 3.5e-05,
114
+ "loss": 1.949,
115
+ "step": 14
116
+ },
117
+ {
118
+ "epoch": 0.046012269938650305,
119
+ "grad_norm": 0.35627888892281423,
120
+ "learning_rate": 3.7500000000000003e-05,
121
+ "loss": 1.9505,
122
+ "step": 15
123
+ },
124
+ {
125
+ "epoch": 0.049079754601226995,
126
+ "grad_norm": 0.33573264334052605,
127
+ "learning_rate": 4e-05,
128
+ "loss": 1.9614,
129
+ "step": 16
130
+ },
131
+ {
132
+ "epoch": 0.05214723926380368,
133
+ "grad_norm": 0.31671336768465796,
134
+ "learning_rate": 4.25e-05,
135
+ "loss": 1.9705,
136
+ "step": 17
137
+ },
138
+ {
139
+ "epoch": 0.05521472392638037,
140
+ "grad_norm": 0.7883355132974788,
141
+ "learning_rate": 4.5e-05,
142
+ "loss": 1.891,
143
+ "step": 18
144
+ },
145
+ {
146
+ "epoch": 0.05828220858895705,
147
+ "grad_norm": 0.38426117984889024,
148
+ "learning_rate": 4.75e-05,
149
+ "loss": 1.9682,
150
+ "step": 19
151
+ },
152
+ {
153
+ "epoch": 0.06134969325153374,
154
+ "grad_norm": 0.5205077926790433,
155
+ "learning_rate": 5e-05,
156
+ "loss": 1.9717,
157
+ "step": 20
158
+ },
159
+ {
160
+ "epoch": 0.06441717791411043,
161
+ "grad_norm": 0.34395402269736797,
162
+ "learning_rate": 4.9998814215961395e-05,
163
+ "loss": 1.9601,
164
+ "step": 21
165
+ },
166
+ {
167
+ "epoch": 0.06748466257668712,
168
+ "grad_norm": 1.0892443652168247,
169
+ "learning_rate": 4.999525698883081e-05,
170
+ "loss": 1.8868,
171
+ "step": 22
172
+ },
173
+ {
174
+ "epoch": 0.0705521472392638,
175
+ "grad_norm": 0.3839309430823124,
176
+ "learning_rate": 4.9989328693550736e-05,
177
+ "loss": 1.9526,
178
+ "step": 23
179
+ },
180
+ {
181
+ "epoch": 0.0736196319018405,
182
+ "grad_norm": 0.5435945484115218,
183
+ "learning_rate": 4.998102995498144e-05,
184
+ "loss": 1.8828,
185
+ "step": 24
186
+ },
187
+ {
188
+ "epoch": 0.07668711656441718,
189
+ "grad_norm": 0.5344791990449174,
190
+ "learning_rate": 4.9970361647835076e-05,
191
+ "loss": 1.9814,
192
+ "step": 25
193
+ },
194
+ {
195
+ "epoch": 0.07975460122699386,
196
+ "grad_norm": 0.4169092381345823,
197
+ "learning_rate": 4.9957324896583496e-05,
198
+ "loss": 2.0039,
199
+ "step": 26
200
+ },
201
+ {
202
+ "epoch": 0.08282208588957055,
203
+ "grad_norm": 0.5321002725036647,
204
+ "learning_rate": 4.9941921075339726e-05,
205
+ "loss": 1.8978,
206
+ "step": 27
207
+ },
208
+ {
209
+ "epoch": 0.08588957055214724,
210
+ "grad_norm": 0.43527235030627903,
211
+ "learning_rate": 4.992415180771313e-05,
212
+ "loss": 1.9955,
213
+ "step": 28
214
+ },
215
+ {
216
+ "epoch": 0.08895705521472393,
217
+ "grad_norm": 0.3352860122105628,
218
+ "learning_rate": 4.990401896663828e-05,
219
+ "loss": 1.9811,
220
+ "step": 29
221
+ },
222
+ {
223
+ "epoch": 0.09202453987730061,
224
+ "grad_norm": 0.5180744406200457,
225
+ "learning_rate": 4.9881524674177544e-05,
226
+ "loss": 1.993,
227
+ "step": 30
228
+ },
229
+ {
230
+ "epoch": 0.0950920245398773,
231
+ "grad_norm": 0.37572166232306053,
232
+ "learning_rate": 4.98566713012974e-05,
233
+ "loss": 1.9254,
234
+ "step": 31
235
+ },
236
+ {
237
+ "epoch": 0.09815950920245399,
238
+ "grad_norm": 0.45641066732216334,
239
+ "learning_rate": 4.982946146761856e-05,
240
+ "loss": 1.8769,
241
+ "step": 32
242
+ },
243
+ {
244
+ "epoch": 0.10122699386503067,
245
+ "grad_norm": 0.3929634926287055,
246
+ "learning_rate": 4.9799898041139806e-05,
247
+ "loss": 2.0258,
248
+ "step": 33
249
+ },
250
+ {
251
+ "epoch": 0.10429447852760736,
252
+ "grad_norm": 0.5314588508536493,
253
+ "learning_rate": 4.976798413793575e-05,
254
+ "loss": 1.9554,
255
+ "step": 34
256
+ },
257
+ {
258
+ "epoch": 0.10736196319018405,
259
+ "grad_norm": 0.748246551881334,
260
+ "learning_rate": 4.973372312182834e-05,
261
+ "loss": 1.9068,
262
+ "step": 35
263
+ },
264
+ {
265
+ "epoch": 0.11042944785276074,
266
+ "grad_norm": 0.4060167480927513,
267
+ "learning_rate": 4.969711860403234e-05,
268
+ "loss": 1.9333,
269
+ "step": 36
270
+ },
271
+ {
272
+ "epoch": 0.11349693251533742,
273
+ "grad_norm": 0.5799530880648744,
274
+ "learning_rate": 4.965817444277468e-05,
275
+ "loss": 1.9181,
276
+ "step": 37
277
+ },
278
+ {
279
+ "epoch": 0.1165644171779141,
280
+ "grad_norm": 0.606660471450205,
281
+ "learning_rate": 4.961689474288779e-05,
282
+ "loss": 1.998,
283
+ "step": 38
284
+ },
285
+ {
286
+ "epoch": 0.1196319018404908,
287
+ "grad_norm": 0.4060851512441128,
288
+ "learning_rate": 4.9573283855376935e-05,
289
+ "loss": 1.897,
290
+ "step": 39
291
+ },
292
+ {
293
+ "epoch": 0.12269938650306748,
294
+ "grad_norm": 0.6739628631888296,
295
+ "learning_rate": 4.95273463769616e-05,
296
+ "loss": 1.9552,
297
+ "step": 40
298
+ },
299
+ {
300
+ "epoch": 0.12576687116564417,
301
+ "grad_norm": 0.33685172710853173,
302
+ "learning_rate": 4.9479087149591016e-05,
303
+ "loss": 1.9792,
304
+ "step": 41
305
+ },
306
+ {
307
+ "epoch": 0.12883435582822086,
308
+ "grad_norm": 0.3259384980995625,
309
+ "learning_rate": 4.9428511259933764e-05,
310
+ "loss": 1.9744,
311
+ "step": 42
312
+ },
313
+ {
314
+ "epoch": 0.13190184049079753,
315
+ "grad_norm": 0.4327785334030348,
316
+ "learning_rate": 4.937562403884162e-05,
317
+ "loss": 1.94,
318
+ "step": 43
319
+ },
320
+ {
321
+ "epoch": 0.13496932515337423,
322
+ "grad_norm": 0.3926063542265063,
323
+ "learning_rate": 4.932043106078772e-05,
324
+ "loss": 1.9529,
325
+ "step": 44
326
+ },
327
+ {
328
+ "epoch": 0.13803680981595093,
329
+ "grad_norm": 1.3215391718011407,
330
+ "learning_rate": 4.926293814327893e-05,
331
+ "loss": 1.8909,
332
+ "step": 45
333
+ },
334
+ {
335
+ "epoch": 0.1411042944785276,
336
+ "grad_norm": 0.36338656895366955,
337
+ "learning_rate": 4.9203151346242745e-05,
338
+ "loss": 1.9136,
339
+ "step": 46
340
+ },
341
+ {
342
+ "epoch": 0.1441717791411043,
343
+ "grad_norm": 0.498562015335393,
344
+ "learning_rate": 4.914107697138843e-05,
345
+ "loss": 1.9528,
346
+ "step": 47
347
+ },
348
+ {
349
+ "epoch": 0.147239263803681,
350
+ "grad_norm": 0.8964552394647333,
351
+ "learning_rate": 4.907672156154293e-05,
352
+ "loss": 1.9196,
353
+ "step": 48
354
+ },
355
+ {
356
+ "epoch": 0.15030674846625766,
357
+ "grad_norm": 0.5849768143890427,
358
+ "learning_rate": 4.901009189996115e-05,
359
+ "loss": 1.9379,
360
+ "step": 49
361
+ },
362
+ {
363
+ "epoch": 0.15337423312883436,
364
+ "grad_norm": 0.29099134515938846,
365
+ "learning_rate": 4.894119500961103e-05,
366
+ "loss": 1.886,
367
+ "step": 50
368
+ },
369
+ {
370
+ "epoch": 0.15644171779141106,
371
+ "grad_norm": 0.337221028366163,
372
+ "learning_rate": 4.887003815243326e-05,
373
+ "loss": 1.9122,
374
+ "step": 51
375
+ },
376
+ {
377
+ "epoch": 0.15950920245398773,
378
+ "grad_norm": 0.3009145092042191,
379
+ "learning_rate": 4.879662882857588e-05,
380
+ "loss": 1.9304,
381
+ "step": 52
382
+ },
383
+ {
384
+ "epoch": 0.16257668711656442,
385
+ "grad_norm": 0.2848317412160051,
386
+ "learning_rate": 4.872097477560374e-05,
387
+ "loss": 1.9373,
388
+ "step": 53
389
+ },
390
+ {
391
+ "epoch": 0.1656441717791411,
392
+ "grad_norm": 0.6132329639328981,
393
+ "learning_rate": 4.864308396768294e-05,
394
+ "loss": 1.9435,
395
+ "step": 54
396
+ },
397
+ {
398
+ "epoch": 0.1687116564417178,
399
+ "grad_norm": 0.3131156581720946,
400
+ "learning_rate": 4.8562964614740284e-05,
401
+ "loss": 1.9489,
402
+ "step": 55
403
+ },
404
+ {
405
+ "epoch": 0.17177914110429449,
406
+ "grad_norm": 0.27232749681035767,
407
+ "learning_rate": 4.8480625161598e-05,
408
+ "loss": 1.8898,
409
+ "step": 56
410
+ },
411
+ {
412
+ "epoch": 0.17484662576687116,
413
+ "grad_norm": 0.4737912499270363,
414
+ "learning_rate": 4.839607428708359e-05,
415
+ "loss": 1.9283,
416
+ "step": 57
417
+ },
418
+ {
419
+ "epoch": 0.17791411042944785,
420
+ "grad_norm": 0.3326629263563354,
421
+ "learning_rate": 4.8309320903115015e-05,
422
+ "loss": 1.9541,
423
+ "step": 58
424
+ },
425
+ {
426
+ "epoch": 0.18098159509202455,
427
+ "grad_norm": 0.3228293620778407,
428
+ "learning_rate": 4.822037415376146e-05,
429
+ "loss": 1.9516,
430
+ "step": 59
431
+ },
432
+ {
433
+ "epoch": 0.18404907975460122,
434
+ "grad_norm": 1.6397638257869722,
435
+ "learning_rate": 4.812924341427942e-05,
436
+ "loss": 1.877,
437
+ "step": 60
438
+ },
439
+ {
440
+ "epoch": 0.18711656441717792,
441
+ "grad_norm": 0.26549680234513334,
442
+ "learning_rate": 4.803593829012456e-05,
443
+ "loss": 1.9009,
444
+ "step": 61
445
+ },
446
+ {
447
+ "epoch": 0.1901840490797546,
448
+ "grad_norm": 0.2866804800126102,
449
+ "learning_rate": 4.7940468615939285e-05,
450
+ "loss": 1.9193,
451
+ "step": 62
452
+ },
453
+ {
454
+ "epoch": 0.19325153374233128,
455
+ "grad_norm": 0.6831206341052352,
456
+ "learning_rate": 4.7842844454516107e-05,
457
+ "loss": 1.9136,
458
+ "step": 63
459
+ },
460
+ {
461
+ "epoch": 0.19631901840490798,
462
+ "grad_norm": 0.36663549660831984,
463
+ "learning_rate": 4.7743076095737025e-05,
464
+ "loss": 1.8692,
465
+ "step": 64
466
+ },
467
+ {
468
+ "epoch": 0.19938650306748465,
469
+ "grad_norm": 6.190735884904401,
470
+ "learning_rate": 4.764117405548891e-05,
471
+ "loss": 1.8542,
472
+ "step": 65
473
+ },
474
+ {
475
+ "epoch": 0.20245398773006135,
476
+ "grad_norm": 0.2877773769970794,
477
+ "learning_rate": 4.753714907455512e-05,
478
+ "loss": 1.8651,
479
+ "step": 66
480
+ },
481
+ {
482
+ "epoch": 0.20245398773006135,
483
+ "eval_loss": 2.587120771408081,
484
+ "eval_runtime": 55.7851,
485
+ "eval_samples_per_second": 1.793,
486
+ "eval_steps_per_second": 0.125,
487
+ "step": 66
488
+ }
489
+ ],
490
+ "logging_steps": 1,
491
+ "max_steps": 326,
492
+ "num_input_tokens_seen": 0,
493
+ "num_train_epochs": 1,
494
+ "save_steps": 66,
495
+ "stateful_callbacks": {
496
+ "TrainerControl": {
497
+ "args": {
498
+ "should_epoch_stop": false,
499
+ "should_evaluate": false,
500
+ "should_log": false,
501
+ "should_save": true,
502
+ "should_training_stop": false
503
+ },
504
+ "attributes": {}
505
+ }
506
+ },
507
+ "total_flos": 72071698710528.0,
508
+ "train_batch_size": 2,
509
+ "trial_name": null,
510
+ "trial_params": null
511
+ }
last-checkpoint/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20a2a75112970d2f5eadf0b3dfedd8ee2a80f0b77d6656f1a708195b6286e91a
3
+ size 8120
last-checkpoint/zero_to_fp32.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
215
+ exclude_frozen_parameters)
216
+ elif zero_stage == 3:
217
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
218
+ exclude_frozen_parameters)
219
+
220
+
221
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
222
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
223
+ return
224
+
225
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
226
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
227
+
228
+ if debug:
229
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
230
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
231
+
232
+ wanted_params = len(frozen_param_shapes)
233
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
234
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
235
+ print(f'Frozen params: Have {avail_numel} numels to process.')
236
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
237
+
238
+ total_params = 0
239
+ total_numel = 0
240
+ for name, shape in frozen_param_shapes.items():
241
+ total_params += 1
242
+ unpartitioned_numel = shape.numel()
243
+ total_numel += unpartitioned_numel
244
+
245
+ state_dict[name] = frozen_param_fragments[name]
246
+
247
+ if debug:
248
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
249
+
250
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
251
+
252
+
253
+ def _has_callable(obj, fn):
254
+ attr = getattr(obj, fn, None)
255
+ return callable(attr)
256
+
257
+
258
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
259
+ param_shapes = zero_model_states[0].param_shapes
260
+
261
+ # Reconstruction protocol:
262
+ #
263
+ # XXX: document this
264
+
265
+ if debug:
266
+ for i in range(world_size):
267
+ for j in range(len(fp32_flat_groups[0])):
268
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
269
+
270
+ # XXX: memory usage doubles here (zero2)
271
+ num_param_groups = len(fp32_flat_groups[0])
272
+ merged_single_partition_of_fp32_groups = []
273
+ for i in range(num_param_groups):
274
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
275
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
276
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
277
+ avail_numel = sum(
278
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
279
+
280
+ if debug:
281
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
282
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
283
+ # not asserting if there is a mismatch due to possible padding
284
+ print(f"Have {avail_numel} numels to process.")
285
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
286
+
287
+ # params
288
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
289
+ # out-of-core computing solution
290
+ total_numel = 0
291
+ total_params = 0
292
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
293
+ offset = 0
294
+ avail_numel = full_single_fp32_vector.numel()
295
+ for name, shape in shapes.items():
296
+
297
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
298
+ total_numel += unpartitioned_numel
299
+ total_params += 1
300
+
301
+ if debug:
302
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
303
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
304
+ offset += unpartitioned_numel
305
+
306
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
307
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
308
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
309
+ # live optimizer object, so we are checking that the numbers are within the right range
310
+ align_to = 2 * world_size
311
+
312
+ def zero2_align(x):
313
+ return align_to * math.ceil(x / align_to)
314
+
315
+ if debug:
316
+ print(f"original offset={offset}, avail_numel={avail_numel}")
317
+
318
+ offset = zero2_align(offset)
319
+ avail_numel = zero2_align(avail_numel)
320
+
321
+ if debug:
322
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
323
+
324
+ # Sanity check
325
+ if offset != avail_numel:
326
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
327
+
328
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
329
+
330
+
331
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
332
+ exclude_frozen_parameters):
333
+ state_dict = OrderedDict()
334
+
335
+ # buffers
336
+ buffers = zero_model_states[0].buffers
337
+ state_dict.update(buffers)
338
+ if debug:
339
+ print(f"added {len(buffers)} buffers")
340
+
341
+ if not exclude_frozen_parameters:
342
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
343
+
344
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
345
+
346
+ # recover shared parameters
347
+ for pair in zero_model_states[0].shared_params:
348
+ if pair[1] in state_dict:
349
+ state_dict[pair[0]] = state_dict[pair[1]]
350
+
351
+ return state_dict
352
+
353
+
354
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
355
+ remainder = unpartitioned_numel % world_size
356
+ padding_numel = (world_size - remainder) if remainder else 0
357
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
358
+ return partitioned_numel, padding_numel
359
+
360
+
361
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
362
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
363
+ return
364
+
365
+ if debug:
366
+ for i in range(world_size):
367
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
368
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
369
+
370
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
371
+ wanted_params = len(frozen_param_shapes)
372
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
373
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
374
+ print(f'Frozen params: Have {avail_numel} numels to process.')
375
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
376
+
377
+ total_params = 0
378
+ total_numel = 0
379
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
380
+ total_params += 1
381
+ unpartitioned_numel = shape.numel()
382
+ total_numel += unpartitioned_numel
383
+
384
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
385
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
386
+
387
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
388
+
389
+ if debug:
390
+ print(
391
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
392
+ )
393
+
394
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
395
+
396
+
397
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
398
+ param_shapes = zero_model_states[0].param_shapes
399
+ avail_numel = fp32_flat_groups[0].numel() * world_size
400
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
401
+ # param, re-consolidating each param, while dealing with padding if any
402
+
403
+ # merge list of dicts, preserving order
404
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
405
+
406
+ if debug:
407
+ for i in range(world_size):
408
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
409
+
410
+ wanted_params = len(param_shapes)
411
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
412
+ # not asserting if there is a mismatch due to possible padding
413
+ avail_numel = fp32_flat_groups[0].numel() * world_size
414
+ print(f"Trainable params: Have {avail_numel} numels to process.")
415
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
416
+
417
+ # params
418
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
419
+ # out-of-core computing solution
420
+ offset = 0
421
+ total_numel = 0
422
+ total_params = 0
423
+ for name, shape in param_shapes.items():
424
+
425
+ unpartitioned_numel = shape.numel()
426
+ total_numel += unpartitioned_numel
427
+ total_params += 1
428
+
429
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
430
+
431
+ if debug:
432
+ print(
433
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
434
+ )
435
+
436
+ # XXX: memory usage doubles here
437
+ state_dict[name] = torch.cat(
438
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
439
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
440
+ offset += partitioned_numel
441
+
442
+ offset *= world_size
443
+
444
+ # Sanity check
445
+ if offset != avail_numel:
446
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
447
+
448
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
449
+
450
+
451
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
452
+ exclude_frozen_parameters):
453
+ state_dict = OrderedDict()
454
+
455
+ # buffers
456
+ buffers = zero_model_states[0].buffers
457
+ state_dict.update(buffers)
458
+ if debug:
459
+ print(f"added {len(buffers)} buffers")
460
+
461
+ if not exclude_frozen_parameters:
462
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
463
+
464
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
465
+
466
+ # recover shared parameters
467
+ for pair in zero_model_states[0].shared_params:
468
+ if pair[1] in state_dict:
469
+ state_dict[pair[0]] = state_dict[pair[1]]
470
+
471
+ return state_dict
472
+
473
+
474
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
475
+ """
476
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
477
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
478
+ via a model hub.
479
+
480
+ Args:
481
+ - ``checkpoint_dir``: path to the desired checkpoint folder
482
+ - ``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``
483
+ - ``exclude_frozen_parameters``: exclude frozen parameters
484
+
485
+ Returns:
486
+ - pytorch ``state_dict``
487
+
488
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
489
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
490
+ the checkpoint.
491
+
492
+ A typical usage might be ::
493
+
494
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
495
+ # do the training and checkpoint saving
496
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
497
+ model = model.cpu() # move to cpu
498
+ model.load_state_dict(state_dict)
499
+ # submit to model hub or save the model to share with others
500
+
501
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
502
+ application. i.e. you will need to re-initialize the deepspeed engine, since
503
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
504
+
505
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
506
+
507
+ """
508
+ if tag is None:
509
+ latest_path = os.path.join(checkpoint_dir, 'latest')
510
+ if os.path.isfile(latest_path):
511
+ with open(latest_path, 'r') as fd:
512
+ tag = fd.read().strip()
513
+ else:
514
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
515
+
516
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
517
+
518
+ if not os.path.isdir(ds_checkpoint_dir):
519
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
520
+
521
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
522
+
523
+
524
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None, exclude_frozen_parameters=False):
525
+ """
526
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
527
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
528
+
529
+ Args:
530
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
531
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
532
+ - ``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``
533
+ - ``exclude_frozen_parameters``: exclude frozen parameters
534
+ """
535
+
536
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
537
+ print(f"Saving fp32 state dict to {output_file}")
538
+ torch.save(state_dict, output_file)
539
+
540
+
541
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
542
+ """
543
+ 1. Put the provided model to cpu
544
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
545
+ 3. Load it into the provided model
546
+
547
+ Args:
548
+ - ``model``: the model object to update
549
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
550
+ - ``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``
551
+
552
+ Returns:
553
+ - ``model`: modified model
554
+
555
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
556
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
557
+ conveniently placed for you in the checkpoint folder.
558
+
559
+ A typical usage might be ::
560
+
561
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
562
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
563
+ # submit to model hub or save the model to share with others
564
+
565
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
566
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
567
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
568
+
569
+ """
570
+ logger.info(f"Extracting fp32 weights")
571
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
572
+
573
+ logger.info(f"Overwriting model with fp32 weights")
574
+ model = model.cpu()
575
+ model.load_state_dict(state_dict, strict=False)
576
+
577
+ return model
578
+
579
+
580
+ if __name__ == "__main__":
581
+
582
+ parser = argparse.ArgumentParser()
583
+ parser.add_argument("checkpoint_dir",
584
+ type=str,
585
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
586
+ parser.add_argument(
587
+ "output_file",
588
+ type=str,
589
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
590
+ parser.add_argument("-t",
591
+ "--tag",
592
+ type=str,
593
+ default=None,
594
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
595
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
596
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
597
+ args = parser.parse_args()
598
+
599
+ debug = args.debug
600
+
601
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
602
+ args.output_file,
603
+ tag=args.tag,
604
+ exclude_frozen_parameters=args.exclude_frozen_parameters)