Add link to paper and project page

#19
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +267 -88
README.md CHANGED
@@ -1,14 +1,15 @@
1
  ---
2
- license: apache-2.0
3
  language:
4
  - en
5
  - zh
6
- pipeline_tag: text-to-video
7
  library_name: diffusers
 
 
8
  tags:
9
  - video
10
  - video-generation
11
  ---
 
12
  # Wan2.1
13
 
14
  <p align="center">
@@ -16,12 +17,12 @@ tags:
16
  <p>
17
 
18
  <p align="center">
19
- 💜 <a href=""><b>Wan</b></a> &nbsp&nbsp | &nbsp&nbsp 🖥️ <a href="https://github.com/Wan-Video/Wan2.1">GitHub</a> &nbsp&nbsp | &nbsp&nbsp🤗 <a href="https://huggingface.co/Wan-AI/">Hugging Face</a>&nbsp&nbsp | &nbsp&nbsp🤖 <a href="https://modelscope.cn/organization/Wan-AI">ModelScope</a>&nbsp&nbsp | &nbsp&nbsp 📑 <a href="">Paper (Coming soon)</a> &nbsp&nbsp | &nbsp&nbsp 📑 <a href="https://wanxai.com">Blog</a> &nbsp&nbsp | &nbsp&nbsp💬 <a href="https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg">WeChat Group</a>&nbsp&nbsp | &nbsp&nbsp 📖 <a href="https://discord.gg/p5XbdQV7">Discord</a>&nbsp&nbsp
20
  <br>
21
 
22
  -----
23
 
24
- [**Wan: Open and Advanced Large-Scale Video Generative Models**]("#") <be>
25
 
26
  In this repository, we present **Wan2.1**, a comprehensive and open suite of video foundation models that pushes the boundaries of video generation. **Wan2.1** offers these key features:
27
  - 👍 **SOTA Performance**: **Wan2.1** consistently outperforms existing open-source models and state-of-the-art commercial solutions across multiple benchmarks.
@@ -30,23 +31,23 @@ In this repository, we present **Wan2.1**, a comprehensive and open suite of vid
30
  - 👍 **Visual Text Generation**: **Wan2.1** is the first video model capable of generating both Chinese and English text, featuring robust text generation that enhances its practical applications.
31
  - 👍 **Powerful Video VAE**: **Wan-VAE** delivers exceptional efficiency and performance, encoding and decoding 1080P videos of any length while preserving temporal information, making it an ideal foundation for video and image generation.
32
 
33
-
34
- This repository hosts our T2V-1.3B model, a versatile solution for video generation that is compatible with nearly all consumer-grade GPUs. In this way, we hope that **Wan2.1** can serve as an easy-to-use tool for more creative teams in video creation, providing a high-quality foundational model for academic teams with limited computing resources. This will facilitate both the rapid development of the video creation community and the swift advancement of video technology.
35
-
36
-
37
  ## Video Demos
38
 
39
  <div align="center">
40
- <video width="80%" controls>
41
- <source src="https://cloud.video.taobao.com/vod/Jth64Y7wNoPcJki_Bo1ZJTDBvNjsgjlVKsNs05Fqfps.mp4" type="video/mp4">
42
- Your browser does not support the video tag.
43
- </video>
44
  </div>
45
 
46
-
47
  ## 🔥 Latest News!!
48
 
49
- * Feb 25, 2025: 👋 We've released the inference code and weights of Wan2.1.
 
 
 
 
 
 
 
 
50
 
51
 
52
  ## 📑 Todo List
@@ -54,27 +55,29 @@ This repository hosts our T2V-1.3B model, a versatile solution for video generat
54
  - [x] Multi-GPU Inference code of the 14B and 1.3B models
55
  - [x] Checkpoints of the 14B and 1.3B models
56
  - [x] Gradio demo
57
- - [ ] Diffusers integration
58
- - [ ] ComfyUI integration
 
59
  - Wan2.1 Image-to-Video
60
  - [x] Multi-GPU Inference code of the 14B model
61
  - [x] Checkpoints of the 14B model
62
  - [x] Gradio demo
63
- - [ ] Diffusers integration
64
- - [ ] ComfyUI integration
 
65
 
66
 
67
  ## Quickstart
68
 
69
  #### Installation
70
  Clone the repo:
71
- ```
72
  git clone https://github.com/Wan-Video/Wan2.1.git
73
  cd Wan2.1
74
  ```
75
 
76
  Install dependencies:
77
- ```
78
  # Ensure torch >= 2.4.0
79
  pip install -r requirements.txt
80
  ```
@@ -89,22 +92,20 @@ pip install -r requirements.txt
89
  | I2V-14B-480P | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-I2V-14B-480P) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-I2V-14B-480P) | Supports 480P
90
  | T2V-1.3B | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-T2V-1.3B) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-T2V-1.3B) | Supports 480P
91
 
92
-
93
  > 💡Note: The 1.3B model is capable of generating videos at 720P resolution. However, due to limited training at this resolution, the results are generally less stable compared to 480P. For optimal performance, we recommend using 480P resolution.
94
 
95
 
96
- Download models using 🤗 huggingface-cli:
97
- ```
98
  pip install "huggingface_hub[cli]"
99
- huggingface-cli download Wan-AI/Wan2.1-T2V-1.3B --local-dir ./Wan2.1-T2V-1.3B
100
  ```
101
 
102
- Download models using 🤖 modelscope-cli:
103
- ```
104
  pip install modelscope
105
- modelscope download Wan-AI/Wan2.1-T2V-1.3B --local_dir ./Wan2.1-T2V-1.3B
106
  ```
107
-
108
  #### Run Text-to-Video Generation
109
 
110
  This repository supports two Text-to-Video models (1.3B and 14B) and two resolutions (480P and 720P). The parameters and configurations for these models are as follows:
@@ -138,33 +139,47 @@ This repository supports two Text-to-Video models (1.3B and 14B) and two resolut
138
  </table>
139
 
140
 
141
- ##### (1) Without Prompt Extention
142
 
143
  To facilitate implementation, we will start with a basic version of the inference process that skips the [prompt extension](#2-using-prompt-extention) step.
144
 
145
  - Single-GPU inference
146
 
147
- ```
148
- python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
149
  ```
150
 
151
  If you encounter OOM (Out-of-Memory) issues, you can use the `--offload_model True` and `--t5_cpu` options to reduce GPU memory usage. For example, on an RTX 4090 GPU:
152
 
153
- ```
154
  python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --offload_model True --t5_cpu --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
155
  ```
156
 
157
  > 💡Note: If you are using the `T2V-1.3B` model, we recommend setting the parameter `--sample_guide_scale 6`. The `--sample_shift parameter` can be adjusted within the range of 8 to 12 based on the performance.
158
 
 
159
  - Multi-GPU inference using FSDP + xDiT USP
160
 
161
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  pip install "xfuser>=0.4.1"
163
- torchrun --nproc_per_node=8 generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --dit_fsdp --t5_fsdp --ulysses_size 8 --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
164
  ```
165
 
166
 
167
- ##### (2) Using Prompt Extention
168
 
169
  Extending the prompts can effectively enrich the details in the generated videos, further enhancing the video quality. Therefore, we recommend enabling prompt extension. We provide the following two methods for prompt extension:
170
 
@@ -173,44 +188,245 @@ Extending the prompts can effectively enrich the details in the generated videos
173
  - Configure the environment variable `DASH_API_KEY` to specify the Dashscope API key. For users of Alibaba Cloud's international site, you also need to set the environment variable `DASH_API_URL` to 'https://dashscope-intl.aliyuncs.com/api/v1'. For more detailed instructions, please refer to the [dashscope document](https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api?spm=a2c63.p38356.0.i1).
174
  - Use the `qwen-plus` model for text-to-video tasks and `qwen-vl-max` for image-to-video tasks.
175
  - You can modify the model used for extension with the parameter `--prompt_extend_model`. For example:
176
- ```
177
- DASH_API_KEY=your_key python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage" --use_prompt_extend --prompt_extend_method 'dashscope' --prompt_extend_target_lang 'ch'
178
  ```
179
 
180
  - Using a local model for extension.
181
 
182
- - By default, the Qwen model on HuggingFace is used for this extension. Users can choose based on the available GPU memory size.
183
- - For text-to-video tasks, you can use models like `Qwen/Qwen2.5-14B-Instruct`, `Qwen/Qwen2.5-7B-Instruct` and `Qwen/Qwen2.5-3B-Instruct`
184
  - For image-to-video tasks, you can use models like `Qwen/Qwen2.5-VL-7B-Instruct` and `Qwen/Qwen2.5-VL-3B-Instruct`.
185
  - Larger models generally provide better extension results but require more GPU memory.
186
  - You can modify the model used for extension with the parameter `--prompt_extend_model` , allowing you to specify either a local model path or a Hugging Face model. For example:
187
 
188
- ```
189
- python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage" --use_prompt_extend --prompt_extend_method 'local_qwen' --prompt_extend_target_lang 'ch'
190
  ```
191
 
192
- ##### (3) Runing local gradio
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  ```
 
 
 
 
 
 
195
  cd gradio
196
  # if one uses dashscope’s API for prompt extension
197
- DASH_API_KEY=your_key python t2v_1.3B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir ./Wan2.1-T2V-1.3B
198
 
199
  # if one uses a local model for prompt extension
200
- python t2v_1.3B_singleGPU.py --prompt_extend_method 'local_qwen' --ckpt_dir ./Wan2.1-T2V-1.3B
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  ```
202
 
 
 
203
 
 
 
 
 
 
 
204
 
205
- ## Evaluation
206
 
207
- We employ our **Wan-Bench** framework to evaluate the performance of the T2V-1.3B model, with the results displayed in the table below. The results indicate that our smaller 1.3B model surpasses the overall metrics of larger open-source models, demonstrating the effectiveness of **WanX2.1**'s architecture and the data construction pipeline.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
  <div align="center">
210
- <img src="assets/vben_1.3b_vs_sota.png" alt="" style="width: 80%;" />
211
  </div>
212
 
213
 
 
 
 
 
 
 
 
 
214
 
215
  ## Computational Efficiency on Different GPUs
216
 
@@ -227,6 +443,9 @@ We test the computational efficiency of different **Wan2.1** models on different
227
  > (3) For the 1.3B model on a single 4090 GPU, set `--offload_model True --t5_cpu`;
228
  > (4) For all testings, no prompt extension was applied, meaning `--use_prompt_extend` was not enabled.
229
 
 
 
 
230
  -------
231
 
232
  ## Introduction of Wan2.1
@@ -255,44 +474,4 @@ We propose a novel 3D causal VAE architecture, termed **Wan-VAE** specifically d
255
  | Model | Dimension | Input Dimension | Output Dimension | Feedforward Dimension | Frequency Dimension | Number of Heads | Number of Layers |
256
  |--------|-----------|-----------------|------------------|-----------------------|---------------------|-----------------|------------------|
257
  | 1.3B | 1536 | 16 | 16 | 8960 | 256 | 12 | 30 |
258
- | 14B | 5120 | 16 | 16 | 13824 | 256 | 40 | 40 |
259
-
260
-
261
-
262
- ##### Data
263
-
264
- We curated and deduplicated a candidate dataset comprising a vast amount of image and video data. During the data curation process, we designed a four-step data cleaning process, focusing on fundamental dimensions, visual quality and motion quality. Through the robust data processing pipeline, we can easily obtain high-quality, diverse, and large-scale training sets of images and videos.
265
-
266
- ![figure1](assets/data_for_diff_stage.jpg "figure1")
267
-
268
-
269
- ##### Comparisons to SOTA
270
- We compared **Wan2.1** with leading open-source and closed-source models to evaluate the performace. Using our carefully designed set of 1,035 internal prompts, we tested across 14 major dimensions and 26 sub-dimensions. Then we calculated the total score through a weighted average based on the importance of each dimension. The detailed results are shown in the table below. These results demonstrate our model's superior performance compared to both open-source and closed-source models.
271
-
272
- ![figure1](assets/vben_vs_sota.png "figure1")
273
-
274
-
275
- ## Citation
276
- If you find our work helpful, please cite us.
277
-
278
- ```
279
- @article{wan2.1,
280
- title = {Wan: Open and Advanced Large-Scale Video Generative Models},
281
- author = {Wan Team},
282
- journal = {},
283
- year = {2025}
284
- }
285
- ```
286
-
287
- ## License Agreement
288
- The models in this repository are licensed under the Apache 2.0 License. We claim no rights over the your generate contents, granting you the freedom to use them while ensuring that your usage complies with the provisions of this license. You are fully accountable for your use of the models, which must not involve sharing any content that violates applicable laws, causes harm to individuals or groups, disseminates personal information intended for harm, spreads misinformation, or targets vulnerable populations. For a complete list of restrictions and details regarding your rights, please refer to the full text of the [license](LICENSE.txt).
289
-
290
-
291
- ## Acknowledgements
292
-
293
- We would like to thank the contributors to the [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium), [Qwen](https://huggingface.co/Qwen), [umt5-xxl](https://huggingface.co/google/umt5-xxl), [diffusers](https://github.com/huggingface/diffusers) and [HuggingFace](https://huggingface.co) repositories, for their open research.
294
-
295
-
296
-
297
- ## Contact Us
298
- If you would like to leave a message to our research or product teams, feel free to join our [Discord](https://discord.gg/p5XbdQV7) or [WeChat groups](https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg)!
 
1
  ---
 
2
  language:
3
  - en
4
  - zh
 
5
  library_name: diffusers
6
+ license: apache-2.0
7
+ pipeline_tag: text-to-video
8
  tags:
9
  - video
10
  - video-generation
11
  ---
12
+
13
  # Wan2.1
14
 
15
  <p align="center">
 
17
  <p>
18
 
19
  <p align="center">
20
+ 💜 <a href="https://wan.video"><b>Wan</b></a> &nbsp&nbsp | &nbsp&nbsp 🖥️ <a href="https://github.com/Wan-Video/Wan2.1">GitHub</a> &nbsp&nbsp | &nbsp&nbsp🤗 <a href="https://huggingface.co/Wan-AI/">Hugging Face</a>&nbsp&nbsp | &nbsp&nbsp🤖 <a href="https://modelscope.cn/organization/Wan-AI">ModelScope</a>&nbsp&nbsp | &nbsp&nbsp 📑 <a href="https://huggingface.co/papers/2503.20314">Paper</a> &nbsp&nbsp | &nbsp&nbsp 📑 <a href="https://wan.video/welcome?spm=a2ty_o02.30011076.0.0.6c9ee41eCcluqg">Blog</a> &nbsp&nbsp | &nbsp&nbsp💬 <a href="https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg">WeChat Group</a>&nbsp&nbsp | &nbsp&nbsp 📖 <a href="https://discord.gg/AKNgpMK4Yj">Discord</a>&nbsp&nbsp
21
  <br>
22
 
23
  -----
24
 
25
+ [**Wan: Open and Advanced Large-Scale Video Generative Models**]("") <be>
26
 
27
  In this repository, we present **Wan2.1**, a comprehensive and open suite of video foundation models that pushes the boundaries of video generation. **Wan2.1** offers these key features:
28
  - 👍 **SOTA Performance**: **Wan2.1** consistently outperforms existing open-source models and state-of-the-art commercial solutions across multiple benchmarks.
 
31
  - 👍 **Visual Text Generation**: **Wan2.1** is the first video model capable of generating both Chinese and English text, featuring robust text generation that enhances its practical applications.
32
  - 👍 **Powerful Video VAE**: **Wan-VAE** delivers exceptional efficiency and performance, encoding and decoding 1080P videos of any length while preserving temporal information, making it an ideal foundation for video and image generation.
33
 
 
 
 
 
34
  ## Video Demos
35
 
36
  <div align="center">
37
+ <video src="https://github.com/user-attachments/assets/4aca6063-60bf-4953-bfb7-e265053f49ef" width="70%" poster=""> </video>
 
 
 
38
  </div>
39
 
 
40
  ## 🔥 Latest News!!
41
 
42
+ * Mar 21, 2025: 👋 We are excited to announce the release of the **Wan2.1** [technical report](https://files.alicdn.com/tpsservice/5c9de1c74de03972b7aa657e5a54756b.pdf). We welcome discussions and feedback!
43
+ * Mar 3, 2025: 👋 **Wan2.1**'s T2V and I2V have been integrated into Diffusers ([T2V](https://huggingface.co/docs/diffusers/main/en/api/pipelines/wan#diffusers.WanPipeline) | [I2V](https://huggingface.co/docs/diffusers/main/en/api/pipelines/wan#diffusers.WanImageToVideoPipeline)). Feel free to give it a try!
44
+ * Feb 27, 2025: 👋 **Wan2.1** has been integrated into [ComfyUI](https://comfyanonymous.github.io/ComfyUI_examples/wan/). Enjoy!
45
+ * Feb 25, 2025: 👋 We've released the inference code and weights of **Wan2.1**.
46
+
47
+ ## Community Works
48
+ If your work has improved **Wan2.1** and you would like more people to see it, please inform us.
49
+ - [TeaCache](https://github.com/ali-vilab/TeaCache) now supports **Wan2.1** acceleration, capable of increasing speed by approximately 2x. Feel free to give it a try!
50
+ - [DiffSynth-Studio](https://github.com/modelscope/DiffSynth-Studio) provides more support for **Wan2.1**, including video-to-video, FP8 quantization, VRAM optimization, LoRA training, and more. Please refer to [their examples](https://github.com/modelscope/DiffSynth-Studio/tree/main/examples/wanvideo).
51
 
52
 
53
  ## 📑 Todo List
 
55
  - [x] Multi-GPU Inference code of the 14B and 1.3B models
56
  - [x] Checkpoints of the 14B and 1.3B models
57
  - [x] Gradio demo
58
+ - [x] ComfyUI integration
59
+ - [x] Diffusers integration
60
+ - [ ] Diffusers + Multi-GPU Inference
61
  - Wan2.1 Image-to-Video
62
  - [x] Multi-GPU Inference code of the 14B model
63
  - [x] Checkpoints of the 14B model
64
  - [x] Gradio demo
65
+ - [x] ComfyUI integration
66
+ - [x] Diffusers integration
67
+ - [ ] Diffusers + Multi-GPU Inference
68
 
69
 
70
  ## Quickstart
71
 
72
  #### Installation
73
  Clone the repo:
74
+ ```sh
75
  git clone https://github.com/Wan-Video/Wan2.1.git
76
  cd Wan2.1
77
  ```
78
 
79
  Install dependencies:
80
+ ```sh
81
  # Ensure torch >= 2.4.0
82
  pip install -r requirements.txt
83
  ```
 
92
  | I2V-14B-480P | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-I2V-14B-480P) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-I2V-14B-480P) | Supports 480P
93
  | T2V-1.3B | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-T2V-1.3B) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-T2V-1.3B) | Supports 480P
94
 
 
95
  > 💡Note: The 1.3B model is capable of generating videos at 720P resolution. However, due to limited training at this resolution, the results are generally less stable compared to 480P. For optimal performance, we recommend using 480P resolution.
96
 
97
 
98
+ Download models using huggingface-cli:
99
+ ``` sh
100
  pip install "huggingface_hub[cli]"
101
+ huggingface-cli download Wan-AI/Wan2.1-T2V-14B --local-dir ./Wan2.1-T2V-14B
102
  ```
103
 
104
+ Download models using modelscope-cli:
105
+ ``` sh
106
  pip install modelscope
107
+ modelscope download Wan-AI/Wan2.1-T2V-14B --local_dir ./Wan2.1-T2V-14B
108
  ```
 
109
  #### Run Text-to-Video Generation
110
 
111
  This repository supports two Text-to-Video models (1.3B and 14B) and two resolutions (480P and 720P). The parameters and configurations for these models are as follows:
 
139
  </table>
140
 
141
 
142
+ ##### (1) Without Prompt Extension
143
 
144
  To facilitate implementation, we will start with a basic version of the inference process that skips the [prompt extension](#2-using-prompt-extention) step.
145
 
146
  - Single-GPU inference
147
 
148
+ ``` sh
149
+ python generate.py --task t2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-T2V-14B --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
150
  ```
151
 
152
  If you encounter OOM (Out-of-Memory) issues, you can use the `--offload_model True` and `--t5_cpu` options to reduce GPU memory usage. For example, on an RTX 4090 GPU:
153
 
154
+ ``` sh
155
  python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --offload_model True --t5_cpu --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
156
  ```
157
 
158
  > 💡Note: If you are using the `T2V-1.3B` model, we recommend setting the parameter `--sample_guide_scale 6`. The `--sample_shift parameter` can be adjusted within the range of 8 to 12 based on the performance.
159
 
160
+
161
  - Multi-GPU inference using FSDP + xDiT USP
162
 
163
+ We use FSDP and [xDiT](https://github.com/xdit-project/xDiT) USP to accelerate inference.
164
+
165
+ * Ulysess Strategy
166
+
167
+ If you want to use [`Ulysses`](https://arxiv.org/abs/2309.14509) strategy, you should set `--ulysses_size $GPU_NUMS`. Note that the `num_heads` should be divisible by `ulysses_size` if you wish to use `Ulysess` strategy. For the 1.3B model, the `num_heads` is `12` which can't be divided by 8 (as most multi-GPU machines have 8 GPUs). Therefore, it is recommended to use `Ring Strategy` instead.
168
+
169
+ * Ring Strategy
170
+
171
+ If you want to use [`Ring`](https://arxiv.org/pdf/2310.01889) strategy, you should set `--ring_size $GPU_NUMS`. Note that the `sequence length` should be divisible by `ring_size` when using the `Ring` strategy.
172
+
173
+ Of course, you can also combine the use of `Ulysses` and `Ring` strategies.
174
+
175
+
176
+ ``` sh
177
  pip install "xfuser>=0.4.1"
178
+ torchrun --nproc_per_node=8 generate.py --task t2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-T2V-14B --dit_fsdp --t5_fsdp --ulysses_size 8 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
179
  ```
180
 
181
 
182
+ ##### (2) Using Prompt Extension
183
 
184
  Extending the prompts can effectively enrich the details in the generated videos, further enhancing the video quality. Therefore, we recommend enabling prompt extension. We provide the following two methods for prompt extension:
185
 
 
188
  - Configure the environment variable `DASH_API_KEY` to specify the Dashscope API key. For users of Alibaba Cloud's international site, you also need to set the environment variable `DASH_API_URL` to 'https://dashscope-intl.aliyuncs.com/api/v1'. For more detailed instructions, please refer to the [dashscope document](https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api?spm=a2c63.p38356.0.i1).
189
  - Use the `qwen-plus` model for text-to-video tasks and `qwen-vl-max` for image-to-video tasks.
190
  - You can modify the model used for extension with the parameter `--prompt_extend_model`. For example:
191
+ ```sh
192
+ DASH_API_KEY=your_key python generate.py --task t2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-T2V-14B --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage" --use_prompt_extend --prompt_extend_method 'dashscope' --prompt_extend_target_lang 'zh'
193
  ```
194
 
195
  - Using a local model for extension.
196
 
197
+ - By default, the Qwen model on HuggingFace is used for this extension. Users can choose Qwen models or other models based on the available GPU memory size.
198
+ - For text-to-video tasks, you can use models like `Qwen/Qwen2.5-14B-Instruct`, `Qwen/Qwen2.5-7B-Instruct` and `Qwen/Qwen2.5-3B-Instruct`.
199
  - For image-to-video tasks, you can use models like `Qwen/Qwen2.5-VL-7B-Instruct` and `Qwen/Qwen2.5-VL-3B-Instruct`.
200
  - Larger models generally provide better extension results but require more GPU memory.
201
  - You can modify the model used for extension with the parameter `--prompt_extend_model` , allowing you to specify either a local model path or a Hugging Face model. For example:
202
 
203
+ ``` sh
204
+ python generate.py --task t2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-T2V-14B --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage" --use_prompt_extend --prompt_extend_method 'local_qwen' --prompt_extend_target_lang 'zh'
205
  ```
206
 
 
207
 
208
+ ##### (3) Running with Diffusers
209
+
210
+ You can easily inference **Wan2.1**-T2V using Diffusers with the following command:
211
+ ``` python
212
+ import torch
213
+ from diffusers.utils import export_to_video
214
+ from diffusers import AutoencoderKLWan, WanPipeline
215
+ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
216
+
217
+ # Available models: Wan-AI/Wan2.1-T2V-14B-Diffusers, Wan-AI/Wan2.1-T2V-1.3B-Diffusers
218
+ model_id = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
219
+ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
220
+ flow_shift = 5.0 # 5.0 for 720P, 3.0 for 480P
221
+ scheduler = UniPCMultistepScheduler(prediction_type='flow_prediction', use_flow_sigmas=True, num_train_timesteps=1000, flow_shift=flow_shift)
222
+ pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
223
+ pipe.scheduler = scheduler
224
+ pipe.to("cuda")
225
+
226
+ prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
227
+ negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
228
+
229
+ output = pipe(
230
+ prompt=prompt,
231
+ negative_prompt=negative_prompt,
232
+ height=720,
233
+ width=1280,
234
+ num_frames=81,
235
+ guidance_scale=5.0,
236
+ ).frames[0]
237
+ export_to_video(output, "output.mp4", fps=16)
238
  ```
239
+ > 💡Note: Please note that this example does not integrate Prompt Extension and distributed inference. We will soon update with the integrated prompt extension and multi-GPU version of Diffusers.
240
+
241
+
242
+ ##### (4) Running local gradio
243
+
244
+ ``` sh
245
  cd gradio
246
  # if one uses dashscope’s API for prompt extension
247
+ DASH_API_KEY=your_key python t2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir ./Wan2.1-T2V-14B
248
 
249
  # if one uses a local model for prompt extension
250
+ python t2v_14B_singleGPU.py --prompt_extend_method 'local_qwen' --ckpt_dir ./Wan2.1-T2V-14B
251
+ ```
252
+
253
+
254
+
255
+ #### Run Image-to-Video Generation
256
+
257
+ Similar to Text-to-Video, Image-to-Video is also divided into processes with and without the prompt extension step. The specific parameters and their corresponding settings are as follows:
258
+ <table>
259
+ <thead>
260
+ <tr>
261
+ <th rowspan="2">Task</th>
262
+ <th colspan="2">Resolution</th>
263
+ <th rowspan="2">Model</th>
264
+ </tr>
265
+ <tr>
266
+ <th>480P</th>
267
+ <th>720P</th>
268
+ </tr>
269
+ </thead>
270
+ <tbody>
271
+ <tr>
272
+ <td>i2v-14B</td>
273
+ <td style="color: green;">❌</td>
274
+ <td style="color: green;">✔️</td>
275
+ <td>Wan2.1-I2V-14B-720P</td>
276
+ </tr>
277
+ <tr>
278
+ <td>i2v-14B</td>
279
+ <td style="color: green;">✔️</td>
280
+ <td style="color: red;">❌</td>
281
+ <td>Wan2.1-T2V-14B-480P</td>
282
+ </tr>
283
+ </tbody>
284
+ </table>
285
+
286
+
287
+ ##### (1) Without Prompt Extension
288
+
289
+ - Single-GPU inference
290
+ ```sh
291
+ python generate.py --task i2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-I2V-14B-720P --image examples/i2v_input.JPG --prompt "Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside."
292
  ```
293
 
294
+ > 💡For the Image-to-Video task, the `size` parameter represents the area of the generated video, with the aspect ratio following that of the original input image.
295
+
296
 
297
+ - Multi-GPU inference using FSDP + xDiT USP
298
+
299
+ ```sh
300
+ pip install "xfuser>=0.4.1"
301
+ torchrun --nproc_per_node=8 generate.py --task i2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-I2V-14B-720P --image examples/i2v_input.JPG --dit_fsdp --t5_fsdp --ulysses_size 8 --prompt "Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside."
302
+ ```
303
 
304
+ ##### (2) Using Prompt Extension
305
 
306
+
307
+ The process of prompt extension can be referenced [here](#2-using-prompt-extention).
308
+
309
+ Run with local prompt extension using `Qwen/Qwen2.5-VL-7B-Instruct`:
310
+ ```
311
+ python generate.py --task i2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-I2V-14B-720P --image examples/i2v_input.JPG --use_prompt_extend --prompt_extend_model Qwen/Qwen2.5-VL-7B-Instruct --prompt "Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside."
312
+ ```
313
+
314
+ Run with remote prompt extension using `dashscope`:
315
+ ```
316
+ DASH_API_KEY=your_key python generate.py --task i2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-I2V-14B-720P --image examples/i2v_input.JPG --use_prompt_extend --prompt_extend_method 'dashscope' --prompt "Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside."
317
+ ```
318
+
319
+
320
+ ##### (3) Running with Diffusers
321
+
322
+ You can easily inference **Wan2.1**-I2V using Diffusers with the following command:
323
+ ``` python
324
+ import torch
325
+ import numpy as np
326
+ from diffusers import AutoencoderKLWan, WanImageToVideoPipeline
327
+ from diffusers.utils import export_to_video, load_image
328
+ from transformers import CLIPVisionModel
329
+
330
+ # Available models: Wan-AI/Wan2.1-I2V-14B-480P-Diffusers, Wan-AI/Wan2.1-I2V-14B-720P-Diffusers
331
+ model_id = "Wan-AI/Wan2.1-I2V-14B-720P-Diffusers"
332
+ image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", torch_dtype=torch.float32)
333
+ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
334
+ pipe = WanImageToVideoPipeline.from_pretrained(model_id, vae=vae, image_encoder=image_encoder, torch_dtype=torch.bfloat16)
335
+ pipe.to("cuda")
336
+
337
+ image = load_image(
338
+ "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg"
339
+ )
340
+ max_area = 720 * 1280
341
+ aspect_ratio = image.height / image.width
342
+ mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1]
343
+ height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
344
+ width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
345
+ image = image.resize((width, height))
346
+ prompt = (
347
+ "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in "
348
+ "the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
349
+ )
350
+ negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
351
+
352
+ output = pipe(
353
+ image=image,
354
+ prompt=prompt,
355
+ negative_prompt=negative_prompt,
356
+ height=height, width=width,
357
+ num_frames=81,
358
+ guidance_scale=5.0
359
+ ).frames[0]
360
+ export_to_video(output, "output.mp4", fps=16)
361
+
362
+ ```
363
+ > 💡Note: Please note that this example does not integrate Prompt Extension and distributed inference. We will soon update with the integrated prompt extension and multi-GPU version of Diffusers.
364
+
365
+
366
+ ##### (4) Running local gradio
367
+
368
+ ```sh
369
+ cd gradio
370
+ # if one only uses 480P model in gradio
371
+ DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_480p ./Wan2.1-I2V-14B-480P
372
+
373
+ # if one only uses 720P model in gradio
374
+ DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_720p ./Wan2.1-I2V-14B-720P
375
+
376
+ # if one uses both 480P and 720P models in gradio
377
+ DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_480p ./Wan2.1-I2V-14B-480P --ckpt_dir_720p ./Wan2.1-I2V-14B-720P
378
+ ```
379
+
380
+
381
+ #### Run Text-to-Image Generation
382
+
383
+ Wan2.1 is a unified model for both image and video generation. Since it was trained on both types of data, it can also generate images. The command for generating images is similar to video generation, as follows:
384
+
385
+ ##### (1) Without Prompt Extension
386
+
387
+ - Single-GPU inference
388
+ ```sh
389
+ python generate.py --task t2i-14B --size 1024*1024 --ckpt_dir ./Wan2.1-T2V-14B --prompt '一个朴素端庄的美人'
390
+ ```
391
+
392
+ - Multi-GPU inference using FSDP + xDiT USP
393
+
394
+ ```sh
395
+ torchrun --nproc_per_node=8 generate.py --dit_fsdp --t5_fsdp --ulysses_size 8 --base_seed 0 --frame_num 1 --task t2i-14B --size 1024*1024 --prompt '一个朴素端庄的美人' --ckpt_dir ./Wan2.1-T2V-14B
396
+ ```
397
+
398
+ ##### (2) With Prompt Extention
399
+
400
+ - Single-GPU inference
401
+ ```sh
402
+ python generate.py --task t2i-14B --size 1024*1024 --ckpt_dir ./Wan2.1-T2V-14B --prompt '一个朴素端庄的美人' --use_prompt_extend
403
+ ```
404
+
405
+ - Multi-GPU inference using FSDP + xDiT USP
406
+ ```sh
407
+ torchrun --nproc_per_node=8 generate.py --dit_fsdp --t5_fsdp --ulysses_size 8 --base_seed 0 --frame_num 1 --task t2i-14B --size 1024*1024 --ckpt_dir ./Wan2.1-T2V-14B --prompt '一个朴素端庄的美人' --use_prompt_extend
408
+ ```
409
+
410
+
411
+ ## Manual Evaluation
412
+
413
+ ##### (1) Text-to-Video Evaluation
414
+
415
+ Through manual evaluation, the results generated after prompt extension are superior to those from both closed-source and open-source models.
416
 
417
  <div align="center">
418
+ <img src="assets/t2v_res.jpg" alt="" style="width: 80%;" />
419
  </div>
420
 
421
 
422
+ ##### (2) Image-to-Video Evaluation
423
+
424
+ We also conducted extensive manual evaluations to evaluate the performance of the Image-to-Video model, and the results are presented in the table below. The results clearly indicate that **Wan2.1** outperforms both closed-source and open-source models.
425
+
426
+ <div align="center">
427
+ <img src="assets/i2v_res.png" alt="" style="width: 80%;" />
428
+ </div>
429
+
430
 
431
  ## Computational Efficiency on Different GPUs
432
 
 
443
  > (3) For the 1.3B model on a single 4090 GPU, set `--offload_model True --t5_cpu`;
444
  > (4) For all testings, no prompt extension was applied, meaning `--use_prompt_extend` was not enabled.
445
 
446
+ > 💡Note: T2V-14B is slower than I2V-14B because the former samples 50 steps while the latter uses 40 steps.
447
+
448
+
449
  -------
450
 
451
  ## Introduction of Wan2.1
 
474
  | Model | Dimension | Input Dimension | Output Dimension | Feedforward Dimension | Frequency Dimension | Number of Heads | Number of Layers |
475
  |--------|-----------|-----------------|------------------|-----------------------|---------------------|-----------------|------------------|
476
  | 1.3B | 1536 | 16 | 16 | 8960 | 256 | 12 | 30 |
477
+ | 14B | 5120 | 16 | 16 | 13824