用途:指导为新模型创建基础适配器,使其跑通 W8A8/W4A16 量化流程。
适用范围:支持 Decoder-only LLM、理解类 VLM(仅处理文本/LLM 主干);不支持多模态生成(如图像/视频/语音生成)、Encoder-only、非 Transformers 模型。
核心工作流:
- 准备:下载模型,建议用 modelscope download 下载非权重文件,示例:modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '.safetensors';阅读 config.json 与 modeling_.py 分析结构。
- 创建适配器:使用模板 assets/model_adapter_template.py(LLM)或 assets/vlm_model_adapter_template.py(VLM),实现 handle_dataset、init_model、generate_model_visit、generate_model_forward、enable_kv_cache 接口。关键原则:visit 与 forward 必须严格一致;MoE 模型建议 unpack 为纯线性层。
- 注册与安装:在 config/config.ini 注册模型与入口,执行 bash install.sh。
- 验证(必需):四步验证——生成测试模型、全回退量化、校验全回退模型与浮点权重严格一致且可完整加载/保存、验证实际量化流程正常(含描述文件规则校验)。
常用脚本位于 scripts/ 目录:scripts/step1_generate_test_model.py、scripts/step2_run_quantization.py、scripts/step3_verify_weights.py、scripts/step4_verify_quant_description.py。
限制:仅覆盖上述适用模型类型;具体接口细节、模板内容与验证标准以对应指南为准,资料未提供更细的收费、平台或效果信息。