Text-to-Video
ckczzj commited on
Commit
b104b34
Β·
1 Parent(s): b1e4ba4

Update README.md

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