Update README.md
76
README.md
@ -1,14 +1,21 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
language:
|
||||
- en
|
||||
- zh
|
||||
tags:
|
||||
- video generation
|
||||
---
|
||||
# Wan2.1
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/logo.png" width="400"/>
|
||||
<p>
|
||||
|
||||
<p align="center">
|
||||
💜 <a href="https://wan.video"><b>Wan</b></a>    |    🖥️ <a href="https://github.com/Wan-Video/Wan2.1">GitHub</a>    |   🤗 <a href="https://huggingface.co/Wan-AI/">Hugging Face</a>   |   🤖 <a href="https://modelscope.cn/organization/Wan-AI">ModelScope</a>   |    📑 <a href="https://arxiv.org/abs/2503.20314">Technical Report</a>    |    📑 <a href="https://wan.video/welcome?spm=a2ty_o02.30011076.0.0.6c9ee41eCcluqg">Blog</a>    |   💬 <a href="https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg">WeChat Group</a>   |    📖 <a href="https://discord.gg/AKNgpMK4Yj">Discord</a>  
|
||||
<br>
|
||||
|
||||
-----
|
||||
|
||||
[**Wan: Open and Advanced Large-Scale Video Generative Models**](https://arxiv.org/abs/2503.20314) <be>
|
||||
@ -28,6 +35,7 @@ In this repository, we present **Wan2.1**, a comprehensive and open suite of vid
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
</div>
|
||||
|
||||
## 🔥 Latest News!!
|
||||
|
||||
* May 14, 2025: 👋 We introduce **Wan2.1** [VACE](https://github.com/ali-vilab/VACE), an all-in-one model for video creation and editing, along with its [inference code](#run-vace), [weights](#model-download), and [technical report](https://arxiv.org/abs/2503.07598)!
|
||||
@ -152,6 +160,7 @@ This repository supports two Text-to-Video models (1.3B and 14B) and two resolut
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
##### (1) Without Prompt Extension
|
||||
|
||||
To facilitate implementation, we will start with a basic version of the inference process that skips the [prompt extension](#2-using-prompt-extention) step.
|
||||
@ -169,14 +178,20 @@ python generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B
|
||||
```
|
||||
|
||||
> 💡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.
|
||||
|
||||
|
||||
- Multi-GPU inference using FSDP + xDiT USP
|
||||
|
||||
We use FSDP and [xDiT](https://github.com/xdit-project/xDiT) USP to accelerate inference.
|
||||
|
||||
* Ulysess Strategy
|
||||
|
||||
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.
|
||||
|
||||
* Ring Strategy
|
||||
|
||||
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.
|
||||
|
||||
Of course, you can also combine the use of `Ulysses` and `Ring` strategies.
|
||||
|
||||
|
||||
@ -220,6 +235,7 @@ import torch
|
||||
from diffusers.utils import export_to_video
|
||||
from diffusers import AutoencoderKLWan, WanPipeline
|
||||
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
||||
|
||||
# Available models: Wan-AI/Wan2.1-T2V-14B-Diffusers, Wan-AI/Wan2.1-T2V-1.3B-Diffusers
|
||||
model_id = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
|
||||
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
||||
@ -228,8 +244,10 @@ scheduler = UniPCMultistepScheduler(prediction_type='flow_prediction', use_flow_
|
||||
pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
|
||||
pipe.scheduler = scheduler
|
||||
pipe.to("cuda")
|
||||
|
||||
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."
|
||||
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"
|
||||
|
||||
output = pipe(
|
||||
prompt=prompt,
|
||||
negative_prompt=negative_prompt,
|
||||
@ -249,6 +267,7 @@ export_to_video(output, "output.mp4", fps=16)
|
||||
cd gradio
|
||||
# if one uses dashscope’s API for prompt extension
|
||||
DASH_API_KEY=your_key python t2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir ./Wan2.1-T2V-14B
|
||||
|
||||
# if one uses a local model for prompt extension
|
||||
python t2v_14B_singleGPU.py --prompt_extend_method 'local_qwen' --ckpt_dir ./Wan2.1-T2V-14B
|
||||
```
|
||||
@ -286,6 +305,7 @@ Similar to Text-to-Video, Image-to-Video is also divided into processes with and
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
##### (1) Without Prompt Extension
|
||||
|
||||
- Single-GPU inference
|
||||
@ -328,12 +348,14 @@ import numpy as np
|
||||
from diffusers import AutoencoderKLWan, WanImageToVideoPipeline
|
||||
from diffusers.utils import export_to_video, load_image
|
||||
from transformers import CLIPVisionModel
|
||||
|
||||
# Available models: Wan-AI/Wan2.1-I2V-14B-480P-Diffusers, Wan-AI/Wan2.1-I2V-14B-720P-Diffusers
|
||||
model_id = "Wan-AI/Wan2.1-I2V-14B-720P-Diffusers"
|
||||
image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", torch_dtype=torch.float32)
|
||||
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
||||
pipe = WanImageToVideoPipeline.from_pretrained(model_id, vae=vae, image_encoder=image_encoder, torch_dtype=torch.bfloat16)
|
||||
pipe.to("cuda")
|
||||
|
||||
image = load_image(
|
||||
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg"
|
||||
)
|
||||
@ -348,6 +370,7 @@ prompt = (
|
||||
"the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
|
||||
)
|
||||
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"
|
||||
|
||||
output = pipe(
|
||||
image=image,
|
||||
prompt=prompt,
|
||||
@ -357,6 +380,7 @@ output = pipe(
|
||||
guidance_scale=5.0
|
||||
).frames[0]
|
||||
export_to_video(output, "output.mp4", fps=16)
|
||||
|
||||
```
|
||||
> 💡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.
|
||||
|
||||
@ -367,8 +391,10 @@ export_to_video(output, "output.mp4", fps=16)
|
||||
cd gradio
|
||||
# if one only uses 480P model in gradio
|
||||
DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_480p ./Wan2.1-I2V-14B-480P
|
||||
|
||||
# if one only uses 720P model in gradio
|
||||
DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_720p ./Wan2.1-I2V-14B-720P
|
||||
|
||||
# if one uses both 480P and 720P models in gradio
|
||||
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
|
||||
```
|
||||
@ -399,6 +425,7 @@ First-Last-Frame-to-Video is also divided into processes with and without the pr
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
##### (1) Without Prompt Extension
|
||||
|
||||
- Single-GPU inference
|
||||
@ -474,6 +501,7 @@ The parameters and configurations for these models are as follows:
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
In VACE, users can input text prompt and optional video, mask, and image for video generation or editing. Detailed instructions for using VACE can be found in the [User Guide](https://github.com/ali-vilab/VACE/blob/main/UserGuide.md).
|
||||
The execution process is as follows:
|
||||
|
||||
@ -497,10 +525,14 @@ torchrun --nproc_per_node=8 generate.py --task vace-14B --size 1280*720 --ckpt_d
|
||||
```
|
||||
|
||||
##### (3) Running local gradio
|
||||
|
||||
- Single-GPU inference
|
||||
```sh
|
||||
cd gradio
|
||||
python vace_1.3B_singleGPU.py --ckpt_dir_720p ./Wan2.1-VACE-1.3B # use 480P model in gradio
|
||||
python gradio/vace.py --ckpt_dir ./Wan2.1-VACE-1.3B
|
||||
```
|
||||
|
||||
- Multi-GPU inference using FSDP + xDiT USP
|
||||
```sh
|
||||
python gradio/vace.py --mp --ulysses_size 8 --ckpt_dir ./Wan2.1-VACE-14B/
|
||||
```
|
||||
|
||||
#### Run Text-to-Image Generation
|
||||
@ -543,6 +575,7 @@ Through manual evaluation, the results generated after prompt extension are supe
|
||||
<img src="assets/t2v_res.jpg" alt="" style="width: 80%;" />
|
||||
</div>
|
||||
|
||||
|
||||
##### (2) Image-to-Video Evaluation
|
||||
|
||||
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.
|
||||
@ -551,6 +584,7 @@ We also conducted extensive manual evaluations to evaluate the performance of th
|
||||
<img src="assets/i2v_res.png" alt="" style="width: 80%;" />
|
||||
</div>
|
||||
|
||||
|
||||
## Computational Efficiency on Different GPUs
|
||||
|
||||
We test the computational efficiency of different **Wan2.1** models on different GPUs in the following table. The results are presented in the format: **Total time (s) / peak GPU memory (GB)**.
|
||||
@ -559,37 +593,64 @@ We test the computational efficiency of different **Wan2.1** models on different
|
||||
<div align="center">
|
||||
<img src="assets/comp_effic.png" alt="" style="width: 80%;" />
|
||||
</div>
|
||||
|
||||
> The parameter settings for the tests presented in this table are as follows:
|
||||
> (1) For the 1.3B model on 8 GPUs, set `--ring_size 8` and `--ulysses_size 1`;
|
||||
> (2) For the 14B model on 1 GPU, use `--offload_model True`;
|
||||
> (3) For the 1.3B model on a single 4090 GPU, set `--offload_model True --t5_cpu`;
|
||||
> (4) For all testings, no prompt extension was applied, meaning `--use_prompt_extend` was not enabled.
|
||||
|
||||
> 💡Note: T2V-14B is slower than I2V-14B because the former samples 50 steps while the latter uses 40 steps.
|
||||
|
||||
|
||||
-------
|
||||
|
||||
## Introduction of Wan2.1
|
||||
|
||||
**Wan2.1** is designed on the mainstream diffusion transformer paradigm, achieving significant advancements in generative capabilities through a series of innovations. These include our novel spatio-temporal variational autoencoder (VAE), scalable training strategies, large-scale data construction, and automated evaluation metrics. Collectively, these contributions enhance the model’s performance and versatility.
|
||||
|
||||
|
||||
##### (1) 3D Variational Autoencoders
|
||||
We propose a novel 3D causal VAE architecture, termed **Wan-VAE** specifically designed for video generation. By combining multiple strategies, we improve spatio-temporal compression, reduce memory usage, and ensure temporal causality. **Wan-VAE** demonstrates significant advantages in performance efficiency compared to other open-source VAEs. Furthermore, our **Wan-VAE** can encode and decode unlimited-length 1080P videos without losing historical temporal information, making it particularly well-suited for video generation tasks.
|
||||
|
||||
|
||||
<div align="center">
|
||||
<img src="assets/video_vae_res.jpg" alt="" style="width: 80%;" />
|
||||
</div>
|
||||
|
||||
|
||||
##### (2) Video Diffusion DiT
|
||||
|
||||
**Wan2.1** is designed using the Flow Matching framework within the paradigm of mainstream Diffusion Transformers. Our model's architecture uses the T5 Encoder to encode multilingual text input, with cross-attention in each transformer block embedding the text into the model structure. Additionally, we employ an MLP with a Linear layer and a SiLU layer to process the input time embeddings and predict six modulation parameters individually. This MLP is shared across all transformer blocks, with each block learning a distinct set of biases. Our experimental findings reveal a significant performance improvement with this approach at the same parameter scale.
|
||||
|
||||
<div align="center">
|
||||
<img src="assets/video_dit_arch.jpg" alt="" style="width: 80%;" />
|
||||
</div>
|
||||
|
||||
|
||||
| Model | Dimension | Input Dimension | Output Dimension | Feedforward Dimension | Frequency Dimension | Number of Heads | Number of Layers |
|
||||
|--------|-----------|-----------------|------------------|-----------------------|---------------------|-----------------|------------------|
|
||||
| 1.3B | 1536 | 16 | 16 | 8960 | 256 | 12 | 30 |
|
||||
| 14B | 5120 | 16 | 16 | 13824 | 256 | 40 | 40 |
|
||||
|
||||
|
||||
|
||||
##### Data
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
|
||||
##### Comparisons to SOTA
|
||||
We compared **Wan2.1** with leading open-source and closed-source models to evaluate the performance. Using our carefully designed set of 1,035 internal prompts, we tested across 14 major dimensions and 26 sub-dimensions. We then compute the total score by performing a weighted calculation on the scores of each dimension, utilizing weights derived from human preferences in the matching process. 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.
|
||||
|
||||

|
||||
|
||||
|
||||
## Citation
|
||||
If you find our work helpful, please cite us.
|
||||
|
||||
```
|
||||
@article{wan2025,
|
||||
title={Wan: Open and Advanced Large-Scale Video Generative Models},
|
||||
@ -598,9 +659,16 @@ If you find our work helpful, please cite us.
|
||||
year={2025}
|
||||
}
|
||||
```
|
||||
|
||||
## License Agreement
|
||||
The models in this repository are licensed under the Apache 2.0 License. We claim no rights over the your generated 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).
|
||||
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
## Contact Us
|
||||
If you would like to leave a message to our research or product teams, feel free to join our [Discord](https://discord.gg/AKNgpMK4Yj) or [WeChat groups](https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg)!
|
||||
If you would like to leave a message to our research or product teams, feel free to join our [Discord](https://discord.gg/AKNgpMK4Yj) or [WeChat groups](https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg)!
|
||||
BIN
assets/comp_effic.png
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
assets/data_for_diff_stage.jpg
Normal file
|
After Width: | Height: | Size: 516 KiB |
BIN
assets/i2v_res.png
Normal file
|
After Width: | Height: | Size: 871 KiB |
BIN
assets/logo.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
assets/t2v_res.jpg
Normal file
|
After Width: | Height: | Size: 294 KiB |
BIN
assets/vben_vs_sota.png
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
BIN
assets/video_dit_arch.jpg
Normal file
|
After Width: | Height: | Size: 628 KiB |
BIN
assets/video_vae_res.jpg
Normal file
|
After Width: | Height: | Size: 208 KiB |