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

StableDiffusionXLInpaintPipeline.from_single_file for refiner returns back Img2ImgPipeline #6001

Closed
darshats opened this issue Nov 30, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@darshats
Copy link

Describe the bug

When using this call:
StableDiffusionXLInpaintPipeline.from_single_file(/sd_xl_refiner_1.0.safetensors), we get an instance of Img2ImgPipeline rather than Inpainting pipeline.
This seems related to 4186, but in this case Img2ImgPipeline doesnt throw an error when mask_image parameter is passed, it just silently ignores it.

Reproduction

from diffusers import StableDiffusionXLInpaintPipeline
from diffusers.utils import load_image

refiner = StableDiffusionXLInpaintPipeline.from_single_file(
"./sd_xl_refiner_1.0.safetensors",
torch_dtype=torch.float16,
use_safetensors=True,
variant="fp16",
)
refiner.to("cuda")

Logs

No response

System Info

Diffusers 0.23

Who can help?

No response

@darshats darshats added the bug Something isn't working label Nov 30, 2023
@sayakpaul
Copy link
Member

Could you provide a fuller reproducible code snippet for us to understand the issue better?

Cc: @DN6

@darshats
Copy link
Author

darshats commented Dec 3, 2023

The intent is to get a refiner for inpainting like described here

However if I run the code below, StableDiffusionXLInpaintPipeline.from_single_file call returns an Img2Img pipeline. The AutoPipelineForInpainting.from_pipe returns an Inpainting pipeline. The single file call looks like a bug?

 pipe = StableDiffusionXLInpaintPipeline.from_single_file(
    "[https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0_0.9vae.safetensors"](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0_0.9vae.safetensors%22),
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True
    )
pipe.to("cuda")

### this returns in Img2Img pipeline that ignores the mask parameter
refiner = StableDiffusionXLInpaintPipeline.from_single_file(
    "[https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/sd_xl_refiner_1.0_0.9vae.safetensors"](https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/sd_xl_refiner_1.0_0.9vae.safetensors%22),
    text_encoder_2=pipe.text_encoder_2,
    vae=pipe.vae,
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True
)
refiner.to('cuda')

## this returns an inpainting pipeline
refiner2 = AutoPipelineForInpainting.from_pipe(
    refiner,
    text_encoder_2=pipe.text_encoder_2,
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True
    )
refiner2.to('cuda')

@DN6
Copy link
Collaborator

DN6 commented Dec 4, 2023

@yiyixuxu Could you take a look here please.

@patrickvonplaten
Copy link
Contributor

The issue is quite easy to reproduce:

from diffusers import StableDiffusionXLInpaintPipeline
import torch

pipe = StableDiffusionXLInpaintPipeline.from_single_file(
    "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0_0.9vae.safetensors",
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True
)
refiner = StableDiffusionXLInpaintPipeline.from_single_file(
    "https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/sd_xl_refiner_1.0_0.9vae.safetensors",
    text_encoder_2=pipe.text_encoder_2,
    vae=pipe.vae,
    torch_dtype=torch.float16,
    variant="fp16",
    use_safetensors=True
)


print("Refiner", refiner.__class__.__name__)   # prints incorrect class

@DN6 it would be nice if you can take a look here since we want to refactor the from_single_file function anyways

@darshats
Copy link
Author

darshats commented Dec 7, 2023

There is another similar issue - on diffusers 0.22.3
The call
pipe = StableDiffusionXLInpaintPipeline.from_single_file( "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0_0.9vae.safetensors", torch_dtype=torch.float16, variant="fp16", use_safetensors=True )
returns back an object of type inpaint pipeline, but the unet config only has 4 channels.

If I use:
pipe = AutoPipelineForInpainting.from_pretrained( "diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16" )
it correctly returns back in inpaint pipeline instance, with unet having 9 channels.

Some docs have the first way of calling (in conjunction with refiner) and some docs have the second (autopipeline) way of calling. But the second one is correct. First one config looks suspect, and its not really inpainting due to unet config only 4 channels.

@DN6
Copy link
Collaborator

DN6 commented Dec 19, 2023

@darshats should be fixed with #6147

@DN6 DN6 closed this as completed Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants