[Flux] Support Union ControlNet (#9175) · scornflake/diffusers@c1e6a32 · GitHub
Skip to content

Commit c1e6a32

Browse files
[Flux] Support Union ControlNet (huggingface#9175)
* refactor --------- Co-authored-by: haofanwang <haofanwang.ai@gmail.com>
1 parent 77b2162 commit c1e6a32

8 files changed

Lines changed: 320 additions & 9 deletions

File tree

‎docs/source/en/_toctree.yml‎

Lines changed: 4 additions & 0 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
# FluxControlNetModel
14+
15+
FluxControlNetModel is an implementation of ControlNet for Flux.1.
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 [`FluxControlNetModel`] should be loaded with [`~ModelMixin.from_pretrained`].
26+
27+
```py
28+
from diffusers import FluxControlNetPipeline
29+
from diffusers.models import FluxControlNetModel, FluxMultiControlNetModel
30+
31+
controlnet = FluxControlNetModel.from_pretrained("InstantX/FLUX.1-dev-Controlnet-Canny")
32+
pipe = FluxControlNetPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", controlnet=controlnet)
33+
34+
controlnet = FluxControlNetModel.from_pretrained("InstantX/FLUX.1-dev-Controlnet-Canny")
35+
controlnet = FluxMultiControlNetModel([controlnet])
36+
pipe = FluxControlNetPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", controlnet=controlnet)
37+
```
38+
39+
## FluxControlNetModel
40+
41+
[[autodoc]] FluxControlNetModel
42+
43+
## FluxControlNetOutput
44+
45+
[[autodoc]] models.controlnet_flux.FluxControlNetOutput
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
# ControlNet with Flux.1
14+
15+
FluxControlNetPipeline is an implementation of ControlNet for Flux.1.
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 controlnet code is implemented by [The InstantX Team](https://huggingface.co/InstantX). You can find pre-trained checkpoints for Flux-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/FLUX.1-dev-Controlnet-Canny) |
31+
| Depth | [The InstantX Team](https://huggingface.co/InstantX) | [Link](https://huggingface.co/Shakker-Labs/FLUX.1-dev-ControlNet-Depth) |
32+
| Union | [The InstantX Team](https://huggingface.co/InstantX) | [Link](https://huggingface.co/InstantX/FLUX.1-dev-Controlnet-Union) |
33+
34+
35+
<Tip>
36+
37+
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.
38+
39+
</Tip>
40+
41+
## FluxControlNetPipeline
42+
[[autodoc]] FluxControlNetPipeline
43+
- all
44+
- __call__
45+
46+
47+
## FluxPipelineOutput
48+
[[autodoc]] pipelines.flux.pipeline_output.FluxPipelineOutput

‎src/diffusers/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@
554554
ControlNetXSAdapter,
555555
DiTTransformer2DModel,
556556
FluxControlNetModel,
557+
FluxMultiControlNetModel,
557558
FluxTransformer2DModel,
558559
HunyuanDiT2DControlNetModel,
559560
HunyuanDiT2DModel,

‎src/diffusers/models/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
_import_structure["autoencoders.consistency_decoder_vae"] = ["ConsistencyDecoderVAE"]
3636
_import_structure["autoencoders.vq_model"] = ["VQModel"]
3737
_import_structure["controlnet"] = ["ControlNetModel"]
38-
_import_structure["controlnet_flux"] = ["FluxControlNetModel"]
38+
_import_structure["controlnet_flux"] = ["FluxControlNetModel", "FluxMultiControlNetModel"]
3939
_import_structure["controlnet_hunyuan"] = ["HunyuanDiT2DControlNetModel", "HunyuanDiT2DMultiControlNetModel"]
4040
_import_structure["controlnet_sd3"] = ["SD3ControlNetModel", "SD3MultiControlNetModel"]
4141
_import_structure["controlnet_sparsectrl"] = ["SparseControlNetModel"]
@@ -88,7 +88,7 @@
8888
VQModel,
8989
)
9090
from .controlnet import ControlNetModel
91-
from .controlnet_flux import FluxControlNetModel
91+
from .controlnet_flux import FluxControlNetModel, FluxMultiControlNetModel
9292
from .controlnet_hunyuan import HunyuanDiT2DControlNetModel, HunyuanDiT2DMultiControlNetModel
9393
from .controlnet_sd3 import SD3ControlNetModel, SD3MultiControlNetModel
9494
from .controlnet_sparsectrl import SparseControlNetModel

‎src/diffusers/models/controlnet_flux.py‎

Lines changed: 134 additions & 3 deletions

0 commit comments

Comments
 (0)