Skip to content

Commit 095393a

Browse files
JPlin鹏徙a-r-r-o-w
authored andcommitted
Support SD3 controlnet inpainting (#9099)
* add controlnet inpainting pipeline * [SD3] add controlnet inpaint example * update example and fix code style * fix code style with ruff * Update controlnet_sd3.md : add control inpaint pipeline * Update docs/source/en/api/pipelines/controlnet_sd3.md Co-authored-by: Aryan <[email protected]> * Update docs/source/en/api/pipelines/controlnet_sd3.md Co-authored-by: Aryan <[email protected]> * Update docs/source/en/api/pipelines/controlnet_sd3.md Co-authored-by: Aryan <[email protected]> * Update src/diffusers/pipelines/controlnet_sd3/pipeline_stable_diffusion_3_controlnet_inpainting.py Co-authored-by: Aryan <[email protected]> * Update __init__.py : add sd3 control pipelines * Update pipeline : add new param doc & check input reference. * fix typo * make style & make quality * add unittest for sd3 controlnet inpaint --------- Co-authored-by: 鹏徙 <[email protected]> Co-authored-by: Aryan <[email protected]>
1 parent 0c78d2a commit 095393a

File tree

7 files changed

+1370
-6
lines changed

7 files changed

+1370
-6
lines changed

docs/source/en/api/pipelines/controlnet_sd3.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--Copyright 2023 The HuggingFace Team and The InstantX Team. All rights reserved.
1+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
44
the License. You may obtain a copy of the License at
@@ -22,7 +22,16 @@ The abstract from the paper is:
2222

2323
*We present ControlNet, a neural network architecture to add spatial conditioning controls to large, pretrained text-to-image diffusion models. ControlNet locks the production-ready large diffusion models, and reuses their deep and robust encoding layers pretrained with billions of images as a strong backbone to learn a diverse set of conditional controls. The neural architecture is connected with "zero convolutions" (zero-initialized convolution layers) that progressively grow the parameters from zero and ensure that no harmful noise could affect the finetuning. We test various conditioning controls, eg, edges, depth, segmentation, human pose, etc, with Stable Diffusion, using single or multiple conditions, with or without prompts. We show that the training of ControlNets is robust with small (<50k) and large (>1m) datasets. Extensive results show that ControlNet may facilitate wider applications to control image diffusion models.*
2424

25-
This code is implemented by [The InstantX Team](https://huggingface.co/InstantX). You can find pre-trained checkpoints for SD3-ControlNet on [The InstantX Team](https://huggingface.co/InstantX) Hub profile.
25+
This controlnet code is mainly implemented by [The InstantX Team](https://huggingface.co/InstantX). The inpainting-related code was developed by [The Alimama Creative Team](https://huggingface.co/alimama-creative). You can find pre-trained checkpoints for SD3-ControlNet in the table below:
26+
27+
28+
| ControlNet type | Developer | Link |
29+
| -------- | ---------- | ---- |
30+
| Canny | [The InstantX Team](https://huggingface.co/InstantX) | [Link](https://huggingface.co/InstantX/SD3-Controlnet-Canny) |
31+
| Pose | [The InstantX Team](https://huggingface.co/InstantX) | [Link](https://huggingface.co/InstantX/SD3-Controlnet-Pose) |
32+
| Tile | [The InstantX Team](https://huggingface.co/InstantX) | [Link](https://huggingface.co/InstantX/SD3-Controlnet-Tile) |
33+
| Inpainting | [The AlimamaCreative Team](https://huggingface.co/alimama-creative) | [link](https://huggingface.co/alimama-creative/SD3-Controlnet-Inpainting) |
34+
2635

2736
<Tip>
2837

@@ -35,5 +44,10 @@ Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers)
3544
- all
3645
- __call__
3746

47+
## StableDiffusion3ControlNetInpaintingPipeline
48+
[[autodoc]] pipelines.controlnet_sd3.pipeline_stable_diffusion_3_controlnet_inpainting.StableDiffusion3ControlNetInpaintingPipeline
49+
- all
50+
- __call__
51+
3852
## StableDiffusion3PipelineOutput
3953
[[autodoc]] pipelines.stable_diffusion_3.pipeline_output.StableDiffusion3PipelineOutput

src/diffusers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
"StableCascadeCombinedPipeline",
309309
"StableCascadeDecoderPipeline",
310310
"StableCascadePriorPipeline",
311+
"StableDiffusion3ControlNetInpaintingPipeline",
311312
"StableDiffusion3ControlNetPipeline",
312313
"StableDiffusion3Img2ImgPipeline",
313314
"StableDiffusion3InpaintPipeline",

src/diffusers/models/controlnet_sd3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(
5555
pooled_projection_dim: int = 2048,
5656
out_channels: int = 16,
5757
pos_embed_max_size: int = 96,
58+
extra_conditioning_channels: int = 0,
5859
):
5960
super().__init__()
6061
default_out_channels = in_channels
@@ -98,7 +99,7 @@ def __init__(
9899
height=sample_size,
99100
width=sample_size,
100101
patch_size=patch_size,
101-
in_channels=in_channels,
102+
in_channels=in_channels + extra_conditioning_channels,
102103
embed_dim=self.inner_dim,
103104
pos_embed_type=None,
104105
)

src/diffusers/pipelines/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
_import_structure["controlnet_sd3"].extend(
174174
[
175175
"StableDiffusion3ControlNetPipeline",
176+
"StableDiffusion3ControlNetInpaintingPipeline",
176177
]
177178
)
178179
_import_structure["deepfloyd_if"] = [
@@ -465,9 +466,7 @@
465466
from .controlnet_hunyuandit import (
466467
HunyuanDiTControlNetPipeline,
467468
)
468-
from .controlnet_sd3 import (
469-
StableDiffusion3ControlNetPipeline,
470-
)
469+
from .controlnet_sd3 import StableDiffusion3ControlNetInpaintingPipeline, StableDiffusion3ControlNetPipeline
471470
from .controlnet_xs import (
472471
StableDiffusionControlNetXSPipeline,
473472
StableDiffusionXLControlNetXSPipeline,

src/diffusers/pipelines/controlnet_sd3/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
_dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects))
2424
else:
2525
_import_structure["pipeline_stable_diffusion_3_controlnet"] = ["StableDiffusion3ControlNetPipeline"]
26+
_import_structure["pipeline_stable_diffusion_3_controlnet_inpainting"] = [
27+
"StableDiffusion3ControlNetInpaintingPipeline"
28+
]
2629

2730
if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT:
2831
try:
@@ -33,6 +36,7 @@
3336
from ...utils.dummy_torch_and_transformers_objects import *
3437
else:
3538
from .pipeline_stable_diffusion_3_controlnet import StableDiffusion3ControlNetPipeline
39+
from .pipeline_stable_diffusion_3_controlnet_inpainting import StableDiffusion3ControlNetInpaintingPipeline
3640

3741
try:
3842
if not (is_transformers_available() and is_flax_available()):

0 commit comments

Comments
 (0)