fix the add_noise function for dpm-multi et al #5158
Merged
Conversation
Collaborator
Author
|
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") |
pcuenca
approved these changes
Sep 23, 2023
Member
pcuenca
left a comment
There was a problem hiding this comment.
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! |
Contributor
|
Very clean fix - thanks a lot @yiyixuxu |
yoonseokjin
pushed a commit
to yoonseokjin/diffusers
that referenced
this pull request
Dec 25, 2023
* remove to _device() for sigmas * update add_noise to use simgas --------- Co-authored-by: yiyixuxu <yixu310@gmail,com>
Merged
AmericanPresidentJimmyCarter
pushed a commit
to AmericanPresidentJimmyCarter/diffusers
that referenced
this pull request
Apr 26, 2024
* remove to _device() for sigmas * update add_noise to use simgas --------- Co-authored-by: yiyixuxu <yixu310@gmail,com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My PR to refactor schedulers #4986 broke img2img pipelines :(
I updated the
add_noiseincorrectly and never tested it with img2img and it was not caught by our current teststhis PR update
add_noiseto usesigmastesting
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=Trueanduse_karras_sigma=Falseconfig. The results are identical.testing
use_karras_sigma=TrueDEISMultistepScheduler
DPMSolverMultistepScheduler(sde)
DPMSolverMultistepScheduler
DPMSolverSingleScheduler
UniPCMultistepScheduler
testing
use_karras_sigma=FalseDEISMultistepScheduler
DPMSolverMultistepScheduler(sde)
DPMSolverMultistepScheduler
DPMSolverSingleScheduler
UniPCMultistepScheduler