Skip to content

[Community pipeline] SDXL Differential Diffusion Img2Img Pipeline - #7550

Merged
yiyixuxu merged 3 commits into
huggingface:mainfrom
asomoza:diff-diff-img2img-community
Apr 2, 2024
Merged

[Community pipeline] SDXL Differential Diffusion Img2Img Pipeline#7550
yiyixuxu merged 3 commits into
huggingface:mainfrom
asomoza:diff-diff-img2img-community

Conversation

@asomoza

Copy link
Copy Markdown
Member

What does this PR do?

Adds Differential Diffusion as a community pipeline as discussed here, this is the SDXL img2img version.

More information and original PR here. I'll add the documentation to the README after the initials reviews.

Once this one is merged I plan to do also:

  • SDXL Differential Diffusion Img2Img Pipeline
  • SDXL Differential Diffusion Img2Img Controlnet Adapter Pipeline
  • SDXL Differential Diffusion Inpaint Pipeline
  • SDXL Differential Diffusion Inpaint Controlnet Adapter Pipeline

Note: It works with turbo and lighting variations, but IMO the only half good one is the lighting 8 steps, with less steps the model can't properly do the inpaint and even with 8, the inpainting isn't that good.

Fixes#7038

Paper: https://differential-diffusion.github.io/paper.pdf
Project site: https://differential-diffusion.github.io/
Code: https://github.com/exx8/differential-diffusion

Example usage:

importtorchfromtorchvisionimporttransformsfromdiffusersimportDPMSolverMultistepSchedulerfromdiffusers.utilsimportload_imagefromexamples.community.pipeline_stable_diffusion_xl_differential_img2imgimport (
StableDiffusionXLDifferentialImg2ImgPipeline,
)
pipeline=StableDiffusionXLDifferentialImg2ImgPipeline.from_pretrained(
"SG161222/RealVisXL_V4.0", torch_dtype=torch.float16, variant="fp16"
).to("cuda")
pipeline.scheduler=DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config, use_karras_sigmas=True)
defpreprocess_image(image):
image=image.convert("RGB")
image=transforms.CenterCrop((image.size[1] //64*64, image.size[0] //64*64))(image)
image=transforms.ToTensor()(image)
image=image*2-1image=image.unsqueeze(0).to("cuda")
returnimagedefpreprocess_map(map):
map=map.convert("L")
map=transforms.CenterCrop((map.size[1] //64*64, map.size[0] //64*64))(map)
map=transforms.ToTensor()(map)
map=map.to("cuda")
returnmapimage=preprocess_image(
load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png?download=true"
)
)
mask=preprocess_map(
load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png?download=true"
)
)
prompt="a green pear"negative_prompt="blurry"image=pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=7.5,
num_inference_steps=25,
original_image=image,
image=image,
strength=1.0,
map=mask,
).images[0]
image.save("result.png")

Examples

RealvisJuggernaut
differential_20240401151708_2861674568differential_20240401151545_2067481981
Lighting 8 stepsIP Adapters
differential_20240401145538_3135922217differential_20240401170302_43613221

Who can review?

@yiyixuxu@sayakpaul@exx8@a-r-r-o-w

@yiyixuxu

Copy link
Copy Markdown
Collaborator

looks good! will merge whenever you're ready!

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@yiyixuxu
yiyixuxu merged commit 73ba810 into huggingface:mainApr 2, 2024
@asomoza
asomoza deleted the diff-diff-img2img-community branch April 2, 2024 04:25
noskill pushed a commit to noskill/diffusers that referenced this pull request Apr 5, 2024
@xinru-liu

Copy link
Copy Markdown

Hi, I would really like to test the differential img2img pipeline, has this been published yet?

@yiyixuxu

Copy link
Copy Markdown
Collaborator

@xinru-liu

Copy link
Copy Markdown

@yiyixuxu
Thank you for getting back, I just tested, it shows
"404 Client Error: Not Found for url: https://raw.githubusercontent.com/huggingface/diffusers/v0.27.2/examples/community/pipeline_stable_diffusion_xl_differential_img2img.py"
I think the name is accurate, not sure why it failed to access the code.

@asomoza

Copy link
Copy Markdown
MemberAuthor

that's because you're trying to access it in the v0.27.2 release, this was merged after the last release so until the next one you have to install diffusers from the git repository:

pip install git+https://github.com/huggingface/diffusers.git

Also you can just download it and use it directly:

https://github.com/huggingface/diffusers/blob/main/examples/community/pipeline_stable_diffusion_xl_differential_img2img.py

@xinru-liu

Copy link
Copy Markdown

that's because you're trying to access it in the v0.27.2 release, this was merged after the last release so until the next one you have to install diffusers from the git repository:

pip install git+https://github.com/huggingface/diffusers.git

Also you can just download it and use it directly:

https://github.com/huggingface/diffusers/blob/main/examples/community/pipeline_stable_diffusion_xl_differential_img2img.py

Thank you @asomoza ! I've tested the solution, it works really well!

sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
)
* initial-commit pipeline created
* updated README.md
Sign up for freeto 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.

Differential Diffusion: Giving Each Pixel Its Strength

4 participants

@asomoza@yiyixuxu@HuggingFaceDocBuilderDev@xinru-liu