diff --git a/msquickcmp/README.md b/msquickcmp/README.md index 4b06421b4a42a6e7a8b7f12832257334e0752686..a5baedecb8b2f36b22137bcaa755412187f35ee3 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}文件夹 | 否 | ### 执行案例 diff --git a/msquickcmp/README_EN.md b/msquickcmp/README_EN.md index 8bb1d059da13d37db86f60e1cf16ad2cae40502e..2d423a1a97a58470c77458f68b2eb30e05cccedd 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 diff --git a/msquickcmp/main.py b/msquickcmp/main.py index bb030a53903410be120dd02acd913877dd91dd23..e0cf992e935c535feafdb9412df18386fe767cc4 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 diff --git a/msquickcmp/npu/npu_dump_data_bin2npy.py b/msquickcmp/npu/npu_dump_data_bin2npy.py new file mode 100644 index 0000000000000000000000000000000000000000..83799e851e5ff93148b28c7a4bd00ea2b7740d51 --- /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