amphora commited on
Commit
1c90a1d
·
verified ·
1 Parent(s): f5de4a5

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 +4 -0
  2. README.md +175 -0
  3. added_tokens.json +24 -0
  4. checkpoint-107/added_tokens.json +24 -0
  5. checkpoint-107/config.json +31 -0
  6. checkpoint-107/generation_config.json +10 -0
  7. checkpoint-107/latest +1 -0
  8. checkpoint-107/merges.txt +0 -0
  9. checkpoint-107/model.safetensors +3 -0
  10. checkpoint-107/rng_state_0.pth +3 -0
  11. checkpoint-107/rng_state_1.pth +3 -0
  12. checkpoint-107/rng_state_2.pth +3 -0
  13. checkpoint-107/rng_state_3.pth +3 -0
  14. checkpoint-107/rng_state_4.pth +3 -0
  15. checkpoint-107/rng_state_5.pth +3 -0
  16. checkpoint-107/rng_state_6.pth +3 -0
  17. checkpoint-107/rng_state_7.pth +3 -0
  18. checkpoint-107/scheduler.pt +3 -0
  19. checkpoint-107/special_tokens_map.json +31 -0
  20. checkpoint-107/tokenizer.json +3 -0
  21. checkpoint-107/tokenizer_config.json +208 -0
  22. checkpoint-107/trainer_state.json +806 -0
  23. checkpoint-107/training_args.bin +3 -0
  24. checkpoint-107/vocab.json +0 -0
  25. checkpoint-107/zero_to_fp32.py +760 -0
  26. checkpoint-214/added_tokens.json +24 -0
  27. checkpoint-214/config.json +31 -0
  28. checkpoint-214/generation_config.json +10 -0
  29. checkpoint-214/latest +1 -0
  30. checkpoint-214/merges.txt +0 -0
  31. checkpoint-214/model.safetensors +3 -0
  32. checkpoint-214/rng_state_0.pth +3 -0
  33. checkpoint-214/rng_state_1.pth +3 -0
  34. checkpoint-214/rng_state_2.pth +3 -0
  35. checkpoint-214/rng_state_3.pth +3 -0
  36. checkpoint-214/rng_state_4.pth +3 -0
  37. checkpoint-214/rng_state_5.pth +3 -0
  38. checkpoint-214/rng_state_6.pth +3 -0
  39. checkpoint-214/rng_state_7.pth +3 -0
  40. checkpoint-214/scheduler.pt +3 -0
  41. checkpoint-214/special_tokens_map.json +31 -0
  42. checkpoint-214/tokenizer.json +3 -0
  43. checkpoint-214/tokenizer_config.json +208 -0
  44. checkpoint-214/trainer_state.json +1579 -0
  45. checkpoint-214/training_args.bin +3 -0
  46. checkpoint-214/vocab.json +0 -0
  47. checkpoint-214/zero_to_fp32.py +760 -0
  48. checkpoint-321/added_tokens.json +24 -0
  49. checkpoint-321/config.json +31 -0
  50. checkpoint-321/generation_config.json +10 -0
.gitattributes CHANGED
@@ -33,3 +33,7 @@ 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
+ checkpoint-107/tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ checkpoint-214/tokenizer.json filter=lfs diff=lfs merge=lfs -text
38
+ checkpoint-321/tokenizer.json filter=lfs diff=lfs merge=lfs -text
39
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ base_model: Qwen/Qwen2.5-Math-1.5B-Instruct
5
+ tags:
6
+ - generated_from_trainer
7
+ datasets:
8
+ - train.jsonl
9
+ model-index:
10
+ - name: outputs/out
11
+ results: []
12
+ ---
13
+
14
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
+ should probably proofread and complete it, then remove this comment. -->
16
+
17
+ [<img src="https://raw.githubusercontent.com/axolotl-ai-cloud/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/axolotl-ai-cloud/axolotl)
18
+ <details><summary>See axolotl config</summary>
19
+
20
+ axolotl version: `0.6.0`
21
+ ```yaml
22
+ base_model: Qwen/Qwen2.5-Math-1.5B-Instruct
23
+ model_type: AutoModelForCausalLM
24
+ tokenizer_type: AutoTokenizer
25
+ trust_remote_code: false
26
+
27
+ load_in_8bit: false
28
+ load_in_4bit: false
29
+ strict: false
30
+
31
+ output_dir: ./outputs/out
32
+ remove_unused_columns: false
33
+
34
+ chat_template: qwen_25
35
+ # chat_template: qwen_25
36
+ datasets:
37
+ - path: train.jsonl
38
+ type: chat_template
39
+ field_messages: messages
40
+ message_field_role: role
41
+ message_field_content: content
42
+ roles:
43
+ system:
44
+ -system
45
+ user:
46
+ - user
47
+ assistant:
48
+ - assistant
49
+
50
+ dataset_prepared_path: mr1-sft-1
51
+ # dataset_prepared_path: ko_r1
52
+ val_set_size: 0.005
53
+ eval_sample_packing: False
54
+
55
+ overrides_of_model_config:
56
+ # RoPE Scaling https://github.com/huggingface/transformers/pull/24653
57
+ rope_scaling:
58
+ type: linear
59
+ factor: 8.0
60
+
61
+ sequence_len: 32768
62
+ sample_packing: False
63
+ pad_to_sequence_len: False
64
+
65
+ wandb_project: MR1
66
+ wandb_entity:
67
+ wandb_watch:
68
+ wandb_name:
69
+ wandb_log_model:
70
+
71
+ plugins:
72
+ - axolotl.integrations.liger.LigerPlugin
73
+ liger_rope: true
74
+ liger_rms_norm: true
75
+ liger_swiglu: true
76
+ liger_fused_linear_cross_entropy: true
77
+
78
+ gradient_accumulation_steps: 32
79
+ micro_batch_size: 2
80
+ eval_batch_size: 1
81
+ num_epochs: 3
82
+ optimizer: paged_adamw_8bit
83
+ lr_scheduler: cosine
84
+ learning_rate: 2e-5
85
+
86
+ train_on_inputs: false
87
+ group_by_length: false
88
+ bf16: auto
89
+ fp16:
90
+ tf32: false
91
+
92
+ gradient_checkpointing: true
93
+ gradient_checkpointing_kwargs:
94
+ use_reentrant: false
95
+ early_stopping_patience:
96
+ resume_from_checkpoint:
97
+ logging_steps: 1
98
+ xformers_attention:
99
+ flash_attention: true
100
+
101
+ warmup_ratio: 0.05
102
+ evals_per_epoch: 3
103
+ eval_max_new_tokens: 128
104
+ eval_table_size:
105
+ saves_per_epoch: 1
106
+ debug:
107
+ deepspeed: deepspeed_configs/zero3_bf16.json
108
+ weight_decay: 0.01
109
+ fsdp:
110
+ fsdp_config:
111
+ special_tokens:
112
+ eos_token:
113
+
114
+ ```
115
+
116
+ </details><br>
117
+
118
+ # outputs/out
119
+
120
+ This model is a fine-tuned version of [Qwen/Qwen2.5-Math-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Math-1.5B-Instruct) on the train.jsonl dataset.
121
+ It achieves the following results on the evaluation set:
122
+ - Loss: 0.6320
123
+
124
+ ## Model description
125
+
126
+ More information needed
127
+
128
+ ## Intended uses & limitations
129
+
130
+ More information needed
131
+
132
+ ## Training and evaluation data
133
+
134
+ More information needed
135
+
136
+ ## Training procedure
137
+
138
+ ### Training hyperparameters
139
+
140
+ The following hyperparameters were used during training:
141
+ - learning_rate: 2e-05
142
+ - train_batch_size: 2
143
+ - eval_batch_size: 1
144
+ - seed: 42
145
+ - distributed_type: multi-GPU
146
+ - num_devices: 8
147
+ - gradient_accumulation_steps: 32
148
+ - total_train_batch_size: 512
149
+ - total_eval_batch_size: 8
150
+ - optimizer: Use OptimizerNames.PAGED_ADAMW_8BIT with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
151
+ - lr_scheduler_type: cosine
152
+ - lr_scheduler_warmup_steps: 16
153
+ - num_epochs: 3.0
154
+
155
+ ### Training results
156
+
157
+ | Training Loss | Epoch | Step | Validation Loss |
158
+ |:-------------:|:------:|:----:|:---------------:|
159
+ | 4.5461 | 0.0093 | 1 | 4.5535 |
160
+ | 1.4397 | 0.3362 | 36 | 1.3349 |
161
+ | 0.8795 | 0.6723 | 72 | 0.8389 |
162
+ | 0.7726 | 1.0 | 108 | 0.7298 |
163
+ | 0.7374 | 1.3362 | 144 | 0.6811 |
164
+ | 0.6928 | 1.6723 | 180 | 0.6554 |
165
+ | 0.6742 | 2.0 | 216 | 0.6418 |
166
+ | 0.691 | 2.3362 | 252 | 0.6349 |
167
+ | 0.6656 | 2.6723 | 288 | 0.6320 |
168
+
169
+
170
+ ### Framework versions
171
+
172
+ - Transformers 4.48.3
173
+ - Pytorch 2.5.1+cu121
174
+ - Datasets 3.2.0
175
+ - Tokenizers 0.21.0
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
checkpoint-107/added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
checkpoint-107/config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Qwen/Qwen2.5-Math-1.5B-Instruct",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "eos_token_id": 151645,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 1536,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 8960,
12
+ "max_position_embeddings": 32768,
13
+ "max_window_layers": 21,
14
+ "model_type": "qwen2",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 28,
17
+ "num_key_value_heads": 2,
18
+ "rms_norm_eps": 1e-06,
19
+ "rope_scaling": {
20
+ "factor": 8.0,
21
+ "type": "linear"
22
+ },
23
+ "rope_theta": 10000.0,
24
+ "sliding_window": null,
25
+ "tie_word_embeddings": true,
26
+ "torch_dtype": "bfloat16",
27
+ "transformers_version": "4.48.3",
28
+ "use_cache": false,
29
+ "use_sliding_window": false,
30
+ "vocab_size": 151665
31
+ }
checkpoint-107/generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "transformers_version": "4.48.3"
10
+ }
checkpoint-107/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step107
checkpoint-107/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-107/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c1a094ea230a47098ca36b3fb49d7978a92b4db7164e1a3d7dfb476de21bc1a
3
+ size 3086634632
checkpoint-107/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36d2a2034ebb05cb71c510897f2795b31164e50f17b270bc25d2be3ad9a17b22
3
+ size 15984
checkpoint-107/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:060dfdb1c49102cbdc8868a6031e68787601b4ccd782f3fb9b137e20c1fd2c7a
3
+ size 15984
checkpoint-107/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:af01895cb66e616591f2e4baa8dcd8151530eab133c73571ccb31c74f35422ce
3
+ size 15984
checkpoint-107/rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:677921992b1e0cef3aee776f245975003d22f51d9bd6ed20f248ded1deb72fa9
3
+ size 15984
checkpoint-107/rng_state_4.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d69353c629541c690c5471f8ec05fdab2bfecf3d37afaa436bc45939da6db68f
3
+ size 15984
checkpoint-107/rng_state_5.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e40ba6668cc03c9162c68a933d164bf38ae2d196a9a6fec03ae615491201185
3
+ size 15984
checkpoint-107/rng_state_6.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:870968fea834e24b2e099cf3e4fe1e3fb8caf38d8f8e5b790d7d47386d4d05f5
3
+ size 15984
checkpoint-107/rng_state_7.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e9e19618bee7c6ef43256fea25abe19bca88535eb1e7dc213cde8929ae4e8180
3
+ size 15984
checkpoint-107/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42ee68d968ce6cc761e6d17993c44cf45babb9f2ad94a6958480df12ec57fe36
3
+ size 1064
checkpoint-107/special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
checkpoint-107/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
checkpoint-107/tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "extra_special_tokens": {},
203
+ "model_max_length": 131072,
204
+ "pad_token": "<|endoftext|>",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
checkpoint-107/trainer_state.json ADDED
@@ -0,0 +1,806 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.9991245987744383,
5
+ "eval_steps": 36,
6
+ "global_step": 107,
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.009337613072658301,
13
+ "grad_norm": 0.6103967193596562,
14
+ "learning_rate": 1.25e-06,
15
+ "loss": 4.5461,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.009337613072658301,
20
+ "eval_loss": 4.553500175476074,
21
+ "eval_runtime": 16.4134,
22
+ "eval_samples_per_second": 16.816,
23
+ "eval_steps_per_second": 2.132,
24
+ "step": 1
25
+ },
26
+ {
27
+ "epoch": 0.018675226145316602,
28
+ "grad_norm": 0.6058263693172029,
29
+ "learning_rate": 2.5e-06,
30
+ "loss": 4.5365,
31
+ "step": 2
32
+ },
33
+ {
34
+ "epoch": 0.028012839217974907,
35
+ "grad_norm": 0.6061325195841676,
36
+ "learning_rate": 3.7500000000000005e-06,
37
+ "loss": 4.5438,
38
+ "step": 3
39
+ },
40
+ {
41
+ "epoch": 0.037350452290633204,
42
+ "grad_norm": 0.5966679918377138,
43
+ "learning_rate": 5e-06,
44
+ "loss": 4.5495,
45
+ "step": 4
46
+ },
47
+ {
48
+ "epoch": 0.04668806536329151,
49
+ "grad_norm": 0.5637877145545853,
50
+ "learning_rate": 6.25e-06,
51
+ "loss": 4.4744,
52
+ "step": 5
53
+ },
54
+ {
55
+ "epoch": 0.05602567843594981,
56
+ "grad_norm": 0.4955765028851229,
57
+ "learning_rate": 7.500000000000001e-06,
58
+ "loss": 4.3581,
59
+ "step": 6
60
+ },
61
+ {
62
+ "epoch": 0.06536329150860812,
63
+ "grad_norm": 0.33161457169025776,
64
+ "learning_rate": 8.750000000000001e-06,
65
+ "loss": 3.9768,
66
+ "step": 7
67
+ },
68
+ {
69
+ "epoch": 0.07470090458126641,
70
+ "grad_norm": 0.30498618054818755,
71
+ "learning_rate": 1e-05,
72
+ "loss": 3.9306,
73
+ "step": 8
74
+ },
75
+ {
76
+ "epoch": 0.08403851765392471,
77
+ "grad_norm": 0.3418457910893006,
78
+ "learning_rate": 1.125e-05,
79
+ "loss": 3.6729,
80
+ "step": 9
81
+ },
82
+ {
83
+ "epoch": 0.09337613072658302,
84
+ "grad_norm": 0.3051650090830193,
85
+ "learning_rate": 1.25e-05,
86
+ "loss": 3.5839,
87
+ "step": 10
88
+ },
89
+ {
90
+ "epoch": 0.10271374379924132,
91
+ "grad_norm": 0.2540841556589586,
92
+ "learning_rate": 1.375e-05,
93
+ "loss": 3.4916,
94
+ "step": 11
95
+ },
96
+ {
97
+ "epoch": 0.11205135687189963,
98
+ "grad_norm": 0.2523065620988122,
99
+ "learning_rate": 1.5000000000000002e-05,
100
+ "loss": 3.3087,
101
+ "step": 12
102
+ },
103
+ {
104
+ "epoch": 0.12138896994455792,
105
+ "grad_norm": 0.20081817150865616,
106
+ "learning_rate": 1.6250000000000002e-05,
107
+ "loss": 3.1931,
108
+ "step": 13
109
+ },
110
+ {
111
+ "epoch": 0.13072658301721624,
112
+ "grad_norm": 0.1823149251708444,
113
+ "learning_rate": 1.7500000000000002e-05,
114
+ "loss": 3.1415,
115
+ "step": 14
116
+ },
117
+ {
118
+ "epoch": 0.14006419608987453,
119
+ "grad_norm": 0.15949645404615334,
120
+ "learning_rate": 1.8750000000000002e-05,
121
+ "loss": 3.0393,
122
+ "step": 15
123
+ },
124
+ {
125
+ "epoch": 0.14940180916253282,
126
+ "grad_norm": 0.1325611844716812,
127
+ "learning_rate": 2e-05,
128
+ "loss": 2.8927,
129
+ "step": 16
130
+ },
131
+ {
132
+ "epoch": 0.15873942223519114,
133
+ "grad_norm": 0.11464751241192053,
134
+ "learning_rate": 1.9999469523400122e-05,
135
+ "loss": 2.7378,
136
+ "step": 17
137
+ },
138
+ {
139
+ "epoch": 0.16807703530784943,
140
+ "grad_norm": 0.1070431164754716,
141
+ "learning_rate": 1.9997878149881576e-05,
142
+ "loss": 2.6558,
143
+ "step": 18
144
+ },
145
+ {
146
+ "epoch": 0.17741464838050774,
147
+ "grad_norm": 0.10433083170549438,
148
+ "learning_rate": 1.999522604828164e-05,
149
+ "loss": 2.534,
150
+ "step": 19
151
+ },
152
+ {
153
+ "epoch": 0.18675226145316604,
154
+ "grad_norm": 0.10117296773389844,
155
+ "learning_rate": 1.9991513499975883e-05,
156
+ "loss": 2.4259,
157
+ "step": 20
158
+ },
159
+ {
160
+ "epoch": 0.19608987452582433,
161
+ "grad_norm": 0.09323265692759455,
162
+ "learning_rate": 1.9986740898848306e-05,
163
+ "loss": 2.3488,
164
+ "step": 21
165
+ },
166
+ {
167
+ "epoch": 0.20542748759848264,
168
+ "grad_norm": 0.07868283241281675,
169
+ "learning_rate": 1.9980908751249556e-05,
170
+ "loss": 2.2658,
171
+ "step": 22
172
+ },
173
+ {
174
+ "epoch": 0.21476510067114093,
175
+ "grad_norm": 0.07548690533550786,
176
+ "learning_rate": 1.997401767594319e-05,
177
+ "loss": 2.1874,
178
+ "step": 23
179
+ },
180
+ {
181
+ "epoch": 0.22410271374379925,
182
+ "grad_norm": 0.07720457793760661,
183
+ "learning_rate": 1.996606840404006e-05,
184
+ "loss": 2.0998,
185
+ "step": 24
186
+ },
187
+ {
188
+ "epoch": 0.23344032681645754,
189
+ "grad_norm": 0.07639897047393754,
190
+ "learning_rate": 1.9957061778920703e-05,
191
+ "loss": 2.0469,
192
+ "step": 25
193
+ },
194
+ {
195
+ "epoch": 0.24277793988911583,
196
+ "grad_norm": 0.07016046755367683,
197
+ "learning_rate": 1.9946998756145894e-05,
198
+ "loss": 1.9562,
199
+ "step": 26
200
+ },
201
+ {
202
+ "epoch": 0.2521155529617741,
203
+ "grad_norm": 0.06084064670530258,
204
+ "learning_rate": 1.9935880403355255e-05,
205
+ "loss": 1.8943,
206
+ "step": 27
207
+ },
208
+ {
209
+ "epoch": 0.26145316603443247,
210
+ "grad_norm": 0.05530834717342951,
211
+ "learning_rate": 1.9923707900153984e-05,
212
+ "loss": 1.7771,
213
+ "step": 28
214
+ },
215
+ {
216
+ "epoch": 0.27079077910709076,
217
+ "grad_norm": 0.05296398833585214,
218
+ "learning_rate": 1.9910482537987704e-05,
219
+ "loss": 1.7624,
220
+ "step": 29
221
+ },
222
+ {
223
+ "epoch": 0.28012839217974905,
224
+ "grad_norm": 0.05206178996458072,
225
+ "learning_rate": 1.989620572000544e-05,
226
+ "loss": 1.6848,
227
+ "step": 30
228
+ },
229
+ {
230
+ "epoch": 0.28946600525240734,
231
+ "grad_norm": 0.050431830710485716,
232
+ "learning_rate": 1.9880878960910772e-05,
233
+ "loss": 1.6577,
234
+ "step": 31
235
+ },
236
+ {
237
+ "epoch": 0.29880361832506563,
238
+ "grad_norm": 0.04760195929852826,
239
+ "learning_rate": 1.9864503886801108e-05,
240
+ "loss": 1.6128,
241
+ "step": 32
242
+ },
243
+ {
244
+ "epoch": 0.308141231397724,
245
+ "grad_norm": 0.04482797539629353,
246
+ "learning_rate": 1.9847082234995172e-05,
247
+ "loss": 1.5791,
248
+ "step": 33
249
+ },
250
+ {
251
+ "epoch": 0.31747884447038227,
252
+ "grad_norm": 0.04130893521590142,
253
+ "learning_rate": 1.982861585384869e-05,
254
+ "loss": 1.5063,
255
+ "step": 34
256
+ },
257
+ {
258
+ "epoch": 0.32681645754304056,
259
+ "grad_norm": 0.04057758728502848,
260
+ "learning_rate": 1.9809106702558277e-05,
261
+ "loss": 1.4877,
262
+ "step": 35
263
+ },
264
+ {
265
+ "epoch": 0.33615407061569885,
266
+ "grad_norm": 0.038180219331760724,
267
+ "learning_rate": 1.978855685095358e-05,
268
+ "loss": 1.4397,
269
+ "step": 36
270
+ },
271
+ {
272
+ "epoch": 0.33615407061569885,
273
+ "eval_loss": 1.3349355459213257,
274
+ "eval_runtime": 16.413,
275
+ "eval_samples_per_second": 16.816,
276
+ "eval_steps_per_second": 2.132,
277
+ "step": 36
278
+ },
279
+ {
280
+ "epoch": 0.34549168368835714,
281
+ "grad_norm": 0.0360323358530499,
282
+ "learning_rate": 1.9766968479277684e-05,
283
+ "loss": 1.3977,
284
+ "step": 37
285
+ },
286
+ {
287
+ "epoch": 0.3548292967610155,
288
+ "grad_norm": 0.035146043601200425,
289
+ "learning_rate": 1.974434387795579e-05,
290
+ "loss": 1.418,
291
+ "step": 38
292
+ },
293
+ {
294
+ "epoch": 0.3641669098336738,
295
+ "grad_norm": 0.033121913235728655,
296
+ "learning_rate": 1.972068544735221e-05,
297
+ "loss": 1.3359,
298
+ "step": 39
299
+ },
300
+ {
301
+ "epoch": 0.37350452290633207,
302
+ "grad_norm": 0.031036722451915032,
303
+ "learning_rate": 1.969599569751571e-05,
304
+ "loss": 1.3401,
305
+ "step": 40
306
+ },
307
+ {
308
+ "epoch": 0.38284213597899036,
309
+ "grad_norm": 0.030669047831503912,
310
+ "learning_rate": 1.9670277247913205e-05,
311
+ "loss": 1.2638,
312
+ "step": 41
313
+ },
314
+ {
315
+ "epoch": 0.39217974905164865,
316
+ "grad_norm": 0.03002785386211285,
317
+ "learning_rate": 1.964353282715183e-05,
318
+ "loss": 1.2649,
319
+ "step": 42
320
+ },
321
+ {
322
+ "epoch": 0.401517362124307,
323
+ "grad_norm": 0.02817025139456513,
324
+ "learning_rate": 1.961576527268946e-05,
325
+ "loss": 1.2476,
326
+ "step": 43
327
+ },
328
+ {
329
+ "epoch": 0.4108549751969653,
330
+ "grad_norm": 0.03110381051330927,
331
+ "learning_rate": 1.9586977530533677e-05,
332
+ "loss": 1.1923,
333
+ "step": 44
334
+ },
335
+ {
336
+ "epoch": 0.4201925882696236,
337
+ "grad_norm": 0.031162812150372473,
338
+ "learning_rate": 1.95571726549292e-05,
339
+ "loss": 1.2044,
340
+ "step": 45
341
+ },
342
+ {
343
+ "epoch": 0.42953020134228187,
344
+ "grad_norm": 0.029584239693380046,
345
+ "learning_rate": 1.9526353808033827e-05,
346
+ "loss": 1.1764,
347
+ "step": 46
348
+ },
349
+ {
350
+ "epoch": 0.43886781441494016,
351
+ "grad_norm": 0.027540684267770742,
352
+ "learning_rate": 1.9494524259582994e-05,
353
+ "loss": 1.1634,
354
+ "step": 47
355
+ },
356
+ {
357
+ "epoch": 0.4482054274875985,
358
+ "grad_norm": 0.028821860863637565,
359
+ "learning_rate": 1.9461687386542826e-05,
360
+ "loss": 1.1426,
361
+ "step": 48
362
+ },
363
+ {
364
+ "epoch": 0.4575430405602568,
365
+ "grad_norm": 0.027945951918964533,
366
+ "learning_rate": 1.9427846672751873e-05,
367
+ "loss": 1.1154,
368
+ "step": 49
369
+ },
370
+ {
371
+ "epoch": 0.4668806536329151,
372
+ "grad_norm": 0.026881160663849425,
373
+ "learning_rate": 1.93930057085515e-05,
374
+ "loss": 1.0981,
375
+ "step": 50
376
+ },
377
+ {
378
+ "epoch": 0.4762182667055734,
379
+ "grad_norm": 0.025002230522002903,
380
+ "learning_rate": 1.9357168190404937e-05,
381
+ "loss": 1.0873,
382
+ "step": 51
383
+ },
384
+ {
385
+ "epoch": 0.48555587977823167,
386
+ "grad_norm": 0.02318894097448886,
387
+ "learning_rate": 1.932033792050515e-05,
388
+ "loss": 1.0701,
389
+ "step": 52
390
+ },
391
+ {
392
+ "epoch": 0.49489349285089,
393
+ "grad_norm": 0.021872991266037325,
394
+ "learning_rate": 1.928251880637141e-05,
395
+ "loss": 1.0439,
396
+ "step": 53
397
+ },
398
+ {
399
+ "epoch": 0.5042311059235483,
400
+ "grad_norm": 0.021369213964442125,
401
+ "learning_rate": 1.924371486043473e-05,
402
+ "loss": 1.062,
403
+ "step": 54
404
+ },
405
+ {
406
+ "epoch": 0.5135687189962066,
407
+ "grad_norm": 0.02074830989778219,
408
+ "learning_rate": 1.920393019961217e-05,
409
+ "loss": 1.0392,
410
+ "step": 55
411
+ },
412
+ {
413
+ "epoch": 0.5229063320688649,
414
+ "grad_norm": 0.020345018132100934,
415
+ "learning_rate": 1.916316904487005e-05,
416
+ "loss": 1.02,
417
+ "step": 56
418
+ },
419
+ {
420
+ "epoch": 0.5322439451415232,
421
+ "grad_norm": 0.01970957719141645,
422
+ "learning_rate": 1.9121435720776122e-05,
423
+ "loss": 0.9923,
424
+ "step": 57
425
+ },
426
+ {
427
+ "epoch": 0.5415815582141815,
428
+ "grad_norm": 0.019741562276937644,
429
+ "learning_rate": 1.9078734655040763e-05,
430
+ "loss": 0.9993,
431
+ "step": 58
432
+ },
433
+ {
434
+ "epoch": 0.5509191712868398,
435
+ "grad_norm": 0.0195142739708107,
436
+ "learning_rate": 1.9035070378047204e-05,
437
+ "loss": 0.9943,
438
+ "step": 59
439
+ },
440
+ {
441
+ "epoch": 0.5602567843594981,
442
+ "grad_norm": 0.017297498916208055,
443
+ "learning_rate": 1.8990447522370886e-05,
444
+ "loss": 0.9753,
445
+ "step": 60
446
+ },
447
+ {
448
+ "epoch": 0.5695943974321565,
449
+ "grad_norm": 0.01658779952035472,
450
+ "learning_rate": 1.8944870822287957e-05,
451
+ "loss": 0.9883,
452
+ "step": 61
453
+ },
454
+ {
455
+ "epoch": 0.5789320105048147,
456
+ "grad_norm": 0.018530815854782102,
457
+ "learning_rate": 1.8898345113273e-05,
458
+ "loss": 0.9482,
459
+ "step": 62
460
+ },
461
+ {
462
+ "epoch": 0.588269623577473,
463
+ "grad_norm": 0.017748842064851857,
464
+ "learning_rate": 1.8850875331485996e-05,
465
+ "loss": 0.9533,
466
+ "step": 63
467
+ },
468
+ {
469
+ "epoch": 0.5976072366501313,
470
+ "grad_norm": 0.016871546397150952,
471
+ "learning_rate": 1.8802466513248635e-05,
472
+ "loss": 0.948,
473
+ "step": 64
474
+ },
475
+ {
476
+ "epoch": 0.6069448497227896,
477
+ "grad_norm": 0.01608669807726683,
478
+ "learning_rate": 1.8753123794509974e-05,
479
+ "loss": 0.9295,
480
+ "step": 65
481
+ },
482
+ {
483
+ "epoch": 0.616282462795448,
484
+ "grad_norm": 0.017453769141315367,
485
+ "learning_rate": 1.8702852410301556e-05,
486
+ "loss": 0.9198,
487
+ "step": 66
488
+ },
489
+ {
490
+ "epoch": 0.6256200758681062,
491
+ "grad_norm": 0.017655286026566987,
492
+ "learning_rate": 1.865165769418196e-05,
493
+ "loss": 0.9535,
494
+ "step": 67
495
+ },
496
+ {
497
+ "epoch": 0.6349576889407645,
498
+ "grad_norm": 0.017498254303415152,
499
+ "learning_rate": 1.8599545077670983e-05,
500
+ "loss": 0.9278,
501
+ "step": 68
502
+ },
503
+ {
504
+ "epoch": 0.6442953020134228,
505
+ "grad_norm": 0.01573094552466445,
506
+ "learning_rate": 1.854652008967335e-05,
507
+ "loss": 0.912,
508
+ "step": 69
509
+ },
510
+ {
511
+ "epoch": 0.6536329150860811,
512
+ "grad_norm": 0.015035283908585596,
513
+ "learning_rate": 1.8492588355892125e-05,
514
+ "loss": 0.9182,
515
+ "step": 70
516
+ },
517
+ {
518
+ "epoch": 0.6629705281587395,
519
+ "grad_norm": 0.01593275185300073,
520
+ "learning_rate": 1.8437755598231857e-05,
521
+ "loss": 0.9109,
522
+ "step": 71
523
+ },
524
+ {
525
+ "epoch": 0.6723081412313977,
526
+ "grad_norm": 0.014842299347889509,
527
+ "learning_rate": 1.8382027634191523e-05,
528
+ "loss": 0.8795,
529
+ "step": 72
530
+ },
531
+ {
532
+ "epoch": 0.6723081412313977,
533
+ "eval_loss": 0.8388988375663757,
534
+ "eval_runtime": 16.5273,
535
+ "eval_samples_per_second": 16.7,
536
+ "eval_steps_per_second": 2.118,
537
+ "step": 72
538
+ },
539
+ {
540
+ "epoch": 0.681645754304056,
541
+ "grad_norm": 0.015086756882680958,
542
+ "learning_rate": 1.8325410376247295e-05,
543
+ "loss": 0.8793,
544
+ "step": 73
545
+ },
546
+ {
547
+ "epoch": 0.6909833673767143,
548
+ "grad_norm": 0.014400642274755383,
549
+ "learning_rate": 1.826790983122527e-05,
550
+ "loss": 0.9139,
551
+ "step": 74
552
+ },
553
+ {
554
+ "epoch": 0.7003209804493726,
555
+ "grad_norm": 0.013490998034899438,
556
+ "learning_rate": 1.8209532099664177e-05,
557
+ "loss": 0.8767,
558
+ "step": 75
559
+ },
560
+ {
561
+ "epoch": 0.709658593522031,
562
+ "grad_norm": 0.011444201595399665,
563
+ "learning_rate": 1.8150283375168112e-05,
564
+ "loss": 0.8525,
565
+ "step": 76
566
+ },
567
+ {
568
+ "epoch": 0.7189962065946892,
569
+ "grad_norm": 0.01133323463508391,
570
+ "learning_rate": 1.8090169943749477e-05,
571
+ "loss": 0.8658,
572
+ "step": 77
573
+ },
574
+ {
575
+ "epoch": 0.7283338196673476,
576
+ "grad_norm": 0.011984830212373445,
577
+ "learning_rate": 1.8029198183162e-05,
578
+ "loss": 0.856,
579
+ "step": 78
580
+ },
581
+ {
582
+ "epoch": 0.7376714327400058,
583
+ "grad_norm": 0.01217011221195066,
584
+ "learning_rate": 1.796737456222413e-05,
585
+ "loss": 0.8892,
586
+ "step": 79
587
+ },
588
+ {
589
+ "epoch": 0.7470090458126641,
590
+ "grad_norm": 0.012510369655517745,
591
+ "learning_rate": 1.7904705640132717e-05,
592
+ "loss": 0.8562,
593
+ "step": 80
594
+ },
595
+ {
596
+ "epoch": 0.7563466588853225,
597
+ "grad_norm": 0.011806935544189488,
598
+ "learning_rate": 1.7841198065767107e-05,
599
+ "loss": 0.8644,
600
+ "step": 81
601
+ },
602
+ {
603
+ "epoch": 0.7656842719579807,
604
+ "grad_norm": 0.011433541340869584,
605
+ "learning_rate": 1.7776858576983713e-05,
606
+ "loss": 0.8692,
607
+ "step": 82
608
+ },
609
+ {
610
+ "epoch": 0.7750218850306391,
611
+ "grad_norm": 0.012566348663586087,
612
+ "learning_rate": 1.771169399990119e-05,
613
+ "loss": 0.8541,
614
+ "step": 83
615
+ },
616
+ {
617
+ "epoch": 0.7843594981032973,
618
+ "grad_norm": 0.01072107470914378,
619
+ "learning_rate": 1.7645711248176198e-05,
620
+ "loss": 0.8403,
621
+ "step": 84
622
+ },
623
+ {
624
+ "epoch": 0.7936971111759556,
625
+ "grad_norm": 0.010617575681982286,
626
+ "learning_rate": 1.7578917322269885e-05,
627
+ "loss": 0.81,
628
+ "step": 85
629
+ },
630
+ {
631
+ "epoch": 0.803034724248614,
632
+ "grad_norm": 0.010466741230697605,
633
+ "learning_rate": 1.7511319308705198e-05,
634
+ "loss": 0.8253,
635
+ "step": 86
636
+ },
637
+ {
638
+ "epoch": 0.8123723373212722,
639
+ "grad_norm": 0.010184306281966645,
640
+ "learning_rate": 1.744292437931502e-05,
641
+ "loss": 0.8526,
642
+ "step": 87
643
+ },
644
+ {
645
+ "epoch": 0.8217099503939306,
646
+ "grad_norm": 0.009850665553519504,
647
+ "learning_rate": 1.7373739790481263e-05,
648
+ "loss": 0.8304,
649
+ "step": 88
650
+ },
651
+ {
652
+ "epoch": 0.8310475634665888,
653
+ "grad_norm": 0.009236577038055978,
654
+ "learning_rate": 1.7303772882365018e-05,
655
+ "loss": 0.7908,
656
+ "step": 89
657
+ },
658
+ {
659
+ "epoch": 0.8403851765392472,
660
+ "grad_norm": 0.03711865800548727,
661
+ "learning_rate": 1.723303107812779e-05,
662
+ "loss": 0.8085,
663
+ "step": 90
664
+ },
665
+ {
666
+ "epoch": 0.8497227896119055,
667
+ "grad_norm": 0.010517236470326855,
668
+ "learning_rate": 1.7161521883143936e-05,
669
+ "loss": 0.8313,
670
+ "step": 91
671
+ },
672
+ {
673
+ "epoch": 0.8590604026845637,
674
+ "grad_norm": 0.011238580368575812,
675
+ "learning_rate": 1.7089252884204376e-05,
676
+ "loss": 0.814,
677
+ "step": 92
678
+ },
679
+ {
680
+ "epoch": 0.8683980157572221,
681
+ "grad_norm": 0.009935862606933948,
682
+ "learning_rate": 1.701623174871168e-05,
683
+ "loss": 0.8032,
684
+ "step": 93
685
+ },
686
+ {
687
+ "epoch": 0.8777356288298803,
688
+ "grad_norm": 0.009655128505771573,
689
+ "learning_rate": 1.6942466223866582e-05,
690
+ "loss": 0.8013,
691
+ "step": 94
692
+ },
693
+ {
694
+ "epoch": 0.8870732419025387,
695
+ "grad_norm": 0.010463930618313586,
696
+ "learning_rate": 1.6867964135846043e-05,
697
+ "loss": 0.8116,
698
+ "step": 95
699
+ },
700
+ {
701
+ "epoch": 0.896410854975197,
702
+ "grad_norm": 0.009360797680160574,
703
+ "learning_rate": 1.679273338897293e-05,
704
+ "loss": 0.8064,
705
+ "step": 96
706
+ },
707
+ {
708
+ "epoch": 0.9057484680478552,
709
+ "grad_norm": 0.00968251573081083,
710
+ "learning_rate": 1.6716781964877413e-05,
711
+ "loss": 0.8208,
712
+ "step": 97
713
+ },
714
+ {
715
+ "epoch": 0.9150860811205136,
716
+ "grad_norm": 0.009894122849502883,
717
+ "learning_rate": 1.664011792165012e-05,
718
+ "loss": 0.8042,
719
+ "step": 98
720
+ },
721
+ {
722
+ "epoch": 0.9244236941931718,
723
+ "grad_norm": 0.010626027391586145,
724
+ "learning_rate": 1.6562749392987255e-05,
725
+ "loss": 0.8037,
726
+ "step": 99
727
+ },
728
+ {
729
+ "epoch": 0.9337613072658302,
730
+ "grad_norm": 0.01083144628829605,
731
+ "learning_rate": 1.648468458732762e-05,
732
+ "loss": 0.8079,
733
+ "step": 100
734
+ },
735
+ {
736
+ "epoch": 0.9430989203384885,
737
+ "grad_norm": 0.012651590456989211,
738
+ "learning_rate": 1.6405931786981753e-05,
739
+ "loss": 0.7903,
740
+ "step": 101
741
+ },
742
+ {
743
+ "epoch": 0.9524365334111468,
744
+ "grad_norm": 0.010619166674062264,
745
+ "learning_rate": 1.6326499347253206e-05,
746
+ "loss": 0.7783,
747
+ "step": 102
748
+ },
749
+ {
750
+ "epoch": 0.9617741464838051,
751
+ "grad_norm": 0.009320303165881526,
752
+ "learning_rate": 1.6246395695552086e-05,
753
+ "loss": 0.8035,
754
+ "step": 103
755
+ },
756
+ {
757
+ "epoch": 0.9711117595564633,
758
+ "grad_norm": 0.009094019045947338,
759
+ "learning_rate": 1.6165629330500952e-05,
760
+ "loss": 0.7839,
761
+ "step": 104
762
+ },
763
+ {
764
+ "epoch": 0.9804493726291217,
765
+ "grad_norm": 0.009044004451355656,
766
+ "learning_rate": 1.6084208821033152e-05,
767
+ "loss": 0.7641,
768
+ "step": 105
769
+ },
770
+ {
771
+ "epoch": 0.98978698570178,
772
+ "grad_norm": 0.009202270165387296,
773
+ "learning_rate": 1.6002142805483686e-05,
774
+ "loss": 0.7666,
775
+ "step": 106
776
+ },
777
+ {
778
+ "epoch": 0.9991245987744383,
779
+ "grad_norm": 0.009577150303950122,
780
+ "learning_rate": 1.591943999067273e-05,
781
+ "loss": 0.7869,
782
+ "step": 107
783
+ }
784
+ ],
785
+ "logging_steps": 1,
786
+ "max_steps": 321,
787
+ "num_input_tokens_seen": 0,
788
+ "num_train_epochs": 3,
789
+ "save_steps": 107,
790
+ "stateful_callbacks": {
791
+ "TrainerControl": {
792
+ "args": {
793
+ "should_epoch_stop": false,
794
+ "should_evaluate": false,
795
+ "should_log": false,
796
+ "should_save": true,
797
+ "should_training_stop": false
798
+ },
799
+ "attributes": {}
800
+ }
801
+ },
802
+ "total_flos": 3.037539103106138e+18,
803
+ "train_batch_size": 2,
804
+ "trial_name": null,
805
+ "trial_params": null
806
+ }
checkpoint-107/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c22096e6a9c9dea84f12ad6313d09723c960a987f46ad9af04dc6c1de407c91
3
+ size 10872
checkpoint-107/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-107/zero_to_fp32.py ADDED
@@ -0,0 +1,760 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example:
14
+ # python zero_to_fp32.py . output_dir/
15
+ # or
16
+ # python zero_to_fp32.py . output_dir/ --safe_serialization
17
+
18
+ import argparse
19
+ import torch
20
+ import glob
21
+ import math
22
+ import os
23
+ import re
24
+ import gc
25
+ import json
26
+ import numpy as np
27
+ from tqdm import tqdm
28
+ from collections import OrderedDict
29
+ from dataclasses import dataclass
30
+
31
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
32
+ # DeepSpeed data structures it has to be available in the current python environment.
33
+ from deepspeed.utils import logger
34
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
35
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
36
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
37
+
38
+
39
+ @dataclass
40
+ class zero_model_state:
41
+ buffers: dict()
42
+ param_shapes: dict()
43
+ shared_params: list
44
+ ds_version: int
45
+ frozen_param_shapes: dict()
46
+ frozen_param_fragments: dict()
47
+
48
+
49
+ debug = 0
50
+
51
+ # load to cpu
52
+ device = torch.device('cpu')
53
+
54
+
55
+ def atoi(text):
56
+ return int(text) if text.isdigit() else text
57
+
58
+
59
+ def natural_keys(text):
60
+ '''
61
+ alist.sort(key=natural_keys) sorts in human order
62
+ http://nedbatchelder.com/blog/200712/human_sorting.html
63
+ (See Toothy's implementation in the comments)
64
+ '''
65
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
66
+
67
+
68
+ def get_model_state_file(checkpoint_dir, zero_stage):
69
+ if not os.path.isdir(checkpoint_dir):
70
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
71
+
72
+ # there should be only one file
73
+ if zero_stage <= 2:
74
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
75
+ elif zero_stage == 3:
76
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
77
+
78
+ if not os.path.exists(file):
79
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
80
+
81
+ return file
82
+
83
+
84
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
85
+ # XXX: need to test that this simple glob rule works for multi-node setup too
86
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
87
+
88
+ if len(ckpt_files) == 0:
89
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
90
+
91
+ return ckpt_files
92
+
93
+
94
+ def get_optim_files(checkpoint_dir):
95
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
96
+
97
+
98
+ def get_model_state_files(checkpoint_dir):
99
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
100
+
101
+
102
+ def parse_model_states(files):
103
+ zero_model_states = []
104
+ for file in files:
105
+ state_dict = torch.load(file, map_location=device, weights_only=False)
106
+
107
+ if BUFFER_NAMES not in state_dict:
108
+ raise ValueError(f"{file} is not a model state checkpoint")
109
+ buffer_names = state_dict[BUFFER_NAMES]
110
+ if debug:
111
+ print("Found buffers:", buffer_names)
112
+
113
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
114
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
115
+ param_shapes = state_dict[PARAM_SHAPES]
116
+
117
+ # collect parameters that are included in param_shapes
118
+ param_names = []
119
+ for s in param_shapes:
120
+ for name in s.keys():
121
+ param_names.append(name)
122
+
123
+ # update with frozen parameters
124
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
125
+ if frozen_param_shapes is not None:
126
+ if debug:
127
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
128
+ param_names += list(frozen_param_shapes.keys())
129
+
130
+ # handle shared params
131
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
132
+
133
+ ds_version = state_dict.get(DS_VERSION, None)
134
+
135
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
136
+
137
+ z_model_state = zero_model_state(buffers=buffers,
138
+ param_shapes=param_shapes,
139
+ shared_params=shared_params,
140
+ ds_version=ds_version,
141
+ frozen_param_shapes=frozen_param_shapes,
142
+ frozen_param_fragments=frozen_param_fragments)
143
+ zero_model_states.append(z_model_state)
144
+
145
+ return zero_model_states
146
+
147
+
148
+ def parse_optim_states(files, ds_checkpoint_dir):
149
+ total_files = len(files)
150
+ state_dicts = []
151
+ for f in tqdm(files, desc='Loading checkpoint shards'):
152
+ state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
153
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
154
+ # and also handle the case where it was already removed by another helper script
155
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
156
+ state_dicts.append(state_dict)
157
+
158
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
159
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
160
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
161
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
162
+
163
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
164
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
165
+ # use the max of the partition_count to get the dp world_size.
166
+
167
+ if type(world_size) is list:
168
+ world_size = max(world_size)
169
+
170
+ if world_size != total_files:
171
+ raise ValueError(
172
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
173
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
174
+ )
175
+
176
+ # the groups are named differently in each stage
177
+ if zero_stage <= 2:
178
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
179
+ elif zero_stage == 3:
180
+ fp32_groups_key = FP32_FLAT_GROUPS
181
+ else:
182
+ raise ValueError(f"unknown zero stage {zero_stage}")
183
+
184
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
185
+ return zero_stage, world_size, fp32_flat_groups
186
+
187
+
188
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
189
+ """
190
+ Returns fp32 state_dict reconstructed from ds checkpoint
191
+
192
+ Args:
193
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
194
+
195
+ """
196
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
197
+
198
+ optim_files = get_optim_files(ds_checkpoint_dir)
199
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
200
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
201
+
202
+ model_files = get_model_state_files(ds_checkpoint_dir)
203
+
204
+ zero_model_states = parse_model_states(model_files)
205
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
206
+
207
+ if zero_stage <= 2:
208
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
209
+ exclude_frozen_parameters)
210
+ elif zero_stage == 3:
211
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
212
+ exclude_frozen_parameters)
213
+
214
+
215
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
216
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
217
+ return
218
+
219
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
220
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
221
+
222
+ if debug:
223
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
224
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
225
+
226
+ wanted_params = len(frozen_param_shapes)
227
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
228
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
229
+ print(f'Frozen params: Have {avail_numel} numels to process.')
230
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
231
+
232
+ total_params = 0
233
+ total_numel = 0
234
+ for name, shape in frozen_param_shapes.items():
235
+ total_params += 1
236
+ unpartitioned_numel = shape.numel()
237
+ total_numel += unpartitioned_numel
238
+
239
+ state_dict[name] = frozen_param_fragments[name]
240
+
241
+ if debug:
242
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
243
+
244
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
245
+
246
+
247
+ def _has_callable(obj, fn):
248
+ attr = getattr(obj, fn, None)
249
+ return callable(attr)
250
+
251
+
252
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
253
+ param_shapes = zero_model_states[0].param_shapes
254
+
255
+ # Reconstruction protocol:
256
+ #
257
+ # XXX: document this
258
+
259
+ if debug:
260
+ for i in range(world_size):
261
+ for j in range(len(fp32_flat_groups[0])):
262
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
263
+
264
+ # XXX: memory usage doubles here (zero2)
265
+ num_param_groups = len(fp32_flat_groups[0])
266
+ merged_single_partition_of_fp32_groups = []
267
+ for i in range(num_param_groups):
268
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
269
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
270
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
271
+ avail_numel = sum(
272
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
273
+
274
+ if debug:
275
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
276
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
277
+ # not asserting if there is a mismatch due to possible padding
278
+ print(f"Have {avail_numel} numels to process.")
279
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
280
+
281
+ # params
282
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
283
+ # out-of-core computing solution
284
+ total_numel = 0
285
+ total_params = 0
286
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
287
+ offset = 0
288
+ avail_numel = full_single_fp32_vector.numel()
289
+ for name, shape in shapes.items():
290
+
291
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
292
+ total_numel += unpartitioned_numel
293
+ total_params += 1
294
+
295
+ if debug:
296
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
297
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
298
+ offset += unpartitioned_numel
299
+
300
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
301
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
302
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
303
+ # live optimizer object, so we are checking that the numbers are within the right range
304
+ align_to = 2 * world_size
305
+
306
+ def zero2_align(x):
307
+ return align_to * math.ceil(x / align_to)
308
+
309
+ if debug:
310
+ print(f"original offset={offset}, avail_numel={avail_numel}")
311
+
312
+ offset = zero2_align(offset)
313
+ avail_numel = zero2_align(avail_numel)
314
+
315
+ if debug:
316
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
317
+
318
+ # Sanity check
319
+ if offset != avail_numel:
320
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
321
+
322
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
323
+
324
+
325
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
326
+ exclude_frozen_parameters):
327
+ state_dict = OrderedDict()
328
+
329
+ # buffers
330
+ buffers = zero_model_states[0].buffers
331
+ state_dict.update(buffers)
332
+ if debug:
333
+ print(f"added {len(buffers)} buffers")
334
+
335
+ if not exclude_frozen_parameters:
336
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
337
+
338
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
339
+
340
+ # recover shared parameters
341
+ for pair in zero_model_states[0].shared_params:
342
+ if pair[1] in state_dict:
343
+ state_dict[pair[0]] = state_dict[pair[1]]
344
+
345
+ return state_dict
346
+
347
+
348
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
349
+ remainder = unpartitioned_numel % world_size
350
+ padding_numel = (world_size - remainder) if remainder else 0
351
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
352
+ return partitioned_numel, padding_numel
353
+
354
+
355
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
356
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
357
+ return
358
+
359
+ if debug:
360
+ for i in range(world_size):
361
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
362
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
363
+
364
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
365
+ wanted_params = len(frozen_param_shapes)
366
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
367
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
368
+ print(f'Frozen params: Have {avail_numel} numels to process.')
369
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
370
+
371
+ total_params = 0
372
+ total_numel = 0
373
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
374
+ total_params += 1
375
+ unpartitioned_numel = shape.numel()
376
+ total_numel += unpartitioned_numel
377
+
378
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
379
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
380
+
381
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
382
+
383
+ if debug:
384
+ print(
385
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
386
+ )
387
+
388
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
389
+
390
+
391
+ class GatheredTensor:
392
+ """
393
+ A pseudo tensor that collects partitioned weights.
394
+ It is more memory efficient when there are multiple groups.
395
+ """
396
+
397
+ def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
398
+ self.flat_groups = flat_groups
399
+ self.flat_groups_offset = flat_groups_offset
400
+ self.offset = offset
401
+ self.partitioned_numel = partitioned_numel
402
+ self.shape = shape
403
+ self.dtype = self.flat_groups[0][0].dtype
404
+
405
+ def contiguous(self):
406
+ """
407
+ Merge partitioned weights from flat_groups into a single tensor.
408
+ """
409
+ end_idx = self.offset + self.partitioned_numel
410
+ world_size = len(self.flat_groups)
411
+ pad_flat_param_chunks = []
412
+
413
+ for rank_i in range(world_size):
414
+ # for each rank, we need to collect weights from related group/groups
415
+ flat_groups_at_rank_i = self.flat_groups[rank_i]
416
+ start_group_id = None
417
+ end_group_id = None
418
+ for group_id in range(len(self.flat_groups_offset)):
419
+ if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
420
+ start_group_id = group_id
421
+ if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
422
+ end_group_id = group_id
423
+ break
424
+ # collect weights from related group/groups
425
+ for group_id in range(start_group_id, end_group_id + 1):
426
+ flat_tensor = flat_groups_at_rank_i[group_id]
427
+ start_offset = self.offset - self.flat_groups_offset[group_id]
428
+ end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
429
+ pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
430
+
431
+ # collect weights from all ranks
432
+ pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
433
+ param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
434
+ return param
435
+
436
+
437
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
438
+ param_shapes = zero_model_states[0].param_shapes
439
+ avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
440
+
441
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
442
+ # param, re-consolidating each param, while dealing with padding if any
443
+
444
+ # merge list of dicts, preserving order
445
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
446
+
447
+ if debug:
448
+ for i in range(world_size):
449
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
450
+
451
+ wanted_params = len(param_shapes)
452
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
453
+ # not asserting if there is a mismatch due to possible padding
454
+ avail_numel = fp32_flat_groups[0].numel() * world_size
455
+ print(f"Trainable params: Have {avail_numel} numels to process.")
456
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
457
+
458
+ # params
459
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
460
+ # out-of-core computing solution
461
+ offset = 0
462
+ total_numel = 0
463
+ total_params = 0
464
+ flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
465
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
466
+ unpartitioned_numel = shape.numel()
467
+ total_numel += unpartitioned_numel
468
+ total_params += 1
469
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
470
+
471
+ if debug:
472
+ print(
473
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
474
+ )
475
+
476
+ # memory efficient tensor
477
+ tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
478
+ state_dict[name] = tensor
479
+ offset += partitioned_numel
480
+
481
+ offset *= world_size
482
+
483
+ # Sanity check
484
+ if offset != avail_numel:
485
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
486
+
487
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
488
+
489
+
490
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
491
+ exclude_frozen_parameters):
492
+ state_dict = OrderedDict()
493
+
494
+ # buffers
495
+ buffers = zero_model_states[0].buffers
496
+ state_dict.update(buffers)
497
+ if debug:
498
+ print(f"added {len(buffers)} buffers")
499
+
500
+ if not exclude_frozen_parameters:
501
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
502
+
503
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
504
+
505
+ # recover shared parameters
506
+ for pair in zero_model_states[0].shared_params:
507
+ if pair[1] in state_dict:
508
+ state_dict[pair[0]] = state_dict[pair[1]]
509
+
510
+ return state_dict
511
+
512
+
513
+ def to_torch_tensor(state_dict, return_empty_tensor=False):
514
+ """
515
+ Convert state_dict of GatheredTensor to torch tensor
516
+ """
517
+ torch_state_dict = {}
518
+ converted_tensors = {}
519
+ for name, tensor in state_dict.items():
520
+ tensor_id = id(tensor)
521
+ if tensor_id in converted_tensors: # shared tensors
522
+ shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
523
+ torch_state_dict[name] = shared_tensor
524
+ else:
525
+ converted_tensors[tensor_id] = name
526
+ if return_empty_tensor:
527
+ torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
528
+ else:
529
+ torch_state_dict[name] = tensor.contiguous()
530
+ return torch_state_dict
531
+
532
+
533
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
534
+ tag=None,
535
+ exclude_frozen_parameters=False,
536
+ lazy_mode=False):
537
+ """
538
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
539
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
540
+ via a model hub.
541
+
542
+ Args:
543
+ - ``checkpoint_dir``: path to the desired checkpoint folder
544
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
545
+ - ``exclude_frozen_parameters``: exclude frozen parameters
546
+ - ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
547
+ Convert the pesduo tensor to torch tensor by ``.contiguous()``
548
+
549
+ Returns:
550
+ - pytorch ``state_dict``
551
+
552
+ A typical usage might be ::
553
+
554
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
555
+ # do the training and checkpoint saving
556
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
557
+ model = model.cpu() # move to cpu
558
+ model.load_state_dict(state_dict)
559
+ # submit to model hub or save the model to share with others
560
+
561
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
562
+ application. i.e. you will need to re-initialize the deepspeed engine, since
563
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
564
+
565
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
566
+
567
+ Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
568
+ You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
569
+ the checkpoint. Or you can load state_dict in lazy mode ::
570
+
571
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
572
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
573
+ for name, lazy_tensor in state_dict.item():
574
+ tensor = lazy_tensor.contiguous() # to cpu
575
+ print(name, tensor)
576
+ # del tensor to release memory if it no longer in use
577
+ """
578
+ if tag is None:
579
+ latest_path = os.path.join(checkpoint_dir, 'latest')
580
+ if os.path.isfile(latest_path):
581
+ with open(latest_path, 'r') as fd:
582
+ tag = fd.read().strip()
583
+ else:
584
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
585
+
586
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
587
+
588
+ if not os.path.isdir(ds_checkpoint_dir):
589
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
590
+
591
+ state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
592
+ if lazy_mode:
593
+ return state_dict
594
+ else:
595
+ return to_torch_tensor(state_dict)
596
+
597
+
598
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
599
+ output_dir,
600
+ max_shard_size="5GB",
601
+ safe_serialization=False,
602
+ tag=None,
603
+ exclude_frozen_parameters=False):
604
+ """
605
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
606
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
607
+
608
+ Args:
609
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
610
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
611
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
612
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
613
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
614
+ - ``exclude_frozen_parameters``: exclude frozen parameters
615
+ """
616
+
617
+ # Dependency pre-check
618
+ if safe_serialization:
619
+ try:
620
+ from safetensors.torch import save_file
621
+ except ImportError:
622
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
623
+ raise
624
+ if max_shard_size is not None:
625
+ try:
626
+ from huggingface_hub import split_torch_state_dict_into_shards
627
+ except ImportError:
628
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
629
+ raise
630
+
631
+ # Convert zero checkpoint to state_dict
632
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
633
+ tag,
634
+ exclude_frozen_parameters,
635
+ lazy_mode=True)
636
+
637
+ # Shard the model if it is too big.
638
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
639
+ if max_shard_size is not None:
640
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
641
+ # an memory-efficient approach for sharding
642
+ empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
643
+ state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
644
+ filename_pattern=filename_pattern,
645
+ max_shard_size=max_shard_size)
646
+ else:
647
+ from collections import namedtuple
648
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
649
+ state_dict_split = StateDictSplit(is_sharded=False,
650
+ filename_to_tensors={weights_name: list(state_dict.keys())})
651
+
652
+ # Save the model by shard
653
+ os.makedirs(output_dir, exist_ok=True)
654
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
655
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
656
+ shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
657
+ shard_state_dict = to_torch_tensor(shard_state_dict)
658
+ output_path = os.path.join(output_dir, shard_file)
659
+ if safe_serialization:
660
+ save_file(shard_state_dict, output_path, metadata={"format": "pt"})
661
+ else:
662
+ torch.save(shard_state_dict, output_path)
663
+ # release the memory of current shard
664
+ for tensor_name in list(shard_state_dict.keys()):
665
+ del state_dict[tensor_name]
666
+ del shard_state_dict[tensor_name]
667
+ del shard_state_dict
668
+ gc.collect()
669
+
670
+ # Save index if sharded
671
+ if state_dict_split.is_sharded:
672
+ index = {
673
+ "metadata": state_dict_split.metadata,
674
+ "weight_map": state_dict_split.tensor_to_filename,
675
+ }
676
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
677
+ save_index_file = os.path.join(output_dir, save_index_file)
678
+ with open(save_index_file, "w", encoding="utf-8") as f:
679
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
680
+ f.write(content)
681
+
682
+
683
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
684
+ """
685
+ 1. Put the provided model to cpu
686
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
687
+ 3. Load it into the provided model
688
+
689
+ Args:
690
+ - ``model``: the model object to update
691
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
692
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
693
+
694
+ Returns:
695
+ - ``model`: modified model
696
+
697
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
698
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
699
+ conveniently placed for you in the checkpoint folder.
700
+
701
+ A typical usage might be ::
702
+
703
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
704
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
705
+ # submit to model hub or save the model to share with others
706
+
707
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
708
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
709
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
710
+
711
+ """
712
+ logger.info(f"Extracting fp32 weights")
713
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
714
+
715
+ logger.info(f"Overwriting model with fp32 weights")
716
+ model = model.cpu()
717
+ model.load_state_dict(state_dict, strict=False)
718
+
719
+ return model
720
+
721
+
722
+ if __name__ == "__main__":
723
+ parser = argparse.ArgumentParser()
724
+ parser.add_argument("checkpoint_dir",
725
+ type=str,
726
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
727
+ parser.add_argument("output_dir",
728
+ type=str,
729
+ help="directory to the pytorch fp32 state_dict output files"
730
+ "(e.g. path/checkpoint-12-output/)")
731
+ parser.add_argument(
732
+ "--max_shard_size",
733
+ type=str,
734
+ default="5GB",
735
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
736
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
737
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
738
+ "without CPU OOM issues.")
739
+ parser.add_argument(
740
+ "--safe_serialization",
741
+ default=False,
742
+ action='store_true',
743
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
744
+ parser.add_argument("-t",
745
+ "--tag",
746
+ type=str,
747
+ default=None,
748
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
749
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
750
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
751
+ args = parser.parse_args()
752
+
753
+ debug = args.debug
754
+
755
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
756
+ args.output_dir,
757
+ max_shard_size=args.max_shard_size,
758
+ safe_serialization=args.safe_serialization,
759
+ tag=args.tag,
760
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
checkpoint-214/added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
checkpoint-214/config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Qwen/Qwen2.5-Math-1.5B-Instruct",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "eos_token_id": 151645,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 1536,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 8960,
12
+ "max_position_embeddings": 32768,
13
+ "max_window_layers": 21,
14
+ "model_type": "qwen2",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 28,
17
+ "num_key_value_heads": 2,
18
+ "rms_norm_eps": 1e-06,
19
+ "rope_scaling": {
20
+ "factor": 8.0,
21
+ "type": "linear"
22
+ },
23
+ "rope_theta": 10000.0,
24
+ "sliding_window": null,
25
+ "tie_word_embeddings": true,
26
+ "torch_dtype": "bfloat16",
27
+ "transformers_version": "4.48.3",
28
+ "use_cache": false,
29
+ "use_sliding_window": false,
30
+ "vocab_size": 151665
31
+ }
checkpoint-214/generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "transformers_version": "4.48.3"
10
+ }
checkpoint-214/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step213
checkpoint-214/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-214/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfdd9e83239574e821a0b2e3a7b4de9e30eb846275fcb8c03ee376106f1210b3
3
+ size 3086634632
checkpoint-214/rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ee195ebde9bf012f945f068f133e7fe22fef5450c496607e3ef11cc2034a186
3
+ size 15984
checkpoint-214/rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bf0fe1a3315d60b197207c5cb249d0ce4f9ce6d7585e696276d9ffbcb5379893
3
+ size 15984
checkpoint-214/rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01c5bd6eae04542162b3e94245555bd81312524066bc01d0ebbfc4fd8554240e
3
+ size 15984
checkpoint-214/rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45b74942c68b00d657cfce186b0eeb4aa8f52efa04b114803b605fee8de45972
3
+ size 15984
checkpoint-214/rng_state_4.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cd66dd2ba958fc9929441817d8154abbd929c0aa9cd66ff3171965bdaaf5d78
3
+ size 15984
checkpoint-214/rng_state_5.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:89eeedefdd62514d0130acc330a5c08e9774c95d38c60997905cfd65fc54b710
3
+ size 15984
checkpoint-214/rng_state_6.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f43ced939100082608f57561a10e1888e69210c80675068db530c5815889910e
3
+ size 15984
checkpoint-214/rng_state_7.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d8d6ee244d99525e7004ae3f02d44ae63082d81fbbab7306f641ac6aeeb736f
3
+ size 15984
checkpoint-214/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d2f0db282a9cd753eddd7ae2d5f2dc0a710bfada7c6671a4b3d7125f8773e81
3
+ size 1064
checkpoint-214/special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
checkpoint-214/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
checkpoint-214/tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "extra_special_tokens": {},
203
+ "model_max_length": 131072,
204
+ "pad_token": "<|endoftext|>",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
checkpoint-214/trainer_state.json ADDED
@@ -0,0 +1,1579 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 1.98978698570178,
5
+ "eval_steps": 36,
6
+ "global_step": 214,
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.009337613072658301,
13
+ "grad_norm": 0.6103967193596562,
14
+ "learning_rate": 1.25e-06,
15
+ "loss": 4.5461,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.009337613072658301,
20
+ "eval_loss": 4.553500175476074,
21
+ "eval_runtime": 16.4134,
22
+ "eval_samples_per_second": 16.816,
23
+ "eval_steps_per_second": 2.132,
24
+ "step": 1
25
+ },
26
+ {
27
+ "epoch": 0.018675226145316602,
28
+ "grad_norm": 0.6058263693172029,
29
+ "learning_rate": 2.5e-06,
30
+ "loss": 4.5365,
31
+ "step": 2
32
+ },
33
+ {
34
+ "epoch": 0.028012839217974907,
35
+ "grad_norm": 0.6061325195841676,
36
+ "learning_rate": 3.7500000000000005e-06,
37
+ "loss": 4.5438,
38
+ "step": 3
39
+ },
40
+ {
41
+ "epoch": 0.037350452290633204,
42
+ "grad_norm": 0.5966679918377138,
43
+ "learning_rate": 5e-06,
44
+ "loss": 4.5495,
45
+ "step": 4
46
+ },
47
+ {
48
+ "epoch": 0.04668806536329151,
49
+ "grad_norm": 0.5637877145545853,
50
+ "learning_rate": 6.25e-06,
51
+ "loss": 4.4744,
52
+ "step": 5
53
+ },
54
+ {
55
+ "epoch": 0.05602567843594981,
56
+ "grad_norm": 0.4955765028851229,
57
+ "learning_rate": 7.500000000000001e-06,
58
+ "loss": 4.3581,
59
+ "step": 6
60
+ },
61
+ {
62
+ "epoch": 0.06536329150860812,
63
+ "grad_norm": 0.33161457169025776,
64
+ "learning_rate": 8.750000000000001e-06,
65
+ "loss": 3.9768,
66
+ "step": 7
67
+ },
68
+ {
69
+ "epoch": 0.07470090458126641,
70
+ "grad_norm": 0.30498618054818755,
71
+ "learning_rate": 1e-05,
72
+ "loss": 3.9306,
73
+ "step": 8
74
+ },
75
+ {
76
+ "epoch": 0.08403851765392471,
77
+ "grad_norm": 0.3418457910893006,
78
+ "learning_rate": 1.125e-05,
79
+ "loss": 3.6729,
80
+ "step": 9
81
+ },
82
+ {
83
+ "epoch": 0.09337613072658302,
84
+ "grad_norm": 0.3051650090830193,
85
+ "learning_rate": 1.25e-05,
86
+ "loss": 3.5839,
87
+ "step": 10
88
+ },
89
+ {
90
+ "epoch": 0.10271374379924132,
91
+ "grad_norm": 0.2540841556589586,
92
+ "learning_rate": 1.375e-05,
93
+ "loss": 3.4916,
94
+ "step": 11
95
+ },
96
+ {
97
+ "epoch": 0.11205135687189963,
98
+ "grad_norm": 0.2523065620988122,
99
+ "learning_rate": 1.5000000000000002e-05,
100
+ "loss": 3.3087,
101
+ "step": 12
102
+ },
103
+ {
104
+ "epoch": 0.12138896994455792,
105
+ "grad_norm": 0.20081817150865616,
106
+ "learning_rate": 1.6250000000000002e-05,
107
+ "loss": 3.1931,
108
+ "step": 13
109
+ },
110
+ {
111
+ "epoch": 0.13072658301721624,
112
+ "grad_norm": 0.1823149251708444,
113
+ "learning_rate": 1.7500000000000002e-05,
114
+ "loss": 3.1415,
115
+ "step": 14
116
+ },
117
+ {
118
+ "epoch": 0.14006419608987453,
119
+ "grad_norm": 0.15949645404615334,
120
+ "learning_rate": 1.8750000000000002e-05,
121
+ "loss": 3.0393,
122
+ "step": 15
123
+ },
124
+ {
125
+ "epoch": 0.14940180916253282,
126
+ "grad_norm": 0.1325611844716812,
127
+ "learning_rate": 2e-05,
128
+ "loss": 2.8927,
129
+ "step": 16
130
+ },
131
+ {
132
+ "epoch": 0.15873942223519114,
133
+ "grad_norm": 0.11464751241192053,
134
+ "learning_rate": 1.9999469523400122e-05,
135
+ "loss": 2.7378,
136
+ "step": 17
137
+ },
138
+ {
139
+ "epoch": 0.16807703530784943,
140
+ "grad_norm": 0.1070431164754716,
141
+ "learning_rate": 1.9997878149881576e-05,
142
+ "loss": 2.6558,
143
+ "step": 18
144
+ },
145
+ {
146
+ "epoch": 0.17741464838050774,
147
+ "grad_norm": 0.10433083170549438,
148
+ "learning_rate": 1.999522604828164e-05,
149
+ "loss": 2.534,
150
+ "step": 19
151
+ },
152
+ {
153
+ "epoch": 0.18675226145316604,
154
+ "grad_norm": 0.10117296773389844,
155
+ "learning_rate": 1.9991513499975883e-05,
156
+ "loss": 2.4259,
157
+ "step": 20
158
+ },
159
+ {
160
+ "epoch": 0.19608987452582433,
161
+ "grad_norm": 0.09323265692759455,
162
+ "learning_rate": 1.9986740898848306e-05,
163
+ "loss": 2.3488,
164
+ "step": 21
165
+ },
166
+ {
167
+ "epoch": 0.20542748759848264,
168
+ "grad_norm": 0.07868283241281675,
169
+ "learning_rate": 1.9980908751249556e-05,
170
+ "loss": 2.2658,
171
+ "step": 22
172
+ },
173
+ {
174
+ "epoch": 0.21476510067114093,
175
+ "grad_norm": 0.07548690533550786,
176
+ "learning_rate": 1.997401767594319e-05,
177
+ "loss": 2.1874,
178
+ "step": 23
179
+ },
180
+ {
181
+ "epoch": 0.22410271374379925,
182
+ "grad_norm": 0.07720457793760661,
183
+ "learning_rate": 1.996606840404006e-05,
184
+ "loss": 2.0998,
185
+ "step": 24
186
+ },
187
+ {
188
+ "epoch": 0.23344032681645754,
189
+ "grad_norm": 0.07639897047393754,
190
+ "learning_rate": 1.9957061778920703e-05,
191
+ "loss": 2.0469,
192
+ "step": 25
193
+ },
194
+ {
195
+ "epoch": 0.24277793988911583,
196
+ "grad_norm": 0.07016046755367683,
197
+ "learning_rate": 1.9946998756145894e-05,
198
+ "loss": 1.9562,
199
+ "step": 26
200
+ },
201
+ {
202
+ "epoch": 0.2521155529617741,
203
+ "grad_norm": 0.06084064670530258,
204
+ "learning_rate": 1.9935880403355255e-05,
205
+ "loss": 1.8943,
206
+ "step": 27
207
+ },
208
+ {
209
+ "epoch": 0.26145316603443247,
210
+ "grad_norm": 0.05530834717342951,
211
+ "learning_rate": 1.9923707900153984e-05,
212
+ "loss": 1.7771,
213
+ "step": 28
214
+ },
215
+ {
216
+ "epoch": 0.27079077910709076,
217
+ "grad_norm": 0.05296398833585214,
218
+ "learning_rate": 1.9910482537987704e-05,
219
+ "loss": 1.7624,
220
+ "step": 29
221
+ },
222
+ {
223
+ "epoch": 0.28012839217974905,
224
+ "grad_norm": 0.05206178996458072,
225
+ "learning_rate": 1.989620572000544e-05,
226
+ "loss": 1.6848,
227
+ "step": 30
228
+ },
229
+ {
230
+ "epoch": 0.28946600525240734,
231
+ "grad_norm": 0.050431830710485716,
232
+ "learning_rate": 1.9880878960910772e-05,
233
+ "loss": 1.6577,
234
+ "step": 31
235
+ },
236
+ {
237
+ "epoch": 0.29880361832506563,
238
+ "grad_norm": 0.04760195929852826,
239
+ "learning_rate": 1.9864503886801108e-05,
240
+ "loss": 1.6128,
241
+ "step": 32
242
+ },
243
+ {
244
+ "epoch": 0.308141231397724,
245
+ "grad_norm": 0.04482797539629353,
246
+ "learning_rate": 1.9847082234995172e-05,
247
+ "loss": 1.5791,
248
+ "step": 33
249
+ },
250
+ {
251
+ "epoch": 0.31747884447038227,
252
+ "grad_norm": 0.04130893521590142,
253
+ "learning_rate": 1.982861585384869e-05,
254
+ "loss": 1.5063,
255
+ "step": 34
256
+ },
257
+ {
258
+ "epoch": 0.32681645754304056,
259
+ "grad_norm": 0.04057758728502848,
260
+ "learning_rate": 1.9809106702558277e-05,
261
+ "loss": 1.4877,
262
+ "step": 35
263
+ },
264
+ {
265
+ "epoch": 0.33615407061569885,
266
+ "grad_norm": 0.038180219331760724,
267
+ "learning_rate": 1.978855685095358e-05,
268
+ "loss": 1.4397,
269
+ "step": 36
270
+ },
271
+ {
272
+ "epoch": 0.33615407061569885,
273
+ "eval_loss": 1.3349355459213257,
274
+ "eval_runtime": 16.413,
275
+ "eval_samples_per_second": 16.816,
276
+ "eval_steps_per_second": 2.132,
277
+ "step": 36
278
+ },
279
+ {
280
+ "epoch": 0.34549168368835714,
281
+ "grad_norm": 0.0360323358530499,
282
+ "learning_rate": 1.9766968479277684e-05,
283
+ "loss": 1.3977,
284
+ "step": 37
285
+ },
286
+ {
287
+ "epoch": 0.3548292967610155,
288
+ "grad_norm": 0.035146043601200425,
289
+ "learning_rate": 1.974434387795579e-05,
290
+ "loss": 1.418,
291
+ "step": 38
292
+ },
293
+ {
294
+ "epoch": 0.3641669098336738,
295
+ "grad_norm": 0.033121913235728655,
296
+ "learning_rate": 1.972068544735221e-05,
297
+ "loss": 1.3359,
298
+ "step": 39
299
+ },
300
+ {
301
+ "epoch": 0.37350452290633207,
302
+ "grad_norm": 0.031036722451915032,
303
+ "learning_rate": 1.969599569751571e-05,
304
+ "loss": 1.3401,
305
+ "step": 40
306
+ },
307
+ {
308
+ "epoch": 0.38284213597899036,
309
+ "grad_norm": 0.030669047831503912,
310
+ "learning_rate": 1.9670277247913205e-05,
311
+ "loss": 1.2638,
312
+ "step": 41
313
+ },
314
+ {
315
+ "epoch": 0.39217974905164865,
316
+ "grad_norm": 0.03002785386211285,
317
+ "learning_rate": 1.964353282715183e-05,
318
+ "loss": 1.2649,
319
+ "step": 42
320
+ },
321
+ {
322
+ "epoch": 0.401517362124307,
323
+ "grad_norm": 0.02817025139456513,
324
+ "learning_rate": 1.961576527268946e-05,
325
+ "loss": 1.2476,
326
+ "step": 43
327
+ },
328
+ {
329
+ "epoch": 0.4108549751969653,
330
+ "grad_norm": 0.03110381051330927,
331
+ "learning_rate": 1.9586977530533677e-05,
332
+ "loss": 1.1923,
333
+ "step": 44
334
+ },
335
+ {
336
+ "epoch": 0.4201925882696236,
337
+ "grad_norm": 0.031162812150372473,
338
+ "learning_rate": 1.95571726549292e-05,
339
+ "loss": 1.2044,
340
+ "step": 45
341
+ },
342
+ {
343
+ "epoch": 0.42953020134228187,
344
+ "grad_norm": 0.029584239693380046,
345
+ "learning_rate": 1.9526353808033827e-05,
346
+ "loss": 1.1764,
347
+ "step": 46
348
+ },
349
+ {
350
+ "epoch": 0.43886781441494016,
351
+ "grad_norm": 0.027540684267770742,
352
+ "learning_rate": 1.9494524259582994e-05,
353
+ "loss": 1.1634,
354
+ "step": 47
355
+ },
356
+ {
357
+ "epoch": 0.4482054274875985,
358
+ "grad_norm": 0.028821860863637565,
359
+ "learning_rate": 1.9461687386542826e-05,
360
+ "loss": 1.1426,
361
+ "step": 48
362
+ },
363
+ {
364
+ "epoch": 0.4575430405602568,
365
+ "grad_norm": 0.027945951918964533,
366
+ "learning_rate": 1.9427846672751873e-05,
367
+ "loss": 1.1154,
368
+ "step": 49
369
+ },
370
+ {
371
+ "epoch": 0.4668806536329151,
372
+ "grad_norm": 0.026881160663849425,
373
+ "learning_rate": 1.93930057085515e-05,
374
+ "loss": 1.0981,
375
+ "step": 50
376
+ },
377
+ {
378
+ "epoch": 0.4762182667055734,
379
+ "grad_norm": 0.025002230522002903,
380
+ "learning_rate": 1.9357168190404937e-05,
381
+ "loss": 1.0873,
382
+ "step": 51
383
+ },
384
+ {
385
+ "epoch": 0.48555587977823167,
386
+ "grad_norm": 0.02318894097448886,
387
+ "learning_rate": 1.932033792050515e-05,
388
+ "loss": 1.0701,
389
+ "step": 52
390
+ },
391
+ {
392
+ "epoch": 0.49489349285089,
393
+ "grad_norm": 0.021872991266037325,
394
+ "learning_rate": 1.928251880637141e-05,
395
+ "loss": 1.0439,
396
+ "step": 53
397
+ },
398
+ {
399
+ "epoch": 0.5042311059235483,
400
+ "grad_norm": 0.021369213964442125,
401
+ "learning_rate": 1.924371486043473e-05,
402
+ "loss": 1.062,
403
+ "step": 54
404
+ },
405
+ {
406
+ "epoch": 0.5135687189962066,
407
+ "grad_norm": 0.02074830989778219,
408
+ "learning_rate": 1.920393019961217e-05,
409
+ "loss": 1.0392,
410
+ "step": 55
411
+ },
412
+ {
413
+ "epoch": 0.5229063320688649,
414
+ "grad_norm": 0.020345018132100934,
415
+ "learning_rate": 1.916316904487005e-05,
416
+ "loss": 1.02,
417
+ "step": 56
418
+ },
419
+ {
420
+ "epoch": 0.5322439451415232,
421
+ "grad_norm": 0.01970957719141645,
422
+ "learning_rate": 1.9121435720776122e-05,
423
+ "loss": 0.9923,
424
+ "step": 57
425
+ },
426
+ {
427
+ "epoch": 0.5415815582141815,
428
+ "grad_norm": 0.019741562276937644,
429
+ "learning_rate": 1.9078734655040763e-05,
430
+ "loss": 0.9993,
431
+ "step": 58
432
+ },
433
+ {
434
+ "epoch": 0.5509191712868398,
435
+ "grad_norm": 0.0195142739708107,
436
+ "learning_rate": 1.9035070378047204e-05,
437
+ "loss": 0.9943,
438
+ "step": 59
439
+ },
440
+ {
441
+ "epoch": 0.5602567843594981,
442
+ "grad_norm": 0.017297498916208055,
443
+ "learning_rate": 1.8990447522370886e-05,
444
+ "loss": 0.9753,
445
+ "step": 60
446
+ },
447
+ {
448
+ "epoch": 0.5695943974321565,
449
+ "grad_norm": 0.01658779952035472,
450
+ "learning_rate": 1.8944870822287957e-05,
451
+ "loss": 0.9883,
452
+ "step": 61
453
+ },
454
+ {
455
+ "epoch": 0.5789320105048147,
456
+ "grad_norm": 0.018530815854782102,
457
+ "learning_rate": 1.8898345113273e-05,
458
+ "loss": 0.9482,
459
+ "step": 62
460
+ },
461
+ {
462
+ "epoch": 0.588269623577473,
463
+ "grad_norm": 0.017748842064851857,
464
+ "learning_rate": 1.8850875331485996e-05,
465
+ "loss": 0.9533,
466
+ "step": 63
467
+ },
468
+ {
469
+ "epoch": 0.5976072366501313,
470
+ "grad_norm": 0.016871546397150952,
471
+ "learning_rate": 1.8802466513248635e-05,
472
+ "loss": 0.948,
473
+ "step": 64
474
+ },
475
+ {
476
+ "epoch": 0.6069448497227896,
477
+ "grad_norm": 0.01608669807726683,
478
+ "learning_rate": 1.8753123794509974e-05,
479
+ "loss": 0.9295,
480
+ "step": 65
481
+ },
482
+ {
483
+ "epoch": 0.616282462795448,
484
+ "grad_norm": 0.017453769141315367,
485
+ "learning_rate": 1.8702852410301556e-05,
486
+ "loss": 0.9198,
487
+ "step": 66
488
+ },
489
+ {
490
+ "epoch": 0.6256200758681062,
491
+ "grad_norm": 0.017655286026566987,
492
+ "learning_rate": 1.865165769418196e-05,
493
+ "loss": 0.9535,
494
+ "step": 67
495
+ },
496
+ {
497
+ "epoch": 0.6349576889407645,
498
+ "grad_norm": 0.017498254303415152,
499
+ "learning_rate": 1.8599545077670983e-05,
500
+ "loss": 0.9278,
501
+ "step": 68
502
+ },
503
+ {
504
+ "epoch": 0.6442953020134228,
505
+ "grad_norm": 0.01573094552466445,
506
+ "learning_rate": 1.854652008967335e-05,
507
+ "loss": 0.912,
508
+ "step": 69
509
+ },
510
+ {
511
+ "epoch": 0.6536329150860811,
512
+ "grad_norm": 0.015035283908585596,
513
+ "learning_rate": 1.8492588355892125e-05,
514
+ "loss": 0.9182,
515
+ "step": 70
516
+ },
517
+ {
518
+ "epoch": 0.6629705281587395,
519
+ "grad_norm": 0.01593275185300073,
520
+ "learning_rate": 1.8437755598231857e-05,
521
+ "loss": 0.9109,
522
+ "step": 71
523
+ },
524
+ {
525
+ "epoch": 0.6723081412313977,
526
+ "grad_norm": 0.014842299347889509,
527
+ "learning_rate": 1.8382027634191523e-05,
528
+ "loss": 0.8795,
529
+ "step": 72
530
+ },
531
+ {
532
+ "epoch": 0.6723081412313977,
533
+ "eval_loss": 0.8388988375663757,
534
+ "eval_runtime": 16.5273,
535
+ "eval_samples_per_second": 16.7,
536
+ "eval_steps_per_second": 2.118,
537
+ "step": 72
538
+ },
539
+ {
540
+ "epoch": 0.681645754304056,
541
+ "grad_norm": 0.015086756882680958,
542
+ "learning_rate": 1.8325410376247295e-05,
543
+ "loss": 0.8793,
544
+ "step": 73
545
+ },
546
+ {
547
+ "epoch": 0.6909833673767143,
548
+ "grad_norm": 0.014400642274755383,
549
+ "learning_rate": 1.826790983122527e-05,
550
+ "loss": 0.9139,
551
+ "step": 74
552
+ },
553
+ {
554
+ "epoch": 0.7003209804493726,
555
+ "grad_norm": 0.013490998034899438,
556
+ "learning_rate": 1.8209532099664177e-05,
557
+ "loss": 0.8767,
558
+ "step": 75
559
+ },
560
+ {
561
+ "epoch": 0.709658593522031,
562
+ "grad_norm": 0.011444201595399665,
563
+ "learning_rate": 1.8150283375168112e-05,
564
+ "loss": 0.8525,
565
+ "step": 76
566
+ },
567
+ {
568
+ "epoch": 0.7189962065946892,
569
+ "grad_norm": 0.01133323463508391,
570
+ "learning_rate": 1.8090169943749477e-05,
571
+ "loss": 0.8658,
572
+ "step": 77
573
+ },
574
+ {
575
+ "epoch": 0.7283338196673476,
576
+ "grad_norm": 0.011984830212373445,
577
+ "learning_rate": 1.8029198183162e-05,
578
+ "loss": 0.856,
579
+ "step": 78
580
+ },
581
+ {
582
+ "epoch": 0.7376714327400058,
583
+ "grad_norm": 0.01217011221195066,
584
+ "learning_rate": 1.796737456222413e-05,
585
+ "loss": 0.8892,
586
+ "step": 79
587
+ },
588
+ {
589
+ "epoch": 0.7470090458126641,
590
+ "grad_norm": 0.012510369655517745,
591
+ "learning_rate": 1.7904705640132717e-05,
592
+ "loss": 0.8562,
593
+ "step": 80
594
+ },
595
+ {
596
+ "epoch": 0.7563466588853225,
597
+ "grad_norm": 0.011806935544189488,
598
+ "learning_rate": 1.7841198065767107e-05,
599
+ "loss": 0.8644,
600
+ "step": 81
601
+ },
602
+ {
603
+ "epoch": 0.7656842719579807,
604
+ "grad_norm": 0.011433541340869584,
605
+ "learning_rate": 1.7776858576983713e-05,
606
+ "loss": 0.8692,
607
+ "step": 82
608
+ },
609
+ {
610
+ "epoch": 0.7750218850306391,
611
+ "grad_norm": 0.012566348663586087,
612
+ "learning_rate": 1.771169399990119e-05,
613
+ "loss": 0.8541,
614
+ "step": 83
615
+ },
616
+ {
617
+ "epoch": 0.7843594981032973,
618
+ "grad_norm": 0.01072107470914378,
619
+ "learning_rate": 1.7645711248176198e-05,
620
+ "loss": 0.8403,
621
+ "step": 84
622
+ },
623
+ {
624
+ "epoch": 0.7936971111759556,
625
+ "grad_norm": 0.010617575681982286,
626
+ "learning_rate": 1.7578917322269885e-05,
627
+ "loss": 0.81,
628
+ "step": 85
629
+ },
630
+ {
631
+ "epoch": 0.803034724248614,
632
+ "grad_norm": 0.010466741230697605,
633
+ "learning_rate": 1.7511319308705198e-05,
634
+ "loss": 0.8253,
635
+ "step": 86
636
+ },
637
+ {
638
+ "epoch": 0.8123723373212722,
639
+ "grad_norm": 0.010184306281966645,
640
+ "learning_rate": 1.744292437931502e-05,
641
+ "loss": 0.8526,
642
+ "step": 87
643
+ },
644
+ {
645
+ "epoch": 0.8217099503939306,
646
+ "grad_norm": 0.009850665553519504,
647
+ "learning_rate": 1.7373739790481263e-05,
648
+ "loss": 0.8304,
649
+ "step": 88
650
+ },
651
+ {
652
+ "epoch": 0.8310475634665888,
653
+ "grad_norm": 0.009236577038055978,
654
+ "learning_rate": 1.7303772882365018e-05,
655
+ "loss": 0.7908,
656
+ "step": 89
657
+ },
658
+ {
659
+ "epoch": 0.8403851765392472,
660
+ "grad_norm": 0.03711865800548727,
661
+ "learning_rate": 1.723303107812779e-05,
662
+ "loss": 0.8085,
663
+ "step": 90
664
+ },
665
+ {
666
+ "epoch": 0.8497227896119055,
667
+ "grad_norm": 0.010517236470326855,
668
+ "learning_rate": 1.7161521883143936e-05,
669
+ "loss": 0.8313,
670
+ "step": 91
671
+ },
672
+ {
673
+ "epoch": 0.8590604026845637,
674
+ "grad_norm": 0.011238580368575812,
675
+ "learning_rate": 1.7089252884204376e-05,
676
+ "loss": 0.814,
677
+ "step": 92
678
+ },
679
+ {
680
+ "epoch": 0.8683980157572221,
681
+ "grad_norm": 0.009935862606933948,
682
+ "learning_rate": 1.701623174871168e-05,
683
+ "loss": 0.8032,
684
+ "step": 93
685
+ },
686
+ {
687
+ "epoch": 0.8777356288298803,
688
+ "grad_norm": 0.009655128505771573,
689
+ "learning_rate": 1.6942466223866582e-05,
690
+ "loss": 0.8013,
691
+ "step": 94
692
+ },
693
+ {
694
+ "epoch": 0.8870732419025387,
695
+ "grad_norm": 0.010463930618313586,
696
+ "learning_rate": 1.6867964135846043e-05,
697
+ "loss": 0.8116,
698
+ "step": 95
699
+ },
700
+ {
701
+ "epoch": 0.896410854975197,
702
+ "grad_norm": 0.009360797680160574,
703
+ "learning_rate": 1.679273338897293e-05,
704
+ "loss": 0.8064,
705
+ "step": 96
706
+ },
707
+ {
708
+ "epoch": 0.9057484680478552,
709
+ "grad_norm": 0.00968251573081083,
710
+ "learning_rate": 1.6716781964877413e-05,
711
+ "loss": 0.8208,
712
+ "step": 97
713
+ },
714
+ {
715
+ "epoch": 0.9150860811205136,
716
+ "grad_norm": 0.009894122849502883,
717
+ "learning_rate": 1.664011792165012e-05,
718
+ "loss": 0.8042,
719
+ "step": 98
720
+ },
721
+ {
722
+ "epoch": 0.9244236941931718,
723
+ "grad_norm": 0.010626027391586145,
724
+ "learning_rate": 1.6562749392987255e-05,
725
+ "loss": 0.8037,
726
+ "step": 99
727
+ },
728
+ {
729
+ "epoch": 0.9337613072658302,
730
+ "grad_norm": 0.01083144628829605,
731
+ "learning_rate": 1.648468458732762e-05,
732
+ "loss": 0.8079,
733
+ "step": 100
734
+ },
735
+ {
736
+ "epoch": 0.9430989203384885,
737
+ "grad_norm": 0.012651590456989211,
738
+ "learning_rate": 1.6405931786981753e-05,
739
+ "loss": 0.7903,
740
+ "step": 101
741
+ },
742
+ {
743
+ "epoch": 0.9524365334111468,
744
+ "grad_norm": 0.010619166674062264,
745
+ "learning_rate": 1.6326499347253206e-05,
746
+ "loss": 0.7783,
747
+ "step": 102
748
+ },
749
+ {
750
+ "epoch": 0.9617741464838051,
751
+ "grad_norm": 0.009320303165881526,
752
+ "learning_rate": 1.6246395695552086e-05,
753
+ "loss": 0.8035,
754
+ "step": 103
755
+ },
756
+ {
757
+ "epoch": 0.9711117595564633,
758
+ "grad_norm": 0.009094019045947338,
759
+ "learning_rate": 1.6165629330500952e-05,
760
+ "loss": 0.7839,
761
+ "step": 104
762
+ },
763
+ {
764
+ "epoch": 0.9804493726291217,
765
+ "grad_norm": 0.009044004451355656,
766
+ "learning_rate": 1.6084208821033152e-05,
767
+ "loss": 0.7641,
768
+ "step": 105
769
+ },
770
+ {
771
+ "epoch": 0.98978698570178,
772
+ "grad_norm": 0.009202270165387296,
773
+ "learning_rate": 1.6002142805483686e-05,
774
+ "loss": 0.7666,
775
+ "step": 106
776
+ },
777
+ {
778
+ "epoch": 0.9991245987744383,
779
+ "grad_norm": 0.009577150303950122,
780
+ "learning_rate": 1.591943999067273e-05,
781
+ "loss": 0.7869,
782
+ "step": 107
783
+ },
784
+ {
785
+ "epoch": 1.0,
786
+ "grad_norm": 0.009577150303950122,
787
+ "learning_rate": 1.5836109150981885e-05,
788
+ "loss": 0.7726,
789
+ "step": 108
790
+ },
791
+ {
792
+ "epoch": 1.0,
793
+ "eval_loss": 0.729849100112915,
794
+ "eval_runtime": 16.4211,
795
+ "eval_samples_per_second": 16.808,
796
+ "eval_steps_per_second": 2.131,
797
+ "step": 108
798
+ },
799
+ {
800
+ "epoch": 1.0093376130726583,
801
+ "grad_norm": 0.025397375893953918,
802
+ "learning_rate": 1.5752159127423262e-05,
803
+ "loss": 0.7934,
804
+ "step": 109
805
+ },
806
+ {
807
+ "epoch": 1.0186752261453167,
808
+ "grad_norm": 0.010902737901808093,
809
+ "learning_rate": 1.5667598826701463e-05,
810
+ "loss": 0.7627,
811
+ "step": 110
812
+ },
813
+ {
814
+ "epoch": 1.0280128392179748,
815
+ "grad_norm": 0.010800327585788388,
816
+ "learning_rate": 1.5582437220268648e-05,
817
+ "loss": 0.7578,
818
+ "step": 111
819
+ },
820
+ {
821
+ "epoch": 1.0373504522906332,
822
+ "grad_norm": 0.009732201305595227,
823
+ "learning_rate": 1.549668334337271e-05,
824
+ "loss": 0.7786,
825
+ "step": 112
826
+ },
827
+ {
828
+ "epoch": 1.0466880653632915,
829
+ "grad_norm": 0.009646638742060199,
830
+ "learning_rate": 1.541034629409865e-05,
831
+ "loss": 0.7867,
832
+ "step": 113
833
+ },
834
+ {
835
+ "epoch": 1.0560256784359499,
836
+ "grad_norm": 0.008481219102834343,
837
+ "learning_rate": 1.532343523240334e-05,
838
+ "loss": 0.7728,
839
+ "step": 114
840
+ },
841
+ {
842
+ "epoch": 1.0653632915086082,
843
+ "grad_norm": 0.007896528546841378,
844
+ "learning_rate": 1.523595937914368e-05,
845
+ "loss": 0.7478,
846
+ "step": 115
847
+ },
848
+ {
849
+ "epoch": 1.0747009045812663,
850
+ "grad_norm": 0.008638298804510322,
851
+ "learning_rate": 1.5147928015098309e-05,
852
+ "loss": 0.7479,
853
+ "step": 116
854
+ },
855
+ {
856
+ "epoch": 1.0840385176539247,
857
+ "grad_norm": 0.009113972298077106,
858
+ "learning_rate": 1.5059350479982966e-05,
859
+ "loss": 0.765,
860
+ "step": 117
861
+ },
862
+ {
863
+ "epoch": 1.093376130726583,
864
+ "grad_norm": 0.007570635714068737,
865
+ "learning_rate": 1.497023617145958e-05,
866
+ "loss": 0.7401,
867
+ "step": 118
868
+ },
869
+ {
870
+ "epoch": 1.1027137437992414,
871
+ "grad_norm": 0.007964839741138431,
872
+ "learning_rate": 1.488059454413923e-05,
873
+ "loss": 0.7397,
874
+ "step": 119
875
+ },
876
+ {
877
+ "epoch": 1.1120513568718997,
878
+ "grad_norm": 0.008981954045478064,
879
+ "learning_rate": 1.4790435108579048e-05,
880
+ "loss": 0.7497,
881
+ "step": 120
882
+ },
883
+ {
884
+ "epoch": 1.1213889699445578,
885
+ "grad_norm": 0.010253710038366608,
886
+ "learning_rate": 1.4699767430273202e-05,
887
+ "loss": 0.747,
888
+ "step": 121
889
+ },
890
+ {
891
+ "epoch": 1.1307265830172162,
892
+ "grad_norm": 0.009127204104812056,
893
+ "learning_rate": 1.4608601128638027e-05,
894
+ "loss": 0.7288,
895
+ "step": 122
896
+ },
897
+ {
898
+ "epoch": 1.1400641960898745,
899
+ "grad_norm": 0.008391872101434881,
900
+ "learning_rate": 1.4516945875991472e-05,
901
+ "loss": 0.7509,
902
+ "step": 123
903
+ },
904
+ {
905
+ "epoch": 1.1494018091625329,
906
+ "grad_norm": 0.007969062908818022,
907
+ "learning_rate": 1.4424811396526892e-05,
908
+ "loss": 0.7475,
909
+ "step": 124
910
+ },
911
+ {
912
+ "epoch": 1.1587394222351912,
913
+ "grad_norm": 0.011220499027460716,
914
+ "learning_rate": 1.4332207465281365e-05,
915
+ "loss": 0.7553,
916
+ "step": 125
917
+ },
918
+ {
919
+ "epoch": 1.1680770353078493,
920
+ "grad_norm": 0.008438223962809686,
921
+ "learning_rate": 1.423914390709861e-05,
922
+ "loss": 0.7417,
923
+ "step": 126
924
+ },
925
+ {
926
+ "epoch": 1.1774146483805077,
927
+ "grad_norm": 0.008124062455599669,
928
+ "learning_rate": 1.4145630595586607e-05,
929
+ "loss": 0.7315,
930
+ "step": 127
931
+ },
932
+ {
933
+ "epoch": 1.186752261453166,
934
+ "grad_norm": 0.008212207725829243,
935
+ "learning_rate": 1.4051677452070064e-05,
936
+ "loss": 0.7358,
937
+ "step": 128
938
+ },
939
+ {
940
+ "epoch": 1.1960898745258244,
941
+ "grad_norm": 0.007992807301141594,
942
+ "learning_rate": 1.3957294444537808e-05,
943
+ "loss": 0.7211,
944
+ "step": 129
945
+ },
946
+ {
947
+ "epoch": 1.2054274875984827,
948
+ "grad_norm": 0.006862436811624155,
949
+ "learning_rate": 1.386249158658522e-05,
950
+ "loss": 0.7328,
951
+ "step": 130
952
+ },
953
+ {
954
+ "epoch": 1.2147651006711409,
955
+ "grad_norm": 0.007484363453260225,
956
+ "learning_rate": 1.3767278936351853e-05,
957
+ "loss": 0.7409,
958
+ "step": 131
959
+ },
960
+ {
961
+ "epoch": 1.2241027137437992,
962
+ "grad_norm": 0.0076572272628448925,
963
+ "learning_rate": 1.3671666595454296e-05,
964
+ "loss": 0.7486,
965
+ "step": 132
966
+ },
967
+ {
968
+ "epoch": 1.2334403268164575,
969
+ "grad_norm": 0.008131184001251386,
970
+ "learning_rate": 1.357566470791445e-05,
971
+ "loss": 0.7376,
972
+ "step": 133
973
+ },
974
+ {
975
+ "epoch": 1.242777939889116,
976
+ "grad_norm": 0.008560166789615074,
977
+ "learning_rate": 1.347928345908329e-05,
978
+ "loss": 0.7506,
979
+ "step": 134
980
+ },
981
+ {
982
+ "epoch": 1.252115552961774,
983
+ "grad_norm": 0.007528447805555166,
984
+ "learning_rate": 1.3382533074560256e-05,
985
+ "loss": 0.7376,
986
+ "step": 135
987
+ },
988
+ {
989
+ "epoch": 1.2614531660344324,
990
+ "grad_norm": 0.007242664476183943,
991
+ "learning_rate": 1.3285423819108349e-05,
992
+ "loss": 0.7294,
993
+ "step": 136
994
+ },
995
+ {
996
+ "epoch": 1.2707907791070907,
997
+ "grad_norm": 0.007533824122445911,
998
+ "learning_rate": 1.3187965995565098e-05,
999
+ "loss": 0.7266,
1000
+ "step": 137
1001
+ },
1002
+ {
1003
+ "epoch": 1.280128392179749,
1004
+ "grad_norm": 0.007327965197210789,
1005
+ "learning_rate": 1.3090169943749475e-05,
1006
+ "loss": 0.7303,
1007
+ "step": 138
1008
+ },
1009
+ {
1010
+ "epoch": 1.2894660052524074,
1011
+ "grad_norm": 0.006703326795271757,
1012
+ "learning_rate": 1.2992046039364893e-05,
1013
+ "loss": 0.7157,
1014
+ "step": 139
1015
+ },
1016
+ {
1017
+ "epoch": 1.2988036183250657,
1018
+ "grad_norm": 0.006779822330163705,
1019
+ "learning_rate": 1.2893604692898381e-05,
1020
+ "loss": 0.7244,
1021
+ "step": 140
1022
+ },
1023
+ {
1024
+ "epoch": 1.308141231397724,
1025
+ "grad_norm": 0.006809286300573549,
1026
+ "learning_rate": 1.2794856348516095e-05,
1027
+ "loss": 0.738,
1028
+ "step": 141
1029
+ },
1030
+ {
1031
+ "epoch": 1.3174788444703822,
1032
+ "grad_norm": 0.006995815937146753,
1033
+ "learning_rate": 1.2695811482955227e-05,
1034
+ "loss": 0.7257,
1035
+ "step": 142
1036
+ },
1037
+ {
1038
+ "epoch": 1.3268164575430406,
1039
+ "grad_norm": 0.007022225511576764,
1040
+ "learning_rate": 1.2596480604412485e-05,
1041
+ "loss": 0.7344,
1042
+ "step": 143
1043
+ },
1044
+ {
1045
+ "epoch": 1.336154070615699,
1046
+ "grad_norm": 0.006750693986284064,
1047
+ "learning_rate": 1.24968742514292e-05,
1048
+ "loss": 0.7374,
1049
+ "step": 144
1050
+ },
1051
+ {
1052
+ "epoch": 1.336154070615699,
1053
+ "eval_loss": 0.6810739636421204,
1054
+ "eval_runtime": 16.3456,
1055
+ "eval_samples_per_second": 16.885,
1056
+ "eval_steps_per_second": 2.141,
1057
+ "step": 144
1058
+ },
1059
+ {
1060
+ "epoch": 1.345491683688357,
1061
+ "grad_norm": 0.00747295934805212,
1062
+ "learning_rate": 1.2397002991773277e-05,
1063
+ "loss": 0.7236,
1064
+ "step": 145
1065
+ },
1066
+ {
1067
+ "epoch": 1.3548292967610154,
1068
+ "grad_norm": 0.006404283125929898,
1069
+ "learning_rate": 1.2296877421317958e-05,
1070
+ "loss": 0.7047,
1071
+ "step": 146
1072
+ },
1073
+ {
1074
+ "epoch": 1.3641669098336737,
1075
+ "grad_norm": 0.007306315558814404,
1076
+ "learning_rate": 1.2196508162917678e-05,
1077
+ "loss": 0.7195,
1078
+ "step": 147
1079
+ },
1080
+ {
1081
+ "epoch": 1.373504522906332,
1082
+ "grad_norm": 0.007020070609447835,
1083
+ "learning_rate": 1.2095905865281026e-05,
1084
+ "loss": 0.7154,
1085
+ "step": 148
1086
+ },
1087
+ {
1088
+ "epoch": 1.3828421359789904,
1089
+ "grad_norm": 0.007513917861345975,
1090
+ "learning_rate": 1.1995081201840958e-05,
1091
+ "loss": 0.7175,
1092
+ "step": 149
1093
+ },
1094
+ {
1095
+ "epoch": 1.3921797490516488,
1096
+ "grad_norm": 0.006157056101055128,
1097
+ "learning_rate": 1.1894044869622403e-05,
1098
+ "loss": 0.711,
1099
+ "step": 150
1100
+ },
1101
+ {
1102
+ "epoch": 1.401517362124307,
1103
+ "grad_norm": 0.006769156388392959,
1104
+ "learning_rate": 1.1792807588107358e-05,
1105
+ "loss": 0.7162,
1106
+ "step": 151
1107
+ },
1108
+ {
1109
+ "epoch": 1.4108549751969652,
1110
+ "grad_norm": 0.007625740849364638,
1111
+ "learning_rate": 1.1691380098097598e-05,
1112
+ "loss": 0.7074,
1113
+ "step": 152
1114
+ },
1115
+ {
1116
+ "epoch": 1.4201925882696236,
1117
+ "grad_norm": 0.006751113454553622,
1118
+ "learning_rate": 1.158977316057513e-05,
1119
+ "loss": 0.7139,
1120
+ "step": 153
1121
+ },
1122
+ {
1123
+ "epoch": 1.429530201342282,
1124
+ "grad_norm": 0.006999228085598098,
1125
+ "learning_rate": 1.1487997555560503e-05,
1126
+ "loss": 0.7129,
1127
+ "step": 154
1128
+ },
1129
+ {
1130
+ "epoch": 1.43886781441494,
1131
+ "grad_norm": 0.007159925361221997,
1132
+ "learning_rate": 1.1386064080969095e-05,
1133
+ "loss": 0.7198,
1134
+ "step": 155
1135
+ },
1136
+ {
1137
+ "epoch": 1.4482054274875984,
1138
+ "grad_norm": 0.006542656052835091,
1139
+ "learning_rate": 1.1283983551465512e-05,
1140
+ "loss": 0.6975,
1141
+ "step": 156
1142
+ },
1143
+ {
1144
+ "epoch": 1.4575430405602567,
1145
+ "grad_norm": 0.007362347745191795,
1146
+ "learning_rate": 1.118176679731619e-05,
1147
+ "loss": 0.7233,
1148
+ "step": 157
1149
+ },
1150
+ {
1151
+ "epoch": 1.466880653632915,
1152
+ "grad_norm": 0.007507454634951982,
1153
+ "learning_rate": 1.1079424663240372e-05,
1154
+ "loss": 0.7013,
1155
+ "step": 158
1156
+ },
1157
+ {
1158
+ "epoch": 1.4762182667055734,
1159
+ "grad_norm": 0.006924288571642269,
1160
+ "learning_rate": 1.0976968007259519e-05,
1161
+ "loss": 0.7169,
1162
+ "step": 159
1163
+ },
1164
+ {
1165
+ "epoch": 1.4855558797782318,
1166
+ "grad_norm": 0.007327013436583258,
1167
+ "learning_rate": 1.0874407699545329e-05,
1168
+ "loss": 0.7045,
1169
+ "step": 160
1170
+ },
1171
+ {
1172
+ "epoch": 1.4948934928508901,
1173
+ "grad_norm": 0.0067947511037762314,
1174
+ "learning_rate": 1.0771754621266466e-05,
1175
+ "loss": 0.7114,
1176
+ "step": 161
1177
+ },
1178
+ {
1179
+ "epoch": 1.5042311059235483,
1180
+ "grad_norm": 0.007479624734064453,
1181
+ "learning_rate": 1.0669019663434117e-05,
1182
+ "loss": 0.7081,
1183
+ "step": 162
1184
+ },
1185
+ {
1186
+ "epoch": 1.5135687189962066,
1187
+ "grad_norm": 0.0071184716193534595,
1188
+ "learning_rate": 1.0566213725746506e-05,
1189
+ "loss": 0.7277,
1190
+ "step": 163
1191
+ },
1192
+ {
1193
+ "epoch": 1.522906332068865,
1194
+ "grad_norm": 0.007760294512478719,
1195
+ "learning_rate": 1.0463347715432488e-05,
1196
+ "loss": 0.7196,
1197
+ "step": 164
1198
+ },
1199
+ {
1200
+ "epoch": 1.532243945141523,
1201
+ "grad_norm": 0.007716707922551307,
1202
+ "learning_rate": 1.0360432546094341e-05,
1203
+ "loss": 0.7197,
1204
+ "step": 165
1205
+ },
1206
+ {
1207
+ "epoch": 1.5415815582141814,
1208
+ "grad_norm": 0.0072311410748593635,
1209
+ "learning_rate": 1.0257479136549889e-05,
1210
+ "loss": 0.7096,
1211
+ "step": 166
1212
+ },
1213
+ {
1214
+ "epoch": 1.5509191712868398,
1215
+ "grad_norm": 0.006676953574505626,
1216
+ "learning_rate": 1.0154498409674051e-05,
1217
+ "loss": 0.6982,
1218
+ "step": 167
1219
+ },
1220
+ {
1221
+ "epoch": 1.560256784359498,
1222
+ "grad_norm": 0.006468587987533156,
1223
+ "learning_rate": 1.0051501291240008e-05,
1224
+ "loss": 0.6774,
1225
+ "step": 168
1226
+ },
1227
+ {
1228
+ "epoch": 1.5695943974321565,
1229
+ "grad_norm": 0.006253950592479604,
1230
+ "learning_rate": 9.948498708759993e-06,
1231
+ "loss": 0.688,
1232
+ "step": 169
1233
+ },
1234
+ {
1235
+ "epoch": 1.5789320105048148,
1236
+ "grad_norm": 0.0065410655967948214,
1237
+ "learning_rate": 9.845501590325949e-06,
1238
+ "loss": 0.7207,
1239
+ "step": 170
1240
+ },
1241
+ {
1242
+ "epoch": 1.5882696235774731,
1243
+ "grad_norm": 0.006364666727868252,
1244
+ "learning_rate": 9.742520863450116e-06,
1245
+ "loss": 0.7027,
1246
+ "step": 171
1247
+ },
1248
+ {
1249
+ "epoch": 1.5976072366501313,
1250
+ "grad_norm": 0.006174978009841133,
1251
+ "learning_rate": 9.639567453905662e-06,
1252
+ "loss": 0.7021,
1253
+ "step": 172
1254
+ },
1255
+ {
1256
+ "epoch": 1.6069448497227896,
1257
+ "grad_norm": 0.006819554213970836,
1258
+ "learning_rate": 9.536652284567514e-06,
1259
+ "loss": 0.6707,
1260
+ "step": 173
1261
+ },
1262
+ {
1263
+ "epoch": 1.616282462795448,
1264
+ "grad_norm": 0.006939549814926166,
1265
+ "learning_rate": 9.433786274253496e-06,
1266
+ "loss": 0.688,
1267
+ "step": 174
1268
+ },
1269
+ {
1270
+ "epoch": 1.625620075868106,
1271
+ "grad_norm": 0.006694022655954106,
1272
+ "learning_rate": 9.330980336565887e-06,
1273
+ "loss": 0.6986,
1274
+ "step": 175
1275
+ },
1276
+ {
1277
+ "epoch": 1.6349576889407644,
1278
+ "grad_norm": 0.006672750770558918,
1279
+ "learning_rate": 9.228245378733537e-06,
1280
+ "loss": 0.7094,
1281
+ "step": 176
1282
+ },
1283
+ {
1284
+ "epoch": 1.6442953020134228,
1285
+ "grad_norm": 0.007263430275454483,
1286
+ "learning_rate": 9.125592300454675e-06,
1287
+ "loss": 0.6912,
1288
+ "step": 177
1289
+ },
1290
+ {
1291
+ "epoch": 1.6536329150860811,
1292
+ "grad_norm": 0.007540180086839557,
1293
+ "learning_rate": 9.023031992740488e-06,
1294
+ "loss": 0.6792,
1295
+ "step": 178
1296
+ },
1297
+ {
1298
+ "epoch": 1.6629705281587395,
1299
+ "grad_norm": 0.0064199964583914505,
1300
+ "learning_rate": 8.92057533675963e-06,
1301
+ "loss": 0.688,
1302
+ "step": 179
1303
+ },
1304
+ {
1305
+ "epoch": 1.6723081412313978,
1306
+ "grad_norm": 0.006196992820903783,
1307
+ "learning_rate": 8.818233202683815e-06,
1308
+ "loss": 0.6928,
1309
+ "step": 180
1310
+ },
1311
+ {
1312
+ "epoch": 1.6723081412313978,
1313
+ "eval_loss": 0.6554006934165955,
1314
+ "eval_runtime": 16.766,
1315
+ "eval_samples_per_second": 16.462,
1316
+ "eval_steps_per_second": 2.088,
1317
+ "step": 180
1318
+ },
1319
+ {
1320
+ "epoch": 1.6816457543040562,
1321
+ "grad_norm": 0.006747686143721935,
1322
+ "learning_rate": 8.71601644853449e-06,
1323
+ "loss": 0.7055,
1324
+ "step": 181
1325
+ },
1326
+ {
1327
+ "epoch": 1.6909833673767143,
1328
+ "grad_norm": 0.006142383641399304,
1329
+ "learning_rate": 8.613935919030908e-06,
1330
+ "loss": 0.6897,
1331
+ "step": 182
1332
+ },
1333
+ {
1334
+ "epoch": 1.7003209804493726,
1335
+ "grad_norm": 0.005877324668671395,
1336
+ "learning_rate": 8.512002444439502e-06,
1337
+ "loss": 0.7044,
1338
+ "step": 183
1339
+ },
1340
+ {
1341
+ "epoch": 1.709658593522031,
1342
+ "grad_norm": 0.006855381402076154,
1343
+ "learning_rate": 8.410226839424871e-06,
1344
+ "loss": 0.6819,
1345
+ "step": 184
1346
+ },
1347
+ {
1348
+ "epoch": 1.718996206594689,
1349
+ "grad_norm": 0.005424415467423937,
1350
+ "learning_rate": 8.308619901902406e-06,
1351
+ "loss": 0.7078,
1352
+ "step": 185
1353
+ },
1354
+ {
1355
+ "epoch": 1.7283338196673474,
1356
+ "grad_norm": 0.0061132223152236785,
1357
+ "learning_rate": 8.207192411892645e-06,
1358
+ "loss": 0.6931,
1359
+ "step": 186
1360
+ },
1361
+ {
1362
+ "epoch": 1.7376714327400058,
1363
+ "grad_norm": 0.006419370473537233,
1364
+ "learning_rate": 8.1059551303776e-06,
1365
+ "loss": 0.7123,
1366
+ "step": 187
1367
+ },
1368
+ {
1369
+ "epoch": 1.7470090458126641,
1370
+ "grad_norm": 0.0063388625830988875,
1371
+ "learning_rate": 8.004918798159046e-06,
1372
+ "loss": 0.6867,
1373
+ "step": 188
1374
+ },
1375
+ {
1376
+ "epoch": 1.7563466588853225,
1377
+ "grad_norm": 0.0058968715521128074,
1378
+ "learning_rate": 7.904094134718975e-06,
1379
+ "loss": 0.6864,
1380
+ "step": 189
1381
+ },
1382
+ {
1383
+ "epoch": 1.7656842719579808,
1384
+ "grad_norm": 0.0064607553768266796,
1385
+ "learning_rate": 7.803491837082324e-06,
1386
+ "loss": 0.6901,
1387
+ "step": 190
1388
+ },
1389
+ {
1390
+ "epoch": 1.7750218850306392,
1391
+ "grad_norm": 0.0067065346597906346,
1392
+ "learning_rate": 7.703122578682047e-06,
1393
+ "loss": 0.7002,
1394
+ "step": 191
1395
+ },
1396
+ {
1397
+ "epoch": 1.7843594981032973,
1398
+ "grad_norm": 0.006375540418233348,
1399
+ "learning_rate": 7.602997008226725e-06,
1400
+ "loss": 0.6952,
1401
+ "step": 192
1402
+ },
1403
+ {
1404
+ "epoch": 1.7936971111759556,
1405
+ "grad_norm": 0.005964849793104097,
1406
+ "learning_rate": 7.503125748570801e-06,
1407
+ "loss": 0.7012,
1408
+ "step": 193
1409
+ },
1410
+ {
1411
+ "epoch": 1.803034724248614,
1412
+ "grad_norm": 0.006923688795252922,
1413
+ "learning_rate": 7.403519395587522e-06,
1414
+ "loss": 0.6873,
1415
+ "step": 194
1416
+ },
1417
+ {
1418
+ "epoch": 1.8123723373212721,
1419
+ "grad_norm": 0.006884309979239693,
1420
+ "learning_rate": 7.304188517044774e-06,
1421
+ "loss": 0.7075,
1422
+ "step": 195
1423
+ },
1424
+ {
1425
+ "epoch": 1.8217099503939305,
1426
+ "grad_norm": 0.006370636558687697,
1427
+ "learning_rate": 7.2051436514839064e-06,
1428
+ "loss": 0.6988,
1429
+ "step": 196
1430
+ },
1431
+ {
1432
+ "epoch": 1.8310475634665888,
1433
+ "grad_norm": 0.00628278997180673,
1434
+ "learning_rate": 7.106395307101621e-06,
1435
+ "loss": 0.6934,
1436
+ "step": 197
1437
+ },
1438
+ {
1439
+ "epoch": 1.8403851765392472,
1440
+ "grad_norm": 0.006032860815901838,
1441
+ "learning_rate": 7.007953960635109e-06,
1442
+ "loss": 0.6938,
1443
+ "step": 198
1444
+ },
1445
+ {
1446
+ "epoch": 1.8497227896119055,
1447
+ "grad_norm": 0.005962967202398698,
1448
+ "learning_rate": 6.909830056250527e-06,
1449
+ "loss": 0.6854,
1450
+ "step": 199
1451
+ },
1452
+ {
1453
+ "epoch": 1.8590604026845639,
1454
+ "grad_norm": 0.00554268821549102,
1455
+ "learning_rate": 6.812034004434904e-06,
1456
+ "loss": 0.6851,
1457
+ "step": 200
1458
+ },
1459
+ {
1460
+ "epoch": 1.8683980157572222,
1461
+ "grad_norm": 0.005725484983585548,
1462
+ "learning_rate": 6.714576180891653e-06,
1463
+ "loss": 0.6936,
1464
+ "step": 201
1465
+ },
1466
+ {
1467
+ "epoch": 1.8777356288298803,
1468
+ "grad_norm": 0.006054690781627555,
1469
+ "learning_rate": 6.617466925439746e-06,
1470
+ "loss": 0.6851,
1471
+ "step": 202
1472
+ },
1473
+ {
1474
+ "epoch": 1.8870732419025387,
1475
+ "grad_norm": 0.005708307473106662,
1476
+ "learning_rate": 6.520716540916709e-06,
1477
+ "loss": 0.678,
1478
+ "step": 203
1479
+ },
1480
+ {
1481
+ "epoch": 1.896410854975197,
1482
+ "grad_norm": 0.0059546695263407905,
1483
+ "learning_rate": 6.424335292085553e-06,
1484
+ "loss": 0.6854,
1485
+ "step": 204
1486
+ },
1487
+ {
1488
+ "epoch": 1.9057484680478551,
1489
+ "grad_norm": 0.006488681044848436,
1490
+ "learning_rate": 6.32833340454571e-06,
1491
+ "loss": 0.6796,
1492
+ "step": 205
1493
+ },
1494
+ {
1495
+ "epoch": 1.9150860811205135,
1496
+ "grad_norm": 0.006493914236731745,
1497
+ "learning_rate": 6.232721063648148e-06,
1498
+ "loss": 0.6745,
1499
+ "step": 206
1500
+ },
1501
+ {
1502
+ "epoch": 1.9244236941931718,
1503
+ "grad_norm": 0.006261095082612158,
1504
+ "learning_rate": 6.137508413414784e-06,
1505
+ "loss": 0.6925,
1506
+ "step": 207
1507
+ },
1508
+ {
1509
+ "epoch": 1.9337613072658302,
1510
+ "grad_norm": 0.00619237862435736,
1511
+ "learning_rate": 6.042705555462192e-06,
1512
+ "loss": 0.693,
1513
+ "step": 208
1514
+ },
1515
+ {
1516
+ "epoch": 1.9430989203384885,
1517
+ "grad_norm": 0.005985860419714863,
1518
+ "learning_rate": 5.948322547929939e-06,
1519
+ "loss": 0.6882,
1520
+ "step": 209
1521
+ },
1522
+ {
1523
+ "epoch": 1.9524365334111469,
1524
+ "grad_norm": 0.006018365152445982,
1525
+ "learning_rate": 5.8543694044133984e-06,
1526
+ "loss": 0.7059,
1527
+ "step": 210
1528
+ },
1529
+ {
1530
+ "epoch": 1.9617741464838052,
1531
+ "grad_norm": 0.006178576965302145,
1532
+ "learning_rate": 5.760856092901394e-06,
1533
+ "loss": 0.6872,
1534
+ "step": 211
1535
+ },
1536
+ {
1537
+ "epoch": 1.9711117595564633,
1538
+ "grad_norm": 0.006209928845152174,
1539
+ "learning_rate": 5.667792534718639e-06,
1540
+ "loss": 0.6955,
1541
+ "step": 212
1542
+ },
1543
+ {
1544
+ "epoch": 1.9804493726291217,
1545
+ "grad_norm": 0.006362809796961763,
1546
+ "learning_rate": 5.575188603473112e-06,
1547
+ "loss": 0.6781,
1548
+ "step": 213
1549
+ },
1550
+ {
1551
+ "epoch": 1.98978698570178,
1552
+ "grad_norm": 0.0073402479875403605,
1553
+ "learning_rate": 5.483054124008528e-06,
1554
+ "loss": 0.669,
1555
+ "step": 214
1556
+ }
1557
+ ],
1558
+ "logging_steps": 1,
1559
+ "max_steps": 321,
1560
+ "num_input_tokens_seen": 0,
1561
+ "num_train_epochs": 3,
1562
+ "save_steps": 107,
1563
+ "stateful_callbacks": {
1564
+ "TrainerControl": {
1565
+ "args": {
1566
+ "should_epoch_stop": false,
1567
+ "should_evaluate": false,
1568
+ "should_log": false,
1569
+ "should_save": true,
1570
+ "should_training_stop": false
1571
+ },
1572
+ "attributes": {}
1573
+ }
1574
+ },
1575
+ "total_flos": 6.043316961713062e+18,
1576
+ "train_batch_size": 2,
1577
+ "trial_name": null,
1578
+ "trial_params": null
1579
+ }
checkpoint-214/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c22096e6a9c9dea84f12ad6313d09723c960a987f46ad9af04dc6c1de407c91
3
+ size 10872
checkpoint-214/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-214/zero_to_fp32.py ADDED
@@ -0,0 +1,760 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example:
14
+ # python zero_to_fp32.py . output_dir/
15
+ # or
16
+ # python zero_to_fp32.py . output_dir/ --safe_serialization
17
+
18
+ import argparse
19
+ import torch
20
+ import glob
21
+ import math
22
+ import os
23
+ import re
24
+ import gc
25
+ import json
26
+ import numpy as np
27
+ from tqdm import tqdm
28
+ from collections import OrderedDict
29
+ from dataclasses import dataclass
30
+
31
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
32
+ # DeepSpeed data structures it has to be available in the current python environment.
33
+ from deepspeed.utils import logger
34
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
35
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
36
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
37
+
38
+
39
+ @dataclass
40
+ class zero_model_state:
41
+ buffers: dict()
42
+ param_shapes: dict()
43
+ shared_params: list
44
+ ds_version: int
45
+ frozen_param_shapes: dict()
46
+ frozen_param_fragments: dict()
47
+
48
+
49
+ debug = 0
50
+
51
+ # load to cpu
52
+ device = torch.device('cpu')
53
+
54
+
55
+ def atoi(text):
56
+ return int(text) if text.isdigit() else text
57
+
58
+
59
+ def natural_keys(text):
60
+ '''
61
+ alist.sort(key=natural_keys) sorts in human order
62
+ http://nedbatchelder.com/blog/200712/human_sorting.html
63
+ (See Toothy's implementation in the comments)
64
+ '''
65
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
66
+
67
+
68
+ def get_model_state_file(checkpoint_dir, zero_stage):
69
+ if not os.path.isdir(checkpoint_dir):
70
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
71
+
72
+ # there should be only one file
73
+ if zero_stage <= 2:
74
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
75
+ elif zero_stage == 3:
76
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
77
+
78
+ if not os.path.exists(file):
79
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
80
+
81
+ return file
82
+
83
+
84
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
85
+ # XXX: need to test that this simple glob rule works for multi-node setup too
86
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
87
+
88
+ if len(ckpt_files) == 0:
89
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
90
+
91
+ return ckpt_files
92
+
93
+
94
+ def get_optim_files(checkpoint_dir):
95
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
96
+
97
+
98
+ def get_model_state_files(checkpoint_dir):
99
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
100
+
101
+
102
+ def parse_model_states(files):
103
+ zero_model_states = []
104
+ for file in files:
105
+ state_dict = torch.load(file, map_location=device, weights_only=False)
106
+
107
+ if BUFFER_NAMES not in state_dict:
108
+ raise ValueError(f"{file} is not a model state checkpoint")
109
+ buffer_names = state_dict[BUFFER_NAMES]
110
+ if debug:
111
+ print("Found buffers:", buffer_names)
112
+
113
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
114
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
115
+ param_shapes = state_dict[PARAM_SHAPES]
116
+
117
+ # collect parameters that are included in param_shapes
118
+ param_names = []
119
+ for s in param_shapes:
120
+ for name in s.keys():
121
+ param_names.append(name)
122
+
123
+ # update with frozen parameters
124
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
125
+ if frozen_param_shapes is not None:
126
+ if debug:
127
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
128
+ param_names += list(frozen_param_shapes.keys())
129
+
130
+ # handle shared params
131
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
132
+
133
+ ds_version = state_dict.get(DS_VERSION, None)
134
+
135
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
136
+
137
+ z_model_state = zero_model_state(buffers=buffers,
138
+ param_shapes=param_shapes,
139
+ shared_params=shared_params,
140
+ ds_version=ds_version,
141
+ frozen_param_shapes=frozen_param_shapes,
142
+ frozen_param_fragments=frozen_param_fragments)
143
+ zero_model_states.append(z_model_state)
144
+
145
+ return zero_model_states
146
+
147
+
148
+ def parse_optim_states(files, ds_checkpoint_dir):
149
+ total_files = len(files)
150
+ state_dicts = []
151
+ for f in tqdm(files, desc='Loading checkpoint shards'):
152
+ state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
153
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
154
+ # and also handle the case where it was already removed by another helper script
155
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
156
+ state_dicts.append(state_dict)
157
+
158
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
159
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
160
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
161
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
162
+
163
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
164
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
165
+ # use the max of the partition_count to get the dp world_size.
166
+
167
+ if type(world_size) is list:
168
+ world_size = max(world_size)
169
+
170
+ if world_size != total_files:
171
+ raise ValueError(
172
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
173
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
174
+ )
175
+
176
+ # the groups are named differently in each stage
177
+ if zero_stage <= 2:
178
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
179
+ elif zero_stage == 3:
180
+ fp32_groups_key = FP32_FLAT_GROUPS
181
+ else:
182
+ raise ValueError(f"unknown zero stage {zero_stage}")
183
+
184
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
185
+ return zero_stage, world_size, fp32_flat_groups
186
+
187
+
188
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
189
+ """
190
+ Returns fp32 state_dict reconstructed from ds checkpoint
191
+
192
+ Args:
193
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
194
+
195
+ """
196
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
197
+
198
+ optim_files = get_optim_files(ds_checkpoint_dir)
199
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
200
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
201
+
202
+ model_files = get_model_state_files(ds_checkpoint_dir)
203
+
204
+ zero_model_states = parse_model_states(model_files)
205
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
206
+
207
+ if zero_stage <= 2:
208
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
209
+ exclude_frozen_parameters)
210
+ elif zero_stage == 3:
211
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
212
+ exclude_frozen_parameters)
213
+
214
+
215
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
216
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
217
+ return
218
+
219
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
220
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
221
+
222
+ if debug:
223
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
224
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
225
+
226
+ wanted_params = len(frozen_param_shapes)
227
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
228
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
229
+ print(f'Frozen params: Have {avail_numel} numels to process.')
230
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
231
+
232
+ total_params = 0
233
+ total_numel = 0
234
+ for name, shape in frozen_param_shapes.items():
235
+ total_params += 1
236
+ unpartitioned_numel = shape.numel()
237
+ total_numel += unpartitioned_numel
238
+
239
+ state_dict[name] = frozen_param_fragments[name]
240
+
241
+ if debug:
242
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
243
+
244
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
245
+
246
+
247
+ def _has_callable(obj, fn):
248
+ attr = getattr(obj, fn, None)
249
+ return callable(attr)
250
+
251
+
252
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
253
+ param_shapes = zero_model_states[0].param_shapes
254
+
255
+ # Reconstruction protocol:
256
+ #
257
+ # XXX: document this
258
+
259
+ if debug:
260
+ for i in range(world_size):
261
+ for j in range(len(fp32_flat_groups[0])):
262
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
263
+
264
+ # XXX: memory usage doubles here (zero2)
265
+ num_param_groups = len(fp32_flat_groups[0])
266
+ merged_single_partition_of_fp32_groups = []
267
+ for i in range(num_param_groups):
268
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
269
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
270
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
271
+ avail_numel = sum(
272
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
273
+
274
+ if debug:
275
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
276
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
277
+ # not asserting if there is a mismatch due to possible padding
278
+ print(f"Have {avail_numel} numels to process.")
279
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
280
+
281
+ # params
282
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
283
+ # out-of-core computing solution
284
+ total_numel = 0
285
+ total_params = 0
286
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
287
+ offset = 0
288
+ avail_numel = full_single_fp32_vector.numel()
289
+ for name, shape in shapes.items():
290
+
291
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
292
+ total_numel += unpartitioned_numel
293
+ total_params += 1
294
+
295
+ if debug:
296
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
297
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
298
+ offset += unpartitioned_numel
299
+
300
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
301
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
302
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
303
+ # live optimizer object, so we are checking that the numbers are within the right range
304
+ align_to = 2 * world_size
305
+
306
+ def zero2_align(x):
307
+ return align_to * math.ceil(x / align_to)
308
+
309
+ if debug:
310
+ print(f"original offset={offset}, avail_numel={avail_numel}")
311
+
312
+ offset = zero2_align(offset)
313
+ avail_numel = zero2_align(avail_numel)
314
+
315
+ if debug:
316
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
317
+
318
+ # Sanity check
319
+ if offset != avail_numel:
320
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
321
+
322
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
323
+
324
+
325
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
326
+ exclude_frozen_parameters):
327
+ state_dict = OrderedDict()
328
+
329
+ # buffers
330
+ buffers = zero_model_states[0].buffers
331
+ state_dict.update(buffers)
332
+ if debug:
333
+ print(f"added {len(buffers)} buffers")
334
+
335
+ if not exclude_frozen_parameters:
336
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
337
+
338
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
339
+
340
+ # recover shared parameters
341
+ for pair in zero_model_states[0].shared_params:
342
+ if pair[1] in state_dict:
343
+ state_dict[pair[0]] = state_dict[pair[1]]
344
+
345
+ return state_dict
346
+
347
+
348
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
349
+ remainder = unpartitioned_numel % world_size
350
+ padding_numel = (world_size - remainder) if remainder else 0
351
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
352
+ return partitioned_numel, padding_numel
353
+
354
+
355
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
356
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
357
+ return
358
+
359
+ if debug:
360
+ for i in range(world_size):
361
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
362
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
363
+
364
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
365
+ wanted_params = len(frozen_param_shapes)
366
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
367
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
368
+ print(f'Frozen params: Have {avail_numel} numels to process.')
369
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
370
+
371
+ total_params = 0
372
+ total_numel = 0
373
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
374
+ total_params += 1
375
+ unpartitioned_numel = shape.numel()
376
+ total_numel += unpartitioned_numel
377
+
378
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
379
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
380
+
381
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
382
+
383
+ if debug:
384
+ print(
385
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
386
+ )
387
+
388
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
389
+
390
+
391
+ class GatheredTensor:
392
+ """
393
+ A pseudo tensor that collects partitioned weights.
394
+ It is more memory efficient when there are multiple groups.
395
+ """
396
+
397
+ def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
398
+ self.flat_groups = flat_groups
399
+ self.flat_groups_offset = flat_groups_offset
400
+ self.offset = offset
401
+ self.partitioned_numel = partitioned_numel
402
+ self.shape = shape
403
+ self.dtype = self.flat_groups[0][0].dtype
404
+
405
+ def contiguous(self):
406
+ """
407
+ Merge partitioned weights from flat_groups into a single tensor.
408
+ """
409
+ end_idx = self.offset + self.partitioned_numel
410
+ world_size = len(self.flat_groups)
411
+ pad_flat_param_chunks = []
412
+
413
+ for rank_i in range(world_size):
414
+ # for each rank, we need to collect weights from related group/groups
415
+ flat_groups_at_rank_i = self.flat_groups[rank_i]
416
+ start_group_id = None
417
+ end_group_id = None
418
+ for group_id in range(len(self.flat_groups_offset)):
419
+ if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
420
+ start_group_id = group_id
421
+ if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
422
+ end_group_id = group_id
423
+ break
424
+ # collect weights from related group/groups
425
+ for group_id in range(start_group_id, end_group_id + 1):
426
+ flat_tensor = flat_groups_at_rank_i[group_id]
427
+ start_offset = self.offset - self.flat_groups_offset[group_id]
428
+ end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
429
+ pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
430
+
431
+ # collect weights from all ranks
432
+ pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
433
+ param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
434
+ return param
435
+
436
+
437
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
438
+ param_shapes = zero_model_states[0].param_shapes
439
+ avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
440
+
441
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
442
+ # param, re-consolidating each param, while dealing with padding if any
443
+
444
+ # merge list of dicts, preserving order
445
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
446
+
447
+ if debug:
448
+ for i in range(world_size):
449
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
450
+
451
+ wanted_params = len(param_shapes)
452
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
453
+ # not asserting if there is a mismatch due to possible padding
454
+ avail_numel = fp32_flat_groups[0].numel() * world_size
455
+ print(f"Trainable params: Have {avail_numel} numels to process.")
456
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
457
+
458
+ # params
459
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
460
+ # out-of-core computing solution
461
+ offset = 0
462
+ total_numel = 0
463
+ total_params = 0
464
+ flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
465
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
466
+ unpartitioned_numel = shape.numel()
467
+ total_numel += unpartitioned_numel
468
+ total_params += 1
469
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
470
+
471
+ if debug:
472
+ print(
473
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
474
+ )
475
+
476
+ # memory efficient tensor
477
+ tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
478
+ state_dict[name] = tensor
479
+ offset += partitioned_numel
480
+
481
+ offset *= world_size
482
+
483
+ # Sanity check
484
+ if offset != avail_numel:
485
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
486
+
487
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
488
+
489
+
490
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
491
+ exclude_frozen_parameters):
492
+ state_dict = OrderedDict()
493
+
494
+ # buffers
495
+ buffers = zero_model_states[0].buffers
496
+ state_dict.update(buffers)
497
+ if debug:
498
+ print(f"added {len(buffers)} buffers")
499
+
500
+ if not exclude_frozen_parameters:
501
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
502
+
503
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
504
+
505
+ # recover shared parameters
506
+ for pair in zero_model_states[0].shared_params:
507
+ if pair[1] in state_dict:
508
+ state_dict[pair[0]] = state_dict[pair[1]]
509
+
510
+ return state_dict
511
+
512
+
513
+ def to_torch_tensor(state_dict, return_empty_tensor=False):
514
+ """
515
+ Convert state_dict of GatheredTensor to torch tensor
516
+ """
517
+ torch_state_dict = {}
518
+ converted_tensors = {}
519
+ for name, tensor in state_dict.items():
520
+ tensor_id = id(tensor)
521
+ if tensor_id in converted_tensors: # shared tensors
522
+ shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
523
+ torch_state_dict[name] = shared_tensor
524
+ else:
525
+ converted_tensors[tensor_id] = name
526
+ if return_empty_tensor:
527
+ torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
528
+ else:
529
+ torch_state_dict[name] = tensor.contiguous()
530
+ return torch_state_dict
531
+
532
+
533
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
534
+ tag=None,
535
+ exclude_frozen_parameters=False,
536
+ lazy_mode=False):
537
+ """
538
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
539
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
540
+ via a model hub.
541
+
542
+ Args:
543
+ - ``checkpoint_dir``: path to the desired checkpoint folder
544
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
545
+ - ``exclude_frozen_parameters``: exclude frozen parameters
546
+ - ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
547
+ Convert the pesduo tensor to torch tensor by ``.contiguous()``
548
+
549
+ Returns:
550
+ - pytorch ``state_dict``
551
+
552
+ A typical usage might be ::
553
+
554
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
555
+ # do the training and checkpoint saving
556
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
557
+ model = model.cpu() # move to cpu
558
+ model.load_state_dict(state_dict)
559
+ # submit to model hub or save the model to share with others
560
+
561
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
562
+ application. i.e. you will need to re-initialize the deepspeed engine, since
563
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
564
+
565
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
566
+
567
+ Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
568
+ You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
569
+ the checkpoint. Or you can load state_dict in lazy mode ::
570
+
571
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
572
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
573
+ for name, lazy_tensor in state_dict.item():
574
+ tensor = lazy_tensor.contiguous() # to cpu
575
+ print(name, tensor)
576
+ # del tensor to release memory if it no longer in use
577
+ """
578
+ if tag is None:
579
+ latest_path = os.path.join(checkpoint_dir, 'latest')
580
+ if os.path.isfile(latest_path):
581
+ with open(latest_path, 'r') as fd:
582
+ tag = fd.read().strip()
583
+ else:
584
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
585
+
586
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
587
+
588
+ if not os.path.isdir(ds_checkpoint_dir):
589
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
590
+
591
+ state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
592
+ if lazy_mode:
593
+ return state_dict
594
+ else:
595
+ return to_torch_tensor(state_dict)
596
+
597
+
598
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
599
+ output_dir,
600
+ max_shard_size="5GB",
601
+ safe_serialization=False,
602
+ tag=None,
603
+ exclude_frozen_parameters=False):
604
+ """
605
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
606
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
607
+
608
+ Args:
609
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
610
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
611
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
612
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
613
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
614
+ - ``exclude_frozen_parameters``: exclude frozen parameters
615
+ """
616
+
617
+ # Dependency pre-check
618
+ if safe_serialization:
619
+ try:
620
+ from safetensors.torch import save_file
621
+ except ImportError:
622
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
623
+ raise
624
+ if max_shard_size is not None:
625
+ try:
626
+ from huggingface_hub import split_torch_state_dict_into_shards
627
+ except ImportError:
628
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
629
+ raise
630
+
631
+ # Convert zero checkpoint to state_dict
632
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
633
+ tag,
634
+ exclude_frozen_parameters,
635
+ lazy_mode=True)
636
+
637
+ # Shard the model if it is too big.
638
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
639
+ if max_shard_size is not None:
640
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
641
+ # an memory-efficient approach for sharding
642
+ empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
643
+ state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
644
+ filename_pattern=filename_pattern,
645
+ max_shard_size=max_shard_size)
646
+ else:
647
+ from collections import namedtuple
648
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
649
+ state_dict_split = StateDictSplit(is_sharded=False,
650
+ filename_to_tensors={weights_name: list(state_dict.keys())})
651
+
652
+ # Save the model by shard
653
+ os.makedirs(output_dir, exist_ok=True)
654
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
655
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
656
+ shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
657
+ shard_state_dict = to_torch_tensor(shard_state_dict)
658
+ output_path = os.path.join(output_dir, shard_file)
659
+ if safe_serialization:
660
+ save_file(shard_state_dict, output_path, metadata={"format": "pt"})
661
+ else:
662
+ torch.save(shard_state_dict, output_path)
663
+ # release the memory of current shard
664
+ for tensor_name in list(shard_state_dict.keys()):
665
+ del state_dict[tensor_name]
666
+ del shard_state_dict[tensor_name]
667
+ del shard_state_dict
668
+ gc.collect()
669
+
670
+ # Save index if sharded
671
+ if state_dict_split.is_sharded:
672
+ index = {
673
+ "metadata": state_dict_split.metadata,
674
+ "weight_map": state_dict_split.tensor_to_filename,
675
+ }
676
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
677
+ save_index_file = os.path.join(output_dir, save_index_file)
678
+ with open(save_index_file, "w", encoding="utf-8") as f:
679
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
680
+ f.write(content)
681
+
682
+
683
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
684
+ """
685
+ 1. Put the provided model to cpu
686
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
687
+ 3. Load it into the provided model
688
+
689
+ Args:
690
+ - ``model``: the model object to update
691
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
692
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
693
+
694
+ Returns:
695
+ - ``model`: modified model
696
+
697
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
698
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
699
+ conveniently placed for you in the checkpoint folder.
700
+
701
+ A typical usage might be ::
702
+
703
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
704
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
705
+ # submit to model hub or save the model to share with others
706
+
707
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
708
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
709
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
710
+
711
+ """
712
+ logger.info(f"Extracting fp32 weights")
713
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
714
+
715
+ logger.info(f"Overwriting model with fp32 weights")
716
+ model = model.cpu()
717
+ model.load_state_dict(state_dict, strict=False)
718
+
719
+ return model
720
+
721
+
722
+ if __name__ == "__main__":
723
+ parser = argparse.ArgumentParser()
724
+ parser.add_argument("checkpoint_dir",
725
+ type=str,
726
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
727
+ parser.add_argument("output_dir",
728
+ type=str,
729
+ help="directory to the pytorch fp32 state_dict output files"
730
+ "(e.g. path/checkpoint-12-output/)")
731
+ parser.add_argument(
732
+ "--max_shard_size",
733
+ type=str,
734
+ default="5GB",
735
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
736
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
737
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
738
+ "without CPU OOM issues.")
739
+ parser.add_argument(
740
+ "--safe_serialization",
741
+ default=False,
742
+ action='store_true',
743
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
744
+ parser.add_argument("-t",
745
+ "--tag",
746
+ type=str,
747
+ default=None,
748
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
749
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
750
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
751
+ args = parser.parse_args()
752
+
753
+ debug = args.debug
754
+
755
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
756
+ args.output_dir,
757
+ max_shard_size=args.max_shard_size,
758
+ safe_serialization=args.safe_serialization,
759
+ tag=args.tag,
760
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
checkpoint-321/added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
checkpoint-321/config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Qwen/Qwen2.5-Math-1.5B-Instruct",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "eos_token_id": 151645,
8
+ "hidden_act": "silu",
9
+ "hidden_size": 1536,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 8960,
12
+ "max_position_embeddings": 32768,
13
+ "max_window_layers": 21,
14
+ "model_type": "qwen2",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 28,
17
+ "num_key_value_heads": 2,
18
+ "rms_norm_eps": 1e-06,
19
+ "rope_scaling": {
20
+ "factor": 8.0,
21
+ "type": "linear"
22
+ },
23
+ "rope_theta": 10000.0,
24
+ "sliding_window": null,
25
+ "tie_word_embeddings": true,
26
+ "torch_dtype": "bfloat16",
27
+ "transformers_version": "4.48.3",
28
+ "use_cache": false,
29
+ "use_sliding_window": false,
30
+ "vocab_size": 151665
31
+ }
checkpoint-321/generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "transformers_version": "4.48.3"
10
+ }