整体概述
小模型推理方案:
ATC转换架构图:
ModelZoo-PyTorch指导文档:https://gitee.com/ascend/ModelZoo-PyTorch/blob/master/ACL_PyTorch/docs/README.md
模型推理
离线推理
导出Onnx
参考链接:ONNX的导出
Onnx转om
离线推理
参考链接:离线推理
Chinese_CLIP上机操作
Chinese_CLIP模型介绍
传统模型基于昇腾迁移适配全流程
模型支持度分析
- 安装msit: https://gitee.com/ascend/msit/blob/master/msit/docs/install/README.md
- 模型转换:pt->onnx:参考链接
- 执行分析命令:
查看results.csv可以看到哪些算子在昇腾支不支持。msit analyze -gm ./resnet.onnx -o ./out
使用onnx-sim对onnx模型进行简化
export bs=24
onnxsim models/vit-b-16.txt.fp32.onnx models/vit-b-16.txt.fp32.bs${bs}.sim.onnx --overwrite-input-shape "text:${bs},512"
Simplifying...
Finish! Here is the difference:
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ ┃ Original Model ┃ Simplified Model ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ Add │ 122 │ 122 │
│ Cast │ 4 │ 1 │
│ Concat │ 48 │ 0 │
│ Constant │ 532 │ 207 │
│ ConstantOfShape │ 1 │ 0 │
│ Div │ 24 │ 24 │
│ Equal │ 1 │ 1 │
│ Erf │ 12 │ 12 │
│ Expand │ 1 │ 0 │
│ Gather │ 101 │ 2 │
│ LayerNormalization │ 25 │ 25 │
│ MatMul │ 97 │ 97 │
│ Mul │ 25 │ 25 │
│ Not │ 1 │ 1 │
│ Range │ 1 │ 0 │
│ Reshape │ 48 │ 48 │
│ Shape │ 99 │ 0 │
│ Softmax │ 12 │ 12 │
│ Sub │ 1 │ 1 │
│ Transpose │ 48 │ 48 │
│ Unsqueeze │ 99 │ 1 │
│ Model Size │ 392.3MiB │ 461.4MiB │
└────────────────────┴────────────────┴──────────────────┘
使用msit surgeon使能onnx模型基于昇腾芯片的优化(onnx->onnx)
msit surgeon功能指导:链接
- msit surgeon安装
# 安装 msit install surgeon # 检查安装是否成功 msit surgeon check
了解什么是知识库:链接
各个命令的使用示例
模型转换(onnx->om)
atc工具使用指导:链接
AOE自动调优(onnx->om)
使用指导:链接
模型压缩:
官方指导文档:链接
离线推理
ais_bench使用安装:链接
推理执行:
在线推理
- torch_npu单算子推理:
开源样例 vs torch_npu适配版本
执行在线推理:

**跑了一把cpu版本和npu版本,发现最后返回logits有差异,需要进一步做精度对齐分析。**
torchair图模式推理:
参考modelzoo适配:链接开源样例 vs torchair适配版本
执行推理:

报错整理
- git clone 报错
解决方案:export GIT_SSL_NO_VERIFY=1
- 安装onnxsim报错
cmake版本问题,导致onnxsim编译一直报错,cmake版本太高或者太低都不行。
```bash
wget https://github.com/Kitware/CMake/releases/download/v3.27.4/cmake-3.27.4.tar.gz
tar -xzf cmake-3.27.4.tar.gz
cd cmake-3.27.4
./bootstrap && make -j$(nproc) && make install
```
- No module named 'auto_optimizer'
auto_optimizer是昇腾基于onnx的改图工具,需要安装msit install surgeon即可。
- 执行msit debug compare报错
比对结果输出路径要先创建出来