模型推理
本章节通过一个简单的示例,介绍在Atlas 800I A2 推理服务器上,如何使用MindIE SD进行文生视频。
- 使用以下命令在任意路径(例如:/home/{用户名}/code)下载模型仓库。
git clone https://modelers.cn/MindIE/Wan2.1.git
- 使用以下命令进入Wan2.1文件夹并安装所需依赖。
cd Wan2.1 pip install -r requirements.txt
- 进行模型推理。(请选择实际下载使用的模型)
- Wan2.1-T2V-14B模型使用8卡推理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
model_base="/home/{用户名}/example/Wan2.1-T2V-14B" torchrun --nproc_per_node=8 generate.py \ --task t2v-14B \ --size 1280*720 \ --ckpt_dir ${model_base} \ --dit_fsdp \ --t5_fsdp \ --sample_steps 50 \ --ulysses_size 8 \ --vae_parallel \ --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \ --use_attentioncache \ --start_step 20 \ --attentioncache_interval 2 \ --end_step 47
- Wan2.1-I2V-14B-480P模型使用8卡推理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
model_base="/home/{用户名}/example/Wan2.1-I2V-14B-480P/" torchrun --nproc_per_node=8 generate.py \ --task i2v-14B \ --size 832*480 \ --ckpt_dir ${model_base} \ --frame_num 81 \ --sample_steps 40 \ --dit_fsdp \ --t5_fsdp \ --cfg_size 1 \ --ulysses_size 8 \ --vae_parallel \ --image examples/i2v_input.JPG \ --base_seed 0 \ --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_attentioncache \ --start_step 12 \ --attentioncache_interval 4 \ --end_step 37
- Wan2.1-I2V-14B-720P模型使用8卡推理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
model_base="/home/{用户名}/example/Wan2.1-I2V-14B-720P/" torchrun --nproc_per_node=8 generate.py \ --task i2v-14B \ --size 1280*720 \ --ckpt_dir ${model_base} \ --frame_num 81 \ --sample_steps 40 \ --dit_fsdp \ --t5_fsdp \ --cfg_size 1 \ --ulysses_size 8 \ --vae_parallel \ --image examples/i2v_input.JPG \ --base_seed 0 \ --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_attentioncache \ --start_step 12 \ --attentioncache_interval 4 \ --end_step 37
表1 参数解释 参数名
参数含义
取值
model_base
权重路径
模型权重所在路径。
task
任务类型
支持“t2v-14B”和“i2v-14B”。
size
视频分辨率
生成视频的宽*高。
- “t2v-14B”模型默认值为1280*720
- “i2v-14B-480P”模型默认值为[832,480]、[720,480]
- “i2v-14B-720P”模型默认值为[1280,720]
frame_num
生成视频的帧数
默认值:81
sample_steps
采样步数
扩散模型的迭代降噪步数。
- t2v模型默认值:50
- i2v模型默认值:40
prompt
文本提示词
用户自定义,用于控制视频生成。
image
用于生成视频的图片路径
i2v模型推理必须,用户自定义,用于控制视频生成。
base_seed
随机种子
用于视频生成的随机种子。
use_attentioncache
使能attentioncache算法优化
此优化为有损优化,如需要开启此优化,请设置如下参数:start_step、attentioncache_interval、end_step,分别表示cache开始的step、连续cache数、cache结束的step;如不开启,则无需设置use_attentioncache、start_step、attentioncache_interval、end_step。
nproc_per_node
并行卡数
- Wan2.1-T2V-14B支持的卡数为1、2、4或8
- Wan2.1-I2V-14B支持的卡数为1、2、4或8
ulysses_size
ulysses并行数
默认值为1,ulysses_size * cfg_size = nproc_per_node。
cfg_size
cfg并行数
默认值为1,ulysses_size * cfg_size = nproc_per_node。
dit_fsdp
DiT使用FSDP
DiT模型是否使用完全分片数据并行(Fully Sharded Data Parallel,FSDP)策略。
t5_fsdp
T5使用FSDP
文本到文本传输转换(Text-To-Text Transfer Transformer,T5)模型是否使用FSDP策略。
vae_parallel:
使能vae并行策略
vae模型是否使用并行策略。
- Wan2.1-T2V-14B模型使用8卡推理