cutelemonlili commited on
Commit
b28adb4
·
verified ·
1 Parent(s): 996feca

Add files using upload-large-folder tool

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151643,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 1536,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 8960,
13
+ "max_position_embeddings": 131072,
14
+ "max_window_layers": 21,
15
+ "model_type": "qwen2",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 28,
18
+ "num_key_value_heads": 2,
19
+ "rms_norm_eps": 1e-06,
20
+ "rope_scaling": null,
21
+ "rope_theta": 10000,
22
+ "sliding_window": 4096,
23
+ "tie_word_embeddings": false,
24
+ "torch_dtype": "bfloat16",
25
+ "transformers_version": "4.49.0",
26
+ "use_cache": false,
27
+ "use_mrope": false,
28
+ "use_sliding_window": false,
29
+ "vocab_size": 151936
30
+ }
generation_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 151646,
4
+ "do_sample": true,
5
+ "eos_token_id": 151643,
6
+ "temperature": 0.6,
7
+ "top_p": 0.95,
8
+ "transformers_version": "4.49.0"
9
+ }
latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step50
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd7794f885763ea54610093c6434279c892012211173a5a43c7b3eed67d81831
3
+ size 3554214752
rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5fdf5dab088e40643817c4729a171b87d19f30b4693074f67498e787ec3ebf99
3
+ size 14960
rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:93534a5e1a72750a0a250a8b7f453be2d25abf03a7ddd59220f8f95670323176
3
+ size 14960
rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15e7056d80551f130219ac8e710c1cdaf71949805baf2be9ab493dd3954bd3dc
3
+ size 14960
scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b1eb06383f9abe538d3bacb9e95a3d1b19c21cae1dfb62d8567723fcc11b74a
3
+ size 1064
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|begin▁of▁sentence|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|end▁of▁sentence|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<|end▁of▁sentence|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4256422650d141f228fe954acee98679da412984c29a569877eefd3af69315a
3
+ size 11422959
tokenizer_config.json ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "151643": {
7
+ "content": "<|end▁of▁sentence|>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "151644": {
15
+ "content": "<|User|>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": false
21
+ },
22
+ "151645": {
23
+ "content": "<|Assistant|>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": false
29
+ },
30
+ "151646": {
31
+ "content": "<|begin▁of▁sentence|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "151647": {
39
+ "content": "<|EOT|>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": false,
43
+ "single_word": false,
44
+ "special": false
45
+ },
46
+ "151648": {
47
+ "content": "<think>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": false,
51
+ "single_word": false,
52
+ "special": false
53
+ },
54
+ "151649": {
55
+ "content": "</think>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": false,
59
+ "single_word": false,
60
+ "special": false
61
+ },
62
+ "151650": {
63
+ "content": "<|quad_start|>",
64
+ "lstrip": false,
65
+ "normalized": false,
66
+ "rstrip": false,
67
+ "single_word": false,
68
+ "special": true
69
+ },
70
+ "151651": {
71
+ "content": "<|quad_end|>",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": false,
75
+ "single_word": false,
76
+ "special": true
77
+ },
78
+ "151652": {
79
+ "content": "<|vision_start|>",
80
+ "lstrip": false,
81
+ "normalized": false,
82
+ "rstrip": false,
83
+ "single_word": false,
84
+ "special": true
85
+ },
86
+ "151653": {
87
+ "content": "<|vision_end|>",
88
+ "lstrip": false,
89
+ "normalized": false,
90
+ "rstrip": false,
91
+ "single_word": false,
92
+ "special": true
93
+ },
94
+ "151654": {
95
+ "content": "<|vision_pad|>",
96
+ "lstrip": false,
97
+ "normalized": false,
98
+ "rstrip": false,
99
+ "single_word": false,
100
+ "special": true
101
+ },
102
+ "151655": {
103
+ "content": "<|image_pad|>",
104
+ "lstrip": false,
105
+ "normalized": false,
106
+ "rstrip": false,
107
+ "single_word": false,
108
+ "special": true
109
+ },
110
+ "151656": {
111
+ "content": "<|video_pad|>",
112
+ "lstrip": false,
113
+ "normalized": false,
114
+ "rstrip": false,
115
+ "single_word": false,
116
+ "special": true
117
+ },
118
+ "151657": {
119
+ "content": "<tool_call>",
120
+ "lstrip": false,
121
+ "normalized": false,
122
+ "rstrip": false,
123
+ "single_word": false,
124
+ "special": false
125
+ },
126
+ "151658": {
127
+ "content": "</tool_call>",
128
+ "lstrip": false,
129
+ "normalized": false,
130
+ "rstrip": false,
131
+ "single_word": false,
132
+ "special": false
133
+ },
134
+ "151659": {
135
+ "content": "<|fim_prefix|>",
136
+ "lstrip": false,
137
+ "normalized": false,
138
+ "rstrip": false,
139
+ "single_word": false,
140
+ "special": false
141
+ },
142
+ "151660": {
143
+ "content": "<|fim_middle|>",
144
+ "lstrip": false,
145
+ "normalized": false,
146
+ "rstrip": false,
147
+ "single_word": false,
148
+ "special": false
149
+ },
150
+ "151661": {
151
+ "content": "<|fim_suffix|>",
152
+ "lstrip": false,
153
+ "normalized": false,
154
+ "rstrip": false,
155
+ "single_word": false,
156
+ "special": false
157
+ },
158
+ "151662": {
159
+ "content": "<|fim_pad|>",
160
+ "lstrip": false,
161
+ "normalized": false,
162
+ "rstrip": false,
163
+ "single_word": false,
164
+ "special": false
165
+ },
166
+ "151663": {
167
+ "content": "<|repo_name|>",
168
+ "lstrip": false,
169
+ "normalized": false,
170
+ "rstrip": false,
171
+ "single_word": false,
172
+ "special": false
173
+ },
174
+ "151664": {
175
+ "content": "<|file_sep|>",
176
+ "lstrip": false,
177
+ "normalized": false,
178
+ "rstrip": false,
179
+ "single_word": false,
180
+ "special": false
181
+ }
182
+ },
183
+ "bos_token": "<|begin▁of▁sentence|>",
184
+ "chat_template": "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='') %}{%- for message in messages %}{%- if message['role'] == 'system' %}{% set ns.system_prompt = message['content'] %}{%- endif %}{%- endfor %}{{bos_token}}{{ns.system_prompt}}{%- for message in messages %}{%- if message['role'] == 'user' %}{%- set ns.is_tool = false -%}{{'<|User|>' + message['content']}}{%- endif %}{%- if message['role'] == 'assistant' and message['content'] is none %}{%- set ns.is_tool = false -%}{%- for tool in message['tool_calls']%}{%- if not ns.is_first %}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin��>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{%- set ns.is_first = true -%}{%- else %}{{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- endfor %}{%- endif %}{%- if message['role'] == 'assistant' and message['content'] is not none %}{%- if ns.is_tool %}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{% set content = message['content'] %}{% if '</think>' in content %}{% set content = content.split('</think>')[-1] %}{% endif %}{{'<|Assistant|>' + content + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_tool = true -%}{%- if ns.is_output_first %}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- set ns.is_output_first = false %}{%- else %}{{'\\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'<|tool▁outputs▁end|>'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'<|Assistant|><think>\\n'}}{% endif %}",
185
+ "clean_up_tokenization_spaces": false,
186
+ "eos_token": "<|end▁of▁sentence|>",
187
+ "extra_special_tokens": {},
188
+ "legacy": true,
189
+ "model_max_length": 16384,
190
+ "pad_token": "<|end▁of▁sentence|>",
191
+ "sp_model_kwargs": {},
192
+ "tokenizer_class": "LlamaTokenizerFast",
193
+ "unk_token": null,
194
+ "use_default_system_prompt": false
195
+ }
trainer_state.json ADDED
@@ -0,0 +1,733 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.0856898029134533,
5
+ "eval_steps": 500,
6
+ "global_step": 50,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "clip_ratio": 0.0,
13
+ "completion_length": 2862.5695190429688,
14
+ "epoch": 0.001713796058269066,
15
+ "grad_norm": 0.16917119920253754,
16
+ "kl": 0.0,
17
+ "learning_rate": 2e-08,
18
+ "loss": 0.0467,
19
+ "reward": 0.12026740610599518,
20
+ "reward_std": 0.47210293635725975,
21
+ "rewards/cosine_scaled_reward": -0.1343107339926064,
22
+ "rewards/format_reward": 0.3888888917863369,
23
+ "step": 1
24
+ },
25
+ {
26
+ "clip_ratio": 0.0,
27
+ "completion_length": 2739.5,
28
+ "epoch": 0.003427592116538132,
29
+ "grad_norm": 0.18499086797237396,
30
+ "kl": 0.0,
31
+ "learning_rate": 4e-08,
32
+ "loss": 0.0391,
33
+ "reward": -0.05314926430583,
34
+ "reward_std": 0.36226021870970726,
35
+ "rewards/cosine_scaled_reward": -0.21407463820651174,
36
+ "rewards/format_reward": 0.3750000111758709,
37
+ "step": 2
38
+ },
39
+ {
40
+ "clip_ratio": 0.0,
41
+ "completion_length": 2830.77783203125,
42
+ "epoch": 0.005141388174807198,
43
+ "grad_norm": 0.18050141632556915,
44
+ "kl": 3.692507743835449e-05,
45
+ "learning_rate": 6e-08,
46
+ "loss": -0.0099,
47
+ "reward": 0.09248740691691637,
48
+ "reward_std": 0.6634868904948235,
49
+ "rewards/cosine_scaled_reward": -0.15514518693089485,
50
+ "rewards/format_reward": 0.4027777798473835,
51
+ "step": 3
52
+ },
53
+ {
54
+ "clip_ratio": 0.0,
55
+ "completion_length": 2805.625,
56
+ "epoch": 0.006855184233076264,
57
+ "grad_norm": 0.16725227236747742,
58
+ "kl": 3.123283386230469e-05,
59
+ "learning_rate": 8e-08,
60
+ "loss": 0.0535,
61
+ "reward": 0.29482341557741165,
62
+ "reward_std": 0.7357868105173111,
63
+ "rewards/cosine_scaled_reward": -0.08869940415024757,
64
+ "rewards/format_reward": 0.4722222313284874,
65
+ "step": 4
66
+ },
67
+ {
68
+ "clip_ratio": 0.0,
69
+ "completion_length": 2503.4305419921875,
70
+ "epoch": 0.00856898029134533,
71
+ "grad_norm": 0.1689172238111496,
72
+ "kl": 2.6106834411621094e-05,
73
+ "learning_rate": 1e-07,
74
+ "loss": 0.0737,
75
+ "reward": 0.5638985820114613,
76
+ "reward_std": 0.5826280601322651,
77
+ "rewards/cosine_scaled_reward": -0.009717360138893127,
78
+ "rewards/format_reward": 0.5833333283662796,
79
+ "step": 5
80
+ },
81
+ {
82
+ "clip_ratio": 0.0,
83
+ "completion_length": 3151.4305419921875,
84
+ "epoch": 0.010282776349614395,
85
+ "grad_norm": 0.20181749761104584,
86
+ "kl": 4.225969314575195e-05,
87
+ "learning_rate": 1.2e-07,
88
+ "loss": 0.0636,
89
+ "reward": -0.12377724796533585,
90
+ "reward_std": 0.5666400231420994,
91
+ "rewards/cosine_scaled_reward": -0.19383307732641697,
92
+ "rewards/format_reward": 0.2638888889923692,
93
+ "step": 6
94
+ },
95
+ {
96
+ "clip_ratio": 0.0,
97
+ "completion_length": 2207.652801513672,
98
+ "epoch": 0.011996572407883462,
99
+ "grad_norm": 0.26183807849884033,
100
+ "kl": 3.224611282348633e-05,
101
+ "learning_rate": 1.4e-07,
102
+ "loss": 0.0306,
103
+ "reward": 0.588454547803849,
104
+ "reward_std": 0.710302334278822,
105
+ "rewards/cosine_scaled_reward": -0.03910606319550425,
106
+ "rewards/format_reward": 0.6666666716337204,
107
+ "step": 7
108
+ },
109
+ {
110
+ "clip_ratio": 0.0,
111
+ "completion_length": 2880.6388549804688,
112
+ "epoch": 0.013710368466152529,
113
+ "grad_norm": 0.1484246701002121,
114
+ "kl": 2.5212764739990234e-05,
115
+ "learning_rate": 1.6e-07,
116
+ "loss": 0.0465,
117
+ "reward": 0.5758275026455522,
118
+ "reward_std": 0.8158164247870445,
119
+ "rewards/cosine_scaled_reward": 0.01708040665835142,
120
+ "rewards/format_reward": 0.5416666716337204,
121
+ "step": 8
122
+ },
123
+ {
124
+ "clip_ratio": 0.0,
125
+ "completion_length": 2553.8611450195312,
126
+ "epoch": 0.015424164524421594,
127
+ "grad_norm": 0.29594743251800537,
128
+ "kl": 2.3365020751953125e-05,
129
+ "learning_rate": 1.8e-07,
130
+ "loss": 0.0821,
131
+ "reward": 0.235587022267282,
132
+ "reward_std": 0.7132463157176971,
133
+ "rewards/cosine_scaled_reward": -0.11137315654195845,
134
+ "rewards/format_reward": 0.45833334419876337,
135
+ "step": 9
136
+ },
137
+ {
138
+ "clip_ratio": 0.0,
139
+ "completion_length": 2864.3333740234375,
140
+ "epoch": 0.01713796058269066,
141
+ "grad_norm": 0.18843963742256165,
142
+ "kl": 3.55839729309082e-05,
143
+ "learning_rate": 2e-07,
144
+ "loss": 0.0595,
145
+ "reward": 0.3688787994906306,
146
+ "reward_std": 0.9138147085905075,
147
+ "rewards/cosine_scaled_reward": -0.016949500888586044,
148
+ "rewards/format_reward": 0.4027777761220932,
149
+ "step": 10
150
+ },
151
+ {
152
+ "clip_ratio": 0.0,
153
+ "completion_length": 2650.374969482422,
154
+ "epoch": 0.018851756640959727,
155
+ "grad_norm": 0.35286611318588257,
156
+ "kl": 3.769993782043457e-05,
157
+ "learning_rate": 2.1999999999999998e-07,
158
+ "loss": 0.1724,
159
+ "reward": 0.1046360395848751,
160
+ "reward_std": 0.672421894967556,
161
+ "rewards/cosine_scaled_reward": -0.12129308935254812,
162
+ "rewards/format_reward": 0.34722223225980997,
163
+ "step": 11
164
+ },
165
+ {
166
+ "clip_ratio": 0.0,
167
+ "completion_length": 2968.8750610351562,
168
+ "epoch": 0.02056555269922879,
169
+ "grad_norm": 0.33867669105529785,
170
+ "kl": 3.49581241607666e-05,
171
+ "learning_rate": 2.4e-07,
172
+ "loss": 0.1097,
173
+ "reward": -0.1256260685622692,
174
+ "reward_std": 0.5329847931861877,
175
+ "rewards/cosine_scaled_reward": -0.22253524931147695,
176
+ "rewards/format_reward": 0.3194444477558136,
177
+ "step": 12
178
+ },
179
+ {
180
+ "clip_ratio": 0.0,
181
+ "completion_length": 2797.5555419921875,
182
+ "epoch": 0.022279348757497857,
183
+ "grad_norm": 0.18638171255588531,
184
+ "kl": 3.197789192199707e-05,
185
+ "learning_rate": 2.6e-07,
186
+ "loss": -0.0238,
187
+ "reward": 0.3018228765577078,
188
+ "reward_std": 0.7313368320465088,
189
+ "rewards/cosine_scaled_reward": -0.06436635553836823,
190
+ "rewards/format_reward": 0.43055556155741215,
191
+ "step": 13
192
+ },
193
+ {
194
+ "clip_ratio": 0.0,
195
+ "completion_length": 2933.9444580078125,
196
+ "epoch": 0.023993144815766924,
197
+ "grad_norm": 0.24482618272304535,
198
+ "kl": 3.820657730102539e-05,
199
+ "learning_rate": 2.8e-07,
200
+ "loss": 0.0235,
201
+ "reward": 0.058196403086185455,
202
+ "reward_std": 0.5374786257743835,
203
+ "rewards/cosine_scaled_reward": -0.12367959041148424,
204
+ "rewards/format_reward": 0.3055555634200573,
205
+ "step": 14
206
+ },
207
+ {
208
+ "clip_ratio": 0.0,
209
+ "completion_length": 3445.888916015625,
210
+ "epoch": 0.02570694087403599,
211
+ "grad_norm": 0.12928012013435364,
212
+ "kl": 4.57763671875e-05,
213
+ "learning_rate": 3e-07,
214
+ "loss": 0.036,
215
+ "reward": -0.03555959090590477,
216
+ "reward_std": 0.8275671154260635,
217
+ "rewards/cosine_scaled_reward": -0.1358353467658162,
218
+ "rewards/format_reward": 0.23611111752688885,
219
+ "step": 15
220
+ },
221
+ {
222
+ "clip_ratio": 0.0,
223
+ "completion_length": 2473.013916015625,
224
+ "epoch": 0.027420736932305057,
225
+ "grad_norm": 0.18912632763385773,
226
+ "kl": 3.026425838470459e-05,
227
+ "learning_rate": 3.2e-07,
228
+ "loss": 0.0402,
229
+ "reward": 0.7541989013552666,
230
+ "reward_std": 0.7829795032739639,
231
+ "rewards/cosine_scaled_reward": 0.07848833221942186,
232
+ "rewards/format_reward": 0.5972222313284874,
233
+ "step": 16
234
+ },
235
+ {
236
+ "clip_ratio": 0.0,
237
+ "completion_length": 2747.5694580078125,
238
+ "epoch": 0.02913453299057412,
239
+ "grad_norm": 0.28827619552612305,
240
+ "kl": 3.106892108917236e-05,
241
+ "learning_rate": 3.4000000000000003e-07,
242
+ "loss": 0.009,
243
+ "reward": 0.4498763456940651,
244
+ "reward_std": 0.5080211237072945,
245
+ "rewards/cosine_scaled_reward": 0.03743817750364542,
246
+ "rewards/format_reward": 0.37500000186264515,
247
+ "step": 17
248
+ },
249
+ {
250
+ "clip_ratio": 0.0,
251
+ "completion_length": 3216.0694580078125,
252
+ "epoch": 0.030848329048843187,
253
+ "grad_norm": 0.13800697028636932,
254
+ "kl": 3.427267074584961e-05,
255
+ "learning_rate": 3.6e-07,
256
+ "loss": -0.0062,
257
+ "reward": -0.10277504308032803,
258
+ "reward_std": 0.5791455134749413,
259
+ "rewards/cosine_scaled_reward": -0.17638752236962318,
260
+ "rewards/format_reward": 0.2500000074505806,
261
+ "step": 18
262
+ },
263
+ {
264
+ "clip_ratio": 0.0,
265
+ "completion_length": 3065.2916870117188,
266
+ "epoch": 0.032562125107112254,
267
+ "grad_norm": 0.1491522639989853,
268
+ "kl": 3.0159950256347656e-05,
269
+ "learning_rate": 3.7999999999999996e-07,
270
+ "loss": 0.0265,
271
+ "reward": 0.019092530012130737,
272
+ "reward_std": 0.7753017023205757,
273
+ "rewards/cosine_scaled_reward": -0.14323152415454388,
274
+ "rewards/format_reward": 0.3055555606260896,
275
+ "step": 19
276
+ },
277
+ {
278
+ "clip_ratio": 0.0,
279
+ "completion_length": 3379.2777709960938,
280
+ "epoch": 0.03427592116538132,
281
+ "grad_norm": 0.2114741951227188,
282
+ "kl": 2.86102294921875e-05,
283
+ "learning_rate": 4e-07,
284
+ "loss": 0.047,
285
+ "reward": -0.053781009279191494,
286
+ "reward_std": 0.6423763372004032,
287
+ "rewards/cosine_scaled_reward": -0.13800161890685558,
288
+ "rewards/format_reward": 0.22222222946584225,
289
+ "step": 20
290
+ },
291
+ {
292
+ "clip_ratio": 0.0,
293
+ "completion_length": 2875.291717529297,
294
+ "epoch": 0.03598971722365039,
295
+ "grad_norm": 0.2242029458284378,
296
+ "kl": 4.082918167114258e-05,
297
+ "learning_rate": 4.1999999999999995e-07,
298
+ "loss": 0.0932,
299
+ "reward": 0.013707960490137339,
300
+ "reward_std": 0.6616120561957359,
301
+ "rewards/cosine_scaled_reward": -0.1528682578355074,
302
+ "rewards/format_reward": 0.3194444552063942,
303
+ "step": 21
304
+ },
305
+ {
306
+ "clip_ratio": 0.0,
307
+ "completion_length": 3119.0833129882812,
308
+ "epoch": 0.037703513281919454,
309
+ "grad_norm": 0.16363810002803802,
310
+ "kl": 2.7298927307128906e-05,
311
+ "learning_rate": 4.3999999999999997e-07,
312
+ "loss": 0.0862,
313
+ "reward": 0.10138127207756042,
314
+ "reward_std": 0.662372387945652,
315
+ "rewards/cosine_scaled_reward": -0.11597602907568216,
316
+ "rewards/format_reward": 0.3333333358168602,
317
+ "step": 22
318
+ },
319
+ {
320
+ "clip_ratio": 0.0,
321
+ "completion_length": 3114.138916015625,
322
+ "epoch": 0.03941730934018852,
323
+ "grad_norm": 0.14078961312770844,
324
+ "kl": 2.0310282707214355e-05,
325
+ "learning_rate": 4.6e-07,
326
+ "loss": 0.0087,
327
+ "reward": -0.18106067180633545,
328
+ "reward_std": 0.5297312885522842,
329
+ "rewards/cosine_scaled_reward": -0.22247478552162647,
330
+ "rewards/format_reward": 0.2638888917863369,
331
+ "step": 23
332
+ },
333
+ {
334
+ "clip_ratio": 0.0,
335
+ "completion_length": 2742.736083984375,
336
+ "epoch": 0.04113110539845758,
337
+ "grad_norm": 0.17268158495426178,
338
+ "kl": 2.4259090423583984e-05,
339
+ "learning_rate": 4.8e-07,
340
+ "loss": 0.0427,
341
+ "reward": 0.21900439262390137,
342
+ "reward_std": 0.4178895503282547,
343
+ "rewards/cosine_scaled_reward": -0.07105334987863898,
344
+ "rewards/format_reward": 0.361111119389534,
345
+ "step": 24
346
+ },
347
+ {
348
+ "clip_ratio": 0.0,
349
+ "completion_length": 2691.263916015625,
350
+ "epoch": 0.04284490145672665,
351
+ "grad_norm": 0.31574270129203796,
352
+ "kl": 3.209710121154785e-05,
353
+ "learning_rate": 5e-07,
354
+ "loss": 0.055,
355
+ "reward": 0.1675301417708397,
356
+ "reward_std": 0.8015742003917694,
357
+ "rewards/cosine_scaled_reward": -0.1454015839844942,
358
+ "rewards/format_reward": 0.4583333395421505,
359
+ "step": 25
360
+ },
361
+ {
362
+ "clip_ratio": 0.0,
363
+ "completion_length": 3124.7361450195312,
364
+ "epoch": 0.044558697514995714,
365
+ "grad_norm": 0.18195514380931854,
366
+ "kl": 3.510713577270508e-05,
367
+ "learning_rate": 5.2e-07,
368
+ "loss": 0.1146,
369
+ "reward": 0.12784775905311108,
370
+ "reward_std": 0.7148727774620056,
371
+ "rewards/cosine_scaled_reward": -0.10968722542747855,
372
+ "rewards/format_reward": 0.3472222276031971,
373
+ "step": 26
374
+ },
375
+ {
376
+ "clip_ratio": 0.0,
377
+ "completion_length": 3161.9306030273438,
378
+ "epoch": 0.04627249357326478,
379
+ "grad_norm": 0.1664053052663803,
380
+ "kl": 1.7210841178894043e-05,
381
+ "learning_rate": 5.4e-07,
382
+ "loss": 0.066,
383
+ "reward": 0.3565527945756912,
384
+ "reward_std": 0.7730190977454185,
385
+ "rewards/cosine_scaled_reward": 0.01160972099751234,
386
+ "rewards/format_reward": 0.3333333432674408,
387
+ "step": 27
388
+ },
389
+ {
390
+ "clip_ratio": 0.0,
391
+ "completion_length": 2473.9444580078125,
392
+ "epoch": 0.04798628963153385,
393
+ "grad_norm": 0.3084779679775238,
394
+ "kl": 3.291666507720947e-05,
395
+ "learning_rate": 5.6e-07,
396
+ "loss": 0.0691,
397
+ "reward": 0.5224915966391563,
398
+ "reward_std": 0.6627854257822037,
399
+ "rewards/cosine_scaled_reward": -0.0026430808939039707,
400
+ "rewards/format_reward": 0.5277777910232544,
401
+ "step": 28
402
+ },
403
+ {
404
+ "clip_ratio": 0.0,
405
+ "completion_length": 3082.3333740234375,
406
+ "epoch": 0.049700085689802914,
407
+ "grad_norm": 0.19051846861839294,
408
+ "kl": 3.807246685028076e-05,
409
+ "learning_rate": 5.8e-07,
410
+ "loss": 0.0483,
411
+ "reward": 0.3683222606778145,
412
+ "reward_std": 1.0155043303966522,
413
+ "rewards/cosine_scaled_reward": -0.024172214791178703,
414
+ "rewards/format_reward": 0.41666666977107525,
415
+ "step": 29
416
+ },
417
+ {
418
+ "clip_ratio": 0.0,
419
+ "completion_length": 2674.8750610351562,
420
+ "epoch": 0.05141388174807198,
421
+ "grad_norm": 0.2294771671295166,
422
+ "kl": 3.553926944732666e-05,
423
+ "learning_rate": 6e-07,
424
+ "loss": 0.094,
425
+ "reward": 0.3091086260974407,
426
+ "reward_std": 0.7602805271744728,
427
+ "rewards/cosine_scaled_reward": -0.10239012539386749,
428
+ "rewards/format_reward": 0.5138888880610466,
429
+ "step": 30
430
+ },
431
+ {
432
+ "clip_ratio": 0.0,
433
+ "completion_length": 2638.4583129882812,
434
+ "epoch": 0.05312767780634105,
435
+ "grad_norm": 0.1822758913040161,
436
+ "kl": 2.135336399078369e-05,
437
+ "learning_rate": 6.2e-07,
438
+ "loss": 0.0591,
439
+ "reward": 0.41959726088680327,
440
+ "reward_std": 0.5659373477101326,
441
+ "rewards/cosine_scaled_reward": 0.0014653010293841362,
442
+ "rewards/format_reward": 0.4166666716337204,
443
+ "step": 31
444
+ },
445
+ {
446
+ "clip_ratio": 0.0,
447
+ "completion_length": 2679.65283203125,
448
+ "epoch": 0.054841473864610114,
449
+ "grad_norm": 0.26114267110824585,
450
+ "kl": 2.42539681494236e-05,
451
+ "learning_rate": 6.4e-07,
452
+ "loss": 0.1342,
453
+ "reward": 0.39799272175878286,
454
+ "reward_std": 0.8707453161478043,
455
+ "rewards/cosine_scaled_reward": -0.08572587324306369,
456
+ "rewards/format_reward": 0.5694444514811039,
457
+ "step": 32
458
+ },
459
+ {
460
+ "clip_ratio": 0.0,
461
+ "completion_length": 2365.5556030273438,
462
+ "epoch": 0.056555269922879174,
463
+ "grad_norm": 0.2686753571033478,
464
+ "kl": 6.015598773956299e-05,
465
+ "learning_rate": 6.6e-07,
466
+ "loss": 0.096,
467
+ "reward": 0.6290882844477892,
468
+ "reward_std": 0.9406441152095795,
469
+ "rewards/cosine_scaled_reward": 0.05065522436052561,
470
+ "rewards/format_reward": 0.5277777798473835,
471
+ "step": 33
472
+ },
473
+ {
474
+ "clip_ratio": 0.0,
475
+ "completion_length": 2769.9722900390625,
476
+ "epoch": 0.05826906598114824,
477
+ "grad_norm": 0.26905301213264465,
478
+ "kl": 9.942054748535156e-05,
479
+ "learning_rate": 6.800000000000001e-07,
480
+ "loss": 0.1084,
481
+ "reward": 0.12581600830890238,
482
+ "reward_std": 0.6685186251997948,
483
+ "rewards/cosine_scaled_reward": -0.13848087890073657,
484
+ "rewards/format_reward": 0.4027777835726738,
485
+ "step": 34
486
+ },
487
+ {
488
+ "clip_ratio": 0.0,
489
+ "completion_length": 3135.5694580078125,
490
+ "epoch": 0.05998286203941731,
491
+ "grad_norm": 0.1376740038394928,
492
+ "kl": 8.040666580200195e-05,
493
+ "learning_rate": 7e-07,
494
+ "loss": 0.0542,
495
+ "reward": -0.20180033892393112,
496
+ "reward_std": 0.46953874826431274,
497
+ "rewards/cosine_scaled_reward": -0.2328446013852954,
498
+ "rewards/format_reward": 0.2638888927176595,
499
+ "step": 35
500
+ },
501
+ {
502
+ "clip_ratio": 0.0,
503
+ "completion_length": 2743.3055725097656,
504
+ "epoch": 0.061696658097686374,
505
+ "grad_norm": 0.19778397679328918,
506
+ "kl": 0.00010716915130615234,
507
+ "learning_rate": 7.2e-07,
508
+ "loss": 0.0158,
509
+ "reward": 0.12446275702677667,
510
+ "reward_std": 0.5396032929420471,
511
+ "rewards/cosine_scaled_reward": -0.1391575187444687,
512
+ "rewards/format_reward": 0.40277778543531895,
513
+ "step": 36
514
+ },
515
+ {
516
+ "clip_ratio": 0.0,
517
+ "completion_length": 3021.9861450195312,
518
+ "epoch": 0.06341045415595545,
519
+ "grad_norm": 0.16646842658519745,
520
+ "kl": 4.979968070983887e-05,
521
+ "learning_rate": 7.4e-07,
522
+ "loss": 0.0452,
523
+ "reward": -0.27577453199774027,
524
+ "reward_std": 0.3186095915734768,
525
+ "rewards/cosine_scaled_reward": -0.26288727298378944,
526
+ "rewards/format_reward": 0.25000000838190317,
527
+ "step": 37
528
+ },
529
+ {
530
+ "clip_ratio": 0.0,
531
+ "completion_length": 2999.0694580078125,
532
+ "epoch": 0.06512425021422451,
533
+ "grad_norm": 0.25001204013824463,
534
+ "kl": 0.00015616416931152344,
535
+ "learning_rate": 7.599999999999999e-07,
536
+ "loss": 0.114,
537
+ "reward": 0.10032026097178459,
538
+ "reward_std": 0.7015992030501366,
539
+ "rewards/cosine_scaled_reward": -0.10261764749884605,
540
+ "rewards/format_reward": 0.3055555634200573,
541
+ "step": 38
542
+ },
543
+ {
544
+ "clip_ratio": 0.0,
545
+ "completion_length": 3170.4027709960938,
546
+ "epoch": 0.06683804627249357,
547
+ "grad_norm": 0.13187235593795776,
548
+ "kl": 0.00024265050888061523,
549
+ "learning_rate": 7.799999999999999e-07,
550
+ "loss": 0.023,
551
+ "reward": 0.032449623104184866,
552
+ "reward_std": 0.7292564660310745,
553
+ "rewards/cosine_scaled_reward": -0.12960851565003395,
554
+ "rewards/format_reward": 0.2916666679084301,
555
+ "step": 39
556
+ },
557
+ {
558
+ "clip_ratio": 0.0,
559
+ "completion_length": 2721.5694580078125,
560
+ "epoch": 0.06855184233076264,
561
+ "grad_norm": 0.24242877960205078,
562
+ "kl": 0.00039273500442504883,
563
+ "learning_rate": 8e-07,
564
+ "loss": 0.1056,
565
+ "reward": 0.2101573906838894,
566
+ "reward_std": 0.5202245805412531,
567
+ "rewards/cosine_scaled_reward": -0.07547687107580714,
568
+ "rewards/format_reward": 0.3611111156642437,
569
+ "step": 40
570
+ },
571
+ {
572
+ "clip_ratio": 0.0,
573
+ "completion_length": 2850.65283203125,
574
+ "epoch": 0.0702656383890317,
575
+ "grad_norm": 0.1599811613559723,
576
+ "kl": 0.00010573863983154297,
577
+ "learning_rate": 8.199999999999999e-07,
578
+ "loss": 0.0787,
579
+ "reward": 0.3573916293680668,
580
+ "reward_std": 0.7150286287069321,
581
+ "rewards/cosine_scaled_reward": -0.022693071980029345,
582
+ "rewards/format_reward": 0.4027777835726738,
583
+ "step": 41
584
+ },
585
+ {
586
+ "clip_ratio": 0.0,
587
+ "completion_length": 2629.402801513672,
588
+ "epoch": 0.07197943444730077,
589
+ "grad_norm": 0.2574199140071869,
590
+ "kl": 0.0005946159362792969,
591
+ "learning_rate": 8.399999999999999e-07,
592
+ "loss": 0.0996,
593
+ "reward": 0.3184794522821903,
594
+ "reward_std": 0.7374207675457001,
595
+ "rewards/cosine_scaled_reward": -0.0699269392844144,
596
+ "rewards/format_reward": 0.45833333022892475,
597
+ "step": 42
598
+ },
599
+ {
600
+ "clip_ratio": 0.0,
601
+ "completion_length": 2797.75,
602
+ "epoch": 0.07369323050556983,
603
+ "grad_norm": 0.1763925850391388,
604
+ "kl": 0.00013440847396850586,
605
+ "learning_rate": 8.599999999999999e-07,
606
+ "loss": 0.081,
607
+ "reward": 0.460858479142189,
608
+ "reward_std": 0.6768517717719078,
609
+ "rewards/cosine_scaled_reward": 0.015151458326727152,
610
+ "rewards/format_reward": 0.4305555671453476,
611
+ "step": 43
612
+ },
613
+ {
614
+ "clip_ratio": 0.0,
615
+ "completion_length": 2764.15283203125,
616
+ "epoch": 0.07540702656383891,
617
+ "grad_norm": 0.14260780811309814,
618
+ "kl": 0.0010910332202911377,
619
+ "learning_rate": 8.799999999999999e-07,
620
+ "loss": -0.0101,
621
+ "reward": 0.24442699179053307,
622
+ "reward_std": 0.7257742322981358,
623
+ "rewards/cosine_scaled_reward": -0.14861984690651298,
624
+ "rewards/format_reward": 0.5416666716337204,
625
+ "step": 44
626
+ },
627
+ {
628
+ "clip_ratio": 0.0,
629
+ "completion_length": 2988.3055419921875,
630
+ "epoch": 0.07712082262210797,
631
+ "grad_norm": 0.14807860553264618,
632
+ "kl": 0.0002259761095046997,
633
+ "learning_rate": 9e-07,
634
+ "loss": 0.0058,
635
+ "reward": 0.1327950283885002,
636
+ "reward_std": 0.6829644069075584,
637
+ "rewards/cosine_scaled_reward": -0.07943581556901336,
638
+ "rewards/format_reward": 0.2916666679084301,
639
+ "step": 45
640
+ },
641
+ {
642
+ "clip_ratio": 0.0,
643
+ "completion_length": 2406.750030517578,
644
+ "epoch": 0.07883461868037704,
645
+ "grad_norm": 0.3411652743816376,
646
+ "kl": 0.0010082721710205078,
647
+ "learning_rate": 9.2e-07,
648
+ "loss": 0.0325,
649
+ "reward": 0.37563128490000963,
650
+ "reward_std": 0.5480553992092609,
651
+ "rewards/cosine_scaled_reward": -0.07607323676347733,
652
+ "rewards/format_reward": 0.5277777835726738,
653
+ "step": 46
654
+ },
655
+ {
656
+ "clip_ratio": 0.0,
657
+ "completion_length": 2894.4306030273438,
658
+ "epoch": 0.0805484147386461,
659
+ "grad_norm": 0.1801064908504486,
660
+ "kl": 0.0010660886764526367,
661
+ "learning_rate": 9.399999999999999e-07,
662
+ "loss": 0.0585,
663
+ "reward": 0.2889724150300026,
664
+ "reward_std": 0.7576765939593315,
665
+ "rewards/cosine_scaled_reward": -0.08468045573681593,
666
+ "rewards/format_reward": 0.4583333358168602,
667
+ "step": 47
668
+ },
669
+ {
670
+ "clip_ratio": 0.0,
671
+ "completion_length": 2787.6111450195312,
672
+ "epoch": 0.08226221079691516,
673
+ "grad_norm": 0.2200099229812622,
674
+ "kl": 0.0008892565965652466,
675
+ "learning_rate": 9.6e-07,
676
+ "loss": 0.1153,
677
+ "reward": 0.6353000029921532,
678
+ "reward_std": 0.7432012036442757,
679
+ "rewards/cosine_scaled_reward": 0.07459445751737803,
680
+ "rewards/format_reward": 0.4861111268401146,
681
+ "step": 48
682
+ },
683
+ {
684
+ "clip_ratio": 0.0,
685
+ "completion_length": 2355.763946533203,
686
+ "epoch": 0.08397600685518423,
687
+ "grad_norm": 0.22268813848495483,
688
+ "kl": 0.002144336700439453,
689
+ "learning_rate": 9.8e-07,
690
+ "loss": 0.0718,
691
+ "reward": 0.5641769841313362,
692
+ "reward_std": 0.697506844997406,
693
+ "rewards/cosine_scaled_reward": -0.016522612422704697,
694
+ "rewards/format_reward": 0.5972222313284874,
695
+ "step": 49
696
+ },
697
+ {
698
+ "clip_ratio": 0.0,
699
+ "completion_length": 2625.7083129882812,
700
+ "epoch": 0.0856898029134533,
701
+ "grad_norm": 0.18417640030384064,
702
+ "kl": 0.0020694732666015625,
703
+ "learning_rate": 1e-06,
704
+ "loss": 0.0792,
705
+ "reward": 0.09065666515380144,
706
+ "reward_std": 0.6994658857584,
707
+ "rewards/cosine_scaled_reward": -0.16300500556826591,
708
+ "rewards/format_reward": 0.4166666753590107,
709
+ "step": 50
710
+ }
711
+ ],
712
+ "logging_steps": 1,
713
+ "max_steps": 500,
714
+ "num_input_tokens_seen": 0,
715
+ "num_train_epochs": 1,
716
+ "save_steps": 25,
717
+ "stateful_callbacks": {
718
+ "TrainerControl": {
719
+ "args": {
720
+ "should_epoch_stop": false,
721
+ "should_evaluate": false,
722
+ "should_log": false,
723
+ "should_save": true,
724
+ "should_training_stop": false
725
+ },
726
+ "attributes": {}
727
+ }
728
+ },
729
+ "total_flos": 0.0,
730
+ "train_batch_size": 6,
731
+ "trial_name": null,
732
+ "trial_params": null
733
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef5e1578db57a0a30c2f11ec7d5ad1212c33cd4e69b490df6a3b1fe0a5dbd90f
3
+ size 8248
zero_to_fp32.py ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example:
14
+ # python zero_to_fp32.py . output_dir/
15
+ # or
16
+ # python zero_to_fp32.py . output_dir/ --safe_serialization
17
+
18
+ import argparse
19
+ import torch
20
+ import glob
21
+ import math
22
+ import os
23
+ import re
24
+ import json
25
+ from tqdm import tqdm
26
+ from collections import OrderedDict
27
+ from dataclasses import dataclass
28
+
29
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
30
+ # DeepSpeed data structures it has to be available in the current python environment.
31
+ from deepspeed.utils import logger
32
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
33
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
34
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
35
+
36
+
37
+ @dataclass
38
+ class zero_model_state:
39
+ buffers: dict()
40
+ param_shapes: dict()
41
+ shared_params: list
42
+ ds_version: int
43
+ frozen_param_shapes: dict()
44
+ frozen_param_fragments: dict()
45
+
46
+
47
+ debug = 0
48
+
49
+ # load to cpu
50
+ device = torch.device('cpu')
51
+
52
+
53
+ def atoi(text):
54
+ return int(text) if text.isdigit() else text
55
+
56
+
57
+ def natural_keys(text):
58
+ '''
59
+ alist.sort(key=natural_keys) sorts in human order
60
+ http://nedbatchelder.com/blog/200712/human_sorting.html
61
+ (See Toothy's implementation in the comments)
62
+ '''
63
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
64
+
65
+
66
+ def get_model_state_file(checkpoint_dir, zero_stage):
67
+ if not os.path.isdir(checkpoint_dir):
68
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
69
+
70
+ # there should be only one file
71
+ if zero_stage <= 2:
72
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
73
+ elif zero_stage == 3:
74
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
75
+
76
+ if not os.path.exists(file):
77
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
78
+
79
+ return file
80
+
81
+
82
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
83
+ # XXX: need to test that this simple glob rule works for multi-node setup too
84
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
85
+
86
+ if len(ckpt_files) == 0:
87
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
88
+
89
+ return ckpt_files
90
+
91
+
92
+ def get_optim_files(checkpoint_dir):
93
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
94
+
95
+
96
+ def get_model_state_files(checkpoint_dir):
97
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
98
+
99
+
100
+ def parse_model_states(files):
101
+ zero_model_states = []
102
+ for file in files:
103
+ state_dict = torch.load(file, map_location=device)
104
+
105
+ if BUFFER_NAMES not in state_dict:
106
+ raise ValueError(f"{file} is not a model state checkpoint")
107
+ buffer_names = state_dict[BUFFER_NAMES]
108
+ if debug:
109
+ print("Found buffers:", buffer_names)
110
+
111
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
112
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
113
+ param_shapes = state_dict[PARAM_SHAPES]
114
+
115
+ # collect parameters that are included in param_shapes
116
+ param_names = []
117
+ for s in param_shapes:
118
+ for name in s.keys():
119
+ param_names.append(name)
120
+
121
+ # update with frozen parameters
122
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
123
+ if frozen_param_shapes is not None:
124
+ if debug:
125
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
126
+ param_names += list(frozen_param_shapes.keys())
127
+
128
+ # handle shared params
129
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
130
+
131
+ ds_version = state_dict.get(DS_VERSION, None)
132
+
133
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
134
+
135
+ z_model_state = zero_model_state(buffers=buffers,
136
+ param_shapes=param_shapes,
137
+ shared_params=shared_params,
138
+ ds_version=ds_version,
139
+ frozen_param_shapes=frozen_param_shapes,
140
+ frozen_param_fragments=frozen_param_fragments)
141
+ zero_model_states.append(z_model_state)
142
+
143
+ return zero_model_states
144
+
145
+
146
+ def parse_optim_states(files, ds_checkpoint_dir):
147
+ total_files = len(files)
148
+ state_dicts = []
149
+ for f in files:
150
+ state_dict = torch.load(f, map_location=device)
151
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
152
+ # and also handle the case where it was already removed by another helper script
153
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
154
+ state_dicts.append(state_dict)
155
+
156
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
157
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
158
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
159
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
160
+
161
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
162
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
163
+ # use the max of the partition_count to get the dp world_size.
164
+
165
+ if type(world_size) is list:
166
+ world_size = max(world_size)
167
+
168
+ if world_size != total_files:
169
+ raise ValueError(
170
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
171
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
172
+ )
173
+
174
+ # the groups are named differently in each stage
175
+ if zero_stage <= 2:
176
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
177
+ elif zero_stage == 3:
178
+ fp32_groups_key = FP32_FLAT_GROUPS
179
+ else:
180
+ raise ValueError(f"unknown zero stage {zero_stage}")
181
+
182
+ if zero_stage <= 2:
183
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
184
+ elif zero_stage == 3:
185
+ # if there is more than one param group, there will be multiple flattened tensors - one
186
+ # flattened tensor per group - for simplicity merge them into a single tensor
187
+ #
188
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
189
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
190
+
191
+ fp32_flat_groups = [
192
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
193
+ ]
194
+
195
+ return zero_stage, world_size, fp32_flat_groups
196
+
197
+
198
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
199
+ """
200
+ Returns fp32 state_dict reconstructed from ds checkpoint
201
+
202
+ Args:
203
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
204
+
205
+ """
206
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
207
+
208
+ optim_files = get_optim_files(ds_checkpoint_dir)
209
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
210
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
211
+
212
+ model_files = get_model_state_files(ds_checkpoint_dir)
213
+
214
+ zero_model_states = parse_model_states(model_files)
215
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
216
+
217
+ if zero_stage <= 2:
218
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
219
+ exclude_frozen_parameters)
220
+ elif zero_stage == 3:
221
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
222
+ exclude_frozen_parameters)
223
+
224
+
225
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
226
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
227
+ return
228
+
229
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
230
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
231
+
232
+ if debug:
233
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
234
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
235
+
236
+ wanted_params = len(frozen_param_shapes)
237
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
238
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
239
+ print(f'Frozen params: Have {avail_numel} numels to process.')
240
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
241
+
242
+ total_params = 0
243
+ total_numel = 0
244
+ for name, shape in frozen_param_shapes.items():
245
+ total_params += 1
246
+ unpartitioned_numel = shape.numel()
247
+ total_numel += unpartitioned_numel
248
+
249
+ state_dict[name] = frozen_param_fragments[name]
250
+
251
+ if debug:
252
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
253
+
254
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
255
+
256
+
257
+ def _has_callable(obj, fn):
258
+ attr = getattr(obj, fn, None)
259
+ return callable(attr)
260
+
261
+
262
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
263
+ param_shapes = zero_model_states[0].param_shapes
264
+
265
+ # Reconstruction protocol:
266
+ #
267
+ # XXX: document this
268
+
269
+ if debug:
270
+ for i in range(world_size):
271
+ for j in range(len(fp32_flat_groups[0])):
272
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
273
+
274
+ # XXX: memory usage doubles here (zero2)
275
+ num_param_groups = len(fp32_flat_groups[0])
276
+ merged_single_partition_of_fp32_groups = []
277
+ for i in range(num_param_groups):
278
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
279
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
280
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
281
+ avail_numel = sum(
282
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
283
+
284
+ if debug:
285
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
286
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
287
+ # not asserting if there is a mismatch due to possible padding
288
+ print(f"Have {avail_numel} numels to process.")
289
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
290
+
291
+ # params
292
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
293
+ # out-of-core computing solution
294
+ total_numel = 0
295
+ total_params = 0
296
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
297
+ offset = 0
298
+ avail_numel = full_single_fp32_vector.numel()
299
+ for name, shape in shapes.items():
300
+
301
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
302
+ total_numel += unpartitioned_numel
303
+ total_params += 1
304
+
305
+ if debug:
306
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
307
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
308
+ offset += unpartitioned_numel
309
+
310
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
311
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
312
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
313
+ # live optimizer object, so we are checking that the numbers are within the right range
314
+ align_to = 2 * world_size
315
+
316
+ def zero2_align(x):
317
+ return align_to * math.ceil(x / align_to)
318
+
319
+ if debug:
320
+ print(f"original offset={offset}, avail_numel={avail_numel}")
321
+
322
+ offset = zero2_align(offset)
323
+ avail_numel = zero2_align(avail_numel)
324
+
325
+ if debug:
326
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
327
+
328
+ # Sanity check
329
+ if offset != avail_numel:
330
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
331
+
332
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
333
+
334
+
335
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
336
+ exclude_frozen_parameters):
337
+ state_dict = OrderedDict()
338
+
339
+ # buffers
340
+ buffers = zero_model_states[0].buffers
341
+ state_dict.update(buffers)
342
+ if debug:
343
+ print(f"added {len(buffers)} buffers")
344
+
345
+ if not exclude_frozen_parameters:
346
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
347
+
348
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
349
+
350
+ # recover shared parameters
351
+ for pair in zero_model_states[0].shared_params:
352
+ if pair[1] in state_dict:
353
+ state_dict[pair[0]] = state_dict[pair[1]]
354
+
355
+ return state_dict
356
+
357
+
358
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
359
+ remainder = unpartitioned_numel % world_size
360
+ padding_numel = (world_size - remainder) if remainder else 0
361
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
362
+ return partitioned_numel, padding_numel
363
+
364
+
365
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
366
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
367
+ return
368
+
369
+ if debug:
370
+ for i in range(world_size):
371
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
372
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
373
+
374
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
375
+ wanted_params = len(frozen_param_shapes)
376
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
377
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
378
+ print(f'Frozen params: Have {avail_numel} numels to process.')
379
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
380
+
381
+ total_params = 0
382
+ total_numel = 0
383
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
384
+ total_params += 1
385
+ unpartitioned_numel = shape.numel()
386
+ total_numel += unpartitioned_numel
387
+
388
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
389
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
390
+
391
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
392
+
393
+ if debug:
394
+ print(
395
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
396
+ )
397
+
398
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
399
+
400
+
401
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
402
+ param_shapes = zero_model_states[0].param_shapes
403
+ avail_numel = fp32_flat_groups[0].numel() * world_size
404
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
405
+ # param, re-consolidating each param, while dealing with padding if any
406
+
407
+ # merge list of dicts, preserving order
408
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
409
+
410
+ if debug:
411
+ for i in range(world_size):
412
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
413
+
414
+ wanted_params = len(param_shapes)
415
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
416
+ # not asserting if there is a mismatch due to possible padding
417
+ avail_numel = fp32_flat_groups[0].numel() * world_size
418
+ print(f"Trainable params: Have {avail_numel} numels to process.")
419
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
420
+
421
+ # params
422
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
423
+ # out-of-core computing solution
424
+ offset = 0
425
+ total_numel = 0
426
+ total_params = 0
427
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering Sharded Weights'):
428
+ unpartitioned_numel = shape.numel()
429
+ total_numel += unpartitioned_numel
430
+ total_params += 1
431
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
432
+
433
+ if debug:
434
+ print(
435
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
436
+ )
437
+
438
+ # XXX: memory usage doubles here
439
+ state_dict[name] = torch.cat(
440
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
441
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
442
+ offset += partitioned_numel
443
+
444
+ offset *= world_size
445
+
446
+ # Sanity check
447
+ if offset != avail_numel:
448
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
449
+
450
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
451
+
452
+
453
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
454
+ exclude_frozen_parameters):
455
+ state_dict = OrderedDict()
456
+
457
+ # buffers
458
+ buffers = zero_model_states[0].buffers
459
+ state_dict.update(buffers)
460
+ if debug:
461
+ print(f"added {len(buffers)} buffers")
462
+
463
+ if not exclude_frozen_parameters:
464
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
465
+
466
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
467
+
468
+ # recover shared parameters
469
+ for pair in zero_model_states[0].shared_params:
470
+ if pair[1] in state_dict:
471
+ state_dict[pair[0]] = state_dict[pair[1]]
472
+
473
+ return state_dict
474
+
475
+
476
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
477
+ """
478
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
479
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
480
+ via a model hub.
481
+
482
+ Args:
483
+ - ``checkpoint_dir``: path to the desired checkpoint folder
484
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
485
+ - ``exclude_frozen_parameters``: exclude frozen parameters
486
+
487
+ Returns:
488
+ - pytorch ``state_dict``
489
+
490
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
491
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
492
+ the checkpoint.
493
+
494
+ A typical usage might be ::
495
+
496
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
497
+ # do the training and checkpoint saving
498
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
499
+ model = model.cpu() # move to cpu
500
+ model.load_state_dict(state_dict)
501
+ # submit to model hub or save the model to share with others
502
+
503
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
504
+ application. i.e. you will need to re-initialize the deepspeed engine, since
505
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
506
+
507
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
508
+
509
+ """
510
+ if tag is None:
511
+ latest_path = os.path.join(checkpoint_dir, 'latest')
512
+ if os.path.isfile(latest_path):
513
+ with open(latest_path, 'r') as fd:
514
+ tag = fd.read().strip()
515
+ else:
516
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
517
+
518
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
519
+
520
+ if not os.path.isdir(ds_checkpoint_dir):
521
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
522
+
523
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
524
+
525
+
526
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
527
+ output_dir,
528
+ max_shard_size="5GB",
529
+ safe_serialization=False,
530
+ tag=None,
531
+ exclude_frozen_parameters=False):
532
+ """
533
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
534
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
535
+
536
+ Args:
537
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
538
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
539
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
540
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
541
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
542
+ - ``exclude_frozen_parameters``: exclude frozen parameters
543
+ """
544
+ # Dependency pre-check
545
+ if safe_serialization:
546
+ try:
547
+ from safetensors.torch import save_file
548
+ except ImportError:
549
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
550
+ raise
551
+ if max_shard_size is not None:
552
+ try:
553
+ from huggingface_hub import split_torch_state_dict_into_shards
554
+ except ImportError:
555
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
556
+ raise
557
+
558
+ # Convert zero checkpoint to state_dict
559
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
560
+
561
+ # Shard the model if it is too big.
562
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
563
+ if max_shard_size is not None:
564
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
565
+ state_dict_split = split_torch_state_dict_into_shards(state_dict,
566
+ filename_pattern=filename_pattern,
567
+ max_shard_size=max_shard_size)
568
+ else:
569
+ from collections import namedtuple
570
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
571
+ state_dict_split = StateDictSplit(is_sharded=False,
572
+ filename_to_tensors={weights_name: list(state_dict.keys())})
573
+
574
+ # Save the model
575
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
576
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
577
+ shard = {tensor: state_dict[tensor].contiguous() for tensor in tensors}
578
+ output_path = os.path.join(output_dir, shard_file)
579
+ if safe_serialization:
580
+ save_file(shard, output_path, metadata={"format": "pt"})
581
+ else:
582
+ torch.save(shard, output_path)
583
+
584
+ # Save index if sharded
585
+ if state_dict_split.is_sharded:
586
+ index = {
587
+ "metadata": state_dict_split.metadata,
588
+ "weight_map": state_dict_split.tensor_to_filename,
589
+ }
590
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
591
+ save_index_file = os.path.join(output_dir, save_index_file)
592
+ with open(save_index_file, "w", encoding="utf-8") as f:
593
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
594
+ f.write(content)
595
+
596
+
597
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
598
+ """
599
+ 1. Put the provided model to cpu
600
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
601
+ 3. Load it into the provided model
602
+
603
+ Args:
604
+ - ``model``: the model object to update
605
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
606
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
607
+
608
+ Returns:
609
+ - ``model`: modified model
610
+
611
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
612
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
613
+ conveniently placed for you in the checkpoint folder.
614
+
615
+ A typical usage might be ::
616
+
617
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
618
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
619
+ # submit to model hub or save the model to share with others
620
+
621
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
622
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
623
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
624
+
625
+ """
626
+ logger.info(f"Extracting fp32 weights")
627
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
628
+
629
+ logger.info(f"Overwriting model with fp32 weights")
630
+ model = model.cpu()
631
+ model.load_state_dict(state_dict, strict=False)
632
+
633
+ return model
634
+
635
+
636
+ if __name__ == "__main__":
637
+ parser = argparse.ArgumentParser()
638
+ parser.add_argument("checkpoint_dir",
639
+ type=str,
640
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
641
+ parser.add_argument("output_dir",
642
+ type=str,
643
+ help="directory to the pytorch fp32 state_dict output files"
644
+ "(e.g. path/checkpoint-12-output/)")
645
+ parser.add_argument(
646
+ "--max_shard_size",
647
+ type=str,
648
+ default="5GB",
649
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
650
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
651
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
652
+ "without CPU OOM issues.")
653
+ parser.add_argument(
654
+ "--safe_serialization",
655
+ default=False,
656
+ action='store_true',
657
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
658
+ parser.add_argument("-t",
659
+ "--tag",
660
+ type=str,
661
+ default=None,
662
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
663
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
664
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
665
+ args = parser.parse_args()
666
+
667
+ debug = args.debug
668
+
669
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
670
+ args.output_dir,
671
+ max_shard_size=args.max_shard_size,
672
+ safe_serialization=args.safe_serialization,
673
+ tag=args.tag,
674
+ exclude_frozen_parameters=args.exclude_frozen_parameters)