Skip to content

Commit e5564d4

Browse files
Support SD3 ControlNet and Multi-ControlNet. (#8566)
* sd3 controlnet --------- Co-authored-by: haofanwang <[email protected]>
1 parent 2921a20 commit e5564d4

File tree

14 files changed

+2039
-3
lines changed

14 files changed

+2039
-3
lines changed

docs/source/en/_toctree.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@
253253
title: PriorTransformer
254254
- local: api/models/controlnet
255255
title: ControlNetModel
256+
- local: api/models/controlnet_sd3
257+
title: SD3ControlNetModel
256258
title: Models
257259
- isExpanded: false
258260
sections:
@@ -276,6 +278,8 @@
276278
title: Consistency Models
277279
- local: api/pipelines/controlnet
278280
title: ControlNet
281+
- local: api/pipelines/controlnet_sd3
282+
title: ControlNet with Stable Diffusion 3
279283
- local: api/pipelines/controlnet_sdxl
280284
title: ControlNet with Stable Diffusion XL
281285
- local: api/pipelines/controlnetxs
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--Copyright 2024 The HuggingFace Team and The InstantX Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# SD3ControlNetModel
14+
15+
SD3ControlNetModel is an implementation of ControlNet for Stable Diffusion 3.
16+
17+
The ControlNet model was introduced in [Adding Conditional Control to Text-to-Image Diffusion Models](https://huggingface.co/papers/2302.05543) by Lvmin Zhang, Anyi Rao, Maneesh Agrawala. It provides a greater degree of control over text-to-image generation by conditioning the model on additional inputs such as edge maps, depth maps, segmentation maps, and keypoints for pose detection.
18+
19+
The abstract from the paper is:
20+
21+
*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.*
22+
23+
## Loading from the original format
24+
25+
By default the [`SD3ControlNetModel`] should be loaded with [`~ModelMixin.from_pretrained`].
26+
27+
```py
28+
from diffusers import StableDiffusion3ControlNetPipeline
29+
from diffusers.models import SD3ControlNetModel, SD3MultiControlNetModel
30+
31+
controlnet = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Canny")
32+
pipe = StableDiffusion3ControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", controlnet=controlnet)
33+
```
34+
35+
## SD3ControlNetModel
36+
37+
[[autodoc]] SD3ControlNetModel
38+
39+
## SD3ControlNetOutput
40+
41+
[[autodoc]] models.controlnet_sd3.SD3ControlNetOutput
42+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!--Copyright 2023 The HuggingFace Team and The InstantX Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# ControlNet with Stable Diffusion 3
14+
15+
StableDiffusion3ControlNetPipeline is an implementation of ControlNet for Stable Diffusion 3.
16+
17+
ControlNet was introduced in [Adding Conditional Control to Text-to-Image Diffusion Models](https://huggingface.co/papers/2302.05543) by Lvmin Zhang, Anyi Rao, and Maneesh Agrawala.
18+
19+
With a ControlNet model, you can provide an additional control image to condition and control Stable Diffusion generation. For example, if you provide a depth map, the ControlNet model generates an image that'll preserve the spatial information from the depth map. It is a more flexible and accurate way to control the image generation process.
20+
21+
The abstract from the paper is:
22+
23+
*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.*
24+
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.
26+
27+
<Tip>
28+
29+
Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading#reuse-components-across-pipelines) section to learn how to efficiently load the same components into multiple pipelines.
30+
31+
</Tip>
32+
33+
## StableDiffusion3ControlNetPipeline
34+
[[autodoc]] StableDiffusion3ControlNetPipeline
35+
- all
36+
- __call__
37+
38+
## StableDiffusion3PipelineOutput
39+
[[autodoc]] pipelines.stable_diffusion_3.pipeline_output.StableDiffusion3PipelineOutput

src/diffusers/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
"MultiAdapter",
9292
"PixArtTransformer2DModel",
9393
"PriorTransformer",
94+
"SD3ControlNetModel",
95+
"SD3MultiControlNetModel",
9496
"SD3Transformer2DModel",
9597
"StableCascadeUNet",
9698
"T2IAdapter",
@@ -278,6 +280,7 @@
278280
"StableCascadeCombinedPipeline",
279281
"StableCascadeDecoderPipeline",
280282
"StableCascadePriorPipeline",
283+
"StableDiffusion3ControlNetPipeline",
281284
"StableDiffusion3Img2ImgPipeline",
282285
"StableDiffusion3Pipeline",
283286
"StableDiffusionAdapterPipeline",
@@ -501,6 +504,8 @@
501504
MultiAdapter,
502505
PixArtTransformer2DModel,
503506
PriorTransformer,
507+
SD3ControlNetModel,
508+
SD3MultiControlNetModel,
504509
SD3Transformer2DModel,
505510
T2IAdapter,
506511
T5FilmDecoder,
@@ -666,6 +671,7 @@
666671
StableCascadeCombinedPipeline,
667672
StableCascadeDecoderPipeline,
668673
StableCascadePriorPipeline,
674+
StableDiffusion3ControlNetPipeline,
669675
StableDiffusion3Img2ImgPipeline,
670676
StableDiffusion3Pipeline,
671677
StableDiffusionAdapterPipeline,

src/diffusers/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
_import_structure["autoencoders.consistency_decoder_vae"] = ["ConsistencyDecoderVAE"]
3434
_import_structure["autoencoders.vq_model"] = ["VQModel"]
3535
_import_structure["controlnet"] = ["ControlNetModel"]
36+
_import_structure["controlnet_sd3"] = ["SD3ControlNetModel", "SD3MultiControlNetModel"]
3637
_import_structure["controlnet_xs"] = ["ControlNetXSAdapter", "UNetControlNetXSModel"]
3738
_import_structure["embeddings"] = ["ImageProjection"]
3839
_import_structure["modeling_utils"] = ["ModelMixin"]
@@ -74,6 +75,7 @@
7475
VQModel,
7576
)
7677
from .controlnet import ControlNetModel
78+
from .controlnet_sd3 import SD3ControlNetModel, SD3MultiControlNetModel
7779
from .controlnet_xs import ControlNetXSAdapter, UNetControlNetXSModel
7880
from .embeddings import ImageProjection
7981
from .modeling_utils import ModelMixin

0 commit comments

Comments
 (0)