|
1 | 1 | # comfyui-hydit |
| 2 | +The ComfyUI code is under review in the official repository. Meanwhile, a temporary version is available below for immediate community use. |
| 3 | +We welcome users to try our workflow and appreciate any inquiries or suggestions. |
2 | 4 |
|
3 | | -This repository houses a tailored node and workflow designed specifically for HunYuan DIT. The official tests conducted on DDPM, DDIM, and DPMMS have consistently yielded results that align with those obtained through the Diffusers library. However, it's important to note that we cannot assure the consistency of results from other ComfyUI native samplers with the Diffusers inference. We cordially invite users to explore our workflow and are open to receiving any inquiries or suggestions you may have. |
4 | 5 |
|
5 | 6 | ## Overview |
| 7 | +- Support two workflows: Standard ComfyUI and Diffusers Wrapper, with the former being recommended. |
| 8 | +- Support HunyuanDiT-v1.1 and v1.2. |
| 9 | +- Support module, lora and clip lora models trained by Kohya. |
| 10 | +- Support module, lora models trained by HunyunDiT official training scripts. |
| 11 | +- ControlNet is coming soon. |
6 | 12 |
|
| 13 | +### Standard Workflow (Recommended) |
| 14 | +- [HunyuanDiT-v1.2](workflow/workflow_v1.2_lora.json) |
| 15 | + |
7 | 16 |
|
8 | | -### Workflow text2image |
| 17 | +- [HunyuanDiT-v1.1](workflow/workflow_v1.1_lora.json) |
| 18 | + |
9 | 19 |
|
10 | | - |
11 | | -[workflow_diffusers](workflow/workflow_diffusers.json) file for HunyuanDiT txt2image with diffusers backend. |
12 | | - |
13 | | -[workflow_ksampler](workflow/workflow_ksampler.json) file for HunyuanDiT txt2image with ksampler backend. |
| 20 | +### Diffusers Wrapper |
| 21 | +- [HunyuanDiT-v1.1-diffusers](workflow/workflow_lora_controlnet.json) |
14 | 22 |  |
15 | | -[workflow_lora_controlnet_diffusers](workflow/workflow_lora_controlnet.json) file for HunyuanDiT lora and controlnet model with diffusers backend. |
16 | 23 |
|
17 | 24 |
|
18 | 25 | ## Usage |
| 26 | +### Dependencies |
19 | 27 |
|
20 | | -Make sure you run the following command inside [ComfyUI](https://github.com/comfyanonymous/ComfyUI) project with our [comfyui-hydit](.) and have correct conda environment. |
21 | | - |
| 28 | +1. Official ComfyUI Environment Setup |
22 | 29 | ```shell |
23 | 30 | # Please use python 3.10 version with cuda 11.7 |
| 31 | +conda create --name comfyui-hydit python=3.10 |
| 32 | +conda activate comfyui-hydit |
| 33 | + |
24 | 34 | # Download comfyui code |
25 | 35 | git clone https://github.com/comfyanonymous/ComfyUI.git |
| 36 | +cd ${ComfyUI} |
| 37 | +git reset --hard 90389b3b8a69c08c3ed0bcc9d87a92246578a8e3 |
26 | 38 |
|
27 | 39 | # Install torch, torchvision, torchaudio |
28 | 40 | pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117 --default-timeout=100 future |
29 | 41 |
|
30 | 42 | # Install Comfyui essential python package |
31 | | -cd ComfyUI |
32 | 43 | pip install -r requirements.txt |
| 44 | +``` |
33 | 45 |
|
34 | | -# ComfyUI has been successfully installed! |
35 | | - |
36 | | - |
| 46 | +2. HunyuanDiT Environment Setup in ComfyUI |
| 47 | +```shell |
37 | 48 | # Move to the ComfyUI custom_nodes folder and copy comfyui-hydit folder from HunyuanDiT Repo. |
38 | | -cd custom_nodes |
| 49 | +cd ${ComfyUI}/custom_nodes |
39 | 50 | git clone https://github.com/Tencent/HunyuanDiT.git |
40 | 51 | cp -r HunyuanDiT/comfyui-hydit ./ |
41 | 52 | rm -rf HunyuanDiT |
42 | | -cd comfyui-hydit |
| 53 | +cd ${ComfyUI}/custom_nodes/comfyui-hydit |
43 | 54 |
|
44 | | -# !!! If using windows system !!! |
45 | | -cd custom_nodes |
| 55 | +# Install some essential python Package. |
| 56 | +pip install -r requirements.txt |
| 57 | +``` |
| 58 | + |
| 59 | +3. (Optional) Deployment on Windows environment |
| 60 | +```shell |
| 61 | +cd ${ComfyUI}/custom_nodes |
46 | 62 | git clone https://github.com/Tencent/HunyuanDiT.git |
47 | 63 | xcopy /E /I HunyuanDiT\comfyui-hydit comfyui-hydit |
48 | 64 | rmdir /S /Q HunyuanDiT |
49 | | -cd comfyui-hydit |
50 | | - |
| 65 | +cd ${ComfyUI}/custom_nodes/comfyui-hydit |
51 | 66 | # Install some essential python Package. |
52 | 67 | pip install -r requirements.txt |
| 68 | +``` |
53 | 69 |
|
54 | | -# Our tool has been successfully installed! |
55 | | - |
| 70 | +4. Running ComfyUI successfully |
| 71 | +```shell |
56 | 72 | # Go to ComfyUI main folder |
57 | | -cd ../.. |
| 73 | +cd ${ComfyUI} |
58 | 74 | # Run the ComfyUI Lauch command |
59 | 75 | python main.py --listen --port 80 |
| 76 | +``` |
| 77 | + |
| 78 | +### Standard workflow (Recommended) |
| 79 | + |
| 80 | +1. Preparing Model Weights |
| 81 | + |
| 82 | +Use the command below to download the file to the specified folder. If already downloaded, create a symbolic link to that folder. |
| 83 | +```shell |
| 84 | +# clip encoder |
| 85 | +wget -O ${ComfyUI}/models/clip/pytorch_model.bin https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2/blob/main/t2i/clip_text_encoder/pytorch_model.bin |
| 86 | +# mt5 |
| 87 | +mkdir ${ComfyUI}/models/t5 |
| 88 | +wget -O ${ComfyUI}/models/t5/pytorch_model.bin https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2/blob/main/t2i/mt5/pytorch_model.bin |
| 89 | +# vae |
| 90 | +wget -O ${ComfyUI}/models/vae/diffusion_pytorch_model.bin https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2/blob/main/t2i/sdxl-vae-fp16-fix/diffusion_pytorch_model.bin |
| 91 | +# base model |
| 92 | +wget -O ${ComfyUI}/models/checkpoints/pytorch_model_ema.pt https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2/blob/main/t2i/model/pytorch_model_ema.pt |
| 93 | +``` |
| 94 | +Put module weights trained through Kohya or the official script in `${ComfyUI}/models/checkpoints/` to switch model weights in ComfyUI. |
| 95 | + |
| 96 | +2. Preparing LoRa Weights |
60 | 97 |
|
61 | | -# Running ComfyUI successfully! |
| 98 | +```shell |
| 99 | +# Put LoRa weights trained by Kohya in ComfyUI/models/loras |
| 100 | +cp ${HunyuanDiT}/kohya_ss/outputs/last-step{xxxx}.safetensors ${ComfyUI}/models/loras |
| 101 | + |
| 102 | +# (Optional) Put LoRa weights trained by official scripts in ComfyUI/models/loras |
| 103 | +python convert_hunyuan_to_coimfyui_lora.py \ |
| 104 | + --lora_path ${HunyuanDiT}/log_EXP/001-lora_porcelain_ema_rank64/checkpoints/0000100.pt/adapter_model.safetensors \ |
| 105 | + --save_lora_path ${ComfyUI}/models/loras/adapter_model_convert.safetensors |
| 106 | + |
| 107 | +# update the `lora.py` file |
| 108 | +cp ${ComfyUI}/custom_nodes/comfyui-hydit/lora.py ${ComfyUI}/comfy/lora.py |
62 | 109 | ``` |
63 | 110 |
|
64 | | -## Download weights for diffusers mode |
| 111 | +### Diffusers Wrapper |
| 112 | +1. Preparing Model Weights |
65 | 113 |
|
66 | 114 | ```shell |
67 | 115 | python -m pip install "huggingface_hub[cli]" |
68 | 116 | mkdir models/hunyuan |
69 | | -huggingface-cli download Tencent-Hunyuan/HunyuanDiT-v1.1 --local-dir ./models/hunyuan/ckpts |
70 | | -huggingface-cli download Tencent-Hunyuan/Distillation-v1.1 pytorch_model_distill.pt --local-dir ./models/hunyuan/ckpts/t2i/model |
| 117 | +huggingface-cli download Tencent-Hunyuan/HunyuanDiT-v1.2 --local-dir ./models/hunyuan/ckpts |
| 118 | +huggingface-cli download Tencent-Hunyuan/HunyuanDiT-v1.2 t2i/model/pytorch_model_ema.pt --local-dir ./models/hunyuan/ckpts/t2i/model |
71 | 119 | ``` |
72 | 120 |
|
73 | | -## Download weights for ksampler mode |
74 | | -Download the [clip encoder](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/blob/main/t2i/clip_text_encoder/pytorch_model.bin) and place it in `ComfyUI/models/clip` |
75 | | -Download the [mt5](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/blob/main/t2i/mt5/pytorch_model.bin) and place it in `ComfyUI/models/t5` |
76 | | -Download the [base model](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/blob/main/t2i/model/pytorch_model_ema.pt) and place it in `ComfyUI/models/checkpoints` |
77 | | -Download the [sdxl vae](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/blob/main/t2i/sdxl-vae-fp16-fix/diffusion_pytorch_model.bin) and place it in `ComfyUI/models/vae` |
| 121 | +2. Preparing LoRa Weights |
78 | 122 |
|
| 123 | +```shell |
| 124 | +# Put LoRa weights trained by Kohya in ComfyUI/models/loras |
| 125 | +cp ${HunyuanDiT}/kohya_ss/outputs/adapter_model.safetensors ${ComfyUI}/models/loras |
| 126 | + |
| 127 | +# (Optional) Put LoRa weights trained by official scripts in ComfyUI/models/loras |
| 128 | +# The PEFT diffuser format needs to be converted into the standard ComfyUI format |
| 129 | +python convert_hunyuan_to_coimfyui_lora.py \ |
| 130 | + --lora_path ${HunyuanDiT}/log_EXP/001-lora_porcelain_ema_rank64/checkpoints/0000100.pt/adapter_model.safetensors \ |
| 131 | + --save_lora_path ${ComfyUI}/models/loras/adapter_model_convert.safetensors |
| 132 | + |
| 133 | +# update the `lora.py` file |
| 134 | +cp ${ComfyUI}/custom_nodes/comfyui-hydit/lora.py ${ComfyUI}/comfy/lora.py |
| 135 | +``` |
79 | 136 |
|
80 | 137 | ## Custom Node |
81 | 138 | Below I'm trying to document all the nodes, thanks for some good work[[1]](#1)[[2]](#2). |
82 | | -#### HunYuan Pipeline Loader |
| 139 | +### HunYuan Pipeline Loader |
83 | 140 | - Loads the full stack of models needed for HunYuanDiT. |
84 | 141 | - **pipeline_folder_name** is the official weight folder path for hunyuan dit including clip_text_encoder, model, mt5, sdxl-vae-fp16-fix and tokenizer. |
85 | 142 | - **lora** optional to load lora weight. |
86 | 143 |
|
87 | | -#### HunYuan Checkpoint Loader |
| 144 | +### HunYuan Checkpoint Loader |
88 | 145 | - Loads the base model for HunYuanDiT in ksampler backend. |
89 | 146 | - **model_name** is the weight list of comfyui checkpoint folder. |
| 147 | +- **version** two option, v1.1 and v1.2. |
90 | 148 |
|
91 | 149 |
|
92 | | -#### HunYuan CLIP Loader |
| 150 | +### HunYuan CLIP Loader |
93 | 151 | - Loads the clip and mt5 model for HunYuanDiT in ksampler backend. |
94 | 152 | - **text_encoder_path** is the weight list of comfyui clip model folder. |
95 | 153 | - **t5_text_encoder_path** is the weight list of comfyui t5 model folder. |
96 | 154 |
|
97 | | -#### HunYuan VAE Loader |
| 155 | +### HunYuan VAE Loader |
98 | 156 | - Loads the vae model for HunYuanDiT in ksampler backend. |
99 | 157 | - **model_name** is the weight list of comfyui vae model folder. |
100 | 158 |
|
101 | | -#### HunYuan Scheduler Loader |
| 159 | +### HunYuan Scheduler Loader |
102 | 160 | - Loads the scheduler algorithm for HunYuanDiT. |
103 | 161 | - **Input** is the algorithm name including ddpm, ddim and dpmms. |
104 | 162 | - **Output** is the instance of diffusers.schedulers. |
105 | 163 |
|
106 | | -#### HunYuan Model Makeup |
| 164 | +### HunYuan Model Makeup |
107 | 165 | - Assemble the models and scheduler module. |
108 | 166 | - **Input** is the instance of StableDiffusionPipeline and diffusers.schedulers. |
109 | 167 | - **Output** is the updated instance of StableDiffusionPipeline. |
110 | 168 |
|
111 | | -#### HunYuan Clip Text Encode |
| 169 | +### HunYuan Clip Text Encode |
112 | 170 | - Assemble the models and scheduler module. |
113 | 171 | - **Input** is the string of positive and negative prompts. |
114 | 172 | - **Output** is the converted string for model. |
115 | 173 |
|
116 | | -#### HunYuan Sampler |
| 174 | +### HunYuan Sampler |
117 | 175 | - Similar with KSampler in ComfyUI. |
118 | 176 | - **Input** is the instance of StableDiffusionPipeline and some hyper-parameters for sampling. |
119 | 177 | - **Output** is the generated image. |
120 | 178 |
|
121 | | -#### HunYuan Lora Loader |
| 179 | +### HunYuan Lora Loader |
122 | 180 | - Loads the lora model for HunYuanDiT in diffusers backend. |
123 | 181 | - **lora_name** is the weight list of comfyui lora folder. |
124 | 182 |
|
125 | | -#### HunYuan ControNet Loader |
| 183 | +### HunYuan ControNet Loader |
126 | 184 | - Loads the controlnet model for HunYuanDiT in diffusers backend. |
127 | 185 | - **controlnet_path** is the weight list of comfyui controlnet folder. |
128 | 186 |
|
|
0 commit comments