Shortcuts

deepspeed

Functions

convert_zero_checkpoint_to_fp32_state_dict

Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict file that can be loaded with torch.load(file) + load_state_dict() and used for training without DeepSpeed.

ds_checkpoint_dir

rtype

str

Utilities that can be used with Deepspeed.

pytorch_lightning.utilities.deepspeed.convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None)[source]

Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict file that can be loaded with torch.load(file) + load_state_dict() and used for training without DeepSpeed. It gets copied into the top level checkpoint dir, so the user can easily do the conversion at any point in the future. Once extracted, the weights don’t require DeepSpeed and can be used in any application. Additionally the script has been modified to ensure we keep the lightning state inside the state dict for being able to run LightningModule.load_from_checkpoint('...')`.

Parameters
  • checkpoint_dir (_PATH) – path to the desired checkpoint folder. (one that contains the tag-folder, like global_step14)

  • output_file (_PATH) – path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)

  • tag (str | None) – 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

Examples

>>> from pytorch_lightning.utilities.deepspeed import (
...     convert_zero_checkpoint_to_fp32_state_dict
... )
>>> # Lightning deepspeed has saved a directory instead of a file
>>> save_path = "lightning_logs/version_0/checkpoints/epoch=0-step=0.ckpt/" 
>>> output_path = "lightning_model.pt" 
>>> convert_zero_checkpoint_to_fp32_state_dict(save_path, output_path) 
Saving fp32 state dict to lightning_model.pt
Return type

None

Read the Docs v: latest
Versions
latest
stable
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.10
1.5.9
1.5.8
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.8
1.3.7
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.10
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.10.0
0.9.0
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.3
0.4.9
future-structure
Downloads
html
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.