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

Load tensors directly on device #1028

Merged
merged 2 commits into from
Feb 7, 2023
Merged

Load tensors directly on device #1028

merged 2 commits into from
Feb 7, 2023

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Jan 30, 2023

This PR refines load_checkpoint_in_model to directly load weights on the GPUs when the checkpoint file is a safetensors file, since safetensors can load very fast directly there. It also introduces a new load_state_dict function to do this loading.

@patrickvonplaten is this enough for your use case in diffusers?

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jan 30, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me

src/accelerate/utils/modeling.py Outdated Show resolved Hide resolved
Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool that works well with diffusers ! Like in transformers, we use load_checkpoint_and_dispatch so it should work out of the box :-)

Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for extending the support to safetensors and the related tests. LGTM! 🤗

sgugger and others added 2 commits February 7, 2023 13:36
Co-authored-by: Zachary Mueller <muellerzr@gmail.com>
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.

5 participants