LoRA

Wan

Wan-2.1 by the Wan Team.

This report presents Wan, a comprehensive and open suite of video foundation models designed to push the boundaries of video generation. Built upon the mainstream diffusion transformer paradigm, Wan achieves significant advancements in generative capabilities through a series of innovations, including our novel VAE, scalable pre-training strategies, large-scale data curation, and automated evaluation metrics. These contributions collectively enhance the model’s performance and versatility. Specifically, Wan is characterized by four key features: Leading Performance: The 14B model of Wan, trained on a vast dataset comprising billions of images and videos, demonstrates the scaling laws of video generation with respect to both data and model size. It consistently outperforms the existing open-source models as well as state-of-the-art commercial solutions across multiple internal and external benchmarks, demonstrating a clear and significant performance superiority. Comprehensiveness: Wan offers two capable models, i.e., 1.3B and 14B parameters, for efficiency and effectiveness respectively. It also covers multiple downstream applications, including image-to-video, instruction-guided video editing, and personal video generation, encompassing up to eight tasks. Consumer-Grade Efficiency: The 1.3B model demonstrates exceptional resource efficiency, requiring only 8.19 GB VRAM, making it compatible with a wide range of consumer-grade GPUs. Openness: We open-source the entire series of Wan, including source code and all models, with the goal of fostering the growth of the video generation community. This openness seeks to significantly expand the creative possibilities of video production in the industry and provide academia with high-quality video foundation models. All the code and models are available at this https URL.

You can find all the original Wan2.1 checkpoints under the Wan-AI organization.

The following Wan models are supported in Diffusers:

[!TIP] Click on the Wan models in the right sidebar for more examples of video generation.

Text-to-Video Generation

The example below demonstrates how to generate a video from text optimized for memory or inference speed.

Refer to the [Reduce memory usage](../../optimization/memory) guide for more details about the various memory saving techniques. The Wan2.1 text-to-video model below requires ~13GB of VRAM. ```py # pip install ftfy import torch import numpy as np from diffusers import AutoModel, WanPipeline from diffusers.quantizers import PipelineQuantizationConfig from diffusers.hooks.group_offloading import apply_group_offloading from diffusers.utils import export_to_video, load_image from transformers import UMT5EncoderModel text_encoder = UMT5EncoderModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="text_encoder", torch_dtype=torch.bfloat16) vae = AutoModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="vae", torch_dtype=torch.float32) transformer = AutoModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="transformer", torch_dtype=torch.bfloat16) # group-offloading onload_device = torch.device("cuda") offload_device = torch.device("cpu") apply_group_offloading(text_encoder, onload_device=onload_device, offload_device=offload_device, offload_type="block_level", num_blocks_per_group=4 ) transformer.enable_group_offload( onload_device=onload_device, offload_device=offload_device, offload_type="leaf_level", use_stream=True ) pipeline = WanPipeline.from_pretrained( "Wan-AI/Wan2.1-T2V-14B-Diffusers", vae=vae, transformer=transformer, text_encoder=text_encoder, torch_dtype=torch.bfloat16 ) pipeline.to("cuda") prompt = """ The camera rushes from far to near in a low-angle shot, revealing a white ferret on a log. It plays, leaps into the water, and emerges, as the camera zooms in for a close-up. Water splashes berry bushes nearby, while moss, snow, and leaves blanket the ground. Birch trees and a light blue sky frame the scene, with ferns in the foreground. Side lighting casts dynamic shadows and warm highlights. Medium composition, front view, low angle, with depth of field. """ 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 = pipeline( prompt=prompt, negative_prompt=negative_prompt, num_frames=81, guidance_scale=5.0, ).frames[0] export_to_video(output, "output.mp4", fps=16) ``` [Compilation](../../optimization/fp16#torchcompile) is slow the first time but subsequent calls to the pipeline are faster. [Caching](../../optimization/cache) may also speed up inference by storing and reusing intermediate outputs. ```py # pip install ftfy import torch import numpy as np from diffusers import AutoModel, WanPipeline from diffusers.hooks.group_offloading import apply_group_offloading from diffusers.utils import export_to_video, load_image from transformers import UMT5EncoderModel text_encoder = UMT5EncoderModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="text_encoder", torch_dtype=torch.bfloat16) vae = AutoModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="vae", torch_dtype=torch.float32) transformer = AutoModel.from_pretrained("Wan-AI/Wan2.1-T2V-14B-Diffusers", subfolder="transformer", torch_dtype=torch.bfloat16) pipeline = WanPipeline.from_pretrained( "Wan-AI/Wan2.1-T2V-14B-Diffusers", vae=vae, transformer=transformer, text_encoder=text_encoder, torch_dtype=torch.bfloat16 ) pipeline.to("cuda") # torch.compile pipeline.transformer.to(memory_format=torch.channels_last) pipeline.transformer = torch.compile( pipeline.transformer, mode="max-autotune", fullgraph=True ) prompt = """ The camera rushes from far to near in a low-angle shot, revealing a white ferret on a log. It plays, leaps into the water, and emerges, as the camera zooms in for a close-up. Water splashes berry bushes nearby, while moss, snow, and leaves blanket the ground. Birch trees and a light blue sky frame the scene, with ferns in the foreground. Side lighting casts dynamic shadows and warm highlights. Medium composition, front view, low angle, with depth of field. """ 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 = pipeline( prompt=prompt, negative_prompt=negative_prompt, num_frames=81, guidance_scale=5.0, ).frames[0] export_to_video(output, "output.mp4", fps=16) ```

First-Last-Frame-to-Video Generation

The example below demonstrates how to use the image-to-video pipeline to generate a video using a text description, a starting frame, and an ending frame.

```python import numpy as np import torch import torchvision.transforms.functional as TF from diffusers import AutoencoderKLWan, WanImageToVideoPipeline from diffusers.utils import export_to_video, load_image from transformers import CLIPVisionModel model_id = "Wan-AI/Wan2.1-FLF2V-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") first_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png") last_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png") def aspect_ratio_resize(image, pipe, 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)) return image, height, width def center_crop_resize(image, height, width): # Calculate resize ratio to match first frame dimensions resize_ratio = max(width / image.width, height / image.height) # Resize the image width = round(image.width * resize_ratio) height = round(image.height * resize_ratio) size = [width, height] image = TF.center_crop(image, size) return image, height, width first_frame, height, width = aspect_ratio_resize(first_frame, pipe) if last_frame.size != first_frame.size: last_frame, _, _ = center_crop_resize(last_frame, height, width) 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." output = pipe( image=first_frame, last_image=last_frame, prompt=prompt, height=height, width=width, guidance_scale=5.5 ).frames[0] export_to_video(output, "output.mp4", fps=16) ```

Any-to-Video Controllable Generation

Wan VACE supports various generation techniques which achieve controllable video generation. Some of the capabilities include:

The code snippets available in this pull request demonstrate some examples of how videos can be generated with controllability signals.

The general rule of thumb to keep in mind when preparing inputs for the VACE pipeline is that the input images, or frames of a video that you want to use for conditioning, should have a corresponding mask that is black in color. The black mask signifies that the model will not generate new content for that area, and only use those parts for conditioning the generation process. For parts/frames that should be generated by the model, the mask should be white in color.

</hfoption> </hfoptions>

Wan-Animate: Unified Character Animation and Replacement with Holistic Replication

Wan-Animate by the Wan Team.

We introduce Wan-Animate, a unified framework for character animation and replacement. Given a character image and a reference video, Wan-Animate can animate the character by precisely replicating the expressions and movements of the character in the video to generate high-fidelity character videos. Alternatively, it can integrate the animated character into the reference video to replace the original character, replicating the scene’s lighting and color tone to achieve seamless environmental integration. Wan-Animate is built upon the Wan model. To adapt it for character animation tasks, we employ a modified input paradigm to differentiate between reference conditions and regions for generation. This design unifies multiple tasks into a common symbolic representation. We use spatially-aligned skeleton signals to replicate body motion and implicit facial features extracted from source images to reenact expressions, enabling the generation of character videos with high controllability and expressiveness. Furthermore, to enhance environmental integration during character replacement, we develop an auxiliary Relighting LoRA. This module preserves the character’s appearance consistency while applying the appropriate environmental lighting and color tone. Experimental results demonstrate that Wan-Animate achieves state-of-the-art performance. We are committed to open-sourcing the model weights and its source code.

The project page: https://humanaigc.github.io/wan-animate

This model was mostly contributed by M. Tolga Cangöz.

Usage

The Wan-Animate pipeline supports two modes of operation:

  1. Animation Mode (default): Animates a character image based on motion and expression from reference videos
  2. Replacement Mode: Replaces a character in a background video with a new character while preserving the scene
Prerequisites

Before using the pipeline, you need to preprocess your reference video to extract:

For replacement mode, you additionally need:

[!NOTE] Raw videos should not be used for inputs such as pose_video, which the pipeline expects to be preprocessed to extract the proper information. Preprocessing scripts to prepare these inputs are available in the original Wan-Animate repository. Integration of these preprocessing steps into Diffusers is planned for a future release.

The example below demonstrates how to use the Wan-Animate pipeline:

```python import numpy as np import torch from diffusers import AutoencoderKLWan, WanAnimatePipeline from diffusers.utils import export_to_video, load_image, load_video model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers" vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32) pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16) pipe.to("cuda") # Load character image and preprocessed videos image = load_image("path/to/character.jpg") pose_video = load_video("path/to/pose_video.mp4") # Preprocessed skeletal keypoints face_video = load_video("path/to/face_video.mp4") # Preprocessed facial features # Resize image to match VAE constraints def aspect_ratio_resize(image, pipe, 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)) return image, height, width image, height, width = aspect_ratio_resize(image, pipe) prompt = "A person dancing energetically in a studio with dynamic lighting and professional camera work" negative_prompt = "blurry, low quality, distorted, deformed, static, poorly drawn" # Generate animated video output = pipe( image=image, pose_video=pose_video, face_video=face_video, prompt=prompt, negative_prompt=negative_prompt, height=height, width=width, segment_frame_length=77, guidance_scale=1.0, mode="animate", # Animation mode (default) ).frames[0] export_to_video(output, "animated_character.mp4", fps=30) ``` ```python import numpy as np import torch from diffusers import AutoencoderKLWan, WanAnimatePipeline from diffusers.utils import export_to_video, load_image, load_video model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers" vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32) pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16) pipe.to("cuda") # Load all required inputs for replacement mode image = load_image("path/to/new_character.jpg") pose_video = load_video("path/to/pose_video.mp4") # Preprocessed skeletal keypoints face_video = load_video("path/to/face_video.mp4") # Preprocessed facial features background_video = load_video("path/to/background_video.mp4") # Original scene mask_video = load_video("path/to/mask_video.mp4") # Black: preserve, White: generate # Resize image to match video dimensions def aspect_ratio_resize(image, pipe, 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)) return image, height, width image, height, width = aspect_ratio_resize(image, pipe) prompt = "A person seamlessly integrated into the scene with consistent lighting and environment" negative_prompt = "blurry, low quality, inconsistent lighting, floating, disconnected from scene" # Replace character in background video output = pipe( image=image, pose_video=pose_video, face_video=face_video, background_video=background_video, mask_video=mask_video, prompt=prompt, negative_prompt=negative_prompt, height=height, width=width, segment_frame_lengths=77, guidance_scale=1.0, mode="replace", # Replacement mode ).frames[0] export_to_video(output, "character_replaced.mp4", fps=30) ``` ```python import numpy as np import torch from diffusers import AutoencoderKLWan, WanAnimatePipeline from diffusers.utils import export_to_video, load_image, load_video model_id = "Wan-AI/Wan2.2-Animate-14B-Diffusers" vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32) pipe = WanAnimatePipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16) pipe.to("cuda") image = load_image("path/to/character.jpg") pose_video = load_video("path/to/pose_video.mp4") face_video = load_video("path/to/face_video.mp4") def aspect_ratio_resize(image, pipe, 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)) return image, height, width image, height, width = aspect_ratio_resize(image, pipe) prompt = "A person dancing energetically in a studio" negative_prompt = "blurry, low quality" # Advanced: Use temporal guidance and custom callback def callback_fn(pipe, step_index, timestep, callback_kwargs): # You can modify latents or other tensors here print(f"Step {step_index}, Timestep {timestep}") return callback_kwargs output = pipe( image=image, pose_video=pose_video, face_video=face_video, prompt=prompt, negative_prompt=negative_prompt, height=height, width=width, segment_frame_length=77, num_inference_steps=50, guidance_scale=5.0, prev_segment_conditioning_frames=5, # Use 5 frames for temporal guidance (1 or 5 recommended) callback_on_step_end=callback_fn, callback_on_step_end_tensor_inputs=["latents"], ).frames[0] export_to_video(output, "animated_advanced.mp4", fps=30) ```

Key Parameters

Notes

WanPipeline

[[autodoc]] WanPipeline

WanImageToVideoPipeline

[[autodoc]] WanImageToVideoPipeline

WanVACEPipeline

[[autodoc]] WanVACEPipeline

WanVideoToVideoPipeline

[[autodoc]] WanVideoToVideoPipeline

WanAnimatePipeline

[[autodoc]] WanAnimatePipeline

WanPipelineOutput

[[autodoc]] pipelines.wan.pipeline_output.WanPipelineOutput