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

[Core] Set weights_only=True nicely when we use torch.load(). #9455

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Sep 18, 2024

What does this PR do?

See internal discussion: https://pytorch.slack.com/archives/CN963QVJB/p1722612785082449.

Can propagate this PR to examples/ and scripts/ after I have an approval.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@sayakpaul
Copy link
Member Author

@yiyixuxu WDYT?

@yiyixuxu
Copy link
Collaborator

can we wrap the torch_load + weights_only into a function and use it everywhere?

@yiyixuxu
Copy link
Collaborator

actually, we already have one, no?

def load_state_dict(checkpoint_file: Union[str, os.PathLike], variant: Optional[str] = None):

@sayakpaul
Copy link
Member Author

That could work! Will update the PR.

@asomoza
Copy link
Member

asomoza commented Sep 19, 2024

just want to bring that there some users that even though it's not recommended and risky, still want to load checkpoints with the weights_only=False option. For example: #8874 #9154

IMO it should be the default but users should be able to change it, I don't have a strong opinion about this just bringing it up to attention.

@sayakpaul
Copy link
Member Author

I think better to wait for Dhruv to come back then.

@sayakpaul
Copy link
Member Author

@DN6 cc I think this is relevant.

@mikaylagawarecki
Copy link

mikaylagawarecki commented Nov 5, 2024

Hey, any update on this, fyi the BC-breaking default flip is coming in torch 2.6 https://dev-discuss.pytorch.org/t/bc-breaking-change-torch-load-is-being-flipped-to-use-weights-only-true-by-default-in-the-nightlies-after-137602/2573 want to make sure everything works smoothly

Is there anything I can do to help push this along? cc @sayakpaul @DN6 @yiyixuxu

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Nov 5, 2024

hi @mikaylagawarecki
I think we've flipped the default long time ago #7393

cc @DN6 to confirm

@DN6
Copy link
Collaborator

DN6 commented Nov 6, 2024

Hi. Yes, we flipped it because of the security issue. We don't allow setting weights_only=True when loading Diffusers models anymore.

weights_only_kwarg = {"weights_only": True} if is_torch_version(">=", "1.13") else {}

Users would have to either convert to safetensors or deserialise those checkpoints on their own

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.

6 participants