diff --git a/debug/accuracy_tools/msprobe/core/common/const.py b/debug/accuracy_tools/msprobe/core/common/const.py index a17288c87fffc763eb193e46ab170354bb35b6af..b4a2083c020b9ecdf33e62d904acd07fe729b87f 100644 --- a/debug/accuracy_tools/msprobe/core/common/const.py +++ b/debug/accuracy_tools/msprobe/core/common/const.py @@ -241,6 +241,7 @@ class Const: NORM = 'Norm' DATA_NAME = 'data_name' STATE = 'state' + REQ_GRAD = 'requires_grad' API_ORIGIN_NAME = 'api_origin_name' TENSOR_STAT_INDEX = 'tensor_stat_index' SUMMARY_METRICS_LIST = [MAX, MIN, MEAN, NORM] @@ -360,22 +361,22 @@ class Const: } def _fused_adamw_( - self, - grads, - exp_avgs, - exp_avg_sqs, - max_exp_avg_sqs, - state_steps, - *, - lr, - beta1, - beta2, - weight_decay, - eps, - amsgrad, - maximize, - grad_scale=None, - found_inf=None + self, + grads, + exp_avgs, + exp_avg_sqs, + max_exp_avg_sqs, + state_steps, + *, + lr, + beta1, + beta2, + weight_decay, + eps, + amsgrad, + maximize, + grad_scale=None, + found_inf=None ): pass @@ -424,6 +425,9 @@ class CompareConst: MIN_RELATIVE_ERR = "MinRelativeErr" MEAN_RELATIVE_ERR = "MeanRelativeErr" NORM_RELATIVE_ERR = "NormRelativeErr" + REQ_GRAD_CONSIST = "Requires_grad Consistent" + NPU_REQ_GRAD = "NPU Requires_grad" + BENCH_REQ_GRAD = "Bench Requires_grad" ACCURACY = "Accuracy Reached or Not" STACK = "NPU_Stack_Info" DATA_NAME = "Data_name" @@ -493,21 +497,21 @@ class CompareConst: ULP_ERR_STATUS = "ulp_err_status" - COMPARE_RESULT_HEADER = [ - NPU_NAME, BENCH_NAME, NPU_DTYPE, BENCH_DTYPE, NPU_SHAPE, BENCH_SHAPE, COSINE, EUC_DIST, - MAX_ABS_ERR, MAX_RELATIVE_ERR, ONE_THOUSANDTH_ERR_RATIO, FIVE_THOUSANDTHS_ERR_RATIO, - NPU_MAX, NPU_MIN, NPU_MEAN, NPU_NORM, BENCH_MAX, BENCH_MIN, BENCH_MEAN, BENCH_NORM, ACCURACY, ERROR_MESSAGE - ] + ALL_COMPARE_INDEX = [COSINE, EUC_DIST, MAX_ABS_ERR, MAX_RELATIVE_ERR, + ONE_THOUSANDTH_ERR_RATIO, FIVE_THOUSANDTHS_ERR_RATIO] + SUMMARY_COMPARE_INDEX = [MAX_DIFF, MIN_DIFF, MEAN_DIFF, NORM_DIFF, + MAX_RELATIVE_ERR, MIN_RELATIVE_ERR, MEAN_RELATIVE_ERR, NORM_RELATIVE_ERR] + MD5_COMPARE_INDEX = [RESULT] - SUMMARY_COMPARE_RESULT_HEADER = [ - NPU_NAME, BENCH_NAME, NPU_DTYPE, BENCH_DTYPE, NPU_SHAPE, BENCH_SHAPE, MAX_DIFF, MIN_DIFF, MEAN_DIFF, NORM_DIFF, - MAX_RELATIVE_ERR, MIN_RELATIVE_ERR, MEAN_RELATIVE_ERR, NORM_RELATIVE_ERR, - NPU_MAX, NPU_MIN, NPU_MEAN, NPU_NORM, BENCH_MAX, BENCH_MIN, BENCH_MEAN, BENCH_NORM, RESULT, ERROR_MESSAGE - ] + BASIC_INFO = [NPU_NAME, BENCH_NAME, NPU_DTYPE, BENCH_DTYPE, NPU_SHAPE, BENCH_SHAPE, NPU_REQ_GRAD, BENCH_REQ_GRAD] + SUMMARY_INFO = [NPU_MAX, NPU_MIN, NPU_MEAN, NPU_NORM, BENCH_MAX, BENCH_MIN, BENCH_MEAN, BENCH_NORM] - MD5_COMPARE_RESULT_HEADER = [ - NPU_NAME, BENCH_NAME, NPU_DTYPE, BENCH_DTYPE, NPU_SHAPE, BENCH_SHAPE, NPU_MD5, BENCH_MD5, RESULT - ] + COMPARE_RESULT_HEADER = BASIC_INFO + ALL_COMPARE_INDEX + SUMMARY_INFO + [REQ_GRAD_CONSIST, ACCURACY, ERROR_MESSAGE] + + SUMMARY_COMPARE_RESULT_HEADER = BASIC_INFO + SUMMARY_COMPARE_INDEX + SUMMARY_INFO + [REQ_GRAD_CONSIST, RESULT, + ERROR_MESSAGE] + + MD5_COMPARE_RESULT_HEADER = BASIC_INFO + [NPU_MD5, BENCH_MD5, REQ_GRAD_CONSIST] + MD5_COMPARE_INDEX COMPARE_RESULT_HEADER_STACK = COMPARE_RESULT_HEADER + [STACK] @@ -521,11 +525,6 @@ class CompareConst: Const.MD5: MD5_COMPARE_RESULT_HEADER } - ALL_COMPARE_INDEX = [COSINE, EUC_DIST, MAX_ABS_ERR, MAX_RELATIVE_ERR, ONE_THOUSANDTH_ERR_RATIO, - FIVE_THOUSANDTHS_ERR_RATIO] - SUMMARY_COMPARE_INDEX = [MAX_DIFF, MIN_DIFF, MEAN_DIFF, NORM_DIFF, - MAX_RELATIVE_ERR, MIN_RELATIVE_ERR, MEAN_RELATIVE_ERR, NORM_RELATIVE_ERR] - # dtype match DTYPE_MATCH_GROUPS = [ @@ -596,7 +595,6 @@ class CompareConst: # error message NO_BENCH = "No bench data matched." - # compare const FLOAT_TYPE = [np.half, np.single, float, np.double, np.float64, np.longdouble] @@ -652,9 +650,11 @@ class CompareConst: OP_NAME_X = 'op_name_x' MATCH_RESULT_COLUMNS = [ - OP_NAME_X, 'dtype_x', 'shape_x', 'summary_x', 'stack_info_x', 'state_x', 'api_origin_name_x', 'data_name_x', + OP_NAME_X, 'dtype_x', 'shape_x', 'summary_x', 'stack_info_x', 'state_x', 'api_origin_name_x', + 'requires_grad_x', 'data_name_x', CMP_KEY, CMP_SHAPE, - 'op_name_y', 'dtype_y', 'shape_y', 'summary_y', 'stack_info_y', 'state_y', 'api_origin_name_y', 'data_name_y' + 'op_name_y', 'dtype_y', 'shape_y', 'summary_y', 'stack_info_y', 'state_y', 'api_origin_name_y', + 'requires_grad_y', 'data_name_y' ] INTERNAL_API_MAPPING_FILE = 'ms_to_pt_api.yaml' diff --git a/debug/accuracy_tools/msprobe/core/compare/acc_compare.py b/debug/accuracy_tools/msprobe/core/compare/acc_compare.py index af9a518ff4f0d38fb336defcf84e3d023bfb2daa..1a76eb91d28e60ebd22d3ad055fd77379cf1a2ae 100644 --- a/debug/accuracy_tools/msprobe/core/compare/acc_compare.py +++ b/debug/accuracy_tools/msprobe/core/compare/acc_compare.py @@ -203,7 +203,8 @@ class ParseData: Const.SUMMARY: [], Const.STACK_INFO: [], Const.STATE: [], - Const.API_ORIGIN_NAME: [] + Const.API_ORIGIN_NAME: [], + Const.REQ_GRAD: [] } if self.mode_config.dump_mode == Const.ALL: result[Const.DATA_NAME] = [] @@ -229,10 +230,9 @@ class ParseData: summary_list = merge_list.get(Const.SUMMARY) data_name_list = merge_list.get(Const.DATA_NAME) state_list = merge_list.get(Const.STATE) - op_name_reorder, summary_reorder, data_name_reorder, state_reorder = reorder_op_x_list(op_name_list, - summary_list, - data_name_list, - state_list) + requires_grad_list = merge_list.get(Const.REQ_GRAD) + op_name_reorder, summary_reorder, data_name_reorder, state_reorder, requires_grad_reorder = ( + reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list, requires_grad_list)) # 遍历单个API的所有item for index, (op_name, state) in enumerate(zip(op_name_reorder, state_reorder)): result[CompareConst.OP_NAME].append(op_name) @@ -252,9 +252,6 @@ class ParseData: check_api_info_len(op_name, struct, 2) result[Const.DTYPE].append(struct[0]) result[Const.SHAPE].append(struct[1]) - if self.mode_config.dump_mode == Const.MD5: - check_api_info_len(op_name, struct, 3) - result[Const.MD5].append(struct[2]) check_api_info_len(op_name, summary_reorder, 1) result[Const.SUMMARY].append(summary_reorder.pop(0)) @@ -265,12 +262,18 @@ class ParseData: else: result[Const.STACK_INFO].append(None) + if self.mode_config.dump_mode == Const.MD5: + check_api_info_len(op_name, struct, 3) + result[Const.MD5].append(struct[2]) if self.mode_config.dump_mode == Const.ALL: check_api_info_len(op_name, data_name_reorder, 1) result[Const.DATA_NAME].append(data_name_reorder.pop(0)) result[Const.STATE].append(state) result[Const.API_ORIGIN_NAME].append(data_name) + check_api_info_len(op_name, requires_grad_reorder, 1) + result[Const.REQ_GRAD].append(requires_grad_reorder.pop(0)) + progress_bar.update(1) progress_bar.close() return pd.DataFrame(result) @@ -641,12 +644,19 @@ class CreateTable: 'data_name_x': CompareConst.DATA_NAME, 'stack_info_x': CompareConst.STACK, 'state_x': Const.STATE, - 'api_origin_name_x': Const.API_ORIGIN_NAME}, inplace=True) + 'api_origin_name_x': Const.API_ORIGIN_NAME, + 'requires_grad_x': CompareConst.NPU_REQ_GRAD, + 'requires_grad_y': CompareConst.BENCH_REQ_GRAD + }, + inplace=True) # process summary data npu_summary = [CompareConst.NPU_MAX, CompareConst.NPU_MIN, CompareConst.NPU_MEAN, CompareConst.NPU_NORM] bench_summary = [CompareConst.BENCH_MAX, CompareConst.BENCH_MIN, CompareConst.BENCH_MEAN, CompareConst.BENCH_NORM] + # process requires_grad + result[CompareConst.REQ_GRAD_CONSIST] = result[CompareConst.NPU_REQ_GRAD] == result[CompareConst.BENCH_REQ_GRAD] + if result.empty: result[npu_summary] = pd.DataFrame(columns=npu_summary) result[bench_summary] = pd.DataFrame(columns=bench_summary) @@ -717,6 +727,7 @@ class CalcStatsDiff: condition_no_bench = result_df[CompareConst.BENCH_NAME] == CompareConst.N_A result_df[condition_no_bench] = result_df[condition_no_bench].fillna(CompareConst.N_A) result_df.loc[condition_no_bench, CompareConst.ERROR_MESSAGE] = CompareConst.NO_BENCH + condition_req_grad_consist = result_df[CompareConst.NPU_REQ_GRAD] == result_df[CompareConst.BENCH_REQ_GRAD] if self.mode_config.dump_mode == Const.MD5: condition_md5_equal = result_df[CompareConst.NPU_MD5] == result_df[CompareConst.BENCH_MD5] @@ -730,14 +741,16 @@ class CalcStatsDiff: warning_flag = pd.DataFrame(warning_list).any() result_df.loc[~condition_no_bench, [CompareConst.RESULT, CompareConst.ERROR_MESSAGE]] = '' result_df.loc[warning_flag, CompareConst.RESULT] = CompareConst.WARNING - result_df.loc[warning_flag, CompareConst.ERROR_MESSAGE] = 'Need double check api accuracy.' + result_df.loc[warning_flag, CompareConst.ERROR_MESSAGE] = 'Need double check api accuracy. ' + result_df.loc[~condition_req_grad_consist, CompareConst.ERROR_MESSAGE] += 'Requires_grad inconsistent. ' else: fill_cols = [CompareConst.COSINE, CompareConst.EUC_DIST, CompareConst.MAX_ABS_ERR, CompareConst.MAX_RELATIVE_ERR, CompareConst.ONE_THOUSANDTH_ERR_RATIO, CompareConst.FIVE_THOUSANDTHS_ERR_RATIO, CompareConst.ERROR_MESSAGE] - result_df.loc[~condition_no_bench, fill_cols] = '' + result_df.loc[~condition_no_bench, fill_cols] = '' # 默认填充'', df默认省缺值为nan,不便后续处理,容易出现意外情况 result_df.loc[~condition_no_bench, CompareConst.ACCURACY] = CompareConst.ACCURACY_CHECK_YES + result_df.loc[~condition_req_grad_consist, CompareConst.ERROR_MESSAGE] = 'Requires_grad inconsistent. ' return result_df[header] diff --git a/debug/accuracy_tools/msprobe/core/compare/highlight.py b/debug/accuracy_tools/msprobe/core/compare/highlight.py index 25eea7a5b43196819a974009cc7783f6275ea190..6a48278d6b7c8ce2c7f054fb640558ae677e6b4d 100644 --- a/debug/accuracy_tools/msprobe/core/compare/highlight.py +++ b/debug/accuracy_tools/msprobe/core/compare/highlight.py @@ -138,12 +138,25 @@ class CheckOverflow(HighlightCheck): add_highlight_row_info(color_columns.red, num, "maximum absolute error exceeds 1e+10") +class CheckReqGradConsist(HighlightCheck): + """检查requires_grad是否一致""" + + def apply(self, info, color_columns, dump_mode): + line, num = info + req_grad_consist_index = get_header_index(CompareConst.REQ_GRAD_CONSIST, dump_mode) + if not line[req_grad_consist_index]: + add_highlight_row_info(color_columns.yellow, num, "requires_grad is inconsistent") + + class HighlightRules: """高亮规则集合,用于检查API的误差""" # 适用于每行的规则 basic_rules = { "check_overflow": CheckOverflow() } + consist_rules = { + "check_req_grad_consist": CheckReqGradConsist() + } # 用于比较输入和输出的规则 # 真实数据检查规则 @@ -176,7 +189,7 @@ class HighLight: if CompareConst.NPU_MD5 in result_df.columns: return - err_msg = result_df.get(CompareConst.ERROR_MESSAGE) + err_msg = result_df.get(CompareConst.ERROR_MESSAGE).copy() red_lines_num_set = highlight_dict.get('red_rows') for color in ['red', 'yellow']: @@ -268,6 +281,13 @@ class HighLight: api_info = ApiInfo(api_input=api_in, api_output=api_out, num_pointer=index) self.apply_comparison_rules(api_info, color_columns) + # 对单行API的输入或输出进行requires_grad是否一致判断 + for i, line in enumerate(result): + index = api_batch_start + i + line_info = LineInfo(line_data=line, num_pointer=index) + for rule in HighlightRules.consist_rules.values(): + rule.apply(line_info, color_columns, self.mode_config.dump_mode) + red_lines_num_set = {x[0] for x in red_lines} yellow_lines_num_set = {x[0] for x in yellow_lines} highlight_dict.get('red_rows', set()).update(red_lines_num_set) diff --git a/debug/accuracy_tools/msprobe/core/compare/merge_result/merge_result.py b/debug/accuracy_tools/msprobe/core/compare/merge_result/merge_result.py index 855c4cef2427dfe2a22e5d6792e0e50da942ac2d..97ddc7ba22e4e8a122e5006f1f6acbe6712ab004 100644 --- a/debug/accuracy_tools/msprobe/core/compare/merge_result/merge_result.py +++ b/debug/accuracy_tools/msprobe/core/compare/merge_result/merge_result.py @@ -109,8 +109,8 @@ def check_index_dump_mode_consistent(dump_mode, rank_num): return [] dump_mode_compare_index_map = { - Const.ALL: CompareConst.ALL_COMPARE_INDEX, - Const.SUMMARY: CompareConst.SUMMARY_COMPARE_INDEX + Const.ALL: CompareConst.ALL_COMPARE_INDEX + [CompareConst.REQ_GRAD_CONSIST], + Const.SUMMARY: CompareConst.SUMMARY_COMPARE_INDEX + [CompareConst.REQ_GRAD_CONSIST] } valid_compare_index = dump_mode_compare_index_map.get(dump_mode) diff --git a/debug/accuracy_tools/msprobe/core/compare/multiprocessing_compute.py b/debug/accuracy_tools/msprobe/core/compare/multiprocessing_compute.py index 19c66e83e98c683db970397c73305c0b8ea530e2..12b253e16a0bd68e5c8ab3ae13ec832aa374dcae 100644 --- a/debug/accuracy_tools/msprobe/core/compare/multiprocessing_compute.py +++ b/debug/accuracy_tools/msprobe/core/compare/multiprocessing_compute.py @@ -136,7 +136,7 @@ class CompareRealData: result.five_thousand_err_ratio_result)[i] result_df.loc[process_index, CompareConst.ACCURACY] = ( check_accuracy(result.cos_result[i], result.max_err_result[i])) - result_df.loc[process_index, CompareConst.ERROR_MESSAGE] = result.err_msgs[i] + result_df.loc[process_index, CompareConst.ERROR_MESSAGE] += result.err_msgs[i] return result_df except ValueError as e: logger.error('result dataframe is not found.') @@ -228,10 +228,11 @@ class CompareRealData: logger.info(f"[{npu_op_name}] Compare result: {err_msg} ") else: logger.info( - "[{}] Compare result: cosine {}, max_abs_err {}, max_relative_err {}, {}, \ - one_thousand_err_ratio {}, " - "five_thousand_err_ratio {}".format(npu_op_name, cos_sim, max_abs_err, max_relative_err, - err_msg, one_thousand_err_ratio, five_thousand_err_ratio)) + f"[{npu_op_name}] Compare result: cosine {cos_sim}, euc_dist {euc_dist}, " + f"max_abs_err {max_abs_err}, max_relative_err {max_relative_err}, " + f"one_thousand_err_ratio {one_thousand_err_ratio}, " + f"five_thousand_err_ratio {five_thousand_err_ratio}, {err_msg}" + ) cos_result.append(cos_sim) euc_dist_result.append(euc_dist) max_err_result.append(max_abs_err) diff --git a/debug/accuracy_tools/msprobe/core/compare/utils.py b/debug/accuracy_tools/msprobe/core/compare/utils.py index c0b0783da9ba6e83a51c5eb2e6224cef00b0a8b1..e64c403271ca07ca1ce7684e617e2c649ba9d703 100644 --- a/debug/accuracy_tools/msprobe/core/compare/utils.py +++ b/debug/accuracy_tools/msprobe/core/compare/utils.py @@ -115,17 +115,18 @@ def op_item_parse(op_data, op_name: str, state: str, depth: int = 0) -> list: state = Const.INPUT default_item = { 'full_op_name': op_name, - 'type': None, - 'Max': None, - 'Min': None, - 'Mean': None, - 'Norm': None, - 'dtype': None, - 'shape': None, - 'md5': None, - 'value': None, - 'data_name': '-1', - 'state': state + Const.TYPE: None, + Const.MAX: None, + Const.MIN: None, + Const.MEAN: None, + Const.NORM: None, + Const.DTYPE: None, + Const.SHAPE: None, + Const.MD5: None, + Const.VALUE: None, + Const.DATA_NAME: '-1', + Const.STATE: state, + Const.REQ_GRAD: None } if depth > Const.MAX_DEPTH: @@ -163,6 +164,8 @@ def gen_op_item(op_data, op_name, state): op_item[Const.DATA_NAME] = data_name op_item['full_op_name'] = data_name.rsplit(Const.SEP, 1)[0] if data_name != '-1' else op_name op_item[Const.STATE] = state + if Const.REQ_GRAD not in op_item: + op_item[Const.REQ_GRAD] = None # 补齐统计量字段 params = [Const.MAX, Const.MIN, Const.MEAN, Const.NORM] @@ -224,12 +227,13 @@ def merge_tensor(tensor_list, dump_mode): CompareConst.DEBUG_STRUCT, Const.SUMMARY, Const.STACK_INFO, - Const.STATE + Const.STATE, + Const.REQ_GRAD ] op_dict = {key: [] for key in keys} if dump_mode == Const.ALL: - op_dict["data_name"] = [] + op_dict[Const.DATA_NAME] = [] for tensor in tensor_list: # A dict(len=2) with 'full_op_name' and 'full_info' is added to the tensor only if self.stack_mode is True @@ -240,6 +244,7 @@ def merge_tensor(tensor_list, dump_mode): op_dict[CompareConst.OP_NAME].append(tensor.get('full_op_name')) state = tensor.get(Const.STATE) op_dict[Const.STATE].append(state) + op_dict[Const.REQ_GRAD].append(tensor.get(Const.REQ_GRAD)) struct_key = CompareConst.STATE_TO_STRUCT_MAPPING.get(state) if not struct_key: @@ -254,7 +259,7 @@ def merge_tensor(tensor_list, dump_mode): [str(tensor[key]) if tensor[key] is None else tensor[key] for key in Const.SUMMARY_METRICS_LIST]) if dump_mode == Const.ALL: - op_dict["data_name"].append(tensor['data_name']) + op_dict[Const.DATA_NAME].append(tensor.get(Const.DATA_NAME)) if not op_dict[CompareConst.KWARGS_STRUCT]: del op_dict[CompareConst.KWARGS_STRUCT] @@ -372,23 +377,25 @@ def reorder_op_name_list(op_name_list, state_list): return op_name_reorder, state_reorder -def reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list): +def reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list, requires_grad_list): """ - 对op_name, summary, data_name, state重新排序,把parameters放到input后output前,data_name由于统计量比对时,为None,单独处理 + 对op_name, summary, data_name, state, requires_grad重新排序, + 把parameters放到input后output前,data_name由于统计量比对时,为None,单独处理 """ if not op_name_list or not summary_list: - return op_name_list, summary_list, data_name_list, state_list + return op_name_list, summary_list, data_name_list, state_list, requires_grad_list index_map = {name: index for index, name in enumerate(op_name_list)} - op_name_reorder, state_order = reorder_op_name_list(op_name_list, state_list) + op_name_reorder, state_reorder = reorder_op_name_list(op_name_list, state_list) summary_reorder = [summary_list[index_map.get(name)] for name in op_name_reorder] + requires_grad_reorder = [requires_grad_list[index_map.get(name)] for name in op_name_reorder] if data_name_list: data_name_reorder = [data_name_list[index_map.get(name)] for name in op_name_reorder] else: data_name_reorder = data_name_list - return op_name_reorder, summary_reorder, data_name_reorder, state_order + return op_name_reorder, summary_reorder, data_name_reorder, state_reorder, requires_grad_reorder def process_summary_data(summary_data): @@ -442,17 +449,22 @@ def stack_column_process(result_item, has_stack, index, key, npu_stack_info): return result_item -def result_item_init(n_info, b_info, dump_mode): +def result_item_init(n_info, b_info, requires_grad_pair, dump_mode): n_len = len(n_info.struct) b_len = len(b_info.struct) + # requires_grad_pair内部创建,固定两个元素 + n_requires_grad = requires_grad_pair[0] + b_requires_grad = requires_grad_pair[1] + req_grad_consist = n_requires_grad == b_requires_grad struct_long_enough = (n_len > 2 and b_len > 2) if dump_mode == Const.MD5 else (n_len > 1 and b_len > 1) if struct_long_enough: result_item = [ - n_info.name, b_info.name, n_info.struct[0], b_info.struct[0], n_info.struct[1], b_info.struct[1] + n_info.name, b_info.name, n_info.struct[0], b_info.struct[0], n_info.struct[1], b_info.struct[1], + n_requires_grad, b_requires_grad ] if dump_mode == Const.MD5: md5_compare_result = CompareConst.PASS if n_info.struct[2] == b_info.struct[2] else CompareConst.DIFF - result_item.extend([n_info.struct[2], b_info.struct[2], md5_compare_result]) + result_item.extend([n_info.struct[2], b_info.struct[2], req_grad_consist, md5_compare_result]) elif dump_mode == Const.SUMMARY: result_item.extend([" "] * 8) # 8个统计量数据情况的比对指标 else: @@ -498,11 +510,15 @@ def get_accuracy(result, n_dict, b_dict, dump_mode): b_name = safe_get_value(b_dict, b_start + index, "b_dict", key="op_name") n_struct = safe_get_value(n_dict, index, "n_dict", key=key) b_struct = safe_get_value(b_dict, index, "b_dict", key=key) + n_requires_grad = safe_get_value(n_dict, n_start + index, "n_dict", key='requires_grad') + b_requires_grad = safe_get_value(b_dict, b_start + index, "b_dict", key='requires_grad') + requires_grad_pair = [n_requires_grad, b_requires_grad] + req_grad_consist = n_requires_grad == b_requires_grad err_msg = "" npu_info = ApiItemInfo(n_name, n_struct, npu_stack_info) bench_info = ApiItemInfo(b_name, b_struct, bench_stack_info) - result_item = result_item_init(npu_info, bench_info, dump_mode) + result_item = result_item_init(npu_info, bench_info, requires_grad_pair, dump_mode) if dump_mode == Const.MD5: result_item = stack_column_process(result_item, has_stack, index, key, npu_stack_info) @@ -518,6 +534,8 @@ def get_accuracy(result, n_dict, b_dict, dump_mode): result_item, accuracy_check, err_msg = get_rela_diff_summary_mode(result_item, npu_summary_data, bench_summary_data, err_msg) + result_item.append(req_grad_consist) + err_msg += "Requires_grad inconsistent." if not req_grad_consist else "" result_item.append(accuracy_check if dump_mode == Const.SUMMARY else CompareConst.ACCURACY_CHECK_YES) result_item.append(err_msg) result_item = stack_column_process(result_item, has_stack, index, key, npu_stack_info) @@ -531,23 +549,30 @@ def get_accuracy(result, n_dict, b_dict, dump_mode): if n_len > b_len: for index in range(b_len, n_len): try: - n_name = n_dict['op_name'][n_start + index] - n_struct = n_dict[key][index] + n_name = safe_get_value(n_dict, n_start + index, "n_dict", key="op_name") + n_struct = safe_get_value(n_dict, index, "n_dict", key=key) + n_requires_grad = safe_get_value(n_dict, n_start + index, "n_dict", key='requires_grad') + if dump_mode == Const.MD5: result_item = [ n_name, CompareConst.NAN, n_struct[0], CompareConst.NAN, n_struct[1], CompareConst.NAN, - n_struct[2], CompareConst.NAN, CompareConst.NAN + n_requires_grad, CompareConst.NAN, + n_struct[2], CompareConst.NAN, + False, + CompareConst.NAN ] result.append(result_item) continue result_item = [ n_name, CompareConst.NAN, n_struct[0], CompareConst.NAN, n_struct[1], CompareConst.NAN, + n_requires_grad, CompareConst.NAN, " ", " ", " ", " ", " ", " " ] summary_data = n_dict.get(CompareConst.SUMMARY)[n_start + index] result_item.extend(summary_data) summary_data = [CompareConst.NAN for _ in range(len(n_dict.get(CompareConst.SUMMARY)[0]))] result_item.extend(summary_data) + result_item.append(False) except IndexError as e: err_msg = "index out of bounds error occurs, please check!\n" \ f"n_dict is {n_dict}" diff --git a/debug/accuracy_tools/msprobe/docs/10.accuracy_compare_PyTorch.md b/debug/accuracy_tools/msprobe/docs/10.accuracy_compare_PyTorch.md index b4a0eb6ae4e603518e516390f1aecfe5283850dc..20a85c18d78c92210d9617607d9da9b8569a1bd0 100644 --- a/debug/accuracy_tools/msprobe/docs/10.accuracy_compare_PyTorch.md +++ b/debug/accuracy_tools/msprobe/docs/10.accuracy_compare_PyTorch.md @@ -203,27 +203,28 @@ PyTorch 精度比对是以 CPU 或 GPU 的计算结果为标杆,通过计算 **公共表头**: -|dump 数据模式|NPU Name (NPU 的 API 名)|Bench Name (bench 的 API 名)|NPU Dtype (NPU 数据类型)|Bench Dtype (bench 数据类型)|NPU Tensor Shape (NPU 张量形状)|Bench Tensor Shape (bench 张量形状)| -|:-:|:-:|:-:|:-:|:-:|:-:|:-:| -|真实数据模式|√|√|√|√|√|√| -|统计数据模式|√|√|√|√|√|√| -|MD5 模式|√|√|√|√|√|√| +|dump 数据模式|NPU Name (NPU 的 API 名)|Bench Name (bench 的 API 名)|NPU Dtype (NPU 数据类型)|Bench Dtype (bench 数据类型)|NPU Tensor Shape (NPU 张量形状)|Bench Tensor Shape (bench 张量形状)| NPU Requires_grad (NPU tensor是否计算梯度) | Bench Requires_grad (Bench tensor是否计算梯度) | +|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:------------------------------------:|:----------------------------------------:| +|真实数据模式|√|√|√|√|√|√| √ | √ | +|统计数据模式|√|√|√|√|√|√| √ | √ | +|MD5 模式|√|√|√|√|√|√| √ | √ | **个性表头**: 统计量有 4 种:最大值(max)、最小值(min)、平均值(mean)和 L2-范数(L2 norm)。 -|dump 数据模式|Cosine (tensor 余弦相似度)|EucDist (tensor 欧式距离)|MaxAbsErr (tensor 最大绝对误差)|MaxRelativeErr (tensor 最大相对误差)|One Thousandth Err Ratio (tensor 相对误差小于千分之一的比例)|Five Thousandth Err Ratio (tensor 相对误差小于千分之五的比例)|NPU 和 bench 的统计量绝对误差 (max, min, mean, L2 norm) diff| NPU 和 bench 的统计量相对误差 (max, min, mean, L2 norm) RelativeErr |NPU 和 bench 的统计量 (max, min, mean, L2 norm)|NPU MD5 (NPU 数据 CRC-32 值)|BENCH MD5 (bench 数据 CRC-32 值)|Result (比对结果)|Accuracy Reached or Not (计算精度是否达标)|Err_message (错误信息提示)|NPU_Stack_Info (堆栈信息)| Data_Name ([NPU真实数据名,Bench真实数据名]) | -|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---------------------------------:| -|真实数据模式|√|√|√|√|√|√|||√||||√|√|√| √ | -|统计数据模式|||||||√|√|√|||√||√|√| | -|MD5 模式||||||||||√|√|√|||√| | +|dump 数据模式|Cosine (tensor 余弦相似度)|EucDist (tensor 欧式距离)|MaxAbsErr (tensor 最大绝对误差)|MaxRelativeErr (tensor 最大相对误差)|One Thousandth Err Ratio (tensor 相对误差小于千分之一的比例)|Five Thousandth Err Ratio (tensor 相对误差小于千分之五的比例)|NPU 和 bench 的统计量绝对误差 (max, min, mean, L2 norm) diff| NPU 和 bench 的统计量相对误差 (max, min, mean, L2 norm) RelativeErr |NPU 和 bench 的统计量 (max, min, mean, L2 norm)|NPU MD5 (NPU 数据 CRC-32 值)|BENCH MD5 (bench 数据 CRC-32 值)| Requires_grad Consistent (计算梯度是否一致) | Result (比对结果) |Accuracy Reached or Not (计算精度是否达标)|Err_message (错误信息提示)|NPU_Stack_Info (堆栈信息)| Data_Name ([NPU真实数据名,Bench真实数据名]) | +|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:-----------------------------------:|:-------------:|:---:|:---:|:---:|:---------------------------------:| +|真实数据模式|√|√|√|√|√|√|||√||| √ | |√|√|√| √ | +|统计数据模式|||||||√|√|√||| √ | √ ||√|√| | +|MD5 模式||||||||||√|√| √ | √ |||√| | 上表中NPU_Stack_Info字段需要配置-s参数生成。 ### 3.2 颜色标记——真实数据模式、统计数据模式 通过在命令行中配置-hl或--highlight开启,或者在比对函数中配置参数highlight=True开启,用于标记精度可疑API或模块。开启后,比对性能会有降低,建议比对较大dump.json文件时不配置此参数。 +颜色标记分为红色标记和黄色标记,红色标记优先级高于黄色标记。 在比对结果中的Err_message列呈现比对结果颜色标记的原因,具体含义如下: 红色标记情况: @@ -232,11 +233,12 @@ PyTorch 精度比对是以 CPU 或 GPU 的计算结果为标杆,通过计算 3. 一个 API 或模块的 One Thousandth Err Ratio 的 input/parameters > 0.9 同时 output < 0.6(真实数据模式)(仅标记output); 4. 一个 API 或模块的 output 的最大值相对误差 (Max diff 除以 max(0.01, Bench max)) > 0.5(统计数据模式)(仅标记output)。 -黄色标记情况(仅标记output): +黄色标记情况(1-4仅标记output,5无限制): 1. 一个 API 或模块的 input/parameters 与 output 的最大值绝对误差都大于 1,同时 output 比 input/parameters 大一个数量级以上(真实数据模式、统计数据模式); 2. 一个 API 或模块的 One Thousandth Err Ratio 的 input/parameters - output > 0.1(真实数据模式); 3. 一个 API 或模块的 output 的最大值相对误差 > 0.1 同时 input/parameters < 0.01(真实数据模式,统计数据模式); -4. 一个 API 或模块的 Cosine 的 input/parameters - output > 0.1(真实数据模式)。 +4. 一个 API 或模块的 Cosine 的 input/parameters - output > 0.1(真实数据模式); +5. 一个 API 或模块的 Requires_grad Consistent 为 False。 ### 3.3 比对结果(Result)——统计数据模式、MD5 模式 @@ -281,8 +283,9 @@ MD5 模式: 9. "Shape of NPU and bench Tensor do not match. Skipped.":NPU 和 Bench 的数据结构不一致(真实数据模式); 10. "The Position of inf or nan in NPU and bench Tensor do not match.":NPU 和 Bench 的数据有 nan/inf(真实数据模式); 11. "This is type of 0-d tensor, can not calculate 'Cosine', 'EucDist', 'One Thousandth Err Ratio' and 'Five Thousandths Err Ratio'.":NPU 为0维张量(真实数据模式); -12. "Dtype of NPU and bench Tensor do not match.":NPU 和 Bench 数据的数据类型不同(真实数据模式); -13. "":除以上情况的其余情况(真实数据模式、统计数据模式)。 +12. "Dtype of NPU and bench Tensor do not match.":NPU 和 Bench 数据的数据类型不同(真实数据模式); +13. "Requires_grad inconsistent.":NPU 和 Bench 的 Requires_grad 不一致(真实数据模式,统计数据模式); +14. "":除以上情况的其余情况(真实数据模式、统计数据模式)。 除以上错误信息提示外,异常数据颜色高亮标记的原因叠加呈现于此列。 @@ -341,10 +344,10 @@ compare_index: - MeanRelativeErr ``` -| 参数名 | 说明 | -| ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| api | 表示需要汇总的API或module名称。如果没有配置,工具会提示报错。
api名称配置格式为:`{api_type}.{api_name}.{API调用次数}.{前向反向}`
须按顺序配置以上四个字段,可按如下组合配置:
{api_type}
{api_type}.{api_name}
{api_type}.{api_name}.{API调用次数}
{api_type}.{api_name}.{API调用次数}.{前向反向}
这里的api指代API或module。 | -| compare_index | 表示需要汇总的比对指标。compare_index需为dump_mode对应比对指标的子集。如果没有配置,工具将根据比对结果自动提取dump_mode对应的全部比对指标进行汇总。
统计数据模式比对指标:Max diff、Min diff、Mean diff、L2norm diff、MaxRelativeErr、MinRelativeErr、MeanRelativeErr、NormRelativeErr
真实数据模式比对指标:Cosine、EucDist、MaxAbsErr、MaxRelativeErr、One Thousandth Err Ratio、Five Thousandths Err Ratio | +| 参数名 | 说明 | +| ------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| api | 表示需要汇总的API或module名称。如果没有配置,工具会提示报错。
api名称配置格式为:`{api_type}.{api_name}.{API调用次数}.{前向反向}`
须按顺序配置以上四个字段,可按如下组合配置:
{api_type}
{api_type}.{api_name}
{api_type}.{api_name}.{API调用次数}
{api_type}.{api_name}.{API调用次数}.{前向反向}
这里的api指代API或module。 | +| compare_index | 表示需要汇总的比对指标。compare_index需为dump_mode对应比对指标的子集。如果没有配置,工具将根据比对结果自动提取dump_mode对应的全部比对指标进行汇总。
统计数据模式比对指标:Max diff、Min diff、Mean diff、L2norm diff、MaxRelativeErr、MinRelativeErr、MeanRelativeErr、NormRelativeErr、Requires_grad Consistent
真实数据模式比对指标:Cosine、EucDist、MaxAbsErr、MaxRelativeErr、One Thousandth Err Ratio、Five Thousandths Err Ratio、Requires_grad Consistent | **汇总结果件说明** diff --git a/debug/accuracy_tools/msprobe/docs/11.accuracy_compare_MindSpore.md b/debug/accuracy_tools/msprobe/docs/11.accuracy_compare_MindSpore.md index dcd53eab47cd0a4ca0c42e15e5ea5e27361e9cb5..15020fdc58009c92c3c3f215bdfff5f8f63fab7e 100644 --- a/debug/accuracy_tools/msprobe/docs/11.accuracy_compare_MindSpore.md +++ b/debug/accuracy_tools/msprobe/docs/11.accuracy_compare_MindSpore.md @@ -245,10 +245,10 @@ compare_index: - MeanRelativeErr ``` -| 参数名 | 说明 | -| ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| api | 表示需要汇总的API或module名称。如果没有配置,工具会提示报错。
api名称配置格式为:`{api_type}.{api_name}.{API调用次数}.{前向反向}`
须按顺序配置以上四个字段,可按如下组合配置:
{api_type}
{api_type}.{api_name}
{api_type}.{api_name}.{API调用次数}
{api_type}.{api_name}.{API调用次数}.{前向反向}
这里的api指代API或module。 | -| compare_index | 表示需要汇总的比对指标。compare_index需为dump_mode对应比对指标的子集。如果没有配置,工具将根据比对结果自动提取dump_mode对应的全部比对指标进行汇总。
统计数据模式比对指标:Max diff、Min diff、Mean diff、L2norm diff、MaxRelativeErr、MinRelativeErr、MeanRelativeErr、NormRelativeErr
真实数据模式比对指标:Cosine、EucDist、MaxAbsErr、MaxRelativeErr、One Thousandth Err Ratio、Five Thousandths Err Ratio | +| 参数名 | 说明 | +| ------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| api | 表示需要汇总的API或module名称。如果没有配置,工具会提示报错。
api名称配置格式为:`{api_type}.{api_name}.{API调用次数}.{前向反向}`
须按顺序配置以上四个字段,可按如下组合配置:
{api_type}
{api_type}.{api_name}
{api_type}.{api_name}.{API调用次数}
{api_type}.{api_name}.{API调用次数}.{前向反向}
这里的api指代API或module。 | +| compare_index | 表示需要汇总的比对指标。compare_index需为dump_mode对应比对指标的子集。如果没有配置,工具将根据比对结果自动提取dump_mode对应的全部比对指标进行汇总。
统计数据模式比对指标:Max diff、Min diff、Mean diff、L2norm diff、MaxRelativeErr、MinRelativeErr、MeanRelativeErr、NormRelativeErr、Requires_grad Consistent
真实数据模式比对指标:Cosine、EucDist、MaxAbsErr、MaxRelativeErr、One Thousandth Err Ratio、Five Thousandths Err Ratio、Requires_grad Consistent | **汇总结果件说明** diff --git a/debug/accuracy_tools/msprobe/docs/img/compare_result.png b/debug/accuracy_tools/msprobe/docs/img/compare_result.png index b321ebed8c7ea04357b57da81cc31ee038d4b94f..3c226d38c362416dc441fe4a48aa30f19d137c41 100644 Binary files a/debug/accuracy_tools/msprobe/docs/img/compare_result.png and b/debug/accuracy_tools/msprobe/docs/img/compare_result.png differ diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare.py index 1f7c515a59b5c13edcae4e890e7054d55984280f..451eb9badf9d9d8a6c30af2b8bdbd01de2580acb 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare.py @@ -351,7 +351,8 @@ class TestUtilsMethods(unittest.TestCase): 'params_grad_struct': [], 'stack_info': [['File']], 'summary': [[1, 1, 1, 1]], - 'state': ['input'] + 'state': ['input'], + 'requires_grad': ['False'] } config_dict = { @@ -399,8 +400,9 @@ class TestUtilsMethods(unittest.TestCase): result = comparator.compare_statistics(file_list) o_data = [ ['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', '[2, 2]', '[2, 2]', 0, 0, 0, 0, '0.0%', 'N/A', '0.0%', '0.0%', - 2, 0, 1, 1, 2, 0, 1, 1, '', '', ['File'], 'input', 'Functional.linear.0.forward' + 'torch.float32', 'torch.float32', '[2, 2]', '[2, 2]', 'False', 'False', + 0, 0, 0, 0, '0.0%', 'N/A', '0.0%', '0.0%', 2, 0, 1, 1, 2, 0, 1, 1, + True, '', '', ['File'], 'input', 'Functional.linear.0.forward' ] ] columns = CompareConst.SUMMARY_COMPARE_RESULT_HEADER + ['NPU_Stack_Info'] + ['state', 'api_origin_name'] @@ -432,8 +434,9 @@ class TestParseData(unittest.TestCase): npu_df, bench_df = parse_data.parse(file_list) target_df = pd.DataFrame( - [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward']], - columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name'] + [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], + [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward', 'False']], + columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'requires_grad'] ) self.assertTrue(npu_df.equals(target_df)) self.assertTrue(bench_df.equals(target_df)) @@ -450,8 +453,9 @@ class TestParseData(unittest.TestCase): npu_df = parse_data.gen_data_df(npu_json_data, stack_json_data) target_df = pd.DataFrame( - [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward']], - columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name'] + [['Functional.linear.0.forward.input.0', 'torch.float32', + [2, 2], [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward', 'False']], + columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'requires_grad'] ) self.assertTrue(npu_df.equals(target_df)) @@ -467,8 +471,9 @@ class TestParseData(unittest.TestCase): npu_df = parse_data.gen_data_df(npu_json_data, stack_json_data) target_df = pd.DataFrame( - [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward', 'Functional.linear.0.forward.input.0.pt']], - columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'data_name'] + [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], + [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward', 'False', 'Functional.linear.0.forward.input.0.pt']], + columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'requires_grad', 'data_name'] ) self.assertTrue(npu_df.equals(target_df)) @@ -484,8 +489,9 @@ class TestParseData(unittest.TestCase): npu_df = parse_data.gen_data_df(npu_json_data, stack_json_data) target_df = pd.DataFrame( - [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward', 123456]], - columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'md5'] + [['Functional.linear.0.forward.input.0', 'torch.float32', [2, 2], + [2, 0, 1, 1], ['File'], 'input', 'Functional.linear.0.forward', 'False', 123456]], + columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'requires_grad', 'md5'] ) self.assertTrue(npu_df.equals(target_df)) @@ -509,7 +515,8 @@ class TestParseData(unittest.TestCase): 'params_struct': [], 'stack_info': [['File']], 'summary': [[2, 0, 1, 1]], - 'state': ['input'] + 'state': ['input'], + 'requires_grad': ['False'] } self.assertEqual(merge_list, target_dict) @@ -679,14 +686,16 @@ class TestMatch(unittest.TestCase): match = Match(mode_config, mapping_config, cross_frame=False) match_result = pd.DataFrame(columns=CompareConst.MATCH_RESULT_COLUMNS) - npu_op_item = pd.Series(['op', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'op_origin', 'data_name', 'op', [1, 2]], + npu_op_item = pd.Series(['op', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'op_origin', 'False', 'data_name', 'op', [1, 2]], index=['op_name_x', 'dtype_x', 'shape_x', 'summary_x', 'stack_info_x', - 'state_x', 'api_origin_name_x', 'data_name_x', + 'state_x', 'api_origin_name_x', 'data_name_x', 'requires_grad_x', 'compare_key', 'compare_shape'] ) match_result = match.put_unmatched_in_table(match_result, npu_op_item) - target_match_result = pd.DataFrame([['op', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'op_origin', 'data_name', 'op', [1, 2], - 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A']], + target_match_result = pd.DataFrame([['op', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'op_origin', 'False', 'data_name', 'op', [1, 2], + 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A']], columns=CompareConst.MATCH_RESULT_COLUMNS) self.assertTrue(match_result.equals(target_match_result)) @@ -696,17 +705,23 @@ class TestMatch(unittest.TestCase): match = Match(mode_config, mapping_config, cross_frame=False) match_result = pd.DataFrame(columns=CompareConst.MATCH_RESULT_COLUMNS) - npu_op_item = pd.Series(['op', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'op_origin', 'data_name', 'op', [1, 2]], - index=['op_name_x', 'dtype_x', 'shape_x', 'summary_x', 'stack_info_x', 'state_x', 'api_origin_name_x', 'data_name_x', + npu_op_item = pd.Series(['op', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'op_origin', 'False', 'data_name', 'op', [1, 2]], + index=['op_name_x', 'dtype_x', 'shape_x', 'summary_x', 'stack_info_x', + 'state_x', 'api_origin_name_x', 'requires_grad_x', 'data_name_x', 'compare_key', 'compare_shape'] ) - bench_op_item = pd.Series(['op', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'op_origin', 'data_name', 'op', [1, 2]], - index=['op_name_y', 'dtype_y', 'shape_y', 'summary_y', 'stack_info_y', 'state_y', 'api_origin_name_y', 'data_name_y', + bench_op_item = pd.Series(['op', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'op_origin', 'False', 'data_name', 'op', [1, 2]], + index=['op_name_y', 'dtype_y', 'shape_y', 'summary_y', 'stack_info_y', + 'state_y', 'api_origin_name_y', 'requires_grad_y', 'data_name_y', 'compare_key', 'compare_shape'] ) match_result = match.put_matched_in_table(match_result, npu_op_item, bench_op_item) - target_match_result = pd.DataFrame([['op', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'op_origin', 'data_name', 'op', [1, 2], - 'op', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'op_origin', 'data_name']], + target_match_result = pd.DataFrame([['op', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'op_origin', 'False', 'data_name', 'op', [1, 2], + 'op', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'op_origin', 'False', 'data_name']], columns=CompareConst.MATCH_RESULT_COLUMNS) self.assertTrue(match_result.equals(target_match_result)) @@ -749,19 +764,38 @@ class TestMatch(unittest.TestCase): match = Match(mode_config, mapping_config, cross_frame=False) npu_df = pd.DataFrame([ - ['Functional.conv2d.3.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.conv2d.3.forward','Functional.conv2d.3.forward.input.0.pt', 'Functional.conv2d.3.forward.input.0', [1, 2]], - ['Functional.amax.1.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.amax.1.forward', 'Functional.amax.0.forward.input.0.pt', 'Functional.amax.1.forward.input.0', [1, 2]] - ], columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'data_name', 'compare_key', 'compare_shape']) + ['Functional.conv2d.3.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.conv2d.3.forward', 'True', 'Functional.conv2d.3.forward.input.0.pt', + 'Functional.conv2d.3.forward.input.0', [1, 2]], + ['Functional.amax.1.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.amax.1.forward', 'True', 'Functional.amax.0.forward.input.0.pt', + 'Functional.amax.1.forward.input.0', [1, 2]] + ], columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', + 'state', 'api_origin_name', 'requires_grad', 'data_name', + 'compare_key', 'compare_shape']) bench_df = pd.DataFrame([ - ['Functional.conv2d.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.conv2d.0.forward', 'Functional.conv2d.0.forward.input.0.pt', 'Functional.conv2d.0.forward.input.0', [1, 2]], - ['Functional.amax.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.amax.0.forward', 'Functional.amax.0.forward.input.0.pt', 'Functional.amax.0.forward.input.0', [1, 2]] - ], columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', 'state', 'api_origin_name', 'data_name', 'compare_key', 'compare_shape']) + ['Functional.conv2d.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.conv2d.0.forward', 'True', 'Functional.conv2d.0.forward.input.0.pt', + 'Functional.conv2d.0.forward.input.0', [1, 2]], + ['Functional.amax.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.amax.0.forward', 'True', 'Functional.amax.0.forward.input.0.pt', + 'Functional.amax.0.forward.input.0', [1, 2]] + ], columns=['op_name', 'dtype', 'shape', 'summary', 'stack_info', + 'state', 'api_origin_name', 'requires_grad', 'data_name', 'compare_key', 'compare_shape']) match_result = match.process_fuzzy_match(npu_df, bench_df) expected = pd.DataFrame( [ - ['Functional.conv2d.3.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.conv2d.3.forward', 'Functional.conv2d.3.forward.input.0.pt', 'Functional.conv2d.3.forward.input.0', [1, 2], 'Functional.conv2d.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.conv2d.0.forward', 'Functional.conv2d.0.forward.input.0.pt'], - ['Functional.amax.1.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.amax.1.forward', 'Functional.amax.0.forward.input.0.pt', 'Functional.amax.1.forward.input.0', [1, 2], 'Functional.amax.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', 'input', 'Functional.amax.0.forward', 'Functional.amax.0.forward.input.0.pt'] + ['Functional.conv2d.3.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.conv2d.3.forward', 'True', 'Functional.conv2d.3.forward.input.0.pt', + 'Functional.conv2d.3.forward.input.0', [1, 2], + 'Functional.conv2d.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.conv2d.0.forward', 'True', 'Functional.conv2d.0.forward.input.0.pt'], + ['Functional.amax.1.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.amax.1.forward', 'True', 'Functional.amax.0.forward.input.0.pt', + 'Functional.amax.1.forward.input.0', [1, 2], + 'Functional.amax.0.forward.input.0', 'float32', [1, 2], 'summary', 'stack_info', + 'input', 'Functional.amax.0.forward', 'True', 'Functional.amax.0.forward.input.0.pt'] ] , columns=CompareConst.MATCH_RESULT_COLUMNS) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py index 173fb550067de76b77524699430691fa87df6c58..9d418ae5e4e7de74ba81216325a69ee057441236 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py @@ -31,15 +31,19 @@ op_name = "Tensor.add_0.0.forward" op_result = [ {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'md5': '00000000', 'Max': 0.33033010363578796, 'Min': -0.331031858921051, 'Mean': -0.030964046716690063, 'data_name': '-1', - 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.forward.input.0', 'state': 'input'}, + 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.forward.input.0', + 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'md5': '00000000', 'Max': 0.003992878366261721, 'Min': -0.008102823048830032, 'Mean': -0.0002002553956117481, 'data_name': '-1', - 'Norm': 0.02844562754034996, 'requires_grad': 'False', 'full_op_name': 'Tensor.add_0.0.forward.input.1', 'state': 'input'}, + 'Norm': 0.02844562754034996, 'requires_grad': 'False', 'full_op_name': 'Tensor.add_0.0.forward.input.1', + 'state': 'input'}, {'full_op_name': 'Tensor.add_0.0.forward.input.alpha', 'dtype': "", 'shape': '[]', 'md5': '0dae4479', - 'Max': -0.1, 'Min': -0.1, 'Mean': -0.1, 'Norm': -0.1, 'data_name': '-1', 'type': 'float', 'value': -0.1, 'state': 'input'}, + 'Max': -0.1, 'Min': -0.1, 'Mean': -0.1, 'Norm': -0.1, 'requires_grad': None, 'data_name': '-1', 'type': 'float', + 'value': -0.1, 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'md5': '00000000', 'Max': 0.33033010363578796, 'Min': -0.331031858921051, 'Mean': -0.030964046716690063, 'data_name': '-1', - 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.forward.output.0', 'state': 'output'}] + 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.forward.output.0', + 'state': 'output'}] # test_read_op_1 op_data_b = { @@ -56,13 +60,16 @@ op_name_b = "Tensor.add_0.0.backward" op_result_b = [ {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'data_name': '-1', 'md5': '00000000', 'Max': 0.33033010363578796, 'Min': -0.331031858921051, 'Mean': -0.030964046716690063, - 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.backward.input.0', 'state': 'input'}, + 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.backward.input.0', + 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'data_name': '-1', 'md5': '00000000', 'Max': 0.003992878366261721, 'Min': -0.008102823048830032, 'Mean': -0.0002002553956117481, - 'Norm': 0.02844562754034996, 'requires_grad': 'False', 'full_op_name': 'Tensor.add_0.0.backward.input.1', 'state': 'input'}, + 'Norm': 0.02844562754034996, 'requires_grad': 'False', 'full_op_name': 'Tensor.add_0.0.backward.input.1', + 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'data_name': '-1', 'md5': '00000000', 'Max': 0.33033010363578796, 'Min': -0.331031858921051, 'Mean': -0.030964046716690063, - 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.backward.output.0', 'state': 'output'}] + 'Norm': 2.2533628940582275, 'requires_grad': 'True', 'full_op_name': 'Tensor.add_0.0.backward.output.0', + 'state': 'output'}] # test_op_item_parse parse_item = [ @@ -80,10 +87,11 @@ o_result_parse = [ 'shape': [5], 'type': 'torch.Tensor', 'full_op_name': 'Distributed.broadcast.0.forward.input.0', 'data_name': '-1', 'md5': '00000000', 'state': 'input'}, {'full_op_name': 'Distributed.broadcast.0.forward.input.1', 'dtype': "", 'shape': '[]', - 'md5': 'f4dbdf21', 'Max': 0, 'Min': 0, 'Mean': 0, 'Norm': 0, 'data_name': '-1', 'type': 'int', 'value': 0, 'state': 'input'}, + 'md5': 'f4dbdf21', 'Max': 0, 'Min': 0, 'Mean': 0, 'Norm': 0, 'data_name': '-1', 'type': 'int', 'value': 0, + 'state': 'input', 'requires_grad': None}, {'Max': None, 'Mean': None, 'Min': None, 'Norm': None, 'data_name': '-1', 'dtype': 'slice', 'type': 'slice', 'full_op_name': 'Distributed.broadcast.0.forward.input.2', 'md5': '5fbbe87f', 'shape': '(3,)', - 'value': [None, None, None], 'state': 'input'} + 'value': [None, None, None], 'state': 'input', 'requires_grad': None} ] # test_resolve_api_special_parameters @@ -118,7 +126,8 @@ npu_dict = {'op_name': ['Functional.conv2d.0.forward.input.0', 'Functional.conv2 [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]], - 'stack_info': []} + 'stack_info': [], + 'requires_grad': [True, False, True, True, True, True, True, True]} bench_dict = {'op_name': ['Functional.conv2d.0.forward.input.0', 'Functional.conv2d.0.forward.input.1', 'Functional.conv2d.0.forward.input.2', 'Functional.conv2d.0.forward.output.0', 'Functional.conv2d.0.forward.parameters.weight', 'Functional.conv2d.0.forward.parameters.bias', @@ -136,39 +145,42 @@ bench_dict = {'op_name': ['Functional.conv2d.0.forward.input.0', 'Functional.con [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]], - 'stack_info': []} + 'stack_info': [], + 'requires_grad': [True, False, True, True, True, True, True, True]} highlight_dict = {'red_rows': [], 'yellow_rows': []} o_result = [ ['Functional.conv2d.0.forward.input.0', 'Functional.conv2d.0.forward.input.0', 'torch.float32', 'torch.float32', - [1, 1, 28, 28], [1, 1, 28, 28], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + [1, 1, 28, 28], [1, 1, 28, 28], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', 3.029174327850342, -2.926689624786377, -0.06619918346405029, 1.0, - 3.029174327850342, -2.926689624786377, -0.06619918346405029, 1.0,'', '', 'None'], + 3.029174327850342, -2.926689624786377, -0.06619918346405029, 1.0, True, '', '', 'None'], ['Functional.conv2d.0.forward.input.1', 'Functional.conv2d.0.forward.input.1', 'torch.float32', 'torch.float32', - [16, 1, 5, 5], [16, 1, 5, 5], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + [16, 1, 5, 5], [16, 1, 5, 5], False, False, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', 0.19919930398464203, -0.19974489510059357, 0.006269412115216255, 1.0, - 0.19919930398464203, -0.19974489510059357, 0.006269412115216255, 1.0, '', '', 'None'], + 0.19919930398464203, -0.19974489510059357, 0.006269412115216255, 1.0, True, '', '', 'None'], ['Functional.conv2d.0.forward.input.2', 'Functional.conv2d.0.forward.input.2', 'torch.float32', 'torch.float32', - [16], [16], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + [16], [16], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', 0.19734230637550354, -0.18177609145641327, 0.007903944700956345, 1.0, - 0.19734230637550354, -0.18177609145641327, 0.007903944700956345, 1.0, '', '', 'None'], + 0.19734230637550354, -0.18177609145641327, 0.007903944700956345, 1.0, True, '', '', 'None'], ['Functional.conv2d.0.forward.parameters.weight', 'Functional.conv2d.0.forward.parameters.weight', 'torch.float32', 'torch.float32', - [1, 16, 28, 28], [1, 16, 28, 28], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, '', '', 'None'], + [1, 16, 28, 28], [1, 16, 28, 28], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, True, '', '', 'None'], ['Functional.conv2d.0.forward.parameters.bias', 'Functional.conv2d.0.forward.parameters.bias', 'torch.float32', 'torch.float32', - [1, 16, 28, 28], [1, 16, 28, 28], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, '', '', 'None'], + [1, 16, 28, 28], [1, 16, 28, 28], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, True, '', '', 'None'], ['Functional.conv2d.0.forward.output.0', 'Functional.conv2d.0.forward.output.0', 'torch.float32', 'torch.float32', - [1, 16, 28, 28], [1, 16, 28, 28], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + [1, 16, 28, 28], [1, 16, 28, 28], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', 2.1166646480560303, -2.190781354904175, -0.003579073818400502, 1.0, - 2.1166646480560303, -2.190781354904175, -0.003579073818400502, 1.0, '', '', 'None'], - ['Functional.conv2d.0.parameters_grad.weight', 'Functional.conv2d.0.parameters_grad.weight', 'torch.float32', 'torch.float32', - [1, 16, 28, 28], [1, 16, 28, 28], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, '', '', 'None'], - ['Functional.conv2d.0.parameters_grad.bias', 'Functional.conv2d.0.parameters_grad.bias', 'torch.float32', 'torch.float32', - [1, 16, 28, 28], [1, 16, 28, 28], 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, '', '', 'None'], + 2.1166646480560303, -2.190781354904175, -0.003579073818400502, 1.0, True, '', '', 'None'], + ['Functional.conv2d.0.parameters_grad.weight', 'Functional.conv2d.0.parameters_grad.weight', 'torch.float32', + 'torch.float32', + [1, 16, 28, 28], [1, 16, 28, 28], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, True, '', '', 'None'], + ['Functional.conv2d.0.parameters_grad.bias', 'Functional.conv2d.0.parameters_grad.bias', 'torch.float32', + 'torch.float32', + [1, 16, 28, 28], [1, 16, 28, 28], True, True, 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, True, '', '', 'None'], ] # test_get_un_match_accuracy @@ -186,9 +198,11 @@ o_result_unmatch_1 = [ 'None'], ['Functional.conv2d.0.forward.output.0', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', 'None'], - ['Functional.conv2d.0.parameters_grad.weight', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', + ['Functional.conv2d.0.parameters_grad.weight', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', + 'N/A', 'None'], - ['Functional.conv2d.0.parameters_grad.bias', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', + ['Functional.conv2d.0.parameters_grad.bias', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', + 'N/A', 'None'] ] o_result_unmatch_2 = [ @@ -196,10 +210,12 @@ o_result_unmatch_2 = [ 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 3.029174327850342, -2.926689624786377, -0.06619918346405029, 1.0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'], ['Functional.conv2d.0.forward.input.1', 'N/A', 'torch.float32', 'N/A', [16, 1, 5, 5], 'N/A', 'N/A', 'N/A', 'N/A', - 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 0.19919930398464203, -0.19974489510059357, 0.006269412115216255, 1.0, 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 0.19919930398464203, -0.19974489510059357, 0.006269412115216255, 1.0, 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'], ['Functional.conv2d.0.forward.input.2', 'N/A', 'torch.float32', 'N/A', [16], 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', - 'N/A', 'N/A', 'N/A', 'N/A', 0.19734230637550354, -0.18177609145641327, 0.007903944700956345, 1.0, 'N/A', 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 0.19734230637550354, -0.18177609145641327, 0.007903944700956345, 1.0, 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'], ['Functional.conv2d.0.forward.parameters.weight', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', @@ -210,12 +226,15 @@ o_result_unmatch_2 = [ 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 1.0, 1.0, 1.0, 1.0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'], ['Functional.conv2d.0.forward.output.0', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', - 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 2.1166646480560303, -2.190781354904175, -0.003579073818400502, 1.0, 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 2.1166646480560303, -2.190781354904175, -0.003579073818400502, 1.0, 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'], - ['Functional.conv2d.0.parameters_grad.weight', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', + ['Functional.conv2d.0.parameters_grad.weight', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 1.0, 1.0, 1.0, 1.0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'], - ['Functional.conv2d.0.parameters_grad.bias', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', 'N/A', + ['Functional.conv2d.0.parameters_grad.bias', 'N/A', 'torch.float32', 'N/A', [1, 16, 28, 28], 'N/A', 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 1.0, 1.0, 1.0, 1.0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'No bench data matched.', 'None'] ] @@ -257,12 +276,14 @@ tensor_list = [ 'full_op_name': 'Tensor.add_.0.forward.input.0', 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'Max': 0.003992878366261721, 'Min': -0.008102823048830032, 'Mean': -0.0002002553956117481, - 'Norm': 0.02844562754034996, 'requires_grad': False, 'full_op_name': 'Tensor.add_.0.forward.input.1', 'state': 'input'}, + 'Norm': 0.02844562754034996, 'requires_grad': False, 'full_op_name': 'Tensor.add_.0.forward.input.1', + 'state': 'input'}, {'full_op_name': 'Tensor.add_.0.forward.input.alpha.0', 'dtype': "", "shape": '[]', 'md5': None, 'Max': -0.1, 'Min': -0.1, 'Mean': -0.1, 'Norm': -0.1, 'data_name': '-1', 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'Max': 0.33033010363578796, 'Min': -0.331031858921051, 'Mean': -0.030964046716690063, - 'Norm': 2.2533628940582275, 'requires_grad': True, 'full_op_name': 'Tensor.add_.0.forward.output.0', 'state': 'output'} + 'Norm': 2.2533628940582275, 'requires_grad': True, 'full_op_name': 'Tensor.add_.0.forward.output.0', + 'state': 'output'} ] result_op_dict = {'op_name': ['Tensor.add_.0.forward.input.0', 'Tensor.add_.0.forward.input.1', 'Tensor.add_.0.forward.input.alpha.0', 'Tensor.add_.0.forward.output.0'], @@ -278,17 +299,20 @@ result_op_dict = {'op_name': ['Tensor.add_.0.forward.input.0', 'Tensor.add_.0.fo [-0.1, -0.1, -0.1, -0.1], [0.33033010363578796, -0.331031858921051, -0.030964046716690063, 2.2533628940582275]], 'stack_info': [], - 'state': ['input', 'input', 'input', 'output']} + 'state': ['input', 'input', 'input', 'output'], + 'requires_grad': [True, False, None, True]} tensor_list_md5 = [ {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'Max': 0.003992878366261721, 'Min': -0.008102823048830032, 'Mean': -0.0002002553956117481, - 'Norm': 0.02844562754034996, 'requires_grad': False, 'full_op_name': 'Tensor.add_.0.forward.input.0', 'md5': 1, 'state': 'input'}, + 'Norm': 0.02844562754034996, 'requires_grad': False, 'full_op_name': 'Tensor.add_.0.forward.input.0', 'md5': 1, + 'state': 'input'}, {'full_op_name': 'Tensor.add_.0.forward.kwargs.alpha.0', 'dtype': "", "shape": '[]', 'md5': None, 'Max': -0.1, 'Min': -0.1, 'Mean': -0.1, 'Norm': -0.1, 'data_name': '-1', 'state': 'input'}, {'type': 'torch.Tensor', 'dtype': 'torch.float32', 'shape': [16, 1, 3, 3], 'Max': 0.33033010363578796, 'Min': -0.331031858921051, 'Mean': -0.030964046716690063, - 'Norm': 2.2533628940582275, 'requires_grad': True, 'full_op_name': 'Tensor.add_.0.forward.output.0', 'md5': 2, 'state': 'output'} + 'Norm': 2.2533628940582275, 'requires_grad': True, 'full_op_name': 'Tensor.add_.0.forward.output.0', 'md5': 2, + 'state': 'output'} ] result_op_dict_md5 = {'op_name': ['Tensor.add_.0.forward.input.0', 'Tensor.add_.0.forward.kwargs.alpha.0', 'Tensor.add_.0.forward.output.0'], @@ -302,7 +326,9 @@ result_op_dict_md5 = {'op_name': ['Tensor.add_.0.forward.input.0', 'Tensor.add_. [-0.1, -0.1, -0.1, -0.1], [0.33033010363578796, -0.331031858921051, -0.030964046716690063, 2.2533628940582275]], 'stack_info': [], - 'state': ['input', 'input', 'output']} + 'state': ['input', 'input', 'output'], + 'requires_grad': [False, None, True] + } base_dir1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'test_acc_compare_utils1') base_dir2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'test_acc_compare_utils2') @@ -374,35 +400,35 @@ class TestUtilsMethods(unittest.TestCase): self.assertEqual(context.exception.code, CompareException.RECURSION_LIMIT_ERROR) def test_get_rela_diff_summary_mode_float_or_int(self): - result_item = [0] * 14 + result_item = [0] * 16 err_msg = '' npu_summary_data = [1, 1, 1, 1] - bench_summary_data = [1, 1, 1, 1] + bench_summary_data = [2, 2, 2, 2] result_item, accuracy_check, err_msg = get_rela_diff_summary_mode(result_item, npu_summary_data, bench_summary_data, err_msg) - self.assertEqual(result_item, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0.0%', '0.0%', '0.0%', '0.0%']) + self.assertEqual(result_item, [0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, '50.0%', '50.0%', '50.0%', '50.0%']) self.assertEqual(accuracy_check, '') self.assertEqual(err_msg, '') def test_get_rela_diff_summary_mode_bool(self): - result_item = [0] * 14 + result_item = [0] * 16 err_msg = '' npu_summary_data = [True, True, True, True] bench_summary_data = [True, True, True, True] result_item, accuracy_check, err_msg = get_rela_diff_summary_mode(result_item, npu_summary_data, bench_summary_data, err_msg) - self.assertEqual(result_item, [0, 0, 0, 0, 0, 0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A']) + self.assertEqual(result_item, [0, 0, 0, 0, 0, 0, 0, 0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A']) self.assertEqual(accuracy_check, '') self.assertEqual(err_msg, '') def test_get_rela_diff_summary_mode_nan(self): - result_item = [0] * 14 + result_item = [0] * 16 err_msg = '' npu_summary_data = [float('nan')] bench_summary_data = [float('nan')] result_item, accuracy_check, err_msg = get_rela_diff_summary_mode(result_item, npu_summary_data, bench_summary_data, err_msg) - self.assertEqual(result_item, [0, 0, 0, 0, 0, 0, 'Nan', 0, 0, 0, 'Nan', 0, 0, 0]) + self.assertEqual(result_item, [0, 0, 0, 0, 0, 0, 0, 0, 'Nan', 0, 0, 0, 'Nan', 0, 0, 0]) self.assertEqual(accuracy_check, '') self.assertEqual(err_msg, '') @@ -496,19 +522,21 @@ class TestUtilsMethods(unittest.TestCase): b_name = 'Tensor.add.0.forward.input.0' b_struct = ('torch.float32', [96]) bench_stack_info = ['abc'] + requires_grad_pair = [True, True] n_info = ApiItemInfo(n_name, n_struct, npu_stack_info) b_info = ApiItemInfo(b_name, b_struct, bench_stack_info) dump_mode = Const.ALL - result_item = result_item_init(n_info, b_info, dump_mode) + result_item = result_item_init(n_info, b_info, requires_grad_pair, dump_mode) self.assertEqual(result_item, ['Tensor.add.0.forward.input.0', 'Tensor.add.0.forward.input.0', - 'torch.float32', 'torch.float32', [96], [96], ' ', ' ', ' ', ' ', ' ', ' ']) + 'torch.float32', 'torch.float32', [96], [96], True, True, + ' ', ' ', ' ', ' ', ' ', ' ']) dump_mode = Const.SUMMARY - result_item = result_item_init(n_info, b_info, dump_mode) + result_item = result_item_init(n_info, b_info, requires_grad_pair, dump_mode) self.assertEqual(result_item, ['Tensor.add.0.forward.input.0', 'Tensor.add.0.forward.input.0', - 'torch.float32', 'torch.float32', [96], [96], ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ']) + 'torch.float32', 'torch.float32', [96], [96], True, True, + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']) def test_result_item_init_md5(self): n_name = 'Tensor.add.0.forward.input.0' @@ -517,13 +545,15 @@ class TestUtilsMethods(unittest.TestCase): b_name = 'Tensor.add.0.forward.input.0' b_struct = ('torch.float32', [96], 'e87000dc') bench_stack_info = ['abc'] + requires_grad_pair = [True, True] n_info = ApiItemInfo(n_name, n_struct, npu_stack_info) b_info = ApiItemInfo(b_name, b_struct, bench_stack_info) dump_mode = Const.MD5 - result_item = result_item_init(n_info, b_info, dump_mode) + result_item = result_item_init(n_info, b_info, requires_grad_pair, dump_mode) self.assertEqual(result_item, ['Tensor.add.0.forward.input.0', 'Tensor.add.0.forward.input.0', - 'torch.float32', 'torch.float32', [96], [96], 'e87000dc', 'e87000dc', 'pass']) + 'torch.float32', 'torch.float32', [96], [96], True, True, + 'e87000dc', 'e87000dc', True, 'pass']) def test_result_item_init_md5_index_error(self): n_name = 'Tensor.add.0.forward.input.0' @@ -532,12 +562,13 @@ class TestUtilsMethods(unittest.TestCase): b_name = 'Tensor.add.0.forward.input.0' b_struct = ('torch.float32', [96]) bench_stack_info = ['abc'] + requires_grad_pair = [True, True] n_info = ApiItemInfo(n_name, n_struct, npu_stack_info) b_info = ApiItemInfo(b_name, b_struct, bench_stack_info) dump_mode = Const.MD5 with self.assertRaises(CompareException) as context: - result_item = result_item_init(n_info, b_info, dump_mode) + result_item = result_item_init(n_info, b_info, requires_grad_pair, dump_mode) self.assertEqual(context.exception.code, CompareException.INDEX_OUT_OF_BOUNDS_ERROR) def test_table_value_is_valid_int(self): @@ -559,10 +590,12 @@ class TestUtilsMethods(unittest.TestCase): class TestReorderOpNameList(unittest.TestCase): def test_reorder_op_name_list(self): # 标准顺序 - op_name_list = ["op.forward.input.0.0", "op.forward.output.0", "op.forward.output.1", "op.forward.parameters.1", "op.forward.parameters.2", "op.parameters_grad.0"] + op_name_list = ["op.forward.input.0.0", "op.forward.output.0", "op.forward.output.1", "op.forward.parameters.1", + "op.forward.parameters.2", "op.parameters_grad.0"] state_list = ["input", "output", "output", "parameters", "parameters", "parameters_grad"] op_name_reorder, state_reorder = reorder_op_name_list(op_name_list, state_list) - expected_result = ["op.forward.input.0.0", "op.forward.parameters.1", "op.forward.parameters.2", "op.forward.output.0", "op.forward.output.1", "op.parameters_grad.0"] + expected_result = ["op.forward.input.0.0", "op.forward.parameters.1", "op.forward.parameters.2", + "op.forward.output.0", "op.forward.output.1", "op.parameters_grad.0"] expected_state = ["input", "parameters", "parameters", "output", "output", "parameters_grad"] self.assertEqual(op_name_reorder, expected_result) self.assertEqual(state_reorder, expected_state) @@ -593,44 +626,53 @@ class TestReorderOpXList(unittest.TestCase): summary_list = ["summary1", "summary2", "summary3"] data_name_list = ["data1", "data2", "data3"] state_list = ["input", "output", "parameters"] - result_op_name, result_summary, result_data_name, result_state = reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list) + requires_grad_list = [True, None, False] + result_op_name, result_summary, result_data_name, result_state, result_requires_grad = reorder_op_x_list( + op_name_list, summary_list, data_name_list, state_list, requires_grad_list) self.assertEqual(result_op_name, ["op.forward.input.0", "op.forward.parameters.weight", "op.forward.output.0"]) self.assertEqual(result_summary, ["summary1", "summary3", "summary2"]) self.assertEqual(result_data_name, ["data1", "data3", "data2"]) self.assertEqual(result_state, ["input", "parameters", "output"]) + self.assertEqual(result_requires_grad, [True, False, None]) # 空 op_name_list 或 summary_list op_name_list = [] summary_list = [] data_name_list = ["data1", "data2", "data3"] state_list = [] - result_op_name, result_summary, result_data_name, result_state = reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list) + result_op_name, result_summary, result_data_name, result_state, result_requires_grad = reorder_op_x_list( + op_name_list, summary_list, data_name_list, state_list, requires_grad_list) self.assertEqual(result_op_name, []) self.assertEqual(result_summary, []) self.assertEqual(result_data_name, ["data1", "data2", "data3"]) self.assertEqual(result_state, []) + self.assertEqual(result_requires_grad, [True, None, False]) # 空 data_name_list op_name_list = ["op.forward.input.0", "op.forward.output.0", "op.forward.parameters.weight"] summary_list = ["summary1", "summary2", "summary3"] data_name_list = [] state_list = ["input", "output", "parameters"] - result_op_name, result_summary, result_data_name, result_state = reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list) + result_op_name, result_summary, result_data_name, result_state, result_requires_grad = reorder_op_x_list( + op_name_list, summary_list, data_name_list, state_list, requires_grad_list) self.assertEqual(result_op_name, ["op.forward.input.0", "op.forward.parameters.weight", "op.forward.output.0"]) self.assertEqual(result_summary, ["summary1", "summary3", "summary2"]) self.assertEqual(result_data_name, []) self.assertEqual(result_state, ["input", "parameters", "output"]) + self.assertEqual(result_requires_grad, [True, False, None]) # data_name_list 为 None op_name_list = ["op.forward.input.0", "op.forward.output.0", "op.forward.parameters.weight"] summary_list = ["summary1", "summary2", "summary3"] data_name_list = None state_list = ["input", "output", "parameters"] - result_op_name, result_summary, result_data_name, result_state = reorder_op_x_list(op_name_list, summary_list, data_name_list, state_list) + result_op_name, result_summary, result_data_name, result_state, result_requires_grad = reorder_op_x_list( + op_name_list, summary_list, data_name_list, state_list, requires_grad_list) self.assertEqual(result_op_name, ["op.forward.input.0", "op.forward.parameters.weight", "op.forward.output.0"]) self.assertEqual(result_summary, ["summary1", "summary3", "summary2"]) self.assertEqual(result_data_name, None) self.assertEqual(result_state, ["input", "parameters", "output"]) + self.assertEqual(result_requires_grad, [True, False, None]) class TestGenOpItem(unittest.TestCase): diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_first_diff_analyze.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_first_diff_analyze.py index c7919efba7e0240ff0d3398357f2ad4d45c1df30..ce7094de70be56ab239412b567a65eebb47a6cca 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_first_diff_analyze.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_first_diff_analyze.py @@ -104,7 +104,8 @@ class TestFirstDiffAnalyze(unittest.TestCase): md5_header = CompareConst.MD5_COMPARE_RESULT_HEADER + [CompareConst.STACK, Const.STATE, Const.API_ORIGIN_NAME] result_slice = [ ['Functional.conv2d.0.forward.input.0', 'Functional.conv2d.0.forward.input.0', 'torch.int32', 'torch.int32', - '[]', '[]', '2144df1c', '2144df1c', 'pass', '', 'input', 'Functional.conv2d.0.forward'] + '[]', '[]', 'True', 'True', '2144df1c', '2144df1c', True, 'pass', + '', 'input', 'Functional.conv2d.0.forward'] ] expected_result = { 'is_same': True, @@ -113,7 +114,9 @@ class TestFirstDiffAnalyze(unittest.TestCase): CompareConst.BENCH_NAME: 'Functional.conv2d.0.forward.input.0', CompareConst.NPU_DTYPE: 'torch.int32', CompareConst.BENCH_DTYPE: 'torch.int32', CompareConst.NPU_SHAPE: '[]', CompareConst.BENCH_SHAPE: '[]', + CompareConst.NPU_REQ_GRAD: 'True', CompareConst.BENCH_REQ_GRAD: 'True', CompareConst.NPU_MD5: '2144df1c', CompareConst.BENCH_MD5: '2144df1c', + CompareConst.REQ_GRAD_CONSIST: True, CompareConst.RESULT: 'pass', CompareConst.STACK: '', Const.STATE: 'input', Const.API_ORIGIN_NAME: 'Functional.conv2d.0.forward' } @@ -128,7 +131,8 @@ class TestFirstDiffAnalyze(unittest.TestCase): md5_header = CompareConst.MD5_COMPARE_RESULT_HEADER + [CompareConst.STACK, Const.STATE, Const.API_ORIGIN_NAME] result_slice = [ ['Functional.conv2d.0.forward.input.0', 'Functional.conv2d.0.forward.input.0', 'torch.int32', 'torch.int32', - '[]', '[]', '2144df1c', '2100df1c', 'Different', '', 'input', 'Functional.conv2d.0.forward'] + '[]', '[]', 'True', 'True', '2144df1c', '2100df1c', True, 'Different', + '', 'input', 'Functional.conv2d.0.forward'] ] expected_result = { 'is_same': False, @@ -137,7 +141,9 @@ class TestFirstDiffAnalyze(unittest.TestCase): CompareConst.BENCH_NAME: 'Functional.conv2d.0.forward.input.0', CompareConst.NPU_DTYPE: 'torch.int32', CompareConst.BENCH_DTYPE: 'torch.int32', CompareConst.NPU_SHAPE: '[]', CompareConst.BENCH_SHAPE: '[]', + CompareConst.NPU_REQ_GRAD: 'True', CompareConst.BENCH_REQ_GRAD: 'True', CompareConst.NPU_MD5: '2144df1c', CompareConst.BENCH_MD5: '2100df1c', + CompareConst.REQ_GRAD_CONSIST: True, CompareConst.RESULT: 'Different', CompareConst.STACK: '', Const.STATE: 'input', Const.API_ORIGIN_NAME: 'Functional.conv2d.0.forward' } diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py index 5a4ca7de47f401c4eb97ad4c224dfd1ae0a92262..733c5fd4c54b82f6b7f99190d36bf22474df9573 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py @@ -20,37 +20,37 @@ from msprobe.core.compare.utils import ApiBatch summary_line_input = ['Functional_batch_norm_0_forward.input.0', 'Functional_batch_norm_0_forward.input.0', - 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 0.01, 0, 0, 0, 1, 1, 1, 1, 1.01, 1, 1, 1, - 'Yes', ''] + 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 0.01, 0, 0, 0, '0.0%', '0.0%', '0.0%', '0.0%', 1, 1, 1, 1, 1.01, 1, 1, 1, + True, 'Yes', ''] summary_line_1 = ['Functional_batch_norm_0_forward.output.0', 'Functional_batch_norm_0_forward.output.0', - 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 10, 0, 0, 0, 2, 0, 1, 1, 1, 1, 1, 1, - 'Warning', ''] + 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 10, 0, 0, 0, '0.0%', '0.0%', '0.0%', '0.0%', 2, 0, 1, 1, 1, 1, 1, 1, + True, 'Warning', ''] summary_line_2 = ['Functional_batch_norm_0_forward.output.1', 'Functional_batch_norm_0_forward.output.1', - 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 0.02, 0, 0, 0, 0.12, 0, 1, 1, 0.1, 1, 1, 1, - 'Warning', ''] + 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 0.02, 0, 0, 0, '0.0%', '0.0%', '0.0%', '0.0%', 0.12, 0, 1, 1, 0.1, 1, 1, 1, + True, 'Warning', ''] summary_line_3 = ['Functional_batch_norm_0_forward.output.2', 'Functional_batch_norm_0_forward.output.2', - 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 0, 0, 0, 0, 2, 0, 1, 1, 1, 1, 1, 1, - 'Warning', ''] + 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 0, 0, 0, 0, '0.0%', '0.0%', '0.0%', '0.0%', 2, 0, 1, 1, 1, 1, 1, 1, + True, 'Warning', ''] line_input = ['Functional.batch.norm.0.forward.input.0', 'Functional.batch.norm.0.forward.input.0', 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 1, 0.5, 1, 1, 0.95, 1, - 1, 1, 1, 1, 1.01, 1, 1, 1, - 'Yes', '', 'input', 'Functional.batch.norm.0.forward'] + 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 1, 0.5, 1, 1, 0.95, 1, 1, 1, 1, 1, 1.01, 1, 1, 1, + True, 'Yes', '', 'input', 'Functional.batch.norm.0.forward'] line_1 = ['Functional.batch.norm.0.forward.output.0', 'Functional.batch.norm.0.forward.output.0', 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 0.8, 0.5, 1, 1, 0.59, 1, - 'nan', 0, 1, 1, 19, 1, 1, 1, - 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] + 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 0.8, 0.5, 1, 1, 0.59, 1, 'nan', 0, 1, 1, 19, 1, 1, 1, + True, 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] line_2 = ['Functional.batch.norm.0.forward.output.1', 'Functional.batch.norm.0.forward.output.1', 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 0.9, 0.5, 1, 1, 0.8, 1, - 0, 0.12, 0, 1, 1, 0.1, 1, 1, - 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] + 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 0.9, 0.5, 1, 1, 0.8, 1, 0, 0.12, 0, 1, 1, 0.1, 1, 1, + True, 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] line_3 = ['Functional.batch.norm.0.forward.output.2', 'Functional.batch.norm.0.forward.output.2', 'torch.float16', - 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], 0.8, 0.5, 1.1e+10, 1, 0.85, 1, - 9, 0.12, 0, 1, 1, 0.1, 1, 1, - 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] + 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, + 0.8, 0.5, 1.1e+10, 1, 0.85, 1, 9, 0.12, 0, 1, 1, 0.1, 1, 1, + True, 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'test_highlight') @@ -58,8 +58,8 @@ base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'test_highl def generate_result_xlsx(base_dir): data_path = os.path.join(base_dir, 'target_result.xlsx') data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], 'True', 'True', + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'True', 'Yes', '', '-1'] ] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) @@ -123,8 +123,8 @@ class TestUtilsMethods(unittest.TestCase): shutil.rmtree(base_dir) def test_CheckOrderMagnitude_normal(self): - api_in = [1, 1, 1, 1, 1, 1, 5, 1, 1] - api_out = [1, 1, 1, 1, 1, 1, 1, 1, 1] + api_in = [1, 1, 1, 1, 1, 1, True, True, 5, 1, 1] + api_out = [1, 1, 1, 1, 1, 1, True, True, 1, 1, 1] info = (api_in, api_out, 1) color_columns = () dump_mode = Const.SUMMARY @@ -134,8 +134,8 @@ class TestUtilsMethods(unittest.TestCase): self.assertEqual(result, None) def test_CheckOneThousandErrorRatio_str(self): - api_in = [1, 1, 1, 1, 1, 1, 0.9, 0.5, 1, 1, "unsupported"] - api_out = [1, 1, 1, 1, 1, 1, 0.9, 0.5, 1, 1, "unsupported"] + api_in = [1, 1, 1, 1, 1, 1, True, True, 0.9, 0.5, 1, 1, "unsupported"] + api_out = [1, 1, 1, 1, 1, 1, True, True, 0.9, 0.5, 1, 1, "unsupported"] info = (api_in, api_out, 1) color_columns = () dump_mode = Const.ALL @@ -146,8 +146,8 @@ class TestUtilsMethods(unittest.TestCase): @patch("msprobe.core.compare.highlight.add_highlight_row_info") def test_CheckOneThousandErrorRatio_red(self, mock_add_highlight_row_info): - api_in = [1, 1, 1, 1, 1, 1, 0.9, 0.5, 1, 1, 1] - api_out = [1, 1, 1, 1, 1, 1, 0.9, 0.5, 1, 1, 0.5] + api_in = [1, 1, 1, 1, 1, 1, True, True, 0.9, 0.5, 1, 1, 1] + api_out = [1, 1, 1, 1, 1, 1, True, True, 0.9, 0.5, 1, 1, 0.5] info = (api_in, api_out, 1) ColorColumns = namedtuple('ColorColumns', ['red', 'yellow']) color_columns = ColorColumns(red=[], yellow=[]) @@ -158,8 +158,8 @@ class TestUtilsMethods(unittest.TestCase): mock_add_highlight_row_info.assert_called_once() def test_CheckCosineSimilarity_str(self): - api_in = [1, 1, 1, 1, 1, 1, "unsupported", 1, 1, "unsupported"] - api_out = [1, 1, 1, 1, 1, 1, "unsupported", 1, 1, "unsupported"] + api_in = [1, 1, 1, 1, 1, 1, True, True, "unsupported", 1, 1, "unsupported"] + api_out = [1, 1, 1, 1, 1, 1, True, True, "unsupported", 1, 1, "unsupported"] info = (api_in, api_out, 1) color_columns = () dump_mode = Const.ALL @@ -174,8 +174,8 @@ class TestUtilsMethods(unittest.TestCase): red_lines, yellow_lines = [], [] color_columns = ColorColumns(red=red_lines, yellow=yellow_lines) - api_in = {6: 0, 18: 1} - api_out = {6: 0.6, 18: 1} + api_in = {8: 0, 20: 1} + api_out = {8: 0.6, 20: 1} num = 1 info = (api_in, api_out, num) CheckMaxRelativeDiff().apply(info, color_columns, dump_mode=Const.SUMMARY) @@ -189,8 +189,8 @@ class TestUtilsMethods(unittest.TestCase): red_lines, yellow_lines = [], [] color_columns = ColorColumns(red=red_lines, yellow=yellow_lines) - api_in = {6: 0.001, 18: 1} - api_out = {6: 0.2, 18: 1} + api_in = {8: 0.001, 20: 1} + api_out = {8: 0.2, 20: 1} num = 1 info = (api_in, api_out, num) CheckMaxRelativeDiff().apply(info, color_columns, dump_mode=Const.SUMMARY) @@ -204,8 +204,8 @@ class TestUtilsMethods(unittest.TestCase): red_lines, yellow_lines = [], [] color_columns = ColorColumns(red=red_lines, yellow=yellow_lines) - api_in = {6: 0.001, 18: np.nan} - api_out = {6: 0.2, 18: 1} + api_in = {8: 0.001, 20: np.nan} + api_out = {8: 0.2, 20: 1} num = 1 info = (api_in, api_out, num) result = CheckMaxRelativeDiff().apply(info, color_columns, dump_mode=Const.SUMMARY) @@ -214,17 +214,21 @@ class TestUtilsMethods(unittest.TestCase): def test_find_error_rows_normal(self): compare_result = np.array([ ["Functional.linear.0.forward.input.0", "Functional.linear.0.forward.input.0", - "torch.float32", "torch.float32", [2, 2], [2, 2], 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", - 1, 1, 1, 1, 1, 1, 1, 1, "", ""], + "torch.float32", "torch.float32", [2, 2], [2, 2], 'True', 'True', + 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", + 1, 1, 1, 1, 1, 1, 1, 1, True, "", ""], ["Functional.linear.0.forward.input.1", "Functional.linear.0.forward.input.1", - "torch.float32", "torch.float32", [2, 2], [2, 2], 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", - 1, 1, 1, 1, 1, 1, 1, 1, "", ""], + "torch.float32", "torch.float32", [2, 2], [2, 2], 'True', 'True', + 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", + 1, 1, 1, 1, 1, 1, 1, 1, True, "", ""], ["Functional.linear.0.forward.input.2", "Functional.linear.0.forward.input.2", - "torch.float32", "torch.float32", [2], [2], 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", - 1, 1, 1, 1, 1, 1, 1, 1, "", ""], + "torch.float32", "torch.float32", [2], [2], 'True', 'True', + 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", + 1, 1, 1, 1, 1, 1, 1, 1, True, "", ""], ["Functional.linear.0.forward.output.0", "Functional.linear.0.forward.output.0", - "torch.float32", "torch.float32", [2, 2], [2, 2], 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", - 1, 1, 1, 1, 1, 1, 1, 1, "", ""], + "torch.float32", "torch.float32", [2, 2], [2, 2], 'True', 'True', + 0.0, 0.0, 0.0, 0.0, "0.0%", "0.0%", "0.0%", "0.0%", + 1, 1, 1, 1, 1, 1, 1, 1, True, "", ""], ], dtype=object) api_batch = ApiBatch("Functional.linear.0.forward", 0) api_batch.input_len = 3 @@ -271,8 +275,8 @@ class TestUtilsMethods(unittest.TestCase): def test_df_malicious_value_check(self): columns = CompareConst.COMPARE_RESULT_HEADER data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', ''] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', ''] ] result_df = pd.DataFrame(data, columns=columns) @@ -289,8 +293,8 @@ class TestUtilsMethods(unittest.TestCase): def test_highlight_rows_xlsx_red(self): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'] ] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) @@ -306,8 +310,8 @@ class TestUtilsMethods(unittest.TestCase): def test_highlight_rows_xlsx_yellow(self): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'] ] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) @@ -324,8 +328,8 @@ class TestUtilsMethods(unittest.TestCase): @patch("msprobe.core.compare.highlight.save_workbook") def test_highlight_rows_xlsx_malicious_columns(self, mock_save_book): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'] ] columns = CompareConst.COMPARE_RESULT_HEADER + ['=Data_name'] result_df = pd.DataFrame(data, columns=columns) @@ -348,11 +352,11 @@ class TestUtilsMethods(unittest.TestCase): @patch("msprobe.core.compare.highlight.save_workbook") def test_highlight_rows_xlsx_malicious_type(self, mock_save_book): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - '=torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'], + '=torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'], ['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - '=torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'] + '=torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'] ] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) @@ -381,11 +385,11 @@ class TestUtilsMethods(unittest.TestCase): def test_update_highlight_err_msg(self): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'], + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'], ['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', '-1'] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', '-1'] ] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) @@ -401,18 +405,18 @@ class TestUtilsMethods(unittest.TestCase): highlight.update_highlight_err_msg(result_df, highlight_dict) t_data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', 'a\nb', '-1'], + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', 'a\nb', '-1'], ['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', 'd', '-1'] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', 'd', '-1'] ] target_result_df = pd.DataFrame(t_data, columns=columns) self.assertTrue(result_df.equals(target_result_df)) def test_update_highlight_err_msg_md5(self): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], 'abc', 'abc', 'pass'] + 'torch.float32', 'torch.float32', True, True, [2, 2], [2, 2], 'abc', 'abc', True, 'pass'] ] columns = CompareConst.MD5_COMPARE_RESULT_HEADER result_df = pd.DataFrame(data, columns=columns) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_multiprocessing_compute.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_multiprocessing_compute.py index afcdd25744bf030a98629902cce4d4efa44a78b8..736bc6207e5d69a48c71bd4f771538952a4b8f5c 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_multiprocessing_compute.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_multiprocessing_compute.py @@ -15,15 +15,15 @@ from msprobe.pytorch.compare.pt_compare import read_real_data from test_acc_compare import generate_dump_json, generate_pt, generate_stack_json data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, - 'Yes', '', ['-1', '-1']]] + True, 'Yes', '', ['-1', '-1']]] o_data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, 'unsupported', 'unsupported', 'unsupported', 'unsupported', 'unsupported', 'unsupported', 1, 1, 1, 1, 1, 1, 1, 1, - 'None', 'NPU does not have data file.', ['-1', '-1']]] + True, 'None', 'NPU does not have data file.', ['-1', '-1']]] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) o_result = pd.DataFrame(o_data, columns=columns) @@ -72,7 +72,7 @@ class TestUtilsMethods(unittest.TestCase): class TestCompareRealData(unittest.TestCase): def setUp(self): - self.result_df = pd.DataFrame(columns=[ + self.result_df = pd.DataFrame([['']*8]*2, columns=[ CompareConst.COSINE, CompareConst.EUC_DIST, CompareConst.MAX_ABS_ERR, CompareConst.MAX_RELATIVE_ERR, CompareConst.ONE_THOUSANDTH_ERR_RATIO, CompareConst.FIVE_THOUSANDTHS_ERR_RATIO, CompareConst.ACCURACY, CompareConst.ERROR_MESSAGE @@ -200,7 +200,8 @@ class TestCompareRealData(unittest.TestCase): 'Functional.linear.0.forward.input.0.pt']} result_df = pd.DataFrame({ 'NPU Name': ['Functional.linear.0.forward.input.0'], - 'Bench Name': ['Functional.linear.0.forward.input.0'] + 'Bench Name': ['Functional.linear.0.forward.input.0'], + 'Err_message': '' }) file_reader = read_real_data @@ -209,19 +210,19 @@ class TestCompareRealData(unittest.TestCase): compare_real_data = CompareRealData(file_reader, mode_config, cross_frame) updated_df = compare_real_data.compare_ops(idx=0, dump_path_dict=dump_path_dict, result_df=result_df, - lock=self.lock, input_param=input_param) + lock=self.lock, input_param=input_param) self.assertEqual(updated_df.loc[0, CompareConst.COSINE], 1.0) self.assertEqual(updated_df.loc[0, CompareConst.MAX_ABS_ERR], 0) def test_do_multi_process(self): data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], - '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, 'Yes', '', ['-1', '-1']]] + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, + '', '', '', '', '', '', 1, 1, 1, 1, 1, 1, 1, 1, True, 'Yes', '', ['-1', '-1']]] o_data = [['Functional.linear.0.forward.input.0', 'Functional.linear.0.forward.input.0', - 'torch.float32', 'torch.float32', [2, 2], [2, 2], + 'torch.float32', 'torch.float32', [2, 2], [2, 2], True, True, 'unsupported', 'unsupported', 'unsupported', 'unsupported', 'unsupported', 'unsupported', - 1, 1, 1, 1, 1, 1, 1, 1, 'None', 'NPU does not have data file.', ['-1', '-1']]] + 1, 1, 1, 1, 1, 1, 1, 1, True, 'None', 'NPU does not have data file.', ['-1', '-1']]] columns = CompareConst.COMPARE_RESULT_HEADER + ['Data_name'] result_df = pd.DataFrame(data, columns=columns) o_result = pd.DataFrame(o_data, columns=columns) diff --git a/debug/accuracy_tools/msprobe/test/visualization_ut/compare/test_mode_adapter.py b/debug/accuracy_tools/msprobe/test/visualization_ut/compare/test_mode_adapter.py index 5f9a64f04dd7d4bffe0881519c2aa1264c105898..25ad91605900b2026235aff693762dec0556d27c 100644 --- a/debug/accuracy_tools/msprobe/test/visualization_ut/compare/test_mode_adapter.py +++ b/debug/accuracy_tools/msprobe/test/visualization_ut/compare/test_mode_adapter.py @@ -26,22 +26,22 @@ class TestModeAdapter(unittest.TestCase): node_data = {'Tensor.__imul__.0.forward.input.0': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': [], 'Max': 16388, 'Min': 16388, 'Mean': 16388, 'Norm': 16388, - 'requires_grad': False, 'md5': 'a563a4ea', + 'requires_grad': 'False', 'md5': 'a563a4ea', 'full_op_name': 'Tensor.__imul__.0.forward.input.0', - 'data_name': '-1'}, + 'data_name': '-1', 'state': 'input'}, 'Tensor.__imul__.0.forward.input.1': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': [], 'Max': 4097, 'Min': 4097, 'Mean': 4097, 'Norm': 4097, - 'requires_grad': False, 'md5': 'ce564339', + 'requires_grad': 'False', 'md5': 'ce564339', 'full_op_name': 'Tensor.__imul__.0.forward.input.1', - 'data_name': '-1'}} + 'data_name': '-1', 'state': 'input'}} compare_dict = {'Tensor.__imul__.0.forward.input.0': ['Tensor.__imul__.0.forward.input.0', 'Tensor.__imul__.0.forward.input.0', 'torch.int64', - 'torch.int64', [], [], 'a563a4ea', 'a563a4ea', 'pass', - []], + 'torch.int64', [], [], 'False', 'False', + 'a563a4ea', 'a563a4ea', True, 'pass', []], 'Tensor.__imul__.0.forward.input.1': ['Tensor.__imul__.0.forward.input.1', 'Tensor.__imul__.0.forward.input.1', 'torch.int64', - 'torch.int64', [], [], 'ce564339', 'ce564559', 'diff', - 'None']} + 'torch.int64', [], [], 'False', 'False', + 'ce564339', 'ce564559', True, 'diff', 'None']} precision_index = ModeAdapter._add_md5_compare_data(node_data, compare_dict) self.assertEqual(precision_index, 0) @@ -49,68 +49,68 @@ class TestModeAdapter(unittest.TestCase): tensor_data = {'Module.module.Float16Module.forward.0.input.0': ['Module.module.Float16Module.forward.0.input.0', 'Module.module.Float16Module.forward.0.input.0', - 'torch.int64', 'torch.int64', [1, 1024], [1, 1024], - 1.0, 0.0, 0.0, 1.0, 1.0, 29992.0, 1.0, 9100.3125, - 474189.09375, 29992.0, 1.0, 9100.3125, 474189.09375, - 'Yes', '', None, + 'torch.int64', 'torch.int64', [1, 1024], [1, 1024], 'False', 'False', + 1.0, 0.0, 0.0, 1.0, 1.0, + 29992.0, 1.0, 9100.3125, 474189.09375, + 29992.0, 1.0, 9100.3125, 474189.09375, + True, 'Yes', '', None, 'Module.module.Float16Module.forward.0.input.0.pt'], 'Module.module.Float16Module.forward.0.input.1': [ 'Module.module.Float16Module.forward.0.input.1', 'Module.module.Float16Module.forward.0.input.1', - 'torch.int64', 'torch.int64', [1, 1024], [1, 1024], - 1.0, 0.0, 0.0, None, 1.0, 1023.0, 0.0, 511.5, - 18904.755859375, 1023.0, 0.0, 511.5, 18904.755859375, - 'Yes', '', 'None', + 'torch.int64', 'torch.int64', [1, 1024], [1, 1024], 'False', 'False', + 1.0, 0.0, 0.0, None, 1.0, + 1023.0, 0.0, 511.5, 18904.755859375, + 1023.0, 0.0, 511.5, 18904.755859375, + True, 'Yes', '', 'None', 'Module.module.Float16Module.forward.0.input.1.pt'], 'Module.module.Float16Module.forward.0.input.2': [ 'Module.module.Float16Module.forward.0.input.2', 'Module.module.Float16Module.forward.0.input.2', - 'torch.bool', 'torch.bool', [1, 1, 1024, 1024], - [1, 1, 1024, 1024], 1.0, 0.0, 0.0, 1.0, 1.0, True, - False, None, None, True, False, None, None, 'Yes', '', - 'None', + 'torch.bool', 'torch.bool', [1, 1, 1024, 1024], [1, 1, 1024, 1024], 'False', 'False', + 1.0, 0.0, 0.0, 1.0, 1.0, + True, False, None, None, True, False, None, None, + True, 'Yes', '', 'None', 'Module.module.Float16Module.forward.0.input.2.pt'], 'Module.module.Float16Module.forward.0.kwargs.labels': [ 'Module.module.Float16Module.forward.0.kwargs.labels', - 'Module.module.Float16Module.forward.0.kwargs.labels', 'torch.int64', - 'torch.int64', [1, 1024], - [1, 1024], 1.0, 0.0, 0.0, 1.0, 1.0, 29992.0, 1.0, 9108.99609375, 474332.28125, - 29992.0, 1.0, - 9108.99609375, 474332.28125, 'Yes', '', 'None', + 'Module.module.Float16Module.forward.0.kwargs.labels', + 'torch.int64', 'torch.int64', [1, 1024], [1, 1024], 'False', 'False', + 1.0, 0.0, 0.0, 1.0, 1.0, + 29992.0, 1.0, 9108.99609375, 474332.28125, + 29992.0, 1.0, 9108.99609375, 474332.28125, + True, 'Yes', '', 'None', 'Module.module.Float16Module.forward.0.kwargs.labels.pt'], 'Module.module.Float16Module.forward.0.output.0': [ 'Module.module.Float16Module.forward.0.output.0', 'Module.module.Float16Module.forward.0.output.0', - 'torch.float32', 'torch.float32', [1, 1024], - [1, 1024], 0.994182636336, 4.863566398621, - 0.461487948895, 0.0068359375, 0.0234375, - 15.402446746826172, 7.318280220031738, - 11.375151634216309, 366.3365173339844, - 10.538880348205566, 10.215872764587402, - 10.378824234008789, 332.1264953613281, 'No', '', - 'None', + 'torch.float32', 'torch.float32', [1, 1024], [1, 1024], 'False', 'False', + 0.994182636336, 4.863566398621, 0.461487948895, 0.0068359375, 0.0234375, + 15.402446746826172, 7.318280220031738, 11.375151634216309, 366.3365173339844, + 10.538880348205566, 10.215872764587402, 10.378824234008789, 332.1264953613281, + True, 'No', '', 'None', 'Module.module.Float16Module.forward.0.output.0.pt']} node_data = {'Module.module.Float16Module.forward.0.input.0': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': [1, 1024], 'Max': 29992.0, 'Min': 1.0, 'Mean': 9100.3125, 'Norm': 474189.09375, - 'requires_grad': False, + 'requires_grad': 'False', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.input.1': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': [1, 1024], 'Max': 1023.0, 'Min': 0.0, 'Mean': 511.5, 'Norm': 18904.755859375, - 'requires_grad': False, + 'requires_grad': 'False', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.input.2': {'type': 'torch.Tensor', 'dtype': 'torch.bool', 'shape': [1, 1, 1024, 1024], 'Max': True, 'Min': False, 'Mean': None, 'Norm': None, - 'requires_grad': False, + 'requires_grad': 'False', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.kwargs.labels': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': None, 'Max': 29992.0, 'Min': 1.0, 'Mean': 9108.99609375, 'Norm': 474332.28125, - 'requires_grad': False, + 'requires_grad': 'False', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.kwargs.None': None} min_thousandth = ModeAdapter._add_real_compare_data(node_data, tensor_data) @@ -120,51 +120,60 @@ class TestModeAdapter(unittest.TestCase): compare_data_dict = { 'Module.module.Float16Module.forward.0.input.0': ['Module.module.Float16Module.forward.0.input.0', 'Module.module.Float16Module.forward.0.input.0', - 'torch.int64', 'torch.int64', [4, 4096], [4, 4096], 0.0, - 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', 30119.0, - 1.0, 8466.25, 1786889.625, 30119.0, 1.0, 8466.25, - 1786889.625, '', ''], + 'torch.int64', 'torch.int64', [4, 4096], [4, 4096], + 'False', 'False', + 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', + 30119.0, 1.0, 8466.25, 1786889.625, + 30119.0, 1.0, 8466.25, 1786889.625, + True, '', '', None], 'Module.module.Float16Module.forward.0.input.1': ['Module.module.Float16Module.forward.0.input.1', 'Module.module.Float16Module.forward.0.input.1', - 'torch.int64', 'torch.int64', [4, 4096], [4, 4096], 0.0, - 0.0, 0.0, 0.0, '0.0%', 'N/A', '0.0%', '0.0%', 4095.0, 0.0, - 2047.5, 302642.375, 4095.0, 0.0, 2047.5, 302642.375, '', - '', 'None'], + 'torch.int64', 'torch.int64', [4, 4096], [4, 4096], + 'False', 'False', + 0.0, 0.0, 0.0, 0.0, '0.0%', 'N/A', '0.0%', '0.0%', + 4095.0, 0.0, 2047.5, 302642.375, + 4095.0, 0.0, 2047.5, 302642.375, + True, '', '', 'None'], 'Module.module.Float16Module.forward.0.input.2': ['Module.module.Float16Module.forward.0.input.2', 'Module.module.Float16Module.forward.0.input.2', - 'torch.bool', 'torch.bool', [1, 1, 4096, 4096], - [1, 1, 4096, 4096], 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', - 'N/A', 'N/A', 'N/A', True, False, None, None, True, False, - None, None, '', '', 'None'], + 'torch.bool', 'torch.bool', + [1, 1, 4096, 4096], [1, 1, 4096, 4096], + 'False', 'False', + 'N/A', 'N/A', 'N/A', 'N/A', + 'N/A', 'N/A', 'N/A', 'N/A', + True, False, None, None, True, False, None, None, + True, '', '', 'None'], 'Module.module.Float16Module.forward.0.input.labels': ['Module.module.Float16Module.forward.0.input.labels', 'Module.module.Float16Module.forward.0.input.labels', - 'torch.float16', 'torch.float16', [4, 4096], - [4, 4096], + 'torch.float16', 'torch.float16', + [4, 4096], [4, 4096], + 'False', 'False', 0.0, 0.0, 0.0, 0.0, '0.0%', '0.0%', '0.0%', '0.0%', 30119.0, 0.00001, 8460.7685546875, 1786117.625, - 30119.0, - 1.0, 8460.7685546875, 1786117.625, '', '', 'None']} + 30119.0, 1.0, 8460.7685546875, 1786117.625, + True, '', '', 'None']} node_data = {'Module.module.Float16Module.forward.0.input.0': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': [4, 4096], 'Max': 30119.0, 'Min': 1.0, 'Mean': 8466.25, 'Norm': 1786889.625, - 'requires_grad': False, + 'requires_grad': 'False', 'data_name': '-1', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.input.1': {'type': 'torch.Tensor', 'dtype': 'torch.int64', 'shape': [4, 4096], 'Max': 4095.0, 'Min': 0.0, 'Mean': 2047.5, 'Norm': 302642.375, - 'requires_grad': False, + 'requires_grad': 'False', 'data_name': '-1', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.input.2': {'type': 'torch.Tensor', 'dtype': 'torch.bool', 'shape': [1, 1, 4096, 4096], 'Max': True, 'Min': False, 'Mean': None, 'Norm': None, - 'requires_grad': False, + 'requires_grad': 'False', 'data_name': '-1', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.input.labels': {'type': 'torch.Tensor', 'dtype': 'torch.float16', 'shape': [4, 4096], 'Max': 30119.0, 'Min': 0.00001, 'Mean': 8460.7685546875, - 'Norm': 1786117.625, 'requires_grad': False, + 'Norm': 1786117.625, + 'requires_grad': 'False', 'data_name': '-1', 'md5': '00000000'}, 'Module.module.Float16Module.forward.0.kwargs.None': None} precision_index = ModeAdapter._add_summary_compare_data(node_data, compare_data_dict) diff --git a/debug/accuracy_tools/msprobe/visualization/builder/msprobe_adapter.py b/debug/accuracy_tools/msprobe/visualization/builder/msprobe_adapter.py index 7e99de16b90d2dc03f389848c2fe327f5af2d036..388a4fef6ace351d971fb2b86b8635c56a0b0215 100644 --- a/debug/accuracy_tools/msprobe/visualization/builder/msprobe_adapter.py +++ b/debug/accuracy_tools/msprobe/visualization/builder/msprobe_adapter.py @@ -156,7 +156,7 @@ def format_node_data(data_dict, node_id=None, compare_mode=None): """ 删除节点数据中不需要展示的字段 """ - del_list = ['requires_grad', 'full_op_name'] + del_list = ['state', 'full_op_name'] if GraphConst.MD5_COMPARE != compare_mode: del_list.append(Const.MD5) if node_id and GraphConst.BATCH_P2P in node_id: diff --git a/debug/accuracy_tools/msprobe/visualization/utils.py b/debug/accuracy_tools/msprobe/visualization/utils.py index aa6276ec0d8c29b8ec6f1f1ad2542b306643d9e5..282a5c56b662788f787604746196df7719e1ed71 100644 --- a/debug/accuracy_tools/msprobe/visualization/utils.py +++ b/debug/accuracy_tools/msprobe/visualization/utils.py @@ -219,9 +219,9 @@ class GraphConst: INPUT = '.input.' OUTPUT = '.output.' STR_MAX_LEN = 50 - MD5_INDEX_LIST = [CompareConst.RESULT] - REAL_DATA_INDEX_LIST = CompareConst.ALL_COMPARE_INDEX - SUMMARY_INDEX_LIST = CompareConst.SUMMARY_COMPARE_INDEX + MD5_INDEX_LIST = CompareConst.MD5_COMPARE_INDEX + [CompareConst.REQ_GRAD_CONSIST] + REAL_DATA_INDEX_LIST = CompareConst.ALL_COMPARE_INDEX + [CompareConst.REQ_GRAD_CONSIST] + SUMMARY_INDEX_LIST = CompareConst.SUMMARY_COMPARE_INDEX + [CompareConst.REQ_GRAD_CONSIST] APIS_BETWEEN_MODULES = 'Apis_Between_Modules' APIS_BETWEEN_MODULES_ALL_RANKS = 'Apis_Between_Modules_All_Ranks' MERGE_NODES = 'Merged_Nodes'