k1h0 commited on
Commit
6ac8891
·
verified ·
1 Parent(s): bc2fe01

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: codellama/CodeLlama-7b-hf
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.14.0
adapter_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_mapping": null,
3
+ "base_model_name_or_path": "codellama/CodeLlama-7b-hf",
4
+ "encoder_hidden_size": 4096,
5
+ "inference_mode": true,
6
+ "num_attention_heads": 32,
7
+ "num_layers": 32,
8
+ "num_transformer_submodules": 1,
9
+ "num_virtual_tokens": 20,
10
+ "peft_type": "PREFIX_TUNING",
11
+ "prefix_projection": true,
12
+ "revision": null,
13
+ "task_type": "CAUSAL_LM",
14
+ "token_dim": 4096
15
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16bc5a7b19cfae6ebe631d3ec5a64df1f4092a9bd27334ebe7c1c7736249a098
3
+ size 10485888
checkpoint-1484/README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: codellama/CodeLlama-7b-hf
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.14.0
checkpoint-1484/adapter_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_mapping": null,
3
+ "base_model_name_or_path": "codellama/CodeLlama-7b-hf",
4
+ "encoder_hidden_size": 4096,
5
+ "inference_mode": true,
6
+ "num_attention_heads": 32,
7
+ "num_layers": 32,
8
+ "num_transformer_submodules": 1,
9
+ "num_virtual_tokens": 20,
10
+ "peft_type": "PREFIX_TUNING",
11
+ "prefix_projection": true,
12
+ "revision": null,
13
+ "task_type": "CAUSAL_LM",
14
+ "token_dim": 4096
15
+ }
checkpoint-1484/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16bc5a7b19cfae6ebe631d3ec5a64df1f4092a9bd27334ebe7c1c7736249a098
3
+ size 10485888
checkpoint-1484/global_step1484/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:b7220a5d92557d0df3d04687fe04e717890d840a9d8c39b734ca57afd81d3b8c
3
+ size 3272607024
checkpoint-1484/global_step1484/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:210a9e497b1bb3a1178457df8659ae0332ab337379a320f7f2042047b6b31883
3
+ size 3272606832
checkpoint-1484/global_step1484/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:1aaf307245004251c97cdef5a1f4f6dd57854027f3e3be294611716af5484149
3
+ size 3272606832
checkpoint-1484/global_step1484/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:795d96a805714a3f7d30002b8a122d57a6112ba45b90e081b3897f91ea798751
3
+ size 3272606832
checkpoint-1484/global_step1484/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01291585acfd90e533c0c86cbb3e4e2e2cd6cfc2ecad8fa646d5f82bb4e8f485
3
+ size 2444036868
checkpoint-1484/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step1484
checkpoint-1484/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0463657eb196db696840f1d09b3adadac520fe49264add5251aeb9addf055fc
3
+ size 15024
checkpoint-1484/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ffe320ec96f869bb8919b462c34efb3292a69842530bead39d0d3b341234bd7
3
+ size 15024
checkpoint-1484/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6596162c350ad095f608ad419bda73c8a08939691194e48e6a039213c5867009
3
+ size 15024
checkpoint-1484/rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:612d8065c6426c751f372c28c3f621bde42e79eaeade12ce126c4b79412e74e9
3
+ size 15024
checkpoint-1484/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48a72f1f07c0dc1b2913fffde3ec12d88bfb3e89442dc52ba087138ee562d340
3
+ size 1064
checkpoint-1484/trainer_state.json ADDED
@@ -0,0 +1,1076 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.9997473684210526,
5
+ "eval_steps": 500,
6
+ "global_step": 1484,
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.0006736842105263158,
13
+ "grad_norm": 3.6967623233795166,
14
+ "learning_rate": 1.3422818791946309e-06,
15
+ "loss": 2.4093,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.006736842105263158,
20
+ "grad_norm": 2.5490193367004395,
21
+ "learning_rate": 1.3422818791946309e-05,
22
+ "loss": 2.4939,
23
+ "step": 10
24
+ },
25
+ {
26
+ "epoch": 0.013473684210526317,
27
+ "grad_norm": 0.18483224511146545,
28
+ "learning_rate": 2.6845637583892618e-05,
29
+ "loss": 1.1877,
30
+ "step": 20
31
+ },
32
+ {
33
+ "epoch": 0.020210526315789474,
34
+ "grad_norm": 0.2031693309545517,
35
+ "learning_rate": 4.026845637583892e-05,
36
+ "loss": 0.8909,
37
+ "step": 30
38
+ },
39
+ {
40
+ "epoch": 0.026947368421052633,
41
+ "grad_norm": 0.6876732707023621,
42
+ "learning_rate": 5.3691275167785237e-05,
43
+ "loss": 0.7581,
44
+ "step": 40
45
+ },
46
+ {
47
+ "epoch": 0.03368421052631579,
48
+ "grad_norm": 0.09247241914272308,
49
+ "learning_rate": 6.711409395973155e-05,
50
+ "loss": 0.7594,
51
+ "step": 50
52
+ },
53
+ {
54
+ "epoch": 0.04042105263157895,
55
+ "grad_norm": 0.1324968934059143,
56
+ "learning_rate": 8.053691275167784e-05,
57
+ "loss": 0.7405,
58
+ "step": 60
59
+ },
60
+ {
61
+ "epoch": 0.04715789473684211,
62
+ "grad_norm": 0.05673883110284805,
63
+ "learning_rate": 9.395973154362417e-05,
64
+ "loss": 0.7065,
65
+ "step": 70
66
+ },
67
+ {
68
+ "epoch": 0.053894736842105266,
69
+ "grad_norm": 0.04617280140519142,
70
+ "learning_rate": 0.00010738255033557047,
71
+ "loss": 0.6817,
72
+ "step": 80
73
+ },
74
+ {
75
+ "epoch": 0.06063157894736842,
76
+ "grad_norm": 0.04381496459245682,
77
+ "learning_rate": 0.0001208053691275168,
78
+ "loss": 0.6789,
79
+ "step": 90
80
+ },
81
+ {
82
+ "epoch": 0.06736842105263158,
83
+ "grad_norm": 0.07428538799285889,
84
+ "learning_rate": 0.0001342281879194631,
85
+ "loss": 0.6816,
86
+ "step": 100
87
+ },
88
+ {
89
+ "epoch": 0.07410526315789474,
90
+ "grad_norm": 0.04249708354473114,
91
+ "learning_rate": 0.00014765100671140942,
92
+ "loss": 0.6997,
93
+ "step": 110
94
+ },
95
+ {
96
+ "epoch": 0.0808421052631579,
97
+ "grad_norm": 0.05957937240600586,
98
+ "learning_rate": 0.0001610738255033557,
99
+ "loss": 0.6807,
100
+ "step": 120
101
+ },
102
+ {
103
+ "epoch": 0.08757894736842105,
104
+ "grad_norm": 0.03975442424416542,
105
+ "learning_rate": 0.000174496644295302,
106
+ "loss": 0.6733,
107
+ "step": 130
108
+ },
109
+ {
110
+ "epoch": 0.09431578947368421,
111
+ "grad_norm": 0.04079463332891464,
112
+ "learning_rate": 0.00018791946308724833,
113
+ "loss": 0.6556,
114
+ "step": 140
115
+ },
116
+ {
117
+ "epoch": 0.10105263157894737,
118
+ "grad_norm": 0.04245497286319733,
119
+ "learning_rate": 0.00019985018726591762,
120
+ "loss": 0.6575,
121
+ "step": 150
122
+ },
123
+ {
124
+ "epoch": 0.10778947368421053,
125
+ "grad_norm": 0.09695123136043549,
126
+ "learning_rate": 0.00019835205992509364,
127
+ "loss": 0.6916,
128
+ "step": 160
129
+ },
130
+ {
131
+ "epoch": 0.11452631578947368,
132
+ "grad_norm": 0.03505201265215874,
133
+ "learning_rate": 0.00019685393258426966,
134
+ "loss": 0.6622,
135
+ "step": 170
136
+ },
137
+ {
138
+ "epoch": 0.12126315789473684,
139
+ "grad_norm": 0.02820334956049919,
140
+ "learning_rate": 0.0001953558052434457,
141
+ "loss": 0.6497,
142
+ "step": 180
143
+ },
144
+ {
145
+ "epoch": 0.128,
146
+ "grad_norm": 0.04135354235768318,
147
+ "learning_rate": 0.00019385767790262173,
148
+ "loss": 0.6671,
149
+ "step": 190
150
+ },
151
+ {
152
+ "epoch": 0.13473684210526315,
153
+ "grad_norm": 0.031461067497730255,
154
+ "learning_rate": 0.00019235955056179775,
155
+ "loss": 0.657,
156
+ "step": 200
157
+ },
158
+ {
159
+ "epoch": 0.1414736842105263,
160
+ "grad_norm": 0.04208710789680481,
161
+ "learning_rate": 0.0001908614232209738,
162
+ "loss": 0.6766,
163
+ "step": 210
164
+ },
165
+ {
166
+ "epoch": 0.1482105263157895,
167
+ "grad_norm": 3.495147705078125,
168
+ "learning_rate": 0.00018936329588014982,
169
+ "loss": 3.9378,
170
+ "step": 220
171
+ },
172
+ {
173
+ "epoch": 0.15494736842105264,
174
+ "grad_norm": 0.18893112242221832,
175
+ "learning_rate": 0.00018786516853932586,
176
+ "loss": 7.1374,
177
+ "step": 230
178
+ },
179
+ {
180
+ "epoch": 0.1616842105263158,
181
+ "grad_norm": 0.0959916040301323,
182
+ "learning_rate": 0.00018636704119850189,
183
+ "loss": 5.8104,
184
+ "step": 240
185
+ },
186
+ {
187
+ "epoch": 0.16842105263157894,
188
+ "grad_norm": 0.08286964148283005,
189
+ "learning_rate": 0.0001848689138576779,
190
+ "loss": 4.7292,
191
+ "step": 250
192
+ },
193
+ {
194
+ "epoch": 0.1751578947368421,
195
+ "grad_norm": 0.04510454833507538,
196
+ "learning_rate": 0.00018337078651685393,
197
+ "loss": 4.9858,
198
+ "step": 260
199
+ },
200
+ {
201
+ "epoch": 0.18189473684210528,
202
+ "grad_norm": 0.2256896197795868,
203
+ "learning_rate": 0.00018187265917602997,
204
+ "loss": 4.7463,
205
+ "step": 270
206
+ },
207
+ {
208
+ "epoch": 0.18863157894736843,
209
+ "grad_norm": 0.06342379748821259,
210
+ "learning_rate": 0.00018037453183520602,
211
+ "loss": 4.517,
212
+ "step": 280
213
+ },
214
+ {
215
+ "epoch": 0.19536842105263158,
216
+ "grad_norm": 0.07497289776802063,
217
+ "learning_rate": 0.00017887640449438204,
218
+ "loss": 4.4052,
219
+ "step": 290
220
+ },
221
+ {
222
+ "epoch": 0.20210526315789473,
223
+ "grad_norm": 0.08952877670526505,
224
+ "learning_rate": 0.00017737827715355806,
225
+ "loss": 3.9614,
226
+ "step": 300
227
+ },
228
+ {
229
+ "epoch": 0.20884210526315788,
230
+ "grad_norm": 0.044066932052373886,
231
+ "learning_rate": 0.00017588014981273408,
232
+ "loss": 4.5861,
233
+ "step": 310
234
+ },
235
+ {
236
+ "epoch": 0.21557894736842106,
237
+ "grad_norm": 0.08251778781414032,
238
+ "learning_rate": 0.0001743820224719101,
239
+ "loss": 4.5163,
240
+ "step": 320
241
+ },
242
+ {
243
+ "epoch": 0.22231578947368422,
244
+ "grad_norm": 0.04723803699016571,
245
+ "learning_rate": 0.00017288389513108615,
246
+ "loss": 4.1904,
247
+ "step": 330
248
+ },
249
+ {
250
+ "epoch": 0.22905263157894737,
251
+ "grad_norm": 0.09082615375518799,
252
+ "learning_rate": 0.0001713857677902622,
253
+ "loss": 4.1982,
254
+ "step": 340
255
+ },
256
+ {
257
+ "epoch": 0.23578947368421052,
258
+ "grad_norm": 0.04866361245512962,
259
+ "learning_rate": 0.00016988764044943822,
260
+ "loss": 3.8506,
261
+ "step": 350
262
+ },
263
+ {
264
+ "epoch": 0.24252631578947367,
265
+ "grad_norm": 0.04515402019023895,
266
+ "learning_rate": 0.00016838951310861424,
267
+ "loss": 4.4254,
268
+ "step": 360
269
+ },
270
+ {
271
+ "epoch": 0.24926315789473685,
272
+ "grad_norm": 0.14205284416675568,
273
+ "learning_rate": 0.00016689138576779026,
274
+ "loss": 4.4111,
275
+ "step": 370
276
+ },
277
+ {
278
+ "epoch": 0.256,
279
+ "grad_norm": 0.16082021594047546,
280
+ "learning_rate": 0.0001653932584269663,
281
+ "loss": 4.1119,
282
+ "step": 380
283
+ },
284
+ {
285
+ "epoch": 0.26273684210526316,
286
+ "grad_norm": 0.061411116272211075,
287
+ "learning_rate": 0.00016389513108614235,
288
+ "loss": 4.059,
289
+ "step": 390
290
+ },
291
+ {
292
+ "epoch": 0.2694736842105263,
293
+ "grad_norm": 0.058379318565130234,
294
+ "learning_rate": 0.00016239700374531837,
295
+ "loss": 3.7307,
296
+ "step": 400
297
+ },
298
+ {
299
+ "epoch": 0.27621052631578946,
300
+ "grad_norm": 0.048859789967536926,
301
+ "learning_rate": 0.0001608988764044944,
302
+ "loss": 4.3039,
303
+ "step": 410
304
+ },
305
+ {
306
+ "epoch": 0.2829473684210526,
307
+ "grad_norm": 0.06003361940383911,
308
+ "learning_rate": 0.0001594007490636704,
309
+ "loss": 4.2032,
310
+ "step": 420
311
+ },
312
+ {
313
+ "epoch": 0.28968421052631577,
314
+ "grad_norm": 0.10120591521263123,
315
+ "learning_rate": 0.00015790262172284646,
316
+ "loss": 3.9567,
317
+ "step": 430
318
+ },
319
+ {
320
+ "epoch": 0.296421052631579,
321
+ "grad_norm": 0.21033401787281036,
322
+ "learning_rate": 0.00015640449438202248,
323
+ "loss": 3.9369,
324
+ "step": 440
325
+ },
326
+ {
327
+ "epoch": 0.3031578947368421,
328
+ "grad_norm": 0.06378967314958572,
329
+ "learning_rate": 0.00015490636704119852,
330
+ "loss": 3.6318,
331
+ "step": 450
332
+ },
333
+ {
334
+ "epoch": 0.3098947368421053,
335
+ "grad_norm": 0.042198359966278076,
336
+ "learning_rate": 0.00015340823970037455,
337
+ "loss": 4.1789,
338
+ "step": 460
339
+ },
340
+ {
341
+ "epoch": 0.31663157894736843,
342
+ "grad_norm": 0.053648848086595535,
343
+ "learning_rate": 0.00015191011235955057,
344
+ "loss": 4.1562,
345
+ "step": 470
346
+ },
347
+ {
348
+ "epoch": 0.3233684210526316,
349
+ "grad_norm": 0.0808805301785469,
350
+ "learning_rate": 0.00015041198501872659,
351
+ "loss": 3.8883,
352
+ "step": 480
353
+ },
354
+ {
355
+ "epoch": 0.33010526315789473,
356
+ "grad_norm": 0.13895294070243835,
357
+ "learning_rate": 0.00014891385767790263,
358
+ "loss": 3.9055,
359
+ "step": 490
360
+ },
361
+ {
362
+ "epoch": 0.3368421052631579,
363
+ "grad_norm": 0.11999215185642242,
364
+ "learning_rate": 0.00014741573033707865,
365
+ "loss": 3.6025,
366
+ "step": 500
367
+ },
368
+ {
369
+ "epoch": 0.34357894736842104,
370
+ "grad_norm": 0.0969998687505722,
371
+ "learning_rate": 0.0001459176029962547,
372
+ "loss": 4.2401,
373
+ "step": 510
374
+ },
375
+ {
376
+ "epoch": 0.3503157894736842,
377
+ "grad_norm": 0.2578948438167572,
378
+ "learning_rate": 0.00014441947565543072,
379
+ "loss": 4.1355,
380
+ "step": 520
381
+ },
382
+ {
383
+ "epoch": 0.35705263157894734,
384
+ "grad_norm": 0.067634217441082,
385
+ "learning_rate": 0.00014292134831460674,
386
+ "loss": 3.8735,
387
+ "step": 530
388
+ },
389
+ {
390
+ "epoch": 0.36378947368421055,
391
+ "grad_norm": 0.1961352676153183,
392
+ "learning_rate": 0.0001414232209737828,
393
+ "loss": 3.7641,
394
+ "step": 540
395
+ },
396
+ {
397
+ "epoch": 0.3705263157894737,
398
+ "grad_norm": 0.07940343767404556,
399
+ "learning_rate": 0.0001399250936329588,
400
+ "loss": 3.5177,
401
+ "step": 550
402
+ },
403
+ {
404
+ "epoch": 0.37726315789473686,
405
+ "grad_norm": 1.3029491901397705,
406
+ "learning_rate": 0.00013842696629213483,
407
+ "loss": 4.1854,
408
+ "step": 560
409
+ },
410
+ {
411
+ "epoch": 0.384,
412
+ "grad_norm": 0.10544762760400772,
413
+ "learning_rate": 0.00013692883895131088,
414
+ "loss": 4.3064,
415
+ "step": 570
416
+ },
417
+ {
418
+ "epoch": 0.39073684210526316,
419
+ "grad_norm": 0.150394469499588,
420
+ "learning_rate": 0.0001354307116104869,
421
+ "loss": 3.9517,
422
+ "step": 580
423
+ },
424
+ {
425
+ "epoch": 0.3974736842105263,
426
+ "grad_norm": 0.06921563297510147,
427
+ "learning_rate": 0.00013393258426966294,
428
+ "loss": 3.8917,
429
+ "step": 590
430
+ },
431
+ {
432
+ "epoch": 0.40421052631578946,
433
+ "grad_norm": 0.06402010470628738,
434
+ "learning_rate": 0.00013243445692883896,
435
+ "loss": 3.5635,
436
+ "step": 600
437
+ },
438
+ {
439
+ "epoch": 0.4109473684210526,
440
+ "grad_norm": 0.08918313682079315,
441
+ "learning_rate": 0.00013093632958801498,
442
+ "loss": 4.1197,
443
+ "step": 610
444
+ },
445
+ {
446
+ "epoch": 0.41768421052631577,
447
+ "grad_norm": 0.054397523403167725,
448
+ "learning_rate": 0.000129438202247191,
449
+ "loss": 4.0442,
450
+ "step": 620
451
+ },
452
+ {
453
+ "epoch": 0.4244210526315789,
454
+ "grad_norm": 0.068702831864357,
455
+ "learning_rate": 0.00012794007490636705,
456
+ "loss": 3.7506,
457
+ "step": 630
458
+ },
459
+ {
460
+ "epoch": 0.43115789473684213,
461
+ "grad_norm": 0.14575353264808655,
462
+ "learning_rate": 0.0001264419475655431,
463
+ "loss": 3.7359,
464
+ "step": 640
465
+ },
466
+ {
467
+ "epoch": 0.4378947368421053,
468
+ "grad_norm": 0.1481335461139679,
469
+ "learning_rate": 0.00012494382022471912,
470
+ "loss": 3.3705,
471
+ "step": 650
472
+ },
473
+ {
474
+ "epoch": 0.44463157894736843,
475
+ "grad_norm": 0.06438197940587997,
476
+ "learning_rate": 0.00012344569288389514,
477
+ "loss": 4.0248,
478
+ "step": 660
479
+ },
480
+ {
481
+ "epoch": 0.4513684210526316,
482
+ "grad_norm": 0.38855019211769104,
483
+ "learning_rate": 0.00012194756554307116,
484
+ "loss": 4.0265,
485
+ "step": 670
486
+ },
487
+ {
488
+ "epoch": 0.45810526315789474,
489
+ "grad_norm": 0.20793034136295319,
490
+ "learning_rate": 0.00012044943820224719,
491
+ "loss": 3.7305,
492
+ "step": 680
493
+ },
494
+ {
495
+ "epoch": 0.4648421052631579,
496
+ "grad_norm": 0.11011853814125061,
497
+ "learning_rate": 0.00011895131086142324,
498
+ "loss": 3.6933,
499
+ "step": 690
500
+ },
501
+ {
502
+ "epoch": 0.47157894736842104,
503
+ "grad_norm": 0.06795340031385422,
504
+ "learning_rate": 0.00011745318352059926,
505
+ "loss": 3.3734,
506
+ "step": 700
507
+ },
508
+ {
509
+ "epoch": 0.4783157894736842,
510
+ "grad_norm": 0.07788679003715515,
511
+ "learning_rate": 0.00011595505617977529,
512
+ "loss": 3.9053,
513
+ "step": 710
514
+ },
515
+ {
516
+ "epoch": 0.48505263157894735,
517
+ "grad_norm": 0.07339611649513245,
518
+ "learning_rate": 0.00011445692883895131,
519
+ "loss": 3.8685,
520
+ "step": 720
521
+ },
522
+ {
523
+ "epoch": 0.4917894736842105,
524
+ "grad_norm": 0.16048288345336914,
525
+ "learning_rate": 0.00011295880149812735,
526
+ "loss": 3.5673,
527
+ "step": 730
528
+ },
529
+ {
530
+ "epoch": 0.4985263157894737,
531
+ "grad_norm": 0.2596355974674225,
532
+ "learning_rate": 0.00011146067415730337,
533
+ "loss": 3.5684,
534
+ "step": 740
535
+ },
536
+ {
537
+ "epoch": 0.5052631578947369,
538
+ "grad_norm": 0.10115884989500046,
539
+ "learning_rate": 0.00010996254681647941,
540
+ "loss": 3.2226,
541
+ "step": 750
542
+ },
543
+ {
544
+ "epoch": 0.512,
545
+ "grad_norm": 0.13997367024421692,
546
+ "learning_rate": 0.00010846441947565545,
547
+ "loss": 3.8579,
548
+ "step": 760
549
+ },
550
+ {
551
+ "epoch": 0.5187368421052632,
552
+ "grad_norm": 0.08359155058860779,
553
+ "learning_rate": 0.00010696629213483147,
554
+ "loss": 3.8313,
555
+ "step": 770
556
+ },
557
+ {
558
+ "epoch": 0.5254736842105263,
559
+ "grad_norm": 0.2407791018486023,
560
+ "learning_rate": 0.0001054681647940075,
561
+ "loss": 3.5257,
562
+ "step": 780
563
+ },
564
+ {
565
+ "epoch": 0.5322105263157895,
566
+ "grad_norm": 0.34615418314933777,
567
+ "learning_rate": 0.00010397003745318352,
568
+ "loss": 3.5113,
569
+ "step": 790
570
+ },
571
+ {
572
+ "epoch": 0.5389473684210526,
573
+ "grad_norm": 0.06987264007329941,
574
+ "learning_rate": 0.00010247191011235954,
575
+ "loss": 3.1525,
576
+ "step": 800
577
+ },
578
+ {
579
+ "epoch": 0.5456842105263158,
580
+ "grad_norm": 0.07933894544839859,
581
+ "learning_rate": 0.00010097378277153558,
582
+ "loss": 3.718,
583
+ "step": 810
584
+ },
585
+ {
586
+ "epoch": 0.5524210526315789,
587
+ "grad_norm": 0.12424171715974808,
588
+ "learning_rate": 9.947565543071161e-05,
589
+ "loss": 3.6641,
590
+ "step": 820
591
+ },
592
+ {
593
+ "epoch": 0.5591578947368421,
594
+ "grad_norm": 0.2515564262866974,
595
+ "learning_rate": 9.797752808988764e-05,
596
+ "loss": 3.4268,
597
+ "step": 830
598
+ },
599
+ {
600
+ "epoch": 0.5658947368421052,
601
+ "grad_norm": 0.30851560831069946,
602
+ "learning_rate": 9.647940074906368e-05,
603
+ "loss": 3.3856,
604
+ "step": 840
605
+ },
606
+ {
607
+ "epoch": 0.5726315789473684,
608
+ "grad_norm": 0.05149822682142258,
609
+ "learning_rate": 9.49812734082397e-05,
610
+ "loss": 3.1259,
611
+ "step": 850
612
+ },
613
+ {
614
+ "epoch": 0.5793684210526315,
615
+ "grad_norm": 0.17960771918296814,
616
+ "learning_rate": 9.348314606741574e-05,
617
+ "loss": 3.6767,
618
+ "step": 860
619
+ },
620
+ {
621
+ "epoch": 0.5861052631578947,
622
+ "grad_norm": 0.17523854970932007,
623
+ "learning_rate": 9.198501872659176e-05,
624
+ "loss": 3.5995,
625
+ "step": 870
626
+ },
627
+ {
628
+ "epoch": 0.592842105263158,
629
+ "grad_norm": 0.3186163008213043,
630
+ "learning_rate": 9.04868913857678e-05,
631
+ "loss": 3.3966,
632
+ "step": 880
633
+ },
634
+ {
635
+ "epoch": 0.5995789473684211,
636
+ "grad_norm": 0.21263690292835236,
637
+ "learning_rate": 8.898876404494383e-05,
638
+ "loss": 3.3526,
639
+ "step": 890
640
+ },
641
+ {
642
+ "epoch": 0.6063157894736843,
643
+ "grad_norm": 0.10399254411458969,
644
+ "learning_rate": 8.749063670411985e-05,
645
+ "loss": 3.0519,
646
+ "step": 900
647
+ },
648
+ {
649
+ "epoch": 0.6130526315789474,
650
+ "grad_norm": 0.13143524527549744,
651
+ "learning_rate": 8.599250936329589e-05,
652
+ "loss": 3.629,
653
+ "step": 910
654
+ },
655
+ {
656
+ "epoch": 0.6197894736842106,
657
+ "grad_norm": 0.15374666452407837,
658
+ "learning_rate": 8.449438202247192e-05,
659
+ "loss": 3.6895,
660
+ "step": 920
661
+ },
662
+ {
663
+ "epoch": 0.6265263157894737,
664
+ "grad_norm": 0.23757484555244446,
665
+ "learning_rate": 8.299625468164794e-05,
666
+ "loss": 3.3622,
667
+ "step": 930
668
+ },
669
+ {
670
+ "epoch": 0.6332631578947369,
671
+ "grad_norm": 0.1661984622478485,
672
+ "learning_rate": 8.149812734082397e-05,
673
+ "loss": 3.3248,
674
+ "step": 940
675
+ },
676
+ {
677
+ "epoch": 0.64,
678
+ "grad_norm": 0.08603614568710327,
679
+ "learning_rate": 8e-05,
680
+ "loss": 3.0086,
681
+ "step": 950
682
+ },
683
+ {
684
+ "epoch": 0.6467368421052632,
685
+ "grad_norm": 0.07694745808839798,
686
+ "learning_rate": 7.850187265917604e-05,
687
+ "loss": 3.5162,
688
+ "step": 960
689
+ },
690
+ {
691
+ "epoch": 0.6534736842105263,
692
+ "grad_norm": 0.16395558416843414,
693
+ "learning_rate": 7.700374531835206e-05,
694
+ "loss": 3.4812,
695
+ "step": 970
696
+ },
697
+ {
698
+ "epoch": 0.6602105263157895,
699
+ "grad_norm": 0.13817398250102997,
700
+ "learning_rate": 7.55056179775281e-05,
701
+ "loss": 3.2516,
702
+ "step": 980
703
+ },
704
+ {
705
+ "epoch": 0.6669473684210526,
706
+ "grad_norm": 0.25807198882102966,
707
+ "learning_rate": 7.400749063670413e-05,
708
+ "loss": 3.2101,
709
+ "step": 990
710
+ },
711
+ {
712
+ "epoch": 0.6736842105263158,
713
+ "grad_norm": 0.06848172843456268,
714
+ "learning_rate": 7.250936329588015e-05,
715
+ "loss": 2.93,
716
+ "step": 1000
717
+ },
718
+ {
719
+ "epoch": 0.6804210526315789,
720
+ "grad_norm": 1.089575171470642,
721
+ "learning_rate": 7.101123595505618e-05,
722
+ "loss": 3.4925,
723
+ "step": 1010
724
+ },
725
+ {
726
+ "epoch": 0.6871578947368421,
727
+ "grad_norm": 0.20126965641975403,
728
+ "learning_rate": 6.951310861423222e-05,
729
+ "loss": 3.4603,
730
+ "step": 1020
731
+ },
732
+ {
733
+ "epoch": 0.6938947368421052,
734
+ "grad_norm": 0.21779027581214905,
735
+ "learning_rate": 6.801498127340824e-05,
736
+ "loss": 3.1723,
737
+ "step": 1030
738
+ },
739
+ {
740
+ "epoch": 0.7006315789473684,
741
+ "grad_norm": 0.18239159882068634,
742
+ "learning_rate": 6.651685393258428e-05,
743
+ "loss": 3.1903,
744
+ "step": 1040
745
+ },
746
+ {
747
+ "epoch": 0.7073684210526315,
748
+ "grad_norm": 0.06677573919296265,
749
+ "learning_rate": 6.50187265917603e-05,
750
+ "loss": 2.8445,
751
+ "step": 1050
752
+ },
753
+ {
754
+ "epoch": 0.7141052631578947,
755
+ "grad_norm": 0.42619746923446655,
756
+ "learning_rate": 6.352059925093634e-05,
757
+ "loss": 3.4319,
758
+ "step": 1060
759
+ },
760
+ {
761
+ "epoch": 0.7208421052631578,
762
+ "grad_norm": 0.12023507058620453,
763
+ "learning_rate": 6.202247191011237e-05,
764
+ "loss": 3.3826,
765
+ "step": 1070
766
+ },
767
+ {
768
+ "epoch": 0.7275789473684211,
769
+ "grad_norm": 0.15099403262138367,
770
+ "learning_rate": 6.052434456928839e-05,
771
+ "loss": 3.1425,
772
+ "step": 1080
773
+ },
774
+ {
775
+ "epoch": 0.7343157894736843,
776
+ "grad_norm": 0.3474717438220978,
777
+ "learning_rate": 5.902621722846442e-05,
778
+ "loss": 3.1279,
779
+ "step": 1090
780
+ },
781
+ {
782
+ "epoch": 0.7410526315789474,
783
+ "grad_norm": 0.12225649505853653,
784
+ "learning_rate": 5.752808988764046e-05,
785
+ "loss": 2.9033,
786
+ "step": 1100
787
+ },
788
+ {
789
+ "epoch": 0.7477894736842106,
790
+ "grad_norm": 0.19639068841934204,
791
+ "learning_rate": 5.6029962546816485e-05,
792
+ "loss": 3.3681,
793
+ "step": 1110
794
+ },
795
+ {
796
+ "epoch": 0.7545263157894737,
797
+ "grad_norm": 0.10571427643299103,
798
+ "learning_rate": 5.453183520599251e-05,
799
+ "loss": 3.335,
800
+ "step": 1120
801
+ },
802
+ {
803
+ "epoch": 0.7612631578947369,
804
+ "grad_norm": 0.5154901146888733,
805
+ "learning_rate": 5.3033707865168545e-05,
806
+ "loss": 3.0952,
807
+ "step": 1130
808
+ },
809
+ {
810
+ "epoch": 0.768,
811
+ "grad_norm": 0.6122628450393677,
812
+ "learning_rate": 5.153558052434457e-05,
813
+ "loss": 3.1269,
814
+ "step": 1140
815
+ },
816
+ {
817
+ "epoch": 0.7747368421052632,
818
+ "grad_norm": 0.19698569178581238,
819
+ "learning_rate": 5.00374531835206e-05,
820
+ "loss": 2.8233,
821
+ "step": 1150
822
+ },
823
+ {
824
+ "epoch": 0.7814736842105263,
825
+ "grad_norm": 0.13018374145030975,
826
+ "learning_rate": 4.853932584269663e-05,
827
+ "loss": 3.3094,
828
+ "step": 1160
829
+ },
830
+ {
831
+ "epoch": 0.7882105263157895,
832
+ "grad_norm": 0.09522128850221634,
833
+ "learning_rate": 4.704119850187266e-05,
834
+ "loss": 3.2765,
835
+ "step": 1170
836
+ },
837
+ {
838
+ "epoch": 0.7949473684210526,
839
+ "grad_norm": 0.10098107159137726,
840
+ "learning_rate": 4.554307116104869e-05,
841
+ "loss": 3.0807,
842
+ "step": 1180
843
+ },
844
+ {
845
+ "epoch": 0.8016842105263158,
846
+ "grad_norm": 0.18019132316112518,
847
+ "learning_rate": 4.404494382022472e-05,
848
+ "loss": 3.0332,
849
+ "step": 1190
850
+ },
851
+ {
852
+ "epoch": 0.8084210526315789,
853
+ "grad_norm": 0.16289708018302917,
854
+ "learning_rate": 4.2546816479400754e-05,
855
+ "loss": 2.7374,
856
+ "step": 1200
857
+ },
858
+ {
859
+ "epoch": 0.8151578947368421,
860
+ "grad_norm": 0.12666673958301544,
861
+ "learning_rate": 4.104868913857678e-05,
862
+ "loss": 3.2118,
863
+ "step": 1210
864
+ },
865
+ {
866
+ "epoch": 0.8218947368421052,
867
+ "grad_norm": 0.16891352832317352,
868
+ "learning_rate": 3.955056179775281e-05,
869
+ "loss": 3.1902,
870
+ "step": 1220
871
+ },
872
+ {
873
+ "epoch": 0.8286315789473684,
874
+ "grad_norm": 0.10958009213209152,
875
+ "learning_rate": 3.805243445692884e-05,
876
+ "loss": 2.9862,
877
+ "step": 1230
878
+ },
879
+ {
880
+ "epoch": 0.8353684210526315,
881
+ "grad_norm": 0.10642745345830917,
882
+ "learning_rate": 3.655430711610487e-05,
883
+ "loss": 3.0052,
884
+ "step": 1240
885
+ },
886
+ {
887
+ "epoch": 0.8421052631578947,
888
+ "grad_norm": 0.05656813085079193,
889
+ "learning_rate": 3.50561797752809e-05,
890
+ "loss": 2.723,
891
+ "step": 1250
892
+ },
893
+ {
894
+ "epoch": 0.8488421052631578,
895
+ "grad_norm": 0.08322717994451523,
896
+ "learning_rate": 3.355805243445693e-05,
897
+ "loss": 3.234,
898
+ "step": 1260
899
+ },
900
+ {
901
+ "epoch": 0.8555789473684211,
902
+ "grad_norm": 0.13246551156044006,
903
+ "learning_rate": 3.2059925093632956e-05,
904
+ "loss": 3.212,
905
+ "step": 1270
906
+ },
907
+ {
908
+ "epoch": 0.8623157894736843,
909
+ "grad_norm": 0.10225304961204529,
910
+ "learning_rate": 3.056179775280899e-05,
911
+ "loss": 2.9484,
912
+ "step": 1280
913
+ },
914
+ {
915
+ "epoch": 0.8690526315789474,
916
+ "grad_norm": 0.19440552592277527,
917
+ "learning_rate": 2.9063670411985024e-05,
918
+ "loss": 2.9266,
919
+ "step": 1290
920
+ },
921
+ {
922
+ "epoch": 0.8757894736842106,
923
+ "grad_norm": 0.08913037180900574,
924
+ "learning_rate": 2.7565543071161047e-05,
925
+ "loss": 2.6801,
926
+ "step": 1300
927
+ },
928
+ {
929
+ "epoch": 0.8825263157894737,
930
+ "grad_norm": 0.10815408080816269,
931
+ "learning_rate": 2.606741573033708e-05,
932
+ "loss": 3.1505,
933
+ "step": 1310
934
+ },
935
+ {
936
+ "epoch": 0.8892631578947369,
937
+ "grad_norm": 0.14371147751808167,
938
+ "learning_rate": 2.4569288389513108e-05,
939
+ "loss": 3.1293,
940
+ "step": 1320
941
+ },
942
+ {
943
+ "epoch": 0.896,
944
+ "grad_norm": 0.1680973470211029,
945
+ "learning_rate": 2.3071161048689138e-05,
946
+ "loss": 2.8961,
947
+ "step": 1330
948
+ },
949
+ {
950
+ "epoch": 0.9027368421052632,
951
+ "grad_norm": 0.19012019038200378,
952
+ "learning_rate": 2.157303370786517e-05,
953
+ "loss": 2.9096,
954
+ "step": 1340
955
+ },
956
+ {
957
+ "epoch": 0.9094736842105263,
958
+ "grad_norm": 0.060957688838243484,
959
+ "learning_rate": 2.00749063670412e-05,
960
+ "loss": 2.6879,
961
+ "step": 1350
962
+ },
963
+ {
964
+ "epoch": 0.9162105263157895,
965
+ "grad_norm": 0.15055014193058014,
966
+ "learning_rate": 1.857677902621723e-05,
967
+ "loss": 3.108,
968
+ "step": 1360
969
+ },
970
+ {
971
+ "epoch": 0.9229473684210526,
972
+ "grad_norm": 0.1378874033689499,
973
+ "learning_rate": 1.707865168539326e-05,
974
+ "loss": 3.0428,
975
+ "step": 1370
976
+ },
977
+ {
978
+ "epoch": 0.9296842105263158,
979
+ "grad_norm": 0.14901022613048553,
980
+ "learning_rate": 1.558052434456929e-05,
981
+ "loss": 2.8589,
982
+ "step": 1380
983
+ },
984
+ {
985
+ "epoch": 0.9364210526315789,
986
+ "grad_norm": 0.17515867948532104,
987
+ "learning_rate": 1.4082397003745318e-05,
988
+ "loss": 2.8563,
989
+ "step": 1390
990
+ },
991
+ {
992
+ "epoch": 0.9431578947368421,
993
+ "grad_norm": 0.11909812688827515,
994
+ "learning_rate": 1.258426966292135e-05,
995
+ "loss": 2.5759,
996
+ "step": 1400
997
+ },
998
+ {
999
+ "epoch": 0.9498947368421052,
1000
+ "grad_norm": 0.16348549723625183,
1001
+ "learning_rate": 1.1086142322097379e-05,
1002
+ "loss": 3.089,
1003
+ "step": 1410
1004
+ },
1005
+ {
1006
+ "epoch": 0.9566315789473684,
1007
+ "grad_norm": 0.08107765763998032,
1008
+ "learning_rate": 9.588014981273409e-06,
1009
+ "loss": 3.0145,
1010
+ "step": 1420
1011
+ },
1012
+ {
1013
+ "epoch": 0.9633684210526315,
1014
+ "grad_norm": 0.13251617550849915,
1015
+ "learning_rate": 8.089887640449438e-06,
1016
+ "loss": 2.8256,
1017
+ "step": 1430
1018
+ },
1019
+ {
1020
+ "epoch": 0.9701052631578947,
1021
+ "grad_norm": 0.10319063812494278,
1022
+ "learning_rate": 6.591760299625469e-06,
1023
+ "loss": 2.8456,
1024
+ "step": 1440
1025
+ },
1026
+ {
1027
+ "epoch": 0.9768421052631578,
1028
+ "grad_norm": 0.08950542658567429,
1029
+ "learning_rate": 5.093632958801498e-06,
1030
+ "loss": 2.605,
1031
+ "step": 1450
1032
+ },
1033
+ {
1034
+ "epoch": 0.983578947368421,
1035
+ "grad_norm": 0.08379487693309784,
1036
+ "learning_rate": 3.5955056179775286e-06,
1037
+ "loss": 3.0334,
1038
+ "step": 1460
1039
+ },
1040
+ {
1041
+ "epoch": 0.9903157894736843,
1042
+ "grad_norm": 0.1561821848154068,
1043
+ "learning_rate": 2.097378277153558e-06,
1044
+ "loss": 3.0357,
1045
+ "step": 1470
1046
+ },
1047
+ {
1048
+ "epoch": 0.9970526315789474,
1049
+ "grad_norm": 0.07574011385440826,
1050
+ "learning_rate": 5.992509363295881e-07,
1051
+ "loss": 2.7458,
1052
+ "step": 1480
1053
+ }
1054
+ ],
1055
+ "logging_steps": 10,
1056
+ "max_steps": 1484,
1057
+ "num_input_tokens_seen": 0,
1058
+ "num_train_epochs": 1,
1059
+ "save_steps": 500,
1060
+ "stateful_callbacks": {
1061
+ "TrainerControl": {
1062
+ "args": {
1063
+ "should_epoch_stop": false,
1064
+ "should_evaluate": false,
1065
+ "should_log": false,
1066
+ "should_save": true,
1067
+ "should_training_stop": true
1068
+ },
1069
+ "attributes": {}
1070
+ }
1071
+ },
1072
+ "total_flos": 2.32780044727799e+18,
1073
+ "train_batch_size": 4,
1074
+ "trial_name": null,
1075
+ "trial_params": null
1076
+ }
checkpoint-1484/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28da48262e760c5feb1c1e1f08d029374a06fa8d076c01d714f0912a196ad9d7
3
+ size 6904
checkpoint-1484/zero_to_fp32.py ADDED
@@ -0,0 +1,760 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 gc
25
+ import json
26
+ import numpy as np
27
+ from tqdm import tqdm
28
+ from collections import OrderedDict
29
+ from dataclasses import dataclass
30
+
31
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
32
+ # DeepSpeed data structures it has to be available in the current python environment.
33
+ from deepspeed.utils import logger
34
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
35
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
36
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
37
+
38
+
39
+ @dataclass
40
+ class zero_model_state:
41
+ buffers: dict()
42
+ param_shapes: dict()
43
+ shared_params: list
44
+ ds_version: int
45
+ frozen_param_shapes: dict()
46
+ frozen_param_fragments: dict()
47
+
48
+
49
+ debug = 0
50
+
51
+ # load to cpu
52
+ device = torch.device('cpu')
53
+
54
+
55
+ def atoi(text):
56
+ return int(text) if text.isdigit() else text
57
+
58
+
59
+ def natural_keys(text):
60
+ '''
61
+ alist.sort(key=natural_keys) sorts in human order
62
+ http://nedbatchelder.com/blog/200712/human_sorting.html
63
+ (See Toothy's implementation in the comments)
64
+ '''
65
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
66
+
67
+
68
+ def get_model_state_file(checkpoint_dir, zero_stage):
69
+ if not os.path.isdir(checkpoint_dir):
70
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
71
+
72
+ # there should be only one file
73
+ if zero_stage <= 2:
74
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
75
+ elif zero_stage == 3:
76
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
77
+
78
+ if not os.path.exists(file):
79
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
80
+
81
+ return file
82
+
83
+
84
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
85
+ # XXX: need to test that this simple glob rule works for multi-node setup too
86
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
87
+
88
+ if len(ckpt_files) == 0:
89
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
90
+
91
+ return ckpt_files
92
+
93
+
94
+ def get_optim_files(checkpoint_dir):
95
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
96
+
97
+
98
+ def get_model_state_files(checkpoint_dir):
99
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
100
+
101
+
102
+ def parse_model_states(files):
103
+ zero_model_states = []
104
+ for file in files:
105
+ state_dict = torch.load(file, map_location=device, weights_only=False)
106
+
107
+ if BUFFER_NAMES not in state_dict:
108
+ raise ValueError(f"{file} is not a model state checkpoint")
109
+ buffer_names = state_dict[BUFFER_NAMES]
110
+ if debug:
111
+ print("Found buffers:", buffer_names)
112
+
113
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
114
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
115
+ param_shapes = state_dict[PARAM_SHAPES]
116
+
117
+ # collect parameters that are included in param_shapes
118
+ param_names = []
119
+ for s in param_shapes:
120
+ for name in s.keys():
121
+ param_names.append(name)
122
+
123
+ # update with frozen parameters
124
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
125
+ if frozen_param_shapes is not None:
126
+ if debug:
127
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
128
+ param_names += list(frozen_param_shapes.keys())
129
+
130
+ # handle shared params
131
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
132
+
133
+ ds_version = state_dict.get(DS_VERSION, None)
134
+
135
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
136
+
137
+ z_model_state = zero_model_state(buffers=buffers,
138
+ param_shapes=param_shapes,
139
+ shared_params=shared_params,
140
+ ds_version=ds_version,
141
+ frozen_param_shapes=frozen_param_shapes,
142
+ frozen_param_fragments=frozen_param_fragments)
143
+ zero_model_states.append(z_model_state)
144
+
145
+ return zero_model_states
146
+
147
+
148
+ def parse_optim_states(files, ds_checkpoint_dir):
149
+ total_files = len(files)
150
+ state_dicts = []
151
+ for f in tqdm(files, desc='Loading checkpoint shards'):
152
+ state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
153
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
154
+ # and also handle the case where it was already removed by another helper script
155
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
156
+ state_dicts.append(state_dict)
157
+
158
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
159
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
160
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
161
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
162
+
163
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
164
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
165
+ # use the max of the partition_count to get the dp world_size.
166
+
167
+ if type(world_size) is list:
168
+ world_size = max(world_size)
169
+
170
+ if world_size != total_files:
171
+ raise ValueError(
172
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
173
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
174
+ )
175
+
176
+ # the groups are named differently in each stage
177
+ if zero_stage <= 2:
178
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
179
+ elif zero_stage == 3:
180
+ fp32_groups_key = FP32_FLAT_GROUPS
181
+ else:
182
+ raise ValueError(f"unknown zero stage {zero_stage}")
183
+
184
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
185
+ return zero_stage, world_size, fp32_flat_groups
186
+
187
+
188
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
189
+ """
190
+ Returns fp32 state_dict reconstructed from ds checkpoint
191
+
192
+ Args:
193
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
194
+
195
+ """
196
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
197
+
198
+ optim_files = get_optim_files(ds_checkpoint_dir)
199
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
200
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
201
+
202
+ model_files = get_model_state_files(ds_checkpoint_dir)
203
+
204
+ zero_model_states = parse_model_states(model_files)
205
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
206
+
207
+ if zero_stage <= 2:
208
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
209
+ exclude_frozen_parameters)
210
+ elif zero_stage == 3:
211
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
212
+ exclude_frozen_parameters)
213
+
214
+
215
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
216
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
217
+ return
218
+
219
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
220
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
221
+
222
+ if debug:
223
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
224
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
225
+
226
+ wanted_params = len(frozen_param_shapes)
227
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
228
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
229
+ print(f'Frozen params: Have {avail_numel} numels to process.')
230
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
231
+
232
+ total_params = 0
233
+ total_numel = 0
234
+ for name, shape in frozen_param_shapes.items():
235
+ total_params += 1
236
+ unpartitioned_numel = shape.numel()
237
+ total_numel += unpartitioned_numel
238
+
239
+ state_dict[name] = frozen_param_fragments[name]
240
+
241
+ if debug:
242
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
243
+
244
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
245
+
246
+
247
+ def _has_callable(obj, fn):
248
+ attr = getattr(obj, fn, None)
249
+ return callable(attr)
250
+
251
+
252
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
253
+ param_shapes = zero_model_states[0].param_shapes
254
+
255
+ # Reconstruction protocol:
256
+ #
257
+ # XXX: document this
258
+
259
+ if debug:
260
+ for i in range(world_size):
261
+ for j in range(len(fp32_flat_groups[0])):
262
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
263
+
264
+ # XXX: memory usage doubles here (zero2)
265
+ num_param_groups = len(fp32_flat_groups[0])
266
+ merged_single_partition_of_fp32_groups = []
267
+ for i in range(num_param_groups):
268
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
269
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
270
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
271
+ avail_numel = sum(
272
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
273
+
274
+ if debug:
275
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
276
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
277
+ # not asserting if there is a mismatch due to possible padding
278
+ print(f"Have {avail_numel} numels to process.")
279
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
280
+
281
+ # params
282
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
283
+ # out-of-core computing solution
284
+ total_numel = 0
285
+ total_params = 0
286
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
287
+ offset = 0
288
+ avail_numel = full_single_fp32_vector.numel()
289
+ for name, shape in shapes.items():
290
+
291
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
292
+ total_numel += unpartitioned_numel
293
+ total_params += 1
294
+
295
+ if debug:
296
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
297
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
298
+ offset += unpartitioned_numel
299
+
300
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
301
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
302
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
303
+ # live optimizer object, so we are checking that the numbers are within the right range
304
+ align_to = 2 * world_size
305
+
306
+ def zero2_align(x):
307
+ return align_to * math.ceil(x / align_to)
308
+
309
+ if debug:
310
+ print(f"original offset={offset}, avail_numel={avail_numel}")
311
+
312
+ offset = zero2_align(offset)
313
+ avail_numel = zero2_align(avail_numel)
314
+
315
+ if debug:
316
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
317
+
318
+ # Sanity check
319
+ if offset != avail_numel:
320
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
321
+
322
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
323
+
324
+
325
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
326
+ exclude_frozen_parameters):
327
+ state_dict = OrderedDict()
328
+
329
+ # buffers
330
+ buffers = zero_model_states[0].buffers
331
+ state_dict.update(buffers)
332
+ if debug:
333
+ print(f"added {len(buffers)} buffers")
334
+
335
+ if not exclude_frozen_parameters:
336
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
337
+
338
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
339
+
340
+ # recover shared parameters
341
+ for pair in zero_model_states[0].shared_params:
342
+ if pair[1] in state_dict:
343
+ state_dict[pair[0]] = state_dict[pair[1]]
344
+
345
+ return state_dict
346
+
347
+
348
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
349
+ remainder = unpartitioned_numel % world_size
350
+ padding_numel = (world_size - remainder) if remainder else 0
351
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
352
+ return partitioned_numel, padding_numel
353
+
354
+
355
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
356
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
357
+ return
358
+
359
+ if debug:
360
+ for i in range(world_size):
361
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
362
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
363
+
364
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
365
+ wanted_params = len(frozen_param_shapes)
366
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
367
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
368
+ print(f'Frozen params: Have {avail_numel} numels to process.')
369
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
370
+
371
+ total_params = 0
372
+ total_numel = 0
373
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
374
+ total_params += 1
375
+ unpartitioned_numel = shape.numel()
376
+ total_numel += unpartitioned_numel
377
+
378
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
379
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
380
+
381
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
382
+
383
+ if debug:
384
+ print(
385
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
386
+ )
387
+
388
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
389
+
390
+
391
+ class GatheredTensor:
392
+ """
393
+ A pseudo tensor that collects partitioned weights.
394
+ It is more memory efficient when there are multiple groups.
395
+ """
396
+
397
+ def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
398
+ self.flat_groups = flat_groups
399
+ self.flat_groups_offset = flat_groups_offset
400
+ self.offset = offset
401
+ self.partitioned_numel = partitioned_numel
402
+ self.shape = shape
403
+ self.dtype = self.flat_groups[0][0].dtype
404
+
405
+ def contiguous(self):
406
+ """
407
+ Merge partitioned weights from flat_groups into a single tensor.
408
+ """
409
+ end_idx = self.offset + self.partitioned_numel
410
+ world_size = len(self.flat_groups)
411
+ pad_flat_param_chunks = []
412
+
413
+ for rank_i in range(world_size):
414
+ # for each rank, we need to collect weights from related group/groups
415
+ flat_groups_at_rank_i = self.flat_groups[rank_i]
416
+ start_group_id = None
417
+ end_group_id = None
418
+ for group_id in range(len(self.flat_groups_offset)):
419
+ if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
420
+ start_group_id = group_id
421
+ if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
422
+ end_group_id = group_id
423
+ break
424
+ # collect weights from related group/groups
425
+ for group_id in range(start_group_id, end_group_id + 1):
426
+ flat_tensor = flat_groups_at_rank_i[group_id]
427
+ start_offset = self.offset - self.flat_groups_offset[group_id]
428
+ end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
429
+ pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
430
+
431
+ # collect weights from all ranks
432
+ pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
433
+ param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
434
+ return param
435
+
436
+
437
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
438
+ param_shapes = zero_model_states[0].param_shapes
439
+ avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
440
+
441
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
442
+ # param, re-consolidating each param, while dealing with padding if any
443
+
444
+ # merge list of dicts, preserving order
445
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
446
+
447
+ if debug:
448
+ for i in range(world_size):
449
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
450
+
451
+ wanted_params = len(param_shapes)
452
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
453
+ # not asserting if there is a mismatch due to possible padding
454
+ avail_numel = fp32_flat_groups[0].numel() * world_size
455
+ print(f"Trainable params: Have {avail_numel} numels to process.")
456
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
457
+
458
+ # params
459
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
460
+ # out-of-core computing solution
461
+ offset = 0
462
+ total_numel = 0
463
+ total_params = 0
464
+ flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
465
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
466
+ unpartitioned_numel = shape.numel()
467
+ total_numel += unpartitioned_numel
468
+ total_params += 1
469
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
470
+
471
+ if debug:
472
+ print(
473
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
474
+ )
475
+
476
+ # memory efficient tensor
477
+ tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
478
+ state_dict[name] = tensor
479
+ offset += partitioned_numel
480
+
481
+ offset *= world_size
482
+
483
+ # Sanity check
484
+ if offset != avail_numel:
485
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
486
+
487
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
488
+
489
+
490
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
491
+ exclude_frozen_parameters):
492
+ state_dict = OrderedDict()
493
+
494
+ # buffers
495
+ buffers = zero_model_states[0].buffers
496
+ state_dict.update(buffers)
497
+ if debug:
498
+ print(f"added {len(buffers)} buffers")
499
+
500
+ if not exclude_frozen_parameters:
501
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
502
+
503
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
504
+
505
+ # recover shared parameters
506
+ for pair in zero_model_states[0].shared_params:
507
+ if pair[1] in state_dict:
508
+ state_dict[pair[0]] = state_dict[pair[1]]
509
+
510
+ return state_dict
511
+
512
+
513
+ def to_torch_tensor(state_dict, return_empty_tensor=False):
514
+ """
515
+ Convert state_dict of GatheredTensor to torch tensor
516
+ """
517
+ torch_state_dict = {}
518
+ converted_tensors = {}
519
+ for name, tensor in state_dict.items():
520
+ tensor_id = id(tensor)
521
+ if tensor_id in converted_tensors: # shared tensors
522
+ shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
523
+ torch_state_dict[name] = shared_tensor
524
+ else:
525
+ converted_tensors[tensor_id] = name
526
+ if return_empty_tensor:
527
+ torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
528
+ else:
529
+ torch_state_dict[name] = tensor.contiguous()
530
+ return torch_state_dict
531
+
532
+
533
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
534
+ tag=None,
535
+ exclude_frozen_parameters=False,
536
+ lazy_mode=False):
537
+ """
538
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
539
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
540
+ via a model hub.
541
+
542
+ Args:
543
+ - ``checkpoint_dir``: path to the desired checkpoint folder
544
+ - ``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``
545
+ - ``exclude_frozen_parameters``: exclude frozen parameters
546
+ - ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
547
+ Convert the pesduo tensor to torch tensor by ``.contiguous()``
548
+
549
+ Returns:
550
+ - pytorch ``state_dict``
551
+
552
+ A typical usage might be ::
553
+
554
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
555
+ # do the training and checkpoint saving
556
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
557
+ model = model.cpu() # move to cpu
558
+ model.load_state_dict(state_dict)
559
+ # submit to model hub or save the model to share with others
560
+
561
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
562
+ application. i.e. you will need to re-initialize the deepspeed engine, since
563
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
564
+
565
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
566
+
567
+ Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
568
+ You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
569
+ the checkpoint. Or you can load state_dict in lazy mode ::
570
+
571
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
572
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
573
+ for name, lazy_tensor in state_dict.item():
574
+ tensor = lazy_tensor.contiguous() # to cpu
575
+ print(name, tensor)
576
+ # del tensor to release memory if it no longer in use
577
+ """
578
+ if tag is None:
579
+ latest_path = os.path.join(checkpoint_dir, 'latest')
580
+ if os.path.isfile(latest_path):
581
+ with open(latest_path, 'r') as fd:
582
+ tag = fd.read().strip()
583
+ else:
584
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
585
+
586
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
587
+
588
+ if not os.path.isdir(ds_checkpoint_dir):
589
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
590
+
591
+ state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
592
+ if lazy_mode:
593
+ return state_dict
594
+ else:
595
+ return to_torch_tensor(state_dict)
596
+
597
+
598
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
599
+ output_dir,
600
+ max_shard_size="5GB",
601
+ safe_serialization=False,
602
+ tag=None,
603
+ exclude_frozen_parameters=False):
604
+ """
605
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
606
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
607
+
608
+ Args:
609
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
610
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
611
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
612
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
613
+ - ``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``
614
+ - ``exclude_frozen_parameters``: exclude frozen parameters
615
+ """
616
+
617
+ # Dependency pre-check
618
+ if safe_serialization:
619
+ try:
620
+ from safetensors.torch import save_file
621
+ except ImportError:
622
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
623
+ raise
624
+ if max_shard_size is not None:
625
+ try:
626
+ from huggingface_hub import split_torch_state_dict_into_shards
627
+ except ImportError:
628
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
629
+ raise
630
+
631
+ # Convert zero checkpoint to state_dict
632
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
633
+ tag,
634
+ exclude_frozen_parameters,
635
+ lazy_mode=True)
636
+
637
+ # Shard the model if it is too big.
638
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
639
+ if max_shard_size is not None:
640
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
641
+ # an memory-efficient approach for sharding
642
+ empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
643
+ state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
644
+ filename_pattern=filename_pattern,
645
+ max_shard_size=max_shard_size)
646
+ else:
647
+ from collections import namedtuple
648
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
649
+ state_dict_split = StateDictSplit(is_sharded=False,
650
+ filename_to_tensors={weights_name: list(state_dict.keys())})
651
+
652
+ # Save the model by shard
653
+ os.makedirs(output_dir, exist_ok=True)
654
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
655
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
656
+ shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
657
+ shard_state_dict = to_torch_tensor(shard_state_dict)
658
+ output_path = os.path.join(output_dir, shard_file)
659
+ if safe_serialization:
660
+ save_file(shard_state_dict, output_path, metadata={"format": "pt"})
661
+ else:
662
+ torch.save(shard_state_dict, output_path)
663
+ # release the memory of current shard
664
+ for tensor_name in list(shard_state_dict.keys()):
665
+ del state_dict[tensor_name]
666
+ del shard_state_dict[tensor_name]
667
+ del shard_state_dict
668
+ gc.collect()
669
+
670
+ # Save index if sharded
671
+ if state_dict_split.is_sharded:
672
+ index = {
673
+ "metadata": state_dict_split.metadata,
674
+ "weight_map": state_dict_split.tensor_to_filename,
675
+ }
676
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
677
+ save_index_file = os.path.join(output_dir, save_index_file)
678
+ with open(save_index_file, "w", encoding="utf-8") as f:
679
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
680
+ f.write(content)
681
+
682
+
683
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
684
+ """
685
+ 1. Put the provided model to cpu
686
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
687
+ 3. Load it into the provided model
688
+
689
+ Args:
690
+ - ``model``: the model object to update
691
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
692
+ - ``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``
693
+
694
+ Returns:
695
+ - ``model`: modified model
696
+
697
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
698
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
699
+ conveniently placed for you in the checkpoint folder.
700
+
701
+ A typical usage might be ::
702
+
703
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
704
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
705
+ # submit to model hub or save the model to share with others
706
+
707
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
708
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
709
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
710
+
711
+ """
712
+ logger.info(f"Extracting fp32 weights")
713
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
714
+
715
+ logger.info(f"Overwriting model with fp32 weights")
716
+ model = model.cpu()
717
+ model.load_state_dict(state_dict, strict=False)
718
+
719
+ return model
720
+
721
+
722
+ if __name__ == "__main__":
723
+ parser = argparse.ArgumentParser()
724
+ parser.add_argument("checkpoint_dir",
725
+ type=str,
726
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
727
+ parser.add_argument("output_dir",
728
+ type=str,
729
+ help="directory to the pytorch fp32 state_dict output files"
730
+ "(e.g. path/checkpoint-12-output/)")
731
+ parser.add_argument(
732
+ "--max_shard_size",
733
+ type=str,
734
+ default="5GB",
735
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
736
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
737
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
738
+ "without CPU OOM issues.")
739
+ parser.add_argument(
740
+ "--safe_serialization",
741
+ default=False,
742
+ action='store_true',
743
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
744
+ parser.add_argument("-t",
745
+ "--tag",
746
+ type=str,
747
+ default=None,
748
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
749
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
750
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
751
+ args = parser.parse_args()
752
+
753
+ debug = args.debug
754
+
755
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
756
+ args.output_dir,
757
+ max_shard_size=args.max_shard_size,
758
+ safe_serialization=args.safe_serialization,
759
+ tag=args.tag,
760
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
logs/events.out.tfevents.1738806841.apolo.2066103.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd129cec2e7b2768185ecf810b2a439324462aa63fa860020502e7dd4cbc0815
3
+ size 8328
logs/events.out.tfevents.1738813546.apolo.2108330.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74b32b9d52814ce91e481a2b4c7676a0ae9fe5f03c5507ded89a5ca3b06e6ae0
3
+ size 37585
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "▁<PRE>",
4
+ "▁<MID>",
5
+ "▁<SUF>",
6
+ "▁<EOT>"
7
+ ],
8
+ "bos_token": {
9
+ "content": "<s>",
10
+ "lstrip": false,
11
+ "normalized": false,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ },
15
+ "eos_token": {
16
+ "content": "</s>",
17
+ "lstrip": false,
18
+ "normalized": false,
19
+ "rstrip": false,
20
+ "single_word": false
21
+ },
22
+ "pad_token": "</s>",
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45ccb9c8b6b561889acea59191d66986d314e7cbd6a78abc6e49b139ca91c1e6
3
+ size 500058
tokenizer_config.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "32007": {
30
+ "content": "▁<PRE>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "32008": {
38
+ "content": "▁<SUF>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "32009": {
46
+ "content": "▁<MID>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "32010": {
54
+ "content": "▁<EOT>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ }
61
+ },
62
+ "additional_special_tokens": [
63
+ "▁<PRE>",
64
+ "▁<MID>",
65
+ "▁<SUF>",
66
+ "▁<EOT>"
67
+ ],
68
+ "bos_token": "<s>",
69
+ "clean_up_tokenization_spaces": false,
70
+ "eos_token": "</s>",
71
+ "eot_token": "▁<EOT>",
72
+ "extra_special_tokens": {},
73
+ "fill_token": "<FILL_ME>",
74
+ "legacy": null,
75
+ "middle_token": "▁<MID>",
76
+ "model_max_length": 2048,
77
+ "pad_token": "</s>",
78
+ "padding_side": "right",
79
+ "prefix_token": "▁<PRE>",
80
+ "sp_model_kwargs": {},
81
+ "suffix_token": "▁<SUF>",
82
+ "tokenizer_class": "CodeLlamaTokenizer",
83
+ "unk_token": "<unk>",
84
+ "use_default_system_prompt": false
85
+ }