HunyuanDiT
Diffusers
Safetensors
English
Chinese
Zhiminli commited on
Commit
5775244
1 Parent(s): d7dd520

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +1 -566
README.md CHANGED
@@ -7,569 +7,4 @@ language:
7
  - en
8
  - zh
9
  ---
10
- <!-- ## **HunyuanDiT** -->
11
-
12
- <p align="center">
13
- <img src="https://raw.githubusercontent.com/Tencent/HunyuanDiT/main/asset/logo.png" height=100>
14
- </p>
15
-
16
- # Hunyuan-DiT : A Powerful Multi-Resolution Diffusion Transformer with Fine-Grained Chinese Understanding
17
-
18
-
19
- This repo contains PyTorch model definitions, pre-trained weights and inference/sampling code for our paper exploring Hunyuan-DiT. You can find more visualizations on our [project page](https://dit.hunyuan.tencent.com/).
20
-
21
- > [**Hunyuan-DiT: A Powerful Multi-Resolution Diffusion Transformer with Fine-Grained Chinese Understanding**](https://arxiv.org/abs/2405.08748) <br>
22
-
23
- > [**DialogGen: Multi-modal Interactive Dialogue System for Multi-turn Text-to-Image Generation**](https://arxiv.org/abs/2403.08857) <br>
24
-
25
- ## 🔥🔥🔥 News!!
26
- * Jun 13, 2024: :zap: HYDiT-v1.1 version is released, which mitigates the issue of image oversaturation and alleviates the watermark issue. Please check [HunyuanDiT-v1.1 ](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.1) and
27
- [Distillation-v1.1](https://huggingface.co/Tencent-Hunyuan/Distillation-v1.1) for more details.
28
- * Jun 13, 2024: :truck: The training code is released, offering [full-parameter training](#full-parameter-training) and [LoRA training](#lora).
29
- * Jun 06, 2024: :tada: Hunyuan-DiT is now available in ComfyUI. Please check [ComfyUI](#using-comfyui) for more details.
30
- * Jun 06, 2024: 🚀 We introduce Distillation version for Hunyuan-DiT acceleration, which achieves **50%** acceleration on NVIDIA GPUs. Please check [Distillation](https://huggingface.co/Tencent-Hunyuan/Distillation) for more details.
31
- * Jun 05, 2024: 🤗 Hunyuan-DiT is now available in 🤗 Diffusers! Please check the [example](#using--diffusers) below.
32
- * Jun 04, 2024: :globe_with_meridians: Support Tencent Cloud links to download the pretrained models! Please check the [links](#-download-pretrained-models) below.
33
- * May 22, 2024: 🚀 We introduce TensorRT version for Hunyuan-DiT acceleration, which achieves **47%** acceleration on NVIDIA GPUs. Please check [TensorRT-libs](https://huggingface.co/Tencent-Hunyuan/TensorRT-libs) for instructions.
34
- * May 22, 2024: 💬 We support demo running multi-turn text2image generation now. Please check the [script](#using-gradio) below.
35
-
36
- ## 🤖 Try it on the web
37
-
38
- Welcome to our web-based [**Tencent Hunyuan Bot**](https://hunyuan.tencent.com/bot/chat), where you can explore our innovative products! Just input the suggested prompts below or any other **imaginative prompts containing drawing-related keywords** to activate the Hunyuan text-to-image generation feature. Unleash your creativity and create any picture you desire, **all for free!**
39
-
40
- You can use simple prompts similar to natural language text
41
-
42
- > 画一只穿着西装的猪
43
- >
44
- > draw a pig in a suit
45
- >
46
- > 生成一幅画,赛博朋克风,跑车
47
- >
48
- > generate a painting, cyberpunk style, sports car
49
-
50
- or multi-turn language interactions to create the picture.
51
-
52
- > 画一个木制的鸟
53
- >
54
- > draw a wooden bird
55
- >
56
- > 变成玻璃的
57
- >
58
- > turn into glass
59
-
60
- ## 📑 Open-source Plan
61
-
62
- - Hunyuan-DiT (Text-to-Image Model)
63
- - [x] Inference
64
- - [x] Checkpoints
65
- - [x] Distillation Version
66
- - [x] TensorRT Version
67
- - [x] Training
68
- - [x] Lora
69
- - [ ] Controlnet (Pose, Canny, Depth, Tile)
70
- - [ ] IP-adapter
71
- - [ ] Hunyuan-DiT-XL checkpoints (0.7B model)
72
- - [ ] Caption model (Re-caption the raw image-text pairs)
73
- - [DialogGen](https://github.com/Centaurusalpha/DialogGen) (Prompt Enhancement Model)
74
- - [x] Inference
75
- - [X] Web Demo (Gradio)
76
- - [x] Multi-turn T2I Demo (Gradio)
77
- - [X] Cli Demo
78
- - [X] ComfyUI
79
- - [X] Diffusers
80
- - [ ] WebUI
81
-
82
-
83
- ## Contents
84
- - [Hunyuan-DiT](#hunyuan-dit--a-powerful-multi-resolution-diffusion-transformer-with-fine-grained-chinese-understanding)
85
- - [Abstract](#abstract)
86
- - [🎉 Hunyuan-DiT Key Features](#-hunyuan-dit-key-features)
87
- - [Chinese-English Bilingual DiT Architecture](#chinese-english-bilingual-dit-architecture)
88
- - [Multi-turn Text2Image Generation](#multi-turn-text2image-generation)
89
- - [📈 Comparisons](#-comparisons)
90
- - [🎥 Visualization](#-visualization)
91
- - [📜 Requirements](#-requirements)
92
- - [🛠 Dependencies and Installation](#%EF%B8%8F-dependencies-and-installation)
93
- - [🧱 Download Pretrained Models](#-download-pretrained-models)
94
- - [:truck: Training](#truck-training)
95
- - [Data Preparation](#data-preparation)
96
- - [Full Parameter Training](#full-parameter-training)
97
- - [LoRA](#lora)
98
- - [🔑 Inference](#-inference)
99
- - [Using Gradio](#using-gradio)
100
- - [Using Diffusers](#using--diffusers)
101
- - [Using Command Line](#using-command-line)
102
- - [More Configurations](#more-configurations)
103
- - [Using ComfyUI](#using-comfyui)
104
- - [🚀 Acceleration (for Linux)](#-acceleration-for-linux)
105
- - [🔗 BibTeX](#-bibtex)
106
-
107
- ## **Abstract**
108
-
109
- We present Hunyuan-DiT, a text-to-image diffusion transformer with fine-grained understanding of both English and Chinese. To construct Hunyuan-DiT, we carefully designed the transformer structure, text encoder, and positional encoding. We also build from scratch a whole data pipeline to update and evaluate data for iterative model optimization. For fine-grained language understanding, we train a Multimodal Large Language Model to refine the captions of the images. Finally, Hunyuan-DiT can perform multi-round multi-modal dialogue with users, generating and refining images according to the context.
110
- Through our carefully designed holistic human evaluation protocol with more than 50 professional human evaluators, Hunyuan-DiT sets a new state-of-the-art in Chinese-to-image generation compared with other open-source models.
111
-
112
-
113
- ## 🎉 **Hunyuan-DiT Key Features**
114
- ### **Chinese-English Bilingual DiT Architecture**
115
- Hunyuan-DiT is a diffusion model in the latent space, as depicted in figure below. Following the Latent Diffusion Model, we use a pre-trained Variational Autoencoder (VAE) to compress the images into low-dimensional latent spaces and train a diffusion model to learn the data distribution with diffusion models. Our diffusion model is parameterized with a transformer. To encode the text prompts, we leverage a combination of pre-trained bilingual (English and Chinese) CLIP and multilingual T5 encoder.
116
- <p align="center">
117
- <img src="https://raw.githubusercontent.com/Tencent/HunyuanDiT/main/asset/framework.png" height=450>
118
- </p>
119
-
120
- ### Multi-turn Text2Image Generation
121
- Understanding natural language instructions and performing multi-turn interaction with users are important for a
122
- text-to-image system. It can help build a dynamic and iterative creation process that bring the user’s idea into reality
123
- step by step. In this section, we will detail how we empower Hunyuan-DiT with the ability to perform multi-round
124
- conversations and image generation. We train MLLM to understand the multi-round user dialogue
125
- and output the new text prompt for image generation.
126
- <p align="center">
127
- <img src="https://raw.githubusercontent.com/Tencent/HunyuanDiT/main/asset/mllm.png" height=300>
128
- </p>
129
-
130
- ## 📈 Comparisons
131
- In order to comprehensively compare the generation capabilities of HunyuanDiT and other models, we constructed a 4-dimensional test set, including Text-Image Consistency, Excluding AI Artifacts, Subject Clarity, Aesthetic. More than 50 professional evaluators performs the evaluation.
132
-
133
- <p align="center">
134
- <table>
135
- <thead>
136
- <tr>
137
- <th rowspan="2">Model</th> <th rowspan="2">Open Source</th> <th>Text-Image Consistency (%)</th> <th>Excluding AI Artifacts (%)</th> <th>Subject Clarity (%)</th> <th rowspan="2">Aesthetics (%)</th> <th rowspan="2">Overall (%)</th>
138
- </tr>
139
- </thead>
140
- <tbody>
141
- <tr>
142
- <td>SDXL</td> <td> ✔ </td> <td>64.3</td> <td>60.6</td> <td>91.1</td> <td>76.3</td> <td>42.7</td>
143
- </tr>
144
- <tr>
145
- <td>PixArt-α</td> <td> ✔</td> <td>68.3</td> <td>60.9</td> <td>93.2</td> <td>77.5</td> <td>45.5</td>
146
- </tr>
147
- <tr>
148
- <td>Playground 2.5</td> <td>✔</td> <td>71.9</td> <td>70.8</td> <td>94.9</td> <td>83.3</td> <td>54.3</td>
149
- </tr>
150
-
151
- <tr>
152
- <td>SD 3</td> <td>&#10008</td> <td>77.1</td> <td>69.3</td> <td>94.6</td> <td>82.5</td> <td>56.7</td>
153
-
154
- </tr>
155
- <tr>
156
- <td>MidJourney v6</td><td>&#10008</td> <td>73.5</td> <td>80.2</td> <td>93.5</td> <td>87.2</td> <td>63.3</td>
157
- </tr>
158
- <tr>
159
- <td>DALL-E 3</td><td>&#10008</td> <td>83.9</td> <td>80.3</td> <td>96.5</td> <td>89.4</td> <td>71.0</td>
160
- </tr>
161
- <tr style="font-weight: bold; background-color: #f2f2f2;">
162
- <td>Hunyuan-DiT</td><td>✔</td> <td>74.2</td> <td>74.3</td> <td>95.4</td> <td>86.6</td> <td>59.0</td>
163
- </tr>
164
- </tbody>
165
- </table>
166
- </p>
167
-
168
- ## 🎥 Visualization
169
-
170
- * **Chinese Elements**
171
- <p align="center">
172
- <img src="https://raw.githubusercontent.com/Tencent/HunyuanDiT/main/asset/chinese elements understanding.png" height=220>
173
- </p>
174
-
175
- * **Long Text Input**
176
-
177
-
178
- <p align="center">
179
- <img src="https://raw.githubusercontent.com/Tencent/HunyuanDiT/main/asset/long text understanding.png" height=310>
180
- </p>
181
-
182
- * **Multi-turn Text2Image Generation**
183
-
184
- https://github.com/Tencent/tencent.github.io/assets/27557933/94b4dcc3-104d-44e1-8bb2-dc55108763d1
185
-
186
-
187
-
188
- ---
189
-
190
- ## 📜 Requirements
191
-
192
- This repo consists of DialogGen (a prompt enhancement model) and Hunyuan-DiT (a text-to-image model).
193
-
194
- The following table shows the requirements for running the models (batch size = 1):
195
-
196
- | Model | --load-4bit (DialogGen) | GPU Peak Memory | GPU |
197
- |:-----------------------:|:-----------------------:|:---------------:|:---------------:|
198
- | DialogGen + Hunyuan-DiT | ✘ | 32G | A100 |
199
- | DialogGen + Hunyuan-DiT | ✔ | 22G | A100 |
200
- | Hunyuan-DiT | - | 11G | A100 |
201
- | Hunyuan-DiT | - | 14G | RTX3090/RTX4090 |
202
-
203
- * An NVIDIA GPU with CUDA support is required.
204
- * We have tested V100 and A100 GPUs.
205
- * **Minimum**: The minimum GPU memory required is 11GB.
206
- * **Recommended**: We recommend using a GPU with 32GB of memory for better generation quality.
207
- * Tested operating system: Linux
208
-
209
- ## 🛠️ Dependencies and Installation
210
-
211
- Begin by cloning the repository:
212
- ```shell
213
- git clone https://github.com/tencent/HunyuanDiT
214
- cd HunyuanDiT
215
- ```
216
-
217
- ### Installation Guide for Linux
218
-
219
- We provide an `environment.yml` file for setting up a Conda environment.
220
- Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
221
-
222
- ```shell
223
- # 1. Prepare conda environment
224
- conda env create -f environment.yml
225
-
226
- # 2. Activate the environment
227
- conda activate HunyuanDiT
228
-
229
- # 3. Install pip dependencies
230
- python -m pip install -r requirements.txt
231
-
232
- # 4. (Optional) Install flash attention v2 for acceleration (requires CUDA 11.6 or above)
233
- python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.1.2.post3
234
- ```
235
-
236
- ## 🧱 Download Pretrained Models
237
- To download the model, first install the huggingface-cli. (Detailed instructions are available [here](https://huggingface.co/docs/huggingface_hub/guides/cli).)
238
-
239
- ```shell
240
- python -m pip install "huggingface_hub[cli]"
241
- ```
242
-
243
- Then download the model using the following commands:
244
-
245
- ```shell
246
- # Create a directory named 'ckpts' where the model will be saved, fulfilling the prerequisites for running the demo.
247
- mkdir ckpts
248
- # Use the huggingface-cli tool to download the model.
249
- # The download time may vary from 10 minutes to 1 hour depending on network conditions.
250
- huggingface-cli download Tencent-Hunyuan/HunyuanDiT --local-dir ./ckpts
251
- ```
252
-
253
- <details>
254
- <summary>💡Tips for using huggingface-cli (network problem)</summary>
255
-
256
- ##### 1. Using HF-Mirror
257
-
258
- If you encounter slow download speeds in China, you can try a mirror to speed up the download process. For example,
259
-
260
- ```shell
261
- HF_ENDPOINT=https://hf-mirror.com huggingface-cli download Tencent-Hunyuan/HunyuanDiT --local-dir ./ckpts
262
- ```
263
-
264
- ##### 2. Resume Download
265
-
266
- `huggingface-cli` supports resuming downloads. If the download is interrupted, you can just rerun the download
267
- command to resume the download process.
268
-
269
- Note: If an `No such file or directory: 'ckpts/.huggingface/.gitignore.lock'` like error occurs during the download
270
- process, you can ignore the error and rerun the download command.
271
-
272
- </details>
273
-
274
- ---
275
-
276
- All models will be automatically downloaded. For more information about the model, visit the Hugging Face repository [here](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT).
277
-
278
- | Model | #Params | Huggingface Download URL | Tencent Cloud Download URL |
279
- |:------------------:|:-------:|:-------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:|
280
- | mT5 | 1.6B | [mT5](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/tree/main/t2i/mt5) | [mT5](https://dit.hunyuan.tencent.com/download/HunyuanDiT/mt5.zip) |
281
- | CLIP | 350M | [CLIP](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/tree/main/t2i/clip_text_encoder) | [CLIP](https://dit.hunyuan.tencent.com/download/HunyuanDiT/clip_text_encoder.zip) |
282
- | Tokenizer | - | [Tokenizer](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/tree/main/t2i/tokenizer) | [Tokenizer](https://dit.hunyuan.tencent.com/download/HunyuanDiT/tokenizer.zip) |
283
- | DialogGen | 7.0B | [DialogGen](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/tree/main/dialoggen) | [DialogGen](https://dit.hunyuan.tencent.com/download/HunyuanDiT/dialoggen.zip) |
284
- | sdxl-vae-fp16-fix | 83M | [sdxl-vae-fp16-fix](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/tree/main/t2i/sdxl-vae-fp16-fix) | [sdxl-vae-fp16-fix](https://dit.hunyuan.tencent.com/download/HunyuanDiT/sdxl-vae-fp16-fix.zip) |
285
- | Hunyuan-DiT | 1.5B | [Hunyuan-DiT](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/tree/main/t2i/model) | [Hunyuan-DiT](https://dit.hunyuan.tencent.com/download/HunyuanDiT/model.zip) |
286
- | Data demo | - | - | [Data demo](https://dit.hunyuan.tencent.com/download/HunyuanDiT/data_demo.zip) |
287
-
288
- ## :truck: Training
289
-
290
- ### Data Preparation
291
-
292
- Refer to the commands below to prepare the training data.
293
-
294
- 1. Install dependencies
295
-
296
- We offer an efficient data management library, named IndexKits, supporting the management of reading hundreds of millions of data during training, see more in [docs](https://github.com/Tencent/HunyuanDiT/blob/main/IndexKits/README.md).
297
- ```shell
298
- # 1 Install dependencies
299
- cd HunyuanDiT
300
- pip install -e ./IndexKits
301
- ```
302
- 2. Data download
303
-
304
- Feel free to download the [data demo](https://dit.hunyuan.tencent.com/download/HunyuanDiT/data_demo.zip).
305
- ```shell
306
- # 2 Data download
307
- wget -O ./dataset/data_demo.zip https://dit.hunyuan.tencent.com/download/HunyuanDiT/data_demo.zip
308
- unzip ./dataset/data_demo.zip -d ./dataset
309
- mkdir ./dataset/porcelain/arrows ./dataset/porcelain/jsons
310
- ```
311
- 3. Data conversion
312
-
313
- Create a CSV file for training data with the fields listed in the table below.
314
-
315
- | Fields | Required | Description | Example |
316
- |:---------------:| :------: |:----------------:|:-----------:|
317
- | `image_path` | Required | image path | `./dataset/porcelain/images/0.png` |
318
- | `text_zh` | Required | text | 青花瓷风格,一只蓝色的鸟儿站在蓝色的花瓶上,周围点缀着白色花朵,背景是白色 |
319
- | `md5` | Optional | image md5 (Message Digest Algorithm 5) | `d41d8cd98f00b204e9800998ecf8427e` |
320
- | `width` | Optional | image width | `1024 ` |
321
- | `height` | Optional | image height | ` 1024 ` |
322
-
323
- > ⚠️ Optional fields like MD5, width, and height can be omitted. If omitted, the script below will automatically calculate them. This process can be time-consuming when dealing with large-scale training data.
324
-
325
- We utilize [Arrow](https://github.com/apache/arrow) for training data format, offering a standard and efficient in-memory data representation. A conversion script is provided to transform CSV files into Arrow format.
326
- ```shell
327
- # 3 Data conversion
328
- python ./hydit/data_loader/csv2arrow.py ./dataset/porcelain/csvfile/image_text.csv ./dataset/porcelain/arrows
329
- ```
330
-
331
- 4. Data Selection and Configuration File Creation
332
-
333
- We configure the training data through YAML files. In these files, you can set up standard data processing strategies for filtering, copying, deduplicating, and more regarding the training data. For more details, see [docs](IndexKits/docs/MakeDataset.md).
334
-
335
- For a sample file, please refer to [file](https://github.com/Tencent/HunyuanDiT/blob/main/dataset/yamls/porcelain.yaml). For a full parameter configuration file, see [file](https://github.com/Tencent/HunyuanDiT/blob/main/IndexKits/docs/MakeDataset.md).
336
-
337
-
338
- 5. Create training data index file using YAML file.
339
-
340
- ```shell
341
- # Single Resolution Data Preparation
342
- idk base -c dataset/yamls/porcelain.yaml -t dataset/porcelain/jsons/porcelain.json
343
-
344
- # Multi Resolution Data Preparation
345
- idk multireso -c dataset/yamls/porcelain_mt.yaml -t dataset/porcelain/jsons/porcelain_mt.json
346
- ```
347
-
348
- The directory structure for `porcelain` dataset is:
349
-
350
- ```shell
351
- cd ./dataset
352
-
353
- porcelain
354
- ├──images/ (image files)
355
- │ ├──0.png
356
- │ ├──1.png
357
- │ ├──......
358
- ├──csvfile/ (csv files containing text-image pairs)
359
- │ ├──image_text.csv
360
- ├──arrows/ (arrow files containing all necessary training data)
361
- │ ├──00000.arrow
362
- │ ├──00001.arrow
363
- │ ├──......
364
- ├──jsons/ (final training data index files which read data from arrow files during training)
365
- │ ├──porcelain.json
366
- │ ├──porcelain_mt.json
367
- ```
368
-
369
- ### Full-parameter Training
370
-
371
- To leverage DeepSpeed in training, you have the flexibility to control **single-node** / **multi-node** training by adjusting parameters such as `--hostfile` and `--master_addr`. For more details, see [link](https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node).
372
-
373
- ```shell
374
- # Single Resolution Data Preparation
375
- PYTHONPATH=./ sh hydit/train.sh --index-file dataset/porcelain/jsons/porcelain.json
376
-
377
- # Multi Resolution Data Preparation
378
- PYTHONPATH=./ sh hydit/train.sh --index-file dataset/porcelain/jsons/porcelain.json --multireso --reso-step 64
379
- ```
380
-
381
- ### LoRA
382
-
383
- We provide training and inference scripts for LoRA, detailed in the [guidances](https://github.com/Tencent/HunyuanDiT/blob/main/lora/README.md).
384
-
385
-
386
- ## 🔑 Inference
387
-
388
- ### Using Gradio
389
-
390
- Make sure the conda environment is activated before running the following command.
391
-
392
- ```shell
393
- # By default, we start a Chinese UI.
394
- python app/hydit_app.py
395
-
396
- # Using Flash Attention for acceleration.
397
- python app/hydit_app.py --infer-mode fa
398
-
399
- # You can disable the enhancement model if the GPU memory is insufficient.
400
- # The enhancement will be unavailable until you restart the app without the `--no-enhance` flag.
401
- python app/hydit_app.py --no-enhance
402
-
403
- # Start with English UI
404
- python app/hydit_app.py --lang en
405
-
406
- # Start a multi-turn T2I generation UI.
407
- # If your GPU memory is less than 32GB, use '--load-4bit' to enable 4-bit quantization, which requires at least 22GB of memory.
408
- python app/multiTurnT2I_app.py
409
- ```
410
- Then the demo can be accessed through http://0.0.0.0:443. It should be noted that the 0.0.0.0 here needs to be X.X.X.X with your server IP.
411
-
412
- ### Using 🤗 Diffusers
413
-
414
- Please install PyTorch version 2.0 or higher in advance to satisfy the requirements of the specified version of the diffusers library.
415
-
416
- Install 🤗 diffusers, ensuring that the version is at least 0.28.1:
417
-
418
- ```shell
419
- pip install git+https://github.com/huggingface/diffusers.git
420
- ```
421
- or
422
- ```shell
423
- pip install diffusers
424
- ```
425
-
426
- You can generate images with both Chinese and English prompts using the following Python script:
427
- ```py
428
- import torch
429
- from diffusers import HunyuanDiTPipeline
430
-
431
- pipe = HunyuanDiTPipeline.from_pretrained("Tencent-Hunyuan/HunyuanDiT-Diffusers", torch_dtype=torch.float16)
432
- pipe.to("cuda")
433
-
434
- # You may also use English prompt as HunyuanDiT supports both English and Chinese
435
- # prompt = "An astronaut riding a horse"
436
- prompt = "一个宇航员在骑马"
437
- image = pipe(prompt).images[0]
438
- ```
439
- You can use our distilled model to generate images even faster:
440
-
441
- ```py
442
- import torch
443
- from diffusers import HunyuanDiTPipeline
444
-
445
- pipe = HunyuanDiTPipeline.from_pretrained("Tencent-Hunyuan/HunyuanDiT-Diffusers-Distilled", torch_dtype=torch.float16)
446
- pipe.to("cuda")
447
-
448
- # You may also use English prompt as HunyuanDiT supports both English and Chinese
449
- # prompt = "An astronaut riding a horse"
450
- prompt = "一个宇航员在骑马"
451
- image = pipe(prompt, num_inference_steps=25).images[0]
452
- ```
453
- More details can be found in [HunyuanDiT-Diffusers-Distilled](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-Diffusers-Distilled)
454
-
455
- ### Using Command Line
456
-
457
- We provide several commands to quick start:
458
-
459
- ```shell
460
- # Prompt Enhancement + Text-to-Image. Torch mode
461
- python sample_t2i.py --prompt "渔舟唱晚"
462
-
463
- # Only Text-to-Image. Torch mode
464
- python sample_t2i.py --prompt "渔舟唱晚" --no-enhance
465
-
466
- # Only Text-to-Image. Flash Attention mode
467
- python sample_t2i.py --infer-mode fa --prompt "渔舟唱晚"
468
-
469
- # Generate an image with other image sizes.
470
- python sample_t2i.py --prompt "渔舟唱晚" --image-size 1280 768
471
-
472
- # Prompt Enhancement + Text-to-Image. DialogGen loads with 4-bit quantization, but it may loss performance.
473
- python sample_t2i.py --prompt "渔舟唱晚" --load-4bit
474
-
475
- ```
476
-
477
- More example prompts can be found in [example_prompts.txt](example_prompts.txt)
478
-
479
- ### More Configurations
480
-
481
- We list some more useful configurations for easy usage:
482
-
483
- | Argument | Default | Description |
484
- |:---------------:|:---------:|:---------------------------------------------------:|
485
- | `--prompt` | None | The text prompt for image generation |
486
- | `--image-size` | 1024 1024 | The size of the generated image |
487
- | `--seed` | 42 | The random seed for generating images |
488
- | `--infer-steps` | 100 | The number of steps for sampling |
489
- | `--negative` | - | The negative prompt for image generation |
490
- | `--infer-mode` | torch | The inference mode (torch, fa, or trt) |
491
- | `--sampler` | ddpm | The diffusion sampler (ddpm, ddim, or dpmms) |
492
- | `--no-enhance` | False | Disable the prompt enhancement model |
493
- | `--model-root` | ckpts | The root directory of the model checkpoints |
494
- | `--load-key` | ema | Load the student model or EMA model (ema or module) |
495
- | `--load-4bit` | Fasle | Load DialogGen model with 4bit quantization |
496
-
497
- ### Using ComfyUI
498
-
499
- We provide several commands to quick start:
500
-
501
- ```shell
502
- # Download comfyui code
503
- git clone https://github.com/comfyanonymous/ComfyUI.git
504
-
505
- # Install torch, torchvision, torchaudio
506
- pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117
507
-
508
- # Install Comfyui essential python package
509
- cd ComfyUI
510
- pip install -r requirements.txt
511
-
512
- # ComfyUI has been successfully installed!
513
-
514
- # Download model weight as before or link the existing model folder to ComfyUI.
515
- python -m pip install "huggingface_hub[cli]"
516
- mkdir models/hunyuan
517
- huggingface-cli download Tencent-Hunyuan/HunyuanDiT --local-dir ./models/hunyuan/ckpts
518
-
519
- # Move to the ComfyUI custom_nodes folder and copy comfyui-hydit folder from HunyuanDiT Repo.
520
- cd custom_nodes
521
- cp -r ${HunyuanDiT}/comfyui-hydit ./
522
- cd comfyui-hydit
523
-
524
- # Install some essential python Package.
525
- pip install -r requirements.txt
526
-
527
- # Our tool has been successfully installed!
528
-
529
- # Go to ComfyUI main folder
530
- cd ../..
531
- # Run the ComfyUI Lauch command
532
- python main.py --listen --port 80
533
-
534
- # Running ComfyUI successfully!
535
- ```
536
- More details can be found in [ComfyUI README](comfyui-hydit/README.md)
537
-
538
- ## 🚀 Acceleration (for Linux)
539
-
540
- - We provide TensorRT version of HunyuanDiT for inference acceleration (faster than flash attention).
541
- See [Tencent-Hunyuan/TensorRT-libs](https://huggingface.co/Tencent-Hunyuan/TensorRT-libs) for more details.
542
-
543
- - We provide Distillation version of HunyuanDiT for inference acceleration.
544
- See [Tencent-Hunyuan/Distillation](https://huggingface.co/Tencent-Hunyuan/Distillation) for more details.
545
-
546
- ## 🔗 BibTeX
547
- If you find [Hunyuan-DiT](https://arxiv.org/abs/2405.08748) or [DialogGen](https://arxiv.org/abs/2403.08857) useful for your research and applications, please cite using this BibTeX:
548
-
549
- ```BibTeX
550
- @misc{li2024hunyuandit,
551
- title={Hunyuan-DiT: A Powerful Multi-Resolution Diffusion Transformer with Fine-Grained Chinese Understanding},
552
- author={Zhimin Li and Jianwei Zhang and Qin Lin and Jiangfeng Xiong and Yanxin Long and Xinchi Deng and Yingfang Zhang and Xingchao Liu and Minbin Huang and Zedong Xiao and Dayou Chen and Jiajun He and Jiahao Li and Wenyue Li and Chen Zhang and Rongwei Quan and Jianxiang Lu and Jiabin Huang and Xiaoyan Yuan and Xiaoxiao Zheng and Yixuan Li and Jihong Zhang and Chao Zhang and Meng Chen and Jie Liu and Zheng Fang and Weiyan Wang and Jinbao Xue and Yangyu Tao and Jianchen Zhu and Kai Liu and Sihuan Lin and Yifu Sun and Yun Li and Dongdong Wang and Mingtao Chen and Zhichao Hu and Xiao Xiao and Yan Chen and Yuhong Liu and Wei Liu and Di Wang and Yong Yang and Jie Jiang and Qinglin Lu},
553
- year={2024},
554
- eprint={2405.08748},
555
- archivePrefix={arXiv},
556
- primaryClass={cs.CV}
557
- }
558
-
559
- @article{huang2024dialoggen,
560
- title={DialogGen: Multi-modal Interactive Dialogue System for Multi-turn Text-to-Image Generation},
561
- author={Huang, Minbin and Long, Yanxin and Deng, Xinchi and Chu, Ruihang and Xiong, Jiangfeng and Liang, Xiaodan and Cheng, Hong and Lu, Qinglin and Liu, Wei},
562
- journal={arXiv preprint arXiv:2403.08857},
563
- year={2024}
564
- }
565
- ```
566
-
567
- ## Start History
568
-
569
- <a href="https://star-history.com/#Tencent/HunyuanDiT&Date">
570
- <picture>
571
- <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Tencent/HunyuanDiT&type=Date&theme=dark" />
572
- <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Tencent/HunyuanDiT&type=Date" />
573
- <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Tencent/HunyuanDiT&type=Date" />
574
- </picture>
575
- </a>
 
7
  - en
8
  - zh
9
  ---
10
+ Hi, the training and inference code for version 1.2, including Lora and ControlNet, will be released soon. Currently, the v1.2 weights on Hugging Face are only for Kohya’s loading. Please primarily refer to the updates on our [GitHub](https://github.com/Tencent/HunyuanDiT).