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

Allow safetensors offload #873

Merged
merged 3 commits into from
Nov 28, 2022
Merged

Allow safetensors offload #873

merged 3 commits into from
Nov 28, 2022

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Nov 18, 2022

This PR reworks a bit the internals of the offload hooks to allow for the case where the checkpoint is saved with safetensors. In this case, there is no need to have a separate save of the weight as a Numpy memory-mapped array, as we can directly access the weight using safe_open.

Goes along with huggingface/transformers#20321

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 18, 2022

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.

Looks easy enough! Just one comment to make sure we add a safetensors check and it should be added to the test requirements most likely 😄

Comment on lines 163 to 164
if weight_info.get("safetensors_file") is not None:
from safetensors import safe_open
Copy link
Collaborator

@muellerzr muellerzr Nov 18, 2022

Choose a reason for hiding this comment

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

We need a guard here for is_safetensors_available and raise an error if not :) (aka make one :) )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, will clean that up on Monday!

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

🔥

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.

Great! Thanks for fixing the nits :)

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.

4 participants