calihyper commited on
Commit
26e5869
1 Parent(s): f72ca28
checkpoint-18000/latest ADDED
@@ -0,0 +1 @@
 
 
1
+ pytorch_model
checkpoint-18000/pytorch_model/mp_rank_00_model_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1dc19e5d62c370f2bcf910e499cbdf88ada08dd9b97cdfd6ace7671361de8ca8
3
+ size 1445217691
checkpoint-18000/pytorch_model/zero_pp_rank_0_mp_rank_00_optim_states.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4019b7ee07078d97b8d87e3da9e476600dc8b82ad31ab3492ac2526a0b0a097
3
+ size 4335381997
checkpoint-18000/random_states_0.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b8c27e48e6b3c60d6df56f66e5f925d408a927be5415a8568d52c1b712741249
3
+ size 14727
checkpoint-18000/scheduler.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31a81cc678ca117e8d93df67c5439b52214da903413ecbe7e0b2e7472e33033f
3
+ size 563
checkpoint-18000/zero_to_fp32.py ADDED
@@ -0,0 +1,461 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
+
23
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
24
+ # DeepSpeed data structures it has to be available in the current python environment.
25
+ from deepspeed.utils import logger
26
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
27
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES)
28
+
29
+ debug = 0
30
+
31
+ # load to cpu
32
+ device = torch.device('cpu')
33
+
34
+
35
+ def atoi(text):
36
+ return int(text) if text.isdigit() else text
37
+
38
+
39
+ def natural_keys(text):
40
+ '''
41
+ alist.sort(key=natural_keys) sorts in human order
42
+ http://nedbatchelder.com/blog/200712/human_sorting.html
43
+ (See Toothy's implementation in the comments)
44
+ '''
45
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
46
+
47
+
48
+ def get_model_state_file(checkpoint_dir, zero_stage):
49
+ if not os.path.isdir(checkpoint_dir):
50
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
51
+
52
+ # there should be only one file
53
+ if zero_stage == 2:
54
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
55
+ elif zero_stage == 3:
56
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
57
+
58
+ if not os.path.exists(file):
59
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
60
+
61
+ return file
62
+
63
+
64
+ def get_optim_files(checkpoint_dir):
65
+ # XXX: need to test that this simple glob rule works for multi-node setup too
66
+ optim_files = sorted(glob.glob(os.path.join(checkpoint_dir, "*_optim_states.pt")), key=natural_keys)
67
+
68
+ if len(optim_files) == 0:
69
+ raise FileNotFoundError(f"can't find '*_optim_states.pt' files in directory '{checkpoint_dir}'")
70
+
71
+ return optim_files
72
+
73
+
74
+ def parse_model_state(file):
75
+ state_dict = torch.load(file, map_location=device)
76
+
77
+ if BUFFER_NAMES not in state_dict:
78
+ raise ValueError(f"{file} is not a model state checkpoint")
79
+ buffer_names = state_dict[BUFFER_NAMES]
80
+ if debug:
81
+ print("Found buffers:", buffer_names)
82
+
83
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
84
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
85
+ param_shapes = state_dict[PARAM_SHAPES]
86
+
87
+ # collect parameters that are included in param_shapes
88
+ param_names = []
89
+ for s in param_shapes:
90
+ for name in s.keys():
91
+ param_names.append(name)
92
+
93
+ # record shared parameters so that they can be recovered based on partners
94
+ # this is because such parameters holding reference only are not saved by optimizer
95
+ shared_params = []
96
+ for param in state_dict["module"]:
97
+ if param not in [*param_names, *buffer_names]:
98
+ for share_param in state_dict["module"]:
99
+ if (state_dict["module"][share_param].data_ptr() == state_dict["module"][param].data_ptr()
100
+ and share_param != param):
101
+ shared_params.append([param, share_param])
102
+ break
103
+
104
+ ds_version = state_dict.get(DS_VERSION, None)
105
+
106
+ return buffers, param_shapes, shared_params, ds_version
107
+
108
+
109
+ def parse_optim_states(files, ds_checkpoint_dir):
110
+
111
+ total_files = len(files)
112
+ state_dicts = []
113
+ for f in files:
114
+ state_dicts.append(torch.load(f, map_location=device))
115
+
116
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
117
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
118
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
119
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
120
+
121
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
122
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
123
+ # use the max of the partition_count to get the dp world_size.
124
+
125
+ if type(world_size) is list:
126
+ world_size = max(world_size)
127
+
128
+ if world_size != total_files:
129
+ raise ValueError(
130
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
131
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
132
+ )
133
+
134
+ # the groups are named differently in each stage
135
+ if zero_stage == 2:
136
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
137
+ elif zero_stage == 3:
138
+ fp32_groups_key = FP32_FLAT_GROUPS
139
+ else:
140
+ raise ValueError(f"unknown zero stage {zero_stage}")
141
+
142
+ if zero_stage == 2:
143
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
144
+ elif zero_stage == 3:
145
+ # if there is more than one param group, there will be multiple flattened tensors - one
146
+ # flattened tensor per group - for simplicity merge them into a single tensor
147
+ #
148
+ # XXX: could make the script more memory efficient for when there are multiple groups - it
149
+ # will require matching the sub-lists of param_shapes for each param group flattened tensor
150
+
151
+ fp32_flat_groups = [
152
+ torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
153
+ ]
154
+
155
+ return zero_stage, world_size, fp32_flat_groups
156
+
157
+
158
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
159
+ """
160
+ Returns fp32 state_dict reconstructed from ds checkpoint
161
+
162
+ Args:
163
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
164
+
165
+ """
166
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
167
+
168
+ optim_files = get_optim_files(ds_checkpoint_dir)
169
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
170
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
171
+
172
+ model_file = get_model_state_file(ds_checkpoint_dir, zero_stage)
173
+ buffers, param_shapes, shared_params, ds_version = parse_model_state(model_file)
174
+ print(f'Parsing checkpoint created by deepspeed=={ds_version}')
175
+
176
+ if zero_stage == 2:
177
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, param_shapes, fp32_flat_groups, buffers,
178
+ shared_params)
179
+ elif zero_stage == 3:
180
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, param_shapes, fp32_flat_groups, buffers,
181
+ shared_params)
182
+
183
+
184
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, param_shapes, fp32_flat_groups, buffers, shared_params):
185
+
186
+ # Reconstruction protocol:
187
+ #
188
+ # XXX: document this
189
+
190
+ if debug:
191
+ for i in range(world_size):
192
+ for j in range(len(fp32_flat_groups[0])):
193
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
194
+
195
+ # XXX: memory usage doubles here (zero2)
196
+ num_param_groups = len(fp32_flat_groups[0])
197
+ merged_single_partition_of_fp32_groups = []
198
+ for i in range(num_param_groups):
199
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
200
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
201
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
202
+ avail_numel = sum(
203
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
204
+
205
+ if debug:
206
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
207
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
208
+ # not asserting if there is a mismatch due to possible padding
209
+ print(f"Have {avail_numel} numels to process.")
210
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
211
+
212
+ state_dict = OrderedDict()
213
+
214
+ # buffers
215
+ state_dict.update(buffers)
216
+ if debug:
217
+ print(f"added {len(buffers)} buffers")
218
+
219
+ # params
220
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
221
+ # out-of-core computing solution
222
+ total_numel = 0
223
+ total_params = 0
224
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
225
+ offset = 0
226
+ avail_numel = full_single_fp32_vector.numel()
227
+ for name, shape in shapes.items():
228
+
229
+ unpartitioned_numel = shape.numel()
230
+ total_numel += unpartitioned_numel
231
+ total_params += 1
232
+
233
+ if debug:
234
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
235
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
236
+ offset += unpartitioned_numel
237
+
238
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
239
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
240
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
241
+ # live optimizer object, so we are checking that the numbers are within the right range
242
+ align_to = 2 * world_size
243
+
244
+ def zero2_align(x):
245
+ return align_to * math.ceil(x / align_to)
246
+
247
+ if debug:
248
+ print(f"original offset={offset}, avail_numel={avail_numel}")
249
+
250
+ offset = zero2_align(offset)
251
+ avail_numel = zero2_align(avail_numel)
252
+
253
+ if debug:
254
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
255
+
256
+ # Sanity check
257
+ if offset != avail_numel:
258
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
259
+
260
+ # recover shared parameters
261
+ for pair in shared_params:
262
+ state_dict[pair[0]] = state_dict[pair[1]]
263
+
264
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
265
+
266
+ return state_dict
267
+
268
+
269
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
270
+ remainder = unpartitioned_numel % world_size
271
+ padding_numel = (world_size - remainder) if remainder else 0
272
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
273
+ return partitioned_numel, padding_numel
274
+
275
+
276
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, param_shapes, fp32_flat_groups, buffers, shared_params):
277
+
278
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
279
+ # param, re-consolidating each param, while dealing with padding if any
280
+
281
+ avail_numel = fp32_flat_groups[0].numel() * world_size
282
+ # merge list of dicts, preserving order
283
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
284
+
285
+ if debug:
286
+ for i in range(world_size):
287
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
288
+
289
+ wanted_params = len(param_shapes)
290
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
291
+ # not asserting if there is a mismatch due to possible padding
292
+ print(f"Have {avail_numel} numels to process.")
293
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
294
+
295
+ state_dict = OrderedDict()
296
+
297
+ # buffers
298
+ state_dict.update(buffers)
299
+ if debug:
300
+ print(f"added {len(buffers)} buffers")
301
+
302
+ # params
303
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
304
+ # out-of-core computing solution
305
+ offset = 0
306
+ total_numel = 0
307
+ total_params = 0
308
+ for name, shape in param_shapes.items():
309
+
310
+ unpartitioned_numel = shape.numel()
311
+ total_numel += unpartitioned_numel
312
+ total_params += 1
313
+
314
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
315
+
316
+ if debug:
317
+ print(
318
+ f"{total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
319
+ )
320
+
321
+ # XXX: memory usage doubles here
322
+ state_dict[name] = torch.cat(
323
+ tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
324
+ 0).narrow(0, 0, unpartitioned_numel).view(shape)
325
+ offset += partitioned_numel
326
+
327
+ offset *= world_size
328
+
329
+ # Sanity check
330
+ if offset != avail_numel:
331
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
332
+
333
+ # recover shared parameters
334
+ for pair in shared_params:
335
+ state_dict[pair[0]] = state_dict[pair[1]]
336
+
337
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
338
+
339
+ return state_dict
340
+
341
+
342
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
343
+ """
344
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
345
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
346
+ via a model hub.
347
+
348
+ Args:
349
+ - ``checkpoint_dir``: path to the desired checkpoint folder
350
+ - ``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``
351
+
352
+ Returns:
353
+ - pytorch ``state_dict``
354
+
355
+ Note: this approach may not work if your application doesn't have sufficient free CPU memory and
356
+ you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
357
+ the checkpoint.
358
+
359
+ A typical usage might be ::
360
+
361
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
362
+ # do the training and checkpoint saving
363
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
364
+ model = model.cpu() # move to cpu
365
+ model.load_state_dict(state_dict)
366
+ # submit to model hub or save the model to share with others
367
+
368
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
369
+ application. i.e. you will need to re-initialize the deepspeed engine, since
370
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
371
+
372
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
373
+
374
+ """
375
+ if tag is None:
376
+ latest_path = os.path.join(checkpoint_dir, 'latest')
377
+ if os.path.isfile(latest_path):
378
+ with open(latest_path, 'r') as fd:
379
+ tag = fd.read().strip()
380
+ else:
381
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
382
+
383
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
384
+
385
+ if not os.path.isdir(ds_checkpoint_dir):
386
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
387
+
388
+ return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
389
+
390
+
391
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
392
+ """
393
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
394
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
395
+
396
+ Args:
397
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
398
+ - ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
399
+ - ``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``
400
+ """
401
+
402
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
403
+ print(f"Saving fp32 state dict to {output_file}")
404
+ torch.save(state_dict, output_file)
405
+
406
+
407
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
408
+ """
409
+ 1. Put the provided model to cpu
410
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
411
+ 3. Load it into the provided model
412
+
413
+ Args:
414
+ - ``model``: the model object to update
415
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
416
+ - ``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``
417
+
418
+ Returns:
419
+ - ``model`: modified model
420
+
421
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
422
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
423
+ conveniently placed for you in the checkpoint folder.
424
+
425
+ A typical usage might be ::
426
+
427
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
428
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
429
+ # submit to model hub or save the model to share with others
430
+
431
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
432
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
433
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
434
+
435
+ """
436
+ logger.info(f"Extracting fp32 weights")
437
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
438
+
439
+ logger.info(f"Overwriting model with fp32 weights")
440
+ model = model.cpu()
441
+ model.load_state_dict(state_dict, strict=False)
442
+
443
+ return model
444
+
445
+
446
+ if __name__ == "__main__":
447
+
448
+ parser = argparse.ArgumentParser()
449
+ parser.add_argument("checkpoint_dir",
450
+ type=str,
451
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
452
+ parser.add_argument(
453
+ "output_file",
454
+ type=str,
455
+ help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
456
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
457
+ args = parser.parse_args()
458
+
459
+ debug = args.debug
460
+
461
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "ControlNetModel",
3
+ "_diffusers_version": "0.15.0.dev0",
4
+ "act_fn": "silu",
5
+ "attention_head_dim": 8,
6
+ "block_out_channels": [
7
+ 320,
8
+ 640,
9
+ 1280,
10
+ 1280
11
+ ],
12
+ "class_embed_type": null,
13
+ "conditioning_embedding_out_channels": [
14
+ 16,
15
+ 32,
16
+ 96,
17
+ 256
18
+ ],
19
+ "controlnet_conditioning_channel_order": "rgb",
20
+ "cross_attention_dim": 768,
21
+ "down_block_types": [
22
+ "CrossAttnDownBlock2D",
23
+ "CrossAttnDownBlock2D",
24
+ "CrossAttnDownBlock2D",
25
+ "DownBlock2D"
26
+ ],
27
+ "downsample_padding": 1,
28
+ "flip_sin_to_cos": true,
29
+ "freq_shift": 0,
30
+ "in_channels": 4,
31
+ "layers_per_block": 2,
32
+ "mid_block_scale_factor": 1,
33
+ "norm_eps": 1e-05,
34
+ "norm_num_groups": 32,
35
+ "num_class_embeds": null,
36
+ "only_cross_attention": false,
37
+ "projection_class_embeddings_input_dim": null,
38
+ "resnet_time_scale_shift": "default",
39
+ "upcast_attention": false,
40
+ "use_linear_projection": false
41
+ }
diffusion_pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fffe223b1a7f3b3b9a2b3a8b9056de51f6ab00b11577ae784a2e2710cfe98db
3
+ size 1445187803
logs/test/1683140389.8742607/events.out.tfevents.1683140389.aiffel-online02-hypeboy.8332.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ae93266498484467120af01cdbc5dc6dc779694b0e43e8e20ba2c3872fe90e6
3
+ size 2270
logs/test/1683140389.8757253/hparams.yml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ adam_beta1: 0.9
2
+ adam_beta2: 0.999
3
+ adam_epsilon: 1.0e-08
4
+ adam_weight_decay: 0.01
5
+ allow_tf32: false
6
+ cache_dir: null
7
+ caption_column: text
8
+ checkpointing_steps: 500
9
+ checkpoints_total_limit: null
10
+ conditioning_image_column: conditioning_image
11
+ controlnet_model_name_or_path: null
12
+ dataloader_num_workers: 0
13
+ dataset_config_name: null
14
+ dataset_name: null
15
+ enable_xformers_memory_efficient_attention: true
16
+ gradient_accumulation_steps: 4
17
+ gradient_checkpointing: true
18
+ hub_model_id: null
19
+ hub_token: null
20
+ image_column: image
21
+ learning_rate: 1.0e-05
22
+ logging_dir: logs
23
+ lr_num_cycles: 1
24
+ lr_power: 1.0
25
+ lr_scheduler: constant
26
+ lr_warmup_steps: 500
27
+ max_grad_norm: 1.0
28
+ max_train_samples: null
29
+ max_train_steps: 9000
30
+ mixed_precision: null
31
+ num_train_epochs: 3000
32
+ num_validation_images: 4
33
+ output_dir: ./checkpoint
34
+ pretrained_model_name_or_path: runwayml/stable-diffusion-v1-5
35
+ proportion_empty_prompts: 0
36
+ push_to_hub: false
37
+ report_to: tensorboard
38
+ resolution: 512
39
+ resume_from_checkpoint: null
40
+ revision: null
41
+ scale_lr: false
42
+ seed: null
43
+ set_grads_to_none: true
44
+ tokenizer_name: null
45
+ tracker_project_name: test
46
+ train_batch_size: 8
47
+ train_data_dir: ./total_dataset/
48
+ use_8bit_adam: false
49
+ validation_steps: 100
logs/test/1683140866.7593164/events.out.tfevents.1683140866.aiffel-online02-hypeboy.8486.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f915c4a97c6254e4117ec76cd3bb91d5c2f9c199f626d66ca48568a0a9a92a85
3
+ size 2269
logs/test/1683140866.7608616/hparams.yml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ adam_beta1: 0.9
2
+ adam_beta2: 0.999
3
+ adam_epsilon: 1.0e-08
4
+ adam_weight_decay: 0.01
5
+ allow_tf32: false
6
+ cache_dir: null
7
+ caption_column: text
8
+ checkpointing_steps: 1000
9
+ checkpoints_total_limit: null
10
+ conditioning_image_column: conditioning_image
11
+ controlnet_model_name_or_path: null
12
+ dataloader_num_workers: 0
13
+ dataset_config_name: null
14
+ dataset_name: null
15
+ enable_xformers_memory_efficient_attention: true
16
+ gradient_accumulation_steps: 4
17
+ gradient_checkpointing: true
18
+ hub_model_id: null
19
+ hub_token: null
20
+ image_column: image
21
+ learning_rate: 1.0e-05
22
+ logging_dir: logs
23
+ lr_num_cycles: 1
24
+ lr_power: 1.0
25
+ lr_scheduler: constant
26
+ lr_warmup_steps: 500
27
+ max_grad_norm: 1.0
28
+ max_train_samples: null
29
+ max_train_steps: 18000
30
+ mixed_precision: null
31
+ num_train_epochs: 3000
32
+ num_validation_images: 4
33
+ output_dir: ./checkpoint
34
+ pretrained_model_name_or_path: runwayml/stable-diffusion-v1-5
35
+ proportion_empty_prompts: 0
36
+ push_to_hub: false
37
+ report_to: tensorboard
38
+ resolution: 512
39
+ resume_from_checkpoint: null
40
+ revision: null
41
+ scale_lr: false
42
+ seed: null
43
+ set_grads_to_none: true
44
+ tokenizer_name: null
45
+ tracker_project_name: test
46
+ train_batch_size: 8
47
+ train_data_dir: ./total_dataset
48
+ use_8bit_adam: false
49
+ validation_steps: 100
logs/test/1683140951.62638/events.out.tfevents.1683140951.aiffel-online02-hypeboy.8583.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33a9217217a348150ca365f5ce2c39658833b1c38c7fb824871dd565736a0cc2
3
+ size 2269
logs/test/1683140951.6278543/hparams.yml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ adam_beta1: 0.9
2
+ adam_beta2: 0.999
3
+ adam_epsilon: 1.0e-08
4
+ adam_weight_decay: 0.01
5
+ allow_tf32: false
6
+ cache_dir: null
7
+ caption_column: text
8
+ checkpointing_steps: 18000
9
+ checkpoints_total_limit: null
10
+ conditioning_image_column: conditioning_image
11
+ controlnet_model_name_or_path: null
12
+ dataloader_num_workers: 0
13
+ dataset_config_name: null
14
+ dataset_name: null
15
+ enable_xformers_memory_efficient_attention: true
16
+ gradient_accumulation_steps: 4
17
+ gradient_checkpointing: true
18
+ hub_model_id: null
19
+ hub_token: null
20
+ image_column: image
21
+ learning_rate: 1.0e-05
22
+ logging_dir: logs
23
+ lr_num_cycles: 1
24
+ lr_power: 1.0
25
+ lr_scheduler: constant
26
+ lr_warmup_steps: 500
27
+ max_grad_norm: 1.0
28
+ max_train_samples: null
29
+ max_train_steps: 18000
30
+ mixed_precision: null
31
+ num_train_epochs: 3000
32
+ num_validation_images: 4
33
+ output_dir: ./checkpoint
34
+ pretrained_model_name_or_path: runwayml/stable-diffusion-v1-5
35
+ proportion_empty_prompts: 0
36
+ push_to_hub: false
37
+ report_to: tensorboard
38
+ resolution: 512
39
+ resume_from_checkpoint: null
40
+ revision: null
41
+ scale_lr: false
42
+ seed: null
43
+ set_grads_to_none: true
44
+ tokenizer_name: null
45
+ tracker_project_name: test
46
+ train_batch_size: 8
47
+ train_data_dir: ./total_dataset
48
+ use_8bit_adam: false
49
+ validation_steps: 100
logs/test/events.out.tfevents.1683140389.aiffel-online02-hypeboy.8332.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5902043a26ef3298ce56e8e011e35e9f8030ba14c7515be4ce43eee437e15d2c
3
+ size 908
logs/test/events.out.tfevents.1683140866.aiffel-online02-hypeboy.8486.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95ed59755ba9b9a76f6510831d0ba94d4f8d2a93b1cdaff5029a0a28935aae38
3
+ size 2220
logs/test/events.out.tfevents.1683140951.aiffel-online02-hypeboy.8583.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d31a0e89863651c941c4fe51b40e443a5d1af134dfc39aaf757ab621190f08d8
3
+ size 1699280