From 1cf4e149df3b44ffd528a655cf93a862aa3088ab Mon Sep 17 00:00:00 2001 From: TAJh Date: Mon, 17 Apr 2023 09:18:56 +0000 Subject: [PATCH 1/4] update msquickcmp/main.py. Signed-off-by: TAJh --- msquickcmp/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msquickcmp/main.py b/msquickcmp/main.py index bb030a53..e0cf992e 100644 --- a/msquickcmp/main.py +++ b/msquickcmp/main.py @@ -18,7 +18,7 @@ from common.utils import AccuracyCompareException from compare.net_compare import NetCompare from npu.npu_dump_data import NpuDumpData - +from npu.npu_dump_data_bin2npy import data_convert def _accuracy_compare_parser(parser): parser.add_argument("-m", "--model-path", dest="model_path", default="", @@ -44,6 +44,8 @@ def _accuracy_compare_parser(parser): " E.g: node_name1:0;node_name2:1;node_name3:0") parser.add_argument("--advisor", dest="advisor", action="store_true", help=" Enable advisor after compare.") + parser.add_argument("--convert", dest = "bin2npy", action="store_true", + help=" Enable npu dump data conversion from bin to npy after compare.") def _generate_golden_data_model(args): @@ -114,6 +116,8 @@ def main(): npu_dump = NpuDumpData(args, output_json_path) npu_dump_data_path, npu_net_output_data_path = npu_dump.generate_dump_data() expect_net_output_node = npu_dump.get_expect_output_name() + # convert data from bin to npy if --convert is used + data_convert(npu_dump_data_path, npu_net_output_data_path, args) # if it's dynamic batch scenario, golden data files should be renamed utils.handle_ground_truth_files(npu_dump.om_parser, npu_dump_data_path, golden_dump_data_path) # compare the entire network -- Gitee From 6f28875911843245d2bb5825b66196dbaf74da5a Mon Sep 17 00:00:00 2001 From: TAJh Date: Sun, 23 Apr 2023 01:26:58 +0000 Subject: [PATCH 2/4] =?UTF-8?q?add=20msquickcmp/npu/npu=5Fdump=5Fdata=5Fbi?= =?UTF-8?q?n2npy.py.=20=E5=A2=9E=E5=8A=A0dump=E6=95=B0=E6=8D=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6bin=E8=BD=ACnpy=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TAJh --- msquickcmp/npu/npu_dump_data_bin2npy.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 msquickcmp/npu/npu_dump_data_bin2npy.py diff --git a/msquickcmp/npu/npu_dump_data_bin2npy.py b/msquickcmp/npu/npu_dump_data_bin2npy.py new file mode 100644 index 00000000..83799e85 --- /dev/null +++ b/msquickcmp/npu/npu_dump_data_bin2npy.py @@ -0,0 +1,34 @@ +import os +import sys + +from common import utils + +MSACCUCMP_FILE_PATH = "toolkit/tools/operator_cmp/compare/msaccucmp.py" + +def data_convert(npu_dump_data_path, npu_net_output_data_path, arguments): + """ + Function Description: + provide the interface for dump data conversion + Exception Description: + when invalid msaccucmp command throw exception + """ + if _check_convert_bin2npy(arguments): + common_path = os.path.commonprefix([npu_dump_data_path, npu_net_output_data_path]) + npu_dump_data_path_diff = os.path.relpath(npu_dump_data_path, common_path) + time_stamp_file_path = npu_dump_data_path_diff.split(os.path.sep)[1] + convert_dir_path = npu_dump_data_path.replace(time_stamp_file_path, time_stamp_file_path+'_bin2npy') + convert_dir_path = os.path.normpath(convert_dir_path) + convert_data_path = _check_data_convert_file(convert_dir_path) + msaccucmp_command_file_path = os.path.join(arguments.cann_path, MSACCUCMP_FILE_PATH) + python_version = sys.executable.split('/')[-1] + bin2npy_cmd = [python_version, msaccucmp_command_file_path,"convert","-d",npu_dump_data_path,"-out",convert_data_path] + utils.execute_command(bin2npy_cmd) + utils.print_info_log("msaccucmp command line: %s "%" ".join(bin2npy_cmd)) + +def _check_data_convert_file(convert_dir_path): + if not os.path.exists(convert_dir_path): + os.makedirs(convert_dir_path) + return convert_dir_path + +def _check_convert_bin2npy(arguments): + return arguments.bin2npy \ No newline at end of file -- Gitee From 601d985e8adc68e587843eef1597ec1dd6213a82 Mon Sep 17 00:00:00 2001 From: TAJh Date: Sun, 23 Apr 2023 01:33:57 +0000 Subject: [PATCH 3/4] =?UTF-8?q?update=20msquickcmp/README.md.=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E--advisor=20=E5=92=8C=20--convert=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TAJh --- msquickcmp/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msquickcmp/README.md b/msquickcmp/README.md index 4b06421b..a5baedec 100644 --- a/msquickcmp/README.md +++ b/msquickcmp/README.md @@ -157,6 +157,8 @@ https://www.hiascend.com/document/detail/zh/canncommercial/60RC1/devtools/auxili | -d,--device | 指定运行设备 [0,255],可选参数,默认0 | 否 | | --output-nodes | 用户指定的输出节点。多个节点用英文分号(;)隔开。例如:node_name1:0;node_name2:1;node_name3:0 | 否 | | --output-size | 指定模型的输出size,有几个输出,就设几个值。动态shape场景下,获取模型的输出size可能为0,用户需根据输入的shape预估一个较合适的值去申请内存。多个输出size用英文分号(,)隔开, 例如"10000,10000,10000"。 | 否 | +| --advisor | 在比对结束后,针对比对结果进行数据分析,给出专家建议 | 否 | +| --convert |支持om比对结果文件数据格式由bin文件转为npy文件,生成的npy文件目录为./dump_data/npu/{时间戳_bin2npy}文件夹 | 否 | ### 执行案例 -- Gitee From 053be3ff31c5e2d22e59d04837ee628e9211de43 Mon Sep 17 00:00:00 2001 From: TAJh Date: Sun, 23 Apr 2023 01:38:09 +0000 Subject: [PATCH 4/4] update msquickcmp/README_EN.md. Signed-off-by: TAJh --- msquickcmp/README_EN.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msquickcmp/README_EN.md b/msquickcmp/README_EN.md index 8bb1d059..2d423a1a 100644 --- a/msquickcmp/README_EN.md +++ b/msquickcmp/README_EN.md @@ -151,6 +151,8 @@ https://www.hiascend.com/document/detail/en/CANNCommunityEdition/60RC1alphaX/dev | -d,--device | Specify running device [0,255], default 0. | No | | --output-nodes | Output node specified by the user. Separate multiple nodes with semicolons, for example, **node_name1:0;node_name2:1;node_name3:0**. | No | | --output-size | Specify the output size of the model. If there are several outputs, set several values. In the dynamic shape scenario, the output size of the acquired model may be 0. The user needs to estimate a more appropriate value according to the input shape to apply for memory. Multiple output sizes are separated by English semicolons (,), such as "10000,10000,10000"。 | No | +| --advisor | After the comparison, datat analysis is performed on the comparison results, and expert advice is given | No | +| --convert | Support om comparison result file data format from bin file to npy file, the generated npy file directory is ./dump_data/npou/{timestamp_bin2npy} folder | No | ### Sample Execution -- Gitee