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

Inconsistent behavior of loading .safetensors models when setting use_safetensors=True #3355

Closed
arthur-x opened this issue May 6, 2023 · 9 comments
Assignees
Labels
bug Something isn't working stale Issues that haven't received updates

Comments

@arthur-x
Copy link

arthur-x commented May 6, 2023

Describe the bug

The use of function StableDiffusionPipeline.from_ckpt is not consistent with the document w.r.t. loading .safetensors models. Specifically, calling this function to load a .safetensors model and in the same time setting use_safetensors=True will result in a ValueError saying safetensors is not installed. Despite already having a safetensors installation.

Related PR:

#3333 discussed about safetensors' doc, but didn't mention the bug, nor did it fix the bug.

Suspected Cause:

Line 1243 in src/diffusers/loaders.py gets the parameter:

use_safetensors = kwargs.pop("use_safetensors", None if is_safetensors_available() else False)

If we set use_safetensors=True, then after this, use_safetensors will be True regardless of is_safetensors_available().

Then at line 1249 we call:

if from_safetensors and use_safetensors is True:
        raise ValueError("Make sure to install `safetensors` with `pip install safetensors`.")

Thus if we have a .safetensors file (which means from_safetensors == True) this throws a ValueError.

Reproduction

from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_ckpt("/path/to/model.safetensors", use_safetensors=True)

Gives:

...
ValueError: Make sure to install `safetensors` with `pip install safetensors`.

Logs

No response

System Info

Colab, latest diffusers

@arthur-x arthur-x added the bug Something isn't working label May 6, 2023
@Zundrium
Copy link

Zundrium commented May 8, 2023

Thanks, this was driving me crazy.

@patrickvonplaten
Copy link
Contributor

@sayakpaul do you maybe have time to look into this?

@github-actions
Copy link

github-actions bot commented Jun 6, 2023

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Jun 6, 2023
@arthur-x
Copy link
Author

arthur-x commented Jun 6, 2023

doesn't look like fixed.

@JemiloII
Copy link

JemiloII commented Jun 7, 2023

i don't like the safetensors format. Most of these safetensors don't load correctly in code and you don't get to know the format. It would have been nice if the safetensors would save like model.pt.safetensors or model.ckpt.safetensors. but it seems you have whatever format you want.

@sayakpaul
Copy link
Member

Gently pinging @patrickvonplaten

@patrickvonplaten
Copy link
Contributor

Think this is fixed with #3466 no? Can you double check?

@arthur-x
Copy link
Author

arthur-x commented Jun 8, 2023

I tried the current main branch version on github. While I am encountering the same issue as in #3466 right now (diffusers trying to treat a local path as url), I read the code and think the inconsistent behavior regarding use_safetensors=True should have been fixed in the main branch.

Again I am unable to verify for sure but it looks okay.

@sayakpaul
Copy link
Member

Okay. Closing this issue thread for now. Feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Issues that haven't received updates
Projects
None yet
Development

No branches or pull requests

5 participants