mit einem Klick
open-model-convert-deploy
// 实现开源模型从PyTorch→ONNX→MindIR→MindSpore Lite的端到端导出/验证/部署/性能评测。用户要求模型拆分导出、精度对齐、MindIR转换或部署工具链时调用。
// 实现开源模型从PyTorch→ONNX→MindIR→MindSpore Lite的端到端导出/验证/部署/性能评测。用户要求模型拆分导出、精度对齐、MindIR转换或部署工具链时调用。
Cloud-side inference with ExtendRT and Ascend backends. Use for server-side inference, Ascend 310/910 deployment, ModelParallelRunner for concurrent serving, ModelGroup for weight sharing, distributed inference, or .mindir format loading.
Model conversion pipeline, parser development, optimization passes and quantization. Use when converting models to .ms, writing parser code, implementing optimizer passes, or configuring quantization.
Build configuration, CMake options, cross-compilation and packaging. Use when building MindSpore Lite, configuring CMake, cross-compiling for ARM/iOS/MCU, packaging release archives, or troubleshooting build errors.
Code formatting, naming conventions, security checks and CI verification. Use when running clang-format, checking code style, writing secure code for model parsing, reviewing code quality, or configuring CI/Jenkins pipelines.
Debugging, unit testing, benchmarking and performance analysis. Use when running gtest, benchmark tools, profiling latency or accuracy, diagnosing operator precision issues, delegate fallback, or memory leaks.
Device-side inference with LiteRT, NNACL and hardware delegates. Use for mobile/IoT inference, Android/iOS integration, NPU/GPU/CoreML delegates, Micro codegen for MCU, on-device training, or C/C++/Java/Python API usage with .ms models.
| name | open-model-convert-deploy |
| description | 实现开源模型从PyTorch→ONNX→MindIR→MindSpore Lite的端到端导出/验证/部署/性能评测。用户要求模型拆分导出、精度对齐、MindIR转换或部署工具链时调用。 |
本技能用于把“开源算法模型”做成可落地的端到端部署方案:按网络结构拆分导出 ONNX、生成模型元信息、ONNX Runtime CPU 推理脚本(CLI+API)、精度对齐验证(含报告)、ONNX→MindIR 转换与 MindSpore Lite CPU 推理实现,并交付一键化工具链与测试/基准/容器化方案。
当用户提出以下诉求之一时调用:
在目标模型目录(例如 mindspore-lite/examples/base_models/<model_name>/)下建议形成如下结构(按需裁剪):
export_<model>_onnx.py:按模块导出 ONNXmodel_info/:
<module>.json:每个模块的输入输出、节点数、算子统计等元数据infer_<model>_onnx.py:ONNX Runtime CPU 推理(CLI + 可 import 的 API)infer_<model>_mslite.py:MindSpore Lite CPU 推理(CLI + 可 import 的 API)tools/:
collect_model_info.py:扫描 ONNX 生成元信息accuracy_eval.py:精度对齐评估与报告生成benchmark.py:延迟/吞吐/内存采集与对比tests/:单元测试(最少覆盖:导出、加载、一次推理、shape 变更、异常分支)说明:仓库规则通常不建议无需求创建文档;若用户明确要求“完整教程/文档”,再生成 README.md。
目标:识别可独立部署的模块组件,并定义模块间接口(张量语义、dtype、shape)。
建议拆分思路:
产出:
要求:
.onnx.data)opset_version(优先 17/18,结合仓库与转换器能力)dynamic_axes 覆盖 batch 与核心动态维度eval() + torch.no_grad()模板要点:
torch.nn.Module,只暴露必要输入输出生成内容(建议 JSON):
inputs:name、dtype、shape(含 dynamic 标注)outputs:同上num_nodesopsetoperators:按 op_type 计数(TopK)model_size_bytes实现建议:
onnx.load() 读取 graphgraph.node 统计算子model.graph.input/output 抽取 I/Ovalue_info 或导出时记录的 I/O spec 补全要求:
python infer_xxx_onnx.py --model ... --input ...from infer_xxx_onnx import Inferencer; Inferencer(...).infer(...)性能采集建议:
time.perf_counter(),区分 warmup 与 measurement/proc/self/status 里的 VmRSS/VmHWMpsutil(仅当仓库已有该依赖;否则不要强依赖)要求(来自用户约束):
实现建议(不引入额外训练/标注成本):
要求:
build.sh 产生,不要直接跑 CMake)常用转换命令模式(以 converter_lite , 昇腾推理后端为例):
converter_lite --fmk=ONNX --optimize=ascend_oriented --modelFile=xxx.onnx --outputFile=xxx --saveType=MINDIR
目标:功能与 ONNX 版本保持一致。
要求:
量化:
说明:是否生成这些交付物取决于用户是否明确要求,避免无必要新增文件。
建议:
export → info → ort_infer_sanity → accuracy_eval → convert → mslite_infer_sanity → benchmark要求: