Text-to-Video
README.md CHANGED
@@ -19,137 +19,98 @@ This repo contains PyTorch model definitions, pre-trained weights and inference/
19
 
20
  > [**HunyuanVideo: A Systematic Framework For Large Video Generation Model Training**](https://arxiv.org/abs/2412.03603) <br>
21
 
 
 
22
 
23
-
24
- ## News!!
25
-
26
- * Jan 13, 2025: πŸ“ˆ We release the [Penguin Video Benchmark](https://github.com/Tencent/HunyuanVideo/blob/main/assets/PenguinVideoBenchmark.csv).
27
- * Dec 18, 2024: πŸƒβ€β™‚οΈ We release the [FP8 model weights](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt) of HunyuanVideo to save more GPU memory.
28
- * Dec 17, 2024: πŸ€— HunyuanVideo has been integrated into [Diffusers](https://huggingface.co/docs/diffusers/main/api/pipelines/hunyuan_video).
29
- * Dec 7, 2024: πŸš€ We release the parallel inference code for HunyuanVideo powered by [xDiT](https://github.com/xdit-project/xDiT).
30
- * Dec 3, 2024: πŸ‘‹ We release the inference code and model weights of HunyuanVideo. [Download](https://github.com/Tencent/HunyuanVideo/blob/main/ckpts/README.md).
31
-
32
-
33
-
34
- ## Open-source Plan
35
 
36
  - HunyuanVideo (Text-to-Video Model)
37
- - [x] Inference
38
- - [x] Checkpoints
39
- - [x] Multi-gpus Sequence Parallel inference (Faster inference speed on more gpus)
40
- - [x] Web Demo (Gradio)
41
- - [x] Diffusers
42
- - [x] FP8 Quantified weight
43
- - [x] Penguin Video Benchmark
44
- - [x] ComfyUI
45
- - [HunyuanVideo (Image-to-Video Model)](https://github.com/Tencent/HunyuanVideo-I2V)
46
  - [x] Inference
47
  - [x] Checkpoints
48
-
49
-
 
 
 
 
 
50
 
51
  ## Contents
52
-
53
- - [HunyuanVideo: A Systematic Framework For Large Video Generation Model](#hunyuanvideo-a-systematic-framework-for-large-video-generation-model)
54
- - [News!!](#news)
55
- - [Open-source Plan](#open-source-plan)
56
  - [Contents](#contents)
57
  - [**Abstract**](#abstract)
58
- - [**HunyuanVideo Overall Architecture**](#hunyuanvideo-overall-architecture)
59
- - [**HunyuanVideo Key Features**](#hunyuanvideo-key-features)
60
  - [**Unified Image and Video Generative Architecture**](#unified-image-and-video-generative-architecture)
61
  - [**MLLM Text Encoder**](#mllm-text-encoder)
62
  - [**3D VAE**](#3d-vae)
63
  - [**Prompt Rewrite**](#prompt-rewrite)
64
- - [Comparisons](#comparisons)
65
- - [Requirements](#requirements)
66
- - [Dependencies and Installation](#️dependencies-and-installation)
67
  - [Installation Guide for Linux](#installation-guide-for-linux)
68
- - [Download Pretrained Models](#download-pretrained-models)
69
- - [Single-gpu Inference](#single-gpu-inference)
70
  - [Using Command Line](#using-command-line)
71
- - [Run a Gradio Server](#run-a-gradio-server)
72
  - [More Configurations](#more-configurations)
73
- - [Parallel Inference on Multiple GPUs by xDiT](#parallel-inference-on-multiple-gpus-by-xdit)
74
- - [Using Command Line](#using-command-line-1)
75
- - [FP8 Inference](#fp8-inference)
76
- - [Using Command Line](#using-command-line-2)
77
- - [BibTeX](#bibtex)
78
  - [Acknowledgements](#acknowledgements)
79
-
80
  ---
81
 
82
  ## **Abstract**
 
83
 
84
- We present HunyuanVideo, a novel open-source video foundation model that exhibits performance in video generation that is comparable to, if not superior to, leading closed-source models. In order to train HunyuanVideo model, we adopt several key technologies for model learning, including data curation, image-video joint model training, and an efficient infrastructure designed to facilitate large-scale model training and inference. Additionally, through an effective strategy for scaling model architecture and dataset, we successfully trained a video generative model with over 13 billion parameters, making it the largest among all open-source models.
85
-
86
- We conducted extensive experiments and implemented a series of targeted designs to ensure high visual quality, motion diversity, text-video alignment, and generation stability. According to professional human evaluation results, HunyuanVideo outperforms previous state-of-the-art models, including Runway Gen-3, Luma 1.6, and 3 top-performing Chinese video generative models. By releasing the code and weights of the foundation model and its applications, we aim to bridge the gap between closed-source and open-source video foundation models. This initiative will empower everyone in the community to experiment with their ideas, fostering a more dynamic and vibrant video generation ecosystem.
87
-
88
-
89
 
90
- ## **HunyuanVideo Overall Architecture**
91
 
92
  HunyuanVideo is trained on a spatial-temporally
93
- compressed latent space, which is compressed through a Causal 3D VAE. Text prompts are encoded
94
- using a large language model, and used as the conditions. Taking Gaussian noise and the conditions as
95
- input, our generative model produces an output latent, which is then decoded to images or videos through
96
  the 3D VAE decoder.
97
-
98
  <p align="center">
99
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/overall.png" height=300>
100
  </p>
101
 
102
-
103
-
104
- ## **HunyuanVideo Key Features**
105
-
106
  ### **Unified Image and Video Generative Architecture**
107
-
108
  HunyuanVideo introduces the Transformer design and employs a Full Attention mechanism for unified image and video generation.
109
  Specifically, we use a "Dual-stream to Single-stream" hybrid model design for video generation. In the dual-stream phase, video and text
110
  tokens are processed independently through multiple Transformer blocks, enabling each modality to learn its own appropriate modulation mechanisms without interference. In the single-stream phase, we concatenate the video and text
111
  tokens and feed them into subsequent Transformer blocks for effective multimodal information fusion.
112
  This design captures complex interactions between visual and semantic information, enhancing
113
  overall model performance.
114
-
115
  <p align="center">
116
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/backbone.png" height=350>
117
  </p>
118
 
119
-
120
  ### **MLLM Text Encoder**
121
-
122
- Some previous text-to-video models typically use pre-trained CLIP and T5-XXL as text encoders where CLIP uses Transformer Encoder and T5 uses an Encoder-Decoder structure. In contrast, we utilize a pre-trained Multimodal Large Language Model (MLLM) with a Decoder-Only structure as our text encoder, which has the following advantages: (i) Compared with T5, MLLM after visual instruction finetuning has better image-text alignment in the feature space, which alleviates the difficulty of the instruction following in diffusion models; (ii)
123
- Compared with CLIP, MLLM has demonstrated superior ability in image detail description
124
- and complex reasoning; (iii) MLLM can play as a zero-shot learner by following system instructions prepended to user prompts, helping text features pay more attention to key information. In addition, MLLM is based on causal attention while T5-XXL utilizes bidirectional attention that produces better text guidance for diffusion models. Therefore, we introduce an extra bidirectional token refiner to enhance text features.
125
-
126
  <p align="center">
127
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/text_encoder.png" height=275>
128
  </p>
129
 
130
-
131
  ### **3D VAE**
132
-
133
- HunyuanVideo trains a 3D VAE with CausalConv3D to compress pixel-space videos and images into a compact latent space. We set the compression ratios of video length, space, and channel to 4, 8, and 16 respectively. This can significantly reduce the number of tokens for the subsequent diffusion transformer model, allowing us to train videos at the original resolution and frame rate.
134
-
135
  <p align="center">
136
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/3dvae.png" height=150>
137
  </p>
138
 
139
-
140
  ### **Prompt Rewrite**
141
-
142
  To address the variability in linguistic style and length of user-provided prompts, we fine-tune the [Hunyuan-Large model](https://github.com/Tencent/Tencent-Hunyuan-Large) as our prompt rewrite model to adapt the original user prompt to model-preferred prompt.
143
 
144
- We provide two rewrite modes: Normal mode and Master mode, which can be called using different prompts. The prompts are shown [here](hyvideo/prompt_rewrite.py). The Normal mode is designed to enhance the video generation model's comprehension of user intent, facilitating a more accurate interpretation of the instructions provided. The Master mode enhances the description of aspects such as composition, lighting, and camera movement, which leans towards generating videos with a higher visual quality. However, this emphasis may occasionally result in the loss of some semantic details.
145
 
146
  The Prompt Rewrite Model can be directly deployed and inferred using the [Hunyuan-Large original code](https://github.com/Tencent/Tencent-Hunyuan-Large). We release the weights of the Prompt Rewrite Model [here](https://huggingface.co/Tencent/HunyuanVideo-PromptRewrite).
147
 
 
148
 
149
-
150
- ## Comparisons
151
-
152
- To evaluate the performance of HunyuanVideo, we selected five strong baselines from closed-source video generation models. In total, we utilized 1,533 text prompts, generating an equal number of video samples with HunyuanVideo in a single run. For a fair comparison, we conducted inference only once, avoiding any cherry-picking of results. When comparing with the baseline methods, we maintained the default settings for all selected models, ensuring consistent video resolution. Videos were assessed based on three criteria: Text Alignment, Motion Quality, and Visual Quality. More than 60 professional evaluators performed the evaluation. Notably, HunyuanVideo demonstrated the best overall performance, particularly excelling in motion quality. Please note that the evaluation is based on Hunyuan Video's high-quality version. This is different from the currently released fast version.
153
 
154
  <p align="center">
155
  <table>
@@ -172,25 +133,23 @@ To evaluate the performance of HunyuanVideo, we selected five strong baselines f
172
  <td>GEN-3 alpha (Web)</td> <td>&#10008</td> <td>6s</td> <td>47.7%</td> <td>54.7%</td> <td>97.5%</td> <td>27.4%</td> <td>4</td>
173
  </tr>
174
  <tr>
175
- <td>Luma1.6 (API)</td><td>&#10008</td> <td>5s</td> <td>57.6%</td> <td>44.2%</td> <td>94.1%</td> <td>24.8%</td> <td>5</td>
176
  </tr>
177
  <tr>
178
- <td>CNTopC (Web)</td> <td>&#10008</td> <td>5s</td> <td>48.4%</td> <td>47.2%</td> <td>96.3%</td> <td>24.6%</td> <td>6</td>
179
  </tr>
180
  </tbody>
181
  </table>
182
  </p>
183
 
184
-
185
-
186
- ## Requirements
187
 
188
  The following table shows the requirements for running HunyuanVideo model (batch size = 1) to generate videos:
189
 
190
- | Model | Setting<br/>(height/width/frame) | GPU Peak Memory |
191
- | :----------: | :------------------------------: | :-------------: |
192
- | HunyuanVideo | 720px1280px129f | 60GB |
193
- | HunyuanVideo | 544px960px129f | 45GB |
194
 
195
  * An NVIDIA GPU with CUDA support is required.
196
  * The model is tested on a single 80G GPU.
@@ -198,12 +157,9 @@ The following table shows the requirements for running HunyuanVideo model (batch
198
  * **Recommended**: We recommend using a GPU with 80GB of memory for better generation quality.
199
  * Tested operating system: Linux
200
 
201
-
202
-
203
- ## Dependencies and Installation
204
 
205
  Begin by cloning the repository:
206
-
207
  ```shell
208
  git clone https://github.com/tencent/HunyuanVideo
209
  cd HunyuanVideo
@@ -211,79 +167,53 @@ cd HunyuanVideo
211
 
212
  ### Installation Guide for Linux
213
 
214
- We recommend CUDA versions 12.4 or 11.8 for the manual installation.
215
-
216
  Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
217
 
 
 
218
  ```shell
219
- # 1. Create conda environment
220
- conda create -n HunyuanVideo python==3.10.9
221
 
222
  # 2. Activate the environment
223
  conda activate HunyuanVideo
224
 
225
- # 3. Install PyTorch and other dependencies using conda
226
- # For CUDA 11.8
227
- conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=11.8 -c pytorch -c nvidia
228
- # For CUDA 12.4
229
- conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.4 -c pytorch -c nvidia
230
-
231
- # 4. Install pip dependencies
232
  python -m pip install -r requirements.txt
233
 
234
- # 5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
235
- python -m pip install ninja
236
- python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.6.3
237
-
238
- # 6. Install xDiT for parallel inference (It is recommended to use torch 2.4.0 and flash-attn 2.6.3)
239
- python -m pip install xfuser==0.4.0
240
  ```
241
 
242
- In case of running into float point exception(core dump) on the specific GPU type, you may try the following solutions:
 
243
 
244
  ```shell
245
- # Option 1: Making sure you have installed CUDA 12.4, CUBLAS>=12.4.5.8, and CUDNN>=9.00 (or simply using our CUDA 12 docker image).
246
- pip install nvidia-cublas-cu12==12.4.5.8
247
- export LD_LIBRARY_PATH=/opt/conda/lib/python3.8/site-packages/nvidia/cublas/lib/
248
-
249
- # Option 2: Forcing to explictly use the CUDA 11.8 compiled version of Pytorch and all the other packages
250
- pip uninstall -r requirements.txt # uninstall all packages
251
- pip uninstall -y xfuser
252
- pip install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu118
253
- pip install -r requirements.txt
254
- pip install ninja
255
- pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.6.3
256
- pip install xfuser==0.4.0
257
- ```
258
 
259
- Additionally, HunyuanVideo also provides a pre-built Docker image. Use the following command to pull and run the docker image.
 
260
 
261
- ```shell
262
- # For CUDA 12.4 (updated to avoid float point exception)
263
- docker pull hunyuanvideo/hunyuanvideo:cuda_12
264
- docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_12
265
 
266
- # For CUDA 11.8
267
- docker pull hunyuanvideo/hunyuanvideo:cuda_11
268
- docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_11
269
  ```
270
 
271
 
 
272
 
273
- ## Download Pretrained Models
274
-
275
- The details of download pretrained models are shown [here](ckpts/README.md).
276
-
277
-
278
-
279
- ## Single-gpu Inference
280
 
 
281
  We list the height/width/frame settings we support in the following table.
282
 
283
- | Resolution | h/w=9:16 | h/w=16:9 | h/w=4:3 | h/w=3:4 | h/w=1:1 |
284
- | :----------------: | :-------------: | :-------------: | :-------------: | :-------------: | :------------: |
285
- | 540p | 544px960px129f | 960px544px129f | 624px832px129f | 832px624px129f | 720px720px129f |
286
- | 720p (recommended) | 720px1280px129f | 1280px720px129f | 1104px832px129f | 832px1104px129f | 960px960px129f |
287
 
288
  ### Using Command Line
289
 
@@ -293,175 +223,46 @@ cd HunyuanVideo
293
  python3 sample_video.py \
294
  --video-size 720 1280 \
295
  --video-length 129 \
296
- --infer-steps 50 \
297
- --prompt "A cat walks on the grass, realistic style." \
298
  --flow-reverse \
 
299
  --use-cpu-offload \
300
  --save-path ./results
301
  ```
302
 
303
- ### Run a Gradio Server
304
-
305
- ```bash
306
- python3 gradio_server.py --flow-reverse
307
-
308
- # set SERVER_NAME and SERVER_PORT manually
309
- # SERVER_NAME=0.0.0.0 SERVER_PORT=8081 python3 gradio_server.py --flow-reverse
310
- ```
311
-
312
  ### More Configurations
313
 
314
  We list some more useful configurations for easy usage:
315
 
316
- | Argument | Default | Description |
317
- | :--------------------: | :-------: | :----------------------------------------------------------: |
318
- | `--prompt` | None | The text prompt for video generation |
319
- | `--video-size` | 720 1280 | The size of the generated video |
320
- | `--video-length` | 129 | The length of the generated video |
321
- | `--infer-steps` | 50 | The number of steps for sampling |
322
- | `--embedded-cfg-scale` | 6.0 | Embedded Classifier free guidance scale |
323
- | `--flow-shift` | 7.0 | Shift factor for flow matching schedulers |
324
- | `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |
325
- | `--seed` | None | The random seed for generating video, if None, we init a random seed |
326
- | `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |
327
- | `--save-path` | ./results | Path to save the generated video |
328
-
329
-
330
-
331
- ## Parallel Inference on Multiple GPUs by xDiT
332
-
333
- [xDiT](https://github.com/xdit-project/xDiT) is a Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters.
334
- It has successfully provided low-latency parallel inference solutions for a variety of DiTs models, including mochi-1, CogVideoX, Flux.1, SD3, etc. This repo adopted the [Unified Sequence Parallelism (USP)](https://arxiv.org/abs/2405.07719) APIs for parallel inference of the HunyuanVideo model.
335
-
336
- ### Using Command Line
337
-
338
- For example, to generate a video with 8 GPUs, you can use the following command:
339
-
340
- ```bash
341
- cd HunyuanVideo
342
-
343
- torchrun --nproc_per_node=8 sample_video.py \
344
- --video-size 1280 720 \
345
- --video-length 129 \
346
- --infer-steps 50 \
347
- --prompt "A cat walks on the grass, realistic style." \
348
- --flow-reverse \
349
- --seed 42 \
350
- --ulysses-degree 8 \
351
- --ring-degree 1 \
352
- --save-path ./results
353
- ```
354
-
355
- You can change the `--ulysses-degree` and `--ring-degree` to control the parallel configurations for the best performance. The valid parallel configurations are shown in the following table.
356
-
357
- <details>
358
- <summary>Supported Parallel Configurations (Click to expand)</summary>
359
-
360
-
361
- | --video-size | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |
362
- | -------------------- | -------------- | -------------------------------- | ---------------- |
363
- | 1280 720 or 720 1280 | 129 | 8x1,4x2,2x4,1x8 | 8 |
364
- | 1280 720 or 720 1280 | 129 | 1x5 | 5 |
365
- | 1280 720 or 720 1280 | 129 | 4x1,2x2,1x4 | 4 |
366
- | 1280 720 or 720 1280 | 129 | 3x1,1x3 | 3 |
367
- | 1280 720 or 720 1280 | 129 | 2x1,1x2 | 2 |
368
- | 1104 832 or 832 1104 | 129 | 4x1,2x2,1x4 | 4 |
369
- | 1104 832 or 832 1104 | 129 | 3x1,1x3 | 3 |
370
- | 1104 832 or 832 1104 | 129 | 2x1,1x2 | 2 |
371
- | 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
372
- | 960 960 | 129 | 4x1,2x2,1x4 | 4 |
373
- | 960 960 | 129 | 3x1,1x3 | 3 |
374
- | 960 960 | 129 | 1x2,2x1 | 2 |
375
- | 960 544 or 544 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
376
- | 960 544 or 544 960 | 129 | 4x1,2x2,1x4 | 4 |
377
- | 960 544 or 544 960 | 129 | 3x1,1x3 | 3 |
378
- | 960 544 or 544 960 | 129 | 1x2,2x1 | 2 |
379
- | 832 624 or 624 832 | 129 | 4x1,2x2,1x4 | 4 |
380
- | 624 832 or 624 832 | 129 | 3x1,1x3 | 3 |
381
- | 832 624 or 624 832 | 129 | 2x1,1x2 | 2 |
382
- | 720 720 | 129 | 1x5 | 5 |
383
- | 720 720 | 129 | 3x1,1x3 | 3 |
384
-
385
- </details>
386
-
387
-
388
- <p align="center">
389
- <table align="center">
390
- <thead>
391
- <tr>
392
- <th colspan="4">Latency (Sec) for 1280x720 (129 frames 50 steps) on 8xGPU</th>
393
- </tr>
394
- <tr>
395
- <th>1</th>
396
- <th>2</th>
397
- <th>4</th>
398
- <th>8</th>
399
- </tr>
400
- </thead>
401
- <tbody>
402
- <tr>
403
- <th>1904.08</th>
404
- <th>934.09 (2.04x)</th>
405
- <th>514.08 (3.70x)</th>
406
- <th>337.58 (5.64x)</th>
407
- </tr>
408
-
409
-
410
- </tbody>
411
- </table>
412
- </p>
413
-
414
-
415
-
416
- ## FP8 Inference
417
-
418
- Using HunyuanVideo with FP8 quantized weights, which saves about 10GB of GPU memory. You can download the [weights](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt) and [weight scales](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8_map.pt) from Huggingface.
419
-
420
- ### Using Command Line
421
-
422
- Here, you must explicitly specify the FP8 weight path. For example, to generate a video with fp8 weights, you can use the following command:
423
-
424
- ```bash
425
- cd HunyuanVideo
426
-
427
- DIT_CKPT_PATH={PATH_TO_FP8_WEIGHTS}/{WEIGHT_NAME}_fp8.pt
428
-
429
- python3 sample_video.py \
430
- --dit-weight ${DIT_CKPT_PATH} \
431
- --video-size 1280 720 \
432
- --video-length 129 \
433
- --infer-steps 50 \
434
- --prompt "A cat walks on the grass, realistic style." \
435
- --seed 42 \
436
- --embedded-cfg-scale 6.0 \
437
- --flow-shift 7.0 \
438
- --flow-reverse \
439
- --use-cpu-offload \
440
- --use-fp8 \
441
- --save-path ./results
442
- ```
443
-
444
-
445
-
446
- ## BibTeX
447
-
448
  If you find [HunyuanVideo](https://arxiv.org/abs/2412.03603) useful for your research and applications, please cite using this BibTeX:
449
 
450
  ```BibTeX
451
  @misc{kong2024hunyuanvideo,
452
  title={HunyuanVideo: A Systematic Framework For Large Video Generative Models},
453
- author={Weijie Kong, Qi Tian, Zijian Zhang, Rox Min, Zuozhuo Dai, Jin Zhou, Jiangfeng Xiong, Xin Li, Bo Wu, Jianwei Zhang, Kathrina Wu, Qin Lin, Aladdin Wang, Andong Wang, Changlin Li, Duojun Huang, Fang Yang, Hao Tan, Hongmei Wang, Jacob Song, Jiawang Bai, Jianbing Wu, Jinbao Xue, Joey Wang, Junkun Yuan, Kai Wang, Mengyang Liu, Pengyu Li, Shuai Li, Weiyan Wang, Wenqing Yu, Xinchi Deng, Yang Li, Yanxin Long, Yi Chen, Yutao Cui, Yuanbo Peng, Zhentao Yu, Zhiyu He, Zhiyong Xu, Zixiang Zhou, Zunnan Xu, Yangyu Tao, Qinglin Lu, Songtao Liu, Dax Zhou, Hongfa Wang, Yong Yang, Di Wang, Yuhong Liu, and Jie Jiang, along with Caesar Zhong},
454
  year={2024},
455
  archivePrefix={arXiv preprint arXiv:2412.03603},
456
- primaryClass={cs.CV},
457
- url={https://arxiv.org/abs/2412.03603},
458
  }
459
  ```
460
 
461
-
462
-
463
  ## Acknowledgements
464
-
465
  We would like to thank the contributors to the [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium), [FLUX](https://github.com/black-forest-labs/flux), [Llama](https://github.com/meta-llama/llama), [LLaVA](https://github.com/haotian-liu/LLaVA), [Xtuner](https://github.com/InternLM/xtuner), [diffusers](https://github.com/huggingface/diffusers) and [HuggingFace](https://huggingface.co) repositories, for their open research and exploration.
466
  Additionally, we also thank the Tencent Hunyuan Multimodal team for their help with the text encoder.
467
-
 
19
 
20
  > [**HunyuanVideo: A Systematic Framework For Large Video Generation Model Training**](https://arxiv.org/abs/2412.03603) <br>
21
 
22
+ ## πŸ”₯πŸ”₯πŸ”₯ News!!
23
+ * Dec 3, 2024: πŸ€— We release the inference code and model weights of HunyuanVideo.
24
 
25
+ ## πŸ“‘ Open-source Plan
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  - HunyuanVideo (Text-to-Video Model)
 
 
 
 
 
 
 
 
 
28
  - [x] Inference
29
  - [x] Checkpoints
30
+ - [ ] Penguin Video Benchmark
31
+ - [ ] Web Demo (Gradio)
32
+ - [ ] ComfyUI
33
+ - [ ] Diffusers
34
+ - HunyuanVideo (Image-to-Video Model)
35
+ - [ ] Inference
36
+ - [ ] Checkpoints
37
 
38
  ## Contents
39
+ - [HunyuanVideo: A Systematic Framework For Large Video Generation Model Training](#hunyuanvideo--a-systematic-framework-for-large-video-generation-model-training)
40
+ - [πŸ”₯πŸ”₯πŸ”₯ News!!](#-news!!)
41
+ - [πŸ“‘ Open-source Plan](#-open-source-plan)
 
42
  - [Contents](#contents)
43
  - [**Abstract**](#abstract)
44
+ - [**HunyuanVideo Overall Architechture**](#-hunyuanvideo-overall-architechture)
45
+ - [πŸŽ‰ **HunyuanVideo Key Features**](#-hunyuanvideo-key-features)
46
  - [**Unified Image and Video Generative Architecture**](#unified-image-and-video-generative-architecture)
47
  - [**MLLM Text Encoder**](#mllm-text-encoder)
48
  - [**3D VAE**](#3d-vae)
49
  - [**Prompt Rewrite**](#prompt-rewrite)
50
+ - [πŸ“ˆ Comparisons](#-comparisons)
51
+ - [πŸ“œ Requirements](#-requirements)
52
+ - [πŸ› οΈ Dependencies and Installation](#-dependencies-and-installation)
53
  - [Installation Guide for Linux](#installation-guide-for-linux)
54
+ - [🧱 Download Pretrained Models](#-download-pretrained-models)
55
+ - [πŸ”‘ Inference](#-inference)
56
  - [Using Command Line](#using-command-line)
 
57
  - [More Configurations](#more-configurations)
58
+ - [πŸ”— BibTeX](#-bibtex)
 
 
 
 
59
  - [Acknowledgements](#acknowledgements)
 
60
  ---
61
 
62
  ## **Abstract**
63
+ We present HunyuanVideo, a novel open-source video foundation model that exhibits performance in video generation that is comparable to, if not superior to, leading closed-source models. HunyuanVideo features a comprehensive framework that integrates several key contributions, including data curation, image-video joint model training, and an efficient infrastructure designed to facilitate large-scale model training and inference. Additionally, through an effective strategy for scaling model architecture and dataset, we successfully trained a video generative model with over 13 billion parameters, making it the largest among all open-source models.
64
 
65
+ We conducted extensive experiments and implemented a series of targeted designs to ensure high visual quality, motion diversity, text-video alignment, and generation stability. According to professional human evaluation results, HunyuanVideo outperforms previous state-of-the-art models, including Runway Gen-3, Luma 1.6, and 3 top performing Chinese video generative models. By releasing the code and weights of the foundation model and its applications, we aim to bridge the gap between closed-source and open-source video foundation models. This initiative will empower everyone in the community to experiment with their ideas, fostering a more dynamic and vibrant video generation ecosystem.
 
 
 
 
66
 
67
+ ## **HunyuanVideo Overall Architechture**
68
 
69
  HunyuanVideo is trained on a spatial-temporally
70
+ compressed latent space, which is compressed through Causal 3D VAE. Text prompts are encoded
71
+ using a large language model, and used as the condition. Gaussian noise and condition are taken as
72
+ input, our generate model generates an output latent, which is decoded to images or videos through
73
  the 3D VAE decoder.
 
74
  <p align="center">
75
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/overall.png" height=300>
76
  </p>
77
 
78
+ ## πŸŽ‰ **HunyuanVideo Key Features**
 
 
 
79
  ### **Unified Image and Video Generative Architecture**
 
80
  HunyuanVideo introduces the Transformer design and employs a Full Attention mechanism for unified image and video generation.
81
  Specifically, we use a "Dual-stream to Single-stream" hybrid model design for video generation. In the dual-stream phase, video and text
82
  tokens are processed independently through multiple Transformer blocks, enabling each modality to learn its own appropriate modulation mechanisms without interference. In the single-stream phase, we concatenate the video and text
83
  tokens and feed them into subsequent Transformer blocks for effective multimodal information fusion.
84
  This design captures complex interactions between visual and semantic information, enhancing
85
  overall model performance.
 
86
  <p align="center">
87
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/backbone.png" height=350>
88
  </p>
89
 
 
90
  ### **MLLM Text Encoder**
91
+ Some previous text-to-video model typically use pretrainednCLIP and T5-XXL as text encoders where CLIP uses Transformer Encoder and T5 uses a Encoder-Decoder structure. In constrast, we utilize a pretrained Multimodal Large Language Model (MLLM) with a Decoder-Only structure as our text encoder, which has following advantages: (i) Compared with T5, MLLM after visual instruction finetuning has better image-text alignment in the feature space, which alleviates the difficulty of instruction following in diffusion models; (ii)
92
+ Compared with CLIP, MLLM has been demonstrated superior ability in image detail description
93
+ and complex reasoning; (iii) MLLM can play as a zero-shot learner by following system instructions prepended to user prompts, helping text features pay more attention to key information. In addition, MLLM is based on causal attention while T5-XXL utilizes bidirectional attention that produces better text guidance for diffusion models. Therefore, we introduce an extra bidirectional token refiner for enhacing text features.
 
 
94
  <p align="center">
95
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/text_encoder.png" height=275>
96
  </p>
97
 
 
98
  ### **3D VAE**
99
+ HunyuanVideo trains a 3D VAE with CausalConv3D to compress pixel-space videos and images into a compact latent space. We set the compression ratios of video length, space and channel to 4, 8 and 16 respectively. This can significantly reduce the number of tokens for the subsequent diffusion transformer model, allowing us to train videos at the original resolution and frame rate.
 
 
100
  <p align="center">
101
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/3dvae.png" height=150>
102
  </p>
103
 
 
104
  ### **Prompt Rewrite**
 
105
  To address the variability in linguistic style and length of user-provided prompts, we fine-tune the [Hunyuan-Large model](https://github.com/Tencent/Tencent-Hunyuan-Large) as our prompt rewrite model to adapt the original user prompt to model-preferred prompt.
106
 
107
+ We provide two rewrite modes: Normal mode and Master mode, which can be called using different prompts. The Normal mode is designed to enhance the video generation model's comprehension of user intent, facilitating a more accurate interpretation of the instructions provided. The Master mode enhances the description of aspects such as composition, lighting, and camera movement, which leans towards generating videos with a higher visual quality. However, this emphasis may occasionally result in the loss of some semantic details.
108
 
109
  The Prompt Rewrite Model can be directly deployed and inferred using the [Hunyuan-Large original code](https://github.com/Tencent/Tencent-Hunyuan-Large). We release the weights of the Prompt Rewrite Model [here](https://huggingface.co/Tencent/HunyuanVideo-PromptRewrite).
110
 
111
+ ## πŸ“ˆ Comparisons
112
 
113
+ To evaluate the performance of HunyuanVideo, we selected five strong baselines from closed-source video generation models. In total, we utilized 1,533 text prompts, generating an equal number of video samples with HunyuanVideo in a single run. For a fair comparison, we conducted inference only once, avoiding any cherry-picking of results. When comparing with the baseline methods, we maintained the default settings for all selected models, ensuring consistent video resolution. Videos were assessed based on three criteria: Text Alignment, Motion Quality and Visual Quality. More than 60 professional evaluators performed the evaluation. Notably, HunyuanVideo demonstrated the best overall performance, particularly excelling in motion quality.
 
 
 
114
 
115
  <p align="center">
116
  <table>
 
133
  <td>GEN-3 alpha (Web)</td> <td>&#10008</td> <td>6s</td> <td>47.7%</td> <td>54.7%</td> <td>97.5%</td> <td>27.4%</td> <td>4</td>
134
  </tr>
135
  <tr>
136
+ <td>Luma1.6 (API)</td><td>&#10008</td> <td>5s</td> <td>57.6%</td> <td>44.2%</td> <td>94.1%</td> <td>24.8%</td> <td>6</td>
137
  </tr>
138
  <tr>
139
+ <td>CNTopC (Web)</td> <td>&#10008</td> <td>5s</td> <td>48.4%</td> <td>47.2%</td> <td>96.3%</td> <td>24.6%</td> <td>5</td>
140
  </tr>
141
  </tbody>
142
  </table>
143
  </p>
144
 
145
+ ## πŸ“œ Requirements
 
 
146
 
147
  The following table shows the requirements for running HunyuanVideo model (batch size = 1) to generate videos:
148
 
149
+ | Model | Setting<br/>(height/width/frame) | Denoising step | GPU Peak Memory |
150
+ |:------------:|:--------------------------------:|:--------------:|:----------------:|
151
+ | HunyuanVideo | 720px1280px129f | 30 | 60GB |
152
+ | HunyuanVideo | 544px960px129f | 30 | 45GB |
153
 
154
  * An NVIDIA GPU with CUDA support is required.
155
  * The model is tested on a single 80G GPU.
 
157
  * **Recommended**: We recommend using a GPU with 80GB of memory for better generation quality.
158
  * Tested operating system: Linux
159
 
160
+ ## πŸ› οΈ Dependencies and Installation
 
 
161
 
162
  Begin by cloning the repository:
 
163
  ```shell
164
  git clone https://github.com/tencent/HunyuanVideo
165
  cd HunyuanVideo
 
167
 
168
  ### Installation Guide for Linux
169
 
170
+ We provide an `environment.yml` file for setting up a Conda environment.
 
171
  Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
172
 
173
+ We recommend CUDA versions 11.8 and 12.0+.
174
+
175
  ```shell
176
+ # 1. Prepare conda environment
177
+ conda env create -f environment.yml
178
 
179
  # 2. Activate the environment
180
  conda activate HunyuanVideo
181
 
182
+ # 3. Install pip dependencies
 
 
 
 
 
 
183
  python -m pip install -r requirements.txt
184
 
185
+ # 4. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
186
+ python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.5.9.post1
 
 
 
 
187
  ```
188
 
189
+ Additionally, HunyuanVideo also provides a pre-built Docker image:
190
+ [docker_hunyuanvideo](https://hub.docker.com/repository/docker/hunyuanvideo/hunyuanvideo/general).
191
 
192
  ```shell
193
+ # 1. Use the following link to download the docker image tar file (For CUDA 12).
194
+ wget https://aivideo.hunyuan.tencent.com/download/HunyuanVideo/hunyuan_video_cu12.tar
 
 
 
 
 
 
 
 
 
 
 
195
 
196
+ # 2. Import the docker tar file and show the image meta information (For CUDA 12).
197
+ docker load -i hunyuan_video.tar
198
 
199
+ docker image ls
 
 
 
200
 
201
+ # 3. Run the container based on the image
202
+ docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged docker_image_tag
 
203
  ```
204
 
205
 
206
+ ## 🧱 Download Pretrained Models
207
 
208
+ The details of download pretrained models are shown [here](https://github.com/Tencent/HunyuanVideo/blob/main/ckpts/README.md).
 
 
 
 
 
 
209
 
210
+ ## πŸ”‘ Inference
211
  We list the height/width/frame settings we support in the following table.
212
 
213
+ | Resolution | h/w=9:16 | h/w=16:9 | h/w=4:3 | h/w=3:4 | h/w=1:1 |
214
+ |:---------------------:|:----------------------------:|:---------------:|:---------------:|:---------------:|:---------------:|
215
+ | 540p | 544px960px129f | 960px544px129f | 624px832px129f | 832px624px129f | 720px720px129f |
216
+ | 720p (recommended) | 720px1280px129f | 1280px720px129f | 1104px832px129f | 832px1104px129f | 960px960px129f |
217
 
218
  ### Using Command Line
219
 
 
223
  python3 sample_video.py \
224
  --video-size 720 1280 \
225
  --video-length 129 \
226
+ --infer-steps 30 \
227
+ --prompt "a cat is running, realistic." \
228
  --flow-reverse \
229
+ --seed 0 \
230
  --use-cpu-offload \
231
  --save-path ./results
232
  ```
233
 
 
 
 
 
 
 
 
 
 
234
  ### More Configurations
235
 
236
  We list some more useful configurations for easy usage:
237
 
238
+ | Argument | Default | Description |
239
+ |:----------------------:|:---------:|:-----------------------------------------:|
240
+ | `--prompt` | None | The text prompt for video generation |
241
+ | `--video-size` | 720 1280 | The size of the generated video |
242
+ | `--video-length` | 129 | The length of the generated video |
243
+ | `--infer-steps` | 30 | The number of steps for sampling |
244
+ | `--embedded-cfg-scale` | 6.0 | Embeded Classifier free guidance scale |
245
+ | `--flow-shift` | 9.0 | Shift factor for flow matching schedulers |
246
+ | `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |
247
+ | `--neg-prompt` | None | The negative prompt for video generation |
248
+ | `--seed` | 0 | The random seed for generating video |
249
+ | `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |
250
+ | `--save-path` | ./results | Path to save the generated video |
251
+
252
+
253
+ ## πŸ”— BibTeX
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  If you find [HunyuanVideo](https://arxiv.org/abs/2412.03603) useful for your research and applications, please cite using this BibTeX:
255
 
256
  ```BibTeX
257
  @misc{kong2024hunyuanvideo,
258
  title={HunyuanVideo: A Systematic Framework For Large Video Generative Models},
259
+ author={Weijie Kong, Qi Tian, Zijian Zhang, Rox Min, Zuozhuo Dai, Jin Zhou, Jiangfeng Xiong, Xin Li, Bo Wu, Jianwei Zhang, Kathrina Wu, Qin Lin, Aladdin Wang, Andong Wang, Changlin Li, Duojun Huang, Fang Yang, Hao Tan, Hongmei Wang, Jacob Song, Jiawang Bai, Jianbing Wu, Jinbao Xue, Joey Wang, Junkun Yuan, Kai Wang, Mengyang Liu, Pengyu Li, Shuai Li, Weiyan Wang, Wenqing Yu, Xinchi Deng, Yang Li, Yanxin Long, Yi Chen, Yutao Cui, Yuanbo Peng, Zhentao Yu, Zhiyu He, Zhiyong Xu, Zixiang Zhou, Yangyu Tao, Qinglin Lu, Songtao Liu, Dax Zhou, Hongfa Wang, Yong Yang, Di Wang, Yuhong Liu, and Jie Jiang, along with Caesar Zhong},
260
  year={2024},
261
  archivePrefix={arXiv preprint arXiv:2412.03603},
262
+ primaryClass={cs.CV}
 
263
  }
264
  ```
265
 
 
 
266
  ## Acknowledgements
 
267
  We would like to thank the contributors to the [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium), [FLUX](https://github.com/black-forest-labs/flux), [Llama](https://github.com/meta-llama/llama), [LLaVA](https://github.com/haotian-liu/LLaVA), [Xtuner](https://github.com/InternLM/xtuner), [diffusers](https://github.com/huggingface/diffusers) and [HuggingFace](https://huggingface.co) repositories, for their open research and exploration.
268
  Additionally, we also thank the Tencent Hunyuan Multimodal team for their help with the text encoder.
 
hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:99fbade8af80b5233194e4e8afcaa3ca68a412fce6403a440f962a432fc18a9c
3
- size 13185233506
 
 
 
 
hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8_map.pt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:9dd948e1717718f93ad5c23cbb32fe5fe14516c7acbe8b39b63cac2a7ab575cd
3
- size 103890