Skip to content

Loading from_pretrained from subfolder with a path to directory raises ValueError: is not a folder containing a .index.json file or a pytorch_model.bin or a model.safetensors file #8898

@christopher5106

Description

@christopher5106

Describe the bug

Loading pretrained pipeline component such as UNET from subfolder with path does not work.

Most of your examples use the subfolder formulation, for example here or here and it is supposed to work with a path.

Reproduction

Save "stabilityai/stable-diffusion-xl-base-1.0" locally on the computer in a "pretrained" folder for example and run

unet = UNet2DConditionModel.from_pretrained(
    "pretrained", subfolder="unet",
)

raises an error ValueError: pretrained is not a folder containing a .index.json file or a pytorch_model.bin or a model.safetensors file

while it works with the remote formulation model repo + model id for hosted models.

A work around is to use

unet = UNet2DConditionModel.from_pretrained(
    "pretrained/unet",
)

that works. If this is the only way to load component weights from directory path, that means all examples can't be run from local path and variable args.pretrained_model_name_or_path should be named args.pretrained_model_name only.

Logs

No response

System Info

Python==3.10.14
Conda env without accelerate
torch==2.3.1
Diffusers installed from source at commit a785992

Who can help?

@DN6 @yiyixuxu @sayakpaul

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions