表 1 版本配套表
| 配套 | 版本 | 环境准备指导 |
|---|---|---|
| Python | 3.11.10 | - |
| torch | 2.9.0 | - |
注意:
# 增加软件包可执行权限,{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
source /usr/local/Ascend/nnal/atb/set_env.sh# 增加软件包可执行权限,{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请从昇腾社区资源下载中心下载与当前PyTorch版本、Python版本和CPU架构匹配的pytorch_v{pytorchversion}_py{pythonversion}.tar.gz软件包。Torch_npu版本配套关系可参考Ascend Extension for PyTorch。
安装前可通过以下命令确认Python版本和CPU架构:
python3 --version
uname -m解压并安装Torch_npu:
tar -xzvf pytorch_v{pytorchversion}_py{pythonversion}.tar.gz
# 解压后,先确认whl包的实际文件名
find . -name "*.whl"
# 安装Torch_npu依赖
pip install pyyaml setuptools
# 安装与当前Python版本和CPU架构匹配的whl包,文件名以实际解压结果为准
pip install torch_npu-{pytorchversion}.xxxx.{arch}.whl安装完成后执行验证:
python3 -c "import torch; import torch_npu; print('torch:', torch.__version__); print('torch_npu:', torch_npu.__version__); print('NPU available:', torch.npu.is_available())"# 若环境镜像中没有gcc、g++,请用户自行安装
yum install gcc
yum install g++
# 导入头文件路径
export CPLUS_INCLUDE_PATH=/usr/include/c++/12/:/usr/include/c++/12/aarch64-openEuler-linux/:$CPLUS_INCLUDE_PATH注:若使用openeuler镜像,需要配置gcc、g++环境,否则会导致fatal error: 'stdio.h' file not found
| 模型 | 链接 |
|---|---|
| Wan2.2-T2V-A14B | 🤗huggingface |
| Wan2.2-I2V-A14B | 🤗huggingface |
| Wan2.2-TI2V-5B | 🤗huggingface |
| 模型 | 支持分辨率 |
|---|---|
| Wan2.2-T2V-A14B | 720*1280, 1280*720, 480*832, 832*480 |
| Wan2.2-I2V-A14B | 720*1280, 1280*720, 480*832, 832*480 |
| Wan2.2-TI2V-5B | 704*1280, 1280*704 |
ALGO用于选择FA计算方式,请在执行python或torchrun命令前根据设备及推理方式进行配置:
| 场景 | ALGO配置 |
|---|---|
| 昇腾Ascend 950设备浮点推理 | export ALGO=0 |
| A2、A3设备浮点推理 | export ALGO=1 |
| 仅使能W8A8/W4A4 MXFP8量化 | export ALGO=0 |
| 使能W8A8/W4A4 MXFP8 + attention FP8量化 | export ALGO=3 |
切换设备或量化方式后,请重新确认ALGO配置。
在Ascend 950设备上设置ALGO=3后,可通过环境变量单独控制T2V Self Attention的Dense FA量化格式,不要求量化DiT权重或传入quant_dit_path。
| 环境变量 | 可选值 | 说明 |
|---|---|---|
FA_PRECISION | fp8、mxfp8、mxfp4 | 设置Dense FA量化格式;不设置时使用checkpoint注入的FA模块或浮点FA |
FA_FP8_MODE | HIGH_PRECISION、C8V16_TILING512 | 仅在FA_PRECISION=fp8时生效;不设置时使用MindIE-SD默认模式 |
以FP8 C8V16模式为例:
export ALGO=3
export FA_PRECISION=fp8
export FA_FP8_MODE=C8V16_TILING512使用RainFusion v3时,Dense阶段由FA_PRECISION控制,Sparse阶段由rainfusion_precision控制。
若推理过程中出现OOM、HCCL端口占用、AOE目录不存在或torchvision版本冲突等问题,请参考九、常见问题。
git clone https://modelers.cn/MindIE/Wan2.2.git
cd Wan2.2
pip3 install -r requirements.txt使用上一步下载的权重
model_base="./Wan2.2-T2V-A14B/"执行命令:
export ALGO=1
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
python generate.py \
--task t2v-A14B \
--ckpt_dir ${model_base} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--offload_model False \
--base_seed 0 参数说明:
执行命令:
export ALGO=1
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
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 2 \
--ulysses_size 4 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--base_seed 0
参数说明:
推荐配置:
torchrun --nproc_per_node=16 generate.py \
--cfg_size 2 \
--ulysses_size 8 \执行命令:
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
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 2 \
--ulysses_size 4 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--use_rainfusion \
--rainfusion_type "v2" \
--sparsity 0.8 \
--sparse_start_step 15 \
--base_seed 0参数说明:
Ascend 950PR使用v3。默认为'v2', 'v1'将不再维护。RainFusion v3将Self Attention分为Dense和Sparse两个阶段,两者的精度分别配置:
ALGO、FA_PRECISION和FA_FP8_MODE控制。rainfusion_precision控制,通过EagleQBSA执行块稀疏Attention。本节示例使用Dense BF16和Sparse mix:前置Dense步骤执行BF16 FA,进入Sparse阶段后,Q/K按块量化为INT8,V量化为FP8。该功能当前仅支持Ascend 950设备,并要求rainfusion_type=v3。
如需组合Dense FP8 C8V16和Sparse mix,可将示例中的ALGO=0替换为独立配置FA量化格式中的三个环境变量;rainfusion_precision=mix保持不变。
执行命令:
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
export FAST_LAYERNORM=1
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 2 \
--ulysses_size 4 \
--ring_size 1 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--use_rainfusion \
--rainfusion_type "v3" \
--rainfusion_precision "mix" \
--sparsity 0.8 \
--sparse_start_step 15 \
--mask_refresh_interval 1 \
--base_seed 0参数说明:
rainfusion_precision设置Sparse阶段的计算精度:
| 取值 | Sparse阶段的数据格式 |
|---|---|
bf16 | Q/K/V使用BF16 |
mix | Q/K按块量化为INT8,V量化为FP8 |
fp8 | Q/K/V使用FP8量化BSA |
mxfp4 | 使用FP4 E2M1数据和E8M0微缩放 |
不设置rainfusion_precision时,依次读取BSA_PRECISION环境变量和量化资产;量化资产包含q_rot/k_rot时推导为fp8,否则使用bf16。Sparse阶段暂不支持mxfp8。
use_rainfusion:启用稀疏FA。rainfusion_type:设置为v3,使用Ascend 950上的RFv3/EagleQBSA路径。sparsity:稀疏度,合法范围为[0, 1)。数值越大,保留的Attention块越少。设置为0时保留全部块,但仍执行所选精度的BSA算子。sparse_start_step:进入Sparse阶段前保留的Dense timestep数量。RFv3当前至少保留前8个timestep为Dense,block 0及索引为38、39的timestep也使用Dense FA。mask_refresh_interval:每隔多少个Sparse timestep重新计算一次块稀疏mask;设置为0表示首次生成后持续复用。ring_size:RFv3/EagleQBSA当前仅支持设置为1,并会关闭Quant All-to-All和All-to-All overlap路径。mxfp4的量程由BSA_MXFP4_DST_TYPE_MAX控制:默认值7.25使用CX档,设置为0时使用OCP档。BSA_MXFP4_SCALE_ALG可进一步指定缩放算法。
使用上一步下载的权重
model_base="./Wan2.2-I2V-A14B/"执行命令:
export ALGO=1
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
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 2 \
--ulysses_size 4 \
--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参数说明:
推荐配置:
torchrun --nproc_per_node=16 generate.py \
--cfg_size 2 \
--ulysses_size 8 \执行命令:
export ALGO=1
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
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 2 \
--ulysses_size 4 \
--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." \
--use_rainfusion \
--rainfusion_type "v2" \
--sparsity 0.8 \
--sparse_start_step 15 \
--base_seed 0参数说明:
I2V的Dense/Sparse阶段划分、精度配置和参数含义与3.3.3 RFv3稀疏量化FA一致。以下示例同样使用Dense BF16和Sparse mix。
执行命令:
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
export FAST_LAYERNORM=1
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 2 \
--ulysses_size 4 \
--ring_size 1 \
--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." \
--use_rainfusion \
--rainfusion_type "v3" \
--rainfusion_precision "mix" \
--sparsity 0.8 \
--sparse_start_step 15 \
--mask_refresh_interval 1 \
--base_seed 0参数说明:
rainfusion_type=v3:启用Ascend 950上的RFv3/EagleQBSA路径。rainfusion_precision=mix:Sparse阶段使用Q/K INT8和V FP8混合量化。使用上一步下载的权重
model_base="./Wan2.2-TI2V-5B/"执行命令:
export ALGO=1
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
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." \
--offload_model False \
--base_seed 0 参数说明:
执行命令:
export ALGO=1
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 2 \
--ulysses_size 4 \
--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参数说明:
推荐配置:
torchrun --nproc_per_node=16 generate.py \
--cfg_size 2 \
--ulysses_size 8 \推荐配置:
--use_attentioncache \
--start_step 20 \
--attentioncache_interval 2 \
--end_step 47参数说明:
MagCache 通过动态计算不同网络层之间的特征幅度差异来决定是否跳过 Transformer block,可以在保证生成质量的前提下显著加速视频生成任务(支持 t2v、ti2v 和 i2v)。该特性已直接集成进 generate.py。
参数说明:
通过动态将 DiT 的 Block 权重卸载到 CPU 并在需要时异步取回,极大降低模型推理期间对 NPU 显存的峰值占用。可配合单卡或多卡测试使用(不支持与 FSDP 联合使用)。
推荐配置:
--async_offload \
--min_reserved_blocks_count 2 \
--offload_model False 参数说明:
新增Wan2.2-T2V、Wan2.2-I2V、Wan2.2-TI2V的W8A8 量化支持,针对DiT模型进行量化,降低显存占用,提高模型推理性能
下载并安装msmodelslim工具
# 1. git clone msmodelslim 代码
git clone https://gitcode.com/Ascend/msmodelslim.git
# 2. 进入到 msmodelslim 的目录并运行安装脚本
cd msmodelslim
bash install.sh以Wan2.2-T2V-A14B模型为例,导出DiT的W8A8 MXFP8量化权重及描述文件
cd /path/to/msmodelslim
# 设置权重路径
model_base="./Wan2.2-T2V-A14B/"
# 设置权重保存路径
save_path="./quant_w8a8_mxfp8"
msmodelslim quant \
--model_path ${model_base} \
--save_path ${save_path} \
--device npu \
--model_type Wan2.2 \
--trust_remote_code True \
--config_path ./lab_practice/wan2_2/wan2_2_w8a8f8_mxfp_t2v.yaml参数说明:
执行后,"./quant_w8a8_mxfp8"目录下会生成两个文件夹:
t2v_high_noise_model
quant_model_description_w8a8_mxfp8.json:量化配置描述文件quant_model_weight_w8a8_mxfp8.safetensors:量化后的权重文件t2v_low_noise_model
quant_model_description_w8a8_mxfp8.json:量化配置描述文件quant_model_weight_w8a8_mxfp8.safetensors:量化后的权重文件按照模型导入路径修改文件夹命名:
cd ./quant_w8a8_mxfp8
mv t2v_high_noise_model high_noise_model
mv t2v_low_noise_model low_noise_model以Wan2.2-T2V-A14B模型为例,执行量化推理
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
export FAST_LAYERNORM=1
model_base="./Wan2.2-T2V-A14B/"
quant_dit_path="./quant_w8a8_mxfp8/"
torchrun --nproc_per_node=8 --master_port=23459 generate.py \
--task t2v-A14B \
--ckpt_dir ${model_base} \
--quant_dit_path ${quant_dit_path} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--cfg_size 2 \
--ulysses_size 4 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--base_seed 0以Wan2.2-T2V-A14B模型为例,执行量化推理
export ALGO=3
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
model_base="./Wan2.2-T2V-A14B/"
quant_dit_path="./quant_w8a8_mxfp8/"
torchrun --nproc_per_node=8 --master_port=23459 generate.py \
--task t2v-A14B \
--ckpt_dir ${model_base} \
--quant_dit_path ${quant_dit_path} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--cfg_size 2 \
--ulysses_size 4 \
--vae_parallel \
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \
--base_seed 0参数说明:
新增Wan2.2-T2V、Wan2.2-I2V、Wan2.2-TI2V的W4A4量化支持,针对DiT模型进行量化,降低显存占用,提高模型推理性能
量化模型使用 CPU offload 或 DiT FSDP 时若出现内部格式转换、拷贝错误,请参见九、常见问题第 7 条。
下载并安装msmodelslim工具
# 1. git clone msmodelslim 代码
git clone https://gitcode.com/Ascend/msmodelslim.git
# 2. 进入到 msmodelslim 的目录并运行安装脚本
cd msmodelslim
bash install.sh以Wan2.2-I2V-A14B模型为例,导出DiT的W4A4 MXFP8量化权重及描述文件
cd /path/to/msmodelslim
# 设置权重路径
model_base="./Wan2.2-I2V-A14B/"
# 设置权重保存路径
save_path="./quant_w4a4_mxfp8"
msmodelslim quant \
--model_path ${model_base} \
--save_path ${save_path} \
--device npu \
--model_type Wan2.2 \
--trust_remote_code True \
--config_path ./lab_practice/wan2_2/wan2_2_w4a4f8_mxfp_i2v.yaml参数说明:
执行后,"./quant_w4a4_mxfp8"目录下会生成两个文件夹:
i2v_high_noise_model
quant_model_description_w4a4_mxfp8.json:量化配置描述文件quant_model_weight_w4a4_mxfp8.safetensors:量化后的权重文件i2v_low_noise_model
quant_model_description_w4a4_mxfp8.json:量化配置描述文件quant_model_weight_w4a4_mxfp8.safetensors:量化后的权重文件按照模型导入路径修改文件夹命名:
cd ./quant_w4a4_mxfp8
mv i2v_high_noise_model high_noise_model
mv i2v_low_noise_model low_noise_model以Wan2.2-I2V-A14B模型为例,执行量化推理
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
export FAST_LAYERNORM=1
model_base="./Wan2.2-I2V-A14B/"
quant_dit_path="./quant_w4a4_mxfp8/"
torchrun --nproc_per_node=8 --master_port=23458 generate.py \
--task i2v-A14B \
--ckpt_dir ${model_base} \
--quant_dit_path ${quant_dit_path} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--cfg_size 2 \
--ulysses_size 4 \
--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-I2V-A14B模型为例,执行量化推理
export ALGO=3
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
model_base="./Wan2.2-T2V-A14B/"
quant_dit_path="./quant_w4a4_mxfp8/"
torchrun --nproc_per_node=8 --master_port=23458 generate.py \
--task i2v-A14B \
--ckpt_dir ${model_base} \
--quant_dit_path ${quant_dit_path} \
--size 1280*720 \
--frame_num 81 \
--sample_steps 40 \
--cfg_size 2 \
--ulysses_size 4 \
--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参数说明:
| 模型 | 分辨率 | 帧数 | 迭代次数 | 卡数 | E2E耗时 |
|---|---|---|---|---|---|
| Wan2.2-T2V-A14B | 1280×720 | 81 | 40 | 8 | 435.99s |
| Wan2.2-I2V-A14B | 1280×720 | 81 | 40 | 8 | 436.42s |
| Wan2.2-TI2V-5B | 1280×704 | 121 | 50 | 8 | 72.21s |
VBench 1.0用于从主体一致性、背景一致性、运动平滑度、成像质量、语义一致性等维度评估视频生成质量。AISBench已适配VBench 1.0,具体说明请参考AISBench VBench 1.0使用指南。
本节以Wan2.2-T2V-A14B和VBench-1.0-mini为例,介绍评测环境安装、视频生成和评分流程。
说明:本节使用仓库根目录下的
vbench.py批量生成评测视频。该脚本基于generate.py扩展,负责读取VBench数据集中的提示词,并按照VBench要求的目录结构保存视频。
在Wan2.2仓库根目录执行:
git clone https://github.com/AISBench/benchmark.git
cd benchmark
pip install -v -e .安装VBench部分评测维度依赖的Detectron2:
pip install -e ais_bench/third_party/detectron2 --no-build-isolation
cd ..x86_64环境可直接安装:
pip install decordARM环境如果没有匹配的预编译包,可通过源码安装:
git clone https://github.com/dmlc/decord.git
cd decord
mkdir build
cd build
cmake .. -DUSE_CUDA=0 -DCMAKE_BUILD_TYPE=Release
make -j
cd ../python
python3 setup.py install --user
cd ../..如果编译过程中提示无法找到FFmpeg,可安装FFmpeg后重新编译:
conda install -c conda-forge ffmpeg=4.4.2如果安装过程中出现依赖版本兼容问题,可尝试使用以下已验证版本:
pip install "setuptools<=82.0.0" "timm==0.9.8"VBench在评测不同维度时需要加载多个辅助模型权重及相关资源文件。为避免评测过程中因网络问题导致文件下载失败,建议提前将这些文件下载到本地。所需文件及缓存说明请参考VBench缓存资源说明。
以下命令将评测所需的权重和资源下载到Wan2.2仓库根目录下的vbench_cache:
cd benchmark
export VBENCH_CACHE_DIR="../vbench_cache"
bash ais_bench/configs/vbench_examples/download_vbench_cache.sh
cd ..后续执行评测时,需要将VBENCH_CACHE_DIR指向同一缓存目录:
export VBENCH_CACHE_DIR="./vbench_cache"VBench支持以下两种评测方式:
建议首先使用VBench-1.0-mini验证完整流程。该数据集是从VBench 1.0标准数据集中采样得到的精简版本。
在Wan2.2仓库根目录执行:
git clone https://modelers.cn/AISBench/VBench-1.0-mini.git下载完成后,确认数据集目录中包含批量生成和评测所需的元数据文件,例如:
VBench-1.0-mini/
├── VBench_kmeans_info.json
└── VBench_full_info.json其中:
VBench_kmeans_info.json用于vbench.py读取提示词并生成视频。VBench_full_info.json用于AISBench Standard模式匹配提示词和评测维度。具体文件名请以下载的数据集实际内容为准,并相应修改后续命令中的路径。
执行批量生成前,根据设备类型配置ALGO,具体配置规则请参考3.1 开始前必读。
以下命令以4卡推理为例:
export ALGO=1
export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True'
export TASK_QUEUE_ENABLE=2
export CPU_AFFINITY_CONF=1
export TOKENIZERS_PARALLELISM=false
export FAST_LAYERNORM=1
model_base="./Wan2.2-T2V-A14B/"
vbench_dataset="./VBench-1.0-mini"
vbench_output="./results_vbench"
torchrun --nproc_per_node=4 --master_port=23459 vbench.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 2 \
--vae_parallel \
--base_seed 0 \
--vbench_mini \
--vbench_mini_root ${vbench_dataset} \
--save_path ${vbench_output} \
--num_samples 1 \
--temporal_flickering_samples 1 \
--skip_existingVBench相关参数说明:
| 参数 | 说明 |
|---|---|
--vbench_mini | 启用VBench-1.0-mini批量生成模式 |
--vbench_mini_root | VBench-1.0-mini数据集根目录 |
--save_path | 评测视频输出根目录 |
--num_samples | 除时序闪烁外,每条提示词生成的视频数量 |
--temporal_flickering_samples | 时序闪烁维度每条提示词生成的视频数量 |
--skip_existing | 输出视频已存在时跳过生成,便于中断后继续执行 |
上述命令将两个采样参数均设置为1,仅用于快速验证生成和评测流程。正式评测建议使用VBench默认采样数量:
--num_samples 5 \
--temporal_flickering_samples 25不同实验之间应保持模型权重、提示词、分辨率、帧数、推理步数、采样数量及随机种子配置一致,否则评测结果不宜直接比较。
进入AISBench目录并复制一份评测配置,避免直接修改原始示例:
cd benchmark
cp ais_bench/configs/vbench_examples/eval_vbench_standard.py \
ais_bench/configs/vbench_examples/eval_vbench_wan22.py打开eval_vbench_wan22.py,根据当前目录结构设置以下配置:
DATA_PATH = "../results_vbench"
VBENCH_CACHE_DIR = "../vbench_cache"
vbench_eval_cfg = dict(
load_ckpt_from_local=True,
full_json_dir="../VBench-1.0-mini/VBench_full_info.json",
)其中:
DATA_PATH为vbench.py生成的视频根目录。VBENCH_CACHE_DIR为第7.2节下载的评测权重及资源缓存目录。full_json_dir为当前数据集对应的VBench_full_info.json。执行评测:
ais_bench ais_bench/configs/vbench_examples/eval_vbench_wan22.py \
--mode eval \
--max-num-workers 1 \
--work_dir ../outputs/vbench_wan22可以通过增大--max-num-workers使用多个设备并行评测,但该值不应超过当前可用设备数量。
各维度评测结果默认保存在:
outputs/vbench_wan22/results/vbench_eval/Standard模式将输出各维度分数,并汇总视频质量分数、语义一致性分数和总分。
Custom模式适用于不属于VBench Standard Prompt Suite的自定义提示词和视频。首先创建视频文件与提示词的对应关系,例如:
{
"sample_000.mp4": "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage.",
"sample_001.mp4": "A lone cowboy rides his horse across an open plain at sunset."
}将该文件保存为custom_prompts.json,并将待评测视频统一放入custom_videos目录。
复制Custom模式配置:
cd benchmark
cp ais_bench/configs/vbench_examples/eval_vbench_custom.py \
ais_bench/configs/vbench_examples/eval_vbench_custom_wan22.py在复制后的配置文件中设置:
DATA_PATH为../custom_videos。prompt_file为../custom_prompts.json。VBENCH_CACHE_DIR为../vbench_cache。执行评测:
ais_bench ais_bench/configs/vbench_examples/eval_vbench_custom_wan22.py \
--mode eval \
--max-num-workers 1 \
--work_dir ../outputs/vbench_custom_wan22Custom模式支持的评测维度少于Standard模式,其结果适合自定义实验之间的对比,不应直接与Standard模式的完整评分进行比较。
Wan2.2 支持通过 --profiler-config 参数开启 NPU 性能采集,用于分析 t2v/ti2v/i2v 推理过程中的算子性能、AI Core 指标等。该功能默认关闭,开启后不影响推理结果,仅在推理外层叠加 profiler 采集。
在推理命令后追加 --profiler-config 参数即可开启采集,最简配置只需指定 "profiler": "torch":
python generate.py --task t2v-A14B --size 1280*720 ... \
--profiler-config '{"profiler": "torch"}'| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
profiler | str | 无 | 采集开关,设为 "torch" 时开启 |
torch_profiler_dir | str | ./profiling_dict | 输出目录(父路径) |
torch_profiler_activities | list | ["CPU", "NPU"] | 采集活动,可选 CPU / NPU |
torch_profiler_record_shapes | bool | true | 是否记录算子输入形状 |
torch_profiler_profile_memory | bool | false | 是否采集内存 |
torch_profiler_with_stack | bool | false | 是否记录调用栈 |
torch_profiler_with_flops | bool | false | 是否记录 FLOPs |
torch_profiler_with_modules | bool | false | 是否记录模块层级 |
torch_profiler_aic_metrics | str | PipeUtilization | AI Core 性能指标,可选 AiCoreNone / PipeUtilization / ArithmeticUtilization / Memory / MemoryL0 / MemoryUB / ResourceConflictRatio / L2Cache / MemoryAccess |
torch_profiler_level | str | Level1 | 采集等级,见 8.3 |
torch_profiler_l2_cache | bool | false | 是否采集 L2 Cache |
torch_profiler_data_simplification | bool | false | 是否开启数据精简 |
| 取值 | 说明 |
|---|---|
Level_none | 不采集所有 Level 层级控制的数据,即关闭 profiler_level |
Level0 | 采集上层应用数据、底层 NPU 数据及 NPU 上执行的算子信息(官方默认值) |
Level1 | 在 Level0 基础上多采集 CANN 层 AscendCL 数据和 AI Core 性能指标,并自动开启 aic_metrics=PipeUtilization,生成 communication.json / communication_matrix.json / api_statistic.csv |
Level2 | 在 Level1 基础上多采集 CANN 层 Runtime 数据及 AI CPU 数据(data_preprocess.csv) |
采集结果输出到 ./profiling_dict/Wan_{task}_{env}_{time}/ 目录(若指定 torch_profiler_dir 则以其为父路径)。最终 trace 文件由 tensorboard_trace_handler 在该目录下生成 {worker}_{timestamp}_ascend_pt/ 子目录,核心数据位于 ASCEND_PROFILER_OUTPUT/trace_view.json。
若出现OOM, 可添加环境变量 export T5_LOAD_CPU=1,以降低显存占用
当前仅TI2V支持attentioncache
若遇到报错: Directory operation failed. Reason: Directory [/usr/local/Ascend/mindie/latest/mindie-rt/aoe] does not exist,请设置环境变量unset TUNE_BANK_PATH
若使用openeuler镜像, 若没有配置gcc、g++环境,会遇到报错:fatal error: 'stdio.h' file not found,请参考1.5 gcc、g++安装
若循环跑纯模型推理,可能会因为HCCL端口未及时释放,导致因端口被占用而推理失败,报错:Failed to bind the IP port. Reason: The IP address and port have been bound already.
HCCL function error :HcclGetRootInfo(&hcclID), error code is 7: 请配置export HCCL_HOST_SOCKET_PORT_RANGE="auto"不指定端口
HCCL function error :HcclGetRootInfo(&hcclID), error code is 11: 请配置sysctl -w net.ipv4.ip_local_reserved_ports=60000-60015预留端口
若环境中的torch为cpu版本,安装requirement.txt时,默认会安装GPU版本的torchvision,导致版本冲突,出现类似AttributeError: partially initialized module 'torchvision' has no attribute 'extension' (most likely due to a circular import)的错误。可通过安装cpu版本的torchvision解决:pip install torchvision==0.24.0 --index-url https://download.pytorch.org/whl/cpu
量化模型开启 CPU offload 或 DiT FSDP 后出现内部格式转换、拷贝错误:
量化模型开启 CPU offload(如 --offload_model True、--async_offload 等)或 DiT FSDP(--dit_fsdp)后,可能出现以下错误:
RuntimeError: Current device only support aclnn operator, and current operator at_npu::native::NPUNativeFunctions::copy_ do not support internal format.当量化权重使用 NZ 等内部格式,而当前运行环境的相关拷贝、格式转换或分布式同步路径不支持该格式时,可能出现上述错误。已在本项目 W4A4 MXFP4 Dual-Scale 配置下观察到该问题,其加载 quant_model_description_w4a4_mxfp4_dualscale.json 的分支会设置 use_nz=True,将量化权重转换为 NZ 内部格式。其他量化配置若使用相同格式和操作路径,也可能受到影响;是否兼容需结合具体配置、运行环境和实现验证。
请根据触发场景处理:
--offload_model False、移除 --async_offload 参数。dist._broadcast_coalesced 路径触发,即使未开启 CPU offload 也可能出现。请移除 --dit_fsdp;已在上述 Dual-Scale 配置及所测环境下确认移除后可正常运行。关闭相应特性后,请确保 NPU 内存充足。