huggingface / diffusers

šŸ¤— Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
25.09k stars 5.18k forks source link

diffusers.FluxPipeline has no .from_single_file() function #9141

Open lutusp opened 1 month ago

lutusp commented 1 month ago

Describe the bug

At the moment one cannot use a local Flux1-dev or -schnell file for lack of an essential function "from_single_file()" in the diffusers.FluxPipeline library. The provided flag "local_files_only" for some reason doesn't solve this problem.

Reproduction

pipe = FluxPipeline.from_single_file(
    'full path to local file, example /(full_path)/flux1-dev.safetensors',
    torch_dtype=torch.bfloat16,
    use_safetensors=True,
    local_files_only=True
    )

Logs

No response

System Info

$ diffusers-cli env

Who can help?

No response

DN6 commented 1 month ago

@lutusp Are you trying to load just the transformer model or do you have the weights for the entire checkpoint saved in a single file checkpoint?

lutusp commented 1 month ago

I guess my explanation wasn't clear enough. My point wasn't that the function created an unexpected outcome, it is that the function doesn't exist. There is no function with that name in diffusers.FluxPipeline.

But apart from that, it was this file: "flux1-dev.safetensors", from here: https://huggingface.co/black-forest-labs/FLUX.1-dev/tree/main .

mlick commented 1 month ago

I have a same question, i want to know how to load local model?

DN6 commented 4 weeks ago

@lutusp Support for single file for Flux at the pipeline level hasn't been added yet because checkpoints that contain all the model components in a single file were only recently released. The checkpoint you shared contains just the transformer weights.

Support for single file loading just the Transformer exists currently.

transformer = FluxTransformer2DModel.from_single_file(
    "https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/flux1-dev.safetensors",
    torch_dtype=torch.bfloat16
).to("cuda")
pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    transformer=transformer,
    torch_dtype=torch.bfloat16
)
tomsin9 commented 3 weeks ago

for the FluxTransformer2DModel.from_single_file(), when i change the path to local, it doesnt work:

OSError: runwayml/stable-diffusion-v1-5 does not appear to have a file named config.json.

sxy771 commented 1 week ago

for the FluxTransformer2DModel.from_single_file(), when i change the path to local, it doesnt work:

OSError: runwayml/stable-diffusion-v1-5 does not appear to have a file named config.json.

I'm also wondering how to handle above errors.

I tried to load flux model downloaded from civitai but the model didn't work showing OSError message.