dvdmrs09 commited on
Commit
e6cab78
·
verified ·
1 Parent(s): 510cb57

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. README.md +144 -0
  3. adapter_config.json +33 -0
  4. adapter_model.bin +3 -0
  5. checkpoint-110/README.md +202 -0
  6. checkpoint-110/adapter_config.json +33 -0
  7. checkpoint-110/adapter_model.safetensors +3 -0
  8. checkpoint-110/global_step110/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
  9. checkpoint-110/global_step110/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt +3 -0
  10. checkpoint-110/global_step110/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt +3 -0
  11. checkpoint-110/global_step110/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt +3 -0
  12. checkpoint-110/global_step110/mp_rank_00_model_states.pt +3 -0
  13. checkpoint-110/latest +1 -0
  14. checkpoint-110/rng_state_0.pth +3 -0
  15. checkpoint-110/rng_state_1.pth +3 -0
  16. checkpoint-110/rng_state_2.pth +3 -0
  17. checkpoint-110/rng_state_3.pth +3 -0
  18. checkpoint-110/scheduler.pt +3 -0
  19. checkpoint-110/trainer_state.json +855 -0
  20. checkpoint-110/training_args.bin +3 -0
  21. checkpoint-110/zero_to_fp32.py +592 -0
  22. checkpoint-46/README.md +202 -0
  23. checkpoint-46/adapter_config.json +33 -0
  24. checkpoint-46/adapter_model.safetensors +3 -0
  25. checkpoint-46/global_step46/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
  26. checkpoint-46/global_step46/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt +3 -0
  27. checkpoint-46/global_step46/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt +3 -0
  28. checkpoint-46/global_step46/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt +3 -0
  29. checkpoint-46/global_step46/mp_rank_00_model_states.pt +3 -0
  30. checkpoint-46/latest +1 -0
  31. checkpoint-46/rng_state_0.pth +3 -0
  32. checkpoint-46/rng_state_1.pth +3 -0
  33. checkpoint-46/rng_state_2.pth +3 -0
  34. checkpoint-46/rng_state_3.pth +3 -0
  35. checkpoint-46/scheduler.pt +3 -0
  36. checkpoint-46/trainer_state.json +375 -0
  37. checkpoint-46/training_args.bin +3 -0
  38. checkpoint-46/zero_to_fp32.py +592 -0
  39. checkpoint-55/README.md +202 -0
  40. checkpoint-55/adapter_config.json +33 -0
  41. checkpoint-55/adapter_model.safetensors +3 -0
  42. checkpoint-55/global_step55/bf16_zero_pp_rank_0_mp_rank_00_optim_states.pt +3 -0
  43. checkpoint-55/global_step55/bf16_zero_pp_rank_1_mp_rank_00_optim_states.pt +3 -0
  44. checkpoint-55/global_step55/bf16_zero_pp_rank_2_mp_rank_00_optim_states.pt +3 -0
  45. checkpoint-55/global_step55/bf16_zero_pp_rank_3_mp_rank_00_optim_states.pt +3 -0
  46. checkpoint-55/global_step55/mp_rank_00_model_states.pt +3 -0
  47. checkpoint-55/latest +1 -0
  48. checkpoint-55/rng_state_0.pth +3 -0
  49. checkpoint-55/rng_state_1.pth +3 -0
  50. checkpoint-55/rng_state_2.pth +3 -0
.gitattributes CHANGED
@@ -33,3 +33,5 @@ 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
+ merged/tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ library_name: peft
4
+ tags:
5
+ - generated_from_trainer
6
+ base_model: google/gemma-2b-it
7
+ model-index:
8
+ - name: peft-gemma2b
9
+ results: []
10
+ ---
11
+
12
+
13
+ [<img src="https://raw.githubusercontent.com/OpenAccess-AI-Collective/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/OpenAccess-AI-Collective/axolotl)
14
+ <details><summary>See axolotl config</summary>
15
+
16
+ axolotl version: `0.4.0`
17
+ ```yaml
18
+ # use google/gemma-7b if you have access
19
+ base_model: google/gemma-2b-it
20
+ model_type: AutoModelForCausalLM
21
+ tokenizer_type: AutoTokenizer
22
+
23
+ load_in_8bit: false
24
+ load_in_4bit: true
25
+ strict: false
26
+
27
+ # huggingface repo
28
+ datasets:
29
+ - path: ./python-oasst/combined_chunk_2.jsonl
30
+ type: oasst
31
+ val_set_size: 0.40
32
+ output_dir: ./out3
33
+
34
+ adapter: qlora
35
+ lora_r: 32
36
+ lora_alpha: 16
37
+ lora_dropout: 0.05
38
+ lora_target_linear: true
39
+
40
+ sequence_len: 4096
41
+ sample_packing: true
42
+ pad_to_sequence_len: true
43
+
44
+ wandb_project: gemma-2b-it
45
+ wandb_entity:
46
+ wandb_watch:
47
+ wandb_name:
48
+ wandb_log_model:
49
+
50
+
51
+ gradient_accumulation_steps: 3
52
+ micro_batch_size: 4
53
+ num_epochs: 2
54
+ optimizer: adamw_bnb_8bit
55
+ lr_scheduler: cosine
56
+ learning_rate: 0.0002
57
+
58
+ train_on_inputs: true
59
+ group_by_length: false
60
+ bf16: auto
61
+ fp16:
62
+ tf32: false
63
+
64
+ gradient_checkpointing: true
65
+ early_stopping_patience:
66
+ resume_from_checkpoint:
67
+ local_rank:
68
+ logging_steps: 1
69
+ xformers_attention:
70
+ flash_attention: true
71
+
72
+ warmup_ratio: 0.1
73
+ evals_per_epoch: 4
74
+ eval_table_size:
75
+ eval_max_new_tokens: 256
76
+ saves_per_epoch: 1
77
+ debug:
78
+ deepspeed: deepspeed_configs/zero1.json
79
+ weight_decay: 0.0
80
+ fsdp:
81
+ fsdp_config:
82
+ special_tokens:
83
+
84
+ ```
85
+
86
+ </details><br>
87
+
88
+ # out3
89
+
90
+ This model is a fine-tuned version of [google/gemma-2b-it](https://huggingface.co/google/gemma-2b-it) on the None dataset.
91
+ It achieves the following results on the evaluation set:
92
+ - Loss: 1.2430
93
+
94
+ ## Model description
95
+
96
+ More information needed
97
+
98
+ ## Intended uses & limitations
99
+
100
+ More information needed
101
+
102
+ ## Training and evaluation data
103
+
104
+ More information needed
105
+
106
+ ## Training procedure
107
+
108
+ ### Training hyperparameters
109
+
110
+ The following hyperparameters were used during training:
111
+ - learning_rate: 0.0002
112
+ - train_batch_size: 4
113
+ - eval_batch_size: 4
114
+ - seed: 42
115
+ - distributed_type: multi-GPU
116
+ - num_devices: 4
117
+ - gradient_accumulation_steps: 3
118
+ - total_train_batch_size: 48
119
+ - total_eval_batch_size: 16
120
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
121
+ - lr_scheduler_type: cosine
122
+ - num_epochs: 2
123
+
124
+ ### Training results
125
+
126
+ | Training Loss | Epoch | Step | Validation Loss |
127
+ |:-------------:|:-----:|:----:|:---------------:|
128
+ | 2.8926 | 0.02 | 1 | 2.7617 |
129
+ | 1.4502 | 0.26 | 12 | 1.4564 |
130
+ | 1.7617 | 0.52 | 24 | 1.3147 |
131
+ | 1.2051 | 0.78 | 36 | 1.2781 |
132
+ | 1.1353 | 1.01 | 48 | 1.2603 |
133
+ | 1.1787 | 1.28 | 60 | 1.2498 |
134
+ | 1.1416 | 1.54 | 72 | 1.2445 |
135
+ | 1.1606 | 1.8 | 84 | 1.2430 |
136
+
137
+
138
+ ### Framework versions
139
+
140
+ - PEFT 0.9.0
141
+ - Transformers 4.38.0
142
+ - Pytorch 2.0.1+cu117
143
+ - Datasets 2.18.0
144
+ - Tokenizers 0.15.0
adapter_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "google/gemma-2b-it",
5
+ "bias": "none",
6
+ "fan_in_fan_out": null,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layers_pattern": null,
10
+ "layers_to_transform": null,
11
+ "loftq_config": {},
12
+ "lora_alpha": 16,
13
+ "lora_dropout": 0.05,
14
+ "megatron_config": null,
15
+ "megatron_core": "megatron.core",
16
+ "modules_to_save": null,
17
+ "peft_type": "LORA",
18
+ "r": 32,
19
+ "rank_pattern": {},
20
+ "revision": null,
21
+ "target_modules": [
22
+ "gate_proj",
23
+ "k_proj",
24
+ "v_proj",
25
+ "up_proj",
26
+ "down_proj",
27
+ "o_proj",
28
+ "q_proj"
29
+ ],
30
+ "task_type": "CAUSAL_LM",
31
+ "use_dora": false,
32
+ "use_rslora": false
33
+ }
adapter_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7588baf2279a9decd1ae4ab0c5f6a03a9c05266fb6133696bade5771b733b19
3
+ size 78486205
checkpoint-110/README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ base_model: google/gemma-2b-it
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.9.0
checkpoint-110/adapter_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "google/gemma-2b-it",
5
+ "bias": "none",
6
+ "fan_in_fan_out": null,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layers_pattern": null,
10
+ "layers_to_transform": null,
11
+ "loftq_config": {},
12
+ "lora_alpha": 16,
13
+ "lora_dropout": 0.05,
14
+ "megatron_config": null,
15
+ "megatron_core": "megatron.core",
16
+ "modules_to_save": null,
17
+ "peft_type": "LORA",
18
+ "r": 32,
19
+ "rank_pattern": {},
20
+ "revision": null,
21
+ "target_modules": [
22
+ "down_proj",
23
+ "k_proj",
24
+ "up_proj",
25
+ "q_proj",
26
+ "v_proj",
27
+ "o_proj",
28
+ "gate_proj"
29
+ ],
30
+ "task_type": "CAUSAL_LM",
31
+ "use_dora": false,
32
+ "use_rslora": false
33
+ }
checkpoint-110/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:808d55cfc0779724020543b0b6f2b69c829ed1a3d5efff889a6f890b8c1139be
3
+ size 78480320
checkpoint-110/global_step110/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:747fb75ccb5a8b04441e183ba81925e338ded294ffbc1e5180c578f13a693e8a
3
+ size 58886423
checkpoint-110/global_step110/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:f22f475db28959ac7679e36700754b955b7f57f0fcf514207b849ed6030ee1ea
3
+ size 58885463
checkpoint-110/global_step110/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:ea14779c099ee005ae1008ea80a4b0899c5154638318f569dc3d41ff21901e46
3
+ size 58886487
checkpoint-110/global_step110/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:939d4da58aa1f75a5c89110a76ec68e3e6badd2ef184d7382afa3dead722fbcb
3
+ size 58885527
checkpoint-110/global_step110/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3da1e771f664c7850a57b8954bc62cf37a8d56bbb7db3bfbc65c349981318c43
3
+ size 1159049457
checkpoint-110/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step110
checkpoint-110/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:24089072fa967ddda688610baf8c506a25f5771b731a9a05c0736c8a961273a7
3
+ size 17655
checkpoint-110/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:afe5f6f9755fd1245cedc10989cb0b4bb48aae05f1ccde8e9deb44e36aebc69b
3
+ size 17655
checkpoint-110/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4e38510525d2854bf2b886708e15173236a90931480e673b0f69f8d620d8bf7
3
+ size 17655
checkpoint-110/rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:53876e4b015161dc8aaad7580a291ce19694f401e74bf98e8ea9b34a5b8866a2
3
+ size 17655
checkpoint-110/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2fb173f58bc277f4540a71b9da714b6eab4897199fe96d39e8ced237b9480a43
3
+ size 627
checkpoint-110/trainer_state.json ADDED
@@ -0,0 +1,855 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 1.9520958083832336,
5
+ "eval_steps": 14,
6
+ "global_step": 110,
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.02,
13
+ "grad_norm": 0.866426735610868,
14
+ "learning_rate": 0.00019995921928281894,
15
+ "loss": 2.7031,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.02,
20
+ "eval_loss": 2.6663479804992676,
21
+ "eval_runtime": 69.9146,
22
+ "eval_samples_per_second": 285.62,
23
+ "eval_steps_per_second": 17.865,
24
+ "step": 1
25
+ },
26
+ {
27
+ "epoch": 0.04,
28
+ "grad_norm": 0.8776710816784347,
29
+ "learning_rate": 0.00019983691039261357,
30
+ "loss": 2.6299,
31
+ "step": 2
32
+ },
33
+ {
34
+ "epoch": 0.05,
35
+ "grad_norm": 0.9796444288699809,
36
+ "learning_rate": 0.00019963317308626914,
37
+ "loss": 2.3027,
38
+ "step": 3
39
+ },
40
+ {
41
+ "epoch": 0.07,
42
+ "grad_norm": 1.1160859766420685,
43
+ "learning_rate": 0.00019934817353485501,
44
+ "loss": 2.0674,
45
+ "step": 4
46
+ },
47
+ {
48
+ "epoch": 0.09,
49
+ "grad_norm": 1.1551321141536093,
50
+ "learning_rate": 0.0001989821441880933,
51
+ "loss": 1.7861,
52
+ "step": 5
53
+ },
54
+ {
55
+ "epoch": 0.11,
56
+ "grad_norm": 0.890274648186441,
57
+ "learning_rate": 0.00019853538358476932,
58
+ "loss": 1.6172,
59
+ "step": 6
60
+ },
61
+ {
62
+ "epoch": 0.13,
63
+ "grad_norm": 0.7807325938639237,
64
+ "learning_rate": 0.00019800825610923934,
65
+ "loss": 1.6323,
66
+ "step": 7
67
+ },
68
+ {
69
+ "epoch": 0.14,
70
+ "grad_norm": 0.7513090074948452,
71
+ "learning_rate": 0.00019740119169423337,
72
+ "loss": 1.6172,
73
+ "step": 8
74
+ },
75
+ {
76
+ "epoch": 0.16,
77
+ "grad_norm": 0.6817700063779598,
78
+ "learning_rate": 0.00019671468547019573,
79
+ "loss": 1.5483,
80
+ "step": 9
81
+ },
82
+ {
83
+ "epoch": 0.18,
84
+ "grad_norm": 0.5485445966786001,
85
+ "learning_rate": 0.00019594929736144976,
86
+ "loss": 1.479,
87
+ "step": 10
88
+ },
89
+ {
90
+ "epoch": 0.2,
91
+ "grad_norm": 0.27041496308401886,
92
+ "learning_rate": 0.00019510565162951537,
93
+ "loss": 1.4292,
94
+ "step": 11
95
+ },
96
+ {
97
+ "epoch": 0.22,
98
+ "grad_norm": 0.24844480119928905,
99
+ "learning_rate": 0.00019418443636395248,
100
+ "loss": 1.4326,
101
+ "step": 12
102
+ },
103
+ {
104
+ "epoch": 0.23,
105
+ "grad_norm": 0.4516773777333339,
106
+ "learning_rate": 0.00019318640292114524,
107
+ "loss": 1.418,
108
+ "step": 13
109
+ },
110
+ {
111
+ "epoch": 0.25,
112
+ "grad_norm": 2.014260828449999,
113
+ "learning_rate": 0.000192112365311485,
114
+ "loss": 1.9883,
115
+ "step": 14
116
+ },
117
+ {
118
+ "epoch": 0.25,
119
+ "eval_loss": 1.441876769065857,
120
+ "eval_runtime": 71.2163,
121
+ "eval_samples_per_second": 280.399,
122
+ "eval_steps_per_second": 17.538,
123
+ "step": 14
124
+ },
125
+ {
126
+ "epoch": 0.27,
127
+ "grad_norm": 0.26474390032516393,
128
+ "learning_rate": 0.00019096319953545185,
129
+ "loss": 1.3955,
130
+ "step": 15
131
+ },
132
+ {
133
+ "epoch": 0.29,
134
+ "grad_norm": 0.22490458783426903,
135
+ "learning_rate": 0.00018973984286913584,
136
+ "loss": 1.376,
137
+ "step": 16
138
+ },
139
+ {
140
+ "epoch": 0.31,
141
+ "grad_norm": 0.33330700318335205,
142
+ "learning_rate": 0.00018844329309978145,
143
+ "loss": 1.3286,
144
+ "step": 17
145
+ },
146
+ {
147
+ "epoch": 0.32,
148
+ "grad_norm": 0.37492777208291783,
149
+ "learning_rate": 0.00018707460771197774,
150
+ "loss": 1.3359,
151
+ "step": 18
152
+ },
153
+ {
154
+ "epoch": 0.34,
155
+ "grad_norm": 0.29525135911036,
156
+ "learning_rate": 0.0001856349030251589,
157
+ "loss": 1.3198,
158
+ "step": 19
159
+ },
160
+ {
161
+ "epoch": 0.36,
162
+ "grad_norm": 0.22284214725380747,
163
+ "learning_rate": 0.00018412535328311814,
164
+ "loss": 1.3325,
165
+ "step": 20
166
+ },
167
+ {
168
+ "epoch": 0.38,
169
+ "grad_norm": 0.39903198098602605,
170
+ "learning_rate": 0.0001825471896962774,
171
+ "loss": 1.3252,
172
+ "step": 21
173
+ },
174
+ {
175
+ "epoch": 0.4,
176
+ "grad_norm": 0.4164131128200096,
177
+ "learning_rate": 0.00018090169943749476,
178
+ "loss": 1.2842,
179
+ "step": 22
180
+ },
181
+ {
182
+ "epoch": 0.41,
183
+ "grad_norm": 0.2610111064228617,
184
+ "learning_rate": 0.00017919022459222752,
185
+ "loss": 1.2979,
186
+ "step": 23
187
+ },
188
+ {
189
+ "epoch": 0.43,
190
+ "grad_norm": 0.2012045009785502,
191
+ "learning_rate": 0.00017741416106390826,
192
+ "loss": 1.2554,
193
+ "step": 24
194
+ },
195
+ {
196
+ "epoch": 0.45,
197
+ "grad_norm": 0.23300289011357986,
198
+ "learning_rate": 0.00017557495743542585,
199
+ "loss": 1.2461,
200
+ "step": 25
201
+ },
202
+ {
203
+ "epoch": 0.47,
204
+ "grad_norm": 0.23652936705914454,
205
+ "learning_rate": 0.0001736741137876405,
206
+ "loss": 1.271,
207
+ "step": 26
208
+ },
209
+ {
210
+ "epoch": 0.49,
211
+ "grad_norm": 0.1925895084011206,
212
+ "learning_rate": 0.00017171318047589637,
213
+ "loss": 1.2515,
214
+ "step": 27
215
+ },
216
+ {
217
+ "epoch": 0.5,
218
+ "grad_norm": 0.12096954328419277,
219
+ "learning_rate": 0.00016969375686552937,
220
+ "loss": 1.2461,
221
+ "step": 28
222
+ },
223
+ {
224
+ "epoch": 0.5,
225
+ "eval_loss": 1.3231805562973022,
226
+ "eval_runtime": 71.3812,
227
+ "eval_samples_per_second": 279.752,
228
+ "eval_steps_per_second": 17.498,
229
+ "step": 28
230
+ },
231
+ {
232
+ "epoch": 0.52,
233
+ "grad_norm": 0.12448721999954601,
234
+ "learning_rate": 0.00016761749002740193,
235
+ "loss": 1.2446,
236
+ "step": 29
237
+ },
238
+ {
239
+ "epoch": 0.54,
240
+ "grad_norm": 0.21969944256734386,
241
+ "learning_rate": 0.00016548607339452853,
242
+ "loss": 1.2783,
243
+ "step": 30
244
+ },
245
+ {
246
+ "epoch": 0.56,
247
+ "grad_norm": 0.2172107697789349,
248
+ "learning_rate": 0.00016330124538088705,
249
+ "loss": 1.2461,
250
+ "step": 31
251
+ },
252
+ {
253
+ "epoch": 0.57,
254
+ "grad_norm": 0.1547872862082663,
255
+ "learning_rate": 0.00016106478796354382,
256
+ "loss": 1.2241,
257
+ "step": 32
258
+ },
259
+ {
260
+ "epoch": 0.59,
261
+ "grad_norm": 0.08869884076741208,
262
+ "learning_rate": 0.00015877852522924732,
263
+ "loss": 1.1846,
264
+ "step": 33
265
+ },
266
+ {
267
+ "epoch": 0.61,
268
+ "grad_norm": 0.1538541877622166,
269
+ "learning_rate": 0.00015644432188667695,
270
+ "loss": 1.23,
271
+ "step": 34
272
+ },
273
+ {
274
+ "epoch": 0.63,
275
+ "grad_norm": 0.20399644873662537,
276
+ "learning_rate": 0.00015406408174555976,
277
+ "loss": 1.2114,
278
+ "step": 35
279
+ },
280
+ {
281
+ "epoch": 0.65,
282
+ "grad_norm": 0.19144417912447978,
283
+ "learning_rate": 0.0001516397461638962,
284
+ "loss": 1.2324,
285
+ "step": 36
286
+ },
287
+ {
288
+ "epoch": 0.66,
289
+ "grad_norm": 0.26912005474616185,
290
+ "learning_rate": 0.0001491732924645604,
291
+ "loss": 1.5522,
292
+ "step": 37
293
+ },
294
+ {
295
+ "epoch": 0.68,
296
+ "grad_norm": 0.09943230167494302,
297
+ "learning_rate": 0.00014666673232256738,
298
+ "loss": 1.1973,
299
+ "step": 38
300
+ },
301
+ {
302
+ "epoch": 0.7,
303
+ "grad_norm": 0.12111451370899122,
304
+ "learning_rate": 0.00014412211012432212,
305
+ "loss": 1.1685,
306
+ "step": 39
307
+ },
308
+ {
309
+ "epoch": 0.72,
310
+ "grad_norm": 0.13274421759806426,
311
+ "learning_rate": 0.00014154150130018866,
312
+ "loss": 1.1846,
313
+ "step": 40
314
+ },
315
+ {
316
+ "epoch": 0.74,
317
+ "grad_norm": 0.12218551159116417,
318
+ "learning_rate": 0.00013892701063173918,
319
+ "loss": 1.2173,
320
+ "step": 41
321
+ },
322
+ {
323
+ "epoch": 0.75,
324
+ "grad_norm": 0.09665309655921935,
325
+ "learning_rate": 0.0001362807705350641,
326
+ "loss": 1.2207,
327
+ "step": 42
328
+ },
329
+ {
330
+ "epoch": 0.75,
331
+ "eval_loss": 1.2895056009292603,
332
+ "eval_runtime": 71.3954,
333
+ "eval_samples_per_second": 279.696,
334
+ "eval_steps_per_second": 17.494,
335
+ "step": 42
336
+ },
337
+ {
338
+ "epoch": 0.77,
339
+ "grad_norm": 0.10941681743668577,
340
+ "learning_rate": 0.00013360493932154302,
341
+ "loss": 1.1943,
342
+ "step": 43
343
+ },
344
+ {
345
+ "epoch": 0.79,
346
+ "grad_norm": 0.13685075654053136,
347
+ "learning_rate": 0.00013090169943749476,
348
+ "loss": 1.1597,
349
+ "step": 44
350
+ },
351
+ {
352
+ "epoch": 0.81,
353
+ "grad_norm": 0.12907173631699106,
354
+ "learning_rate": 0.00012817325568414297,
355
+ "loss": 1.1851,
356
+ "step": 45
357
+ },
358
+ {
359
+ "epoch": 0.83,
360
+ "grad_norm": 0.1036179369816153,
361
+ "learning_rate": 0.00012542183341934872,
362
+ "loss": 1.1987,
363
+ "step": 46
364
+ },
365
+ {
366
+ "epoch": 0.84,
367
+ "grad_norm": 0.08667840513163542,
368
+ "learning_rate": 0.00012264967674257646,
369
+ "loss": 1.1724,
370
+ "step": 47
371
+ },
372
+ {
373
+ "epoch": 0.86,
374
+ "grad_norm": 0.1144689947654717,
375
+ "learning_rate": 0.00011985904666457455,
376
+ "loss": 1.1997,
377
+ "step": 48
378
+ },
379
+ {
380
+ "epoch": 0.88,
381
+ "grad_norm": 0.13847211768760592,
382
+ "learning_rate": 0.0001170522192632624,
383
+ "loss": 1.1602,
384
+ "step": 49
385
+ },
386
+ {
387
+ "epoch": 0.9,
388
+ "grad_norm": 0.11095253849183417,
389
+ "learning_rate": 0.00011423148382732853,
390
+ "loss": 1.1758,
391
+ "step": 50
392
+ },
393
+ {
394
+ "epoch": 0.92,
395
+ "grad_norm": 0.08573841203966975,
396
+ "learning_rate": 0.00011139914098905406,
397
+ "loss": 1.1846,
398
+ "step": 51
399
+ },
400
+ {
401
+ "epoch": 0.93,
402
+ "grad_norm": 0.0948235516667105,
403
+ "learning_rate": 0.00010855750084788398,
404
+ "loss": 1.1948,
405
+ "step": 52
406
+ },
407
+ {
408
+ "epoch": 0.95,
409
+ "grad_norm": 0.121781824636731,
410
+ "learning_rate": 0.00010570888108627681,
411
+ "loss": 1.1753,
412
+ "step": 53
413
+ },
414
+ {
415
+ "epoch": 0.97,
416
+ "grad_norm": 0.10546391970558401,
417
+ "learning_rate": 0.00010285560507936961,
418
+ "loss": 1.1699,
419
+ "step": 54
420
+ },
421
+ {
422
+ "epoch": 0.99,
423
+ "grad_norm": 0.34233328008898944,
424
+ "learning_rate": 0.0001,
425
+ "loss": 1.5063,
426
+ "step": 55
427
+ },
428
+ {
429
+ "epoch": 1.01,
430
+ "grad_norm": 0.11900909777508013,
431
+ "learning_rate": 9.71443949206304e-05,
432
+ "loss": 1.1479,
433
+ "step": 56
434
+ },
435
+ {
436
+ "epoch": 1.01,
437
+ "eval_loss": 1.2747071981430054,
438
+ "eval_runtime": 71.4286,
439
+ "eval_samples_per_second": 279.566,
440
+ "eval_steps_per_second": 17.486,
441
+ "step": 56
442
+ },
443
+ {
444
+ "epoch": 1.02,
445
+ "grad_norm": 0.11736589205080973,
446
+ "learning_rate": 9.42911189137232e-05,
447
+ "loss": 1.1411,
448
+ "step": 57
449
+ },
450
+ {
451
+ "epoch": 1.02,
452
+ "grad_norm": 0.12677764502316016,
453
+ "learning_rate": 9.144249915211605e-05,
454
+ "loss": 1.1514,
455
+ "step": 58
456
+ },
457
+ {
458
+ "epoch": 1.04,
459
+ "grad_norm": 0.11697640877801936,
460
+ "learning_rate": 8.860085901094595e-05,
461
+ "loss": 1.144,
462
+ "step": 59
463
+ },
464
+ {
465
+ "epoch": 1.05,
466
+ "grad_norm": 0.10851474914032534,
467
+ "learning_rate": 8.57685161726715e-05,
468
+ "loss": 1.1538,
469
+ "step": 60
470
+ },
471
+ {
472
+ "epoch": 1.07,
473
+ "grad_norm": 0.10591523712985791,
474
+ "learning_rate": 8.294778073673762e-05,
475
+ "loss": 1.1675,
476
+ "step": 61
477
+ },
478
+ {
479
+ "epoch": 1.09,
480
+ "grad_norm": 0.10109697997845449,
481
+ "learning_rate": 8.014095333542548e-05,
482
+ "loss": 1.1528,
483
+ "step": 62
484
+ },
485
+ {
486
+ "epoch": 1.11,
487
+ "grad_norm": 0.11774452860536459,
488
+ "learning_rate": 7.735032325742355e-05,
489
+ "loss": 1.144,
490
+ "step": 63
491
+ },
492
+ {
493
+ "epoch": 1.13,
494
+ "grad_norm": 0.11052397113271337,
495
+ "learning_rate": 7.457816658065134e-05,
496
+ "loss": 1.1533,
497
+ "step": 64
498
+ },
499
+ {
500
+ "epoch": 1.14,
501
+ "grad_norm": 0.09932538763675618,
502
+ "learning_rate": 7.182674431585704e-05,
503
+ "loss": 1.1562,
504
+ "step": 65
505
+ },
506
+ {
507
+ "epoch": 1.16,
508
+ "grad_norm": 0.100642669752315,
509
+ "learning_rate": 6.909830056250527e-05,
510
+ "loss": 1.1504,
511
+ "step": 66
512
+ },
513
+ {
514
+ "epoch": 1.18,
515
+ "grad_norm": 0.08717942179921322,
516
+ "learning_rate": 6.639506067845697e-05,
517
+ "loss": 1.1353,
518
+ "step": 67
519
+ },
520
+ {
521
+ "epoch": 1.2,
522
+ "grad_norm": 0.10484048248463712,
523
+ "learning_rate": 6.371922946493591e-05,
524
+ "loss": 1.1196,
525
+ "step": 68
526
+ },
527
+ {
528
+ "epoch": 1.22,
529
+ "grad_norm": 0.10322601363425112,
530
+ "learning_rate": 6.107298936826086e-05,
531
+ "loss": 1.1226,
532
+ "step": 69
533
+ },
534
+ {
535
+ "epoch": 1.23,
536
+ "grad_norm": 0.10689324440748724,
537
+ "learning_rate": 5.845849869981137e-05,
538
+ "loss": 1.1797,
539
+ "step": 70
540
+ },
541
+ {
542
+ "epoch": 1.23,
543
+ "eval_loss": 1.2690308094024658,
544
+ "eval_runtime": 71.4252,
545
+ "eval_samples_per_second": 279.579,
546
+ "eval_steps_per_second": 17.487,
547
+ "step": 70
548
+ },
549
+ {
550
+ "epoch": 1.25,
551
+ "grad_norm": 0.10301775684317682,
552
+ "learning_rate": 5.5877889875677845e-05,
553
+ "loss": 1.1265,
554
+ "step": 71
555
+ },
556
+ {
557
+ "epoch": 1.27,
558
+ "grad_norm": 0.08476164067920204,
559
+ "learning_rate": 5.333326767743263e-05,
560
+ "loss": 1.145,
561
+ "step": 72
562
+ },
563
+ {
564
+ "epoch": 1.29,
565
+ "grad_norm": 0.09070035744584001,
566
+ "learning_rate": 5.082670753543961e-05,
567
+ "loss": 1.1226,
568
+ "step": 73
569
+ },
570
+ {
571
+ "epoch": 1.31,
572
+ "grad_norm": 0.09969553773787451,
573
+ "learning_rate": 4.836025383610382e-05,
574
+ "loss": 1.1323,
575
+ "step": 74
576
+ },
577
+ {
578
+ "epoch": 1.32,
579
+ "grad_norm": 0.1100883382765975,
580
+ "learning_rate": 4.593591825444028e-05,
581
+ "loss": 1.1353,
582
+ "step": 75
583
+ },
584
+ {
585
+ "epoch": 1.34,
586
+ "grad_norm": 0.10084037635805906,
587
+ "learning_rate": 4.355567811332311e-05,
588
+ "loss": 1.1689,
589
+ "step": 76
590
+ },
591
+ {
592
+ "epoch": 1.36,
593
+ "grad_norm": 0.08865185209055175,
594
+ "learning_rate": 4.12214747707527e-05,
595
+ "loss": 1.1304,
596
+ "step": 77
597
+ },
598
+ {
599
+ "epoch": 1.38,
600
+ "grad_norm": 0.08317004226644682,
601
+ "learning_rate": 3.893521203645618e-05,
602
+ "loss": 1.0801,
603
+ "step": 78
604
+ },
605
+ {
606
+ "epoch": 1.4,
607
+ "grad_norm": 0.08437511567708315,
608
+ "learning_rate": 3.669875461911297e-05,
609
+ "loss": 1.1265,
610
+ "step": 79
611
+ },
612
+ {
613
+ "epoch": 1.41,
614
+ "grad_norm": 0.08737931667441079,
615
+ "learning_rate": 3.45139266054715e-05,
616
+ "loss": 1.1206,
617
+ "step": 80
618
+ },
619
+ {
620
+ "epoch": 1.43,
621
+ "grad_norm": 0.09676132223503787,
622
+ "learning_rate": 3.238250997259808e-05,
623
+ "loss": 1.0879,
624
+ "step": 81
625
+ },
626
+ {
627
+ "epoch": 1.45,
628
+ "grad_norm": 0.3064914875240821,
629
+ "learning_rate": 3.030624313447067e-05,
630
+ "loss": 1.4707,
631
+ "step": 82
632
+ },
633
+ {
634
+ "epoch": 1.47,
635
+ "grad_norm": 0.10108431705762476,
636
+ "learning_rate": 2.828681952410366e-05,
637
+ "loss": 1.1489,
638
+ "step": 83
639
+ },
640
+ {
641
+ "epoch": 1.49,
642
+ "grad_norm": 0.10356256932007075,
643
+ "learning_rate": 2.6325886212359498e-05,
644
+ "loss": 1.084,
645
+ "step": 84
646
+ },
647
+ {
648
+ "epoch": 1.49,
649
+ "eval_loss": 1.2660632133483887,
650
+ "eval_runtime": 71.4598,
651
+ "eval_samples_per_second": 279.444,
652
+ "eval_steps_per_second": 17.478,
653
+ "step": 84
654
+ },
655
+ {
656
+ "epoch": 1.5,
657
+ "grad_norm": 0.11000673888436871,
658
+ "learning_rate": 2.4425042564574184e-05,
659
+ "loss": 1.1494,
660
+ "step": 85
661
+ },
662
+ {
663
+ "epoch": 1.52,
664
+ "grad_norm": 0.09066127881300992,
665
+ "learning_rate": 2.2585838936091754e-05,
666
+ "loss": 1.1572,
667
+ "step": 86
668
+ },
669
+ {
670
+ "epoch": 1.54,
671
+ "grad_norm": 0.09757831324550774,
672
+ "learning_rate": 2.0809775407772503e-05,
673
+ "loss": 1.103,
674
+ "step": 87
675
+ },
676
+ {
677
+ "epoch": 1.56,
678
+ "grad_norm": 0.0934233089422467,
679
+ "learning_rate": 1.9098300562505266e-05,
680
+ "loss": 1.1001,
681
+ "step": 88
682
+ },
683
+ {
684
+ "epoch": 1.57,
685
+ "grad_norm": 0.09106355313835601,
686
+ "learning_rate": 1.74528103037226e-05,
687
+ "loss": 1.1406,
688
+ "step": 89
689
+ },
690
+ {
691
+ "epoch": 1.59,
692
+ "grad_norm": 0.09454088595436297,
693
+ "learning_rate": 1.587464671688187e-05,
694
+ "loss": 1.1387,
695
+ "step": 90
696
+ },
697
+ {
698
+ "epoch": 1.61,
699
+ "grad_norm": 0.09689276747664,
700
+ "learning_rate": 1.4365096974841108e-05,
701
+ "loss": 1.1318,
702
+ "step": 91
703
+ },
704
+ {
705
+ "epoch": 1.63,
706
+ "grad_norm": 0.08987470798352144,
707
+ "learning_rate": 1.2925392288022298e-05,
708
+ "loss": 1.1592,
709
+ "step": 92
710
+ },
711
+ {
712
+ "epoch": 1.65,
713
+ "grad_norm": 0.08771103153086109,
714
+ "learning_rate": 1.1556706900218572e-05,
715
+ "loss": 1.1582,
716
+ "step": 93
717
+ },
718
+ {
719
+ "epoch": 1.66,
720
+ "grad_norm": 0.08740633683699849,
721
+ "learning_rate": 1.026015713086418e-05,
722
+ "loss": 1.1787,
723
+ "step": 94
724
+ },
725
+ {
726
+ "epoch": 1.68,
727
+ "grad_norm": 0.08404626340301383,
728
+ "learning_rate": 9.036800464548157e-06,
729
+ "loss": 1.1362,
730
+ "step": 95
731
+ },
732
+ {
733
+ "epoch": 1.7,
734
+ "grad_norm": 0.08750778902246109,
735
+ "learning_rate": 7.887634688515e-06,
736
+ "loss": 1.1387,
737
+ "step": 96
738
+ },
739
+ {
740
+ "epoch": 1.72,
741
+ "grad_norm": 0.08581989813901233,
742
+ "learning_rate": 6.813597078854772e-06,
743
+ "loss": 1.1421,
744
+ "step": 97
745
+ },
746
+ {
747
+ "epoch": 1.74,
748
+ "grad_norm": 0.08777403515933545,
749
+ "learning_rate": 5.8155636360475385e-06,
750
+ "loss": 1.1035,
751
+ "step": 98
752
+ },
753
+ {
754
+ "epoch": 1.74,
755
+ "eval_loss": 1.2641561031341553,
756
+ "eval_runtime": 71.4805,
757
+ "eval_samples_per_second": 279.363,
758
+ "eval_steps_per_second": 17.473,
759
+ "step": 98
760
+ },
761
+ {
762
+ "epoch": 1.75,
763
+ "grad_norm": 0.08385195939000219,
764
+ "learning_rate": 4.8943483704846475e-06,
765
+ "loss": 1.1113,
766
+ "step": 99
767
+ },
768
+ {
769
+ "epoch": 1.77,
770
+ "grad_norm": 0.08908998416660925,
771
+ "learning_rate": 4.050702638550275e-06,
772
+ "loss": 1.1104,
773
+ "step": 100
774
+ },
775
+ {
776
+ "epoch": 1.79,
777
+ "grad_norm": 0.08249447233292928,
778
+ "learning_rate": 3.2853145298042953e-06,
779
+ "loss": 1.1396,
780
+ "step": 101
781
+ },
782
+ {
783
+ "epoch": 1.81,
784
+ "grad_norm": 0.08608973089588336,
785
+ "learning_rate": 2.5988083057666533e-06,
786
+ "loss": 1.1055,
787
+ "step": 102
788
+ },
789
+ {
790
+ "epoch": 1.83,
791
+ "grad_norm": 0.09951373726217344,
792
+ "learning_rate": 1.9917438907606556e-06,
793
+ "loss": 1.1221,
794
+ "step": 103
795
+ },
796
+ {
797
+ "epoch": 1.84,
798
+ "grad_norm": 0.08532100595350145,
799
+ "learning_rate": 1.4646164152307018e-06,
800
+ "loss": 1.0898,
801
+ "step": 104
802
+ },
803
+ {
804
+ "epoch": 1.86,
805
+ "grad_norm": 0.08282306531770366,
806
+ "learning_rate": 1.0178558119067315e-06,
807
+ "loss": 1.1118,
808
+ "step": 105
809
+ },
810
+ {
811
+ "epoch": 1.88,
812
+ "grad_norm": 0.08416795073468437,
813
+ "learning_rate": 6.518264651449779e-07,
814
+ "loss": 1.1133,
815
+ "step": 106
816
+ },
817
+ {
818
+ "epoch": 1.9,
819
+ "grad_norm": 0.08760805801842701,
820
+ "learning_rate": 3.6682691373086665e-07,
821
+ "loss": 1.123,
822
+ "step": 107
823
+ },
824
+ {
825
+ "epoch": 1.92,
826
+ "grad_norm": 0.08618073017190576,
827
+ "learning_rate": 1.630896073864352e-07,
828
+ "loss": 1.0981,
829
+ "step": 108
830
+ },
831
+ {
832
+ "epoch": 1.93,
833
+ "grad_norm": 0.0908365337693141,
834
+ "learning_rate": 4.078071718107701e-08,
835
+ "loss": 1.1328,
836
+ "step": 109
837
+ },
838
+ {
839
+ "epoch": 1.95,
840
+ "grad_norm": 0.09003969262620456,
841
+ "learning_rate": 0.0,
842
+ "loss": 1.1104,
843
+ "step": 110
844
+ }
845
+ ],
846
+ "logging_steps": 1,
847
+ "max_steps": 110,
848
+ "num_input_tokens_seen": 0,
849
+ "num_train_epochs": 2,
850
+ "save_steps": 55,
851
+ "total_flos": 2.6221185296708403e+17,
852
+ "train_batch_size": 4,
853
+ "trial_name": null,
854
+ "trial_params": null
855
+ }
checkpoint-110/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:123d1fd699788f7d60d917b5964a4e0851773abfe7e74a3a42baed90eb8677c6
3
+ size 6331
checkpoint-110/zero_to_fp32.py ADDED
@@ -0,0 +1,592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states)
215
+ elif zero_stage == 3:
216
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states)
217
+
218
+
219
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
220
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
221
+ return
222
+
223
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
224
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
225
+
226
+ if debug:
227
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
228
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
229
+
230
+ wanted_params = len(frozen_param_shapes)
231
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
232
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
233
+ print(f'Frozen params: Have {avail_numel} numels to process.')
234
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
235
+
236
+ total_params = 0
237
+ total_numel = 0
238
+ for name, shape in frozen_param_shapes.items():
239
+ total_params += 1
240
+ unpartitioned_numel = shape.numel()
241
+ total_numel += unpartitioned_numel
242
+
243
+ state_dict[name] = frozen_param_fragments[name]
244
+
245
+ if debug:
246
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
247
+
248
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
249
+
250
+
251
+ def _has_callable(obj, fn):
252
+ attr = getattr(obj, fn, None)
253
+ return callable(attr)
254
+
255
+
256
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
257
+ param_shapes = zero_model_states[0].param_shapes
258
+
259
+ # Reconstruction protocol:
260
+ #
261
+ # XXX: document this
262
+
263
+ if debug:
264
+ for i in range(world_size):
265
+ for j in range(len(fp32_flat_groups[0])):
266
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
267
+
268
+ # XXX: memory usage doubles here (zero2)
269
+ num_param_groups = len(fp32_flat_groups[0])
270
+ merged_single_partition_of_fp32_groups = []
271
+ for i in range(num_param_groups):
272
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
273
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
274
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
275
+ avail_numel = sum(
276
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
277
+
278
+ if debug:
279
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
280
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
281
+ # not asserting if there is a mismatch due to possible padding
282
+ print(f"Have {avail_numel} numels to process.")
283
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
284
+
285
+ # params
286
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
287
+ # out-of-core computing solution
288
+ total_numel = 0
289
+ total_params = 0
290
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
291
+ offset = 0
292
+ avail_numel = full_single_fp32_vector.numel()
293
+ for name, shape in shapes.items():
294
+
295
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
296
+ total_numel += unpartitioned_numel
297
+ total_params += 1
298
+
299
+ if debug:
300
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
301
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
302
+ offset += unpartitioned_numel
303
+
304
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
305
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
306
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
307
+ # live optimizer object, so we are checking that the numbers are within the right range
308
+ align_to = 2 * world_size
309
+
310
+ def zero2_align(x):
311
+ return align_to * math.ceil(x / align_to)
312
+
313
+ if debug:
314
+ print(f"original offset={offset}, avail_numel={avail_numel}")
315
+
316
+ offset = zero2_align(offset)
317
+ avail_numel = zero2_align(avail_numel)
318
+
319
+ if debug:
320
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
321
+
322
+ # Sanity check
323
+ if offset != avail_numel:
324
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
325
+
326
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
327
+
328
+
329
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states):
330
+ state_dict = OrderedDict()
331
+
332
+ # buffers
333
+ buffers = zero_model_states[0].buffers
334
+ state_dict.update(buffers)
335
+ if debug:
336
+ print(f"added {len(buffers)} buffers")
337
+
338
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
339
+
340
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
341
+
342
+ # recover shared parameters
343
+ for pair in zero_model_states[0].shared_params:
344
+ if pair[1] in state_dict:
345
+ state_dict[pair[0]] = state_dict[pair[1]]
346
+
347
+ return state_dict
348
+
349
+
350
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
351
+ remainder = unpartitioned_numel % world_size
352
+ padding_numel = (world_size - remainder) if remainder else 0
353
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
354
+ return partitioned_numel, padding_numel
355
+
356
+
357
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
358
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
359
+ return
360
+
361
+ if debug:
362
+ for i in range(world_size):
363
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
364
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
365
+
366
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
367
+ wanted_params = len(frozen_param_shapes)
368
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
369
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
370
+ print(f'Frozen params: Have {avail_numel} numels to process.')
371
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
372
+
373
+ total_params = 0
374
+ total_numel = 0
375
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
376
+ total_params += 1
377
+ unpartitioned_numel = shape.numel()
378
+ total_numel += unpartitioned_numel
379
+
380
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
381
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
382
+
383
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
384
+
385
+ if debug:
386
+ print(
387
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
388
+ )
389
+
390
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
391
+
392
+
393
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
394
+ param_shapes = zero_model_states[0].param_shapes
395
+ avail_numel = fp32_flat_groups[0].numel() * world_size
396
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
397
+ # param, re-consolidating each param, while dealing with padding if any
398
+
399
+ # merge list of dicts, preserving order
400
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
401
+
402
+ if debug:
403
+ for i in range(world_size):
404
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
405
+
406
+ wanted_params = len(param_shapes)
407
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
408
+ # not asserting if there is a mismatch due to possible padding
409
+ avail_numel = fp32_flat_groups[0].numel() * world_size
410
+ print(f"Trainable params: Have {avail_numel} numels to process.")
411
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
412
+
413
+ # params
414
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
415
+ # out-of-core computing solution
416
+ offset = 0
417
+ total_numel = 0
418
+ total_params = 0
419
+ for name, shape in param_shapes.items():
420
+
421
+ unpartitioned_numel = shape.numel()
422
+ total_numel += unpartitioned_numel
423
+ total_params += 1
424
+
425
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
426
+
427
+ if debug:
428
+ print(
429
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
430
+ )
431
+
432
+ # XXX: memory usage doubles here
433
+ state_dict[name] = torch.cat(
434
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
435
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
436
+ offset += partitioned_numel
437
+
438
+ offset *= world_size
439
+
440
+ # Sanity check
441
+ if offset != avail_numel:
442
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
443
+
444
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
445
+
446
+
447
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states):
448
+ state_dict = OrderedDict()
449
+
450
+ # buffers
451
+ buffers = zero_model_states[0].buffers
452
+ state_dict.update(buffers)
453
+ if debug:
454
+ print(f"added {len(buffers)} buffers")
455
+
456
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
457
+
458
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
459
+
460
+ # recover shared parameters
461
+ for pair in zero_model_states[0].shared_params:
462
+ if pair[1] in state_dict:
463
+ state_dict[pair[0]] = state_dict[pair[1]]
464
+
465
+ return state_dict
466
+
467
+
468
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
469
+ """
470
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
471
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
472
+ via a model hub.
473
+
474
+ Args:
475
+ - ``checkpoint_dir``: path to the desired checkpoint folder
476
+ - ``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``
477
+
478
+ Returns:
479
+ - pytorch ``state_dict``
480
+
481
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
482
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
483
+ the checkpoint.
484
+
485
+ A typical usage might be ::
486
+
487
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
488
+ # do the training and checkpoint saving
489
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
490
+ model = model.cpu() # move to cpu
491
+ model.load_state_dict(state_dict)
492
+ # submit to model hub or save the model to share with others
493
+
494
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
495
+ application. i.e. you will need to re-initialize the deepspeed engine, since
496
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
497
+
498
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
499
+
500
+ """
501
+ if tag is None:
502
+ latest_path = os.path.join(checkpoint_dir, 'latest')
503
+ if os.path.isfile(latest_path):
504
+ with open(latest_path, 'r') as fd:
505
+ tag = fd.read().strip()
506
+ else:
507
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
508
+
509
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
510
+
511
+ if not os.path.isdir(ds_checkpoint_dir):
512
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
513
+
514
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
515
+
516
+
517
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
518
+ """
519
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
520
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
521
+
522
+ Args:
523
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
524
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
525
+ - ``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``
526
+ """
527
+
528
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
529
+ print(f"Saving fp32 state dict to {output_file}")
530
+ torch.save(state_dict, output_file)
531
+
532
+
533
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
534
+ """
535
+ 1. Put the provided model to cpu
536
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
537
+ 3. Load it into the provided model
538
+
539
+ Args:
540
+ - ``model``: the model object to update
541
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
542
+ - ``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``
543
+
544
+ Returns:
545
+ - ``model`: modified model
546
+
547
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
548
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
549
+ conveniently placed for you in the checkpoint folder.
550
+
551
+ A typical usage might be ::
552
+
553
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
554
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
555
+ # submit to model hub or save the model to share with others
556
+
557
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
558
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
559
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
560
+
561
+ """
562
+ logger.info(f"Extracting fp32 weights")
563
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
564
+
565
+ logger.info(f"Overwriting model with fp32 weights")
566
+ model = model.cpu()
567
+ model.load_state_dict(state_dict, strict=False)
568
+
569
+ return model
570
+
571
+
572
+ if __name__ == "__main__":
573
+
574
+ parser = argparse.ArgumentParser()
575
+ parser.add_argument("checkpoint_dir",
576
+ type=str,
577
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
578
+ parser.add_argument(
579
+ "output_file",
580
+ type=str,
581
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
582
+ parser.add_argument("-t",
583
+ "--tag",
584
+ type=str,
585
+ default=None,
586
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
587
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
588
+ args = parser.parse_args()
589
+
590
+ debug = args.debug
591
+
592
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file, tag=args.tag)
checkpoint-46/README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ base_model: google/gemma-2b-it
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.9.0
checkpoint-46/adapter_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "google/gemma-2b-it",
5
+ "bias": "none",
6
+ "fan_in_fan_out": null,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layers_pattern": null,
10
+ "layers_to_transform": null,
11
+ "loftq_config": {},
12
+ "lora_alpha": 16,
13
+ "lora_dropout": 0.05,
14
+ "megatron_config": null,
15
+ "megatron_core": "megatron.core",
16
+ "modules_to_save": null,
17
+ "peft_type": "LORA",
18
+ "r": 32,
19
+ "rank_pattern": {},
20
+ "revision": null,
21
+ "target_modules": [
22
+ "gate_proj",
23
+ "k_proj",
24
+ "v_proj",
25
+ "up_proj",
26
+ "down_proj",
27
+ "o_proj",
28
+ "q_proj"
29
+ ],
30
+ "task_type": "CAUSAL_LM",
31
+ "use_dora": false,
32
+ "use_rslora": false
33
+ }
checkpoint-46/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4f805062e6421d7c69a2ee547e3af8350f624451ce165140c7232181316db33
3
+ size 78480320
checkpoint-46/global_step46/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:9852910ac2adb1970801337fce7443a3bfdcaeabe07d654cff61bf2c432cbb3d
3
+ size 58886423
checkpoint-46/global_step46/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:c202b3d15fad6725b57469ab741165c4f095730417a3e390ce5fb29dda5a5c75
3
+ size 58885463
checkpoint-46/global_step46/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:a7f5dc5545b3f194373b58996d0aed9e1376e5a54254941eb23eb2b0aaee3a8e
3
+ size 58886487
checkpoint-46/global_step46/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:ec4ee84e8c134757373034201b648cb6e00fb8cc5f98385d4f02971bf99516e0
3
+ size 58885527
checkpoint-46/global_step46/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83d32f1971fddca0d11f12821e2366f4b0767156570446e5cc7bb231abc22851
3
+ size 1159049457
checkpoint-46/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step46
checkpoint-46/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b165aaa144fad4f4fa49d6dd695add421ab6c181ffc890115a172d00266723ab
3
+ size 17655
checkpoint-46/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d430c8b2f065299cc8e2d4fdc64fdd296a0649dc1216084e10018c2c0f201921
3
+ size 17655
checkpoint-46/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e513afae097b3d69141e7a925b55bd2f6657df9a7840cf02b10d4263576d744
3
+ size 17655
checkpoint-46/rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d013a562702b25cfd982378c7c0866be0e8fda59f98cb265cc32ba235b5bd6a
3
+ size 17655
checkpoint-46/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:761d7aba80bef53190f12e33a600d1e0cbb142bd0005601918622cc3b27ad6ff
3
+ size 627
checkpoint-46/trainer_state.json ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 1.0,
5
+ "eval_steps": 12,
6
+ "global_step": 46,
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.02,
13
+ "grad_norm": 0.9959812474764307,
14
+ "learning_rate": 0.0001999417022366174,
15
+ "loss": 2.8926,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.02,
20
+ "eval_loss": 2.7616989612579346,
21
+ "eval_runtime": 62.0214,
22
+ "eval_samples_per_second": 322.227,
23
+ "eval_steps_per_second": 20.154,
24
+ "step": 1
25
+ },
26
+ {
27
+ "epoch": 0.04,
28
+ "grad_norm": 0.9553562375664082,
29
+ "learning_rate": 0.00019976687691905393,
30
+ "loss": 2.7178,
31
+ "step": 2
32
+ },
33
+ {
34
+ "epoch": 0.07,
35
+ "grad_norm": 1.074690670043139,
36
+ "learning_rate": 0.00019947572788580947,
37
+ "loss": 2.3477,
38
+ "step": 3
39
+ },
40
+ {
41
+ "epoch": 0.09,
42
+ "grad_norm": 1.2607308881446835,
43
+ "learning_rate": 0.00019906859460363307,
44
+ "loss": 2.0869,
45
+ "step": 4
46
+ },
47
+ {
48
+ "epoch": 0.11,
49
+ "grad_norm": 1.5197691743409516,
50
+ "learning_rate": 0.00019854595177171968,
51
+ "loss": 1.8477,
52
+ "step": 5
53
+ },
54
+ {
55
+ "epoch": 0.13,
56
+ "grad_norm": 0.7112299977659389,
57
+ "learning_rate": 0.00019790840876823232,
58
+ "loss": 1.7227,
59
+ "step": 6
60
+ },
61
+ {
62
+ "epoch": 0.15,
63
+ "grad_norm": 0.7680093267515216,
64
+ "learning_rate": 0.00019715670893979414,
65
+ "loss": 1.6553,
66
+ "step": 7
67
+ },
68
+ {
69
+ "epoch": 0.17,
70
+ "grad_norm": 0.7744797513985666,
71
+ "learning_rate": 0.00019629172873477995,
72
+ "loss": 1.6455,
73
+ "step": 8
74
+ },
75
+ {
76
+ "epoch": 0.2,
77
+ "grad_norm": 0.735518802506217,
78
+ "learning_rate": 0.00019531447668141608,
79
+ "loss": 1.5508,
80
+ "step": 9
81
+ },
82
+ {
83
+ "epoch": 0.22,
84
+ "grad_norm": 0.4535717241942791,
85
+ "learning_rate": 0.00019422609221188207,
86
+ "loss": 1.5039,
87
+ "step": 10
88
+ },
89
+ {
90
+ "epoch": 0.24,
91
+ "grad_norm": 0.29477652700703394,
92
+ "learning_rate": 0.0001930278443337833,
93
+ "loss": 1.502,
94
+ "step": 11
95
+ },
96
+ {
97
+ "epoch": 0.26,
98
+ "grad_norm": 0.24434475566463373,
99
+ "learning_rate": 0.00019172113015054532,
100
+ "loss": 1.4502,
101
+ "step": 12
102
+ },
103
+ {
104
+ "epoch": 0.26,
105
+ "eval_loss": 1.456370234489441,
106
+ "eval_runtime": 63.0041,
107
+ "eval_samples_per_second": 317.202,
108
+ "eval_steps_per_second": 19.84,
109
+ "step": 12
110
+ },
111
+ {
112
+ "epoch": 0.28,
113
+ "grad_norm": 0.45228370307484317,
114
+ "learning_rate": 0.00019030747323245327,
115
+ "loss": 1.4277,
116
+ "step": 13
117
+ },
118
+ {
119
+ "epoch": 0.3,
120
+ "grad_norm": 0.46523254227617566,
121
+ "learning_rate": 0.0001887885218402375,
122
+ "loss": 1.4097,
123
+ "step": 14
124
+ },
125
+ {
126
+ "epoch": 0.33,
127
+ "grad_norm": 0.2855872854921807,
128
+ "learning_rate": 0.00018716604700327514,
129
+ "loss": 1.3833,
130
+ "step": 15
131
+ },
132
+ {
133
+ "epoch": 0.35,
134
+ "grad_norm": 0.25447863105741503,
135
+ "learning_rate": 0.00018544194045464886,
136
+ "loss": 1.3652,
137
+ "step": 16
138
+ },
139
+ {
140
+ "epoch": 0.37,
141
+ "grad_norm": 0.3619444462250106,
142
+ "learning_rate": 0.0001836182124254711,
143
+ "loss": 1.3677,
144
+ "step": 17
145
+ },
146
+ {
147
+ "epoch": 0.39,
148
+ "grad_norm": 0.36635956863370217,
149
+ "learning_rate": 0.0001816969893010442,
150
+ "loss": 1.332,
151
+ "step": 18
152
+ },
153
+ {
154
+ "epoch": 0.41,
155
+ "grad_norm": 0.39509330975297474,
156
+ "learning_rate": 0.00017968051114159047,
157
+ "loss": 1.3086,
158
+ "step": 19
159
+ },
160
+ {
161
+ "epoch": 0.43,
162
+ "grad_norm": 0.3249913054000147,
163
+ "learning_rate": 0.000177571129070442,
164
+ "loss": 1.3071,
165
+ "step": 20
166
+ },
167
+ {
168
+ "epoch": 0.46,
169
+ "grad_norm": 0.30914838660163285,
170
+ "learning_rate": 0.00017537130253273613,
171
+ "loss": 1.2729,
172
+ "step": 21
173
+ },
174
+ {
175
+ "epoch": 0.48,
176
+ "grad_norm": 0.42289317853499514,
177
+ "learning_rate": 0.00017308359642781242,
178
+ "loss": 1.2773,
179
+ "step": 22
180
+ },
181
+ {
182
+ "epoch": 0.5,
183
+ "grad_norm": 0.35414226064550436,
184
+ "learning_rate": 0.00017071067811865476,
185
+ "loss": 1.2417,
186
+ "step": 23
187
+ },
188
+ {
189
+ "epoch": 0.52,
190
+ "grad_norm": 1.5532132927649234,
191
+ "learning_rate": 0.00016825531432186543,
192
+ "loss": 1.7617,
193
+ "step": 24
194
+ },
195
+ {
196
+ "epoch": 0.52,
197
+ "eval_loss": 1.314684271812439,
198
+ "eval_runtime": 63.1261,
199
+ "eval_samples_per_second": 316.588,
200
+ "eval_steps_per_second": 19.802,
201
+ "step": 24
202
+ },
203
+ {
204
+ "epoch": 0.54,
205
+ "grad_norm": 0.12961326680655122,
206
+ "learning_rate": 0.00016572036788179727,
207
+ "loss": 1.2183,
208
+ "step": 25
209
+ },
210
+ {
211
+ "epoch": 0.57,
212
+ "grad_norm": 0.1963943275104468,
213
+ "learning_rate": 0.00016310879443260528,
214
+ "loss": 1.2222,
215
+ "step": 26
216
+ },
217
+ {
218
+ "epoch": 0.59,
219
+ "grad_norm": 0.21010667932420385,
220
+ "learning_rate": 0.00016042363895210946,
221
+ "loss": 1.2163,
222
+ "step": 27
223
+ },
224
+ {
225
+ "epoch": 0.61,
226
+ "grad_norm": 0.2259721381332128,
227
+ "learning_rate": 0.00015766803221148673,
228
+ "loss": 1.2217,
229
+ "step": 28
230
+ },
231
+ {
232
+ "epoch": 0.63,
233
+ "grad_norm": 0.19095866752454876,
234
+ "learning_rate": 0.00015484518712493187,
235
+ "loss": 1.2212,
236
+ "step": 29
237
+ },
238
+ {
239
+ "epoch": 0.65,
240
+ "grad_norm": 0.11496636776764421,
241
+ "learning_rate": 0.00015195839500354335,
242
+ "loss": 1.2212,
243
+ "step": 30
244
+ },
245
+ {
246
+ "epoch": 0.67,
247
+ "grad_norm": 0.12075046364081166,
248
+ "learning_rate": 0.00014901102171780174,
249
+ "loss": 1.1616,
250
+ "step": 31
251
+ },
252
+ {
253
+ "epoch": 0.7,
254
+ "grad_norm": 0.21352779335608432,
255
+ "learning_rate": 0.00014600650377311522,
256
+ "loss": 1.2002,
257
+ "step": 32
258
+ },
259
+ {
260
+ "epoch": 0.72,
261
+ "grad_norm": 0.20188789347169253,
262
+ "learning_rate": 0.0001429483443030082,
263
+ "loss": 1.2236,
264
+ "step": 33
265
+ },
266
+ {
267
+ "epoch": 0.74,
268
+ "grad_norm": 0.1547188722220508,
269
+ "learning_rate": 0.00013984010898462416,
270
+ "loss": 1.1826,
271
+ "step": 34
272
+ },
273
+ {
274
+ "epoch": 0.76,
275
+ "grad_norm": 0.11634196980431331,
276
+ "learning_rate": 0.00013668542188130566,
277
+ "loss": 1.209,
278
+ "step": 35
279
+ },
280
+ {
281
+ "epoch": 0.78,
282
+ "grad_norm": 0.11144391112143442,
283
+ "learning_rate": 0.00013348796121709862,
284
+ "loss": 1.2051,
285
+ "step": 36
286
+ },
287
+ {
288
+ "epoch": 0.78,
289
+ "eval_loss": 1.2780728340148926,
290
+ "eval_runtime": 63.136,
291
+ "eval_samples_per_second": 316.539,
292
+ "eval_steps_per_second": 19.799,
293
+ "step": 36
294
+ },
295
+ {
296
+ "epoch": 0.8,
297
+ "grad_norm": 0.16076857117392804,
298
+ "learning_rate": 0.0001302514550881076,
299
+ "loss": 1.2046,
300
+ "step": 37
301
+ },
302
+ {
303
+ "epoch": 0.83,
304
+ "grad_norm": 0.15687324678725567,
305
+ "learning_rate": 0.00012697967711570242,
306
+ "loss": 1.21,
307
+ "step": 38
308
+ },
309
+ {
310
+ "epoch": 0.85,
311
+ "grad_norm": 0.4130016628721442,
312
+ "learning_rate": 0.00012367644204664468,
313
+ "loss": 1.5093,
314
+ "step": 39
315
+ },
316
+ {
317
+ "epoch": 0.87,
318
+ "grad_norm": 0.1343313559360696,
319
+ "learning_rate": 0.0001203456013052634,
320
+ "loss": 1.2051,
321
+ "step": 40
322
+ },
323
+ {
324
+ "epoch": 0.89,
325
+ "grad_norm": 0.11359323094812154,
326
+ "learning_rate": 0.00011699103850286669,
327
+ "loss": 1.2031,
328
+ "step": 41
329
+ },
330
+ {
331
+ "epoch": 0.91,
332
+ "grad_norm": 0.09939941549415923,
333
+ "learning_rate": 0.00011361666490962468,
334
+ "loss": 1.1929,
335
+ "step": 42
336
+ },
337
+ {
338
+ "epoch": 0.93,
339
+ "grad_norm": 0.09916599553279144,
340
+ "learning_rate": 0.00011022641489420342,
341
+ "loss": 1.1748,
342
+ "step": 43
343
+ },
344
+ {
345
+ "epoch": 0.96,
346
+ "grad_norm": 0.14209942605129547,
347
+ "learning_rate": 0.0001068242413364671,
348
+ "loss": 1.1665,
349
+ "step": 44
350
+ },
351
+ {
352
+ "epoch": 0.98,
353
+ "grad_norm": 0.12442345202001188,
354
+ "learning_rate": 0.00010341411101859679,
355
+ "loss": 1.1768,
356
+ "step": 45
357
+ },
358
+ {
359
+ "epoch": 1.0,
360
+ "grad_norm": 0.26217962366852043,
361
+ "learning_rate": 0.0001,
362
+ "loss": 1.5122,
363
+ "step": 46
364
+ }
365
+ ],
366
+ "logging_steps": 1,
367
+ "max_steps": 92,
368
+ "num_input_tokens_seen": 0,
369
+ "num_train_epochs": 2,
370
+ "save_steps": 46,
371
+ "total_flos": 1.096730008312873e+17,
372
+ "train_batch_size": 4,
373
+ "trial_name": null,
374
+ "trial_params": null
375
+ }
checkpoint-46/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c43810cdb8f146f2245bb960f4cc7afe1dd2bc3429988aca22dc36faf28059d
3
+ size 6331
checkpoint-46/zero_to_fp32.py ADDED
@@ -0,0 +1,592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states)
215
+ elif zero_stage == 3:
216
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states)
217
+
218
+
219
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
220
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
221
+ return
222
+
223
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
224
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
225
+
226
+ if debug:
227
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
228
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
229
+
230
+ wanted_params = len(frozen_param_shapes)
231
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
232
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
233
+ print(f'Frozen params: Have {avail_numel} numels to process.')
234
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
235
+
236
+ total_params = 0
237
+ total_numel = 0
238
+ for name, shape in frozen_param_shapes.items():
239
+ total_params += 1
240
+ unpartitioned_numel = shape.numel()
241
+ total_numel += unpartitioned_numel
242
+
243
+ state_dict[name] = frozen_param_fragments[name]
244
+
245
+ if debug:
246
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
247
+
248
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
249
+
250
+
251
+ def _has_callable(obj, fn):
252
+ attr = getattr(obj, fn, None)
253
+ return callable(attr)
254
+
255
+
256
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
257
+ param_shapes = zero_model_states[0].param_shapes
258
+
259
+ # Reconstruction protocol:
260
+ #
261
+ # XXX: document this
262
+
263
+ if debug:
264
+ for i in range(world_size):
265
+ for j in range(len(fp32_flat_groups[0])):
266
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
267
+
268
+ # XXX: memory usage doubles here (zero2)
269
+ num_param_groups = len(fp32_flat_groups[0])
270
+ merged_single_partition_of_fp32_groups = []
271
+ for i in range(num_param_groups):
272
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
273
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
274
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
275
+ avail_numel = sum(
276
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
277
+
278
+ if debug:
279
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
280
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
281
+ # not asserting if there is a mismatch due to possible padding
282
+ print(f"Have {avail_numel} numels to process.")
283
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
284
+
285
+ # params
286
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
287
+ # out-of-core computing solution
288
+ total_numel = 0
289
+ total_params = 0
290
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
291
+ offset = 0
292
+ avail_numel = full_single_fp32_vector.numel()
293
+ for name, shape in shapes.items():
294
+
295
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
296
+ total_numel += unpartitioned_numel
297
+ total_params += 1
298
+
299
+ if debug:
300
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
301
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
302
+ offset += unpartitioned_numel
303
+
304
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
305
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
306
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
307
+ # live optimizer object, so we are checking that the numbers are within the right range
308
+ align_to = 2 * world_size
309
+
310
+ def zero2_align(x):
311
+ return align_to * math.ceil(x / align_to)
312
+
313
+ if debug:
314
+ print(f"original offset={offset}, avail_numel={avail_numel}")
315
+
316
+ offset = zero2_align(offset)
317
+ avail_numel = zero2_align(avail_numel)
318
+
319
+ if debug:
320
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
321
+
322
+ # Sanity check
323
+ if offset != avail_numel:
324
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
325
+
326
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
327
+
328
+
329
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states):
330
+ state_dict = OrderedDict()
331
+
332
+ # buffers
333
+ buffers = zero_model_states[0].buffers
334
+ state_dict.update(buffers)
335
+ if debug:
336
+ print(f"added {len(buffers)} buffers")
337
+
338
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
339
+
340
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
341
+
342
+ # recover shared parameters
343
+ for pair in zero_model_states[0].shared_params:
344
+ if pair[1] in state_dict:
345
+ state_dict[pair[0]] = state_dict[pair[1]]
346
+
347
+ return state_dict
348
+
349
+
350
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
351
+ remainder = unpartitioned_numel % world_size
352
+ padding_numel = (world_size - remainder) if remainder else 0
353
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
354
+ return partitioned_numel, padding_numel
355
+
356
+
357
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
358
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
359
+ return
360
+
361
+ if debug:
362
+ for i in range(world_size):
363
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
364
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
365
+
366
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
367
+ wanted_params = len(frozen_param_shapes)
368
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
369
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
370
+ print(f'Frozen params: Have {avail_numel} numels to process.')
371
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
372
+
373
+ total_params = 0
374
+ total_numel = 0
375
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
376
+ total_params += 1
377
+ unpartitioned_numel = shape.numel()
378
+ total_numel += unpartitioned_numel
379
+
380
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
381
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
382
+
383
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
384
+
385
+ if debug:
386
+ print(
387
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
388
+ )
389
+
390
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
391
+
392
+
393
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
394
+ param_shapes = zero_model_states[0].param_shapes
395
+ avail_numel = fp32_flat_groups[0].numel() * world_size
396
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
397
+ # param, re-consolidating each param, while dealing with padding if any
398
+
399
+ # merge list of dicts, preserving order
400
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
401
+
402
+ if debug:
403
+ for i in range(world_size):
404
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
405
+
406
+ wanted_params = len(param_shapes)
407
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
408
+ # not asserting if there is a mismatch due to possible padding
409
+ avail_numel = fp32_flat_groups[0].numel() * world_size
410
+ print(f"Trainable params: Have {avail_numel} numels to process.")
411
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
412
+
413
+ # params
414
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
415
+ # out-of-core computing solution
416
+ offset = 0
417
+ total_numel = 0
418
+ total_params = 0
419
+ for name, shape in param_shapes.items():
420
+
421
+ unpartitioned_numel = shape.numel()
422
+ total_numel += unpartitioned_numel
423
+ total_params += 1
424
+
425
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
426
+
427
+ if debug:
428
+ print(
429
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
430
+ )
431
+
432
+ # XXX: memory usage doubles here
433
+ state_dict[name] = torch.cat(
434
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
435
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
436
+ offset += partitioned_numel
437
+
438
+ offset *= world_size
439
+
440
+ # Sanity check
441
+ if offset != avail_numel:
442
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
443
+
444
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
445
+
446
+
447
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states):
448
+ state_dict = OrderedDict()
449
+
450
+ # buffers
451
+ buffers = zero_model_states[0].buffers
452
+ state_dict.update(buffers)
453
+ if debug:
454
+ print(f"added {len(buffers)} buffers")
455
+
456
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
457
+
458
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
459
+
460
+ # recover shared parameters
461
+ for pair in zero_model_states[0].shared_params:
462
+ if pair[1] in state_dict:
463
+ state_dict[pair[0]] = state_dict[pair[1]]
464
+
465
+ return state_dict
466
+
467
+
468
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
469
+ """
470
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
471
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
472
+ via a model hub.
473
+
474
+ Args:
475
+ - ``checkpoint_dir``: path to the desired checkpoint folder
476
+ - ``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``
477
+
478
+ Returns:
479
+ - pytorch ``state_dict``
480
+
481
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
482
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
483
+ the checkpoint.
484
+
485
+ A typical usage might be ::
486
+
487
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
488
+ # do the training and checkpoint saving
489
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
490
+ model = model.cpu() # move to cpu
491
+ model.load_state_dict(state_dict)
492
+ # submit to model hub or save the model to share with others
493
+
494
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
495
+ application. i.e. you will need to re-initialize the deepspeed engine, since
496
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
497
+
498
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
499
+
500
+ """
501
+ if tag is None:
502
+ latest_path = os.path.join(checkpoint_dir, 'latest')
503
+ if os.path.isfile(latest_path):
504
+ with open(latest_path, 'r') as fd:
505
+ tag = fd.read().strip()
506
+ else:
507
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
508
+
509
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
510
+
511
+ if not os.path.isdir(ds_checkpoint_dir):
512
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
513
+
514
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
515
+
516
+
517
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
518
+ """
519
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
520
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
521
+
522
+ Args:
523
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
524
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
525
+ - ``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``
526
+ """
527
+
528
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
529
+ print(f"Saving fp32 state dict to {output_file}")
530
+ torch.save(state_dict, output_file)
531
+
532
+
533
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
534
+ """
535
+ 1. Put the provided model to cpu
536
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
537
+ 3. Load it into the provided model
538
+
539
+ Args:
540
+ - ``model``: the model object to update
541
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
542
+ - ``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``
543
+
544
+ Returns:
545
+ - ``model`: modified model
546
+
547
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
548
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
549
+ conveniently placed for you in the checkpoint folder.
550
+
551
+ A typical usage might be ::
552
+
553
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
554
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
555
+ # submit to model hub or save the model to share with others
556
+
557
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
558
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
559
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
560
+
561
+ """
562
+ logger.info(f"Extracting fp32 weights")
563
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
564
+
565
+ logger.info(f"Overwriting model with fp32 weights")
566
+ model = model.cpu()
567
+ model.load_state_dict(state_dict, strict=False)
568
+
569
+ return model
570
+
571
+
572
+ if __name__ == "__main__":
573
+
574
+ parser = argparse.ArgumentParser()
575
+ parser.add_argument("checkpoint_dir",
576
+ type=str,
577
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
578
+ parser.add_argument(
579
+ "output_file",
580
+ type=str,
581
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
582
+ parser.add_argument("-t",
583
+ "--tag",
584
+ type=str,
585
+ default=None,
586
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
587
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
588
+ args = parser.parse_args()
589
+
590
+ debug = args.debug
591
+
592
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file, tag=args.tag)
checkpoint-55/README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ base_model: google/gemma-2b-it
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.9.0
checkpoint-55/adapter_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "google/gemma-2b-it",
5
+ "bias": "none",
6
+ "fan_in_fan_out": null,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layers_pattern": null,
10
+ "layers_to_transform": null,
11
+ "loftq_config": {},
12
+ "lora_alpha": 16,
13
+ "lora_dropout": 0.05,
14
+ "megatron_config": null,
15
+ "megatron_core": "megatron.core",
16
+ "modules_to_save": null,
17
+ "peft_type": "LORA",
18
+ "r": 32,
19
+ "rank_pattern": {},
20
+ "revision": null,
21
+ "target_modules": [
22
+ "down_proj",
23
+ "k_proj",
24
+ "up_proj",
25
+ "q_proj",
26
+ "v_proj",
27
+ "o_proj",
28
+ "gate_proj"
29
+ ],
30
+ "task_type": "CAUSAL_LM",
31
+ "use_dora": false,
32
+ "use_rslora": false
33
+ }
checkpoint-55/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d1edc3d855436f9861a042b87d27ef93f67d417404e2545f1ad57eda3ca69ff
3
+ size 78480320
checkpoint-55/global_step55/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:2104a313d2624e7f4ac5e557b557aa19c29fe5d005f33e824b341a0e7eaa48e5
3
+ size 58886423
checkpoint-55/global_step55/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:cefbaff50a0cc2ed1ad8d1066051df27eabbba05cb291eaeeeb18e78082d200f
3
+ size 58885463
checkpoint-55/global_step55/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:07741327312405bbfdb835ca082556e9ec5dba02c874ac98c49b8475b8040f9d
3
+ size 58886487
checkpoint-55/global_step55/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:c440b9c26a32e7e570f147fa8356307f748789400eaefc4b594c8c561c260c01
3
+ size 58885527
checkpoint-55/global_step55/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00511e35a1d4d0f7513c7ff2a4829d4c2204862cdc73180a03ad0d7b289ea754
3
+ size 1159049457
checkpoint-55/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step55
checkpoint-55/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8b2056fa67792ace30300b98f23b3ab3d644e32b902db24c352e0ab44404e78
3
+ size 17655
checkpoint-55/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a10faa18b876f22999c0fe0f8b3b63b8b85749c7015ceec8ad57f04b111a0272
3
+ size 17655
checkpoint-55/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73b99b0efd4d198d3cc9d21ee39ad07baaefe8c2a4cc4854481ab7f40faa9d90
3
+ size 17655