Ascend-SACT/Wan2.2-5B-TI2V-ARM-MindIE
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

介绍

本文档介绍在ARM服务器的容器环境下,基于MindIE推理引擎进行Wan2.2 5B TI2V模型推理的方法。

一、Wan2.2 5B TI2V模型介绍

Wan2.2 5B TI2V是由阿里开源的视频生成模型。该模型支持720P分辨率、24fps的文本到视频以及图像到视频生成。支持通过文本输入,或文本与图片结合的输入方式来生成视频。

二、宿主机环境准备

1、配置硬件环境

  1. 请参考以下链接安装CANN组件。 https://vllm-ascend.readthedocs.io/zh-cn/latest/installation.html

三、容器化安装部署

2.1 拉取MindIE镜像

在宿主机上登录后,执行以下指令拉取MindIE镜像(以下为openEuler+python3.11的镜像包,该镜像包已内置CANN、torch、torch_npu、python等基础环境)。 docker pull swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie: 2.1.RC1-800I-A2-py311-openeuler24.03-lts

2.2 创建容器

在宿主机上通过bash运行以下指令创建容器 docker run -itd -u 0 --ipc=host --network host --privileged
-e PYTORCH_NPU_ALLOC_CONF=max_split_size_mb:256
-e ASCEND_RT_VISIBLE_DEVICES=0
--name mindie_wan2_2
--device=/dev/davinci5
--device /dev/davinci_manager
--device /dev/devmm_svm
--device /dev/hisi_hdc
-v /usr/local/dcmi:/usr/local/dcmi
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info
-v /etc/ascend_install.info:/etc/ascend_install.info
-v /home/model:/model
-v /home/Wan2.2:/home
-w /home
-p 8090:8090
-it swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:2.1.RC1-800I-A2-py311-openeuler24.03-lts bash 参数说明: • name: 容器名称 • device=/dev/davinci5:所使用的NPU(编号从0到7),示例中使用5号NPU • -v /home/model:/model 将模型目录挂载为/model • -v /home/Wan2.2:/home 将容器工作目录挂载为/home • swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:2.1.RC1-800I-A2-py311-openeuler24.03-lts 容器镜像名称

3、配置pip源

如果使用pip安装软件时出现下载问题,可以执行以下两条命令,将pip源更换为中国科学技术大学的源。科大pip源在国内使用更为稳定(推荐国内用户使用),默认的github源从国内访问基本都会失败。 pip config list pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

四、模型下载及依赖包安装

1、进入容器

执行以下指令进入docker容器,后续所有操作步骤均在vllm-ascend-tangyun用户下进行: docker exec -it mindie_wan2_2 bash

2、下载模型权重

在魔乐社区找到对应模型的链接(https://modelers.cn/models/Modelers_Park/Wan2.2-TI2V-5B)。 在/home目录下新建一个目录,用于存放模型文件: mkdir /home/model/ cd /home/model/ 执行以下命令下载完整模型库: git clone https://modelers.cn/Modelers_Park/Wan2.2-TI2V-5B.git

3、下载requirements.txt

打开魔乐社区如下链接:https://modelers.cn/models/MindIE/Wan2.2/blob/main/,下载requirements.txt文件。 注意: 1、昇腾上需要将flash_attn替换为yunchang。 2、torch版本改为2.1.0。 torch==2.1.0 torchvision>=0.16.0 opencv-python>=4.9.0.80 diffusers>=0.31.0 transformers==4.54.1 tokenizers>=0.20.3 accelerate==1.9.0 tqdm imageio[ffmpeg] easydict ftfy dashscope imageio-ffmpeg numpy>=1.23.5,<2 yunchang="=0.6.0"

4、安装依赖包

在容器的home目录下执行如下指令安装依赖包: pip install -r requirements.txt

安装最后一个依赖包yunchang时可能会出现错误,无法下载,可以执行下面命令更换pip源为阿里云: pip config set global.index-url https://mirrors.aliyun.com/pypi/simple pip config set install.trusted-host mirrors.aliyun.com 单独执行安装命令: pip install yunchang

5、下载模型推理脚本

执行指令: cd /home/Wan2.2 git clone https://modelers.cn/MindIE/Wan2.2.git

五、模型推理

1、设置环境变量

在容器中执行命令设置环境变量: 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" 参数说明: • ALGO: 为0表示默认FA算子;设置为1表示使用高性能FA算子

2、拉起推理服务

文本到视频推理: python generate.py
--task ti2v-5B
--ckpt_dir /model/Wan2.2-TI2V-5B/
--size 1280*704
--prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage"

图片到视频推理: python generate.py
--task ti2v-5B
--ckpt_dir /model/Wan2.2-TI2V-5B/
--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 参数说明: • task: 任务类型。 • ckpt_dir: 模型的权重路径 • size: 生成视频的分辨率,支持(1280,720)、(832,480)分辨率 • frame_num: 生成视频的帧数 • sample_steps: 推理步数 • image: 输入图片路径 • prompt: 文本提示词 • base_seed: 随机种子

命令执行后会打印如下日志表示成功: [2025-09-04 10:02:24,588] INFO: loading /model/Wan2.2-TI2V-5B/models_t5_umt5-xxl-enc-bf16.pth [2025-09-04 10:02:34,400] INFO: loading /model/Wan2.2-TI2V-5B/Wan2.2_VAE.pth [2025-09-04 10:02:36,660] INFO: Creating WanModel from /model/Wan2.2-TI2V-5B/ Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 14.24it/s] [2025-09-04 10:02:38,202] INFO: Warm up 2 steps ... 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:29<00:00, 14.91s/it] [2025-09-04 10:03:40,395] INFO: Generating video ... 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [12:00<00:00, 14.40s/it] [2025-09-04 10:16:15,615] INFO: Generating video used time 755.2163s [2025-09-04 10:16:15,616] INFO: Saving generated video to ti2v-5B_1280704_1_1_1_1_Two_anthropomorphic_cats_in_comfy_boxing_gear_and__20250904_101615.mp4 [2025-09-04 10:16:18,328] INFO: Finished. 生成的视频文件在容器工作目录下: -rw-r-----. 1 root root 12175313 Sep 4 10:16 'ti2v-5B_1280704_1_1_1_1_Two_anthropomorphic_cats_in_comfy_boxing_gear_and__20250904_101615.mp4'

六、模型量化

1、 下载&安装量化工具

执行如下命令下载量化工具: git clone https://gitee.com/ascend/msit.git 进入到msit/msmodelslim的目录: cd msit/msmodelslim 在进入的msmodelslim目录下,运行安装脚本: bash install.sh

2、模型量化

进入到推理脚本所在的目录(目录见1.2.1章节): cd /inspire/sj-ssd/project/pretrain-test/tangyun-W25097/infer/Wan2.2 修改推理脚本修复一个bug,在generate.py的513行下面增加如下标红语句: elif "ti2v" in args.task: logging.info("Creating WanTI2V pipeline.") wan_ti2v = wan.WanTI2V( config="cfg," checkpoint_dir="args.ckpt_dir," quant_data_dir="args.quant_data_dir," device_id="device," rank="rank," t5_fsdp="args.t5_fsdp," dit_fsdp="args.dit_fsdp," use_sp="(args.ulysses_size" > 1), t5_cpu=args.t5_cpu, convert_model_dtype=args.convert_model_dtype, use_vae_parallel=args.vae_parallel, quant_mode=args.quant_mode )

执行如下命令,进行模型量化: python generate.py
--task ti2v-5B
--ckpt_dir /inspire/sj-ssd/project/pretrain-test/public/workspace/models/Wan2.2-TI2V-5B
--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
--quant_mode 2
--quant_data_dir "./output/quant_data" 执行完,会在当前目录下生成一个output/quant_data/ti2v_quant_weights_anti目录: [root:ti2v_quant_weights_anti]pwd/inspire/sj−ssd/project/pretrain−test/tangyun−W25097/infer/wan−infer−quant/Wan2.2/output/quantdata/ti2vquantweightsanti[root:ti2vquantweightsanti] pwd /inspire/sj-ssd/project/pretrain-test/tangyun-W25097/infer/wan-infer-quant/Wan2.2/output/quant_data/ti2v_quant_weights_anti [root:ti2v_quant_weights_anti]pwd/inspire/sj−ssd/project/pretrain−test/tangyun−W25097/infer/wan−infer−quant/Wan2.2/output/quantd​ata/ti2vq​uantw​eightsa​nti[root:ti2vq​uantw​eightsa​nti] ll total 4903552 -rw------- 1 root root 69926 9月 15 18:37 quant_model_description_w8a8_dynamic.json -r-------- 1 root root 5021008816 9月 15 18:37 quant_model_weight_w8a8_dynamic.safetensors