Text-to-Video
README.md CHANGED
@@ -19,138 +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
  - [ ] ComfyUI
45
- - [ ] Multi-gpus PipeFusion inference (Low memory requirements)
46
  - HunyuanVideo (Image-to-Video Model)
47
  - [ ] Inference
48
  - [ ] Checkpoints
49
 
50
-
51
-
52
  ## Contents
53
-
54
- - [HunyuanVideo: A Systematic Framework For Large Video Generation Model](#hunyuanvideo-a-systematic-framework-for-large-video-generation-model)
55
- - [News!!](#news)
56
- - [Open-source Plan](#open-source-plan)
57
  - [Contents](#contents)
58
  - [**Abstract**](#abstract)
59
- - [**HunyuanVideo Overall Architecture**](#hunyuanvideo-overall-architecture)
60
- - [**HunyuanVideo Key Features**](#hunyuanvideo-key-features)
61
  - [**Unified Image and Video Generative Architecture**](#unified-image-and-video-generative-architecture)
62
  - [**MLLM Text Encoder**](#mllm-text-encoder)
63
  - [**3D VAE**](#3d-vae)
64
  - [**Prompt Rewrite**](#prompt-rewrite)
65
- - [Comparisons](#comparisons)
66
- - [Requirements](#requirements)
67
- - [Dependencies and Installation](#️dependencies-and-installation)
68
  - [Installation Guide for Linux](#installation-guide-for-linux)
69
- - [Download Pretrained Models](#download-pretrained-models)
70
- - [Single-gpu Inference](#single-gpu-inference)
71
  - [Using Command Line](#using-command-line)
72
- - [Run a Gradio Server](#run-a-gradio-server)
73
  - [More Configurations](#more-configurations)
74
- - [Parallel Inference on Multiple GPUs by xDiT](#parallel-inference-on-multiple-gpus-by-xdit)
75
- - [Using Command Line](#using-command-line-1)
76
- - [FP8 Inference](#fp8-inference)
77
- - [Using Command Line](#using-command-line-2)
78
- - [BibTeX](#bibtex)
79
  - [Acknowledgements](#acknowledgements)
80
-
81
  ---
82
 
83
  ## **Abstract**
 
84
 
85
- 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.
86
-
87
- 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.
88
 
89
-
90
-
91
- ## **HunyuanVideo Overall Architecture**
92
 
93
  HunyuanVideo is trained on a spatial-temporally
94
- compressed latent space, which is compressed through a Causal 3D VAE. Text prompts are encoded
95
- using a large language model, and used as the conditions. Taking Gaussian noise and the conditions as
96
- input, our generative model produces an output latent, which is then decoded to images or videos through
97
  the 3D VAE decoder.
98
-
99
  <p align="center">
100
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/overall.png" height=300>
101
  </p>
102
 
103
-
104
-
105
- ## **HunyuanVideo Key Features**
106
-
107
  ### **Unified Image and Video Generative Architecture**
108
-
109
  HunyuanVideo introduces the Transformer design and employs a Full Attention mechanism for unified image and video generation.
110
  Specifically, we use a "Dual-stream to Single-stream" hybrid model design for video generation. In the dual-stream phase, video and text
111
  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
112
  tokens and feed them into subsequent Transformer blocks for effective multimodal information fusion.
113
  This design captures complex interactions between visual and semantic information, enhancing
114
  overall model performance.
115
-
116
  <p align="center">
117
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/backbone.png" height=350>
118
  </p>
119
 
120
-
121
  ### **MLLM Text Encoder**
122
-
123
- 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)
124
- Compared with CLIP, MLLM has demonstrated superior ability in image detail description
125
- 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.
126
-
127
  <p align="center">
128
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/text_encoder.png" height=275>
129
  </p>
130
 
131
-
132
  ### **3D VAE**
133
-
134
- 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.
135
-
136
  <p align="center">
137
  <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/3dvae.png" height=150>
138
  </p>
139
 
140
-
141
  ### **Prompt Rewrite**
142
-
143
  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.
144
 
145
- 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.
146
 
147
  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).
148
 
 
149
 
150
-
151
- ## Comparisons
152
-
153
- 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.
154
 
155
  <p align="center">
156
  <table>
@@ -173,25 +133,23 @@ To evaluate the performance of HunyuanVideo, we selected five strong baselines f
173
  <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>
174
  </tr>
175
  <tr>
176
- <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>
177
  </tr>
178
  <tr>
179
- <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>
180
  </tr>
181
  </tbody>
182
  </table>
183
  </p>
184
 
185
-
186
-
187
- ## Requirements
188
 
189
  The following table shows the requirements for running HunyuanVideo model (batch size = 1) to generate videos:
190
 
191
- | Model | Setting<br/>(height/width/frame) | GPU Peak Memory |
192
- | :----------: | :------------------------------: | :-------------: |
193
- | HunyuanVideo | 720px1280px129f | 60GB |
194
- | HunyuanVideo | 544px960px129f | 45GB |
195
 
196
  * An NVIDIA GPU with CUDA support is required.
197
  * The model is tested on a single 80G GPU.
@@ -199,12 +157,9 @@ The following table shows the requirements for running HunyuanVideo model (batch
199
  * **Recommended**: We recommend using a GPU with 80GB of memory for better generation quality.
200
  * Tested operating system: Linux
201
 
202
-
203
-
204
- ## Dependencies and Installation
205
 
206
  Begin by cloning the repository:
207
-
208
  ```shell
209
  git clone https://github.com/tencent/HunyuanVideo
210
  cd HunyuanVideo
@@ -212,79 +167,53 @@ cd HunyuanVideo
212
 
213
  ### Installation Guide for Linux
214
 
215
- We recommend CUDA versions 12.4 or 11.8 for the manual installation.
216
-
217
  Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
218
 
 
 
219
  ```shell
220
- # 1. Create conda environment
221
- conda create -n HunyuanVideo python==3.10.9
222
 
223
  # 2. Activate the environment
224
  conda activate HunyuanVideo
225
 
226
- # 3. Install PyTorch and other dependencies using conda
227
- # For CUDA 11.8
228
- conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=11.8 -c pytorch -c nvidia
229
- # For CUDA 12.4
230
- conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.4 -c pytorch -c nvidia
231
-
232
- # 4. Install pip dependencies
233
  python -m pip install -r requirements.txt
234
 
235
- # 5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
236
- python -m pip install ninja
237
- python -m pip install git+https://github.com/Dao-AILab/[email protected]
238
-
239
- # 6. Install xDiT for parallel inference (It is recommended to use torch 2.4.0 and flash-attn 2.6.3)
240
- python -m pip install xfuser==0.4.0
241
  ```
242
 
243
- In case of running into float point exception(core dump) on the specific GPU type, you may try the following solutions:
 
244
 
245
  ```shell
246
- # 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).
247
- pip install nvidia-cublas-cu12==12.4.5.8
248
- export LD_LIBRARY_PATH=/opt/conda/lib/python3.8/site-packages/nvidia/cublas/lib/
249
-
250
- # Option 2: Forcing to explictly use the CUDA 11.8 compiled version of Pytorch and all the other packages
251
- pip uninstall -r requirements.txt # uninstall all packages
252
- pip uninstall -y xfuser
253
- pip install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu118
254
- pip install -r requirements.txt
255
- pip install ninja
256
- pip install git+https://github.com/Dao-AILab/[email protected]
257
- pip install xfuser==0.4.0
258
- ```
259
 
260
- Additionally, HunyuanVideo also provides a pre-built Docker image. Use the following command to pull and run the docker image.
 
261
 
262
- ```shell
263
- # For CUDA 12.4 (updated to avoid float point exception)
264
- docker pull hunyuanvideo/hunyuanvideo:cuda_12
265
- 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
266
 
267
- # For CUDA 11.8
268
- docker pull hunyuanvideo/hunyuanvideo:cuda_11
269
- 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
270
  ```
271
 
272
 
 
273
 
274
- ## Download Pretrained Models
275
-
276
- The details of download pretrained models are shown [here](ckpts/README.md).
277
-
278
-
279
-
280
- ## Single-gpu Inference
281
 
 
282
  We list the height/width/frame settings we support in the following table.
283
 
284
- | Resolution | h/w=9:16 | h/w=16:9 | h/w=4:3 | h/w=3:4 | h/w=1:1 |
285
- | :----------------: | :-------------: | :-------------: | :-------------: | :-------------: | :------------: |
286
- | 540p | 544px960px129f | 960px544px129f | 624px832px129f | 832px624px129f | 720px720px129f |
287
- | 720p (recommended) | 720px1280px129f | 1280px720px129f | 1104px832px129f | 832px1104px129f | 960px960px129f |
288
 
289
  ### Using Command Line
290
 
@@ -294,175 +223,46 @@ cd HunyuanVideo
294
  python3 sample_video.py \
295
  --video-size 720 1280 \
296
  --video-length 129 \
297
- --infer-steps 50 \
298
- --prompt "A cat walks on the grass, realistic style." \
299
  --flow-reverse \
 
300
  --use-cpu-offload \
301
  --save-path ./results
302
  ```
303
 
304
- ### Run a Gradio Server
305
-
306
- ```bash
307
- python3 gradio_server.py --flow-reverse
308
-
309
- # set SERVER_NAME and SERVER_PORT manually
310
- # SERVER_NAME=0.0.0.0 SERVER_PORT=8081 python3 gradio_server.py --flow-reverse
311
- ```
312
-
313
  ### More Configurations
314
 
315
  We list some more useful configurations for easy usage:
316
 
317
- | Argument | Default | Description |
318
- | :--------------------: | :-------: | :----------------------------------------------------------: |
319
- | `--prompt` | None | The text prompt for video generation |
320
- | `--video-size` | 720 1280 | The size of the generated video |
321
- | `--video-length` | 129 | The length of the generated video |
322
- | `--infer-steps` | 50 | The number of steps for sampling |
323
- | `--embedded-cfg-scale` | 6.0 | Embedded Classifier free guidance scale |
324
- | `--flow-shift` | 7.0 | Shift factor for flow matching schedulers |
325
- | `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |
326
- | `--seed` | None | The random seed for generating video, if None, we init a random seed |
327
- | `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |
328
- | `--save-path` | ./results | Path to save the generated video |
329
-
330
-
331
-
332
- ## Parallel Inference on Multiple GPUs by xDiT
333
-
334
- [xDiT](https://github.com/xdit-project/xDiT) is a Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters.
335
- 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.
336
-
337
- ### Using Command Line
338
-
339
- For example, to generate a video with 8 GPUs, you can use the following command:
340
-
341
- ```bash
342
- cd HunyuanVideo
343
-
344
- torchrun --nproc_per_node=8 sample_video.py \
345
- --video-size 1280 720 \
346
- --video-length 129 \
347
- --infer-steps 50 \
348
- --prompt "A cat walks on the grass, realistic style." \
349
- --flow-reverse \
350
- --seed 42 \
351
- --ulysses-degree 8 \
352
- --ring-degree 1 \
353
- --save-path ./results
354
- ```
355
-
356
- 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.
357
-
358
- <details>
359
- <summary>Supported Parallel Configurations (Click to expand)</summary>
360
-
361
-
362
- | --video-size | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |
363
- | -------------------- | -------------- | -------------------------------- | ---------------- |
364
- | 1280 720 or 720 1280 | 129 | 8x1,4x2,2x4,1x8 | 8 |
365
- | 1280 720 or 720 1280 | 129 | 1x5 | 5 |
366
- | 1280 720 or 720 1280 | 129 | 4x1,2x2,1x4 | 4 |
367
- | 1280 720 or 720 1280 | 129 | 3x1,1x3 | 3 |
368
- | 1280 720 or 720 1280 | 129 | 2x1,1x2 | 2 |
369
- | 1104 832 or 832 1104 | 129 | 4x1,2x2,1x4 | 4 |
370
- | 1104 832 or 832 1104 | 129 | 3x1,1x3 | 3 |
371
- | 1104 832 or 832 1104 | 129 | 2x1,1x2 | 2 |
372
- | 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
373
- | 960 960 | 129 | 4x1,2x2,1x4 | 4 |
374
- | 960 960 | 129 | 3x1,1x3 | 3 |
375
- | 960 960 | 129 | 1x2,2x1 | 2 |
376
- | 960 544 or 544 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
377
- | 960 544 or 544 960 | 129 | 4x1,2x2,1x4 | 4 |
378
- | 960 544 or 544 960 | 129 | 3x1,1x3 | 3 |
379
- | 960 544 or 544 960 | 129 | 1x2,2x1 | 2 |
380
- | 832 624 or 624 832 | 129 | 4x1,2x2,1x4 | 4 |
381
- | 624 832 or 624 832 | 129 | 3x1,1x3 | 3 |
382
- | 832 624 or 624 832 | 129 | 2x1,1x2 | 2 |
383
- | 720 720 | 129 | 1x5 | 5 |
384
- | 720 720 | 129 | 3x1,1x3 | 3 |
385
-
386
- </details>
387
-
388
-
389
- <p align="center">
390
- <table align="center">
391
- <thead>
392
- <tr>
393
- <th colspan="4">Latency (Sec) for 1280x720 (129 frames 50 steps) on 8xGPU</th>
394
- </tr>
395
- <tr>
396
- <th>1</th>
397
- <th>2</th>
398
- <th>4</th>
399
- <th>8</th>
400
- </tr>
401
- </thead>
402
- <tbody>
403
- <tr>
404
- <th>1904.08</th>
405
- <th>934.09 (2.04x)</th>
406
- <th>514.08 (3.70x)</th>
407
- <th>337.58 (5.64x)</th>
408
- </tr>
409
-
410
-
411
- </tbody>
412
- </table>
413
- </p>
414
-
415
-
416
-
417
- ## FP8 Inference
418
-
419
- 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.
420
-
421
- ### Using Command Line
422
-
423
- Here, you must explicitly specify the FP8 weight path. For example, to generate a video with fp8 weights, you can use the following command:
424
-
425
- ```bash
426
- cd HunyuanVideo
427
-
428
- DIT_CKPT_PATH={PATH_TO_FP8_WEIGHTS}/{WEIGHT_NAME}_fp8.pt
429
-
430
- python3 sample_video.py \
431
- --dit-weight ${DIT_CKPT_PATH} \
432
- --video-size 1280 720 \
433
- --video-length 129 \
434
- --infer-steps 50 \
435
- --prompt "A cat walks on the grass, realistic style." \
436
- --seed 42 \
437
- --embedded-cfg-scale 6.0 \
438
- --flow-shift 7.0 \
439
- --flow-reverse \
440
- --use-cpu-offload \
441
- --use-fp8 \
442
- --save-path ./results
443
- ```
444
-
445
-
446
-
447
- ## BibTeX
448
-
449
  If you find [HunyuanVideo](https://arxiv.org/abs/2412.03603) useful for your research and applications, please cite using this BibTeX:
450
 
451
  ```BibTeX
452
  @misc{kong2024hunyuanvideo,
453
  title={HunyuanVideo: A Systematic Framework For Large Video Generative Models},
454
- 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},
455
  year={2024},
456
  archivePrefix={arXiv preprint arXiv:2412.03603},
457
- primaryClass={cs.CV},
458
- url={https://arxiv.org/abs/2412.03603},
459
  }
460
  ```
461
 
462
-
463
-
464
  ## Acknowledgements
465
-
466
  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.
467
  Additionally, we also thank the Tencent Hunyuan Multimodal team for their help with the text encoder.
468
-
 
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/[email protected]
 
 
 
 
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