Wan2.1 Fun Full Parameter Training Guide

July 14, 2026 ยท View on GitHub

This document provides a complete workflow for full parameter training of Wan2.1 Fun Diffusion Transformer, including environment setup, data preparation, distributed training, and inference testing.

Note: Wan2.1 Fun is a video generation model that supports Text-to-Video (T2V), Image-to-Video (I2V), and Video Inpainting. This document covers the training workflow for both normal video generation and video inpainting tasks.


Table of Contents


1. Environment Setup

Option 1: Using requirements.txt

pip install -r requirements.txt

Option 2: Manual Installation

pip install Pillow einops safetensors timm tomesd librosa "torch>=2.1.2" torchdiffeq torchsde decord datasets numpy scikit-image
pip install omegaconf SentencePiece imageio[ffmpeg] imageio[pyav] tensorboard beautifulsoup4 ftfy func_timeout onnxruntime
pip install "peft>=0.17.0" "accelerate>=0.25.0" "gradio>=3.41.2" "diffusers>=0.30.1" "transformers>=4.46.2"
pip install yunchang xfuser modelscope openpyxl
pip uninstall opencv-python opencv-contrib-python opencv-python-headless -y
pip install opencv-python-headless
pip install deepspeed==0.17.0 numpy==1.26.4

Option 3: Using Docker

When using Docker, ensure that the GPU driver and CUDA environment are properly installed on your machine, then execute the following commands:

# pull image
docker pull mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:cogvideox_fun

# enter image
docker run -it -p 7860:7860 --network host --gpus all --security-opt seccomp:unconfined --shm-size 200g mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:cogvideox_fun

2. Data Preparation

2.1 Quick Test Dataset

We provide a test dataset containing several training samples.

# Download official demo dataset
modelscope download --dataset PAI/X-Fun-Videos-Demo --local_dir ./datasets/X-Fun-Videos-Demo

2.2 Dataset Structure

๐Ÿ“ฆ datasets/
โ”œโ”€โ”€ ๐Ÿ“‚ my_dataset/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ train/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ video001.mp4
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ video002.mp4
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ ...
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ metadata.json

2.3 metadata.json Format

Relative Path Format (example format):

[
  {
    "file_path": "train/video001.mp4",
    "text": "A beautiful sunset over the ocean, golden hour lighting",
    "type": "video",
    "width": 1024,
    "height": 1024
  },
  {
    "file_path": "train/video002.mp4",
    "text": "A person walking through a forest, cinematic view",
    "type": "video",
    "width": 1328,
    "height": 1328
  }
]

Absolute Path Format:

[
  {
    "file_path": "/mnt/data/videos/sunset.mp4",
    "text": "A beautiful sunset over the ocean",
    "type": "video",
    "width": 1024,
    "height": 1024
  }
]

Key Field Descriptions:

  • file_path: Video path (relative or absolute path)
  • text: Video description (English prompt)
  • type: Data type, should be "video"
  • width / height: Video width and height (recommended to provide, used for bucket training. If not provided, they will be automatically read during training, which may affect training speed when data is stored on slow storage systems like OSS).
    • You can use scripts/process_json_add_width_and_height.py to extract width and height from JSON files without these fields. It supports processing both images and videos.
    • Usage: python scripts/process_json_add_width_and_height.py --input_file datasets/X-Fun-Videos-Demo/metadata.json --output_file datasets/X-Fun-Videos-Demo/metadata_add_width_height.json.

2.4 Relative vs Absolute Path Usage

Relative Path:

If your data uses relative paths, configure in the training script:

export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"

Absolute Path:

If your data uses absolute paths, configure in the training script:

export DATASET_NAME=""
export DATASET_META_NAME="/mnt/data/metadata_add_width_height.json"

๐Ÿ’ก Recommendation: If the dataset is small and stored locally, use relative paths. If the dataset is stored on external storage (e.g., NAS, OSS) or shared across multiple machines, use absolute paths.


3. Full Parameter Training

3.1 Download Pretrained Model

# Create model directory
mkdir -p models/Diffusion_Transformer

# Download official Wan2.1 Fun weights
# Inpaint model (Video Inpainting)
modelscope download --model PAI/Wan2.1-Fun-V1.1-1.3B-InP --local_dir models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP

# modelscope download --model PAI/Wan2.1-Fun-V1.1-14B-InP --local_dir models/Diffusion_Transformer/Wan2.1-Fun-V1.1-14B-InP

3.2 Quick Start (DeepSpeed-Zero-2)

After downloading the dataset as in 2.1 Quick Test Dataset and the pretrained model as in 3.1 Download Pretrained Model, you can directly copy and run the quick start command.

We recommend using DeepSpeed-Zero-2 or FSDP for training. Here we use DeepSpeed-Zero-2 as an example.

The difference between DeepSpeed-Zero-2 and FSDP in this repository is whether the model weights are sharded. If GPU memory is insufficient when using multiple GPUs with DeepSpeed-Zero-2, you can switch to FSDP for training.

export MODEL_NAME="models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"
export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"
# NCCL_IB_DISABLE=1 and NCCL_P2P_DISABLE=1 are used in multi nodes without RDMA. 
# export NCCL_IB_DISABLE=1
# export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/wan2.1_fun/train.py \
  --config_path="config/wan2.1/wan_civitai.yaml" \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --train_data_dir=$DATASET_NAME \
  --train_data_meta=$DATASET_META_NAME \
  --image_sample_size=640 \
  --video_sample_size=640 \
  --token_sample_size=640 \
  --video_sample_stride=2 \
  --video_sample_n_frames=81 \
  --train_batch_size=1 \
  --video_repeat=1 \
  --gradient_accumulation_steps=1 \
  --dataloader_num_workers=8 \
  --num_train_epochs=100 \
  --checkpointing_steps=50 \
  --learning_rate=2e-05 \
  --lr_scheduler="constant_with_warmup" \
  --lr_warmup_steps=100 \
  --seed=42 \
  --output_dir="output_dir_wan2.1_fun" \
  --gradient_checkpointing \
  --mixed_precision="bf16" \
  --adam_weight_decay=3e-2 \
  --adam_epsilon=1e-10 \
  --vae_mini_batch=1 \
  --max_grad_norm=0.05 \
  --random_hw_adapt \
  --training_with_video_token_length \
  --enable_bucket \
  --uniform_sampling \
  --low_vram \
  --train_mode="inpaint" \
  --trainable_modules "."

3.3 Training Parameter Reference

Key Parameter Descriptions:

ParameterDescriptionExample Value
--pretrained_model_name_or_pathPretrained model pathmodels/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP
--train_data_dirTraining data directorydatasets/X-Fun-Videos-Demo/
--train_data_metaTraining data metadata filedatasets/X-Fun-Videos-Demo/metadata_add_width_height.json
--train_batch_sizeBatch size1
--image_sample_sizeMaximum training resolution for images640
--video_sample_sizeMaximum training resolution for videos640
--token_sample_sizeToken sample size640
--video_sample_strideVideo sample stride2
--video_sample_n_framesNumber of video frames to sample81
--gradient_accumulation_stepsGradient accumulation steps (effectively increases batch size)1
--dataloader_num_workersNumber of DataLoader workers8
--num_train_epochsNumber of training epochs100
--checkpointing_stepsSave checkpoint every N steps50
--learning_rateInitial learning rate2e-05
--lr_schedulerLearning rate schedulerconstant_with_warmup
--lr_warmup_stepsLearning rate warmup steps100
--seedRandom seed42
--output_dirOutput directoryoutput_dir_wan2.1_fun
--gradient_checkpointingGradient checkpointing-
--mixed_precisionMixed precision: fp16/bf16bf16
--adam_weight_decayAdamW weight decay3e-2
--adam_epsilonAdamW epsilon value1e-10
--vae_mini_batchMini-batch size for VAE encoding1
--max_grad_normMaximum gradient norm for clipping0.05
--enable_bucketEnable bucket training without cropping, groups by resolution-
--random_hw_adaptRandomly scale images/videos to [min_size, max_size]-
--training_with_video_token_lengthTrain based on token length, supports arbitrary resolutions-
--uniform_samplingUniform timestep sampling-
--low_vramLow VRAM mode-
--train_modeTraining mode: inpaint (video inpainting)inpaint
--resume_from_checkpointResume training from checkpoint, use "latest" to auto-selectNone
--validation_stepsRun validation every N steps100
--validation_epochsRun validation every N epochs500
--validation_promptsPrompts for validation video generation"A brown dog shaking its head..."
--validation_pathsReference image paths for inpaint validation (inpaint mode only)"asset/1.png"
--trainable_modulesTrainable modules ("." means all modules)"."

Sample Size Configuration Guide:

  • video_sample_size represents the resolution size for videos; when random_hw_adapt is True, it represents the minimum value for both video and image resolutions.
  • image_sample_size represents the resolution size for images; when random_hw_adapt is True, it represents the maximum value for both video and image resolutions.
  • token_sample_size represents the resolution corresponding to the maximum token length when training_with_video_token_length is True.
  • Due to potential confusion in configuration, if you don't require arbitrary resolution for finetuning, it is recommended to set video_sample_size, image_sample_size, and token_sample_size to the same fixed value, such as (320, 480, 512, 640, 960).
    • All set to 320 represents 240P.
    • All set to 480 represents 320P.
    • All set to 640 represents 480P.
    • All set to 960 represents 720P.

Token Length Training Explanation:

  • When training_with_video_token_length is enabled, the model trains based on token length.
  • For example: a video with 512x512 resolution and 49 frames has a token length of 13,312, requiring token_sample_size = 512.
    • At 512x512 resolution, the number of video frames is 49 (~= 512 * 512 * 49 / 512 / 512).
    • At 768x768 resolution, the number of video frames is 21 (~= 512 * 512 * 49 / 768 / 768).
    • At 1024x1024 resolution, the number of video frames is 9 (~= 512 * 512 * 49 / 1024 / 1024).
    • These resolutions combined with their corresponding frame counts allow the model to generate videos of different sizes.

3.4 Training Validation

You can configure validation parameters to periodically generate test videos during training, allowing you to monitor training progress and model quality.

Validation Parameter Descriptions:

ParameterDescriptionRecommended Value
--validation_stepsRun validation every N steps100
--validation_epochsRun validation every N epochs500
--validation_promptsPrompts for validation video generationEnglish prompts
--validation_pathsReference image paths for inpaint validation (inpaint mode only)"asset/1.png"

Inpaint Mode Example (Video Inpainting Validation):

  --validation_paths "asset/1.png" \
  --validation_steps=100 \
  --validation_epochs=500 \
  --validation_prompts="A brown dog shaking its head, sitting on a light-colored sofa in a cozy room. Behind the dog, there's a framed painting on a shelf, surrounded by pink flowers. The soft, warm lighting in the room creates a comfortable atmosphere."

Notes:

  • Validation videos will be saved to the output_dir directory
  • Multiple prompts format: --validation_prompts "prompt1" "prompt2" "prompt3"
  • inpaint mode requires the --validation_paths parameter

3.5 Training with FSDP

If GPU memory is insufficient when using multiple GPUs with DeepSpeed-Zero-2, you can switch to FSDP for training.

export MODEL_NAME="models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"
export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"
# NCCL_IB_DISABLE=1 and NCCL_P2P_DISABLE=1 are used in multi nodes without RDMA. 
# export NCCL_IB_DISABLE=1
# export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

accelerate launch --mixed_precision="bf16" --use_fsdp --fsdp_auto_wrap_policy TRANSFORMER_BASED_WRAP --fsdp_transformer_layer_cls_to_wrap=WanAttentionBlock --fsdp_sharding_strategy "FULL_SHARD" --fsdp_state_dict_type=SHARDED_STATE_DICT --fsdp_backward_prefetch "BACKWARD_PRE" --fsdp_cpu_ram_efficient_loading False scripts/wan2.1_fun/train.py \
  --config_path="config/wan2.1/wan_civitai.yaml" \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --train_data_dir=$DATASET_NAME \
  --train_data_meta=$DATASET_META_NAME \
  --image_sample_size=640 \
  --video_sample_size=640 \
  --token_sample_size=640 \
  --video_sample_stride=2 \
  --video_sample_n_frames=81 \
  --train_batch_size=1 \
  --video_repeat=1 \
  --gradient_accumulation_steps=1 \
  --dataloader_num_workers=8 \
  --num_train_epochs=100 \
  --checkpointing_steps=50 \
  --learning_rate=2e-05 \
  --lr_scheduler="constant_with_warmup" \
  --lr_warmup_steps=100 \
  --seed=42 \
  --output_dir="output_dir_wan2.1_fun" \
  --gradient_checkpointing \
  --mixed_precision="bf16" \
  --adam_weight_decay=3e-2 \
  --adam_epsilon=1e-10 \
  --vae_mini_batch=1 \
  --max_grad_norm=0.05 \
  --random_hw_adapt \
  --training_with_video_token_length \
  --enable_bucket \
  --uniform_sampling \
  --low_vram \
  --train_mode="inpaint" \
  --trainable_modules "."

3.6 Other Backends

3.6.1 Training with DeepSpeed-Zero-3

DeepSpeed Zero-3 is not highly recommended at the moment. In this repository, using FSDP has fewer errors and is more stable.

DeepSpeed Zero-3 is suitable for 14B Wan at high resolutions. After training, you can use the following command to get the final model:

python scripts/zero_to_bf16.py output_dir/checkpoint-{our-num-steps} output_dir/checkpoint-{your-num-steps}-outputs --max_shard_size 80GB --safe_serialization

Training shell command is as follows:

export MODEL_NAME="models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"
export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"
# NCCL_IB_DISABLE=1 and NCCL_P2P_DISABLE=1 are used in multi nodes without RDMA. 
# export NCCL_IB_DISABLE=1
# export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

accelerate launch --zero_stage 3 --zero3_save_16bit_model true --zero3_init_flag true --use_deepspeed --deepspeed_config_file config/zero_stage3_config.json --deepspeed_multinode_launcher standard scripts/wan2.1_fun/train.py \
  --config_path="config/wan2.1/wan_civitai.yaml" \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --train_data_dir=$DATASET_NAME \
  --train_data_meta=$DATASET_META_NAME \
  --image_sample_size=640 \
  --video_sample_size=640 \
  --token_sample_size=640 \
  --video_sample_stride=2 \
  --video_sample_n_frames=81 \
  --train_batch_size=1 \
  --video_repeat=1 \
  --gradient_accumulation_steps=1 \
  --dataloader_num_workers=8 \
  --num_train_epochs=100 \
  --checkpointing_steps=50 \
  --learning_rate=2e-05 \
  --lr_scheduler="constant_with_warmup" \
  --lr_warmup_steps=100 \
  --seed=42 \
  --output_dir="output_dir_wan2.1_fun" \
  --gradient_checkpointing \
  --mixed_precision="bf16" \
  --adam_weight_decay=3e-2 \
  --adam_epsilon=1e-10 \
  --vae_mini_batch=1 \
  --max_grad_norm=0.05 \
  --random_hw_adapt \
  --training_with_video_token_length \
  --enable_bucket \
  --uniform_sampling \
  --low_vram \
  --train_mode="inpaint" \
  --trainable_modules "."

3.6.2 Training Without DeepSpeed and FSDP

This approach is not recommended as it lacks memory-saving backends and may easily cause out-of-memory errors. Provided here for reference only.

export MODEL_NAME="models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"
export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"
# NCCL_IB_DISABLE=1 and NCCL_P2P_DISABLE=1 are used in multi nodes without RDMA. 
# export NCCL_IB_DISABLE=1
# export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

accelerate launch --mixed_precision="bf16" scripts/wan2.1_fun/train.py \
  --config_path="config/wan2.1/wan_civitai.yaml" \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --train_data_dir=$DATASET_NAME \
  --train_data_meta=$DATASET_META_NAME \
  --image_sample_size=640 \
  --video_sample_size=640 \
  --token_sample_size=640 \
  --video_sample_stride=2 \
  --video_sample_n_frames=81 \
  --train_batch_size=1 \
  --video_repeat=1 \
  --gradient_accumulation_steps=1 \
  --dataloader_num_workers=8 \
  --num_train_epochs=100 \
  --checkpointing_steps=50 \
  --learning_rate=2e-05 \
  --lr_scheduler="constant_with_warmup" \
  --lr_warmup_steps=100 \
  --seed=42 \
  --output_dir="output_dir_wan2.1_fun" \
  --gradient_checkpointing \
  --mixed_precision="bf16" \
  --adam_weight_decay=3e-2 \
  --adam_epsilon=1e-10 \
  --vae_mini_batch=1 \
  --max_grad_norm=0.05 \
  --random_hw_adapt \
  --training_with_video_token_length \
  --enable_bucket \
  --uniform_sampling \
  --low_vram \
  --train_mode="inpaint" \
  --trainable_modules "."

3.7 Multi-Node Distributed Training

Suitable for: Ultra-large-scale datasets, faster training speed

3.7.1 Environment Configuration

Assuming 2 machines with 8 GPUs each:

Machine 0 (Master):

export MODEL_NAME="models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"
export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"
export MASTER_ADDR="192.168.1.100"  # Master machine IP
export MASTER_PORT=10086
export WORLD_SIZE=2                  # Total number of machines
export NUM_PROCESS=16                # Total processes = machines ร— 8
export RANK=0                        # Current machine rank (0 or 1)
# NCCL_IB_DISABLE=1 and NCCL_P2P_DISABLE=1 are used in multi nodes without RDMA. 
# export NCCL_IB_DISABLE=1
# export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

accelerate launch --mixed_precision="bf16" --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --num_machines=$WORLD_SIZE --num_processes=$NUM_PROCESS --machine_rank=$RANK --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/wan2.1_fun/train.py \
  --config_path="config/wan2.1/wan_civitai.yaml" \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --train_data_dir=$DATASET_NAME \
  --train_data_meta=$DATASET_META_NAME \
  --image_sample_size=640 \
  --video_sample_size=640 \
  --token_sample_size=640 \
  --video_sample_stride=2 \
  --video_sample_n_frames=81 \
  --train_batch_size=1 \
  --video_repeat=1 \
  --gradient_accumulation_steps=1 \
  --dataloader_num_workers=8 \
  --num_train_epochs=100 \
  --checkpointing_steps=50 \
  --learning_rate=2e-05 \
  --lr_scheduler="constant_with_warmup" \
  --lr_warmup_steps=100 \
  --seed=42 \
  --output_dir="output_dir_wan2.1_fun" \
  --gradient_checkpointing \
  --mixed_precision="bf16" \
  --adam_weight_decay=3e-2 \
  --adam_epsilon=1e-10 \
  --vae_mini_batch=1 \
  --max_grad_norm=0.05 \
  --random_hw_adapt \
  --training_with_video_token_length \
  --enable_bucket \
  --uniform_sampling \
  --low_vram \
  --train_mode="inpaint" \
  --trainable_modules "."

Machine 1 (Worker):

export MODEL_NAME="models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"
export DATASET_NAME="datasets/X-Fun-Videos-Demo/"
export DATASET_META_NAME="datasets/X-Fun-Videos-Demo/metadata_add_width_height.json"
export MASTER_ADDR="192.168.1.100"  # Same as Master
export MASTER_PORT=10086
export WORLD_SIZE=2
export NUM_PROCESS=16
export RANK=1  # Note: this is 1
# NCCL_IB_DISABLE=1 and NCCL_P2P_DISABLE=1 are used in multi nodes without RDMA. 
# export NCCL_IB_DISABLE=1
# export NCCL_P2P_DISABLE=1
NCCL_DEBUG=INFO

# Use the same accelerate launch command as Machine 0

3.7.2 Multi-Node Training Notes

  • Network Requirements:

    • Recommended: RDMA/InfiniBand (high performance)
    • Without RDMA, add environment variables:
      export NCCL_IB_DISABLE=1
      export NCCL_P2P_DISABLE=1
      
  • Data Synchronization: All machines must have access to the same data paths (NFS/shared storage)


4. Inference Testing

4.1 Inference Parameter Reference

Key Parameter Descriptions:

ParameterDescriptionExample Value
GPU_memory_modeGPU memory management mode, see table belowmodel_group_offload
ulysses_degreeHead dimension parallelism, 1 for single GPU1
ring_degreeSequence dimension parallelism, 1 for single GPU1
fsdp_ditUse FSDP for Transformer during multi-GPU inferenceFalse
fsdp_text_encoderUse FSDP for text encoder during multi-GPU inferenceTrue
compile_ditCompile Transformer for faster inference (effective for fixed resolution)False
model_nameModel pathmodels/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP
sampler_nameSampler type: Flow, Flow_Unipc, Flow_DPM++Flow_Unipc
transformer_pathPath to trained Transformer weightsNone
vae_pathPath to trained VAE weightsNone
lora_pathLoRA weights pathNone
sample_sizeGenerated video resolution [height, width][480, 832] or [832, 480]
video_lengthNumber of video frames81
fpsFrames per second16
weight_dtypeModel weight precision, use torch.float16 for GPUs not supporting bf16torch.bfloat16
validation_image_startReference image path for inpaint mode"asset/1.png"
validation_image_endTarget image path for inpaint mode (set to None for pure I2V)None
promptPositive prompt describing content"A brown dog shaking its head..."
negative_promptNegative prompt to avoid certain content"low resolution, low quality..."
guidance_scaleGuidance strength6.0
seedRandom seed for reproducibility43
num_inference_stepsNumber of inference steps50
lora_weightLoRA weight strength0.55
save_pathPath to save generated videosamples/wan-videos-fun-t2v or samples/wan-videos-fun-i2v

GPU Memory Management Modes:

ModeDescriptionMemory Usage
model_full_loadFull model loaded to GPUHighest
model_full_load_and_qfloat8Full load + FP8 quantizationHigh
model_cpu_offloadOffload model to CPU after useMedium
model_cpu_offload_and_qfloat8CPU offload + FP8 quantizationMedium-Low
model_group_offloadLayer groups switch between CPU/CUDALow
sequential_cpu_offloadLayer-by-layer offload (slowest)Lowest

4.2 Text-to-Video (T2V) Inference

Run the following command for single GPU inference:

python examples/wan2.1_fun/predict_t2v.py

Edit examples/wan2.1_fun/predict_t2v.py according to your needs. For initial inference, focus on the following parameters. If you're interested in other parameters, refer to the inference parameter reference above.

# Choose based on GPU memory
GPU_memory_mode = "sequential_cpu_offload"
# Based on actual model path
model_name = "models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"  
# Path to trained weights, e.g., "output_dir_wan2.1_fun/checkpoint-xxx/diffusion_pytorch_model.safetensors"
transformer_path = None  
# Write based on the content you want to generate
prompt = "A brown dog shaking its head, sitting on a light-colored sofa in a cozy room. Behind the dog, there's a framed painting on a shelf, surrounded by pink flowers. The soft, warm lighting in the room creates a comfortable atmosphere."  
# ...

4.3 Image-to-Video (I2V) Inference

Run the following command for single GPU inference:

python examples/wan2.1_fun/predict_i2v.py

Edit examples/wan2.1_fun/predict_i2v.py according to your needs. For initial inference, focus on the following parameters. If you're interested in other parameters, refer to the inference parameter reference above.

# Choose based on GPU memory
GPU_memory_mode = "sequential_cpu_offload"
# Based on actual model path
model_name = "models/Diffusion_Transformer/Wan2.1-Fun-V1.1-1.3B-InP"  
# Path to trained weights, e.g., "output_dir_wan2.1_fun/checkpoint-xxx/diffusion_pytorch_model.safetensors"
transformer_path = None  
# Starting image for image-to-video / inpaint
validation_image_start = "asset/1.png"
# Target image for inpaint (set to None for pure image-to-video)
validation_image_end = None
# Write based on the content you want to generate
prompt = "A brown dog shaking its head, sitting on a light-colored sofa in a cozy room. Behind the dog, there's a framed painting on a shelf, surrounded by pink flowers. The soft, warm lighting in the room creates a comfortable atmosphere."  
# ...

4.4 Multi-GPU Parallel Inference

Suitable for: High-resolution generation, accelerated inference

Install Parallel Inference Dependencies

pip install xfuser==0.4.2 yunchang==0.6.2

Configure Parallel Strategy

Edit examples/wan2.1_fun/predict_t2v.py or examples/wan2.1_fun/predict_i2v.py:

``$\text{python}

\text{Ensure} \text{ulysses_degree} \times \text{ring_degree} = \text{number} \text{of} \text{GPUs} \text{used}

\text{For} \text{example}, \text{using} 2 \text{GPUs}:

\text{ulysses_degree} = 2 # \text{Head} \text{dimension} \text{parallelism} \text{ring_degree} = 1 # \text{Sequence} \text{dimension} \text{parallelism} $``

Configuration Principles:

  • ulysses_degree must be divisible by the model's number of heads
  • ring_degree splits along the sequence dimension and affects communication overhead; avoid using it when heads can be evenly divided

Configuration Examples:

GPU Countulysses_degreering_degreeDescription
111Single GPU
441Head parallelism
881Head parallelism
842Hybrid parallelism

Run Multi-GPU Inference

torchrun --nproc-per-node=2 examples/wan2.1_fun/predict_t2v.py

5. Additional Resources