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
26.13k stars 5.38k forks source link

DPMSolverSinglestepScheduler, SD generates blank images at EVEN step numbers #6949

Closed Vargol closed 8 months ago

Vargol commented 9 months ago

Describe the bug

If DPMSolverSinglestepScheduler is used as a schedule with a stable diffusion pipeline the image generated by stable diffusion is a blank, black image if the number of inference steps is even.

Here's a shared Colab ready to go https://colab.research.google.com/drive/1AUOvWu380FDJE0J0XOWKPBqX4qR2wUpZ?usp=sharing Note this has the step numbers as (10,12, 11, 13, 14) as I wanted to check it wasn't just every other run worked

Reproduction

%pip install --quiet --upgrade diffusers transformers accelerate mediapy torchaudio torchdata torchtext torchvision
import mediapy as media
from diffusers import DiffusionPipeline, DPMSolverSinglestepScheduler

from diffusers import DiffusionPipeline, AutoencoderKL, UNet2DConditionModel, DPMSolverSinglestepScheduler

model_ref = "runwayml/stable-diffusion-v1-5"

prompt = "A film still of a teddy bear standing in a lush green jungle"

pipe = DiffusionPipeline.from_pretrained(
      model_ref,
      use_safetensors=True,
      safety_checker=None
     )
pipe.to('cuda')

pipe.scheduler =  DPMSolverSinglestepScheduler.from_config(pipe.scheduler.config)

for i in (10,11, 12, 13, 14):

  images = pipe(
    prompt = prompt,
    num_inference_steps=i,
    guidance_scale=8
    ).images

  print(f'num_inference_steps {i}')
  media.show_images(images)

### Logs

```shell
You have disabled the safety checker for <class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline'> by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .

System Info

Who can help?

@yiyixuxu @patrickvonplaten

Vargol commented 9 months ago

I've also checked this using SDXL and SDXL on MacOS (MPS) with the same results. Also the same with use_karras_sigmas=True

hipsterusername commented 9 months ago

In testing Diffusers .25, this wasn't an issue, so seems to have been a regression with the fixes put into place.

This seems to be a regression where even numbers fail and odd numbers with the # of steps. I seem to recall this was a previous issue and there was a fix implemented for this a while back.

yiyixuxu commented 9 months ago

thanks for reporting! on this

patrickvonplaten commented 9 months ago

@Vargol can you check with the newest diffusers release (0.26.3?)

Vargol commented 9 months ago

@patrickvonplaten I can't check CUDA (looks like I hit the resource limits ) but its working fine on my mac, both even and odd step counts are now producing images,

github-actions[bot] commented 8 months ago

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.

Vargol commented 8 months ago

Finally checked this on CUDA and its fixed there too, so I'l close the issue.