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

Experimental per control type scale for ControlNet Union #10723

Merged
merged 7 commits into from
Feb 27, 2025

Conversation

hlky
Copy link
Member

@hlky hlky commented Feb 5, 2025

What does this PR do?

This adds experimental support for per control type scale to ControlNet Union.

Code

from diffusers import (
    StableDiffusionXLControlNetUnionPipeline,
    ControlNetUnionModel,
    AutoencoderKL,
)
from diffusers.utils import load_image
import torch

prompt = "A bird"
seg = load_image("house_seg.png")
canny = load_image("bird_canny.png")
controlnet = ControlNetUnionModel.from_pretrained(
    "xinsir/controlnet-union-sdxl-1.0", torch_dtype=torch.float16
)
vae = AutoencoderKL.from_pretrained(
    "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
)
pipe = StableDiffusionXLControlNetUnionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    controlnet=controlnet,
    vae=vae,
    torch_dtype=torch.float16,
    variant="fp16",
)
pipe.enable_model_cpu_offload()
image = pipe(
    prompt,
    control_image=[seg, canny],
    control_mode=[5, 3],
    height=1024,
    width=1024,
    controlnet_conditioning_scale=[0.0, 1.0],
    generator=torch.Generator().manual_seed(0),
).images[0]

Control images

house_seg

bird_canny

Canny Canny Seg Canny No Seg
canny canny_seg canny_no_seg

Canny: control_image=[canny]
Canny Seg: control_image=[seg, canny]
Canny No Seg: control_image=[seg, canny] with controlnet_conditioning_scale=[0.0, 1.0]

Fixes #10656

Note: we will also add MultiControlNet support for ControlNet Union in another PR.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@yiyixuxu @asomoza @vladmandic

@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.

@hlky hlky mentioned this pull request Feb 5, 2025
6 tasks
@john09282922
Copy link

john09282922 commented Feb 13, 2025

Is this one possible to use pro-max version as well?
also if it is possible, can you merge to sdxl_union_inpaint model as well?
@hlky

Thanks

@hlky hlky mentioned this pull request Feb 13, 2025
6 tasks
@hlky
Copy link
Member Author

hlky commented Feb 13, 2025

@john09282922 Yes.

@hlky
Copy link
Member Author

hlky commented Feb 13, 2025

Pose+Seg Pose Seg
pose_seg pose seg
import torch

from diffusers import StableDiffusionXLControlNetUnionPipeline
from diffusers.models import ControlNetUnionModel, AutoencoderKL
from diffusers.utils import load_image

room_seg_img = load_image(
    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/room_seg.png"
)
pose_img = load_image(
    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/pose.png"
)

controlnet = ControlNetUnionModel.from_pretrained(
    "brad-twinkl/controlnet-union-sdxl-1.0-promax", torch_dtype=torch.float16
)
vae = AutoencoderKL.from_pretrained(
    "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
)
pipe = StableDiffusionXLControlNetUnionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    controlnet=controlnet,
    vae=vae,
    torch_dtype=torch.float16,
    variant="fp16",
)
pipe.enable_model_cpu_offload()

image = pipe(
    prompt="an astronaut in space",
    width=1024,
    height=1024,
    negative_prompt="lowres, low quality, worst quality",
    control_image=[pose_img, room_seg_img],
    control_mode=[0, 5],
    #controlnet_conditioning_scale=[0.0, 1.0],
    num_inference_steps=50,
    generator=torch.Generator().manual_seed(42),
).images[0]

image.save("result.jpg")

Also unifies the interface for MultiControlNet cc @vladmandic simply splits to list of list internally

cc @guiyrt However I can't seem to reproduce the results here with MultiControlNet, checked on PR and main. Edit: seems ok now

Pose+Seg Pose Seg
multi_pose_seg multi_pose multi_seg

Uses standard scaling with MultiControlNet and experimental scaling otherwise.

@hlky hlky merged commit 37a5f1b into huggingface:main Feb 27, 2025
11 of 12 checks passed
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.

ControlNet union pipeline fails on multi-model
4 participants