Skip to content
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

Support safetensors export #6579

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Support safetensors export #6579

wants to merge 7 commits into from

Conversation

xu-song
Copy link
Contributor

@xu-song xu-song commented Sep 27, 2024

Feature

This commit implements the following features:

  • support saving checkpoint as safetensors (more commonly used format)
  • support sharding checkpoints (which is important for very large models)

Most of the codes are borrowed from https://github.com/huggingface/transformers/blob/v4.45.1/src/transformers/modeling_utils.py#L2490

Usage

For pytorch_model.bin export

python zero_to_fp32.py . output_dir/

For model.safetensors export

python zero_to_fp32.py . output_dir/ --safe_serialization

@tohtana
Copy link
Contributor

tohtana commented Sep 27, 2024

I think DeepSpeed is designed to work in the environment where HF is not installed.

requirements/requirements.txt doesn't have transformer (requirements/requirements-dev.txt does) and there are try-except to imports for transformers (example). Can we have local import to attempt to load transformers and huggingface_hub only when the safetensor option is specified? We can also show an error message when the option is enabled and the modules are not available.

@xu-song
Copy link
Contributor Author

xu-song commented Sep 29, 2024

@tohtana Following your suggestions, I made some optimization for import issue.

@tohtana
Copy link
Contributor

tohtana commented Oct 1, 2024

Thank you @xu-song! The formatting test fails, can you check it?

@tohtana tohtana self-requested a review October 4, 2024 20:22
@xu-song
Copy link
Contributor Author

xu-song commented Oct 5, 2024

formatting has been fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants