Skip to content

Commit fa2abfd

Browse files
gnobitabxingchaoliuyiyixuxu
authored
[Tencent Hunyuan Team] Add Hunyuan-DiT ControlNet Inference (huggingface#8694)
* add controlnet support --------- Co-authored-by: xingchaoliu <[email protected]> Co-authored-by: yiyixuxu <yixu310@gmail,com>
1 parent 1d3ef67 commit fa2abfd

File tree

15 files changed

+1988
-3
lines changed

15 files changed

+1988
-3
lines changed

docs/source/en/_toctree.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@
257257
title: PriorTransformer
258258
- local: api/models/controlnet
259259
title: ControlNetModel
260+
- local: api/models/controlnet_hunyuandit
261+
title: HunyuanDiT2DControlNetModel
260262
- local: api/models/controlnet_sd3
261263
title: SD3ControlNetModel
262264
title: Models
@@ -282,6 +284,8 @@
282284
title: Consistency Models
283285
- local: api/pipelines/controlnet
284286
title: ControlNet
287+
- local: api/pipelines/controlnet_hunyuandit
288+
title: ControlNet with Hunyuan-DiT
285289
- local: api/pipelines/controlnet_sd3
286290
title: ControlNet with Stable Diffusion 3
287291
- local: api/pipelines/controlnet_sdxl
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!--Copyright 2024 The HuggingFace Team and Tencent Hunyuan 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+
# HunyuanDiT2DControlNetModel
14+
15+
HunyuanDiT2DControlNetModel is an implementation of ControlNet for [Hunyuan-DiT](https://arxiv.org/abs/2405.08748).
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 Hunyuan-DiT 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 Tencent Hunyuan Team. You can find pre-trained checkpoints for Hunyuan-DiT ControlNets on [Tencent Hunyuan](https://huggingface.co/Tencent-Hunyuan).
26+
27+
## Example For Loading HunyuanDiT2DControlNetModel
28+
29+
```py
30+
from diffusers import HunyuanDiT2DControlNetModel
31+
import torch
32+
controlnet = HunyuanDiT2DControlNetModel.from_pretrained("Tencent-Hunyuan/HunyuanDiT-v1.1-ControlNet-Diffusers-Pose", torch_dtype=torch.float16)
33+
```
34+
35+
## HunyuanDiT2DControlNetModel
36+
37+
[[autodoc]] HunyuanDiT2DControlNetModel
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--Copyright 2024 The HuggingFace Team and Tencent Hunyuan 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 Hunyuan-DiT
14+
15+
HunyuanDiTControlNetPipeline is an implementation of ControlNet for [Hunyuan-DiT](https://arxiv.org/abs/2405.08748).
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 Hunyuan-DiT 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 Tencent Hunyuan Team. You can find pre-trained checkpoints for Hunyuan-DiT ControlNets on [Tencent Hunyuan](https://huggingface.co/Tencent-Hunyuan).
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+
## HunyuanDiTControlNetPipeline
34+
[[autodoc]] HunyuanDiTControlNetPipeline
35+
- all
36+
- __call__

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
1+
<!--Copyright 2024 The HuggingFace Team and Tencent Hunyuan 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

src/diffusers/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
"ControlNetModel",
8484
"ControlNetXSAdapter",
8585
"DiTTransformer2DModel",
86+
"HunyuanDiT2DControlNetModel",
8687
"HunyuanDiT2DModel",
88+
"HunyuanDiT2DMultiControlNetModel",
8789
"I2VGenXLUNet",
8890
"Kandinsky3UNet",
8991
"ModelMixin",
@@ -234,6 +236,7 @@
234236
"BlipDiffusionPipeline",
235237
"CLIPImageProjection",
236238
"CycleDiffusionPipeline",
239+
"HunyuanDiTControlNetPipeline",
237240
"HunyuanDiTPipeline",
238241
"I2VGenXLPipeline",
239242
"IFImg2ImgPipeline",
@@ -500,7 +503,9 @@
500503
ControlNetModel,
501504
ControlNetXSAdapter,
502505
DiTTransformer2DModel,
506+
HunyuanDiT2DControlNetModel,
503507
HunyuanDiT2DModel,
508+
HunyuanDiT2DMultiControlNetModel,
504509
I2VGenXLUNet,
505510
Kandinsky3UNet,
506511
ModelMixin,
@@ -629,6 +634,7 @@
629634
AudioLDMPipeline,
630635
CLIPImageProjection,
631636
CycleDiffusionPipeline,
637+
HunyuanDiTControlNetPipeline,
632638
HunyuanDiTPipeline,
633639
I2VGenXLPipeline,
634640
IFImg2ImgPipeline,

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_hunyuan"] = ["HunyuanDiT2DControlNetModel", "HunyuanDiT2DMultiControlNetModel"]
3637
_import_structure["controlnet_sd3"] = ["SD3ControlNetModel", "SD3MultiControlNetModel"]
3738
_import_structure["controlnet_xs"] = ["ControlNetXSAdapter", "UNetControlNetXSModel"]
3839
_import_structure["embeddings"] = ["ImageProjection"]
@@ -75,6 +76,7 @@
7576
VQModel,
7677
)
7778
from .controlnet import ControlNetModel
79+
from .controlnet_hunyuan import HunyuanDiT2DControlNetModel, HunyuanDiT2DMultiControlNetModel
7880
from .controlnet_sd3 import SD3ControlNetModel, SD3MultiControlNetModel
7981
from .controlnet_xs import ControlNetXSAdapter, UNetControlNetXSModel
8082
from .embeddings import ImageProjection

0 commit comments

Comments
 (0)