diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\345\267\245\345\205\267.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\345\267\245\345\205\267.md" deleted file mode 100644 index cc4b679dab05b7aa3dc79db1b46b0ab4900ef0eb..0000000000000000000000000000000000000000 --- "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\345\267\245\345\205\267.md" +++ /dev/null @@ -1,32 +0,0 @@ -## 仓库地址:[张东宇/onnx_tools](https://gitee.com/zhang-dongyu/onnx_tools) - -## numpy_data_cmp - -简介:逐个对比两个numpy的每一个数据,输出每个数据的误差,和最后统计的最大误差以及误差比。 - -## one_step_accuracy_cmp - -简介:全流程精度比对工具,基于《开发辅助工具指南(推理)》的《7 精度比对工具使用指南》,串起流程,只需一步操作即可生成中间数据、对比结果。 - -## oxinterface - -简介:一套操作简单的onnx改图接口。 - -功能: - -1. 修改常量节点(Initializer)的名字、数据类型、数据值 -2. 新增常量节点(Initializer) -3. 保存常量节点(Initializer)的数据 -4. 向模型中插入节点 -5. 从模型中截取单节点、从模型中截取一段模型 -6. 获取模型输入、输出、中间tensor、Initializer的信息(包括:tensor名字、shape、类型) -7. dump模型所有节点的数据 -8. ... - -## pyacl_infer - -简介:一套封装好的python acl推理脚本,类似benchmark,支持动态shape,支持推理时间统计。 - -## run_profiling - -简介:封装好的简单易用的profiling性能分析工具。 diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/13\343\200\220\346\241\210\344\276\213\345\210\206\344\272\253\343\200\221\357\274\232Bert Base Uncased\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230 .docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/nlp/Bert Base Uncased\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230 .docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/13\343\200\220\346\241\210\344\276\213\345\210\206\344\272\253\343\200\221\357\274\232Bert Base Uncased\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230 .docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/nlp/Bert Base Uncased\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230 .docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/12\343\200\220\346\241\210\344\276\213\345\210\206\344\272\253\343\200\221\357\274\232Transformer\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/nlp/Transformer\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/12\343\200\220\346\241\210\344\276\213\345\210\206\344\272\253\343\200\221\357\274\232Transformer\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/ONNX\346\250\241\345\236\213\346\216\250\347\220\206\346\214\207\345\257\274/official/nlp/Transformer\346\250\241\345\236\213\350\277\201\347\247\273\350\260\203\344\274\230.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/01\343\200\220\351\241\271\347\233\256\350\203\214\346\231\257\343\200\221\357\274\232ONNX\346\216\250\347\220\206\346\250\241\345\236\213\350\203\214\346\231\257\344\270\216\347\233\256\345\275\225.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\345\212\237\350\203\275\346\211\223\351\200\232/1. ONNX\346\216\250\347\220\206\346\250\241\345\236\213\350\203\214\346\231\257\344\270\216\347\233\256\345\275\225.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/01\343\200\220\351\241\271\347\233\256\350\203\214\346\231\257\343\200\221\357\274\232ONNX\346\216\250\347\220\206\346\250\241\345\236\213\350\203\214\346\231\257\344\270\216\347\233\256\345\275\225.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\345\212\237\350\203\275\346\211\223\351\200\232/1. ONNX\346\216\250\347\220\206\346\250\241\345\236\213\350\203\214\346\231\257\344\270\216\347\233\256\345\275\225.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/03\343\200\220\350\277\201\347\247\273\346\265\201\347\250\213\343\200\221\357\274\232ONNX\346\250\241\345\236\213\350\277\201\347\247\273\346\265\201\347\250\213.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\345\212\237\350\203\275\346\211\223\351\200\232/2. ONNX\346\250\241\345\236\213\350\277\201\347\247\273\346\265\201\347\250\213.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/03\343\200\220\350\277\201\347\247\273\346\265\201\347\250\213\343\200\221\357\274\232ONNX\346\250\241\345\236\213\350\277\201\347\247\273\346\265\201\347\250\213.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\345\212\237\350\203\275\346\211\223\351\200\232/2. ONNX\346\250\241\345\236\213\350\277\201\347\247\273\346\265\201\347\250\213.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/02\343\200\220\345\274\200\345\217\221\347\216\257\345\242\203\343\200\221\357\274\232\345\274\200\345\217\221\347\216\257\345\242\203\357\274\210CANN\345\271\263\345\217\260\357\274\211\346\220\255\345\273\272.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\345\274\200\345\217\221\347\216\257\345\242\203/1. \345\274\200\345\217\221\347\216\257\345\242\203\357\274\210CANN\345\271\263\345\217\260\357\274\211\346\220\255\345\273\272.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/02\343\200\220\345\274\200\345\217\221\347\216\257\345\242\203\343\200\221\357\274\232\345\274\200\345\217\221\347\216\257\345\242\203\357\274\210CANN\345\271\263\345\217\260\357\274\211\346\220\255\345\273\272.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\345\274\200\345\217\221\347\216\257\345\242\203/1. \345\274\200\345\217\221\347\216\257\345\242\203\357\274\210CANN\345\271\263\345\217\260\357\274\211\346\220\255\345\273\272.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/07\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232Profiling\350\204\232\346\234\254\344\270\216\346\225\260\346\215\256\350\216\267\345\217\226.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/1. Profiling\350\204\232\346\234\254\344\270\216\346\225\260\346\215\256\350\216\267\345\217\226.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/07\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232Profiling\350\204\232\346\234\254\344\270\216\346\225\260\346\215\256\350\216\267\345\217\226.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/1. Profiling\350\204\232\346\234\254\344\270\216\346\225\260\346\215\256\350\216\267\345\217\226.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/08\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232NPU\344\270\216GPU\344\270\213Profilig\346\225\260\346\215\256\345\210\206\346\236\220.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/2. NPU\344\270\216GPU\344\270\213Profilig\346\225\260\346\215\256\345\210\206\346\236\220.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/08\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232NPU\344\270\216GPU\344\270\213Profilig\346\225\260\346\215\256\345\210\206\346\236\220.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/2. NPU\344\270\216GPU\344\270\213Profilig\346\225\260\346\215\256\345\210\206\346\236\220.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/09\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232NPU\344\270\213OM\346\250\241\345\236\213Autotune\350\260\203\344\274\230.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/3. NPU\344\270\213OM\346\250\241\345\236\213Autotune\350\260\203\344\274\230.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/09\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232NPU\344\270\213OM\346\250\241\345\236\213Autotune\350\260\203\344\274\230.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/3. NPU\344\270\213OM\346\250\241\345\236\213Autotune\350\260\203\344\274\230.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/10\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213UB\350\236\215\345\220\210.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/4. ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213UB\350\236\215\345\220\210.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/10\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213UB\350\236\215\345\220\210.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/4. ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213UB\350\236\215\345\220\210.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/11\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213Graph\350\236\215\345\220\210.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/5. ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213Graph\350\236\215\345\220\210.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/11\343\200\220\346\200\247\350\203\275\350\260\203\344\274\230\343\200\221\357\274\232ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213Graph\350\236\215\345\220\210.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\346\200\247\350\203\275\350\260\203\344\274\230/5. ONNX\346\216\250\347\220\206\346\250\241\345\236\213\346\200\247\350\203\275\344\274\230\345\214\226\344\271\213Graph\350\236\215\345\220\210.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/numpy_data_cmp/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/numpy_data_cmp/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..1d8223ff19f121c4dfd1b2827d73bbb69e159773 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/numpy_data_cmp/README.md" @@ -0,0 +1,26 @@ +# 功能 + +逐个对比两个numpy的每一个数据,输出每个数据的误差,和最后统计的最大误差以及误差比(误差比=有误差的数据个数/数据总个数)。 + +**要求:** 两个numpy的数据个数必须一致。 + +# 使用示例 + +## 对比npy类型数据 + +```shell +python numpy_data_cmp.py --type=npy --left_data_path=./left_data.npy --right_data_path=./right_data.npy +``` + +## 对比bin类型数据 + +```shell +python numpy_data_cmp.py --type=bin --left_data_path=./left_data.npy --left_data_type=np.float32 --right_data_path=./right_data.npy --right_data_type=np.float32 +``` + +## 查看帮助 + +```shell +python numpy_data_cmp.py -h +``` + diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/numpy_data_cmp/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/numpy_data_cmp/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f7df4387a9af22adbc00090fca6b8ff01497ee40 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/numpy_data_cmp/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" @@ -0,0 +1 @@ +https://gitee.com/zhang-dongyu/onnx_tools \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.imgs/1622597724195.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.imgs/1622597724195.png" new file mode 100644 index 0000000000000000000000000000000000000000..bfd01ce0cf55fe5978eba323205e9f14decc3873 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.imgs/1622597724195.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.imgs/1622712256468.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.imgs/1622712256468.png" new file mode 100644 index 0000000000000000000000000000000000000000..372af554113c6c69b597e123492a3ad7f32aeec4 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.imgs/1622712256468.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..88d659772247bec39b56683a727c06a82c078ebf --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/README.md" @@ -0,0 +1,67 @@ +# 简介 + +一步式精度比对工具。基于[《 CANN 5.0.1 开发辅助工具指南 (推理) 01.pdf》](https://cmc-szv.clouddragon.huawei.com/cmcversion/index/releaseView?deltaId=3696745162342656&isSelect=inner&url_data=CANN%E8%B5%84%E6%96%99%3E%E6%A0%87%E5%87%86%E6%80%81%3Ezh%3E%E6%8E%A8%E7%90%86)的 **《7 精度比对工具使用指南》** ,串起流程,只需一步操作即可生成中间dump数据、对比结果Excel文件。 + +# 准备工作 + +- 需要提前准备[msame](https://gitee.com/ascend/tools/tree/master/msame#https://gitee.com/ascend/tools.git)工具。本代码仓提供编译好的,在`msame`文件夹下,根据自己的系统获取对应版本。若无法使用,则需要用户自己重新编译。 + +# 如何使用? + +1、根据实际情况修改`config.yaml`文件,例如: + +```yaml +input_info: + - bin_path: ./input_data/0.bin + shape: (1, 3, 224, 224) + dtype: np.float32 + input_name: image +om_path: ./wide_resnet50_2_bs1.om +onnx_path: ./wide_resnet50_2.onnx +dump_save_path: ./dump_data +npu_device_id: 0 +msame_path: ./msame/x86/msame +msaccucmp_py_path: /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/toolkit/tools/operator_cmp/compare/msaccucmp.py +env: | + export install_path=/usr/local/Ascend/ascend-toolkit/latest + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp +``` + +**参数说明&注意事项:** + +- bin_path:模型的输入数据 +- shape:此输入数据的维度,写成python tuple格式 +- dtype:此输入数据的类型,numpy类型写法,写成np.float32,np.int32,...,不可写成numpy.float32,numpy.int32,... +- input_name:此输入数据对应的onnx模型的输入名字 +- 若模型有多个输入,input_info数组一定要按照onnx模型图中的输入顺序提供,不可颠倒顺序,否则dump出的om数据不可靠,甚至无法dump出om数据 +- npu_device_id:所用的npu设备id,**若运行出现卡死,说明npu设备正在被使用,尝试使用其它设备** +- 新版cann toolkit中的`msaccucmp.pyc`已改为`msaccucmp.py` +- env:cann toolkit环境变量 + +2、输入如下命令,开始生成dump数据并对比: + +```shell +python one_step_accuracy_cmp.py config.yaml +``` + +**dump生成的目录说明:** + +![1622597724195](README.imgs/1622597724195.png) + +- 20210601210956:om模型dump出的原始数据 +- 20210601210956_om:om模型dump出的原始数据转numpy后的数据 +- 20210601210956_onnx:onnx模型的dump数据 +- 20210601210956_cmp:比对报告CSV文件存放目录 + +# 特别说明(必看) + +若从对比excel文件,或者**20210601210956_om**目录中发现om的dump数据都为0,或者感觉om dump出的数据比较奇怪,感觉不正确,那么atc转om的时候加上`--buffer_optimize=off_optimize`关闭数据缓存优化,再运行一遍,看结果是否符合预期。 + +缓存优化默认是开启的,有些om在开启缓存优化后dump出的数据都是0,而有些om的某些节点dump出的数据是0,导致比对结果看起来不正常。 + +个人建议,先不关闭缓存优化,对比一遍,然后再关闭缓存优化对比一遍,比较两次得到的Excel文件。 + +![1622712256468](README.imgs/1622712256468.png) \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f7df4387a9af22adbc00090fca6b8ff01497ee40 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/one_step_accuracy_cmp/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" @@ -0,0 +1 @@ +https://gitee.com/zhang-dongyu/onnx_tools \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622106987221.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622106987221.png" new file mode 100644 index 0000000000000000000000000000000000000000..0542f7760af118e5a095b9072e070c3a57730d25 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622106987221.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107015560.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107015560.png" new file mode 100644 index 0000000000000000000000000000000000000000..0ad1db16ffb4ddebc656f9d86c34bb71f50de96b Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107015560.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107202867.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107202867.png" new file mode 100644 index 0000000000000000000000000000000000000000..f994b95fb511a801292f91c242af80f13524dca6 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107202867.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107221716.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107221716.png" new file mode 100644 index 0000000000000000000000000000000000000000..a57781c620409dd7aaac8e2b36529e1893b2f25d Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107221716.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107709834.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107709834.png" new file mode 100644 index 0000000000000000000000000000000000000000..42b9659d320e743218753b33025fce541b262227 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622107709834.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622108249450.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622108249450.png" new file mode 100644 index 0000000000000000000000000000000000000000..4e3fe7ef773d24a38b1726544602d14400775d1c Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622108249450.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112318360.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112318360.png" new file mode 100644 index 0000000000000000000000000000000000000000..389693174f041e0bdd2353b6e5eb2787ea113229 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112318360.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112612814.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112612814.png" new file mode 100644 index 0000000000000000000000000000000000000000..e39ec7e440ca69b3dbdf0f3e7db49ce019a27f80 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112612814.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112917399.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112917399.png" new file mode 100644 index 0000000000000000000000000000000000000000..a6e19419e46551bfca1d984da2092b3eca3f22f9 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112917399.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112935370.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112935370.png" new file mode 100644 index 0000000000000000000000000000000000000000..b2294053dc027b758566f88f1192087aaaa01bee Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622112935370.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622113043387.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622113043387.png" new file mode 100644 index 0000000000000000000000000000000000000000..6ef26d633cf28a50e4e7f9890f31c04dc1d7d279 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622113043387.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622113217416.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622113217416.png" new file mode 100644 index 0000000000000000000000000000000000000000..3d0e6f0adb894c4ca2abba843b42be1c3f5ee246 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622113217416.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622115015117.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622115015117.png" new file mode 100644 index 0000000000000000000000000000000000000000..e8a95b5a07eca0aa7d86761ae5e1fda8a4ce5a03 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622115015117.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622115648885.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622115648885.png" new file mode 100644 index 0000000000000000000000000000000000000000..b29c6246c642822aa78fae16cb50327b63c8b662 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622115648885.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622116321331.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622116321331.png" new file mode 100644 index 0000000000000000000000000000000000000000..a9dcc4a2a0d3f7c5681baaac9507f839b00d5d2b Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1622116321331.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624938045299.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624938045299.png" new file mode 100644 index 0000000000000000000000000000000000000000..74afc54005da9e1e6b57e08e93bfec91f399a811 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624938045299.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624938080996.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624938080996.png" new file mode 100644 index 0000000000000000000000000000000000000000..8130e82f8f1d8979101b09710e684adf5a20f589 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624938080996.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624956415448.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624956415448.png" new file mode 100644 index 0000000000000000000000000000000000000000..0a12af9333edd3b2720b636e88438292f10b3e15 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624956415448.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624956500650.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624956500650.png" new file mode 100644 index 0000000000000000000000000000000000000000..e22c384eb87124f6baaa42b1913cb8e3a4b8f192 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624956500650.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624958747025.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624958747025.png" new file mode 100644 index 0000000000000000000000000000000000000000..4a223b99a8a4004fcdee5eef165e3fa0fbfa5a99 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624958747025.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624959810471.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624959810471.png" new file mode 100644 index 0000000000000000000000000000000000000000..79f7b1d0b3b7e0f8359ff9cab0d35fb01b432d83 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1624959810471.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625018717940.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625018717940.png" new file mode 100644 index 0000000000000000000000000000000000000000..b80107398de8f93d6a7e0d409c5edad69c989ab7 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625018717940.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625020990020.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625020990020.png" new file mode 100644 index 0000000000000000000000000000000000000000..8d34419247a360e216bf1cce13e2eaa38f7eecc8 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625020990020.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625040902674.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625040902674.png" new file mode 100644 index 0000000000000000000000000000000000000000..4082bcc4be14e73410bc311e7a8331182d3ea071 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625040902674.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625040996328.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625040996328.png" new file mode 100644 index 0000000000000000000000000000000000000000..e4aa8fdd35fe2296320f0140283adb42f8862eec Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625040996328.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625041088057.png" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625041088057.png" new file mode 100644 index 0000000000000000000000000000000000000000..7fec91ecf50d7244e2d44e3c67b861748ecf5d87 Binary files /dev/null and "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.imgs/1625041088057.png" differ diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..444bad66c180a872f6c04ef5b817aac675c5e5a8 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/README.md" @@ -0,0 +1,692 @@ +[TOC] + +# 前言 + +- 简介:一套操作简单的onnx改图接口。 +- 演进:根据业务需求,功能持续更新和优化中... +- 问题:可能有隐含bug,欢迎使用并告知我修复。 + +# 依赖 + +- python==3.8.5 +- onnx==1.8.1 +- onnxruntime==1.7.0 +- skl2onnx==1.8.0 +- numpy==1.19.5 + +# 环境搭建 + +搭建conda环境: + +```shell +conda create -n OXInterface python==3.8.5 +conda activate OXInterface +pip install onnx==1.8.1 onnxruntime==1.7.0 skl2onnx==1.8.0 numpy==1.19.5 +``` + +按照此方法搭建环境一定可以用,其它情况不做保证。 + +# 使用教程 + +## Example 1:修改Initializer节点的名字 + +**功能:** 修改Initializer 497的名字(Conv_0下)。 + +**注意:** 修改Initializer的名字,需要相应修改使用该Initializer的节点的输入。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxinitializer_497 = oxgraph.get_oxinitializer_by_name('497') +oxinitializer_497.set_name('497_new') +oxnode_conv_0 = oxgraph.get_oxnode_by_name('Conv_0') +oxnode_conv_0.input[1] = '497_new' +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_1.onnx') +``` + +**修改之后:** + +![1622112318360](README.imgs/1622112318360.png) + +## Example 2:修改Initializer节点的数据类型 + +**功能:** 修改Initializer 497的数据类型(Conv_0下),float32改为float16。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxinitializer_497 = oxgraph.get_oxinitializer_by_name('497') +oxinitializer_497.set_data_type(OXDataType.float16) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_2.onnx') +``` + +**修改之前:** + +![1622106987221](README.imgs/1622106987221.png) + +**修改之后:** + +![1622107015560](README.imgs/1622107015560.png) + +## Example 3:修改Initializer节点的数据值 + +**功能:** 修改Initializer 497的数据值(Conv_0下)。 + +**示例代码:** + +```python +import numpy as np +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxinitializer_497 = oxgraph.get_oxinitializer_by_name('497') +new_data = np.array([1, 2, 3, 4], dtype=np.int32) +oxinitializer_497.set_data(new_data) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_3.onnx') +``` + +**修改之前:** + +![1622107202867](README.imgs/1622107202867.png) + +**修改之后:** + +![1622107221716](README.imgs/1622107221716.png) + +## Example 4:新增Initializer节点 + +**功能:** 构造并向模型中增加一个新的Initializer。 + +**说明:** 根据自己需求决定该新Initializer给哪个节点用,示例代码只是构造并向模型中添加了一个Initializer节点,并未指明给哪个节点用,所以打开新模型看不到什么变化。 + +**示例代码:** + +```python +import numpy as np +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +data = np.array([1, 2, 3, 4], dtype=np.int32) +oxgraph.add_initializer('new_initializer', data) +new_initializer = oxgraph.get_oxinitializer_by_name('new_initializer') +print(new_initializer) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_4.onnx') +``` + +## Example 5:保存Initializer节点的数据 + +**功能:** 保存Initializer 497的数据(Conv_0下)。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxinitializer_497 = oxgraph.get_oxinitializer_by_name('497') +oxinitializer_497.save_data('./initializer_497.npy') +``` + +## Example 6:插入节点 + +**功能:** 向模型中插入节点。 + +**函数:** + +- `insert_node`函数插入节点,并自动连边。无法涵盖所有场景,若结果不符合预期,请用`add_node`函数,并手动指定连边关系。 +- `add_node`函数只能插入节点,但无法自动连边。需要结合模型图分析连边关系,并手动连边。 + +### Sub Example 1 + +**功能:** 插入单输入单输出节点。在`Relu_1`和`MaxPool_2`之间插入一个`Cast`节点。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.insert_node(bef_node_info_list=['Relu_1:0'], + aft_node_info_list=['MaxPool_2:0'], + op_type='Cast', + op_name='Cast1', + to=int(OXDataType.float16)) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_6_1.onnx') +``` + +**参数说明:** + +- `bef_node_info_list`指定了插入节点的前驱节点; +- `aft_node_info_list`指定了插入节点的后继节点; +- `Relu_1:0`中的`:0`表示`Cast1`的输入要连接`Relu_1`的第`0`个输出; +- `MaxPool_2:0`中的`:0`表示`Cast1`的输出要连接`MaxPool_2`的第`0`个输入; +- 若连边是`:0`,则可以省略,其它情况不可省略。例如`:1`或`:0:1`等就不能省略。简化后为:`bef_node_info_list=['Relu_1']`,`aft_node_info_list=['MaxPool_2']`。 + +**修改之后:** + +![1622107709834](README.imgs/1622107709834.png) + +### Sub Example 2 + +**功能:** 插入多输入多输出节点。在`Conv_7`、`Conv_8`和`Add_9`之间插入一个新节点。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.insert_node(bef_node_info_list=['Conv_7', 'Conv_8'], + aft_node_info_list=['Add_9:0:1'], + op_type='Add', + op_name='Add_New') +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_6_2.onnx') +``` + +**参数说明:** + +- `Add_9:0:1`指示`Add_New`的输出同时连接到`Add_9`的第`0`和输入和第`1`个输入上。 + +**修改之后:** + +![1622108249450](README.imgs/1622108249450.png) + +### Sub Example 3 + +**功能:** 插入多输入多输出节点。在`Relu_6`、`MaxPool_2`、`Conv_7`和`Conv_8`之间插入一个新节点。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.insert_node(bef_node_info_list=['Relu_6', 'MaxPool_2'], + aft_node_info_list=['Conv_7', 'Conv_8'], + op_type='Add', + op_name='Add_New') +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_6_3.onnx') +``` + +**修改之后:** + +![1622112612814](README.imgs/1622112612814.png) + +### Sub Example 4 + +**功能:** 在输入节点和`Conv_0`之间插入一个`Cast`节点。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.insert_node( + bef_node_info_list=['image'], + aft_node_info_list=['Conv_0'], + op_type='Cast', + op_name='Cast1', + to=int(OXDataType.float16), +) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_6_4.onnx') +``` + +**修改之后:** + +![1624958747025](README.imgs/1624958747025.png) + +### Sub Example 5 + +**功能:** 在` Gemm_121 `和输出节点之间插入一个`Cast`节点。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.insert_node(bef_node_info_list=['Gemm_121'], + aft_node_info_list=['class'], + op_type='Cast', + op_name='Cast1', + to=int(OXDataType.float16)) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_6_5.onnx') +``` + +**修改之后:** + +![1624959810471](README.imgs/1624959810471.png) + +### Sub Example 6 + +**功能:** 自己手动连边。在` Relu_1`和` MaxPool_2`之间插入一个`Reshape`节点(需要结合模型图分析连边关系)。 + +**示例代码:** + +```python +import numpy as np +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') + +# 构造一个常量节点 +oxgraph.add_initializer('Initializer_New', np.array([1, 2, 3, 4], dtype=np.int32)) + +# 增加一个Reshape节点 +# Reshape_New的一个输入接Relu_1的输出,另个输入接Initializer_New +# Reshape_New的输入设定为Reshape_New_0(也可以是其它名字) +oxgraph.add_node(op_type='Reshape', op_name='Reshape_New', inputs=['323', 'Initializer_New'], outputs=['Reshape_New_0']) + +# MaxPool_2的第一个输入接Reshape_New的输出Reshape_New_0 +MaxPool_2 = oxgraph.get_oxnode_by_name('MaxPool_2') +MaxPool_2.input[0] = 'Reshape_New_0' + +# 保存模型 +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_6_6.onnx') +``` + +**修改之后:** + +![1625020990020](README.imgs/1625020990020.png) + +## Example 7:截取模型 + +**功能:** 截取模型。 + +**用途:** 可以用来单独验证某段网络的精度。 + +**说明:** + +- `trunc_model`函数使用节点名指定截图的范围; +- `extract_model`函数使用tensor名指定截图的范围。 + +### Sub Example 1 + +**功能:** 截取`Add_9`单节点。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.trunc_model( + trunc_beg_node_name_list=['Add_9'], + trunc_end_node_name_list=['Add_9'], + new_model_save_path='./test_model/wide_resnet50_2_example_7_1.onnx', +) +``` + +**截取之后:** + +![1622112935370](README.imgs/1622112935370.png) + +### Sub Example 2 + +**功能:** 截取`Add_9`到`Add_16`之间的网络。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.trunc_model( + trunc_beg_node_name_list=['Add_9'], + trunc_end_node_name_list=['Add_16'], + new_model_save_path='./test_model/wide_resnet50_2_example_7_2.onnx', +) +``` + +**截取之后:** + +![1622112917399](README.imgs/1622112917399.png) + + + +### Sub Example 3 + +**功能:** 截取一段网络(开始节点为多个,结束节点为多个)。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.trunc_model( + trunc_beg_node_name_list=['Conv_3', 'Conv_8'], + trunc_end_node_name_list=['Add_16', 'Conv_13'], + new_model_save_path='./test_model/wide_resnet50_2_example_7_3.onnx', +) +``` + +**截取之后:** + +![1622113043387](README.imgs/1622113043387.png) + +### Sub Example 4 + +**功能:** 截取一段网络(开始节点为多个,结束节点为多个),并保留Initializer输入。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.trunc_model( + trunc_beg_node_name_list=['Conv_3', 'Conv_8'], + trunc_end_node_name_list=['Add_16', 'Conv_13'], + new_model_save_path='./test_model/wide_resnet50_2_example_7_4.onnx', + keep_input_initializer=True +) +``` + +**说明:**`Conv_3`和`Conv_8`每个节点都有三个输入,但其中两个输入都是常量节点(Initializer),指定`keep_input_initializer=True`参数保留这些常量输入。与**Sub Example 3**对比看区别。 + +**截取之后:** + +![1622113217416](README.imgs/1622113217416.png) + +### Sub Example 5 + +**功能:** 对于比较复杂的截图需求,由用户自己提供截图信息。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.trunc_model( + trunc_beg_node_name_list=['Conv_3', 'Add_9'], + trunc_end_node_name_list=['Conv_101', 'Conv_102'], + new_model_save_path='./test_model/wide_resnet50_2_example_7_5.onnx', + userdef_trunc_beg_node_info_list= + [ + { + 'trunc_beg_node_name': 'Conv_3', + 'new_input_info_list': [ + { + 'input_name': 'new_input_1', + 'dtype': OXDataType.float32, + 'shape': ('-1', 64, 56, 56), + 'input_idx': 0 + } + ] + }, + { + 'trunc_beg_node_name': 'Add_9', + 'new_input_info_list': [ + { + 'input_name': 'new_input_2', + 'dtype': OXDataType.float32, + 'shape': ('-1', 256, 56, 56), + 'input_idx': 1 + } + ] + } + ] +) +``` + +**参数说明:** + +- `'input_idx': 0`指定`new_input_1`作为`Conv_3`的第一个输入; +- `'input_idx': 1`指定`new_input_2`作为`Add_9`的第二个输入; +- `'-1'`:其实是字符串`-1`而不是数字`-1`,也可以是其它任何字符串,比如`'batch_size'`。字符串表示这是动态shape,如果是静态shape,用数字而非字符串,e.g. `'shape': (1, 256, 56, 56)`。模型tensor的shape信息可参考`Example 8`获取。 +- `dtype`:表示数据类型,对应onnx支持的数据类型,这里定义了枚举`OXDataType`,方便用户使用。 + +**分析:** + +开始节点为`Conv_3`和` Add_9`这种类型,自动截图会产生错误的图形,需要用户自己指定截图信息。因为,如果是自动截图,代码判断`Conv_3`节点除常量节点(Initializer)`500`和`501`后,还需要生成一个输入,那么就生成了`new_input_1`这个输入;代码判断`Add_9`有两个输入,因此会自动生成`new_input_2`和`new_input_3`两个输入,然而,`Add_9`的一个输入是`Conv_3`这半边`Conv_7`的输出,那么其实这个自动生成的`new_input_2`是多余的,就会产生错误的图形。 + +**截取之后前边:** + +![1622115648885](README.imgs/1622115648885.png) + +**截取之后后边:** + +![1622115015117](README.imgs/1622115015117.png) + +### Sub Example 6 + +**功能:** 使用官方提供的`extract_model`函数截图。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.extract_model( + input_tensor_name_list=['323'], + output_tensor_name_list=['335'], + new_model_save_path='./test_model/wide_resnet50_2_example_7_6.onnx') +``` + +**截取之后:** + +![1625018717940](README.imgs/1625018717940.png) + +## Example 8:获取shape信息 + +### Sub Example 1 + +**功能:** 获取模型输入、输出、中间tensor、Initializer的信息(包括:tensor名字、shape、类型)。 + +**用途举例:** om的`GatherV2D`算子的`indices`不支持`-1`输入,若onnx中`Gather`算子的`indices`为`-1`,则需要根据获取到的tensor信息修改`indices`的值。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +print(oxgraph.get_input_tensor_info()) +print(oxgraph.get_output_tensor_info()) +print(oxgraph.get_all_tensor_info()) +``` + +### Sub Example 2 + +**功能:** 推导模型各个算子的输出shape信息。 + +**用途:** 有些模型从onnx图中无法看出算子输出shape信息,也无法获取shape信息,通过此函数可以推导出shape信息。 + +**原理:** 用真实数据运行一遍模型,记录各个算子的输出shape信息。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +infer_tensor_info = oxgraph.infer_shape( + input_data_info_list=[{ + 'model_input_name': 'image', + 'shape': '(1, 3, 224, 224)', + 'dtype': 'np.float32' + }]) +print(infer_tensor_info) +``` + +## Example 9:dump模型所有节点的数据 + +**功能:** dump模型所有节点的数据。 + +**用途:** 精度分析。 + +**示例代码:** + +```python +import os +import numpy as np +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +input_data = np.random.rand(1, 3, 224, 224).astype(np.float32) +np.save('./input.npy', input_data) +oxgraph.dump_all_node_data( + input_data_info_list= + [ + { + 'model_input_name': 'image', + 'npy_file_path': './input.npy', + } + ], + dump_data_save_path='./dump_data' +) +os.remove('./input.npy') +``` + +**dump数据:** + +![1622116321331](README.imgs/1622116321331.png) + +## Example 10:新增,删除,修改节点属性 + +### Sub Example 1 + +**功能:** 修改`Conv_0`的`dilations`属性。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxnode = oxgraph.get_oxnode_by_name('Conv_0') +oxnode.set_attribute(attr_name='dilations', attr_value=[2, 2]) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_10_1.onnx') +``` + +**修改之前:** + +![1624938045299](README.imgs/1624938045299.png) + +**修改之后:** + +![1624938080996](README.imgs/1624938080996.png) + +### Sub Example 2 + +**功能:** 给`Conv_0`增加一个属性。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxnode = oxgraph.get_oxnode_by_name('Conv_0') +attr = oxnode.add_attribute(attr_name='new_attr', attr_value=[0, 0]) +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_10_2.onnx') +``` + +**修改之后:** + +![1625040902674](README.imgs/1625040902674.png) + +### Sub Example 3 + +**功能:** 删除`Conv_0`的一个属性。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxnode = oxgraph.get_oxnode_by_name('Conv_0') +attr = oxnode.remove_attribute('dilations') +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_10_3.onnx') +``` + +**修改之前:** + +![1625041088057](README.imgs/1625041088057.png) + +**修改之后:** + +![1625040996328](README.imgs/1625040996328.png) + +## Example 11:删除节点 + +**功能:** 从模型中删除节点。 + +**限制:** 若开启自动连边,则删除的节点必须只有一个前驱节点,否则需要手动连边。另外,若结果不符合预期,也需要自己手动连边。 + +### Sub Example 1 + +**功能**: 删除`Relu_1`并自动连边(`Relu_1`为单输入,单输出)。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.remove_node('Relu_1') +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_11_1.onnx') +``` + +### Sub Example 2 + +**功能**: 删除`Relu_10`并自动连边(`Relu_10`为单输入,多输出)。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') +oxgraph.remove_node('Relu_10') +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_11_2.onnx') +``` + +### Sub Example 3 + +**功能**: 删除`Add_9`和` Relu_10`并手动连边(需要结合模型图查看节点关系)。 + +**示例代码:** + +```python +from OXInterface import OXDataType, OXGraph, OXInitializer, OXNode + +oxgraph = OXGraph('./test_model/wide_resnet50_2.onnx') + +# 删除节点 +oxgraph.remove_node('Add_9', auto_link=False) +oxgraph.remove_node('Relu_10', auto_link=False) + +# 获取删除节点的前后节点 +Conv_7 = oxgraph.get_oxnode_by_name('Conv_7') +Conv_8 = oxgraph.get_oxnode_by_name('Conv_8') +Add_16 = oxgraph.get_oxnode_by_name('Add_16') +Conv_11 = oxgraph.get_oxnode_by_name('Conv_11') + +# 自定义连边 +# Add_16的第1个输入接Conv_7的第0个输出 +# Conv_11的第0个输入接Conv_8的第0个输出 +Add_16.input[1] = Conv_7.output[0] +Conv_11.input[0] = Conv_8.output[0] + +oxgraph.save_new_model('./test_model/wide_resnet50_2_example_11_3.onnx') +``` + +**删除之前:** + +![1624956415448](README.imgs/1624956415448.png) + +**删除之后:** + +![1624956500650](README.imgs/1624956500650.png) diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f7df4387a9af22adbc00090fca6b8ff01497ee40 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/oxinterface/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" @@ -0,0 +1 @@ +https://gitee.com/zhang-dongyu/onnx_tools \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/pyacl_infer/README.md" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/pyacl_infer/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..c99812b47dd50c228f6a9060447489cfb704686d --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/pyacl_infer/README.md" @@ -0,0 +1,77 @@ +# 参数说明 + +- --model_path:模型路径 +- --device_id:npu id +- --cpu_run:MeasureTime类的cpu_run参数,`True` 或 `False`,默认就用`True` +- --sync_infer:推理方式 + - True:同步推理(若要和GPU推理时间做对比,只能用同步推理模式计算时间) + - False:异步推理 +- --workspace:类似TensorRT `workspace`参数,计算平均推理时间时排除前n次推理 +- --input_info_file_path:类似benchmark的bin_info文件 +- --input_dtypes:模型输入的类型,用逗号分割(参考后续类型说明) + - e.g. 模型只有一个输入:`--input_dtypes=float32` + - e.g. 模型有多个输入:`--input_dtypes=float32,float32,float32`(需要和bin_info文件多输入排列一致) +- --infer_res_save_path:推理结果保存目录 +- --res_save_type:推理结果保存类型,`bin`或`npy` + +# 类型说明 + +```python +DTYPE = { + 'float16': np.float16, + 'float32': np.float32, + 'float64': np.float64, + 'int16': np.int16, + 'int32': np.int32, + 'int64': np.int64, + 'uint8': np.uint8, + 'uint16': np.uint16, + 'uint32': np.uint32, + 'uint64': np.uint64 +} +``` + +# bin_info文件说明 + +因为支持动态shape,相比于benchmark的bin_info文件,需要多加一列shape信息,e.g. + +``` +0 ./bert_bin/input_ids_0.bin (1,512) +0 ./bert_bin/segment_ids_0.bin (1,512) +0 ./bert_bin/input_mask_0.bin (1,512) +1 ./bert_bin/input_ids_1.bin (1,512) +1 ./bert_bin/segment_ids_1.bin (1,512) +1 ./bert_bin/input_mask_1.bin (1,512) +``` + +**注意:** shape信息不能加空格,例如:`(1,512)`不能写成`(1, 512)`,后者逗号后边有个空格。 + +# 使用示例 + +1、导入环境变量 + +```shell +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp +``` + +**注意:** `PYTHONPATH`环境变量中要加入`acl`模块的路径`${install_path}/pyACL/python/site-packages/acl`,否则运行脚本会提示无法找到`acl`模块,上述环境变量中已经加入了。 + +2、运行脚本,开始推理 + +```python +python3.7 pyacl_infer.py \ +--model_path=./bert_base_uncased.om \ +--device_id=0 \ +--cpu_run=True \ +--sync_infer=True \ +--workspace=10 \ +--input_info_file_path=./input.info \ +--input_dtypes=int64,int64,int64 \ +--infer_res_save_path=./infer_res \ +--res_save_type=bin +``` + diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/pyacl_infer/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/pyacl_infer/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f7df4387a9af22adbc00090fca6b8ff01497ee40 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/pyacl_infer/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" @@ -0,0 +1 @@ +https://gitee.com/zhang-dongyu/onnx_tools \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/run_profiling/run_profiling.sh" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/run_profiling/run_profiling.sh" new file mode 100644 index 0000000000000000000000000000000000000000..d0993f5bf0c418e1aba36b6cd1060467e8a89c57 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/run_profiling/run_profiling.sh" @@ -0,0 +1,87 @@ +#!/bin/bash + +# 导入环境变量 +export install_path=/usr/local/Ascend/ascend-toolkit/latest +export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH +export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/pyACL/python/site-packages/acl:$PYTHONPATH +export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH +export ASCEND_OPP_PATH=${install_path}/opp + +# usage +if [ $# -ne 4 ] +then + echo "usage: sh run_profiling.sh " + exit 1 +fi + +# 清空终端 +clear +echo "[INFO] Now, run run_profiling.sh ...\n" + +# 变量赋值 +benchmark_path=$1 +om_path=$2 +res_save_path=$3 +device_id=$4 + +# 参数校验 +if [ ! -e $benchmark_path ] +then + echo "'$benchmark_path' not exist!" + exit 1 +fi + +if [ ! -e $om_path ] +then + echo "'$om_path' not exist!" + exit 1 +fi + +if [ $device_id -lt 0 ] +then + echo "'device_id' must >= 0" + exit 1 +fi + +# 删除然后创建结果保存目录 +if [ -e $res_save_path ] +then + rm -rf $res_save_path + mkdir $res_save_path +else + mkdir $res_save_path +fi + +# 运行profiling工具 +# + 推理 +echo "[INFO] Step 1: Infering ..." +$install_path/x86_64-linux/tools/profiler/bin/msprof --output=$res_save_path \ + --sys-hardware-mem=on --sys-cpu-profiling=on --sys-profiling=on --sys-pid-profiling=on --sys-io-profiling=on \ + --dvpp-profiling=off --runtime-api=on --task-time=on --model-execution=on --aicpu=on \ + --application="$benchmark_path --round=10 -om_path=$om_path -device_id=$device_id -batch_size=1" +echo + +# + 分析 +echo "[INFO] Step 2: Analyzing ..." +python3.7 $install_path/toolkit/tools/profiler/profiler_tool/analysis/msprof/msprof.py import \ + -dir $res_save_path +echo + +# + export summary +echo "[INFO] Step 3: Export summary ..." +python3.7 $install_path/toolkit/tools/profiler/profiler_tool/analysis/msprof/msprof.py export summary \ + -dir $res_save_path --iteration-id 1 +echo + +# + export timeline +echo "[INFO] Step 4: Export timeline ..." +python3.7 $install_path/toolkit/tools/profiler/profiler_tool/analysis/msprof/msprof.py export timeline \ + -dir $res_save_path --iteration-id 1 +echo + +# + 删除多余目录 +rm -rf $res_save_path/log $res_save_path/sqlite ./result + +# 结束 +echo "[INFO] Done!" +exit 0 diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/run_profiling/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/run_profiling/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f7df4387a9af22adbc00090fca6b8ff01497ee40 --- /dev/null +++ "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\233\270\345\205\263\345\267\245\345\205\267/run_profiling/\345\267\245\345\205\267Gitee\350\216\267\345\217\226\345\234\260\345\235\200.txt" @@ -0,0 +1 @@ +https://gitee.com/zhang-dongyu/onnx_tools \ No newline at end of file diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/04\343\200\220\347\262\276\345\272\246\350\260\203\344\274\230\343\200\221\357\274\232\347\262\276\345\272\246\345\210\206\346\236\220\346\265\201\347\250\213.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\344\274\230/1. \347\262\276\345\272\246\345\210\206\346\236\220\346\265\201\347\250\213.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/04\343\200\220\347\262\276\345\272\246\350\260\203\344\274\230\343\200\221\357\274\232\347\262\276\345\272\246\345\210\206\346\236\220\346\265\201\347\250\213.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\344\274\230/1. \347\262\276\345\272\246\345\210\206\346\236\220\346\265\201\347\250\213.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/05\343\200\220\347\262\276\345\272\246\350\260\203\344\274\230\343\200\221\357\274\232\344\270\200\346\255\245\345\274\217\347\262\276\345\272\246\346\257\224\345\257\271\345\267\245\345\205\267\344\275\277\347\224\250\346\225\231\347\250\213.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\344\274\230/2. \344\270\200\346\255\245\345\274\217\347\262\276\345\272\246\346\257\224\345\257\271\345\267\245\345\205\267\344\275\277\347\224\250\346\225\231\347\250\213.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/05\343\200\220\347\262\276\345\272\246\350\260\203\344\274\230\343\200\221\357\274\232\344\270\200\346\255\245\345\274\217\347\262\276\345\272\246\346\257\224\345\257\271\345\267\245\345\205\267\344\275\277\347\224\250\346\225\231\347\250\213.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\344\274\230/2. \344\270\200\346\255\245\345\274\217\347\262\276\345\272\246\346\257\224\345\257\271\345\267\245\345\205\267\344\275\277\347\224\250\346\225\231\347\250\213.docx" diff --git "a/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/06\343\200\220\347\262\276\345\272\246\350\260\203\344\274\230\343\200\221\357\274\232OXInterface\344\275\277\347\224\250\346\225\231\347\250\213\357\274\210\344\270\200\345\245\227\346\223\215\344\275\234\347\256\200\345\215\225\347\232\204ONNX\346\224\271\345\233\276\346\216\245\345\217\243\357\274\211.docx" "b/Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\344\274\230/3. OXInterface\344\275\277\347\224\250\346\225\231\347\250\213\357\274\210\344\270\200\345\245\227\346\223\215\344\275\234\347\256\200\345\215\225\347\232\204ONNX\346\224\271\345\233\276\346\216\245\345\217\243\357\274\211.docx" similarity index 100% rename from "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/06\343\200\220\347\262\276\345\272\246\350\260\203\344\274\230\343\200\221\357\274\232OXInterface\344\275\277\347\224\250\346\225\231\347\250\213\357\274\210\344\270\200\345\245\227\346\223\215\344\275\234\347\256\200\345\215\225\347\232\204ONNX\346\224\271\345\233\276\346\216\245\345\217\243\357\274\211.docx" rename to "Ascend-PyTorch\347\246\273\347\272\277\346\216\250\347\220\206\346\214\207\345\257\274/\344\270\223\351\242\230\346\241\210\344\276\213/\347\262\276\345\272\246\350\260\203\344\274\230/3. OXInterface\344\275\277\347\224\250\346\225\231\347\250\213\357\274\210\344\270\200\345\245\227\346\223\215\344\275\234\347\256\200\345\215\225\347\232\204ONNX\346\224\271\345\233\276\346\216\245\345\217\243\357\274\211.docx"