-
Notifications
You must be signed in to change notification settings - Fork 6k
fix the add_noise function for dpm-multi et al #5158
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
Conversation
More testing here I also test various strength levels (from 0.1 ~ 0.95 with 0.05 interval) for each of the schedulers we updated, for both I uploaded outputs here https://huggingface.co/datasets/YiYiXu/pr5158/tree/main import requests
import numpy as np
from PIL import Image
from io import BytesIO
import torch
from diffusers import (
StableDiffusionImg2ImgPipeline,
DPMSolverSinglestepScheduler,
DPMSolverMultistepScheduler,
UniPCMultistepScheduler,
DEISMultistepScheduler,
)
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))
device = "cuda"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
).to(device)
scheduler_config = dict(pipe.scheduler.config)
# DPMSolverMultistepScheduler
sched_name = "dpm_miulti"
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
scheduler_config, use_karras_sigmas=True, algorithm_type="dpmsolver++")
for strength in torch.linspace(0.1,0.95,18):
images = pipe(
prompt="a fantasy landscape",
negative_prompt=None,
image=init_image,
strength=strength,
num_inference_steps=15,
guidance_scale=10,
num_images_per_prompt=1
).images
image = images[0].save(f"test_2_out/[{sched_name}]_{strength:.2f}.png")
# DPMSolverMultistepScheduler(sde)
sched_name = "dpm_miulti_sde"
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
scheduler_config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++")
for strength in torch.linspace(0.1,0.95,18):
images = pipe(
prompt="a fantasy landscape",
negative_prompt=None,
image=init_image,
strength=strength,
num_inference_steps=15,
guidance_scale=10,
num_images_per_prompt=1
).images
image = images[0].save(f"test_2_out/[{sched_name}]_{strength:.2f}.png")
# DPMSolverSingleScheduler
sched_name = "dpm_single"
pipe.scheduler = DPMSolverSinglestepScheduler.from_config(
scheduler_config, use_karras_sigmas=True)
for strength in torch.linspace(0.1,0.95,18):
images = pipe(
prompt="a fantasy landscape",
negative_prompt=None,
image=init_image,
strength=strength,
num_inference_steps=15,
guidance_scale=10,
num_images_per_prompt=1
).images
image = images[0].save(f"test_2_out/[{sched_name}]_{strength:.2f}.png")
# UniPCMultistepScheduler
sched_name = "unipc"
pipe.scheduler = UniPCMultistepScheduler.from_config(
scheduler_config, use_karras_sigmas=True)
for strength in torch.linspace(0.1,0.95,18):
images = pipe(
prompt="a fantasy landscape",
negative_prompt=None,
image=init_image,
strength=strength,
num_inference_steps=15,
guidance_scale=10,
num_images_per_prompt=1
).images
image = images[0].save(f"test_2_out/[{sched_name}]_{strength:.2f}.png")
# DEISMultistepScheduler
sched_name = "deis"
pipe.scheduler = DEISMultistepScheduler.from_config(
scheduler_config, use_karras_sigmas=True)
for strength in torch.linspace(0.1,0.95,18):
images = pipe(
prompt="a fantasy landscape",
negative_prompt=None,
image=init_image,
strength=strength,
num_inference_steps=15,
guidance_scale=10,
num_images_per_prompt=1
).images
image = images[0].save(f"test_2_out/[{sched_name}]_{strength:.2f}.png") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me (tested DPMSolverMultistepScheduler). The SDXL refiner step was broken, wasn't it? Did we receive any reports?
I'd suggest we merge this soon but then create tests (or fix them) as a followup, to ensure we catch similar problems in the future.
Thanks for fixing this so fast! |
Very clean fix - thanks a lot @yiyixuxu |
* remove to _device() for sigmas * update add_noise to use simgas --------- Co-authored-by: yiyixuxu <yixu310@gmail,com>
* remove to _device() for sigmas * update add_noise to use simgas --------- Co-authored-by: yiyixuxu <yixu310@gmail,com>
My PR to refactor schedulers #4986 broke img2img pipelines :(
I updated the
add_noise
incorrectly and never tested it with img2img and it was not caught by our current teststhis PR update
add_noise
to usesigmas
testing
I compared outputs from this branch vs the output from a branch where I reverted the commit that introduced this bug #4986
I used a single strength value
0.8
, and I tested bothuse_karras_sigma=True
anduse_karras_sigma=False
config. The results are identical.testing
use_karras_sigma=True
DEISMultistepScheduler
DPMSolverMultistepScheduler(sde)
DPMSolverMultistepScheduler
DPMSolverSingleScheduler
UniPCMultistepScheduler
testing
use_karras_sigma=False
DEISMultistepScheduler
DPMSolverMultistepScheduler(sde)
DPMSolverMultistepScheduler
DPMSolverSingleScheduler
UniPCMultistepScheduler