文件最后提交记录最后更新时间
[docs] fix bug about multimodal_sd example Co-authored-by: caishengcheng<caishengcheng@huawei.com> # message auto-generated for no-merge-commit merge: !422 merge docs into master [docs] fix bug about multimodal_sd example Created-by: caishengcheng Commit-by: caishengcheng Merged-by: ascend-robot Description: 感谢您贡献的Pull Request! 在提交之前,请务必阅读 [CONTRIBUTING.md](https://gitcode.com/Ascend/msmodelslim/blob/master/CONTRIBUTING.md)。 Thanks for sending a pull request! BEFORE SUBMITTING, PLEASE READ [CONTRIBUTING.md](https://gitcode.com/Ascend/msmodelslim/blob/master/CONTRIBUTING.md). ## PR描述 (What this PR does / why we need it?) 因为多模态生成模型一键量化适配了quant_type参数,同步修改example相关描述 See merge request: Ascend/msmodelslim!4229 天前
README.md

Wan2.2 量化使用说明

Wan2.2 模型介绍

Wan2.2 是阿里巴巴在 Wan 系列上的新一代开源视频基础模型,面向更高质量、更可控的影视级视频生成;在 Wan2.1 的基础上进一步扩充训练数据与能力,并引入面向视频扩散的混合专家(MoE)等设计,在保持开放生态的同时提升生成效率与观感。支持文本到视频(T2V)、图像到视频(I2V)以及文本+图像到视频(TI2V) 等多种模式。

使用前准备

支持的模型版本与量化策略

模型系列 模型版本 模型仓库链接 W8A8 W8A16 W4A16 W4A4 时间步量化 FA3量化 异常值抑制量化 量化命令
Wan2.2 Wan2.2-T2V-A14B Wan2.2-T2V-A14B FA3+W8A8动态量化
Wan2.2-I2V-A14B Wan2.2-I2V-A14B FA3+W8A8动态量化
Wan2.2-TI2V-5B Wan2.2-TI2V-5B FA3+W8A8动态量化

说明:

  • ✅ 表示该量化策略已通过msModelSlim官方验证,功能完整、性能稳定,建议优先采用。
  • 空格表示该量化策略暂未通过msModelSlim官方验证,用户可根据实际需求进行配置尝试,但量化效果和功能稳定性无法得到官方保证。
  • 点击量化命令列中的链接可跳转到对应的具体量化命令
  • 注意执行量化需要在模型文件路径下

Wan2.2 量化支持

Wan2.2模型基于Transformer架构,msmodelslim支持对其中Transformer部分进行量化,并支持逐层量化,能够显著降低量化过程中的内存占用。

量化特性

  • 逐层量化: 支持逐层处理,大幅降低内存占用
  • 单卡量化: 结合逐层量化特性,可实现在Atlas 800I/800T A2(64G)设备上的单卡量化

量化命令

Wan2.2-T2V-A14B FA3+W8A8动态量化

使用quant_type参数进行一键量化

W8A8(MXFP8)+FA3(FP8动态)

msmodelslim quant \
    --model_path /path/to/wan2_2_t2v_float_weights \
    --save_path /path/to/wan2_2_t2v_quantized_weights \
    --device npu \
    --model_type Wan2.2-T2V-A14B \
    --quant_type w8a8f8 \
    --trust_remote_code True

Wan2.2-I2V-A14B FA3+W8A8动态量化

使用quant_type参数进行一键量化

W8A8(MXFP8)+FA3(FP8动态)

msmodelslim quant \
    --model_path /path/to/wan2_2_i2v_float_weights \
    --save_path /path/to/wan2_2_i2v_quantized_weights \
    --device npu \
    --model_type Wan2.2-I2V-A14B \
    --quant_type w8a8f8 \
    --trust_remote_code True

Wan2.2-TI2V-5B FA3+W8A8动态量化

使用quant_type参数进行一键量化

W8A8(MXFP8)+FA3(FP8动态)

msmodelslim quant \
    --model_path /path/to/wan2_2_ti2v_float_weights \
    --save_path /path/to/wan2_2_ti2v_quantized_weights \
    --device npu \
    --model_type Wan2.2-TI2V-5B \
    --quant_type w8a8f8 \
    --trust_remote_code True

配置文件说明

基础配置结构

apiversion: multimodal_sd_modelslim_v1

spec:
  process:
    - type: "linear_quant"
      qconfig:
        act:
          scope: "per_block"
          dtype: "mxfp8"
          symmetric: True
          method: "minmax"
        weight:
          scope: "per_block"
          dtype: "mxfp8"
          symmetric: True
          method: "minmax"
      include:
        - "*"
    - type: "online_quarot"
      include: 
        - "*.self_attn.*"
    - type: "fa3_quant"
      qconfig:
        dtype: "fp8_e4m3"
        scope: "per_token"
        symmetric: True
        method: "minmax"
      include:
        - "*self_attn"
  save:
    - type: "mindie_format_saver"
      part_file_size: 0

  # 基础配置
  multimodal_sd_config:
    dump_config:
      capture_mode: "args"
      dump_data_dir: ""  # default is save_path
    model_config:
      prompt: "A stylish woman walks down a Tokyo street filled with warm glowing neon and animated city signage. She wears a black leather jacket, a long red dress, and black boots, and carries a black purse. She wears sunglasses and red lipstick. She walks confidently and casually. The street is damp and reflective, creating a mirror effect of the colorful lights. Many pedestrians walk about."
      # 模型加载参数
      convert_model_dtype: True
      task: "t2v-A14B"

关键配置参数

量化配置 (process)

  • type: 处理器类型,固定为"linear_quant"
  • qconfig.act: 激活值量化配置
    • scope: 量化范围,mxfp8配合使用"per_block"
    • dtype: 数据类型
    • symmetric: 是否对称量化,推荐True
    • method: 量化方法,推荐"minmax"
  • qconfig.weight: 权重量化配置
    • scope: 量化范围,mxfp8配合使用"per_block"
    • dtype: 数据类型
    • symmetric: 是否对称量化,推荐True
    • method: 量化方法,推荐"minmax"

保存配置 (save)

  • type: 保存器类型,使用"mindie_format_saver"
  • part_file_size: 分片文件大小,0表示不分片

多模态配置 (multimodal_sd_config)

  • dump_config: 校准数据捕获配置

    • capture_mode: 捕获模式,当前仅支持配置为"args"
    • dump_data_dir: 校准数据保存目录,配置为空字符串时会自动转换为使用量化权重保存路径
  • model_config: 模型加载与推理配置,具体可配置的参数需要参考原始推理工程仓Wan2.2模型仓库

    字段名 作用 说明 可选值
    prompt 校准提示词 用于生成校准数据的文本描述 字符串
    offload_model 模型卸载 是否在推理后卸载模型到CPU,值为True时开启 True/False
    frame_num 生成帧数 视频生成的帧数 大于0的整数
    task 任务类型 指定模型任务类型,"t2v-A14B"表示文本生成视频任务、"i2v-A14B"表示图像生成视频任务,"ti2v-5B"表示文本+图像生成视频任务 "t2v-A14B", "i2v-A14B", "ti2v-5B"
    size 生成尺寸 视频或图像的尺寸规格 参考Wan2.2模型仓库配置
    sample_steps 采样步数 扩散模型的采样步数 大于0的整数

FAQ

现象:如何自定义量化配置?
解决方案:可以修改配置文件中的process部分,调整量化参数和层选择策略。

附录

相关资源