You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
660
+
Convert ZeRO 2 or 3 checkpoint into a consolidated ``state_dict`` file that can be
636
661
loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
637
662
638
663
Args:
639
664
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
640
-
- ``output_dir``: directory to the pytorch fp32 state_dict output files
665
+
- ``output_dir``: directory for the PyTorch state_dict output files
666
+
- ``dtype``: output tensor dtype. Supports float32, float16, and bfloat16 as strings or torch dtypes.
641
667
- ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
642
668
- ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
643
669
- ``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``
The conversion reconstructs the ZeRO master weights in fp32, casts each output
294
+
shard immediately before it is saved, and plans shard sizes using the selected
295
+
dtype. Shared parameters remain shared in the exported state dict. The same
296
+
functionality is available from Python:
297
+
298
+
```python
299
+
import torch
300
+
from deepspeed.utils.zero_to_fp32 import convert_zero_checkpoint_to_state_dict
301
+
302
+
convert_zero_checkpoint_to_state_dict(
303
+
checkpoint_dir,
304
+
output_dir,
305
+
dtype=torch.bfloat16,
306
+
)
307
+
```
308
+
309
+
Questions and maintenance: [@gaoxiaomo](https://github.com/gaoxiaomo).
310
+
311
+
Note: fp32 conversion currently uses about 2x the final checkpoint size in CPU
312
+
memory. Lower-precision export still reconstructs the fp32 master weights, so
313
+
its peak memory is larger than 2x the final fp16/bf16 checkpoint size.
286
314
{: .notice--info}
287
315
288
316
Alternatively, if you have plenty of spare CPU memory and instead of getting the file you want your model to be updated to its fp32 weights, you can do the following at the end of the training:
0 commit comments