基于昇腾玩转电影级视频生成模型Wan 2.2
7月28日,阿里开源了新一代视频生成模型王者通义万相Wan2.2。此次共开源文生视频(Wan2.2-T2V-A14B)、图生视频(Wan2.2-I2V-A14B)和统一视频生成(Wan2.2-IT2V-5B)三款模型,其中文生视频模型和图生视频模型均为业界首个使用MoE架构的视频生成模型,总参数量为27B,激活参数14B;同时,首创电影美学控制系统,光影、色彩、构图、微表情等能力媲美专业电影水平。
昇腾支持该模型开箱部署和推理,模型已上线魔乐社区,欢迎下载体验!
🔗模型链接:
https://modelers.cn/models/MindIE/Wan2.2
01
模型介绍
Wan2.2模型将MoE(混合专家)架构实现到了视频生成扩散模型中!A14B版本由高噪专家模型和低噪专家模型组成,考虑扩散模型的去噪过程存在阶段性差异,我们根据去噪时间步进行了专家模型划分——高噪声阶段关注生成视频的整体布局,低噪声阶段则更关注细节的完善。
在生成视频时,噪声首先经过高噪专家模型进行前期去噪,再经过低噪专家模型进行后期去噪,高噪和低噪专家模型各自独立激活。因此Wan2.2生成的视频分布与真实视频差异更小,质量更高!
Wan2.2还首创了「电影美学控制系统」,光影、色彩、构图、微表情等能力媲美专业电影水平。例如,用户输入「黄昏」、「柔光」、「边缘光」、「暖色调」「中心构图」等关键词,模型可自动生成金色的落日余晖的浪漫画面;使用「冷色调」、「硬光」、「平衡图」、「低角度」的组合,则可以生成接近科幻片的画面效果。
通义万相还开源了一款5B小尺寸的统一视频生成模型,单一模型同时支持文生视频和图生视频,可在消费级显卡部署。该模型采用了高压缩率3D VAE架构,时间与空间压缩比达到高达 4×16×16,信息压缩率提升至 64,均实现了开源模型的最高水平,仅需22G显存(单张消费级显卡)即可在数分钟内生成5秒高清视频,是目前24帧每秒、720P像素级的生成速度最快的基础模型。
以下为手把手推理教程。
02
准备运行环境
配套 | 版本 |
Python | 3.11.10 |
torch | 2.1.0 |
1. 获取CANN&MindIE安装包&环境准备
• 设备支持 Atlas 800I/800T A2(8*64G)推理设备:支持的卡数最小为1 Atlas 800I/800T A2(8*64G)
(https://www.hiascend.com/developer/download/community/result?module=pt+ie+cann&product=4&model=32)
• 环境准备指导:
https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha002/softwareinst/instg/instg_0001.html
2. CANN安装
# 增加软件包可执行权限,{version}表示软件版本号,{arch}表示CPU架构,{soc}表示昇腾AI处理器的版本。
chmod +x ./Ascend-cann-toolkit_{version}_linux-{arch}.run
chmod +x ./Ascend-cann-kernels-{soc}_{version}_linux.run
# 校验软件包安装文件的一致性和完整性
./Ascend-cann-toolkit_{version}_linux-{arch}.run --check
./Ascend-cann-kernels-{soc}_{version}_linux.run --check
# 安装
./Ascend-cann-toolkit_{version}_linux-{arch}.run --install
./Ascend-cann-kernels-{soc}_{version}_linux.run --install
# 设置环境变量
source /usr/local/Ascend/ascend-toolkit/set_env.sh
3. 环境依赖安装
pip3 install -r requirements.txt
4. MindIE安装
# 增加软件包可执行权限,{version}表示软件版本号,{arch}表示CPU架构。
chmod +x ./Ascend-mindie_${version}_linux-${arch}.run
./Ascend-mindie_${version}_linux-${arch}.run --check
# 方式一:默认路径安装
./Ascend-mindie_${version}_linux-${arch}.run --install
# 设置环境变量
cd /usr/local/Ascend/mindie && source set_env.sh
# 方式二:指定路径安装
./Ascend-mindie_${version}_linux-${arch}.run --install-path=${AieInstallPath}
# 设置环境变量
cd ${AieInstallPath}/mindie && source set_env.sh
5. Torch_npu安装
下载 pytorch_v{pytorchversion}_py{pythonversion}.tar.gz
tar -xzvf pytorch_v{pytorchversion}_py{pythonversion}.tar.gz
# 解压后,会有whl包
pip install torch_npu-{pytorchversion}.xxxx.{arch}.whl
03
下载权重
从魔乐社区或者HuggingFace下载权重:
Wan2.2-T2V-A14B: https://modelers.cn/models/Modelers_Park/Wan2.2-T2V-A14B
Wan2.2-I2V-A14B: https://modelers.cn/models/Modelers_Park/Wan2.2-I2V-A14B
Wan2.2-TI2V-5B: https://modelers.cn/models/Modelers_Park/Wan2.2-TI2V-5B
04
Wan2.2使用
下载到本地
git clone https://modelers.cn/MindIE/Wan2.2.git
Wan2.2-T2V-A14B
使用上一步下载的权重:
model_base="./Wan2.2-T2V-A14B/"
等价优化:
8卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=8 --master_port=23459 generate.py \
--task t2v-A14B \
--ckpt_dir ${model_base} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 1 \
--ulysses_size 8 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--base_seed 0
参数说明
• ALGO: 为0表示默认FA算子; 设置为1表示使用高性能FA算子
• task: 任务类型
• ckpt_dir: 模型的权重路径
• size: 生成视频的分辨率,支持(1280,720)、(832,480)分辨率
• frame_num: 生成视频的帧数
• sample_steps: 推理步数
• dit_fsdp: dit使能fsdp, 用以降低显存占用
• t5_fsdp: t5使能fsdp, 用以降低显存占用
• cfg_size: cfg并行数
• ulysses_size: ulysses并行数
• vae_parallel: 使能vae并行策略
• prompt: 文本提示词
• base_seed: 随机种子
16卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=16 --master_port=23459 generate.py \
--task t2v-A14B \
--ckpt_dir ${model_base} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 2 \
--ulysses_size 8 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--base_seed 0
Wan2.2-I2V-A14B
使用上一步下载的权重:
model_base="./Wan2.2-I2V-A14B/"
等价优化
8卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=8 generate.py \
--task i2v-A14B \
--ckpt_dir ${model_base} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 1 \
--ulysses_size 8 \
--vae_parallel \
--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." \
--base_seed 0
参数说明
• ALGO: 为0表示默认FA算子; 设置为1表示使用高性能FA算子
• task: 任务类型
• ckpt_dir: 模型的权重路径
• size: 生成视频的分辨率,支持(1280,720)、(832,480)分辨率
• frame_num: 生成视频的帧数
• sample_steps: 推理步数
• dit_fsdp: dit使能fsdp, 用以降低显存占用
• t5_fsdp: t5使能fsdp, 用以降低显存占用
• cfg_size: cfg并行数
• ulysses_size: ulysses并行数
• vae_parallel: 使能vae并行策略
• image: 输入图片路径
• prompt: 文本提示词
• base_seed: 随机种子
16卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=16 --master_port=23459 generate.py \
--task i2v-A14B \
--ckpt_dir ${model_base} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 2 \
--ulysses_size 8 \
--vae_parallel \
--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." \
--base_seed 0
Wan2.2-TI2V-5B
使用上一步下载的权重:
model_base="./Wan2.2-TI2V-5B/"
等价优化
单卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
python generate.py \
--task ti2v-5B \
--ckpt_dir ${model_base} \
--size 1280*704 \
--frame_num 121 \
--sample_steps 50 \
--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." \
--base_seed 0
参数说明
• ALGO: 为0表示默认FA算子;设置为1表示使用高性能FA算子
• task: 任务类型
• ckpt_dir: 模型的权重路径
• size: 生成视频的分辨率,支持(1280,720)、(832,480)分辨率
• frame_num: 生成视频的帧数
• sample_steps: 推理步数
• image: 输入图片路径
• prompt: 文本提示词
• base_seed: 随机种子
8卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=8 generate.py \
--task ti2v-5B \
--ckpt_dir ${model_base} \
--size 1280*704 \
--frame_num 121 \
--sample_steps 50 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 1 \
--ulysses_size 8 \
--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." \
--base_seed 0
参数说明
• ALGO: 为0表示默认FA算子;设置为1表示使用高性能FA算子
• task: 任务类型
• ckpt_dir: 模型的权重路径
• size: 生成视频的分辨率,支持(1280,720)、(832,480)分辨率
• frame_num: 生成视频的帧数
• sample_steps: 推理步数
• dit_fsdp: dit使能fsdp, 用以降低显存占用
• t5_fsdp: t5使能fsdp, 用以降低显存占用
• cfg_size: cfg并行数
• ulysses_size: ulysses并行数
• vae_parallel: 使能vae并行策略
• image: 输入图片路径
• prompt: 文本提示词
• base_seed: 随机种子
16卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=16 --master_port=23459 generate.py \
--task ti2v-5B \
--ckpt_dir ${model_base} \
--size 1280*704 \
--frame_num 81 \
--sample_steps 40 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 2 \
--ulysses_size 8 \
--vae_parallel \
--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." \
--base_seed 0
算法优化
单卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
python generate.py \
--task ti2v-5B \
--ckpt_dir ${model_base} \
--size 1280*704 \
--frame_num 121 \
--sample_steps 50 \
--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." \
--base_seed 0 \
--use_attentioncache \
--start_step 20 \
--attentioncache_interval 2 \
--end_step 47
参数说明
• ALGO: 为0表示默认FA算子;设置为1表示使用高性能FA算子
• use_attentioncache: 使能attentioncache策略
• start_step: cache开始的step
• attentioncache_interval: cache重计算间隔
• end_step: cache结束的step
8卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=8 generate.py \
--task ti2v-5B \
--ckpt_dir ${model_base} \
--size 1280*704 \
--frame_num 121 \
--sample_steps 50 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 1 \
--ulysses_size 8 \
--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." \
--base_seed 0 \
--use_attentioncache \
--start_step 20 \
--attentioncache_interval 2 \
--end_step 47
16卡性能测试
执行命令
export ALGO=0
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
torchrun --nproc_per_node=16 --master_port=23459 generate.py \
--task ti2v-5B \
--ckpt_dir ${model_base} \
--size 1280*704 \
--frame_num 81 \
--sample_steps 40 \
--dit_fsdp \
--t5_fsdp \
--cfg_size 2 \
--ulysses_size 8 \
--vae_parallel \
--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." \
--base_seed 0 \
--use_attentioncache \
--start_step 20 \
--attentioncache_interval 2 \
--end_step 47
注:
1. 若出现OOM, 可添加环境变量 export T5_LOAD_CPU=1,以降低显存占用
2. 当前仅TI2V支持attentioncache
05
推理结果参考
Atlas 800I A2 (8*64G) 64核(arm) 性能数据
欢迎体验
教程中提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License。
如您在使用该模型的过程中,发现任何问题(包括但不限于功能问题、合规问题),可以在魔乐社区模型讨论区留言。