Wan-Video/Wan2.1

GitHub: Wan-Video/Wan2.1

Wan2.1 是一套全面开源的大规模视频生成基础模型,支持文本生视频、图像生视频、视频编辑等多种视频生成与编辑任务。

Stars: 16454 | Forks: 2939

# Wan2.1

💜 Wan    |    🖥️ GitHub    |   🤗 Hugging Face   |   🤖 ModelScope   |    📑 技术报告    |    📑 博客    |   💬 微信群   |    📖 Discord  
[**Wan:开放且先进的大规模视频生成模型**](https://arxiv.org/abs/2503.20314) 在本代码库中,我们展示了 **Wan2.1**,一套全面且开放的视频基础模型,突破了视频生成的边界。**Wan2.1** 提供了以下主要特性: - 👍 **SOTA 性能**:**Wan2.1** 在多个基准测试中始终优于现有的开源模型和最先进的商业解决方案。 - 👍 **支持消费级 GPU**:T2V-1.3B 模型仅需 8.19 GB VRAM,使其兼容几乎所有消费级 GPU。它可以在 RTX 4090 上约 4 分钟内生成一段 5 秒的 480P 视频(无需使用量化等优化技术)。其性能甚至可与某些闭源模型相媲美。 - 👍 **多种任务**:**Wan2.1** 在文本生成视频(Text-to-Video)、图像生成视频(Image-to-Video)、视频编辑、文本生成图像(Text-to-Image)以及视频生成音频(Video-to-Audio)方面表现出色,推动了视频生成领域的发展。 - 👍 **视觉文本生成**:**Wan2.1** 是首个能够同时生成中英文文本的视频模型,其强大的文本生成能力增强了它的实际应用价值。 - 👍 **强大的视频 VAE**:**Wan-VAE** 提供了卓越的效率和性能,能够对任意长度的 1080P 视频进行编码和解码,同时保留时间信息,使其成为视频和图像生成的理想基础。 ## 视频演示

## 🔥 最新消息!! * 2025年5月14日:👋 我们推出了 **Wan2.1** [VACE](https://github.com/ali-vilab/VACE),这是一个用于视频创建和编辑的一体化模型,同时发布了其[推理代码](#run-vace)、[权重](#model-download)和[技术报告](https://arxiv.org/abs/2503.07598)! * 2025年4月17日:👋 我们推出了 **Wan2.1** [FLF2V](#run-first-last-frame-to-video-generation) 及其推理代码和权重! * 2025年3月21日:👋 我们很高兴地宣布发布 **Wan2.1** [技术报告](https://files.alicdn.com/tpsservice/5c9de1c74de03972b7aa657e5a54756b.pdf)。欢迎讨论与反馈! * 2025年3月3日:👋 **Wan2.1** 的 T2V 和 I2V 已集成到 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))。欢迎大家尝试! * 2025年2月27日:👋 **Wan2.1** 已集成到 [ComfyUI](https://comfyanonymous.github.io/ComfyUI_examples/wan/) 中。尽情享受吧! * 2025年2月25日:👋 我们已发布 **Wan2.1** 的推理代码和权重。 ## 📑 待办列表 - Wan2.1 文本生成视频(Text-to-Video) - [x] 14B 和 1.3B 模型的多 GPU 推理代码 - [x] 14B 和 1.3B 模型的权重 - [x] Gradio demo - [x] ComfyUI 集成 - [x] Diffusers 集成 - [ ] Diffusers + 多 GPU 推理 - Wan2.1 图像生成视频(Image-to-Video) - [x] 14B 模型的多 GPU 推理代码 - [x] 14B 模型的权重 - [x] Gradio demo - [x] ComfyUI 集成 - [x] Diffusers 集成 - [ ] Diffusers + 多 GPU 推理 - Wan2.1 首尾帧生成视频(First-Last-Frame-to-Video) - [x] 14B 模型的多 GPU 推理代码 - [x] 14B 模型的权重 - [x] Gradio demo - [ ] ComfyUI 集成 - [ ] Diffusers 集成 - [ ] Diffusers + 多 GPU 推理 - Wan2.1 VACE - [x] 14B 和 1.3B 模型的多 GPU 推理代码 - [x] 14B 和 1.3B 模型的权重 - [x] Gradio demo - [x] ComfyUI 集成 - [ ] Diffusers 集成 - [ ] Diffusers + 多 GPU 推理 ## 快速开始 #### 安装 克隆代码库: ``` git clone https://github.com/Wan-Video/Wan2.1.git cd Wan2.1 ``` 安装依赖项: ``` # 确保 torch >= 2.4.0 pip install -r requirements.txt ``` #### 模型下载 | 模型 | 下载链接 | 备注 | |--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------| | T2V-14B | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-T2V-14B) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-T2V-14B) | 同时支持 480P 和 720P | I2V-14B-720P | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-I2V-14B-720P) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-I2V-14B-720P) | 支持 720P | 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) | 支持 480P | 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) | 支持 480P | FLF2V-14B | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-FLF2V-14B-720P) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-FLF2V-14B-720P) | 支持 720P | VACE-1.3B | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-VACE-1.3B) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-VACE-1.3B) | 支持 480P | VACE-14B | 🤗 [Huggingface](https://huggingface.co/Wan-AI/Wan2.1-VACE-14B) 🤖 [ModelScope](https://www.modelscope.cn/models/Wan-AI/Wan2.1-VACE-14B) | 同时支持 480P 和 720P 使用 huggingface-cli 下载模型: ``` pip install "huggingface_hub[cli]" huggingface-cli download Wan-AI/Wan2.1-T2V-14B --local-dir ./Wan2.1-T2V-14B ``` 使用 modelscope-cli 下载模型: ``` pip install modelscope modelscope download Wan-AI/Wan2.1-T2V-14B --local_dir ./Wan2.1-T2V-14B ``` #### 运行文本生成视频(Text-to-Video) 本代码库支持两种文本生成视频模型(1.3B 和 14B)以及两种分辨率(480P 和 720P)。这些模型的参数和配置如下:
任务 分辨率 模型
480P 720P
t2v-14B ✔️ ✔️ Wan2.1-T2V-14B
t2v-1.3B ✔️ Wan2.1-T2V-1.3B
##### (1) 不使用 Prompt 扩展 为了方便实现,我们将从跳过 [Prompt 扩展](#2-using-prompt-extention) 步骤的基础版推理流程开始。 - 单 GPU 推理 ``` 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." ``` 如果遇到 OOM(显存不足)问题,可以使用 `--offload_model True` 和 `--t5_cpu` 选项来减少 GPU 显存使用。例如,在 RTX 4090 GPU 上: ``` 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." ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 我们使用 FSDP 和 [xDiT](https://github.com/xdit-project/xDiT) USP 来加速推理。 * Ulysess 策略 如果你想使用 [`Ulysses`](https://arxiv.org/abs/2309.14509) 策略,你应该设置 `--ulysses_size $GPU_NUMS`。请注意,如果你想使用 `Ulysess` 策略,`num_heads` 必须能被 `ulysses_size` 整除。对于 1.3B 模型,其 `num_heads` 为 `12`,无法被 8 整除(因为大多数多 GPU 机器有 8 个 GPU)。因此,建议改用 `Ring 策略`。 * Ring 策略 如果你想使用 [`Ring`](https://arxiv.org/pdf/2310.01889) 策略,你应该设置 `--ring_size $GPU_NUMS`。请注意,使用 `Ring` 策略时,`序列长度`(sequence length)必须能被 `ring_size` 整除。 当然,你也可以结合使用 `Ulysses` 和 `Ring` 策略。 ``` pip install "xfuser>=0.4.1" 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." ``` ##### (2) 使用 Prompt 扩展 扩展 Prompt 可以有效丰富生成视频中的细节,进一步提升视频质量。因此,我们建议启用 Prompt 扩展。我们提供以下两种 Prompt 扩展方法: - 使用 Dashscope API 进行扩展。 - 提前申请 `dashscope.api_key`([英文](https://www.alibabacloud.com/help/en/model-studio/getting-started/first-api-call-to-qwen) | [中文](https://help.aliyun.com/zh/model-studio/getting-started/first-api-call-to-qwen))。 - 配置环境变量 `DASH_API_KEY` 以指定 Dashscope API key。对于阿里云国际站用户,还需将环境变量 `DASH_API_URL` 设置为 'https://dashscope-intl.aliyuncs.com/api/v1'。更详细的说明请参阅 [Dashscope 文档](https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api?spm=a2c63.p38356.0.i1)。 - 文本生成视频任务使用 `qwen-plus` 模型,图像生成视频任务使用 `qwen-vl-max`。 - 你可以使用 `--prompt_extend_model` 参数修改用于扩展的模型。例如: ``` 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' ``` - 使用本地模型进行扩展。 - 默认情况下,此扩展使用 HuggingFace 上的 Qwen 模型。用户可根据可用的 GPU 显存大小选择 Qwen 模型或其他模型。 - 对于文本生成视频任务,你可以使用 `Qwen/Qwen2.5-14B-Instruct`、`Qwen/Qwen2.5-7B-Instruct` 和 `Qwen/Qwen2.5-3B-Instruct` 等模型。 - 对于图像生成视频或首尾帧生成视频任务,你可以使用 `Qwen/Qwen2.5-VL-7B-Instruct` 和 `Qwen/Qwen2.5-VL-3B-Instruct` 等模型。 - 更大的模型通常能提供更好的扩展效果,但需要更多的 GPU 显存。 - 你可以使用 `--prompt_extend_model` 参数修改用于扩展的模型,允许指定本地模型路径或 Hugging Face 模型。例如: ``` 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' ``` ##### (3) 使用 Diffusers 运行 你可以使用 Diffusers 通过以下命令轻松推理 **Wan2.1**-T2V: ``` import torch from diffusers.utils import export_to_video from diffusers import AutoencoderKLWan, WanPipeline from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler # 可用模型: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) flow_shift = 5.0 # 5.0 for 720P, 3.0 for 480P scheduler = UniPCMultistepScheduler(prediction_type='flow_prediction', use_flow_sigmas=True, num_train_timesteps=1000, flow_shift=flow_shift) 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, height=720, width=1280, num_frames=81, guidance_scale=5.0, ).frames[0] export_to_video(output, "output.mp4", fps=16) ``` ##### (4) 运行本地 Gradio ``` cd gradio # 如果使用 dashscope 的 API 进行 prompt 扩展 DASH_API_KEY=your_key python t2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir ./Wan2.1-T2V-14B # 如果使用本地模型进行 prompt 扩展 python t2v_14B_singleGPU.py --prompt_extend_method 'local_qwen' --ckpt_dir ./Wan2.1-T2V-14B ``` #### 运行图像生成视频(Image-to-Video) 与文本生成视频类似,图像生成视频也分为包含和不包含 Prompt 扩展步骤的过程。具体参数及其相应设置如下:
任务 分辨率 模型
480P 720P
i2v-14B ✔️ Wan2.1-I2V-14B-720P
i2v-14B ✔️ Wan2.1-T2V-14B-480P
##### (1) 不使用 Prompt 扩展 - 单 GPU 推理 ``` 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." ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 ``` pip install "xfuser>=0.4.1" 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." ``` ##### (2) 使用 Prompt 扩展 Prompt 扩展的流程可以参考[这里](#2-using-prompt-extention)。 使用 `Qwen/Qwen2.5-VL-7B-Instruct` 运行本地 Prompt 扩展: ``` 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." ``` 使用 `dashscope` 运行远程 Prompt 扩展: ``` 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." ``` ##### (3) 使用 Diffusers 运行 你可以使用 Diffusers 通过以下命令轻松推理 **Wan2.1**-I2V: ``` import torch import numpy as np from diffusers import AutoencoderKLWan, WanImageToVideoPipeline from diffusers.utils import export_to_video, load_image from transformers import CLIPVisionModel # 可用模型: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" ) max_area = 720 * 1280 aspect_ratio = image.height / image.width mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1] height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value image = image.resize((width, height)) prompt = ( "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in " "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, negative_prompt=negative_prompt, height=height, width=width, num_frames=81, guidance_scale=5.0 ).frames[0] export_to_video(output, "output.mp4", fps=16) ``` ##### (4) 运行本地 Gradio ``` cd gradio # 如果在 gradio 中仅使用 480P 模型 DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_480p ./Wan2.1-I2V-14B-480P # 如果在 gradio 中仅使用 720P 模型 DASH_API_KEY=your_key python i2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_720p ./Wan2.1-I2V-14B-720P # 如果在 gradio 中同时使用 480P 和 720P 模型 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 ``` #### 运行首尾帧生成视频(First-Last-Frame-to-Video) 首尾帧生成视频也分为包含和不包含 Prompt 扩展步骤的过程。目前仅支持 720P。具体参数和相应设置如下:
任务 分辨率 模型
480P 720P
flf2v-14B ✔️ Wan2.1-FLF2V-14B-720P
##### (1) 不使用 Prompt 扩展 - 单 GPU 推理 ``` python generate.py --task flf2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-FLF2V-14B-720P --first_frame examples/flf2v_input_first_frame.png --last_frame examples/flf2v_input_last_frame.png --prompt "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird’s feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective." ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 ``` pip install "xfuser>=0.4.1" torchrun --nproc_per_node=8 generate.py --task flf2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-FLF2V-14B-720P --first_frame examples/flf2v_input_first_frame.png --last_frame examples/flf2v_input_last_frame.png --dit_fsdp --t5_fsdp --ulysses_size 8 --prompt "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird’s feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective." ``` ##### (2) 使用 Prompt 扩展 Prompt 扩展的流程可以参考[这里](#2-using-prompt-extention)。 使用 `Qwen/Qwen2.5-VL-7B-Instruct` 运行本地 Prompt 扩展: ``` python generate.py --task flf2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-FLF2V-14B-720P --first_frame examples/flf2v_input_first_frame.png --last_frame examples/flf2v_input_last_frame.png --use_prompt_extend --prompt_extend_model Qwen/Qwen2.5-VL-7B-Instruct --prompt "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird’s feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective." ``` 使用 `dashscope` 运行远程 Prompt 扩展: ``` DASH_API_KEY=your_key python generate.py --task flf2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-FLF2V-14B-720P --first_frame examples/flf2v_input_first_frame.png --last_frame examples/flf2v_input_last_frame.png --use_prompt_extend --prompt_extend_method 'dashscope' --prompt "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird’s feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective." ``` ##### (3) 运行本地 Gradio ``` cd gradio # 在 gradio 中使用 720P 模型 DASH_API_KEY=your_key python flf2v_14B_singleGPU.py --prompt_extend_method 'dashscope' --ckpt_dir_720p ./Wan2.1-FLF2V-14B-720P ``` #### 运行 VACE [VACE](https://github.com/ali-vilab/VACE) 现在支持两种模型(1.3B 和 14B)以及两种主要分辨率(480P 和 720P)。 输入支持任意分辨率,但为了达到最佳效果,视频尺寸应在特定范围内。 这些模型的参数和配置如下:
任务 分辨率 模型
480P(~81x480x832) 720P(~81x720x1280)
VACE ✔️ ✔️ Wan2.1-VACE-14B
VACE ✔️ Wan2.1-VACE-1.3B
在 VACE 中,用户可以输入文本 Prompt 以及可选的视频、mask 和图像,用于视频生成或编辑。有关使用 VACE 的详细说明,请参阅[用户指南](https://github.com/ali-vilab/VACE/blob/main/UserGuide.md)。 执行流程如下: ##### (1) 预处理 用户收集的素材需要预处理为 VACE 可识别的输入,包括 `src_video`、`src_mask`、`src_ref_images` 和 `prompt`。 对于 R2V(基于参考图的视频生成,Reference-to-Video),你可以跳过此预处理步骤,但对于 V2V(视频转视频编辑,Video-to-Video Editing)和 MV2V(带 mask 的视频转视频编辑,Masked Video-to-Video Editing)任务,需要进行额外的预处理,以获取带有深度、姿态或 mask 区域等条件的视频。 更多详细信息,请参阅 [vace_preproccess](https://github.com/ali-vilab/VACE/blob/main/vace/vace_preproccess.py)。 ##### (2) CLI 推理 - 单 GPU 推理 ``` python generate.py --task vace-1.3B --size 832*480 --ckpt_dir ./Wan2.1-VACE-1.3B --src_ref_images examples/girl.png,examples/snake.png --prompt "在一个欢乐而充满节日气氛的场景中,穿着鲜艳红色春服的小女孩正与她的可爱卡通蛇嬉戏。她的春服上绣着金色吉祥图案,散发着喜庆的气息,脸上洋溢着灿烂的笑容。蛇身呈现出亮眼的绿色,形状圆润,宽大的眼睛让它显得既友善又幽默。小女孩欢快地用手轻轻抚摸着蛇的头部,共同享受着这温馨的时刻。周围五彩斑斓的灯笼和彩带装饰着环境,阳光透过洒在她们身上,营造出一个充满友爱与幸福的新年氛围。" ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 ``` torchrun --nproc_per_node=8 generate.py --task vace-14B --size 1280*720 --ckpt_dir ./Wan2.1-VACE-14B --dit_fsdp --t5_fsdp --ulysses_size 8 --src_ref_images examples/girl.png,examples/snake.png --prompt "在一个欢乐而充满节日气氛的场景中,穿着鲜艳红色春服的小女孩正与她的可爱卡通蛇嬉戏。她的春服上绣着金色吉祥图案,散发着喜庆的气息,脸上洋溢着灿烂的笑容。蛇身呈现出亮眼的绿色,形状圆润,宽大的眼睛让它显得既友善又幽默。小女孩欢快地用手轻轻抚摸着蛇的头部,共同享受着这温馨的时刻。周围五彩斑斓的灯笼和彩带装饰着环境,阳光透过洒在她们身上,营造出一个充满友爱与幸福的新年氛围。" ``` ##### (3) 运行本地 Gradio - 单 GPU 推理 ``` python gradio/vace.py --ckpt_dir ./Wan2.1-VACE-1.3B ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 ``` python gradio/vace.py --mp --ulysses_size 8 --ckpt_dir ./Wan2.1-VACE-14B/ ``` #### 运行文本生成图像(Text-to-Image) Wan2.1 是一个用于图像和视频生成的统一模型。由于它是在这两种类型的数据上训练的,因此它也能够生成图像。生成图像的命令与生成视频类似,如下所示: ##### (1) 不使用 Prompt 扩展 - 单 GPU 推理 ``` python generate.py --task t2i-14B --size 1024*1024 --ckpt_dir ./Wan2.1-T2V-14B --prompt '一个朴素端庄的美人' ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 ``` 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 ``` ##### (2) 使用 Prompt 扩展 - 单 GPU 推理 ``` python generate.py --task t2i-14B --size 1024*1024 --ckpt_dir ./Wan2.1-T2V-14B --prompt '一个朴素端庄的美人' --use_prompt_extend ``` - 使用 FSDP + xDiT USP 的多 GPU 推理 ``` 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 ``` ## 人工评估 ##### (1) 文本生成视频评估 通过人工评估,经过 Prompt 扩展后生成的结果优于闭源和开源模型的结果。
##### (2) 图像生成视频评估 我们还进行了广泛的人工评估来评估图像生成视频模型的性能,结果如下表所示。结果清楚地表明,**Wan2.1** 优于闭源和开源模型。
## 不同 GPU 上的计算效率 我们在下表中测试了不同 **Wan2.1** 模型在不同 GPU 上的计算效率。结果以以下格式呈现:**总时间 (秒) / GPU 峰值显存 (GB)**。
## Wan2.1 简介 **Wan2.1** 采用主流的扩散 Transformer(Diffusion Transformer)范式设计,通过一系列创新在生成能力上取得了重大进展。这些创新包括我们新颖的时空变分自编码器(VAE)、可扩展的训练策略、大规模数据构建和自动化评估指标。这些贡献共同提升了模型的性能和多功能性。 ##### (1) 3D 变分自编码器 我们提出了一种新颖的 3D 因果 VAE 架构,称为 **Wan-VAE**,专为视频生成而设计。通过结合多种策略,我们改善了时空压缩,减少了内存使用,并确保了时间因果性。与其他开源 VAE 相比,**Wan-VAE** 在性能效率上展现出显著优势。此外,我们的 **Wan-VAE** 能够在不丢失历史时间信息的情况下,对无限长度的 1080P 视频进行编码和解码,使其特别适合视频生成任务。
##### (2) 视频扩散 DiT **Wan2.1** 在主流 Diffusion Transformer 范式中使用 Flow Matching 框架进行设计。我们的模型架构使用 T5 Encoder 对多语言文本输入进行编码,并在每个 Transformer 块中使用交叉注意力(cross-attention)将文本嵌入到模型结构中。此外,我们采用了一个包含 Linear 层和 SiLU 层的 MLP 来处理输入时间嵌入,并分别预测六个调制参数。这个 MLP 被所有的 Transformer 块共享,每个块学习一组不同的偏置。我们的实验结果表明,这种方法在相同的参数规模下带来了显著的性能提升。
| 模型 | 维度 | 输入维度 | 输出维度 | 前馈维度 | 频率维度 | 注意力头数 | 层数 | |--------|-----------|-----------------|------------------|-----------------------|---------------------|-----------------|------------------| | 1.3B | 1536 | 16 | 16 | 8960 | 256 | 12 | 30 | | 14B | 5120 | 16 | 16 | 13824 | 256 | 40 | 40 | ##### 数据 我们整理并去重了一个包含大量图像和视频数据的候选数据集。在数据整理过程中,我们设计了一个四步数据清洗流程,重点关注基本维度、视觉质量和运动质量。通过稳健的数据处理流水线,我们能够轻松获得高质量、多样化且大规模的图像和视频训练集。 ![figure1](assets/data_for_diff_stage.jpg "figure1") ##### 与 SOTA 的比较 我们将 **Wan2.1** 与领先的闭源和开源模型进行了比较,以评估其性能。使用我们精心设计的包含 1,035 个内部 Prompt 的集合,我们测试了 14 个主要维度和 26 个子维度。然后,我们利用匹配过程中的人类偏好得出的权重,对各个维度的分数进行加权计算,从而得出总分。详细结果如下表所示。这些结果证明了我们的模型与闭源和开源模型相比具有卓越的性能。 ![figure1](assets/vben_vs_sota.png "figure1") ## 引用 如果您觉得我们的工作有帮助,请引用我们。 ``` @article{wan2025, title={Wan: Open and Advanced Large-Scale Video Generative Models}, author={Team Wan and Ang Wang and Baole Ai and Bin Wen and Chaojie Mao and Chen-Wei Xie and Di Chen and Feiwu Yu and Haiming Zhao and Jianxiao Yang and Jianyuan Zeng and Jiayu Wang and Jingfeng Zhang and Jingren Zhou and Jinkai Wang and Jixuan Chen and Kai Zhu and Kang Zhao and Keyu Yan and Lianghua Huang and Mengyang Feng and Ningyi Zhang and Pandeng Li and Pingyu Wu and Ruihang Chu and Ruili Feng and Shiwei Zhang and Siyang Sun and Tao Fang and Tianxing Wang and Tianyi Gui and Tingyu Weng and Tong Shen and Wei Lin and Wei Wang and Wei Wang and Wenmeng Zhou and Wente Wang and Wenting Shen and Wenyuan Yu and Xianzhong Shi and Xiaoming Huang and Xin Xu and Yan Kou and Yangyu Lv and Yifei Li and Yijing Liu and Yiming Wang and Yingya Zhang and Yitong Huang and Yong Li and You Wu and Yu Liu and Yulin Pan and Yun Zheng and Yuntao Hong and Yupeng Shi and Yutong Feng and Zeyinzi Jiang and Zhen Han and Zhi-Fan Wu and Ziyu Liu}, journal = {arXiv preprint arXiv:2503.20314}, year={2025} } ``` ## 许可协议 本代码库中的模型采用 Apache 2.0 许可协议授权。我们对您生成的内容不主张任何权利,授予您使用它们的自由,前提是确保您的使用符合本许可协议的规定。您对自己的模型使用行为负完全责任,使用行为不得涉及分享任何违反适用法律、对个人或群体造成伤害、传播旨在造成伤害的个人信息、散布虚假信息或针对弱势群体的内容。有关限制条件和您权利的完整列表及详细信息,请参阅[许可协议](LICENSE.txt)全文。 ## 致谢 我们要感谢 [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) 和 [HuggingFace](https://huggingface.co) 代码库的贡献者,感谢他们的开放研究。 ## 联系我们 如果您想给我们的研究或产品团队留言,欢迎加入我们的 [Discord](https://discord.gg/AKNgpMK4Yj) 或 [微信群](https://gw.alicdn.com/imgextra/i2/O1CN01tqjWFi1ByuyehkTSB_!!6000000000015-0-tps-611-1279.jpg)!
标签:AI, IaC 扫描, 凭据扫描, 图生视频, 多模态模型, 文生视频, 深度学习, 生成式AI, 索引, 自动化代码审查, 视频生成, 逆向工具