Skip to content

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

Closed
@arthur-x

Description

@arthur-x

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

Metadata

Metadata

Labels

bugSomething isn't workingstaleIssues that haven't received updates

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions