1cd HunyuanDiT
2# Use the huggingface-cli tool to download the model.
3# We recommend using distilled weights as the base model for ControlNet inference, as our provided pretrained weights are trained on them.
4huggingface-cli download Tencent-Hunyuan/HYDiT-ControlNet-v1.2 --local-dir ./ckpts/t2i/controlnet
5huggingface-cli download Tencent-Hunyuan/Distillation-v1.2 ./pytorch_model_distill.pt --local-dir ./ckpts/t2i/model
6
7# Quick start
8python sample_controlnet.py --infer-mode fa --no-enhance --load-key distill --infer-steps 50 --control-type canny --prompt "在夜晚的酒店门前,一座古老的中国风格的狮子雕像矗立着,它的眼睛闪烁着光芒,仿佛在守护着这座建筑。背景是夜晚的酒店前,构图方式是特写,平视,居中构图。这张照片呈现了真实摄影风格,蕴含了中国雕塑文化,同时展现了神秘氛围" --condition-image-path controlnet/asset/input/canny.jpg --control-weight 1.0| Condition Input | ||
| Canny ControlNet | Depth ControlNet | Pose ControlNet |
| 在夜晚的酒店门前,一座古老的中国风格的狮子雕像矗立着,它的眼睛闪烁着光芒,仿佛在守护着这座建筑。背景是夜晚的酒店前,构图方式是特写,平视,居中构图。这张照片呈现了真实摄影风格,蕴含了中国雕塑文化,同时展现了神秘氛围 (At night, an ancient Chinese-style lion statue stands in front of the hotel, its eyes gleaming as if guarding the building. The background is the hotel entrance at night, with a close-up, eye-level, and centered composition. This photo presents a realistic photographic style, embodies Chinese sculpture culture, and reveals a mysterious atmosphere.) | 在茂密的森林中,一只黑白相间的熊猫静静地坐在绿树红花中,周围是山川和海洋。背景是白天的森林,光线充足。照片采用特写、平视和居中构图的方式,呈现出写实的效果 (In the dense forest, a black and white panda sits quietly among the green trees and red flowers, surrounded by mountains and oceans. The background is a daytime forest with ample light. The photo uses a close-up, eye-level, and centered composition to create a realistic effect.) | 在白天的森林中,一位穿着绿色上衣的亚洲女性站在大象旁边。照片采用了中景、平视和居中构图的方式,呈现出写实的效果。这张照片蕴含了人物摄影文化,并展现了宁静的氛围 (In the daytime forest, an Asian woman wearing a green shirt stands beside an elephant. The photo uses a medium shot, eye-level, and centered composition to create a realistic effect. This picture embodies the character photography culture and conveys a serene atmosphere.) |
![]() | ![]() | ![]() |
| ControlNet Output | ||
![]() | ![]() | ![]() |
hydit/annotator/ckpts directory. We provide serveral commands to quick install:1mkdir ./hydit/annotator/ckpts
2wget -O ./hydit/annotator/ckpts/dwpose.zip https://dit.hunyuan.tencent.com/download/HunyuanDiT/dwpose.zip
3unzip ./hydit/annotator/ckpts/dwpose.zip -d ./hydit/annotator/ckpts/1pip install matplotlib==3.7.5
2pip install onnxruntime_gpu==1.16.3
3pip install opencv-python==4.8.1.78ema, module and distill, and you can choose according to the actual effects. By default, we use distill weights.distill weights into the main model and conduct ControlNet training.--multireso and --reso-step 64 parameter.1task_flag="canny_controlnet" # the task flag is used to identify folders.
2control_type=canny
3resume_module_root=./ckpts/t2i/model/pytorch_model_distill.pt # checkpoint root for resume
4index_file=/path/to/your/indexfile # index file for dataloader
5results_dir=./log_EXP # save root for results
6batch_size=1 # training batch size
7image_size=1024 # training image resolution
8grad_accu_steps=2 # gradient accumulation
9warmup_num_steps=0 # warm-up steps
10lr=0.0001 # learning rate
11ckpt_every=10000 # create a ckpt every a few steps.
12ckpt_latest_every=5000 # create a ckpt named `latest.pt` every a few steps.
13epochs=100 # total training epochs
14
15
16sh $(dirname "$0")/run_g_controlnet.sh \
17 --task-flag ${task_flag} \
18 --control-type ${control_type} \
19 --noise-schedule scaled_linear --beta-start 0.00085 --beta-end 0.018 \
20 --predict-type v_prediction \
21 --uncond-p 0.44 \
22 --uncond-p-t5 0.44 \
23 --index-file ${index_file} \
24 --random-flip \
25 --lr ${lr} \
26 --batch-size ${batch_size} \
27 --image-size ${image_size} \
28 --global-seed 999 \
29 --grad-accu-steps ${grad_accu_steps} \
30 --warmup-num-steps ${warmup_num_steps} \
31 --use-flash-attn \
32 --use-fp16 \
33 --results-dir ${results_dir} \
34 --resume \
35 --resume-module-root ${resume_module_root} \
36 --epochs ${epochs} \
37 --ckpt-every ${ckpt_every} \
38 --ckpt-latest-every ${ckpt_latest_every} \
39 --log-every 10 \
40 --deepspeed \
41 --deepspeed-optimizer \
42 --use-zero-stage 2 \
43 --gradient-checkpointing \
44 "$@"
45| Parameter | Description | Recommended Parameter Value | Note |
|---|---|---|---|
--batch-size | Training batch size | 1 | Depends on GPU memory |
--grad-accu-steps | Size of gradient accumulation | 2 | - |
--lr | Learning rate | 0.0001 | - |
--control-type | ControlNet condition type, support 3 types now (canny, depth and pose) | / | - |
python sample_controlnet.py --infer-mode fa --control-weight "[1.0 * (0.825 ** float(19 - i)) for i in range(19)]" --no-enhance --load-key distill --infer-steps 50 --control-type canny --prompt "在夜晚的酒店门前,一座古老的中国风格的狮子雕像矗立着,它的眼睛闪烁着光芒,仿佛在守护着这座建筑。背景是夜晚的酒店前,构图方式是特写,平视,居中构图。这张照片呈现了真实摄影风格,蕴含了中国雕塑文化,同时展现了神秘氛围" --condition-image-path controlnet/asset/input/canny.jpgpython sample_controlnet.py --infer-mode fa --control-weight 1.0 --no-enhance --load-key distill --infer-steps 50 --control-type canny --prompt "在夜晚的酒店门前,一座古老的中国风格的狮子雕像矗立着,它的眼睛闪烁着光芒,仿佛在守护着这座建筑。背景是夜晚的酒店前,构图方式是特写,平视,居中构图。这张照片呈现了真实摄影风格,蕴含了中国雕塑文化,同时展现了神秘氛围" --condition-image-path controlnet/asset/input/canny.jpgpython sample_controlnet.py --infer-mode fa --control-weight 1.0 --no-enhance --load-key distill --infer-steps 50 --control-type depth --prompt "在茂密的森林中,一只黑白相间的熊猫静静地坐在绿树红花中,周围是山川和海洋。背景是白天的森林,光线充足。照片采用特写、平视和居中构图的方式,呈现出写实的效果" --condition-image-path controlnet/asset/input/depth.jpgpython3 sample_controlnet.py --infer-mode fa --control-weight 1.0 --no-enhance --load-key distill --infer-steps 50 --control-type pose --prompt "在白天的森林中,一位穿着绿色上衣的亚洲女性站在大象旁边。照片采用了中景、平视和居中构图的方式,呈现出写实的效果。这张照片蕴含了人物摄影文化,并展现了宁静的氛围" --condition-image-path controlnet/asset/input/pose.jpg1cd HunyuanDiT
2# Use the huggingface-cli tool to download the model.
3# We recommend using distilled weights as the base model for ControlNet inference, as our provided pretrained weights are trained on them.
4huggingface-cli download Tencent-Hunyuan/HYDiT-ControlNet-v1.1 --local-dir ./HunyuanDiT-v1.1/t2i/controlnet
5huggingface-cli download Tencent-Hunyuan/Distillation-v1.1 ./pytorch_model_distill.pt --local-dir ./HunyuanDiT-v1.1/t2i/model1task_flag="canny_controlnet" # the task flag is used to identify folders.
2control_type=canny
3resume_module_root=./ckpts/t2i/model/pytorch_model_distill.pt # checkpoint root for resume
4index_file=/path/to/your/indexfile # index file for dataloader
5results_dir=./log_EXP # save root for results
6batch_size=1 # training batch size
7image_size=1024 # training image resolution
8grad_accu_steps=2 # gradient accumulation
9warmup_num_steps=0 # warm-up steps
10lr=0.0001 # learning rate
11ckpt_every=10000 # create a ckpt every a few steps.
12ckpt_latest_every=5000 # create a ckpt named `latest.pt` every a few steps.
13epochs=100 # total training epochs
14
15
16sh $(dirname "$0")/run_g_controlnet.sh \
17 --task-flag ${task_flag} \
18 --control-type ${control_type} \
19 --noise-schedule scaled_linear --beta-start 0.00085 --beta-end 0.03 \
20 --predict-type v_prediction \
21 --multireso \
22 --reso-step 64 \
23 --uncond-p 0.44 \
24 --uncond-p-t5 0.44 \
25 --index-file ${index_file} \
26 --random-flip \
27 --lr ${lr} \
28 --batch-size ${batch_size} \
29 --image-size ${image_size} \
30 --global-seed 999 \
31 --grad-accu-steps ${grad_accu_steps} \
32 --warmup-num-steps ${warmup_num_steps} \
33 --use-flash-attn \
34 --use-fp16 \
35 --results-dir ${results_dir} \
36 --resume \
37 --resume-module-root ${resume_module_root} \
38 --epochs ${epochs} \
39 --ckpt-every ${ckpt_every} \
40 --ckpt-latest-every ${ckpt_latest_every} \
41 --log-every 10 \
42 --deepspeed \
43 --deepspeed-optimizer \
44 --use-zero-stage 2 \
45 --use-style-cond \
46 --size-cond 1024 1024 \
47 "$@"python3 sample_controlnet.py --no-enhance --load-key distill --infer-steps 50 --control-type canny --prompt "在夜晚的酒店门前,一座古老的中国风格的狮子雕像矗立着,它的眼睛闪烁着光芒,仿佛在守护着这座建筑。背景是夜晚的酒店前,构图方式是特写,平视,居中构图。这张照片呈现了真实摄影风格,蕴含了中国雕塑文化,同时展现了神秘氛围" --condition-image-path controlnet/asset/input/canny.jpg --control-weight 1.0 --use-style-cond --size-cond 1024 1024 --beta-end 0.03python3 sample_controlnet.py --no-enhance --load-key distill --infer-steps 50 --control-type depth --prompt "在茂密的森林中,一只黑白相间的熊猫静静地坐在绿树红花中,周围是山川和海洋。背景是白天的森林,光线充足" --condition-image-path controlnet/asset/input/depth.jpg --control-weight 1.0 --use-style-cond --size-cond 1024 1024 --beta-end 0.03python3 sample_controlnet.py --no-enhance --load-key distill --infer-steps 50 --control-type pose --prompt "一位亚洲女性,身穿绿色上衣,戴着紫色头巾和紫色围巾,站在黑板前。背景是黑板。照片采用近景、平视和居中构图的方式呈现真实摄影风格" --condition-image-path controlnet/asset/input/pose.jpg --control-weight 1.0 --use-style-cond --size-cond 1024 1024 --beta-end 0.03