Yaning1001 commited on
Commit
86ee53d
·
verified ·
1 Parent(s): 64f2284

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1000/added_tokens.json +4 -0
  2. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1000/latest +1 -0
  3. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1000/zero_to_fp32.py +604 -0
  4. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/added_tokens.json +4 -0
  5. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/config.json +39 -0
  6. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/generation_config.json +6 -0
  7. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/latest +1 -0
  8. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/merges.txt +0 -0
  9. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/special_tokens_map.json +12 -0
  10. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/tokenizer.json +0 -0
  11. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/tokenizer_config.json +36 -0
  12. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/trainer_state.json +0 -0
  13. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/vocab.json +0 -0
  14. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/zero_to_fp32.py +604 -0
  15. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/config.json +39 -0
  16. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/generation_config.json +6 -0
  17. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/special_tokens_map.json +12 -0
  18. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/tokenizer_config.json +36 -0
  19. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/trainer_state.json +0 -0
  20. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/vocab.json +0 -0
  21. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/added_tokens.json +4 -0
  22. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/config.json +39 -0
  23. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/generation_config.json +6 -0
  24. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/latest +1 -0
  25. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/merges.txt +0 -0
  26. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/special_tokens_map.json +12 -0
  27. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/tokenizer.json +0 -0
  28. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/tokenizer_config.json +36 -0
  29. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/trainer_state.json +1593 -0
  30. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/vocab.json +0 -0
  31. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/zero_to_fp32.py +604 -0
  32. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/added_tokens.json +4 -0
  33. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/config.json +39 -0
  34. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/generation_config.json +6 -0
  35. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/latest +1 -0
  36. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/merges.txt +0 -0
  37. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/special_tokens_map.json +12 -0
  38. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/tokenizer.json +0 -0
  39. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/tokenizer_config.json +36 -0
  40. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/trainer_state.json +0 -0
  41. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/vocab.json +0 -0
  42. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/zero_to_fp32.py +604 -0
  43. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/added_tokens.json +4 -0
  44. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/config.json +39 -0
  45. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/generation_config.json +6 -0
  46. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/latest +1 -0
  47. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/merges.txt +0 -0
  48. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/special_tokens_map.json +12 -0
  49. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/tokenizer.json +0 -0
  50. checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/tokenizer_config.json +36 -0
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1000/added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[PAD]": 50257,
3
+ "🅁": 50258
4
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1000/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step1000
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1000/zero_to_fp32.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
215
+ exclude_frozen_parameters)
216
+ elif zero_stage == 3:
217
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
218
+ exclude_frozen_parameters)
219
+
220
+
221
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
222
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
223
+ return
224
+
225
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
226
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
227
+
228
+ if debug:
229
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
230
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
231
+
232
+ wanted_params = len(frozen_param_shapes)
233
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
234
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
235
+ print(f'Frozen params: Have {avail_numel} numels to process.')
236
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
237
+
238
+ total_params = 0
239
+ total_numel = 0
240
+ for name, shape in frozen_param_shapes.items():
241
+ total_params += 1
242
+ unpartitioned_numel = shape.numel()
243
+ total_numel += unpartitioned_numel
244
+
245
+ state_dict[name] = frozen_param_fragments[name]
246
+
247
+ if debug:
248
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
249
+
250
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
251
+
252
+
253
+ def _has_callable(obj, fn):
254
+ attr = getattr(obj, fn, None)
255
+ return callable(attr)
256
+
257
+
258
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
259
+ param_shapes = zero_model_states[0].param_shapes
260
+
261
+ # Reconstruction protocol:
262
+ #
263
+ # XXX: document this
264
+
265
+ if debug:
266
+ for i in range(world_size):
267
+ for j in range(len(fp32_flat_groups[0])):
268
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
269
+
270
+ # XXX: memory usage doubles here (zero2)
271
+ num_param_groups = len(fp32_flat_groups[0])
272
+ merged_single_partition_of_fp32_groups = []
273
+ for i in range(num_param_groups):
274
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
275
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
276
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
277
+ avail_numel = sum(
278
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
279
+
280
+ if debug:
281
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
282
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
283
+ # not asserting if there is a mismatch due to possible padding
284
+ print(f"Have {avail_numel} numels to process.")
285
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
286
+
287
+ # params
288
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
289
+ # out-of-core computing solution
290
+ total_numel = 0
291
+ total_params = 0
292
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
293
+ offset = 0
294
+ avail_numel = full_single_fp32_vector.numel()
295
+ for name, shape in shapes.items():
296
+
297
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
298
+ total_numel += unpartitioned_numel
299
+ total_params += 1
300
+
301
+ if debug:
302
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
303
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
304
+ offset += unpartitioned_numel
305
+
306
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
307
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
308
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
309
+ # live optimizer object, so we are checking that the numbers are within the right range
310
+ align_to = 2 * world_size
311
+
312
+ def zero2_align(x):
313
+ return align_to * math.ceil(x / align_to)
314
+
315
+ if debug:
316
+ print(f"original offset={offset}, avail_numel={avail_numel}")
317
+
318
+ offset = zero2_align(offset)
319
+ avail_numel = zero2_align(avail_numel)
320
+
321
+ if debug:
322
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
323
+
324
+ # Sanity check
325
+ if offset != avail_numel:
326
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
327
+
328
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
329
+
330
+
331
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
332
+ exclude_frozen_parameters):
333
+ state_dict = OrderedDict()
334
+
335
+ # buffers
336
+ buffers = zero_model_states[0].buffers
337
+ state_dict.update(buffers)
338
+ if debug:
339
+ print(f"added {len(buffers)} buffers")
340
+
341
+ if not exclude_frozen_parameters:
342
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
343
+
344
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
345
+
346
+ # recover shared parameters
347
+ for pair in zero_model_states[0].shared_params:
348
+ if pair[1] in state_dict:
349
+ state_dict[pair[0]] = state_dict[pair[1]]
350
+
351
+ return state_dict
352
+
353
+
354
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
355
+ remainder = unpartitioned_numel % world_size
356
+ padding_numel = (world_size - remainder) if remainder else 0
357
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
358
+ return partitioned_numel, padding_numel
359
+
360
+
361
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
362
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
363
+ return
364
+
365
+ if debug:
366
+ for i in range(world_size):
367
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
368
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
369
+
370
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
371
+ wanted_params = len(frozen_param_shapes)
372
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
373
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
374
+ print(f'Frozen params: Have {avail_numel} numels to process.')
375
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
376
+
377
+ total_params = 0
378
+ total_numel = 0
379
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
380
+ total_params += 1
381
+ unpartitioned_numel = shape.numel()
382
+ total_numel += unpartitioned_numel
383
+
384
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
385
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
386
+
387
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
388
+
389
+ if debug:
390
+ print(
391
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
392
+ )
393
+
394
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
395
+
396
+
397
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
398
+ param_shapes = zero_model_states[0].param_shapes
399
+ avail_numel = fp32_flat_groups[0].numel() * world_size
400
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
401
+ # param, re-consolidating each param, while dealing with padding if any
402
+
403
+ # merge list of dicts, preserving order
404
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
405
+
406
+ if debug:
407
+ for i in range(world_size):
408
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
409
+
410
+ wanted_params = len(param_shapes)
411
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
412
+ # not asserting if there is a mismatch due to possible padding
413
+ avail_numel = fp32_flat_groups[0].numel() * world_size
414
+ print(f"Trainable params: Have {avail_numel} numels to process.")
415
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
416
+
417
+ # params
418
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
419
+ # out-of-core computing solution
420
+ offset = 0
421
+ total_numel = 0
422
+ total_params = 0
423
+ for name, shape in param_shapes.items():
424
+
425
+ unpartitioned_numel = shape.numel()
426
+ total_numel += unpartitioned_numel
427
+ total_params += 1
428
+
429
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
430
+
431
+ if debug:
432
+ print(
433
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
434
+ )
435
+
436
+ # XXX: memory usage doubles here
437
+ state_dict[name] = torch.cat(
438
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
439
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
440
+ offset += partitioned_numel
441
+
442
+ offset *= world_size
443
+
444
+ # Sanity check
445
+ if offset != avail_numel:
446
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
447
+
448
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
449
+
450
+
451
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
452
+ exclude_frozen_parameters):
453
+ state_dict = OrderedDict()
454
+
455
+ # buffers
456
+ buffers = zero_model_states[0].buffers
457
+ state_dict.update(buffers)
458
+ if debug:
459
+ print(f"added {len(buffers)} buffers")
460
+
461
+ if not exclude_frozen_parameters:
462
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
463
+
464
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
465
+
466
+ # recover shared parameters
467
+ for pair in zero_model_states[0].shared_params:
468
+ if pair[1] in state_dict:
469
+ state_dict[pair[0]] = state_dict[pair[1]]
470
+
471
+ return state_dict
472
+
473
+
474
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
475
+ """
476
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
477
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
478
+ via a model hub.
479
+
480
+ Args:
481
+ - ``checkpoint_dir``: path to the desired checkpoint folder
482
+ - ``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``
483
+ - ``exclude_frozen_parameters``: exclude frozen parameters
484
+
485
+ Returns:
486
+ - pytorch ``state_dict``
487
+
488
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
489
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
490
+ the checkpoint.
491
+
492
+ A typical usage might be ::
493
+
494
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
495
+ # do the training and checkpoint saving
496
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
497
+ model = model.cpu() # move to cpu
498
+ model.load_state_dict(state_dict)
499
+ # submit to model hub or save the model to share with others
500
+
501
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
502
+ application. i.e. you will need to re-initialize the deepspeed engine, since
503
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
504
+
505
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
506
+
507
+ """
508
+ if tag is None:
509
+ latest_path = os.path.join(checkpoint_dir, 'latest')
510
+ if os.path.isfile(latest_path):
511
+ with open(latest_path, 'r') as fd:
512
+ tag = fd.read().strip()
513
+ else:
514
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
515
+
516
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
517
+
518
+ if not os.path.isdir(ds_checkpoint_dir):
519
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
520
+
521
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
522
+
523
+
524
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None, exclude_frozen_parameters=False):
525
+ """
526
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
527
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
528
+
529
+ Args:
530
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
531
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
532
+ - ``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``
533
+ - ``exclude_frozen_parameters``: exclude frozen parameters
534
+ """
535
+
536
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
537
+ print(f"Saving fp32 state dict to {output_file}")
538
+ torch.save(state_dict, output_file)
539
+
540
+
541
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
542
+ """
543
+ 1. Put the provided model to cpu
544
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
545
+ 3. Load it into the provided model
546
+
547
+ Args:
548
+ - ``model``: the model object to update
549
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
550
+ - ``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``
551
+
552
+ Returns:
553
+ - ``model`: modified model
554
+
555
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
556
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
557
+ conveniently placed for you in the checkpoint folder.
558
+
559
+ A typical usage might be ::
560
+
561
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
562
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
563
+ # submit to model hub or save the model to share with others
564
+
565
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
566
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
567
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
568
+
569
+ """
570
+ logger.info(f"Extracting fp32 weights")
571
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
572
+
573
+ logger.info(f"Overwriting model with fp32 weights")
574
+ model = model.cpu()
575
+ model.load_state_dict(state_dict, strict=False)
576
+
577
+ return model
578
+
579
+
580
+ if __name__ == "__main__":
581
+
582
+ parser = argparse.ArgumentParser()
583
+ parser.add_argument("checkpoint_dir",
584
+ type=str,
585
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
586
+ parser.add_argument(
587
+ "output_file",
588
+ type=str,
589
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
590
+ parser.add_argument("-t",
591
+ "--tag",
592
+ type=str,
593
+ default=None,
594
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
595
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
596
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
597
+ args = parser.parse_args()
598
+
599
+ debug = args.debug
600
+
601
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
602
+ args.output_file,
603
+ tag=args.tag,
604
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[PAD]": 50257,
3
+ "🅁": 50258
4
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.45.1",
37
+ "use_cache": true,
38
+ "vocab_size": 50257
39
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.45.1"
6
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step1800
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": {
5
+ "content": "[PAD]",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "unk_token": "<|endoftext|>"
12
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/tokenizer_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": "[PAD]",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "50258": {
21
+ "content": "🅁",
22
+ "lstrip": true,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ }
28
+ },
29
+ "bos_token": "<|endoftext|>",
30
+ "clean_up_tokenization_spaces": false,
31
+ "eos_token": "<|endoftext|>",
32
+ "model_max_length": 1024,
33
+ "pad_token": "[PAD]",
34
+ "tokenizer_class": "GPT2Tokenizer",
35
+ "unk_token": "<|endoftext|>"
36
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1800/zero_to_fp32.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
215
+ exclude_frozen_parameters)
216
+ elif zero_stage == 3:
217
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
218
+ exclude_frozen_parameters)
219
+
220
+
221
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
222
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
223
+ return
224
+
225
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
226
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
227
+
228
+ if debug:
229
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
230
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
231
+
232
+ wanted_params = len(frozen_param_shapes)
233
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
234
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
235
+ print(f'Frozen params: Have {avail_numel} numels to process.')
236
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
237
+
238
+ total_params = 0
239
+ total_numel = 0
240
+ for name, shape in frozen_param_shapes.items():
241
+ total_params += 1
242
+ unpartitioned_numel = shape.numel()
243
+ total_numel += unpartitioned_numel
244
+
245
+ state_dict[name] = frozen_param_fragments[name]
246
+
247
+ if debug:
248
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
249
+
250
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
251
+
252
+
253
+ def _has_callable(obj, fn):
254
+ attr = getattr(obj, fn, None)
255
+ return callable(attr)
256
+
257
+
258
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
259
+ param_shapes = zero_model_states[0].param_shapes
260
+
261
+ # Reconstruction protocol:
262
+ #
263
+ # XXX: document this
264
+
265
+ if debug:
266
+ for i in range(world_size):
267
+ for j in range(len(fp32_flat_groups[0])):
268
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
269
+
270
+ # XXX: memory usage doubles here (zero2)
271
+ num_param_groups = len(fp32_flat_groups[0])
272
+ merged_single_partition_of_fp32_groups = []
273
+ for i in range(num_param_groups):
274
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
275
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
276
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
277
+ avail_numel = sum(
278
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
279
+
280
+ if debug:
281
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
282
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
283
+ # not asserting if there is a mismatch due to possible padding
284
+ print(f"Have {avail_numel} numels to process.")
285
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
286
+
287
+ # params
288
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
289
+ # out-of-core computing solution
290
+ total_numel = 0
291
+ total_params = 0
292
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
293
+ offset = 0
294
+ avail_numel = full_single_fp32_vector.numel()
295
+ for name, shape in shapes.items():
296
+
297
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
298
+ total_numel += unpartitioned_numel
299
+ total_params += 1
300
+
301
+ if debug:
302
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
303
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
304
+ offset += unpartitioned_numel
305
+
306
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
307
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
308
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
309
+ # live optimizer object, so we are checking that the numbers are within the right range
310
+ align_to = 2 * world_size
311
+
312
+ def zero2_align(x):
313
+ return align_to * math.ceil(x / align_to)
314
+
315
+ if debug:
316
+ print(f"original offset={offset}, avail_numel={avail_numel}")
317
+
318
+ offset = zero2_align(offset)
319
+ avail_numel = zero2_align(avail_numel)
320
+
321
+ if debug:
322
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
323
+
324
+ # Sanity check
325
+ if offset != avail_numel:
326
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
327
+
328
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
329
+
330
+
331
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
332
+ exclude_frozen_parameters):
333
+ state_dict = OrderedDict()
334
+
335
+ # buffers
336
+ buffers = zero_model_states[0].buffers
337
+ state_dict.update(buffers)
338
+ if debug:
339
+ print(f"added {len(buffers)} buffers")
340
+
341
+ if not exclude_frozen_parameters:
342
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
343
+
344
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
345
+
346
+ # recover shared parameters
347
+ for pair in zero_model_states[0].shared_params:
348
+ if pair[1] in state_dict:
349
+ state_dict[pair[0]] = state_dict[pair[1]]
350
+
351
+ return state_dict
352
+
353
+
354
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
355
+ remainder = unpartitioned_numel % world_size
356
+ padding_numel = (world_size - remainder) if remainder else 0
357
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
358
+ return partitioned_numel, padding_numel
359
+
360
+
361
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
362
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
363
+ return
364
+
365
+ if debug:
366
+ for i in range(world_size):
367
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
368
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
369
+
370
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
371
+ wanted_params = len(frozen_param_shapes)
372
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
373
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
374
+ print(f'Frozen params: Have {avail_numel} numels to process.')
375
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
376
+
377
+ total_params = 0
378
+ total_numel = 0
379
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
380
+ total_params += 1
381
+ unpartitioned_numel = shape.numel()
382
+ total_numel += unpartitioned_numel
383
+
384
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
385
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
386
+
387
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
388
+
389
+ if debug:
390
+ print(
391
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
392
+ )
393
+
394
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
395
+
396
+
397
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
398
+ param_shapes = zero_model_states[0].param_shapes
399
+ avail_numel = fp32_flat_groups[0].numel() * world_size
400
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
401
+ # param, re-consolidating each param, while dealing with padding if any
402
+
403
+ # merge list of dicts, preserving order
404
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
405
+
406
+ if debug:
407
+ for i in range(world_size):
408
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
409
+
410
+ wanted_params = len(param_shapes)
411
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
412
+ # not asserting if there is a mismatch due to possible padding
413
+ avail_numel = fp32_flat_groups[0].numel() * world_size
414
+ print(f"Trainable params: Have {avail_numel} numels to process.")
415
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
416
+
417
+ # params
418
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
419
+ # out-of-core computing solution
420
+ offset = 0
421
+ total_numel = 0
422
+ total_params = 0
423
+ for name, shape in param_shapes.items():
424
+
425
+ unpartitioned_numel = shape.numel()
426
+ total_numel += unpartitioned_numel
427
+ total_params += 1
428
+
429
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
430
+
431
+ if debug:
432
+ print(
433
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
434
+ )
435
+
436
+ # XXX: memory usage doubles here
437
+ state_dict[name] = torch.cat(
438
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
439
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
440
+ offset += partitioned_numel
441
+
442
+ offset *= world_size
443
+
444
+ # Sanity check
445
+ if offset != avail_numel:
446
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
447
+
448
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
449
+
450
+
451
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
452
+ exclude_frozen_parameters):
453
+ state_dict = OrderedDict()
454
+
455
+ # buffers
456
+ buffers = zero_model_states[0].buffers
457
+ state_dict.update(buffers)
458
+ if debug:
459
+ print(f"added {len(buffers)} buffers")
460
+
461
+ if not exclude_frozen_parameters:
462
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
463
+
464
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
465
+
466
+ # recover shared parameters
467
+ for pair in zero_model_states[0].shared_params:
468
+ if pair[1] in state_dict:
469
+ state_dict[pair[0]] = state_dict[pair[1]]
470
+
471
+ return state_dict
472
+
473
+
474
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
475
+ """
476
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
477
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
478
+ via a model hub.
479
+
480
+ Args:
481
+ - ``checkpoint_dir``: path to the desired checkpoint folder
482
+ - ``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``
483
+ - ``exclude_frozen_parameters``: exclude frozen parameters
484
+
485
+ Returns:
486
+ - pytorch ``state_dict``
487
+
488
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
489
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
490
+ the checkpoint.
491
+
492
+ A typical usage might be ::
493
+
494
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
495
+ # do the training and checkpoint saving
496
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
497
+ model = model.cpu() # move to cpu
498
+ model.load_state_dict(state_dict)
499
+ # submit to model hub or save the model to share with others
500
+
501
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
502
+ application. i.e. you will need to re-initialize the deepspeed engine, since
503
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
504
+
505
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
506
+
507
+ """
508
+ if tag is None:
509
+ latest_path = os.path.join(checkpoint_dir, 'latest')
510
+ if os.path.isfile(latest_path):
511
+ with open(latest_path, 'r') as fd:
512
+ tag = fd.read().strip()
513
+ else:
514
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
515
+
516
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
517
+
518
+ if not os.path.isdir(ds_checkpoint_dir):
519
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
520
+
521
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
522
+
523
+
524
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None, exclude_frozen_parameters=False):
525
+ """
526
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
527
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
528
+
529
+ Args:
530
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
531
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
532
+ - ``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``
533
+ - ``exclude_frozen_parameters``: exclude frozen parameters
534
+ """
535
+
536
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
537
+ print(f"Saving fp32 state dict to {output_file}")
538
+ torch.save(state_dict, output_file)
539
+
540
+
541
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
542
+ """
543
+ 1. Put the provided model to cpu
544
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
545
+ 3. Load it into the provided model
546
+
547
+ Args:
548
+ - ``model``: the model object to update
549
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
550
+ - ``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``
551
+
552
+ Returns:
553
+ - ``model`: modified model
554
+
555
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
556
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
557
+ conveniently placed for you in the checkpoint folder.
558
+
559
+ A typical usage might be ::
560
+
561
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
562
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
563
+ # submit to model hub or save the model to share with others
564
+
565
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
566
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
567
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
568
+
569
+ """
570
+ logger.info(f"Extracting fp32 weights")
571
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
572
+
573
+ logger.info(f"Overwriting model with fp32 weights")
574
+ model = model.cpu()
575
+ model.load_state_dict(state_dict, strict=False)
576
+
577
+ return model
578
+
579
+
580
+ if __name__ == "__main__":
581
+
582
+ parser = argparse.ArgumentParser()
583
+ parser.add_argument("checkpoint_dir",
584
+ type=str,
585
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
586
+ parser.add_argument(
587
+ "output_file",
588
+ type=str,
589
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
590
+ parser.add_argument("-t",
591
+ "--tag",
592
+ type=str,
593
+ default=None,
594
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
595
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
596
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
597
+ args = parser.parse_args()
598
+
599
+ debug = args.debug
600
+
601
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
602
+ args.output_file,
603
+ tag=args.tag,
604
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.45.1",
37
+ "use_cache": true,
38
+ "vocab_size": 50257
39
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.45.1"
6
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": {
5
+ "content": "[PAD]",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "unk_token": "<|endoftext|>"
12
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/tokenizer_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": "[PAD]",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "50258": {
21
+ "content": "🅁",
22
+ "lstrip": true,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ }
28
+ },
29
+ "bos_token": "<|endoftext|>",
30
+ "clean_up_tokenization_spaces": false,
31
+ "eos_token": "<|endoftext|>",
32
+ "model_max_length": 1024,
33
+ "pad_token": "[PAD]",
34
+ "tokenizer_class": "GPT2Tokenizer",
35
+ "unk_token": "<|endoftext|>"
36
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-1900/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[PAD]": 50257,
3
+ "🅁": 50258
4
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.45.1",
37
+ "use_cache": true,
38
+ "vocab_size": 50257
39
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.45.1"
6
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step200
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": {
5
+ "content": "[PAD]",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "unk_token": "<|endoftext|>"
12
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/tokenizer_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": "[PAD]",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "50258": {
21
+ "content": "🅁",
22
+ "lstrip": true,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ }
28
+ },
29
+ "bos_token": "<|endoftext|>",
30
+ "clean_up_tokenization_spaces": false,
31
+ "eos_token": "<|endoftext|>",
32
+ "model_max_length": 1024,
33
+ "pad_token": "[PAD]",
34
+ "tokenizer_class": "GPT2Tokenizer",
35
+ "unk_token": "<|endoftext|>"
36
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/trainer_state.json ADDED
@@ -0,0 +1,1593 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 0.2054442732408834,
5
+ "eval_steps": 10,
6
+ "global_step": 200,
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.001027221366204417,
13
+ "grad_norm": 0.0,
14
+ "learning_rate": 0.0,
15
+ "loss": 4.8613,
16
+ "step": 1
17
+ },
18
+ {
19
+ "epoch": 0.002054442732408834,
20
+ "grad_norm": 0.0,
21
+ "learning_rate": 0.0,
22
+ "loss": 4.8757,
23
+ "step": 2
24
+ },
25
+ {
26
+ "epoch": 0.0030816640986132513,
27
+ "grad_norm": 0.0,
28
+ "learning_rate": 0.0,
29
+ "loss": 4.9408,
30
+ "step": 3
31
+ },
32
+ {
33
+ "epoch": 0.004108885464817668,
34
+ "grad_norm": 0.0,
35
+ "learning_rate": 0.0,
36
+ "loss": 4.9219,
37
+ "step": 4
38
+ },
39
+ {
40
+ "epoch": 0.005136106831022085,
41
+ "grad_norm": 0.0,
42
+ "learning_rate": 0.0,
43
+ "loss": 4.9043,
44
+ "step": 5
45
+ },
46
+ {
47
+ "epoch": 0.0061633281972265025,
48
+ "grad_norm": 0.0,
49
+ "learning_rate": 0.0,
50
+ "loss": 4.8965,
51
+ "step": 6
52
+ },
53
+ {
54
+ "epoch": 0.007190549563430919,
55
+ "grad_norm": 0.0,
56
+ "learning_rate": 0.0,
57
+ "loss": 4.8307,
58
+ "step": 7
59
+ },
60
+ {
61
+ "epoch": 0.008217770929635337,
62
+ "grad_norm": 0.0,
63
+ "learning_rate": 0.0,
64
+ "loss": 4.9173,
65
+ "step": 8
66
+ },
67
+ {
68
+ "epoch": 0.009244992295839754,
69
+ "grad_norm": 0.0,
70
+ "learning_rate": 0.0,
71
+ "loss": 4.9069,
72
+ "step": 9
73
+ },
74
+ {
75
+ "epoch": 0.01027221366204417,
76
+ "grad_norm": 0.0,
77
+ "learning_rate": 0.0,
78
+ "loss": 4.9076,
79
+ "step": 10
80
+ },
81
+ {
82
+ "epoch": 0.01027221366204417,
83
+ "eval_loss": 4.63671875,
84
+ "eval_runtime": 8.1008,
85
+ "eval_samples_per_second": 123.444,
86
+ "eval_steps_per_second": 5.185,
87
+ "step": 10
88
+ },
89
+ {
90
+ "epoch": 0.011299435028248588,
91
+ "grad_norm": 0.0,
92
+ "learning_rate": 0.0,
93
+ "loss": 4.9036,
94
+ "step": 11
95
+ },
96
+ {
97
+ "epoch": 0.012326656394453005,
98
+ "grad_norm": 0.0,
99
+ "learning_rate": 0.0,
100
+ "loss": 4.8652,
101
+ "step": 12
102
+ },
103
+ {
104
+ "epoch": 0.01335387776065742,
105
+ "grad_norm": 0.0,
106
+ "learning_rate": 0.0,
107
+ "loss": 4.9336,
108
+ "step": 13
109
+ },
110
+ {
111
+ "epoch": 0.014381099126861838,
112
+ "grad_norm": 0.0,
113
+ "learning_rate": 0.0,
114
+ "loss": 4.9245,
115
+ "step": 14
116
+ },
117
+ {
118
+ "epoch": 0.015408320493066256,
119
+ "grad_norm": 0.0,
120
+ "learning_rate": 0.0,
121
+ "loss": 4.9336,
122
+ "step": 15
123
+ },
124
+ {
125
+ "epoch": 0.016435541859270673,
126
+ "grad_norm": 0.0,
127
+ "learning_rate": 0.0,
128
+ "loss": 4.8516,
129
+ "step": 16
130
+ },
131
+ {
132
+ "epoch": 0.01746276322547509,
133
+ "grad_norm": 0.0,
134
+ "learning_rate": 0.0,
135
+ "loss": 4.8704,
136
+ "step": 17
137
+ },
138
+ {
139
+ "epoch": 0.01848998459167951,
140
+ "grad_norm": 0.0,
141
+ "learning_rate": 0.0,
142
+ "loss": 4.9004,
143
+ "step": 18
144
+ },
145
+ {
146
+ "epoch": 0.019517205957883924,
147
+ "grad_norm": 0.0,
148
+ "learning_rate": 0.0,
149
+ "loss": 4.8112,
150
+ "step": 19
151
+ },
152
+ {
153
+ "epoch": 0.02054442732408834,
154
+ "grad_norm": 0.0,
155
+ "learning_rate": 0.0,
156
+ "loss": 4.8672,
157
+ "step": 20
158
+ },
159
+ {
160
+ "epoch": 0.02054442732408834,
161
+ "eval_loss": 4.63671875,
162
+ "eval_runtime": 8.0523,
163
+ "eval_samples_per_second": 124.188,
164
+ "eval_steps_per_second": 5.216,
165
+ "step": 20
166
+ },
167
+ {
168
+ "epoch": 0.02157164869029276,
169
+ "grad_norm": 28.116819381713867,
170
+ "learning_rate": 1.7123287671232876e-08,
171
+ "loss": 4.9049,
172
+ "step": 21
173
+ },
174
+ {
175
+ "epoch": 0.022598870056497175,
176
+ "grad_norm": 27.03044319152832,
177
+ "learning_rate": 3.424657534246575e-08,
178
+ "loss": 4.918,
179
+ "step": 22
180
+ },
181
+ {
182
+ "epoch": 0.02362609142270159,
183
+ "grad_norm": 27.387975692749023,
184
+ "learning_rate": 5.136986301369863e-08,
185
+ "loss": 4.86,
186
+ "step": 23
187
+ },
188
+ {
189
+ "epoch": 0.02465331278890601,
190
+ "grad_norm": 26.709815979003906,
191
+ "learning_rate": 6.84931506849315e-08,
192
+ "loss": 4.8659,
193
+ "step": 24
194
+ },
195
+ {
196
+ "epoch": 0.025680534155110426,
197
+ "grad_norm": 28.10965919494629,
198
+ "learning_rate": 8.561643835616439e-08,
199
+ "loss": 4.8789,
200
+ "step": 25
201
+ },
202
+ {
203
+ "epoch": 0.02670775552131484,
204
+ "grad_norm": 27.105060577392578,
205
+ "learning_rate": 1.0273972602739726e-07,
206
+ "loss": 4.8581,
207
+ "step": 26
208
+ },
209
+ {
210
+ "epoch": 0.02773497688751926,
211
+ "grad_norm": 28.362043380737305,
212
+ "learning_rate": 1.1986301369863014e-07,
213
+ "loss": 4.8626,
214
+ "step": 27
215
+ },
216
+ {
217
+ "epoch": 0.028762198253723677,
218
+ "grad_norm": 26.980588912963867,
219
+ "learning_rate": 1.36986301369863e-07,
220
+ "loss": 4.873,
221
+ "step": 28
222
+ },
223
+ {
224
+ "epoch": 0.029789419619928096,
225
+ "grad_norm": 27.26178550720215,
226
+ "learning_rate": 1.541095890410959e-07,
227
+ "loss": 4.9076,
228
+ "step": 29
229
+ },
230
+ {
231
+ "epoch": 0.030816640986132512,
232
+ "grad_norm": 27.26181983947754,
233
+ "learning_rate": 1.7123287671232878e-07,
234
+ "loss": 4.9069,
235
+ "step": 30
236
+ },
237
+ {
238
+ "epoch": 0.030816640986132512,
239
+ "eval_loss": 4.63671875,
240
+ "eval_runtime": 8.1739,
241
+ "eval_samples_per_second": 122.341,
242
+ "eval_steps_per_second": 5.138,
243
+ "step": 30
244
+ },
245
+ {
246
+ "epoch": 0.03184386235233693,
247
+ "grad_norm": 27.67842674255371,
248
+ "learning_rate": 1.8835616438356165e-07,
249
+ "loss": 4.8991,
250
+ "step": 31
251
+ },
252
+ {
253
+ "epoch": 0.03287108371854135,
254
+ "grad_norm": 27.32350730895996,
255
+ "learning_rate": 2.0547945205479452e-07,
256
+ "loss": 4.9108,
257
+ "step": 32
258
+ },
259
+ {
260
+ "epoch": 0.03389830508474576,
261
+ "grad_norm": 27.842466354370117,
262
+ "learning_rate": 2.226027397260274e-07,
263
+ "loss": 4.8939,
264
+ "step": 33
265
+ },
266
+ {
267
+ "epoch": 0.03492552645095018,
268
+ "grad_norm": 28.03348159790039,
269
+ "learning_rate": 2.397260273972603e-07,
270
+ "loss": 4.8783,
271
+ "step": 34
272
+ },
273
+ {
274
+ "epoch": 0.035952747817154594,
275
+ "grad_norm": 27.308210372924805,
276
+ "learning_rate": 2.568493150684932e-07,
277
+ "loss": 4.877,
278
+ "step": 35
279
+ },
280
+ {
281
+ "epoch": 0.03697996918335902,
282
+ "grad_norm": 27.26631736755371,
283
+ "learning_rate": 2.73972602739726e-07,
284
+ "loss": 4.8281,
285
+ "step": 36
286
+ },
287
+ {
288
+ "epoch": 0.03800719054956343,
289
+ "grad_norm": 26.74373435974121,
290
+ "learning_rate": 2.910958904109589e-07,
291
+ "loss": 4.9264,
292
+ "step": 37
293
+ },
294
+ {
295
+ "epoch": 0.03903441191576785,
296
+ "grad_norm": 26.75712013244629,
297
+ "learning_rate": 3.082191780821918e-07,
298
+ "loss": 4.8672,
299
+ "step": 38
300
+ },
301
+ {
302
+ "epoch": 0.040061633281972264,
303
+ "grad_norm": 27.08635711669922,
304
+ "learning_rate": 3.2534246575342466e-07,
305
+ "loss": 4.8711,
306
+ "step": 39
307
+ },
308
+ {
309
+ "epoch": 0.04108885464817668,
310
+ "grad_norm": 27.5158634185791,
311
+ "learning_rate": 3.4246575342465755e-07,
312
+ "loss": 4.8984,
313
+ "step": 40
314
+ },
315
+ {
316
+ "epoch": 0.04108885464817668,
317
+ "eval_loss": 4.63671875,
318
+ "eval_runtime": 8.1684,
319
+ "eval_samples_per_second": 122.423,
320
+ "eval_steps_per_second": 5.142,
321
+ "step": 40
322
+ },
323
+ {
324
+ "epoch": 0.042116076014381096,
325
+ "grad_norm": 25.9942684173584,
326
+ "learning_rate": 3.595890410958904e-07,
327
+ "loss": 4.8079,
328
+ "step": 41
329
+ },
330
+ {
331
+ "epoch": 0.04314329738058552,
332
+ "grad_norm": 28.041112899780273,
333
+ "learning_rate": 3.767123287671233e-07,
334
+ "loss": 4.8405,
335
+ "step": 42
336
+ },
337
+ {
338
+ "epoch": 0.044170518746789934,
339
+ "grad_norm": 27.068256378173828,
340
+ "learning_rate": 3.938356164383562e-07,
341
+ "loss": 4.9121,
342
+ "step": 43
343
+ },
344
+ {
345
+ "epoch": 0.04519774011299435,
346
+ "grad_norm": 27.018674850463867,
347
+ "learning_rate": 4.1095890410958903e-07,
348
+ "loss": 4.8529,
349
+ "step": 44
350
+ },
351
+ {
352
+ "epoch": 0.046224961479198766,
353
+ "grad_norm": 27.157318115234375,
354
+ "learning_rate": 4.2808219178082193e-07,
355
+ "loss": 4.8307,
356
+ "step": 45
357
+ },
358
+ {
359
+ "epoch": 0.04725218284540318,
360
+ "grad_norm": 26.827917098999023,
361
+ "learning_rate": 4.452054794520548e-07,
362
+ "loss": 4.8385,
363
+ "step": 46
364
+ },
365
+ {
366
+ "epoch": 0.048279404211607604,
367
+ "grad_norm": 26.432662963867188,
368
+ "learning_rate": 4.6232876712328767e-07,
369
+ "loss": 4.8503,
370
+ "step": 47
371
+ },
372
+ {
373
+ "epoch": 0.04930662557781202,
374
+ "grad_norm": 26.891084671020508,
375
+ "learning_rate": 4.794520547945206e-07,
376
+ "loss": 4.9082,
377
+ "step": 48
378
+ },
379
+ {
380
+ "epoch": 0.050333846944016436,
381
+ "grad_norm": 26.872167587280273,
382
+ "learning_rate": 4.965753424657534e-07,
383
+ "loss": 4.86,
384
+ "step": 49
385
+ },
386
+ {
387
+ "epoch": 0.05136106831022085,
388
+ "grad_norm": 26.370975494384766,
389
+ "learning_rate": 5.136986301369864e-07,
390
+ "loss": 4.819,
391
+ "step": 50
392
+ },
393
+ {
394
+ "epoch": 0.05136106831022085,
395
+ "eval_loss": 4.6328125,
396
+ "eval_runtime": 8.1128,
397
+ "eval_samples_per_second": 123.262,
398
+ "eval_steps_per_second": 5.177,
399
+ "step": 50
400
+ },
401
+ {
402
+ "epoch": 0.05238828967642527,
403
+ "grad_norm": 27.79764747619629,
404
+ "learning_rate": 5.308219178082192e-07,
405
+ "loss": 4.8737,
406
+ "step": 51
407
+ },
408
+ {
409
+ "epoch": 0.05341551104262968,
410
+ "grad_norm": 25.080102920532227,
411
+ "learning_rate": 5.47945205479452e-07,
412
+ "loss": 4.8568,
413
+ "step": 52
414
+ },
415
+ {
416
+ "epoch": 0.054442732408834106,
417
+ "grad_norm": 26.24574089050293,
418
+ "learning_rate": 5.65068493150685e-07,
419
+ "loss": 4.7917,
420
+ "step": 53
421
+ },
422
+ {
423
+ "epoch": 0.05546995377503852,
424
+ "grad_norm": 25.477985382080078,
425
+ "learning_rate": 5.821917808219178e-07,
426
+ "loss": 4.8301,
427
+ "step": 54
428
+ },
429
+ {
430
+ "epoch": 0.05649717514124294,
431
+ "grad_norm": 25.411081314086914,
432
+ "learning_rate": 5.993150684931507e-07,
433
+ "loss": 4.8164,
434
+ "step": 55
435
+ },
436
+ {
437
+ "epoch": 0.05752439650744735,
438
+ "grad_norm": 24.9583797454834,
439
+ "learning_rate": 6.164383561643836e-07,
440
+ "loss": 4.7949,
441
+ "step": 56
442
+ },
443
+ {
444
+ "epoch": 0.05855161787365177,
445
+ "grad_norm": 26.102153778076172,
446
+ "learning_rate": 6.335616438356165e-07,
447
+ "loss": 4.8086,
448
+ "step": 57
449
+ },
450
+ {
451
+ "epoch": 0.05957883923985619,
452
+ "grad_norm": 26.286907196044922,
453
+ "learning_rate": 6.506849315068493e-07,
454
+ "loss": 4.8099,
455
+ "step": 58
456
+ },
457
+ {
458
+ "epoch": 0.06060606060606061,
459
+ "grad_norm": 25.195068359375,
460
+ "learning_rate": 6.678082191780823e-07,
461
+ "loss": 4.8685,
462
+ "step": 59
463
+ },
464
+ {
465
+ "epoch": 0.061633281972265024,
466
+ "grad_norm": 25.254196166992188,
467
+ "learning_rate": 6.849315068493151e-07,
468
+ "loss": 4.8203,
469
+ "step": 60
470
+ },
471
+ {
472
+ "epoch": 0.061633281972265024,
473
+ "eval_loss": 4.625,
474
+ "eval_runtime": 8.1304,
475
+ "eval_samples_per_second": 122.995,
476
+ "eval_steps_per_second": 5.166,
477
+ "step": 60
478
+ },
479
+ {
480
+ "epoch": 0.06266050333846944,
481
+ "grad_norm": 25.127748489379883,
482
+ "learning_rate": 7.020547945205481e-07,
483
+ "loss": 4.7956,
484
+ "step": 61
485
+ },
486
+ {
487
+ "epoch": 0.06368772470467386,
488
+ "grad_norm": 25.56139373779297,
489
+ "learning_rate": 7.191780821917808e-07,
490
+ "loss": 4.8073,
491
+ "step": 62
492
+ },
493
+ {
494
+ "epoch": 0.06471494607087827,
495
+ "grad_norm": 25.190975189208984,
496
+ "learning_rate": 7.363013698630137e-07,
497
+ "loss": 4.8353,
498
+ "step": 63
499
+ },
500
+ {
501
+ "epoch": 0.0657421674370827,
502
+ "grad_norm": 24.852304458618164,
503
+ "learning_rate": 7.534246575342466e-07,
504
+ "loss": 4.8236,
505
+ "step": 64
506
+ },
507
+ {
508
+ "epoch": 0.0667693888032871,
509
+ "grad_norm": 24.120141983032227,
510
+ "learning_rate": 7.705479452054795e-07,
511
+ "loss": 4.6797,
512
+ "step": 65
513
+ },
514
+ {
515
+ "epoch": 0.06779661016949153,
516
+ "grad_norm": 23.0483455657959,
517
+ "learning_rate": 7.876712328767124e-07,
518
+ "loss": 4.6842,
519
+ "step": 66
520
+ },
521
+ {
522
+ "epoch": 0.06882383153569595,
523
+ "grad_norm": 22.356775283813477,
524
+ "learning_rate": 8.047945205479453e-07,
525
+ "loss": 4.7311,
526
+ "step": 67
527
+ },
528
+ {
529
+ "epoch": 0.06985105290190036,
530
+ "grad_norm": 22.69537925720215,
531
+ "learning_rate": 8.219178082191781e-07,
532
+ "loss": 4.7272,
533
+ "step": 68
534
+ },
535
+ {
536
+ "epoch": 0.07087827426810478,
537
+ "grad_norm": 22.291152954101562,
538
+ "learning_rate": 8.39041095890411e-07,
539
+ "loss": 4.7109,
540
+ "step": 69
541
+ },
542
+ {
543
+ "epoch": 0.07190549563430919,
544
+ "grad_norm": 21.66524314880371,
545
+ "learning_rate": 8.561643835616439e-07,
546
+ "loss": 4.7904,
547
+ "step": 70
548
+ },
549
+ {
550
+ "epoch": 0.07190549563430919,
551
+ "eval_loss": 4.6015625,
552
+ "eval_runtime": 8.3582,
553
+ "eval_samples_per_second": 119.642,
554
+ "eval_steps_per_second": 5.025,
555
+ "step": 70
556
+ },
557
+ {
558
+ "epoch": 0.07293271700051361,
559
+ "grad_norm": 22.571956634521484,
560
+ "learning_rate": 8.732876712328768e-07,
561
+ "loss": 4.7285,
562
+ "step": 71
563
+ },
564
+ {
565
+ "epoch": 0.07395993836671803,
566
+ "grad_norm": 22.55990219116211,
567
+ "learning_rate": 8.904109589041097e-07,
568
+ "loss": 4.6576,
569
+ "step": 72
570
+ },
571
+ {
572
+ "epoch": 0.07498715973292244,
573
+ "grad_norm": 22.43810272216797,
574
+ "learning_rate": 9.075342465753426e-07,
575
+ "loss": 4.7552,
576
+ "step": 73
577
+ },
578
+ {
579
+ "epoch": 0.07601438109912687,
580
+ "grad_norm": 21.978988647460938,
581
+ "learning_rate": 9.246575342465753e-07,
582
+ "loss": 4.7461,
583
+ "step": 74
584
+ },
585
+ {
586
+ "epoch": 0.07704160246533127,
587
+ "grad_norm": 22.340654373168945,
588
+ "learning_rate": 9.417808219178083e-07,
589
+ "loss": 4.6986,
590
+ "step": 75
591
+ },
592
+ {
593
+ "epoch": 0.0780688238315357,
594
+ "grad_norm": 21.94169044494629,
595
+ "learning_rate": 9.589041095890411e-07,
596
+ "loss": 4.7038,
597
+ "step": 76
598
+ },
599
+ {
600
+ "epoch": 0.07909604519774012,
601
+ "grad_norm": 21.635208129882812,
602
+ "learning_rate": 9.76027397260274e-07,
603
+ "loss": 4.6777,
604
+ "step": 77
605
+ },
606
+ {
607
+ "epoch": 0.08012326656394453,
608
+ "grad_norm": 21.09151268005371,
609
+ "learning_rate": 9.931506849315068e-07,
610
+ "loss": 4.7773,
611
+ "step": 78
612
+ },
613
+ {
614
+ "epoch": 0.08115048793014895,
615
+ "grad_norm": 21.541440963745117,
616
+ "learning_rate": 1.0102739726027399e-06,
617
+ "loss": 4.6608,
618
+ "step": 79
619
+ },
620
+ {
621
+ "epoch": 0.08217770929635336,
622
+ "grad_norm": 21.233154296875,
623
+ "learning_rate": 1.0273972602739727e-06,
624
+ "loss": 4.7337,
625
+ "step": 80
626
+ },
627
+ {
628
+ "epoch": 0.08217770929635336,
629
+ "eval_loss": 4.58203125,
630
+ "eval_runtime": 8.0829,
631
+ "eval_samples_per_second": 123.719,
632
+ "eval_steps_per_second": 5.196,
633
+ "step": 80
634
+ },
635
+ {
636
+ "epoch": 0.08320493066255778,
637
+ "grad_norm": 21.584636688232422,
638
+ "learning_rate": 1.0445205479452056e-06,
639
+ "loss": 4.6458,
640
+ "step": 81
641
+ },
642
+ {
643
+ "epoch": 0.08423215202876219,
644
+ "grad_norm": 21.521387100219727,
645
+ "learning_rate": 1.0616438356164384e-06,
646
+ "loss": 4.6198,
647
+ "step": 82
648
+ },
649
+ {
650
+ "epoch": 0.08525937339496661,
651
+ "grad_norm": 21.139148712158203,
652
+ "learning_rate": 1.0787671232876712e-06,
653
+ "loss": 4.6927,
654
+ "step": 83
655
+ },
656
+ {
657
+ "epoch": 0.08628659476117104,
658
+ "grad_norm": 20.5504150390625,
659
+ "learning_rate": 1.095890410958904e-06,
660
+ "loss": 4.6426,
661
+ "step": 84
662
+ },
663
+ {
664
+ "epoch": 0.08731381612737545,
665
+ "grad_norm": 20.150310516357422,
666
+ "learning_rate": 1.1130136986301371e-06,
667
+ "loss": 4.6146,
668
+ "step": 85
669
+ },
670
+ {
671
+ "epoch": 0.08834103749357987,
672
+ "grad_norm": 19.10382652282715,
673
+ "learning_rate": 1.13013698630137e-06,
674
+ "loss": 4.6178,
675
+ "step": 86
676
+ },
677
+ {
678
+ "epoch": 0.08936825885978428,
679
+ "grad_norm": 18.845382690429688,
680
+ "learning_rate": 1.1472602739726028e-06,
681
+ "loss": 4.5703,
682
+ "step": 87
683
+ },
684
+ {
685
+ "epoch": 0.0903954802259887,
686
+ "grad_norm": 18.1544189453125,
687
+ "learning_rate": 1.1643835616438357e-06,
688
+ "loss": 4.6048,
689
+ "step": 88
690
+ },
691
+ {
692
+ "epoch": 0.09142270159219312,
693
+ "grad_norm": 17.512283325195312,
694
+ "learning_rate": 1.1815068493150685e-06,
695
+ "loss": 4.5866,
696
+ "step": 89
697
+ },
698
+ {
699
+ "epoch": 0.09244992295839753,
700
+ "grad_norm": 18.081344604492188,
701
+ "learning_rate": 1.1986301369863014e-06,
702
+ "loss": 4.582,
703
+ "step": 90
704
+ },
705
+ {
706
+ "epoch": 0.09244992295839753,
707
+ "eval_loss": 4.53125,
708
+ "eval_runtime": 8.1682,
709
+ "eval_samples_per_second": 122.426,
710
+ "eval_steps_per_second": 5.142,
711
+ "step": 90
712
+ },
713
+ {
714
+ "epoch": 0.09347714432460195,
715
+ "grad_norm": 17.38676643371582,
716
+ "learning_rate": 1.2157534246575344e-06,
717
+ "loss": 4.5514,
718
+ "step": 91
719
+ },
720
+ {
721
+ "epoch": 0.09450436569080636,
722
+ "grad_norm": 17.519012451171875,
723
+ "learning_rate": 1.2328767123287673e-06,
724
+ "loss": 4.5638,
725
+ "step": 92
726
+ },
727
+ {
728
+ "epoch": 0.09553158705701079,
729
+ "grad_norm": 17.74829864501953,
730
+ "learning_rate": 1.25e-06,
731
+ "loss": 4.5716,
732
+ "step": 93
733
+ },
734
+ {
735
+ "epoch": 0.09655880842321521,
736
+ "grad_norm": 17.831249237060547,
737
+ "learning_rate": 1.267123287671233e-06,
738
+ "loss": 4.5697,
739
+ "step": 94
740
+ },
741
+ {
742
+ "epoch": 0.09758602978941962,
743
+ "grad_norm": 17.400928497314453,
744
+ "learning_rate": 1.284246575342466e-06,
745
+ "loss": 4.5592,
746
+ "step": 95
747
+ },
748
+ {
749
+ "epoch": 0.09861325115562404,
750
+ "grad_norm": 17.711442947387695,
751
+ "learning_rate": 1.3013698630136986e-06,
752
+ "loss": 4.5078,
753
+ "step": 96
754
+ },
755
+ {
756
+ "epoch": 0.09964047252182845,
757
+ "grad_norm": 17.26605796813965,
758
+ "learning_rate": 1.3184931506849317e-06,
759
+ "loss": 4.5892,
760
+ "step": 97
761
+ },
762
+ {
763
+ "epoch": 0.10066769388803287,
764
+ "grad_norm": 17.803537368774414,
765
+ "learning_rate": 1.3356164383561645e-06,
766
+ "loss": 4.4668,
767
+ "step": 98
768
+ },
769
+ {
770
+ "epoch": 0.1016949152542373,
771
+ "grad_norm": 17.142738342285156,
772
+ "learning_rate": 1.3527397260273976e-06,
773
+ "loss": 4.5391,
774
+ "step": 99
775
+ },
776
+ {
777
+ "epoch": 0.1027221366204417,
778
+ "grad_norm": 17.18332290649414,
779
+ "learning_rate": 1.3698630136986302e-06,
780
+ "loss": 4.5384,
781
+ "step": 100
782
+ },
783
+ {
784
+ "epoch": 0.1027221366204417,
785
+ "eval_loss": 4.49609375,
786
+ "eval_runtime": 8.101,
787
+ "eval_samples_per_second": 123.442,
788
+ "eval_steps_per_second": 5.185,
789
+ "step": 100
790
+ },
791
+ {
792
+ "epoch": 0.10374935798664613,
793
+ "grad_norm": 17.503074645996094,
794
+ "learning_rate": 1.386986301369863e-06,
795
+ "loss": 4.5436,
796
+ "step": 101
797
+ },
798
+ {
799
+ "epoch": 0.10477657935285054,
800
+ "grad_norm": 17.03574562072754,
801
+ "learning_rate": 1.4041095890410961e-06,
802
+ "loss": 4.5189,
803
+ "step": 102
804
+ },
805
+ {
806
+ "epoch": 0.10580380071905496,
807
+ "grad_norm": 17.297348022460938,
808
+ "learning_rate": 1.421232876712329e-06,
809
+ "loss": 4.4512,
810
+ "step": 103
811
+ },
812
+ {
813
+ "epoch": 0.10683102208525937,
814
+ "grad_norm": 17.349184036254883,
815
+ "learning_rate": 1.4383561643835616e-06,
816
+ "loss": 4.5365,
817
+ "step": 104
818
+ },
819
+ {
820
+ "epoch": 0.10785824345146379,
821
+ "grad_norm": 16.68321990966797,
822
+ "learning_rate": 1.4554794520547946e-06,
823
+ "loss": 4.5026,
824
+ "step": 105
825
+ },
826
+ {
827
+ "epoch": 0.10888546481766821,
828
+ "grad_norm": 17.097679138183594,
829
+ "learning_rate": 1.4726027397260275e-06,
830
+ "loss": 4.5306,
831
+ "step": 106
832
+ },
833
+ {
834
+ "epoch": 0.10991268618387262,
835
+ "grad_norm": 16.458786010742188,
836
+ "learning_rate": 1.4897260273972605e-06,
837
+ "loss": 4.5091,
838
+ "step": 107
839
+ },
840
+ {
841
+ "epoch": 0.11093990755007704,
842
+ "grad_norm": 16.699987411499023,
843
+ "learning_rate": 1.5068493150684932e-06,
844
+ "loss": 4.5488,
845
+ "step": 108
846
+ },
847
+ {
848
+ "epoch": 0.11196712891628145,
849
+ "grad_norm": 16.068634033203125,
850
+ "learning_rate": 1.5239726027397262e-06,
851
+ "loss": 4.4023,
852
+ "step": 109
853
+ },
854
+ {
855
+ "epoch": 0.11299435028248588,
856
+ "grad_norm": 16.19753646850586,
857
+ "learning_rate": 1.541095890410959e-06,
858
+ "loss": 4.5267,
859
+ "step": 110
860
+ },
861
+ {
862
+ "epoch": 0.11299435028248588,
863
+ "eval_loss": 4.4296875,
864
+ "eval_runtime": 8.1416,
865
+ "eval_samples_per_second": 122.826,
866
+ "eval_steps_per_second": 5.159,
867
+ "step": 110
868
+ },
869
+ {
870
+ "epoch": 0.1140215716486903,
871
+ "grad_norm": 16.418561935424805,
872
+ "learning_rate": 1.5582191780821921e-06,
873
+ "loss": 4.418,
874
+ "step": 111
875
+ },
876
+ {
877
+ "epoch": 0.1150487930148947,
878
+ "grad_norm": 15.953530311584473,
879
+ "learning_rate": 1.5753424657534248e-06,
880
+ "loss": 4.4883,
881
+ "step": 112
882
+ },
883
+ {
884
+ "epoch": 0.11607601438109913,
885
+ "grad_norm": 15.907369613647461,
886
+ "learning_rate": 1.5924657534246576e-06,
887
+ "loss": 4.3965,
888
+ "step": 113
889
+ },
890
+ {
891
+ "epoch": 0.11710323574730354,
892
+ "grad_norm": 16.10055923461914,
893
+ "learning_rate": 1.6095890410958907e-06,
894
+ "loss": 4.4512,
895
+ "step": 114
896
+ },
897
+ {
898
+ "epoch": 0.11813045711350796,
899
+ "grad_norm": 15.759989738464355,
900
+ "learning_rate": 1.6267123287671235e-06,
901
+ "loss": 4.3919,
902
+ "step": 115
903
+ },
904
+ {
905
+ "epoch": 0.11915767847971238,
906
+ "grad_norm": 15.749765396118164,
907
+ "learning_rate": 1.6438356164383561e-06,
908
+ "loss": 4.5052,
909
+ "step": 116
910
+ },
911
+ {
912
+ "epoch": 0.12018489984591679,
913
+ "grad_norm": 15.092001914978027,
914
+ "learning_rate": 1.6609589041095892e-06,
915
+ "loss": 4.4375,
916
+ "step": 117
917
+ },
918
+ {
919
+ "epoch": 0.12121212121212122,
920
+ "grad_norm": 14.8633451461792,
921
+ "learning_rate": 1.678082191780822e-06,
922
+ "loss": 4.3997,
923
+ "step": 118
924
+ },
925
+ {
926
+ "epoch": 0.12223934257832562,
927
+ "grad_norm": 14.971479415893555,
928
+ "learning_rate": 1.695205479452055e-06,
929
+ "loss": 4.4102,
930
+ "step": 119
931
+ },
932
+ {
933
+ "epoch": 0.12326656394453005,
934
+ "grad_norm": 14.7716064453125,
935
+ "learning_rate": 1.7123287671232877e-06,
936
+ "loss": 4.4434,
937
+ "step": 120
938
+ },
939
+ {
940
+ "epoch": 0.12326656394453005,
941
+ "eval_loss": 4.38671875,
942
+ "eval_runtime": 8.1933,
943
+ "eval_samples_per_second": 122.051,
944
+ "eval_steps_per_second": 5.126,
945
+ "step": 120
946
+ },
947
+ {
948
+ "epoch": 0.12429378531073447,
949
+ "grad_norm": 14.274008750915527,
950
+ "learning_rate": 1.7294520547945206e-06,
951
+ "loss": 4.4596,
952
+ "step": 121
953
+ },
954
+ {
955
+ "epoch": 0.12532100667693888,
956
+ "grad_norm": 14.329883575439453,
957
+ "learning_rate": 1.7465753424657536e-06,
958
+ "loss": 4.3704,
959
+ "step": 122
960
+ },
961
+ {
962
+ "epoch": 0.1263482280431433,
963
+ "grad_norm": 14.691496849060059,
964
+ "learning_rate": 1.7636986301369865e-06,
965
+ "loss": 4.3444,
966
+ "step": 123
967
+ },
968
+ {
969
+ "epoch": 0.12737544940934772,
970
+ "grad_norm": 14.369722366333008,
971
+ "learning_rate": 1.7808219178082193e-06,
972
+ "loss": 4.3372,
973
+ "step": 124
974
+ },
975
+ {
976
+ "epoch": 0.12840267077555212,
977
+ "grad_norm": 13.581815719604492,
978
+ "learning_rate": 1.7979452054794521e-06,
979
+ "loss": 4.375,
980
+ "step": 125
981
+ },
982
+ {
983
+ "epoch": 0.12942989214175654,
984
+ "grad_norm": 13.743803024291992,
985
+ "learning_rate": 1.8150684931506852e-06,
986
+ "loss": 4.4056,
987
+ "step": 126
988
+ },
989
+ {
990
+ "epoch": 0.13045711350796096,
991
+ "grad_norm": 13.931293487548828,
992
+ "learning_rate": 1.832191780821918e-06,
993
+ "loss": 4.3522,
994
+ "step": 127
995
+ },
996
+ {
997
+ "epoch": 0.1314843348741654,
998
+ "grad_norm": 13.874761581420898,
999
+ "learning_rate": 1.8493150684931507e-06,
1000
+ "loss": 4.3783,
1001
+ "step": 128
1002
+ },
1003
+ {
1004
+ "epoch": 0.1325115562403698,
1005
+ "grad_norm": 14.007351875305176,
1006
+ "learning_rate": 1.8664383561643837e-06,
1007
+ "loss": 4.3535,
1008
+ "step": 129
1009
+ },
1010
+ {
1011
+ "epoch": 0.1335387776065742,
1012
+ "grad_norm": 14.182611465454102,
1013
+ "learning_rate": 1.8835616438356166e-06,
1014
+ "loss": 4.3978,
1015
+ "step": 130
1016
+ },
1017
+ {
1018
+ "epoch": 0.1335387776065742,
1019
+ "eval_loss": 4.35546875,
1020
+ "eval_runtime": 8.1643,
1021
+ "eval_samples_per_second": 122.485,
1022
+ "eval_steps_per_second": 5.144,
1023
+ "step": 130
1024
+ },
1025
+ {
1026
+ "epoch": 0.13456599897277863,
1027
+ "grad_norm": 13.796817779541016,
1028
+ "learning_rate": 1.9006849315068496e-06,
1029
+ "loss": 4.3529,
1030
+ "step": 131
1031
+ },
1032
+ {
1033
+ "epoch": 0.13559322033898305,
1034
+ "grad_norm": 13.67389965057373,
1035
+ "learning_rate": 1.9178082191780823e-06,
1036
+ "loss": 4.4186,
1037
+ "step": 132
1038
+ },
1039
+ {
1040
+ "epoch": 0.13662044170518747,
1041
+ "grad_norm": 13.272880554199219,
1042
+ "learning_rate": 1.9349315068493153e-06,
1043
+ "loss": 4.3965,
1044
+ "step": 133
1045
+ },
1046
+ {
1047
+ "epoch": 0.1376476630713919,
1048
+ "grad_norm": 13.589006423950195,
1049
+ "learning_rate": 1.952054794520548e-06,
1050
+ "loss": 4.3307,
1051
+ "step": 134
1052
+ },
1053
+ {
1054
+ "epoch": 0.1386748844375963,
1055
+ "grad_norm": 13.390036582946777,
1056
+ "learning_rate": 1.969178082191781e-06,
1057
+ "loss": 4.3639,
1058
+ "step": 135
1059
+ },
1060
+ {
1061
+ "epoch": 0.1397021058038007,
1062
+ "grad_norm": 12.994545936584473,
1063
+ "learning_rate": 1.9863013698630136e-06,
1064
+ "loss": 4.3145,
1065
+ "step": 136
1066
+ },
1067
+ {
1068
+ "epoch": 0.14072932717000514,
1069
+ "grad_norm": 13.275940895080566,
1070
+ "learning_rate": 2.0034246575342467e-06,
1071
+ "loss": 4.2676,
1072
+ "step": 137
1073
+ },
1074
+ {
1075
+ "epoch": 0.14175654853620956,
1076
+ "grad_norm": 12.996981620788574,
1077
+ "learning_rate": 2.0205479452054797e-06,
1078
+ "loss": 4.4238,
1079
+ "step": 138
1080
+ },
1081
+ {
1082
+ "epoch": 0.14278376990241398,
1083
+ "grad_norm": 12.925374031066895,
1084
+ "learning_rate": 2.037671232876713e-06,
1085
+ "loss": 4.2786,
1086
+ "step": 139
1087
+ },
1088
+ {
1089
+ "epoch": 0.14381099126861838,
1090
+ "grad_norm": 12.948338508605957,
1091
+ "learning_rate": 2.0547945205479454e-06,
1092
+ "loss": 4.3424,
1093
+ "step": 140
1094
+ },
1095
+ {
1096
+ "epoch": 0.14381099126861838,
1097
+ "eval_loss": 4.328125,
1098
+ "eval_runtime": 8.3013,
1099
+ "eval_samples_per_second": 120.462,
1100
+ "eval_steps_per_second": 5.059,
1101
+ "step": 140
1102
+ },
1103
+ {
1104
+ "epoch": 0.1448382126348228,
1105
+ "grad_norm": 12.943131446838379,
1106
+ "learning_rate": 2.071917808219178e-06,
1107
+ "loss": 4.2682,
1108
+ "step": 141
1109
+ },
1110
+ {
1111
+ "epoch": 0.14586543400102722,
1112
+ "grad_norm": 11.763097763061523,
1113
+ "learning_rate": 2.089041095890411e-06,
1114
+ "loss": 4.276,
1115
+ "step": 142
1116
+ },
1117
+ {
1118
+ "epoch": 0.14689265536723164,
1119
+ "grad_norm": 12.934331893920898,
1120
+ "learning_rate": 2.106164383561644e-06,
1121
+ "loss": 4.4095,
1122
+ "step": 143
1123
+ },
1124
+ {
1125
+ "epoch": 0.14791987673343607,
1126
+ "grad_norm": 12.17612361907959,
1127
+ "learning_rate": 2.123287671232877e-06,
1128
+ "loss": 4.3053,
1129
+ "step": 144
1130
+ },
1131
+ {
1132
+ "epoch": 0.14894709809964046,
1133
+ "grad_norm": 12.38232135772705,
1134
+ "learning_rate": 2.14041095890411e-06,
1135
+ "loss": 4.2467,
1136
+ "step": 145
1137
+ },
1138
+ {
1139
+ "epoch": 0.14997431946584489,
1140
+ "grad_norm": 12.592203140258789,
1141
+ "learning_rate": 2.1575342465753425e-06,
1142
+ "loss": 4.2773,
1143
+ "step": 146
1144
+ },
1145
+ {
1146
+ "epoch": 0.1510015408320493,
1147
+ "grad_norm": 12.006210327148438,
1148
+ "learning_rate": 2.1746575342465755e-06,
1149
+ "loss": 4.2572,
1150
+ "step": 147
1151
+ },
1152
+ {
1153
+ "epoch": 0.15202876219825373,
1154
+ "grad_norm": 12.58430290222168,
1155
+ "learning_rate": 2.191780821917808e-06,
1156
+ "loss": 4.2995,
1157
+ "step": 148
1158
+ },
1159
+ {
1160
+ "epoch": 0.15305598356445815,
1161
+ "grad_norm": 12.709675788879395,
1162
+ "learning_rate": 2.2089041095890412e-06,
1163
+ "loss": 4.3392,
1164
+ "step": 149
1165
+ },
1166
+ {
1167
+ "epoch": 0.15408320493066255,
1168
+ "grad_norm": 12.174428939819336,
1169
+ "learning_rate": 2.2260273972602743e-06,
1170
+ "loss": 4.2734,
1171
+ "step": 150
1172
+ },
1173
+ {
1174
+ "epoch": 0.15408320493066255,
1175
+ "eval_loss": 4.29296875,
1176
+ "eval_runtime": 8.1394,
1177
+ "eval_samples_per_second": 122.859,
1178
+ "eval_steps_per_second": 5.16,
1179
+ "step": 150
1180
+ },
1181
+ {
1182
+ "epoch": 0.15511042629686697,
1183
+ "grad_norm": 11.123571395874023,
1184
+ "learning_rate": 2.243150684931507e-06,
1185
+ "loss": 4.151,
1186
+ "step": 151
1187
+ },
1188
+ {
1189
+ "epoch": 0.1561376476630714,
1190
+ "grad_norm": 11.71768569946289,
1191
+ "learning_rate": 2.26027397260274e-06,
1192
+ "loss": 4.2695,
1193
+ "step": 152
1194
+ },
1195
+ {
1196
+ "epoch": 0.15716486902927582,
1197
+ "grad_norm": 11.423957824707031,
1198
+ "learning_rate": 2.2773972602739726e-06,
1199
+ "loss": 4.2884,
1200
+ "step": 153
1201
+ },
1202
+ {
1203
+ "epoch": 0.15819209039548024,
1204
+ "grad_norm": 11.415791511535645,
1205
+ "learning_rate": 2.2945205479452057e-06,
1206
+ "loss": 4.2487,
1207
+ "step": 154
1208
+ },
1209
+ {
1210
+ "epoch": 0.15921931176168463,
1211
+ "grad_norm": 11.772719383239746,
1212
+ "learning_rate": 2.3116438356164387e-06,
1213
+ "loss": 4.2415,
1214
+ "step": 155
1215
+ },
1216
+ {
1217
+ "epoch": 0.16024653312788906,
1218
+ "grad_norm": 11.59867000579834,
1219
+ "learning_rate": 2.3287671232876713e-06,
1220
+ "loss": 4.1628,
1221
+ "step": 156
1222
+ },
1223
+ {
1224
+ "epoch": 0.16127375449409348,
1225
+ "grad_norm": 11.289015769958496,
1226
+ "learning_rate": 2.3458904109589044e-06,
1227
+ "loss": 4.3132,
1228
+ "step": 157
1229
+ },
1230
+ {
1231
+ "epoch": 0.1623009758602979,
1232
+ "grad_norm": 11.444629669189453,
1233
+ "learning_rate": 2.363013698630137e-06,
1234
+ "loss": 4.3164,
1235
+ "step": 158
1236
+ },
1237
+ {
1238
+ "epoch": 0.1633281972265023,
1239
+ "grad_norm": 11.693326950073242,
1240
+ "learning_rate": 2.38013698630137e-06,
1241
+ "loss": 4.2539,
1242
+ "step": 159
1243
+ },
1244
+ {
1245
+ "epoch": 0.16435541859270672,
1246
+ "grad_norm": 11.368536949157715,
1247
+ "learning_rate": 2.3972602739726027e-06,
1248
+ "loss": 4.2708,
1249
+ "step": 160
1250
+ },
1251
+ {
1252
+ "epoch": 0.16435541859270672,
1253
+ "eval_loss": 4.26171875,
1254
+ "eval_runtime": 8.1405,
1255
+ "eval_samples_per_second": 122.843,
1256
+ "eval_steps_per_second": 5.159,
1257
+ "step": 160
1258
+ },
1259
+ {
1260
+ "epoch": 0.16538263995891114,
1261
+ "grad_norm": 11.117278099060059,
1262
+ "learning_rate": 2.4143835616438358e-06,
1263
+ "loss": 4.2174,
1264
+ "step": 161
1265
+ },
1266
+ {
1267
+ "epoch": 0.16640986132511557,
1268
+ "grad_norm": 10.721233367919922,
1269
+ "learning_rate": 2.431506849315069e-06,
1270
+ "loss": 4.2493,
1271
+ "step": 162
1272
+ },
1273
+ {
1274
+ "epoch": 0.16743708269132,
1275
+ "grad_norm": 11.11534595489502,
1276
+ "learning_rate": 2.4486301369863015e-06,
1277
+ "loss": 4.2194,
1278
+ "step": 163
1279
+ },
1280
+ {
1281
+ "epoch": 0.16846430405752438,
1282
+ "grad_norm": 10.975207328796387,
1283
+ "learning_rate": 2.4657534246575345e-06,
1284
+ "loss": 4.2109,
1285
+ "step": 164
1286
+ },
1287
+ {
1288
+ "epoch": 0.1694915254237288,
1289
+ "grad_norm": 10.390185356140137,
1290
+ "learning_rate": 2.482876712328767e-06,
1291
+ "loss": 4.2051,
1292
+ "step": 165
1293
+ },
1294
+ {
1295
+ "epoch": 0.17051874678993323,
1296
+ "grad_norm": 10.932448387145996,
1297
+ "learning_rate": 2.5e-06,
1298
+ "loss": 4.2376,
1299
+ "step": 166
1300
+ },
1301
+ {
1302
+ "epoch": 0.17154596815613765,
1303
+ "grad_norm": 10.311753273010254,
1304
+ "learning_rate": 2.5171232876712333e-06,
1305
+ "loss": 4.1654,
1306
+ "step": 167
1307
+ },
1308
+ {
1309
+ "epoch": 0.17257318952234207,
1310
+ "grad_norm": 10.680136680603027,
1311
+ "learning_rate": 2.534246575342466e-06,
1312
+ "loss": 4.222,
1313
+ "step": 168
1314
+ },
1315
+ {
1316
+ "epoch": 0.17360041088854647,
1317
+ "grad_norm": 11.132901191711426,
1318
+ "learning_rate": 2.551369863013699e-06,
1319
+ "loss": 4.2832,
1320
+ "step": 169
1321
+ },
1322
+ {
1323
+ "epoch": 0.1746276322547509,
1324
+ "grad_norm": 10.849762916564941,
1325
+ "learning_rate": 2.568493150684932e-06,
1326
+ "loss": 4.2734,
1327
+ "step": 170
1328
+ },
1329
+ {
1330
+ "epoch": 0.1746276322547509,
1331
+ "eval_loss": 4.23046875,
1332
+ "eval_runtime": 8.1466,
1333
+ "eval_samples_per_second": 122.751,
1334
+ "eval_steps_per_second": 5.156,
1335
+ "step": 170
1336
+ },
1337
+ {
1338
+ "epoch": 0.17565485362095531,
1339
+ "grad_norm": 10.316183090209961,
1340
+ "learning_rate": 2.585616438356164e-06,
1341
+ "loss": 4.1986,
1342
+ "step": 171
1343
+ },
1344
+ {
1345
+ "epoch": 0.17668207498715974,
1346
+ "grad_norm": 10.631659507751465,
1347
+ "learning_rate": 2.6027397260273973e-06,
1348
+ "loss": 4.166,
1349
+ "step": 172
1350
+ },
1351
+ {
1352
+ "epoch": 0.17770929635336416,
1353
+ "grad_norm": 10.439342498779297,
1354
+ "learning_rate": 2.6198630136986303e-06,
1355
+ "loss": 4.2148,
1356
+ "step": 173
1357
+ },
1358
+ {
1359
+ "epoch": 0.17873651771956856,
1360
+ "grad_norm": 10.113866806030273,
1361
+ "learning_rate": 2.6369863013698634e-06,
1362
+ "loss": 4.1445,
1363
+ "step": 174
1364
+ },
1365
+ {
1366
+ "epoch": 0.17976373908577298,
1367
+ "grad_norm": 9.995186805725098,
1368
+ "learning_rate": 2.654109589041096e-06,
1369
+ "loss": 4.2269,
1370
+ "step": 175
1371
+ },
1372
+ {
1373
+ "epoch": 0.1807909604519774,
1374
+ "grad_norm": 10.036297798156738,
1375
+ "learning_rate": 2.671232876712329e-06,
1376
+ "loss": 4.224,
1377
+ "step": 176
1378
+ },
1379
+ {
1380
+ "epoch": 0.18181818181818182,
1381
+ "grad_norm": 10.111323356628418,
1382
+ "learning_rate": 2.688356164383562e-06,
1383
+ "loss": 4.1562,
1384
+ "step": 177
1385
+ },
1386
+ {
1387
+ "epoch": 0.18284540318438625,
1388
+ "grad_norm": 10.693925857543945,
1389
+ "learning_rate": 2.705479452054795e-06,
1390
+ "loss": 4.2617,
1391
+ "step": 178
1392
+ },
1393
+ {
1394
+ "epoch": 0.18387262455059064,
1395
+ "grad_norm": 10.322890281677246,
1396
+ "learning_rate": 2.7226027397260274e-06,
1397
+ "loss": 4.1016,
1398
+ "step": 179
1399
+ },
1400
+ {
1401
+ "epoch": 0.18489984591679506,
1402
+ "grad_norm": 10.171163558959961,
1403
+ "learning_rate": 2.7397260273972604e-06,
1404
+ "loss": 4.2878,
1405
+ "step": 180
1406
+ },
1407
+ {
1408
+ "epoch": 0.18489984591679506,
1409
+ "eval_loss": 4.203125,
1410
+ "eval_runtime": 8.1188,
1411
+ "eval_samples_per_second": 123.171,
1412
+ "eval_steps_per_second": 5.173,
1413
+ "step": 180
1414
+ },
1415
+ {
1416
+ "epoch": 0.1859270672829995,
1417
+ "grad_norm": 10.186366081237793,
1418
+ "learning_rate": 2.7568493150684935e-06,
1419
+ "loss": 4.2207,
1420
+ "step": 181
1421
+ },
1422
+ {
1423
+ "epoch": 0.1869542886492039,
1424
+ "grad_norm": 9.998559951782227,
1425
+ "learning_rate": 2.773972602739726e-06,
1426
+ "loss": 4.224,
1427
+ "step": 182
1428
+ },
1429
+ {
1430
+ "epoch": 0.18798151001540833,
1431
+ "grad_norm": 10.428750991821289,
1432
+ "learning_rate": 2.791095890410959e-06,
1433
+ "loss": 4.2266,
1434
+ "step": 183
1435
+ },
1436
+ {
1437
+ "epoch": 0.18900873138161273,
1438
+ "grad_norm": 10.26636791229248,
1439
+ "learning_rate": 2.8082191780821922e-06,
1440
+ "loss": 4.1309,
1441
+ "step": 184
1442
+ },
1443
+ {
1444
+ "epoch": 0.19003595274781715,
1445
+ "grad_norm": 9.86103630065918,
1446
+ "learning_rate": 2.8253424657534253e-06,
1447
+ "loss": 4.1169,
1448
+ "step": 185
1449
+ },
1450
+ {
1451
+ "epoch": 0.19106317411402157,
1452
+ "grad_norm": 9.904764175415039,
1453
+ "learning_rate": 2.842465753424658e-06,
1454
+ "loss": 4.1419,
1455
+ "step": 186
1456
+ },
1457
+ {
1458
+ "epoch": 0.192090395480226,
1459
+ "grad_norm": 9.750298500061035,
1460
+ "learning_rate": 2.8595890410958905e-06,
1461
+ "loss": 4.1335,
1462
+ "step": 187
1463
+ },
1464
+ {
1465
+ "epoch": 0.19311761684643042,
1466
+ "grad_norm": 10.10220718383789,
1467
+ "learning_rate": 2.876712328767123e-06,
1468
+ "loss": 4.1452,
1469
+ "step": 188
1470
+ },
1471
+ {
1472
+ "epoch": 0.1941448382126348,
1473
+ "grad_norm": 10.194372177124023,
1474
+ "learning_rate": 2.8938356164383562e-06,
1475
+ "loss": 4.1732,
1476
+ "step": 189
1477
+ },
1478
+ {
1479
+ "epoch": 0.19517205957883924,
1480
+ "grad_norm": 9.45039176940918,
1481
+ "learning_rate": 2.9109589041095893e-06,
1482
+ "loss": 4.124,
1483
+ "step": 190
1484
+ },
1485
+ {
1486
+ "epoch": 0.19517205957883924,
1487
+ "eval_loss": 4.1796875,
1488
+ "eval_runtime": 8.1489,
1489
+ "eval_samples_per_second": 122.715,
1490
+ "eval_steps_per_second": 5.154,
1491
+ "step": 190
1492
+ },
1493
+ {
1494
+ "epoch": 0.19619928094504366,
1495
+ "grad_norm": 9.065196990966797,
1496
+ "learning_rate": 2.9280821917808223e-06,
1497
+ "loss": 4.1689,
1498
+ "step": 191
1499
+ },
1500
+ {
1501
+ "epoch": 0.19722650231124808,
1502
+ "grad_norm": 8.964832305908203,
1503
+ "learning_rate": 2.945205479452055e-06,
1504
+ "loss": 4.1621,
1505
+ "step": 192
1506
+ },
1507
+ {
1508
+ "epoch": 0.1982537236774525,
1509
+ "grad_norm": 9.150090217590332,
1510
+ "learning_rate": 2.962328767123288e-06,
1511
+ "loss": 4.1302,
1512
+ "step": 193
1513
+ },
1514
+ {
1515
+ "epoch": 0.1992809450436569,
1516
+ "grad_norm": 9.464834213256836,
1517
+ "learning_rate": 2.979452054794521e-06,
1518
+ "loss": 4.1276,
1519
+ "step": 194
1520
+ },
1521
+ {
1522
+ "epoch": 0.20030816640986132,
1523
+ "grad_norm": 9.080924987792969,
1524
+ "learning_rate": 2.9965753424657533e-06,
1525
+ "loss": 4.0879,
1526
+ "step": 195
1527
+ },
1528
+ {
1529
+ "epoch": 0.20133538777606574,
1530
+ "grad_norm": 8.936680793762207,
1531
+ "learning_rate": 3.0136986301369864e-06,
1532
+ "loss": 4.1009,
1533
+ "step": 196
1534
+ },
1535
+ {
1536
+ "epoch": 0.20236260914227017,
1537
+ "grad_norm": 9.066742897033691,
1538
+ "learning_rate": 3.0308219178082194e-06,
1539
+ "loss": 4.1257,
1540
+ "step": 197
1541
+ },
1542
+ {
1543
+ "epoch": 0.2033898305084746,
1544
+ "grad_norm": 9.437700271606445,
1545
+ "learning_rate": 3.0479452054794525e-06,
1546
+ "loss": 4.1055,
1547
+ "step": 198
1548
+ },
1549
+ {
1550
+ "epoch": 0.20441705187467898,
1551
+ "grad_norm": 9.56484317779541,
1552
+ "learning_rate": 3.065068493150685e-06,
1553
+ "loss": 4.1836,
1554
+ "step": 199
1555
+ },
1556
+ {
1557
+ "epoch": 0.2054442732408834,
1558
+ "grad_norm": 9.032593727111816,
1559
+ "learning_rate": 3.082191780821918e-06,
1560
+ "loss": 4.0485,
1561
+ "step": 200
1562
+ },
1563
+ {
1564
+ "epoch": 0.2054442732408834,
1565
+ "eval_loss": 4.15625,
1566
+ "eval_runtime": 8.1569,
1567
+ "eval_samples_per_second": 122.595,
1568
+ "eval_steps_per_second": 5.149,
1569
+ "step": 200
1570
+ }
1571
+ ],
1572
+ "logging_steps": 1,
1573
+ "max_steps": 2919,
1574
+ "num_input_tokens_seen": 0,
1575
+ "num_train_epochs": 3,
1576
+ "save_steps": 100,
1577
+ "stateful_callbacks": {
1578
+ "TrainerControl": {
1579
+ "args": {
1580
+ "should_epoch_stop": false,
1581
+ "should_evaluate": false,
1582
+ "should_log": false,
1583
+ "should_save": true,
1584
+ "should_training_stop": false
1585
+ },
1586
+ "attributes": {}
1587
+ }
1588
+ },
1589
+ "total_flos": 1881302630400000.0,
1590
+ "train_batch_size": 3,
1591
+ "trial_name": null,
1592
+ "trial_params": null
1593
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-200/zero_to_fp32.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
215
+ exclude_frozen_parameters)
216
+ elif zero_stage == 3:
217
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
218
+ exclude_frozen_parameters)
219
+
220
+
221
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
222
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
223
+ return
224
+
225
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
226
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
227
+
228
+ if debug:
229
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
230
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
231
+
232
+ wanted_params = len(frozen_param_shapes)
233
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
234
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
235
+ print(f'Frozen params: Have {avail_numel} numels to process.')
236
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
237
+
238
+ total_params = 0
239
+ total_numel = 0
240
+ for name, shape in frozen_param_shapes.items():
241
+ total_params += 1
242
+ unpartitioned_numel = shape.numel()
243
+ total_numel += unpartitioned_numel
244
+
245
+ state_dict[name] = frozen_param_fragments[name]
246
+
247
+ if debug:
248
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
249
+
250
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
251
+
252
+
253
+ def _has_callable(obj, fn):
254
+ attr = getattr(obj, fn, None)
255
+ return callable(attr)
256
+
257
+
258
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
259
+ param_shapes = zero_model_states[0].param_shapes
260
+
261
+ # Reconstruction protocol:
262
+ #
263
+ # XXX: document this
264
+
265
+ if debug:
266
+ for i in range(world_size):
267
+ for j in range(len(fp32_flat_groups[0])):
268
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
269
+
270
+ # XXX: memory usage doubles here (zero2)
271
+ num_param_groups = len(fp32_flat_groups[0])
272
+ merged_single_partition_of_fp32_groups = []
273
+ for i in range(num_param_groups):
274
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
275
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
276
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
277
+ avail_numel = sum(
278
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
279
+
280
+ if debug:
281
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
282
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
283
+ # not asserting if there is a mismatch due to possible padding
284
+ print(f"Have {avail_numel} numels to process.")
285
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
286
+
287
+ # params
288
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
289
+ # out-of-core computing solution
290
+ total_numel = 0
291
+ total_params = 0
292
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
293
+ offset = 0
294
+ avail_numel = full_single_fp32_vector.numel()
295
+ for name, shape in shapes.items():
296
+
297
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
298
+ total_numel += unpartitioned_numel
299
+ total_params += 1
300
+
301
+ if debug:
302
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
303
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
304
+ offset += unpartitioned_numel
305
+
306
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
307
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
308
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
309
+ # live optimizer object, so we are checking that the numbers are within the right range
310
+ align_to = 2 * world_size
311
+
312
+ def zero2_align(x):
313
+ return align_to * math.ceil(x / align_to)
314
+
315
+ if debug:
316
+ print(f"original offset={offset}, avail_numel={avail_numel}")
317
+
318
+ offset = zero2_align(offset)
319
+ avail_numel = zero2_align(avail_numel)
320
+
321
+ if debug:
322
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
323
+
324
+ # Sanity check
325
+ if offset != avail_numel:
326
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
327
+
328
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
329
+
330
+
331
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
332
+ exclude_frozen_parameters):
333
+ state_dict = OrderedDict()
334
+
335
+ # buffers
336
+ buffers = zero_model_states[0].buffers
337
+ state_dict.update(buffers)
338
+ if debug:
339
+ print(f"added {len(buffers)} buffers")
340
+
341
+ if not exclude_frozen_parameters:
342
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
343
+
344
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
345
+
346
+ # recover shared parameters
347
+ for pair in zero_model_states[0].shared_params:
348
+ if pair[1] in state_dict:
349
+ state_dict[pair[0]] = state_dict[pair[1]]
350
+
351
+ return state_dict
352
+
353
+
354
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
355
+ remainder = unpartitioned_numel % world_size
356
+ padding_numel = (world_size - remainder) if remainder else 0
357
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
358
+ return partitioned_numel, padding_numel
359
+
360
+
361
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
362
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
363
+ return
364
+
365
+ if debug:
366
+ for i in range(world_size):
367
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
368
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
369
+
370
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
371
+ wanted_params = len(frozen_param_shapes)
372
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
373
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
374
+ print(f'Frozen params: Have {avail_numel} numels to process.')
375
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
376
+
377
+ total_params = 0
378
+ total_numel = 0
379
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
380
+ total_params += 1
381
+ unpartitioned_numel = shape.numel()
382
+ total_numel += unpartitioned_numel
383
+
384
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
385
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
386
+
387
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
388
+
389
+ if debug:
390
+ print(
391
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
392
+ )
393
+
394
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
395
+
396
+
397
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
398
+ param_shapes = zero_model_states[0].param_shapes
399
+ avail_numel = fp32_flat_groups[0].numel() * world_size
400
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
401
+ # param, re-consolidating each param, while dealing with padding if any
402
+
403
+ # merge list of dicts, preserving order
404
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
405
+
406
+ if debug:
407
+ for i in range(world_size):
408
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
409
+
410
+ wanted_params = len(param_shapes)
411
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
412
+ # not asserting if there is a mismatch due to possible padding
413
+ avail_numel = fp32_flat_groups[0].numel() * world_size
414
+ print(f"Trainable params: Have {avail_numel} numels to process.")
415
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
416
+
417
+ # params
418
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
419
+ # out-of-core computing solution
420
+ offset = 0
421
+ total_numel = 0
422
+ total_params = 0
423
+ for name, shape in param_shapes.items():
424
+
425
+ unpartitioned_numel = shape.numel()
426
+ total_numel += unpartitioned_numel
427
+ total_params += 1
428
+
429
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
430
+
431
+ if debug:
432
+ print(
433
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
434
+ )
435
+
436
+ # XXX: memory usage doubles here
437
+ state_dict[name] = torch.cat(
438
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
439
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
440
+ offset += partitioned_numel
441
+
442
+ offset *= world_size
443
+
444
+ # Sanity check
445
+ if offset != avail_numel:
446
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
447
+
448
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
449
+
450
+
451
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
452
+ exclude_frozen_parameters):
453
+ state_dict = OrderedDict()
454
+
455
+ # buffers
456
+ buffers = zero_model_states[0].buffers
457
+ state_dict.update(buffers)
458
+ if debug:
459
+ print(f"added {len(buffers)} buffers")
460
+
461
+ if not exclude_frozen_parameters:
462
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
463
+
464
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
465
+
466
+ # recover shared parameters
467
+ for pair in zero_model_states[0].shared_params:
468
+ if pair[1] in state_dict:
469
+ state_dict[pair[0]] = state_dict[pair[1]]
470
+
471
+ return state_dict
472
+
473
+
474
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
475
+ """
476
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
477
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
478
+ via a model hub.
479
+
480
+ Args:
481
+ - ``checkpoint_dir``: path to the desired checkpoint folder
482
+ - ``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``
483
+ - ``exclude_frozen_parameters``: exclude frozen parameters
484
+
485
+ Returns:
486
+ - pytorch ``state_dict``
487
+
488
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
489
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
490
+ the checkpoint.
491
+
492
+ A typical usage might be ::
493
+
494
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
495
+ # do the training and checkpoint saving
496
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
497
+ model = model.cpu() # move to cpu
498
+ model.load_state_dict(state_dict)
499
+ # submit to model hub or save the model to share with others
500
+
501
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
502
+ application. i.e. you will need to re-initialize the deepspeed engine, since
503
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
504
+
505
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
506
+
507
+ """
508
+ if tag is None:
509
+ latest_path = os.path.join(checkpoint_dir, 'latest')
510
+ if os.path.isfile(latest_path):
511
+ with open(latest_path, 'r') as fd:
512
+ tag = fd.read().strip()
513
+ else:
514
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
515
+
516
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
517
+
518
+ if not os.path.isdir(ds_checkpoint_dir):
519
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
520
+
521
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
522
+
523
+
524
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None, exclude_frozen_parameters=False):
525
+ """
526
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
527
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
528
+
529
+ Args:
530
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
531
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
532
+ - ``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``
533
+ - ``exclude_frozen_parameters``: exclude frozen parameters
534
+ """
535
+
536
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
537
+ print(f"Saving fp32 state dict to {output_file}")
538
+ torch.save(state_dict, output_file)
539
+
540
+
541
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
542
+ """
543
+ 1. Put the provided model to cpu
544
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
545
+ 3. Load it into the provided model
546
+
547
+ Args:
548
+ - ``model``: the model object to update
549
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
550
+ - ``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``
551
+
552
+ Returns:
553
+ - ``model`: modified model
554
+
555
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
556
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
557
+ conveniently placed for you in the checkpoint folder.
558
+
559
+ A typical usage might be ::
560
+
561
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
562
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
563
+ # submit to model hub or save the model to share with others
564
+
565
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
566
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
567
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
568
+
569
+ """
570
+ logger.info(f"Extracting fp32 weights")
571
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
572
+
573
+ logger.info(f"Overwriting model with fp32 weights")
574
+ model = model.cpu()
575
+ model.load_state_dict(state_dict, strict=False)
576
+
577
+ return model
578
+
579
+
580
+ if __name__ == "__main__":
581
+
582
+ parser = argparse.ArgumentParser()
583
+ parser.add_argument("checkpoint_dir",
584
+ type=str,
585
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
586
+ parser.add_argument(
587
+ "output_file",
588
+ type=str,
589
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
590
+ parser.add_argument("-t",
591
+ "--tag",
592
+ type=str,
593
+ default=None,
594
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
595
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
596
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
597
+ args = parser.parse_args()
598
+
599
+ debug = args.debug
600
+
601
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
602
+ args.output_file,
603
+ tag=args.tag,
604
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[PAD]": 50257,
3
+ "🅁": 50258
4
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.45.1",
37
+ "use_cache": true,
38
+ "vocab_size": 50257
39
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.45.1"
6
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step2000
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": {
5
+ "content": "[PAD]",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "unk_token": "<|endoftext|>"
12
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/tokenizer_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": "[PAD]",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "50258": {
21
+ "content": "🅁",
22
+ "lstrip": true,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ }
28
+ },
29
+ "bos_token": "<|endoftext|>",
30
+ "clean_up_tokenization_spaces": false,
31
+ "eos_token": "<|endoftext|>",
32
+ "model_max_length": 1024,
33
+ "pad_token": "[PAD]",
34
+ "tokenizer_class": "GPT2Tokenizer",
35
+ "unk_token": "<|endoftext|>"
36
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2000/zero_to_fp32.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example: python zero_to_fp32.py . pytorch_model.bin
14
+
15
+ import argparse
16
+ import torch
17
+ import glob
18
+ import math
19
+ import os
20
+ import re
21
+ from collections import OrderedDict
22
+ from dataclasses import dataclass
23
+
24
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
25
+ # DeepSpeed data structures it has to be available in the current python environment.
26
+ from deepspeed.utils import logger
27
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
28
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
29
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
30
+
31
+
32
+ @dataclass
33
+ class zero_model_state:
34
+ buffers: dict()
35
+ param_shapes: dict()
36
+ shared_params: list
37
+ ds_version: int
38
+ frozen_param_shapes: dict()
39
+ frozen_param_fragments: dict()
40
+
41
+
42
+ debug = 0
43
+
44
+ # load to cpu
45
+ device = torch.device('cpu')
46
+
47
+
48
+ def atoi(text):
49
+ return int(text) if text.isdigit() else text
50
+
51
+
52
+ def natural_keys(text):
53
+ '''
54
+ alist.sort(key=natural_keys) sorts in human order
55
+ http://nedbatchelder.com/blog/200712/human_sorting.html
56
+ (See Toothy's implementation in the comments)
57
+ '''
58
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
59
+
60
+
61
+ def get_model_state_file(checkpoint_dir, zero_stage):
62
+ if not os.path.isdir(checkpoint_dir):
63
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
64
+
65
+ # there should be only one file
66
+ if zero_stage <= 2:
67
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
68
+ elif zero_stage == 3:
69
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
70
+
71
+ if not os.path.exists(file):
72
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
73
+
74
+ return file
75
+
76
+
77
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
78
+ # XXX: need to test that this simple glob rule works for multi-node setup too
79
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
80
+
81
+ if len(ckpt_files) == 0:
82
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
83
+
84
+ return ckpt_files
85
+
86
+
87
+ def get_optim_files(checkpoint_dir):
88
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
89
+
90
+
91
+ def get_model_state_files(checkpoint_dir):
92
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
93
+
94
+
95
+ def parse_model_states(files):
96
+ zero_model_states = []
97
+ for file in files:
98
+ state_dict = torch.load(file, map_location=device)
99
+
100
+ if BUFFER_NAMES not in state_dict:
101
+ raise ValueError(f"{file} is not a model state checkpoint")
102
+ buffer_names = state_dict[BUFFER_NAMES]
103
+ if debug:
104
+ print("Found buffers:", buffer_names)
105
+
106
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
107
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
108
+ param_shapes = state_dict[PARAM_SHAPES]
109
+
110
+ # collect parameters that are included in param_shapes
111
+ param_names = []
112
+ for s in param_shapes:
113
+ for name in s.keys():
114
+ param_names.append(name)
115
+
116
+ # update with frozen parameters
117
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
118
+ if frozen_param_shapes is not None:
119
+ if debug:
120
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
121
+ param_names += list(frozen_param_shapes.keys())
122
+
123
+ # handle shared params
124
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
125
+
126
+ ds_version = state_dict.get(DS_VERSION, None)
127
+
128
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
129
+
130
+ z_model_state = zero_model_state(buffers=buffers,
131
+ param_shapes=param_shapes,
132
+ shared_params=shared_params,
133
+ ds_version=ds_version,
134
+ frozen_param_shapes=frozen_param_shapes,
135
+ frozen_param_fragments=frozen_param_fragments)
136
+ zero_model_states.append(z_model_state)
137
+
138
+ return zero_model_states
139
+
140
+
141
+ def parse_optim_states(files, ds_checkpoint_dir):
142
+
143
+ total_files = len(files)
144
+ state_dicts = []
145
+ for f in files:
146
+ state_dict = torch.load(f, map_location=device)
147
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
148
+ # and also handle the case where it was already removed by another helper script
149
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
150
+ state_dicts.append(state_dict)
151
+
152
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
153
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
154
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
155
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
156
+
157
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
158
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
159
+ # use the max of the partition_count to get the dp world_size.
160
+
161
+ if type(world_size) is list:
162
+ world_size = max(world_size)
163
+
164
+ if world_size != total_files:
165
+ raise ValueError(
166
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
167
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
168
+ )
169
+
170
+ # the groups are named differently in each stage
171
+ if zero_stage <= 2:
172
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
173
+ elif zero_stage == 3:
174
+ fp32_groups_key = FP32_FLAT_GROUPS
175
+ else:
176
+ raise ValueError(f"unknown zero stage {zero_stage}")
177
+
178
+ if zero_stage <= 2:
179
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
180
+ elif zero_stage == 3:
181
+ # if there is more than one param group, there will be multiple flattened tensors - one
182
+ # flattened tensor per group - for simplicity merge them into a single tensor
183
+ #
184
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
185
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
186
+
187
+ fp32_flat_groups = [
188
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
189
+ ]
190
+
191
+ return zero_stage, world_size, fp32_flat_groups
192
+
193
+
194
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
195
+ """
196
+ Returns fp32 state_dict reconstructed from ds checkpoint
197
+
198
+ Args:
199
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
200
+
201
+ """
202
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
203
+
204
+ optim_files = get_optim_files(ds_checkpoint_dir)
205
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
206
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
207
+
208
+ model_files = get_model_state_files(ds_checkpoint_dir)
209
+
210
+ zero_model_states = parse_model_states(model_files)
211
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
212
+
213
+ if zero_stage <= 2:
214
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
215
+ exclude_frozen_parameters)
216
+ elif zero_stage == 3:
217
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
218
+ exclude_frozen_parameters)
219
+
220
+
221
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
222
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
223
+ return
224
+
225
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
226
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
227
+
228
+ if debug:
229
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
230
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
231
+
232
+ wanted_params = len(frozen_param_shapes)
233
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
234
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
235
+ print(f'Frozen params: Have {avail_numel} numels to process.')
236
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
237
+
238
+ total_params = 0
239
+ total_numel = 0
240
+ for name, shape in frozen_param_shapes.items():
241
+ total_params += 1
242
+ unpartitioned_numel = shape.numel()
243
+ total_numel += unpartitioned_numel
244
+
245
+ state_dict[name] = frozen_param_fragments[name]
246
+
247
+ if debug:
248
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
249
+
250
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
251
+
252
+
253
+ def _has_callable(obj, fn):
254
+ attr = getattr(obj, fn, None)
255
+ return callable(attr)
256
+
257
+
258
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
259
+ param_shapes = zero_model_states[0].param_shapes
260
+
261
+ # Reconstruction protocol:
262
+ #
263
+ # XXX: document this
264
+
265
+ if debug:
266
+ for i in range(world_size):
267
+ for j in range(len(fp32_flat_groups[0])):
268
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
269
+
270
+ # XXX: memory usage doubles here (zero2)
271
+ num_param_groups = len(fp32_flat_groups[0])
272
+ merged_single_partition_of_fp32_groups = []
273
+ for i in range(num_param_groups):
274
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
275
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
276
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
277
+ avail_numel = sum(
278
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
279
+
280
+ if debug:
281
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
282
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
283
+ # not asserting if there is a mismatch due to possible padding
284
+ print(f"Have {avail_numel} numels to process.")
285
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
286
+
287
+ # params
288
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
289
+ # out-of-core computing solution
290
+ total_numel = 0
291
+ total_params = 0
292
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
293
+ offset = 0
294
+ avail_numel = full_single_fp32_vector.numel()
295
+ for name, shape in shapes.items():
296
+
297
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
298
+ total_numel += unpartitioned_numel
299
+ total_params += 1
300
+
301
+ if debug:
302
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
303
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
304
+ offset += unpartitioned_numel
305
+
306
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
307
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
308
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
309
+ # live optimizer object, so we are checking that the numbers are within the right range
310
+ align_to = 2 * world_size
311
+
312
+ def zero2_align(x):
313
+ return align_to * math.ceil(x / align_to)
314
+
315
+ if debug:
316
+ print(f"original offset={offset}, avail_numel={avail_numel}")
317
+
318
+ offset = zero2_align(offset)
319
+ avail_numel = zero2_align(avail_numel)
320
+
321
+ if debug:
322
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
323
+
324
+ # Sanity check
325
+ if offset != avail_numel:
326
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
327
+
328
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
329
+
330
+
331
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
332
+ exclude_frozen_parameters):
333
+ state_dict = OrderedDict()
334
+
335
+ # buffers
336
+ buffers = zero_model_states[0].buffers
337
+ state_dict.update(buffers)
338
+ if debug:
339
+ print(f"added {len(buffers)} buffers")
340
+
341
+ if not exclude_frozen_parameters:
342
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
343
+
344
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
345
+
346
+ # recover shared parameters
347
+ for pair in zero_model_states[0].shared_params:
348
+ if pair[1] in state_dict:
349
+ state_dict[pair[0]] = state_dict[pair[1]]
350
+
351
+ return state_dict
352
+
353
+
354
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
355
+ remainder = unpartitioned_numel % world_size
356
+ padding_numel = (world_size - remainder) if remainder else 0
357
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
358
+ return partitioned_numel, padding_numel
359
+
360
+
361
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
362
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
363
+ return
364
+
365
+ if debug:
366
+ for i in range(world_size):
367
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
368
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
369
+
370
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
371
+ wanted_params = len(frozen_param_shapes)
372
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
373
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
374
+ print(f'Frozen params: Have {avail_numel} numels to process.')
375
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
376
+
377
+ total_params = 0
378
+ total_numel = 0
379
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
380
+ total_params += 1
381
+ unpartitioned_numel = shape.numel()
382
+ total_numel += unpartitioned_numel
383
+
384
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
385
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
386
+
387
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
388
+
389
+ if debug:
390
+ print(
391
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
392
+ )
393
+
394
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
395
+
396
+
397
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
398
+ param_shapes = zero_model_states[0].param_shapes
399
+ avail_numel = fp32_flat_groups[0].numel() * world_size
400
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
401
+ # param, re-consolidating each param, while dealing with padding if any
402
+
403
+ # merge list of dicts, preserving order
404
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
405
+
406
+ if debug:
407
+ for i in range(world_size):
408
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
409
+
410
+ wanted_params = len(param_shapes)
411
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
412
+ # not asserting if there is a mismatch due to possible padding
413
+ avail_numel = fp32_flat_groups[0].numel() * world_size
414
+ print(f"Trainable params: Have {avail_numel} numels to process.")
415
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
416
+
417
+ # params
418
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
419
+ # out-of-core computing solution
420
+ offset = 0
421
+ total_numel = 0
422
+ total_params = 0
423
+ for name, shape in param_shapes.items():
424
+
425
+ unpartitioned_numel = shape.numel()
426
+ total_numel += unpartitioned_numel
427
+ total_params += 1
428
+
429
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
430
+
431
+ if debug:
432
+ print(
433
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
434
+ )
435
+
436
+ # XXX: memory usage doubles here
437
+ state_dict[name] = torch.cat(
438
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
439
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
440
+ offset += partitioned_numel
441
+
442
+ offset *= world_size
443
+
444
+ # Sanity check
445
+ if offset != avail_numel:
446
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
447
+
448
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
449
+
450
+
451
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
452
+ exclude_frozen_parameters):
453
+ state_dict = OrderedDict()
454
+
455
+ # buffers
456
+ buffers = zero_model_states[0].buffers
457
+ state_dict.update(buffers)
458
+ if debug:
459
+ print(f"added {len(buffers)} buffers")
460
+
461
+ if not exclude_frozen_parameters:
462
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
463
+
464
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
465
+
466
+ # recover shared parameters
467
+ for pair in zero_model_states[0].shared_params:
468
+ if pair[1] in state_dict:
469
+ state_dict[pair[0]] = state_dict[pair[1]]
470
+
471
+ return state_dict
472
+
473
+
474
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None, exclude_frozen_parameters=False):
475
+ """
476
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
477
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
478
+ via a model hub.
479
+
480
+ Args:
481
+ - ``checkpoint_dir``: path to the desired checkpoint folder
482
+ - ``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``
483
+ - ``exclude_frozen_parameters``: exclude frozen parameters
484
+
485
+ Returns:
486
+ - pytorch ``state_dict``
487
+
488
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
489
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
490
+ the checkpoint.
491
+
492
+ A typical usage might be ::
493
+
494
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
495
+ # do the training and checkpoint saving
496
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
497
+ model = model.cpu() # move to cpu
498
+ model.load_state_dict(state_dict)
499
+ # submit to model hub or save the model to share with others
500
+
501
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
502
+ application. i.e. you will need to re-initialize the deepspeed engine, since
503
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
504
+
505
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
506
+
507
+ """
508
+ if tag is None:
509
+ latest_path = os.path.join(checkpoint_dir, 'latest')
510
+ if os.path.isfile(latest_path):
511
+ with open(latest_path, 'r') as fd:
512
+ tag = fd.read().strip()
513
+ else:
514
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
515
+
516
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
517
+
518
+ if not os.path.isdir(ds_checkpoint_dir):
519
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
520
+
521
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
522
+
523
+
524
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None, exclude_frozen_parameters=False):
525
+ """
526
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
527
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
528
+
529
+ Args:
530
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
531
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
532
+ - ``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``
533
+ - ``exclude_frozen_parameters``: exclude frozen parameters
534
+ """
535
+
536
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag, exclude_frozen_parameters)
537
+ print(f"Saving fp32 state dict to {output_file}")
538
+ torch.save(state_dict, output_file)
539
+
540
+
541
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
542
+ """
543
+ 1. Put the provided model to cpu
544
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
545
+ 3. Load it into the provided model
546
+
547
+ Args:
548
+ - ``model``: the model object to update
549
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
550
+ - ``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``
551
+
552
+ Returns:
553
+ - ``model`: modified model
554
+
555
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
556
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
557
+ conveniently placed for you in the checkpoint folder.
558
+
559
+ A typical usage might be ::
560
+
561
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
562
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
563
+ # submit to model hub or save the model to share with others
564
+
565
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
566
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
567
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
568
+
569
+ """
570
+ logger.info(f"Extracting fp32 weights")
571
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
572
+
573
+ logger.info(f"Overwriting model with fp32 weights")
574
+ model = model.cpu()
575
+ model.load_state_dict(state_dict, strict=False)
576
+
577
+ return model
578
+
579
+
580
+ if __name__ == "__main__":
581
+
582
+ parser = argparse.ArgumentParser()
583
+ parser.add_argument("checkpoint_dir",
584
+ type=str,
585
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
586
+ parser.add_argument(
587
+ "output_file",
588
+ type=str,
589
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
590
+ parser.add_argument("-t",
591
+ "--tag",
592
+ type=str,
593
+ default=None,
594
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
595
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
596
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
597
+ args = parser.parse_args()
598
+
599
+ debug = args.debug
600
+
601
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
602
+ args.output_file,
603
+ tag=args.tag,
604
+ exclude_frozen_parameters=args.exclude_frozen_parameters)
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[PAD]": 50257,
3
+ "🅁": 50258
4
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "gpt2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.45.1",
37
+ "use_cache": true,
38
+ "vocab_size": 50257
39
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.45.1"
6
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step2800
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": {
5
+ "content": "[PAD]",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "unk_token": "<|endoftext|>"
12
+ }
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoints/GPT-2/babylm_reverse_control_10M_seed0/runs/checkpoint-2800/tokenizer_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": "[PAD]",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "50258": {
21
+ "content": "🅁",
22
+ "lstrip": true,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ }
28
+ },
29
+ "bos_token": "<|endoftext|>",
30
+ "clean_up_tokenization_spaces": false,
31
+ "eos_token": "<|endoftext|>",
32
+ "model_max_length": 1024,
33
+ "pad_token": "[PAD]",
34
+ "tokenizer_class": "GPT2Tokenizer",
35
+ "unk_token": "<|endoftext|>"
36
+ }