文件最后提交记录最后更新时间
【docs】:大模型检查低错修改 Co-authored-by: zzm30<zhengzhimin1@h-partners.com> # message auto-generated for no-merge-commit merge: !333 merge master into master 【docs】:大模型检查低错修改 Created-by: zzm30 Commit-by: zzm30 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?) - 请明确说明您提交PR的变更内容。本部分旨在概述所做的变更,以及此PR是如何解决该问题的。请尽可能地提供有助于评审人员更高效、更快速完成检视审查的实用说明。 - 请说明为何需要这些更改,例如具体的使用场景或bug描述。 - 关联issue号(如果有)。 - Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. If possible, please consider writing useful notes for better and faster reviews in your PR. - Please clarify why the changes are needed. For instance, the use case and bug description. - Related issue number (if any) ## 面向用户的变更 (Does this PR introduce _any_ user-facing change)? - 请注意,这里指的是**任何**面向用户的变更,包括但不限于API、用户界面或其他使用方式上的变更。 - Note that it means *any* user-facing change including all aspects such as API, interface or other behavior changes. ## 功能验证 (How was this patch tested?) 请确认CI已通过增量及存量的单元测试用例。 如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤(最好提供完整的可复现的操作路径及关键截图),以便Committer能够快速复现验证,也便于后续的维护。 如果未添加测试,请说明未添加的原因,以及为何难添加测试。 - [_] 功能自验 - [_] 本地自验截图(涉及个人标识符等敏感信息请注意脱敏) - [_] 新增/变更内容是否已新增/适配UT测试用例看护 CI passed with new added/existing test. If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future. If tests were not added, please describe why they were not added and/or why it was difficult to add. - [_] Self-verification of the feature. - [_] Screenshot of local self-verification (please anonymize any sensitive information such as personal identifiers) - [_] Have new or modified unit test (UT) cases been added or adapted to cover the newly added or changed content? See merge request: Ascend/msmodelslim!3331 个月前
【msmodelslim】刷新文件头部声明和版权 Co-authored-by: caishengcheng<caishengcheng@huawei.com> # message auto-generated for no-merge-commit merge: !28 merge license into master 【msmodelslim】刷新文件头部声明和版权 Created-by: caishengcheng Commit-by: caishengcheng Merged-by: ascend-robot Description: 【msmodelslim】刷新文件头部声明和版权 See merge request: Ascend/msmodelslim!284 个月前
README.md

GLM-4.1V 量化说明

模型介绍

  • GLM-4.1V-9B-Thinking 是由智谱 AI 联合清华大学团队推出的多模态大模型,该模型引入思考范式,并通过基于课程采样的强化学习(Reinforcement Learning with Curriculum Sampling,RLCS)全面提升模型能力。

使用前准备

  • 安装 msModelSlim 工具,详情请参见《msModelSlim工具安装指南》
  • 针对GLM-4.1V,transformers版本需要安装为4.53.0:
    • pip install transformers==4.53.0

GLM-4.1V模型当前已验证的量化方法

模型 原始浮点权重 量化方式 推理框架支持情况 量化命令
GLM-4.1V-9B-Thinking GLM-4.1V-9B-Thinking W8A8SC量化 MindIE 预计3.0.RC1版本支持
vLLM Ascend 当前不支持
W8A8SC量化

生成量化权重

  • 量化权重统一使用quant_glm41v.py脚本生成,在“使用示例”章节提供GLM-4.1V-9B-Thinking模型量化权重生成快速启动命令。

  • 如果需要使用NPU多卡量化,请先配置多卡环境变量(Atlas 300I DUO 系列产品不支持多卡量化):

    export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
    export PYTORCH_NPU_ALLOC_CONF=expandable_segments:False
    
  • 若加载自定义模型,调用from_pretrained函数时要指定trust_remote_code=True,让修改后的自定义代码文件能够正确地被加载。(请确保加载的自定义代码文件的安全性)

使用示例

GLM-4.1V系列

GLM-4.1V-9B-Thinking W8A8SC量化 异常值抑制算法使用m2

该示例在NPU上生成GLM-4.1V-9B-Thinking模型的量化权重。使用m2算法进行异常值抑制。

请将{浮点权重路径}和{W8A8S量化权重路径}替换为用户实际路径。{校准集图片路径}默认为"../calibImages"。部署量化权重时,如在使用场景精度出现明显掉点,用户可根据实际场景替换为其他图片(建议30张)。

Atlas 300I DUO 使用以下方法稀疏量化压缩(W8A8SC),需先执行稀疏,然后再执行压缩,且压缩功能只有 Atlas 300I DUO 设备支持。

  • 稀疏量化

    python quant_glm41v.py \
      --model_path {浮点权重路径} \
      --save_directory {W8A8S量化权重路径} \
      --calib_images {校准集图片路径} \
      --w_bit 4 \
      --a_bit 8 \
      --device_type npu \
      --anti_method m2 \
      --is_lowbit True \
      --fraction 0.01 \
      --use_sigma True \
      --torch_dtype fp16 \
      --trust_remote_code True
    
  • 权重压缩

    注意:权重压缩需要先安装MindIE

    # TP数为tensor parallel并行个数
    export IGNORE_INFER_ERROR=1
    torchrun --nproc_per_node {TP数} -m examples.convert.model_slim.sparse_compressor --model_path {W8A8S量化权重路径} --save_directory {W8A8SC量化权重路径}
    

附录

量化参数说明

参数名 含义 可选/必选 默认值 使用方法
model_path 浮点权重路径 必选 无默认值 输入原始浮点权重目录路径。
calib_images 校准集图片路径 可选 ../calibImages 输入校准数据集的目录路径。本示例中图片来源于公开数据集COCO。 如在使用场景精度出现明显掉点,用户可根据实际场景替换为其他图片(建议30张)。
save_directory 量化权重路径 必选 无默认值 输出量化权重路径。
part_file_size 量化权重文件大小,单位是GB 可选 默认为None时不限制单个权重文件大小,此时只生成一个量化权重文件。 生成量化权重文件大小,请用户自定义单个量化权重文件的大小上限。
w_bit 权重量化bit 可选 8 在GLM-4.1V-9B-Thinking量化场景下支持配置为4或8。
a_bit 激活值量化bit 可选 8 在GLM-4.1V-9B-Thinking量化场景下支持配置为8。
device_type 量化运行设备类型 可选 'cpu' 可选值:['cpu', 'npu']。
trust_remote_code 是否信任自定义代码 可选 False 指定trust_remote_code=True让修改后的自定义代码文件能够正确地被加载(请确保所加载的自定义代码文件来源可靠,避免潜在的安全风险)。
anti_method 异常值抑制算法 可选 'm2' 可选值:['m2']。'm2'对应多模态理解模型场景下优化后的Outlier Suppression Plus异常值抑制算法。
act_method 激活值量化方法 可选 2 (1) 1代表Label-Free场景的min-max量化方式。
(2) 2代表Label-Free场景的histogram量化方式。
(3) 3代表Label-Free场景的自动混合量化方式。
open_outlier 是否开启权重异常值划分 可选 True 可以配置为True或者False。
设置为True时开启权重异常值划分,反之则关闭。
is_dynamic 是否使用动态量化,即W8A8中的激活量化参数动态生成 可选 False 可以配置为True或者False。
设置为True时使用动态量化,反之则不使用。
is_lowbit 是否使用稀疏量化的lowbit算法 可选 False 可以配置为True或者False。
设置为True时,表示使用稀疏量化的lowbit算法,反之则不使用。
w4a8_dynamic per-group量化场景下需要设置为True。
co_sparse 是否开启稀疏量化功能 可选 False True: 使用稀疏量化功能;
False: 不使用稀疏量化功能。
fraction 模型权重稀疏量化过程中被保护的异常值占比 可选 0.01 取值范围[0.01,0.1]。
do_smooth 是否启动smooth量化功能 可选 False True: 开启smooth量化功能;
False: 不开启smooth量化功能。
use_sigma 是否启动sigma功能 可选 False True: 开启sigma功能;
False: 不开启sigma功能。
sigma_factor sigma功能中sigma的系数 可选 3.0 数据类型为float,默认值为3.0,取值范围为[1.0, 3.0]。
说明:仅当use_sigma为True时生效。
torch_dtype 设置加载权重的数据类型 可选 bf16 可选值:['bf16', 'fp16']。默认值为bf16。
group_size per-group量化的分组数量 可选 64 设置为64,128,256,512。
w4a8_dynamic per-group量化场景下仅支持256。
mindie_format 多模态理解模型量化后的权重配置文件是否兼容MindIE现有版本 可选 False 开启mindie_format时保存的量化权重格式能够兼容MindIE当前的版本,不开启mindie_format时保存的量化权重可用于vLLM Ascend部署。
  • 更多参数配置要求,请参考量化过程中配置的参数 QuantConfig 以及量化参数配置类 Calibrator