-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Add configurable dtype for ZeRO checkpoint export #8318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a single-parent, non-merge commit, but its commit message contains no AGENTS.md reference: AGENTS.md:L8-L8 Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original commit f38e9a0 already contains Signed-off-by: gaoxiaomo 165135449+gaoxiaomo@users.noreply.github.com, and the repository DCO check is passing. The follow-up commit 7ffebd1 is signed off as well. |
||
| # DeepSpeed Team | ||
|
|
||
| import argparse | ||
|
|
||
| import deepspeed.utils.zero_to_fp32 as zero_to_fp32 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the checkpoint is recovered under a different installed DeepSpeed version, this qualified import resolves Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 7ffebd1. Package imports now use the relative sibling module, while direct execution imports zero_to_fp32.py from the copied script directory. The new regression runs a copied zero_to_torch.py beside a stub converter and verifies that the local converter is invoked. |
||
|
|
||
|
|
||
| def main(args=None): | ||
| parser = argparse.ArgumentParser( | ||
| description="Convert a DeepSpeed ZeRO checkpoint to float32, float16, or bfloat16 PyTorch weights.") | ||
| parser.add_argument("checkpoint_dir", | ||
| type=str, | ||
| help="path to the desired checkpoint folder, e.g., path/checkpoint-12") | ||
| parser.add_argument("output_dir", type=str, help="directory for the converted PyTorch state_dict files") | ||
| parser.add_argument("--dtype", | ||
| type=str, | ||
| choices=sorted(zero_to_fp32.OUTPUT_DTYPE_NAMES), | ||
| required=True, | ||
| help="output tensor dtype") | ||
| parser.add_argument("--max_shard_size", | ||
| type=str, | ||
| default="5GB", | ||
| help="maximum size of each checkpoint shard, such as 5GB or 500MB") | ||
| parser.add_argument("--safe_serialization", | ||
| default=False, | ||
| action='store_true', | ||
| help="save with safetensors instead of PyTorch pickle serialization") | ||
| parser.add_argument("-t", | ||
| "--tag", | ||
| type=str, | ||
| default=None, | ||
| help="checkpoint tag used as a unique identifier, e.g., global_step1") | ||
| parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters") | ||
| parser.add_argument("-d", "--debug", action='store_true', help="enable debug output") | ||
| parsed_args = parser.parse_args(args) | ||
|
|
||
| zero_to_fp32.debug = parsed_args.debug | ||
| zero_to_fp32.convert_zero_checkpoint_to_state_dict(parsed_args.checkpoint_dir, | ||
| parsed_args.output_dir, | ||
| dtype=parsed_args.dtype, | ||
| max_shard_size=parsed_args.max_shard_size, | ||
| safe_serialization=parsed_args.safe_serialization, | ||
| tag=parsed_args.tag, | ||
| exclude_frozen_parameters=parsed_args.exclude_frozen_parameters) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this script is copied into a checkpoint,
_change_recovery_script_permissionsmakes it executable and the documentation tells users to invoke it as./zero_to_torch.py, but the file has no shebang. Executing such a copied script directly causes the shell to interpret the Python source and fail immediately; add a Python shebang as used byzero_to_fp32.py.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7ffebd1. The recovery entry point now starts with a Python shebang. The standalone regression also verifies the copied script retains the shebang.