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

[Core] is_cosxl_edit arg in SDXL ip2p. #7650

Merged
merged 9 commits into from
Apr 16, 2024
Merged

[Core] is_cosxl_edit arg in SDXL ip2p. #7650

merged 9 commits into from
Apr 16, 2024

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Apr 12, 2024

What does this PR do?

As found out by @yiyixuxu here:
#7621 (comment)

Related to #7621.

Cc: @apolinario for awareness.

@sayakpaul sayakpaul requested review from DN6 and yiyixuxu April 12, 2024 07:22
sayakpaul and others added 2 commits April 12, 2024 12:53
Co-authored-by: Yiyi Xu <yixu310@gmail.com>
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@sayakpaul
Copy link
Member Author

@DN6 your comments have been addressed.

@sayakpaul sayakpaul requested a review from DN6 April 13, 2024 07:33
@sayakpaul
Copy link
Member Author

Failing test is quite unrelated.

@sayakpaul
Copy link
Member Author

Here's testing code:

import torch
from diffusers import StableDiffusionXLInstructPix2PixPipeline, EDMEulerScheduler
from diffusers.utils import load_image
import numpy as np
import math

def set_timesteps_patched(self, num_inference_steps: int, device = None):
    self.num_inference_steps = num_inference_steps
    
    ramp = np.linspace(0, 1, self.num_inference_steps)
    sigmas = torch.linspace(math.log(self.config.sigma_min), math.log(self.config.sigma_max), len(ramp)).exp().flip(0)
    
    sigmas = (sigmas).to(dtype=torch.float32, device=device)
    self.timesteps = self.precondition_noise(sigmas)
    
    self.sigmas = torch.cat([sigmas, torch.zeros(1, device=sigmas.device)])
    self._step_index = None
    self._begin_index = None
    self.sigmas = self.sigmas.to("cpu")  # to avoid too much CPU/GPU communication

inst_file = "https://huggingface.co/stabilityai/cosxl/blob/main/cosxl_edit.safetensors"

pipe = StableDiffusionXLInstructPix2PixPipeline.from_single_file(
    inst_file, num_in_channels=8, is_cosxl_edit=True
).to("cuda")

# This won't be needed after https://github.com/huggingface/diffusers/pull/7649
EDMEulerScheduler.set_timesteps = set_timesteps_patched
pipe.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")

resolution = 1024
image = load_image(
    "https://hf.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png"
).resize((resolution, resolution))

edit_instruction = "Turn sky into a cloudy one"
edited_image = pipe(
    prompt=edit_instruction,
    image=image,
    height=resolution,
    width=resolution,
    num_inference_steps=20,
).images[0]
edited_image.save("edited_image.png")

^ matches what Yiyi got here: #7621 (comment).

@sayakpaul
Copy link
Member Author

Created an issue for the installation failure here: astral-sh/uv#3031.

I will submit a quick PR replacing the uv installation step that's causing the failure to unblock this PR.

Copy link
Collaborator

@DN6 DN6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏽. The failing test looks unrelated.

@DN6 DN6 merged commit 9d50f7e into main Apr 16, 2024
17 checks passed
sayakpaul added a commit that referenced this pull request Dec 23, 2024
* is_cosxl_edit arg in SDXL ip2p.

* Empty-Commit

Co-authored-by: Yiyi Xu <yixu310@gmail.com>

* doc

* remove redundant logic.

* reflect drhuv's comments.

---------

Co-authored-by: Yiyi Xu <yixu310@gmail.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants