Ascend-SACT/MOVA-720p
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MOVA昇腾精度、性能调优

快速开始

参考:https://ai.gitcode.com/Ascend-SACT/MOVA-X86-pytorch 部署环境

推理精度调优

1、随机数固定

gpu保存随机数,代码位置:mova/diffusion/pipelines/pipeline_mova.py 399行

        torch.save(latents.to("cpu"), "/home/MOVA/output/latents.pt")

将该pt文件传到npu环境,在mova/diffusion/pipelines/pipeline_mova.py 389行加载

        latents = torch.load("/home/MOVA/gpu-pre/latents.pt", weights_only=False, map_location='cpu').to("npu")

同时gpu也在mova/diffusion/pipelines/pipeline_mova.py 399行加载该文件;注释 torch.save操作

        latents = torch.load("/home/MOVA/gpu-pre/latents.pt", weights_only=False, map_location='cpu').to("cuda")

2、算子替换

修改npu,mova/utils/adapter.py

def apply_rotary_pos_emb_adapter(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
      return _apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim)

推理性能优化

单机、多机场景

1、安装mindiesd

whl包下载链接:http://gitcode.com/Ascend/MindIE-SD/releases?presetConfig={%22tags%22:3,%22release%22:2}

pip install mindiesd-*.whl

2、下载mova npu调优代码

git clone https://atomgit.com/Ascend-SACT/MOVA-720p.git
cd MOVA-720p
git checkout ascend_910B

3、量化

1)下载量化工具

git clone https://gitcode.com/Ascend/msmodelslim.git
cd msmodelslim
bash install.sh

2)下载wan2.2量化脚本

git clone https://modelers.cn/MindIE/Wan2.2
  1. 修改quant_wan22.py脚本
        quant_dit_model(
            model_path=args.ckpt_dir, 
            subfolder="video_dit",
            dtype=config.param_dtype,
            save_path=args.quant_dit_path,
            disable_name_list=disable_name_list
        )
        quant_dit_model(
            model_path=args.ckpt_dir,
            subfolder="video_dit_2",
            dtype=config.param_dtype,
            save_path=args.quant_dit_path,
            disable_name_list=disable_name_list
        )

4)执行量化命令

python quant_wan22.py --task i2v-A14B --ckpt_dir /root/work/filestorage/gh/ckpts/MOVA-720p-test --quant_dit_path ./quant_w8a8_dynamic --quant_type W8A8 --is_dynamic

优化特性

使用npu亲和融合算子

RMSNorm、layernorm_scale_shift、rope

使用LA和稀疏FA替换传统FA算子

支持w8a8量化

并行策略优化单机U4R2改为U8R1

支持多机推理

视频高噪声->低噪声权重同时加载到npu避免推理中间offload到cpu耗时长的问题