SuperAPI AI 工具集

huawei-cloud-msmodelslim-model-adapt

测试与质量

查看项目

更新于 10-15 22:14

技能介绍

用途:为 msModelSlim 创建基础 Transformers 模型适配器,使新模型可运行 W8A8/W4A16 量化工作流,面向昇腾 NPU 部署。

主要能力:支持 decoder-only LLM 与理解型 VLM(仅文本/LLM 主干);提供 LLM 与 VLM 适配器模板;需实现 handle_dataset、init_model、generate_model_visit、generate_model_forward、enable_kv_cache 等接口;visit 与 forward 必须严格一致,MoE 模型建议展开为纯线性层。

使用方式:先下载模型(推荐 modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '.safetensors'),读取 config.json 与 modeling_.py 分析结构;再基于 assets/model_adapter_template.py 或 assets/vlm_model_adapter_template.py 创建适配器;在 config/config.ini 注册模型与入口后执行 bash install.sh;最后运行四步验证脚本:scripts/step1_generate_test_model.py、scripts/step2_run_quantization.py、scripts/step3_verify_weights.py、scripts/step4_verify_quant_description.py。

环境要求:Python 3.8+、transformers >= 4.40.0、msmodelslim >= 1.0.0;可用 python3 --version 及导入检查确认,缺失时 pip3 install --user transformers msmodelslim。

限制:不支持多模态生成(Stable Diffusion/Flux/Wan)、encoder-only 模型及非 Transformers 架构;四步验证为必需步骤,需确认全回退模型与浮点权重完全一致且可完整加载保存。具体参数与脚本细节以官方文档为准。