goingyt commited on
Commit
fce6e65
Β·
verified Β·
1 Parent(s): 545ad0c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +269 -0
README.md CHANGED
@@ -8,3 +8,272 @@ pinned: false
8
  ---
9
 
10
  Edit this `README.md` markdown file to author your organization card.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
  Edit this `README.md` markdown file to author your organization card.
11
+
12
+ ---
13
+ pipeline_tag: text-to-video
14
+ license: other
15
+ license_name: tencent-hunyuan-community
16
+ license_link: LICENSE
17
+ ---
18
+
19
+ <!-- ## **HunyuanVideo** -->
20
+
21
+ <p align="center">
22
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/logo.png" height=100>
23
+ </p>
24
+
25
+ # HunyuanVideo: A Systematic Framework For Large Video Generation Model Training
26
+
27
+ -----
28
+
29
+ This repo contains PyTorch model definitions, pre-trained weights and inference/sampling code for our paper exploring HunyuanVideo. You can find more visualizations on our [project page](https://aivideo.hunyuan.tencent.com).
30
+
31
+ > [**HunyuanVideo: A Systematic Framework For Large Video Generation Model Training**](https://arxiv.org/abs/2412.03603) <br>
32
+
33
+ ## πŸ”₯πŸ”₯πŸ”₯ News!!
34
+ * Dec 3, 2024: πŸ€— We release the inference code and model weights of HunyuanVideo.
35
+
36
+ ## πŸ“‘ Open-source Plan
37
+
38
+ - HunyuanVideo (Text-to-Video Model)
39
+ - [x] Inference
40
+ - [x] Checkpoints
41
+ - [ ] Penguin Video Benchmark
42
+ - [ ] Web Demo (Gradio)
43
+ - [ ] ComfyUI
44
+ - [ ] Diffusers
45
+ - HunyuanVideo (Image-to-Video Model)
46
+ - [ ] Inference
47
+ - [ ] Checkpoints
48
+
49
+ ## Contents
50
+ - [HunyuanVideo: A Systematic Framework For Large Video Generation Model Training](#hunyuanvideo--a-systematic-framework-for-large-video-generation-model-training)
51
+ - [πŸ”₯πŸ”₯πŸ”₯ News!!](#-news!!)
52
+ - [πŸ“‘ Open-source Plan](#-open-source-plan)
53
+ - [Contents](#contents)
54
+ - [**Abstract**](#abstract)
55
+ - [**HunyuanVideo Overall Architechture**](#-hunyuanvideo-overall-architechture)
56
+ - [πŸŽ‰ **HunyuanVideo Key Features**](#-hunyuanvideo-key-features)
57
+ - [**Unified Image and Video Generative Architecture**](#unified-image-and-video-generative-architecture)
58
+ - [**MLLM Text Encoder**](#mllm-text-encoder)
59
+ - [**3D VAE**](#3d-vae)
60
+ - [**Prompt Rewrite**](#prompt-rewrite)
61
+ - [πŸ“ˆ Comparisons](#-comparisons)
62
+ - [πŸ“œ Requirements](#-requirements)
63
+ - [πŸ› οΈ Dependencies and Installation](#-dependencies-and-installation)
64
+ - [Installation Guide for Linux](#installation-guide-for-linux)
65
+ - [🧱 Download Pretrained Models](#-download-pretrained-models)
66
+ - [πŸ”‘ Inference](#-inference)
67
+ - [Using Command Line](#using-command-line)
68
+ - [More Configurations](#more-configurations)
69
+ - [πŸ”— BibTeX](#-bibtex)
70
+ - [Acknowledgements](#acknowledgements)
71
+ ---
72
+
73
+ ## **Abstract**
74
+ 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.
75
+
76
+ 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.
77
+
78
+ ## **HunyuanVideo Overall Architechture**
79
+
80
+ HunyuanVideo is trained on a spatial-temporally
81
+ compressed latent space, which is compressed through Causal 3D VAE. Text prompts are encoded
82
+ using a large language model, and used as the condition. Gaussian noise and condition are taken as
83
+ input, our generate model generates an output latent, which is decoded to images or videos through
84
+ the 3D VAE decoder.
85
+ <p align="center">
86
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/overall.png" height=300>
87
+ </p>
88
+
89
+ ## πŸŽ‰ **HunyuanVideo Key Features**
90
+ ### **Unified Image and Video Generative Architecture**
91
+ HunyuanVideo introduces the Transformer design and employs a Full Attention mechanism for unified image and video generation.
92
+ Specifically, we use a "Dual-stream to Single-stream" hybrid model design for video generation. In the dual-stream phase, video and text
93
+ 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
94
+ tokens and feed them into subsequent Transformer blocks for effective multimodal information fusion.
95
+ This design captures complex interactions between visual and semantic information, enhancing
96
+ overall model performance.
97
+ <p align="center">
98
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/backbone.png" height=350>
99
+ </p>
100
+
101
+ ### **MLLM Text Encoder**
102
+ 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)
103
+ Compared with CLIP, MLLM has been demonstrated superior ability in image detail description
104
+ 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.
105
+ <p align="center">
106
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/text_encoder.png" height=275>
107
+ </p>
108
+
109
+ ### **3D VAE**
110
+ 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.
111
+ <p align="center">
112
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/3dvae.png" height=150>
113
+ </p>
114
+
115
+ ### **Prompt Rewrite**
116
+ 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.
117
+
118
+ 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.
119
+
120
+ 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).
121
+
122
+ ## πŸ“ˆ Comparisons
123
+
124
+ 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.
125
+
126
+ <p align="center">
127
+ <table>
128
+ <thead>
129
+ <tr>
130
+ <th rowspan="2">Model</th> <th rowspan="2">Open Source</th> <th>Duration</th> <th>Text Alignment</th> <th>Motion Quality</th> <th rowspan="2">Visual Quality</th> <th rowspan="2">Overall</th> <th rowspan="2">Ranking</th>
131
+ </tr>
132
+ </thead>
133
+ <tbody>
134
+ <tr>
135
+ <td>HunyuanVideo (Ours)</td> <td> βœ” </td> <td>5s</td> <td>61.8%</td> <td>66.5%</td> <td>95.7%</td> <td>41.3%</td> <td>1</td>
136
+ </tr>
137
+ <tr>
138
+ <td>CNTopA (API)</td> <td> &#10008 </td> <td>5s</td> <td>62.6%</td> <td>61.7%</td> <td>95.6%</td> <td>37.7%</td> <td>2</td>
139
+ </tr>
140
+ <tr>
141
+ <td>CNTopB (Web)</td> <td> &#10008</td> <td>5s</td> <td>60.1%</td> <td>62.9%</td> <td>97.7%</td> <td>37.5%</td> <td>3</td>
142
+ </tr>
143
+ <tr>
144
+ <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>
145
+ </tr>
146
+ <tr>
147
+ <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>
148
+ </tr>
149
+ <tr>
150
+ <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>
151
+ </tr>
152
+ </tbody>
153
+ </table>
154
+ </p>
155
+
156
+ ## πŸ“œ Requirements
157
+
158
+ The following table shows the requirements for running HunyuanVideo model (batch size = 1) to generate videos:
159
+
160
+ | Model | Setting<br/>(height/width/frame) | Denoising step | GPU Peak Memory |
161
+ |:------------:|:--------------------------------:|:--------------:|:----------------:|
162
+ | HunyuanVideo | 720px1280px129f | 30 | 60GB |
163
+ | HunyuanVideo | 544px960px129f | 30 | 45GB |
164
+
165
+ * An NVIDIA GPU with CUDA support is required.
166
+ * The model is tested on a single 80G GPU.
167
+ * **Minimum**: The minimum GPU memory required is 60GB for 720px1280px129f and 45G for 544px960px129f.
168
+ * **Recommended**: We recommend using a GPU with 80GB of memory for better generation quality.
169
+ * Tested operating system: Linux
170
+
171
+ ## πŸ› οΈ Dependencies and Installation
172
+
173
+ Begin by cloning the repository:
174
+ ```shell
175
+ git clone https://github.com/tencent/HunyuanVideo
176
+ cd HunyuanVideo
177
+ ```
178
+
179
+ ### Installation Guide for Linux
180
+
181
+ We provide an `environment.yml` file for setting up a Conda environment.
182
+ Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
183
+
184
+ We recommend CUDA versions 11.8 and 12.0+.
185
+
186
+ ```shell
187
+ # 1. Prepare conda environment
188
+ conda env create -f environment.yml
189
+
190
+ # 2. Activate the environment
191
+ conda activate HunyuanVideo
192
+
193
+ # 3. Install pip dependencies
194
+ python -m pip install -r requirements.txt
195
+
196
+ # 4. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
197
+ python -m pip install git+https://github.com/Dao-AILab/[email protected]
198
+ ```
199
+
200
+ Additionally, HunyuanVideo also provides a pre-built Docker image:
201
+ [docker_hunyuanvideo](https://hub.docker.com/repository/docker/hunyuanvideo/hunyuanvideo/general).
202
+
203
+ ```shell
204
+ # 1. Use the following link to download the docker image tar file (For CUDA 12).
205
+ wget https://aivideo.hunyuan.tencent.com/download/HunyuanVideo/hunyuan_video_cu12.tar
206
+
207
+ # 2. Import the docker tar file and show the image meta information (For CUDA 12).
208
+ docker load -i hunyuan_video.tar
209
+
210
+ docker image ls
211
+
212
+ # 3. Run the container based on the image
213
+ 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
214
+ ```
215
+
216
+
217
+ ## 🧱 Download Pretrained Models
218
+
219
+ The details of download pretrained models are shown [here](https://github.com/Tencent/HunyuanVideo/blob/main/ckpts/README.md).
220
+
221
+ ## πŸ”‘ Inference
222
+ We list the height/width/frame settings we support in the following table.
223
+
224
+ | Resolution | h/w=9:16 | h/w=16:9 | h/w=4:3 | h/w=3:4 | h/w=1:1 |
225
+ |:---------------------:|:----------------------------:|:---------------:|:---------------:|:---------------:|:---------------:|
226
+ | 540p | 544px960px129f | 960px544px129f | 624px832px129f | 832px624px129f | 720px720px129f |
227
+ | 720p (recommended) | 720px1280px129f | 1280px720px129f | 1104px832px129f | 832px1104px129f | 960px960px129f |
228
+
229
+ ### Using Command Line
230
+
231
+ ```bash
232
+ cd HunyuanVideo
233
+
234
+ python3 sample_video.py \
235
+ --video-size 720 1280 \
236
+ --video-length 129 \
237
+ --infer-steps 30 \
238
+ --prompt "a cat is running, realistic." \
239
+ --flow-reverse \
240
+ --seed 0 \
241
+ --use-cpu-offload \
242
+ --save-path ./results
243
+ ```
244
+
245
+ ### More Configurations
246
+
247
+ We list some more useful configurations for easy usage:
248
+
249
+ | Argument | Default | Description |
250
+ |:----------------------:|:---------:|:-----------------------------------------:|
251
+ | `--prompt` | None | The text prompt for video generation |
252
+ | `--video-size` | 720 1280 | The size of the generated video |
253
+ | `--video-length` | 129 | The length of the generated video |
254
+ | `--infer-steps` | 30 | The number of steps for sampling |
255
+ | `--embedded-cfg-scale` | 6.0 | Embeded Classifier free guidance scale |
256
+ | `--flow-shift` | 9.0 | Shift factor for flow matching schedulers |
257
+ | `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |
258
+ | `--neg-prompt` | None | The negative prompt for video generation |
259
+ | `--seed` | 0 | The random seed for generating video |
260
+ | `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |
261
+ | `--save-path` | ./results | Path to save the generated video |
262
+
263
+
264
+ ## πŸ”— BibTeX
265
+ If you find [HunyuanVideo](https://arxiv.org/abs/2412.03603) useful for your research and applications, please cite using this BibTeX:
266
+
267
+ ```BibTeX
268
+ @misc{kong2024hunyuanvideo,
269
+ title={HunyuanVideo: A Systematic Framework For Large Video Generative Models},
270
+ 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},
271
+ year={2024},
272
+ archivePrefix={arXiv preprint arXiv:2412.03603},
273
+ primaryClass={cs.CV}
274
+ }
275
+ ```
276
+
277
+ ## Acknowledgements
278
+ 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.
279
+ Additionally, we also thank the Tencent Hunyuan Multimodal team for their help with the text encoder.