PEFT
Safetensors
sleepdeprived3 commited on
Commit
56ce20b
·
verified ·
1 Parent(s): 04fa19a

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: mistralai/Mistral-Nemo-Instruct-2407
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.15.1
adapter_config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "mistralai/Mistral-Nemo-Instruct-2407",
5
+ "bias": "none",
6
+ "corda_config": null,
7
+ "eva_config": null,
8
+ "exclude_modules": null,
9
+ "fan_in_fan_out": null,
10
+ "inference_mode": true,
11
+ "init_lora_weights": true,
12
+ "layer_replication": null,
13
+ "layers_pattern": null,
14
+ "layers_to_transform": null,
15
+ "loftq_config": {},
16
+ "lora_alpha": 32,
17
+ "lora_bias": false,
18
+ "lora_dropout": 0.1,
19
+ "megatron_config": null,
20
+ "megatron_core": "megatron.core",
21
+ "modules_to_save": null,
22
+ "peft_type": "LORA",
23
+ "r": 32,
24
+ "rank_pattern": {},
25
+ "revision": null,
26
+ "target_modules": [
27
+ "o_proj",
28
+ "v_proj",
29
+ "k_proj",
30
+ "q_proj",
31
+ "gate_proj",
32
+ "up_proj",
33
+ "down_proj"
34
+ ],
35
+ "task_type": "CAUSAL_LM",
36
+ "trainable_token_indices": null,
37
+ "use_dora": false,
38
+ "use_rslora": false
39
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08d19f934ca1a14a01857cfb4940605cec545447de6279dbf541e011c4e94c6e
3
+ size 228141160
global_step599/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:5f38ac9c77df5534f00d084b7400bf12168c3774dcaa7d09beb48e74ee1e0d46
3
+ size 1368456848
global_step599/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d0fccad359da002ccc73788d7110556776b2c13fdae46572b1e022df98984bc
3
+ size 402429729
latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step599
rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4587d199845342f90878f4dc0e7dbce541f83908f1a4d8e2e8f87afa3831c475
3
+ size 14244
scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d88891425b6da9fdf531ec7fe7e0434c0cb51007e555d2cc2480e16d7c4600c
3
+ size 1064
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": "</s>",
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
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0240ce510f08e6c2041724e9043e33be9d251d1e4a4d94eb68cd47b954b61d2
3
+ size 17078292
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff
 
trainer_state.json ADDED
@@ -0,0 +1,874 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_global_step": null,
3
+ "best_metric": null,
4
+ "best_model_checkpoint": null,
5
+ "epoch": 1.0309544282029235,
6
+ "eval_steps": 500,
7
+ "global_step": 600,
8
+ "is_hyper_param_search": false,
9
+ "is_local_process_zero": true,
10
+ "is_world_process_zero": true,
11
+ "log_history": [
12
+ {
13
+ "epoch": 0.008598452278589854,
14
+ "grad_norm": 0.5736560821533203,
15
+ "learning_rate": 5.517241379310345e-08,
16
+ "loss": 1.4983,
17
+ "step": 5
18
+ },
19
+ {
20
+ "epoch": 0.017196904557179708,
21
+ "grad_norm": 0.47119423747062683,
22
+ "learning_rate": 1.2413793103448275e-07,
23
+ "loss": 1.2594,
24
+ "step": 10
25
+ },
26
+ {
27
+ "epoch": 0.025795356835769563,
28
+ "grad_norm": 0.6366227865219116,
29
+ "learning_rate": 1.9310344827586205e-07,
30
+ "loss": 1.5001,
31
+ "step": 15
32
+ },
33
+ {
34
+ "epoch": 0.034393809114359415,
35
+ "grad_norm": 0.5710499882698059,
36
+ "learning_rate": 2.620689655172414e-07,
37
+ "loss": 1.5602,
38
+ "step": 20
39
+ },
40
+ {
41
+ "epoch": 0.04299226139294927,
42
+ "grad_norm": 0.4520650804042816,
43
+ "learning_rate": 3.310344827586207e-07,
44
+ "loss": 1.4316,
45
+ "step": 25
46
+ },
47
+ {
48
+ "epoch": 0.051590713671539126,
49
+ "grad_norm": 0.5874906778335571,
50
+ "learning_rate": 4e-07,
51
+ "loss": 1.5158,
52
+ "step": 30
53
+ },
54
+ {
55
+ "epoch": 0.06018916595012898,
56
+ "grad_norm": 0.4618767201900482,
57
+ "learning_rate": 4.689655172413793e-07,
58
+ "loss": 1.3945,
59
+ "step": 35
60
+ },
61
+ {
62
+ "epoch": 0.06878761822871883,
63
+ "grad_norm": 0.47305673360824585,
64
+ "learning_rate": 5.379310344827586e-07,
65
+ "loss": 1.4154,
66
+ "step": 40
67
+ },
68
+ {
69
+ "epoch": 0.07738607050730868,
70
+ "grad_norm": 0.5665937066078186,
71
+ "learning_rate": 6.068965517241379e-07,
72
+ "loss": 1.3776,
73
+ "step": 45
74
+ },
75
+ {
76
+ "epoch": 0.08598452278589853,
77
+ "grad_norm": 0.5359976291656494,
78
+ "learning_rate": 6.758620689655172e-07,
79
+ "loss": 1.5018,
80
+ "step": 50
81
+ },
82
+ {
83
+ "epoch": 0.09458297506448839,
84
+ "grad_norm": 0.5621670484542847,
85
+ "learning_rate": 7.448275862068965e-07,
86
+ "loss": 1.4493,
87
+ "step": 55
88
+ },
89
+ {
90
+ "epoch": 0.10318142734307825,
91
+ "grad_norm": 0.5842466354370117,
92
+ "learning_rate": 8.137931034482758e-07,
93
+ "loss": 1.4241,
94
+ "step": 60
95
+ },
96
+ {
97
+ "epoch": 0.1117798796216681,
98
+ "grad_norm": 0.6147713661193848,
99
+ "learning_rate": 8.827586206896551e-07,
100
+ "loss": 1.4748,
101
+ "step": 65
102
+ },
103
+ {
104
+ "epoch": 0.12037833190025796,
105
+ "grad_norm": 0.6653420925140381,
106
+ "learning_rate": 9.517241379310345e-07,
107
+ "loss": 1.6576,
108
+ "step": 70
109
+ },
110
+ {
111
+ "epoch": 0.1289767841788478,
112
+ "grad_norm": 0.5247882604598999,
113
+ "learning_rate": 1.0206896551724139e-06,
114
+ "loss": 1.439,
115
+ "step": 75
116
+ },
117
+ {
118
+ "epoch": 0.13757523645743766,
119
+ "grad_norm": 0.6043932437896729,
120
+ "learning_rate": 1.089655172413793e-06,
121
+ "loss": 1.475,
122
+ "step": 80
123
+ },
124
+ {
125
+ "epoch": 0.1461736887360275,
126
+ "grad_norm": 0.614253580570221,
127
+ "learning_rate": 1.1586206896551724e-06,
128
+ "loss": 1.4928,
129
+ "step": 85
130
+ },
131
+ {
132
+ "epoch": 0.15477214101461736,
133
+ "grad_norm": 0.6523554921150208,
134
+ "learning_rate": 1.2275862068965516e-06,
135
+ "loss": 1.5111,
136
+ "step": 90
137
+ },
138
+ {
139
+ "epoch": 0.16337059329320722,
140
+ "grad_norm": 0.4596118628978729,
141
+ "learning_rate": 1.2965517241379309e-06,
142
+ "loss": 1.4672,
143
+ "step": 95
144
+ },
145
+ {
146
+ "epoch": 0.17196904557179707,
147
+ "grad_norm": 0.5627196431159973,
148
+ "learning_rate": 1.3655172413793103e-06,
149
+ "loss": 1.4621,
150
+ "step": 100
151
+ },
152
+ {
153
+ "epoch": 0.18056749785038692,
154
+ "grad_norm": 0.5366098284721375,
155
+ "learning_rate": 1.4344827586206896e-06,
156
+ "loss": 1.3875,
157
+ "step": 105
158
+ },
159
+ {
160
+ "epoch": 0.18916595012897677,
161
+ "grad_norm": 0.48968908190727234,
162
+ "learning_rate": 1.5034482758620688e-06,
163
+ "loss": 1.4264,
164
+ "step": 110
165
+ },
166
+ {
167
+ "epoch": 0.19776440240756663,
168
+ "grad_norm": 0.5644566416740417,
169
+ "learning_rate": 1.5724137931034483e-06,
170
+ "loss": 1.3822,
171
+ "step": 115
172
+ },
173
+ {
174
+ "epoch": 0.2063628546861565,
175
+ "grad_norm": 0.49979278445243835,
176
+ "learning_rate": 1.6413793103448275e-06,
177
+ "loss": 1.4866,
178
+ "step": 120
179
+ },
180
+ {
181
+ "epoch": 0.21496130696474636,
182
+ "grad_norm": 0.5352433919906616,
183
+ "learning_rate": 1.710344827586207e-06,
184
+ "loss": 1.3047,
185
+ "step": 125
186
+ },
187
+ {
188
+ "epoch": 0.2235597592433362,
189
+ "grad_norm": 0.5073248744010925,
190
+ "learning_rate": 1.7793103448275862e-06,
191
+ "loss": 1.4763,
192
+ "step": 130
193
+ },
194
+ {
195
+ "epoch": 0.23215821152192606,
196
+ "grad_norm": 0.48227864503860474,
197
+ "learning_rate": 1.8482758620689653e-06,
198
+ "loss": 1.4552,
199
+ "step": 135
200
+ },
201
+ {
202
+ "epoch": 0.2407566638005159,
203
+ "grad_norm": 0.4420427978038788,
204
+ "learning_rate": 1.9172413793103447e-06,
205
+ "loss": 1.3285,
206
+ "step": 140
207
+ },
208
+ {
209
+ "epoch": 0.24935511607910577,
210
+ "grad_norm": 0.4224660396575928,
211
+ "learning_rate": 1.986206896551724e-06,
212
+ "loss": 1.4294,
213
+ "step": 145
214
+ },
215
+ {
216
+ "epoch": 0.2579535683576956,
217
+ "grad_norm": 0.3935889005661011,
218
+ "learning_rate": 1.999989634963924e-06,
219
+ "loss": 1.32,
220
+ "step": 150
221
+ },
222
+ {
223
+ "epoch": 0.26655202063628547,
224
+ "grad_norm": 0.352851539850235,
225
+ "learning_rate": 1.9999475273731217e-06,
226
+ "loss": 1.326,
227
+ "step": 155
228
+ },
229
+ {
230
+ "epoch": 0.2751504729148753,
231
+ "grad_norm": 0.4401000142097473,
232
+ "learning_rate": 1.9998730307756826e-06,
233
+ "loss": 1.352,
234
+ "step": 160
235
+ },
236
+ {
237
+ "epoch": 0.2837489251934652,
238
+ "grad_norm": 0.3836155831813812,
239
+ "learning_rate": 1.9997661475846052e-06,
240
+ "loss": 1.3492,
241
+ "step": 165
242
+ },
243
+ {
244
+ "epoch": 0.292347377472055,
245
+ "grad_norm": 0.32301604747772217,
246
+ "learning_rate": 1.9996268812619105e-06,
247
+ "loss": 1.309,
248
+ "step": 170
249
+ },
250
+ {
251
+ "epoch": 0.3009458297506449,
252
+ "grad_norm": 0.37157368659973145,
253
+ "learning_rate": 1.999455236318534e-06,
254
+ "loss": 1.4444,
255
+ "step": 175
256
+ },
257
+ {
258
+ "epoch": 0.30954428202923473,
259
+ "grad_norm": 0.340994268655777,
260
+ "learning_rate": 1.999251218314176e-06,
261
+ "loss": 1.2391,
262
+ "step": 180
263
+ },
264
+ {
265
+ "epoch": 0.3181427343078246,
266
+ "grad_norm": 0.3156416714191437,
267
+ "learning_rate": 1.999014833857124e-06,
268
+ "loss": 1.2496,
269
+ "step": 185
270
+ },
271
+ {
272
+ "epoch": 0.32674118658641443,
273
+ "grad_norm": 0.35868847370147705,
274
+ "learning_rate": 1.998746090604037e-06,
275
+ "loss": 1.3442,
276
+ "step": 190
277
+ },
278
+ {
279
+ "epoch": 0.3353396388650043,
280
+ "grad_norm": 0.31525614857673645,
281
+ "learning_rate": 1.9984449972597e-06,
282
+ "loss": 1.3011,
283
+ "step": 195
284
+ },
285
+ {
286
+ "epoch": 0.34393809114359414,
287
+ "grad_norm": 0.47816550731658936,
288
+ "learning_rate": 1.9981115635767376e-06,
289
+ "loss": 1.2962,
290
+ "step": 200
291
+ },
292
+ {
293
+ "epoch": 0.352536543422184,
294
+ "grad_norm": 0.31586989760398865,
295
+ "learning_rate": 1.9977458003553037e-06,
296
+ "loss": 1.2353,
297
+ "step": 205
298
+ },
299
+ {
300
+ "epoch": 0.36113499570077384,
301
+ "grad_norm": 0.3226100206375122,
302
+ "learning_rate": 1.9973477194427262e-06,
303
+ "loss": 1.2135,
304
+ "step": 210
305
+ },
306
+ {
307
+ "epoch": 0.3697334479793637,
308
+ "grad_norm": 0.3332583010196686,
309
+ "learning_rate": 1.996917333733128e-06,
310
+ "loss": 1.2553,
311
+ "step": 215
312
+ },
313
+ {
314
+ "epoch": 0.37833190025795355,
315
+ "grad_norm": 0.33345943689346313,
316
+ "learning_rate": 1.9964546571670053e-06,
317
+ "loss": 1.2652,
318
+ "step": 220
319
+ },
320
+ {
321
+ "epoch": 0.3869303525365434,
322
+ "grad_norm": 0.37145930528640747,
323
+ "learning_rate": 1.995959704730779e-06,
324
+ "loss": 1.1999,
325
+ "step": 225
326
+ },
327
+ {
328
+ "epoch": 0.39552880481513325,
329
+ "grad_norm": 0.41526567935943604,
330
+ "learning_rate": 1.9954324924563086e-06,
331
+ "loss": 1.3373,
332
+ "step": 230
333
+ },
334
+ {
335
+ "epoch": 0.4041272570937231,
336
+ "grad_norm": 0.2987145781517029,
337
+ "learning_rate": 1.9948730374203715e-06,
338
+ "loss": 1.2249,
339
+ "step": 235
340
+ },
341
+ {
342
+ "epoch": 0.412725709372313,
343
+ "grad_norm": 0.49898993968963623,
344
+ "learning_rate": 1.994281357744112e-06,
345
+ "loss": 1.2323,
346
+ "step": 240
347
+ },
348
+ {
349
+ "epoch": 0.42132416165090286,
350
+ "grad_norm": 0.2862403392791748,
351
+ "learning_rate": 1.9936574725924525e-06,
352
+ "loss": 1.1908,
353
+ "step": 245
354
+ },
355
+ {
356
+ "epoch": 0.4299226139294927,
357
+ "grad_norm": 0.31127598881721497,
358
+ "learning_rate": 1.9930014021734732e-06,
359
+ "loss": 1.3326,
360
+ "step": 250
361
+ },
362
+ {
363
+ "epoch": 0.43852106620808257,
364
+ "grad_norm": 0.44075530767440796,
365
+ "learning_rate": 1.9923131677377585e-06,
366
+ "loss": 1.1721,
367
+ "step": 255
368
+ },
369
+ {
370
+ "epoch": 0.4471195184866724,
371
+ "grad_norm": 0.29328110814094543,
372
+ "learning_rate": 1.991592791577708e-06,
373
+ "loss": 1.2735,
374
+ "step": 260
375
+ },
376
+ {
377
+ "epoch": 0.45571797076526227,
378
+ "grad_norm": 0.3364109396934509,
379
+ "learning_rate": 1.9908402970268145e-06,
380
+ "loss": 1.1244,
381
+ "step": 265
382
+ },
383
+ {
384
+ "epoch": 0.4643164230438521,
385
+ "grad_norm": 0.3128204047679901,
386
+ "learning_rate": 1.9900557084589077e-06,
387
+ "loss": 1.2281,
388
+ "step": 270
389
+ },
390
+ {
391
+ "epoch": 0.472914875322442,
392
+ "grad_norm": 0.30848929286003113,
393
+ "learning_rate": 1.989239051287366e-06,
394
+ "loss": 1.2333,
395
+ "step": 275
396
+ },
397
+ {
398
+ "epoch": 0.4815133276010318,
399
+ "grad_norm": 0.36058536171913147,
400
+ "learning_rate": 1.988390351964291e-06,
401
+ "loss": 1.2995,
402
+ "step": 280
403
+ },
404
+ {
405
+ "epoch": 0.4901117798796217,
406
+ "grad_norm": 0.3388177752494812,
407
+ "learning_rate": 1.9875096379796535e-06,
408
+ "loss": 1.3073,
409
+ "step": 285
410
+ },
411
+ {
412
+ "epoch": 0.49871023215821153,
413
+ "grad_norm": 0.3674142062664032,
414
+ "learning_rate": 1.986596937860402e-06,
415
+ "loss": 1.2673,
416
+ "step": 290
417
+ },
418
+ {
419
+ "epoch": 0.5073086844368013,
420
+ "grad_norm": 0.30132225155830383,
421
+ "learning_rate": 1.9856522811695374e-06,
422
+ "loss": 1.2107,
423
+ "step": 295
424
+ },
425
+ {
426
+ "epoch": 0.5159071367153912,
427
+ "grad_norm": 0.3170187473297119,
428
+ "learning_rate": 1.9846756985051573e-06,
429
+ "loss": 1.1624,
430
+ "step": 300
431
+ },
432
+ {
433
+ "epoch": 0.524505588993981,
434
+ "grad_norm": 0.3753427565097809,
435
+ "learning_rate": 1.9836672214994637e-06,
436
+ "loss": 1.2782,
437
+ "step": 305
438
+ },
439
+ {
440
+ "epoch": 0.5331040412725709,
441
+ "grad_norm": 0.36705997586250305,
442
+ "learning_rate": 1.9826268828177393e-06,
443
+ "loss": 1.134,
444
+ "step": 310
445
+ },
446
+ {
447
+ "epoch": 0.5417024935511608,
448
+ "grad_norm": 0.3330920338630676,
449
+ "learning_rate": 1.9815547161572892e-06,
450
+ "loss": 1.1611,
451
+ "step": 315
452
+ },
453
+ {
454
+ "epoch": 0.5503009458297506,
455
+ "grad_norm": 0.3084378242492676,
456
+ "learning_rate": 1.980450756246348e-06,
457
+ "loss": 1.2008,
458
+ "step": 320
459
+ },
460
+ {
461
+ "epoch": 0.5588993981083406,
462
+ "grad_norm": 0.3422742486000061,
463
+ "learning_rate": 1.979315038842957e-06,
464
+ "loss": 1.136,
465
+ "step": 325
466
+ },
467
+ {
468
+ "epoch": 0.5674978503869303,
469
+ "grad_norm": 0.4076729118824005,
470
+ "learning_rate": 1.9781476007338054e-06,
471
+ "loss": 1.179,
472
+ "step": 330
473
+ },
474
+ {
475
+ "epoch": 0.5760963026655203,
476
+ "grad_norm": 0.38809648156166077,
477
+ "learning_rate": 1.976948479733038e-06,
478
+ "loss": 1.1762,
479
+ "step": 335
480
+ },
481
+ {
482
+ "epoch": 0.58469475494411,
483
+ "grad_norm": 0.38286837935447693,
484
+ "learning_rate": 1.9757177146810307e-06,
485
+ "loss": 1.0976,
486
+ "step": 340
487
+ },
488
+ {
489
+ "epoch": 0.5932932072227,
490
+ "grad_norm": 0.33073902130126953,
491
+ "learning_rate": 1.9744553454431325e-06,
492
+ "loss": 1.1775,
493
+ "step": 345
494
+ },
495
+ {
496
+ "epoch": 0.6018916595012898,
497
+ "grad_norm": 0.30669665336608887,
498
+ "learning_rate": 1.9731614129083753e-06,
499
+ "loss": 1.1242,
500
+ "step": 350
501
+ },
502
+ {
503
+ "epoch": 0.6104901117798797,
504
+ "grad_norm": 0.36842820048332214,
505
+ "learning_rate": 1.9718359589881475e-06,
506
+ "loss": 1.233,
507
+ "step": 355
508
+ },
509
+ {
510
+ "epoch": 0.6190885640584695,
511
+ "grad_norm": 0.28934866189956665,
512
+ "learning_rate": 1.970479026614837e-06,
513
+ "loss": 1.0545,
514
+ "step": 360
515
+ },
516
+ {
517
+ "epoch": 0.6276870163370594,
518
+ "grad_norm": 0.36205312609672546,
519
+ "learning_rate": 1.9690906597404428e-06,
520
+ "loss": 1.0926,
521
+ "step": 365
522
+ },
523
+ {
524
+ "epoch": 0.6362854686156492,
525
+ "grad_norm": 0.39489033818244934,
526
+ "learning_rate": 1.967670903335148e-06,
527
+ "loss": 1.2244,
528
+ "step": 370
529
+ },
530
+ {
531
+ "epoch": 0.6448839208942391,
532
+ "grad_norm": 0.29848822951316833,
533
+ "learning_rate": 1.966219803385865e-06,
534
+ "loss": 1.1829,
535
+ "step": 375
536
+ },
537
+ {
538
+ "epoch": 0.6534823731728289,
539
+ "grad_norm": 0.31506502628326416,
540
+ "learning_rate": 1.9647374068947467e-06,
541
+ "loss": 1.1418,
542
+ "step": 380
543
+ },
544
+ {
545
+ "epoch": 0.6620808254514188,
546
+ "grad_norm": 0.39251357316970825,
547
+ "learning_rate": 1.963223761877662e-06,
548
+ "loss": 1.1543,
549
+ "step": 385
550
+ },
551
+ {
552
+ "epoch": 0.6706792777300086,
553
+ "grad_norm": 0.3380272686481476,
554
+ "learning_rate": 1.9616789173626418e-06,
555
+ "loss": 1.0856,
556
+ "step": 390
557
+ },
558
+ {
559
+ "epoch": 0.6792777300085985,
560
+ "grad_norm": 0.379609614610672,
561
+ "learning_rate": 1.960102923388291e-06,
562
+ "loss": 1.1562,
563
+ "step": 395
564
+ },
565
+ {
566
+ "epoch": 0.6878761822871883,
567
+ "grad_norm": 0.26444530487060547,
568
+ "learning_rate": 1.958495831002168e-06,
569
+ "loss": 1.1356,
570
+ "step": 400
571
+ },
572
+ {
573
+ "epoch": 0.6964746345657782,
574
+ "grad_norm": 0.4068126082420349,
575
+ "learning_rate": 1.9568576922591304e-06,
576
+ "loss": 1.2286,
577
+ "step": 405
578
+ },
579
+ {
580
+ "epoch": 0.705073086844368,
581
+ "grad_norm": 0.3288695514202118,
582
+ "learning_rate": 1.955188560219648e-06,
583
+ "loss": 1.206,
584
+ "step": 410
585
+ },
586
+ {
587
+ "epoch": 0.7136715391229579,
588
+ "grad_norm": 0.33392417430877686,
589
+ "learning_rate": 1.9534884889480876e-06,
590
+ "loss": 1.1944,
591
+ "step": 415
592
+ },
593
+ {
594
+ "epoch": 0.7222699914015477,
595
+ "grad_norm": 0.37305575609207153,
596
+ "learning_rate": 1.951757533510957e-06,
597
+ "loss": 1.204,
598
+ "step": 420
599
+ },
600
+ {
601
+ "epoch": 0.7308684436801376,
602
+ "grad_norm": 0.3695738911628723,
603
+ "learning_rate": 1.949995749975127e-06,
604
+ "loss": 1.1728,
605
+ "step": 425
606
+ },
607
+ {
608
+ "epoch": 0.7394668959587274,
609
+ "grad_norm": 0.37770697474479675,
610
+ "learning_rate": 1.948203195406009e-06,
611
+ "loss": 1.2171,
612
+ "step": 430
613
+ },
614
+ {
615
+ "epoch": 0.7480653482373173,
616
+ "grad_norm": 0.38213881850242615,
617
+ "learning_rate": 1.9463799278657124e-06,
618
+ "loss": 1.1948,
619
+ "step": 435
620
+ },
621
+ {
622
+ "epoch": 0.7566638005159071,
623
+ "grad_norm": 0.4096551239490509,
624
+ "learning_rate": 1.9445260064111607e-06,
625
+ "loss": 1.1774,
626
+ "step": 440
627
+ },
628
+ {
629
+ "epoch": 0.765262252794497,
630
+ "grad_norm": 0.41796615719795227,
631
+ "learning_rate": 1.9426414910921785e-06,
632
+ "loss": 1.1234,
633
+ "step": 445
634
+ },
635
+ {
636
+ "epoch": 0.7738607050730868,
637
+ "grad_norm": 0.3439182639122009,
638
+ "learning_rate": 1.9407264429495484e-06,
639
+ "loss": 1.1748,
640
+ "step": 450
641
+ },
642
+ {
643
+ "epoch": 0.7824591573516767,
644
+ "grad_norm": 0.34333643317222595,
645
+ "learning_rate": 1.938780924013032e-06,
646
+ "loss": 1.1441,
647
+ "step": 455
648
+ },
649
+ {
650
+ "epoch": 0.7910576096302665,
651
+ "grad_norm": 0.32014700770378113,
652
+ "learning_rate": 1.936804997299362e-06,
653
+ "loss": 1.1205,
654
+ "step": 460
655
+ },
656
+ {
657
+ "epoch": 0.7996560619088564,
658
+ "grad_norm": 0.3878689408302307,
659
+ "learning_rate": 1.9347987268101996e-06,
660
+ "loss": 1.1397,
661
+ "step": 465
662
+ },
663
+ {
664
+ "epoch": 0.8082545141874462,
665
+ "grad_norm": 0.3905511796474457,
666
+ "learning_rate": 1.9327621775300633e-06,
667
+ "loss": 1.1016,
668
+ "step": 470
669
+ },
670
+ {
671
+ "epoch": 0.8168529664660361,
672
+ "grad_norm": 0.3861243426799774,
673
+ "learning_rate": 1.9306954154242233e-06,
674
+ "loss": 1.0783,
675
+ "step": 475
676
+ },
677
+ {
678
+ "epoch": 0.825451418744626,
679
+ "grad_norm": 0.3234269618988037,
680
+ "learning_rate": 1.9285985074365627e-06,
681
+ "loss": 1.0694,
682
+ "step": 480
683
+ },
684
+ {
685
+ "epoch": 0.8340498710232158,
686
+ "grad_norm": 0.39914825558662415,
687
+ "learning_rate": 1.926471521487413e-06,
688
+ "loss": 1.2053,
689
+ "step": 485
690
+ },
691
+ {
692
+ "epoch": 0.8426483233018057,
693
+ "grad_norm": 0.39884087443351746,
694
+ "learning_rate": 1.924314526471351e-06,
695
+ "loss": 1.1663,
696
+ "step": 490
697
+ },
698
+ {
699
+ "epoch": 0.8512467755803955,
700
+ "grad_norm": 0.3793065547943115,
701
+ "learning_rate": 1.922127592254968e-06,
702
+ "loss": 1.083,
703
+ "step": 495
704
+ },
705
+ {
706
+ "epoch": 0.8598452278589854,
707
+ "grad_norm": 0.3194003403186798,
708
+ "learning_rate": 1.919910789674609e-06,
709
+ "loss": 1.0664,
710
+ "step": 500
711
+ },
712
+ {
713
+ "epoch": 0.8684436801375752,
714
+ "grad_norm": 0.30485859513282776,
715
+ "learning_rate": 1.917664190534075e-06,
716
+ "loss": 1.0426,
717
+ "step": 505
718
+ },
719
+ {
720
+ "epoch": 0.8770421324161651,
721
+ "grad_norm": 0.3151833117008209,
722
+ "learning_rate": 1.915387867602298e-06,
723
+ "loss": 1.157,
724
+ "step": 510
725
+ },
726
+ {
727
+ "epoch": 0.8856405846947549,
728
+ "grad_norm": 0.41206279397010803,
729
+ "learning_rate": 1.913081894610986e-06,
730
+ "loss": 1.1125,
731
+ "step": 515
732
+ },
733
+ {
734
+ "epoch": 0.8942390369733448,
735
+ "grad_norm": 0.42712071537971497,
736
+ "learning_rate": 1.9107463462522332e-06,
737
+ "loss": 0.9867,
738
+ "step": 520
739
+ },
740
+ {
741
+ "epoch": 0.9028374892519346,
742
+ "grad_norm": 0.45993658900260925,
743
+ "learning_rate": 1.9083812981760998e-06,
744
+ "loss": 1.2464,
745
+ "step": 525
746
+ },
747
+ {
748
+ "epoch": 0.9114359415305245,
749
+ "grad_norm": 0.34718605875968933,
750
+ "learning_rate": 1.9059868269881636e-06,
751
+ "loss": 1.0646,
752
+ "step": 530
753
+ },
754
+ {
755
+ "epoch": 0.9200343938091143,
756
+ "grad_norm": 0.4059743285179138,
757
+ "learning_rate": 1.9035630102470375e-06,
758
+ "loss": 1.08,
759
+ "step": 535
760
+ },
761
+ {
762
+ "epoch": 0.9286328460877042,
763
+ "grad_norm": 0.34420260787010193,
764
+ "learning_rate": 1.9011099264618573e-06,
765
+ "loss": 1.0843,
766
+ "step": 540
767
+ },
768
+ {
769
+ "epoch": 0.937231298366294,
770
+ "grad_norm": 0.36102572083473206,
771
+ "learning_rate": 1.89862765508974e-06,
772
+ "loss": 1.0874,
773
+ "step": 545
774
+ },
775
+ {
776
+ "epoch": 0.945829750644884,
777
+ "grad_norm": 0.4396149516105652,
778
+ "learning_rate": 1.896116276533208e-06,
779
+ "loss": 1.1614,
780
+ "step": 550
781
+ },
782
+ {
783
+ "epoch": 0.9544282029234737,
784
+ "grad_norm": 0.3992445170879364,
785
+ "learning_rate": 1.8935758721375862e-06,
786
+ "loss": 1.122,
787
+ "step": 555
788
+ },
789
+ {
790
+ "epoch": 0.9630266552020637,
791
+ "grad_norm": 0.3218730092048645,
792
+ "learning_rate": 1.8910065241883678e-06,
793
+ "loss": 0.9754,
794
+ "step": 560
795
+ },
796
+ {
797
+ "epoch": 0.9716251074806534,
798
+ "grad_norm": 0.3818008601665497,
799
+ "learning_rate": 1.8884083159085468e-06,
800
+ "loss": 1.1747,
801
+ "step": 565
802
+ },
803
+ {
804
+ "epoch": 0.9802235597592434,
805
+ "grad_norm": 0.407429575920105,
806
+ "learning_rate": 1.8857813314559254e-06,
807
+ "loss": 1.1048,
808
+ "step": 570
809
+ },
810
+ {
811
+ "epoch": 0.9888220120378332,
812
+ "grad_norm": 0.4260193407535553,
813
+ "learning_rate": 1.8831256559203843e-06,
814
+ "loss": 1.1217,
815
+ "step": 575
816
+ },
817
+ {
818
+ "epoch": 0.9974204643164231,
819
+ "grad_norm": 0.3930356204509735,
820
+ "learning_rate": 1.8804413753211304e-06,
821
+ "loss": 1.1259,
822
+ "step": 580
823
+ },
824
+ {
825
+ "epoch": 1.0051590713671539,
826
+ "grad_norm": 0.3557448983192444,
827
+ "learning_rate": 1.8777285766039075e-06,
828
+ "loss": 1.1636,
829
+ "step": 585
830
+ },
831
+ {
832
+ "epoch": 1.0137575236457437,
833
+ "grad_norm": 0.34454646706581116,
834
+ "learning_rate": 1.8749873476381826e-06,
835
+ "loss": 1.093,
836
+ "step": 590
837
+ },
838
+ {
839
+ "epoch": 1.0223559759243337,
840
+ "grad_norm": 0.4703282415866852,
841
+ "learning_rate": 1.8722177772142973e-06,
842
+ "loss": 1.0716,
843
+ "step": 595
844
+ },
845
+ {
846
+ "epoch": 1.0309544282029235,
847
+ "grad_norm": 0.418491929769516,
848
+ "learning_rate": 1.8694199550405942e-06,
849
+ "loss": 1.0626,
850
+ "step": 600
851
+ }
852
+ ],
853
+ "logging_steps": 5,
854
+ "max_steps": 2905,
855
+ "num_input_tokens_seen": 0,
856
+ "num_train_epochs": 5,
857
+ "save_steps": 50,
858
+ "stateful_callbacks": {
859
+ "TrainerControl": {
860
+ "args": {
861
+ "should_epoch_stop": false,
862
+ "should_evaluate": false,
863
+ "should_log": false,
864
+ "should_save": true,
865
+ "should_training_stop": false
866
+ },
867
+ "attributes": {}
868
+ }
869
+ },
870
+ "total_flos": 1.4341188063131075e+18,
871
+ "train_batch_size": 8,
872
+ "trial_name": null,
873
+ "trial_params": null
874
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc08ca78b1b85a05419bb60ccf59304233558785fc7d6c7ac2b94b1b45d61f82
3
+ size 8376
zero_to_fp32.py ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example:
14
+ # python zero_to_fp32.py . output_dir/
15
+ # or
16
+ # python zero_to_fp32.py . output_dir/ --safe_serialization
17
+
18
+ import argparse
19
+ import torch
20
+ import glob
21
+ import math
22
+ import os
23
+ import re
24
+ import json
25
+ from tqdm import tqdm
26
+ from collections import OrderedDict
27
+ from dataclasses import dataclass
28
+
29
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
30
+ # DeepSpeed data structures it has to be available in the current python environment.
31
+ from deepspeed.utils import logger
32
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
33
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
34
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
35
+
36
+
37
+ @dataclass
38
+ class zero_model_state:
39
+ buffers: dict()
40
+ param_shapes: dict()
41
+ shared_params: list
42
+ ds_version: int
43
+ frozen_param_shapes: dict()
44
+ frozen_param_fragments: dict()
45
+
46
+
47
+ debug = 0
48
+
49
+ # load to cpu
50
+ device = torch.device('cpu')
51
+
52
+
53
+ def atoi(text):
54
+ return int(text) if text.isdigit() else text
55
+
56
+
57
+ def natural_keys(text):
58
+ '''
59
+ alist.sort(key=natural_keys) sorts in human order
60
+ http://nedbatchelder.com/blog/200712/human_sorting.html
61
+ (See Toothy's implementation in the comments)
62
+ '''
63
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
64
+
65
+
66
+ def get_model_state_file(checkpoint_dir, zero_stage):
67
+ if not os.path.isdir(checkpoint_dir):
68
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
69
+
70
+ # there should be only one file
71
+ if zero_stage <= 2:
72
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
73
+ elif zero_stage == 3:
74
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
75
+
76
+ if not os.path.exists(file):
77
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
78
+
79
+ return file
80
+
81
+
82
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
83
+ # XXX: need to test that this simple glob rule works for multi-node setup too
84
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
85
+
86
+ if len(ckpt_files) == 0:
87
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
88
+
89
+ return ckpt_files
90
+
91
+
92
+ def get_optim_files(checkpoint_dir):
93
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
94
+
95
+
96
+ def get_model_state_files(checkpoint_dir):
97
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
98
+
99
+
100
+ def parse_model_states(files):
101
+ zero_model_states = []
102
+ for file in files:
103
+ state_dict = torch.load(file, map_location=device)
104
+
105
+ if BUFFER_NAMES not in state_dict:
106
+ raise ValueError(f"{file} is not a model state checkpoint")
107
+ buffer_names = state_dict[BUFFER_NAMES]
108
+ if debug:
109
+ print("Found buffers:", buffer_names)
110
+
111
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
112
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
113
+ param_shapes = state_dict[PARAM_SHAPES]
114
+
115
+ # collect parameters that are included in param_shapes
116
+ param_names = []
117
+ for s in param_shapes:
118
+ for name in s.keys():
119
+ param_names.append(name)
120
+
121
+ # update with frozen parameters
122
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
123
+ if frozen_param_shapes is not None:
124
+ if debug:
125
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
126
+ param_names += list(frozen_param_shapes.keys())
127
+
128
+ # handle shared params
129
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
130
+
131
+ ds_version = state_dict.get(DS_VERSION, None)
132
+
133
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
134
+
135
+ z_model_state = zero_model_state(buffers=buffers,
136
+ param_shapes=param_shapes,
137
+ shared_params=shared_params,
138
+ ds_version=ds_version,
139
+ frozen_param_shapes=frozen_param_shapes,
140
+ frozen_param_fragments=frozen_param_fragments)
141
+ zero_model_states.append(z_model_state)
142
+
143
+ return zero_model_states
144
+
145
+
146
+ def parse_optim_states(files, ds_checkpoint_dir):
147
+ total_files = len(files)
148
+ state_dicts = []
149
+ for f in files:
150
+ state_dict = torch.load(f, map_location=device)
151
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
152
+ # and also handle the case where it was already removed by another helper script
153
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
154
+ state_dicts.append(state_dict)
155
+
156
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
157
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
158
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
159
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
160
+
161
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
162
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
163
+ # use the max of the partition_count to get the dp world_size.
164
+
165
+ if type(world_size) is list:
166
+ world_size = max(world_size)
167
+
168
+ if world_size != total_files:
169
+ raise ValueError(
170
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
171
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
172
+ )
173
+
174
+ # the groups are named differently in each stage
175
+ if zero_stage <= 2:
176
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
177
+ elif zero_stage == 3:
178
+ fp32_groups_key = FP32_FLAT_GROUPS
179
+ else:
180
+ raise ValueError(f"unknown zero stage {zero_stage}")
181
+
182
+ if zero_stage <= 2:
183
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
184
+ elif zero_stage == 3:
185
+ # if there is more than one param group, there will be multiple flattened tensors - one
186
+ # flattened tensor per group - for simplicity merge them into a single tensor
187
+ #
188
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
189
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
190
+
191
+ fp32_flat_groups = [
192
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
193
+ ]
194
+
195
+ return zero_stage, world_size, fp32_flat_groups
196
+
197
+
198
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
199
+ """
200
+ Returns fp32 state_dict reconstructed from ds checkpoint
201
+
202
+ Args:
203
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
204
+
205
+ """
206
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
207
+
208
+ optim_files = get_optim_files(ds_checkpoint_dir)
209
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
210
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
211
+
212
+ model_files = get_model_state_files(ds_checkpoint_dir)
213
+
214
+ zero_model_states = parse_model_states(model_files)
215
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
216
+
217
+ if zero_stage <= 2:
218
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
219
+ exclude_frozen_parameters)
220
+ elif zero_stage == 3:
221
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
222
+ exclude_frozen_parameters)
223
+
224
+
225
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
226
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
227
+ return
228
+
229
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
230
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
231
+
232
+ if debug:
233
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
234
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
235
+
236
+ wanted_params = len(frozen_param_shapes)
237
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
238
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
239
+ print(f'Frozen params: Have {avail_numel} numels to process.')
240
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
241
+
242
+ total_params = 0
243
+ total_numel = 0
244
+ for name, shape in frozen_param_shapes.items():
245
+ total_params += 1
246
+ unpartitioned_numel = shape.numel()
247
+ total_numel += unpartitioned_numel
248
+
249
+ state_dict[name] = frozen_param_fragments[name]
250
+
251
+ if debug:
252
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
253
+
254
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
255
+
256
+
257
+ def _has_callable(obj, fn):
258
+ attr = getattr(obj, fn, None)
259
+ return callable(attr)
260
+
261
+
262
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
263
+ param_shapes = zero_model_states[0].param_shapes
264
+
265
+ # Reconstruction protocol:
266
+ #
267
+ # XXX: document this
268
+
269
+ if debug:
270
+ for i in range(world_size):
271
+ for j in range(len(fp32_flat_groups[0])):
272
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
273
+
274
+ # XXX: memory usage doubles here (zero2)
275
+ num_param_groups = len(fp32_flat_groups[0])
276
+ merged_single_partition_of_fp32_groups = []
277
+ for i in range(num_param_groups):
278
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
279
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
280
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
281
+ avail_numel = sum(
282
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
283
+
284
+ if debug:
285
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
286
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
287
+ # not asserting if there is a mismatch due to possible padding
288
+ print(f"Have {avail_numel} numels to process.")
289
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
290
+
291
+ # params
292
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
293
+ # out-of-core computing solution
294
+ total_numel = 0
295
+ total_params = 0
296
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
297
+ offset = 0
298
+ avail_numel = full_single_fp32_vector.numel()
299
+ for name, shape in shapes.items():
300
+
301
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
302
+ total_numel += unpartitioned_numel
303
+ total_params += 1
304
+
305
+ if debug:
306
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
307
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
308
+ offset += unpartitioned_numel
309
+
310
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
311
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
312
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
313
+ # live optimizer object, so we are checking that the numbers are within the right range
314
+ align_to = 2 * world_size
315
+
316
+ def zero2_align(x):
317
+ return align_to * math.ceil(x / align_to)
318
+
319
+ if debug:
320
+ print(f"original offset={offset}, avail_numel={avail_numel}")
321
+
322
+ offset = zero2_align(offset)
323
+ avail_numel = zero2_align(avail_numel)
324
+
325
+ if debug:
326
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
327
+
328
+ # Sanity check
329
+ if offset != avail_numel:
330
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
331
+
332
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
333
+
334
+
335
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
336
+ exclude_frozen_parameters):
337
+ state_dict = OrderedDict()
338
+
339
+ # buffers
340
+ buffers = zero_model_states[0].buffers
341
+ state_dict.update(buffers)
342
+ if debug:
343
+ print(f"added {len(buffers)} buffers")
344
+
345
+ if not exclude_frozen_parameters:
346
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
347
+
348
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
349
+
350
+ # recover shared parameters
351
+ for pair in zero_model_states[0].shared_params:
352
+ if pair[1] in state_dict:
353
+ state_dict[pair[0]] = state_dict[pair[1]]
354
+
355
+ return state_dict
356
+
357
+
358
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
359
+ remainder = unpartitioned_numel % world_size
360
+ padding_numel = (world_size - remainder) if remainder else 0
361
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
362
+ return partitioned_numel, padding_numel
363
+
364
+
365
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
366
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
367
+ return
368
+
369
+ if debug:
370
+ for i in range(world_size):
371
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
372
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
373
+
374
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
375
+ wanted_params = len(frozen_param_shapes)
376
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
377
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
378
+ print(f'Frozen params: Have {avail_numel} numels to process.')
379
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
380
+
381
+ total_params = 0
382
+ total_numel = 0
383
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
384
+ total_params += 1
385
+ unpartitioned_numel = shape.numel()
386
+ total_numel += unpartitioned_numel
387
+
388
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
389
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
390
+
391
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
392
+
393
+ if debug:
394
+ print(
395
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
396
+ )
397
+
398
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
399
+
400
+
401
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
402
+ param_shapes = zero_model_states[0].param_shapes
403
+ avail_numel = fp32_flat_groups[0].numel() * world_size
404
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
405
+ # param, re-consolidating each param, while dealing with padding if any
406
+
407
+ # merge list of dicts, preserving order
408
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
409
+
410
+ if debug:
411
+ for i in range(world_size):
412
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
413
+
414
+ wanted_params = len(param_shapes)
415
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
416
+ # not asserting if there is a mismatch due to possible padding
417
+ avail_numel = fp32_flat_groups[0].numel() * world_size
418
+ print(f"Trainable params: Have {avail_numel} numels to process.")
419
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
420
+
421
+ # params
422
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
423
+ # out-of-core computing solution
424
+ offset = 0
425
+ total_numel = 0
426
+ total_params = 0
427
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering Sharded Weights'):
428
+ unpartitioned_numel = shape.numel()
429
+ total_numel += unpartitioned_numel
430
+ total_params += 1
431
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
432
+
433
+ if debug:
434
+ print(
435
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
436
+ )
437
+
438
+ # XXX: memory usage doubles here
439
+ state_dict[name] = torch.cat(
440
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
441
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
442
+ offset += partitioned_numel
443
+
444
+ offset *= world_size
445
+
446
+ # Sanity check
447
+ if offset != avail_numel:
448
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
449
+
450
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
451
+
452
+
453
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
454
+ exclude_frozen_parameters):
455
+ state_dict = OrderedDict()
456
+
457
+ # buffers
458
+ buffers = zero_model_states[0].buffers
459
+ state_dict.update(buffers)
460
+ if debug:
461
+ print(f"added {len(buffers)} buffers")
462
+
463
+ if not exclude_frozen_parameters:
464
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
465
+
466
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
467
+
468
+ # recover shared parameters
469
+ for pair in zero_model_states[0].shared_params:
470
+ if pair[1] in state_dict:
471
+ state_dict[pair[0]] = state_dict[pair[1]]
472
+
473
+ return state_dict
474
+
475
+
476
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
477
+ """
478
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
479
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
480
+ via a model hub.
481
+
482
+ Args:
483
+ - ``checkpoint_dir``: path to the desired checkpoint folder
484
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
485
+ - ``exclude_frozen_parameters``: exclude frozen parameters
486
+
487
+ Returns:
488
+ - pytorch ``state_dict``
489
+
490
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
491
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
492
+ the checkpoint.
493
+
494
+ A typical usage might be ::
495
+
496
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
497
+ # do the training and checkpoint saving
498
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
499
+ model = model.cpu() # move to cpu
500
+ model.load_state_dict(state_dict)
501
+ # submit to model hub or save the model to share with others
502
+
503
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
504
+ application. i.e. you will need to re-initialize the deepspeed engine, since
505
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
506
+
507
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
508
+
509
+ """
510
+ if tag is None:
511
+ latest_path = os.path.join(checkpoint_dir, 'latest')
512
+ if os.path.isfile(latest_path):
513
+ with open(latest_path, 'r') as fd:
514
+ tag = fd.read().strip()
515
+ else:
516
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
517
+
518
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
519
+
520
+ if not os.path.isdir(ds_checkpoint_dir):
521
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
522
+
523
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
524
+
525
+
526
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
527
+ output_dir,
528
+ max_shard_size="5GB",
529
+ safe_serialization=False,
530
+ tag=None,
531
+ exclude_frozen_parameters=False):
532
+ """
533
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
534
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
535
+
536
+ Args:
537
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
538
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
539
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
540
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
541
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
542
+ - ``exclude_frozen_parameters``: exclude frozen parameters
543
+ """
544
+ # Dependency pre-check
545
+ if safe_serialization:
546
+ try:
547
+ from safetensors.torch import save_file
548
+ except ImportError:
549
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
550
+ raise
551
+ if max_shard_size is not None:
552
+ try:
553
+ from huggingface_hub import split_torch_state_dict_into_shards
554
+ except ImportError:
555
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
556
+ raise
557
+
558
+ # Convert zero checkpoint to state_dict
559
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
560
+
561
+ # Shard the model if it is too big.
562
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
563
+ if max_shard_size is not None:
564
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
565
+ state_dict_split = split_torch_state_dict_into_shards(state_dict,
566
+ filename_pattern=filename_pattern,
567
+ max_shard_size=max_shard_size)
568
+ else:
569
+ from collections import namedtuple
570
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
571
+ state_dict_split = StateDictSplit(is_sharded=False,
572
+ filename_to_tensors={weights_name: list(state_dict.keys())})
573
+
574
+ # Save the model
575
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
576
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
577
+ shard = {tensor: state_dict[tensor].contiguous() for tensor in tensors}
578
+ output_path = os.path.join(output_dir, shard_file)
579
+ if safe_serialization:
580
+ save_file(shard, output_path, metadata={"format": "pt"})
581
+ else:
582
+ torch.save(shard, output_path)
583
+
584
+ # Save index if sharded
585
+ if state_dict_split.is_sharded:
586
+ index = {
587
+ "metadata": state_dict_split.metadata,
588
+ "weight_map": state_dict_split.tensor_to_filename,
589
+ }
590
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
591
+ save_index_file = os.path.join(output_dir, save_index_file)
592
+ with open(save_index_file, "w", encoding="utf-8") as f:
593
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
594
+ f.write(content)
595
+
596
+
597
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
598
+ """
599
+ 1. Put the provided model to cpu
600
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
601
+ 3. Load it into the provided model
602
+
603
+ Args:
604
+ - ``model``: the model object to update
605
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
606
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
607
+
608
+ Returns:
609
+ - ``model`: modified model
610
+
611
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
612
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
613
+ conveniently placed for you in the checkpoint folder.
614
+
615
+ A typical usage might be ::
616
+
617
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
618
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
619
+ # submit to model hub or save the model to share with others
620
+
621
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
622
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
623
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
624
+
625
+ """
626
+ logger.info(f"Extracting fp32 weights")
627
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
628
+
629
+ logger.info(f"Overwriting model with fp32 weights")
630
+ model = model.cpu()
631
+ model.load_state_dict(state_dict, strict=False)
632
+
633
+ return model
634
+
635
+
636
+ if __name__ == "__main__":
637
+ parser = argparse.ArgumentParser()
638
+ parser.add_argument("checkpoint_dir",
639
+ type=str,
640
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
641
+ parser.add_argument("output_dir",
642
+ type=str,
643
+ help="directory to the pytorch fp32 state_dict output files"
644
+ "(e.g. path/checkpoint-12-output/)")
645
+ parser.add_argument(
646
+ "--max_shard_size",
647
+ type=str,
648
+ default="5GB",
649
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
650
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
651
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
652
+ "without CPU OOM issues.")
653
+ parser.add_argument(
654
+ "--safe_serialization",
655
+ default=False,
656
+ action='store_true',
657
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
658
+ parser.add_argument("-t",
659
+ "--tag",
660
+ type=str,
661
+ default=None,
662
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
663
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
664
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
665
+ args = parser.parse_args()
666
+
667
+ debug = args.debug
668
+
669
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
670
+ args.output_dir,
671
+ max_shard_size=args.max_shard_size,
672
+ safe_serialization=args.safe_serialization,
673
+ tag=args.tag,
674
+ exclude_frozen_parameters=args.exclude_frozen_parameters)