diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/graph_controls_board/components/tf_filter_precision_error/index.ts b/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/graph_controls_board/components/tf_filter_precision_error/index.ts index 8ddf63321ad355d134eb83797e97cf7f142a17a0..28095466359632e8f540b8167aa7f774219a73a8 100644 --- a/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/graph_controls_board/components/tf_filter_precision_error/index.ts +++ b/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/graph_controls_board/components/tf_filter_precision_error/index.ts @@ -19,7 +19,6 @@ class TfFilterPrecisionError extends PolymerElement { confirm-text="确认" confirm-theme=" primary" opened="{{filterDialogOpened}}" - confirm="[[onFlterDialogConfirm]]" > { }; + @property({ type: Array }) + lastFilterValue: string[] = []; + MAX_RELATIVE_ERR = "0"; MIN_RELATIVE_ERR = "1"; MEAN_RELATIVE_ERR = "2"; @@ -55,12 +57,27 @@ class TfFilterPrecisionError extends PolymerElement { _selectionChanged() { this.set('filterValue', [this.MAX_RELATIVE_ERR, this.MIN_RELATIVE_ERR, this.MEAN_RELATIVE_ERR, this.NORM_RELATIVE_ERR]); } + @observe('filterDialogOpened') + _onFlterDialogOpened = () => { + if (this.filterDialogOpened) { + this.set('lastFilterValue', this.filterValue); + } + + } + override ready(): void { super.ready(); const filterDialog = this.shadowRoot?.querySelector('#filter-dialog') as HTMLElement; filterDialog?.addEventListener('confirm', this.onFlterDialogConfirm) + filterDialog?.addEventListener('cancel', this.onFlterDialogCancel) this.set('filterValue', [this.MAX_RELATIVE_ERR, this.MIN_RELATIVE_ERR, this.MEAN_RELATIVE_ERR, this.NORM_RELATIVE_ERR]); } + + + onFlterDialogCancel = (e: any) => { + this.set('filterValue', this.lastFilterValue); + } + onFlterDialogConfirm = async (e: any) => { if (isEmpty(this.filterValue)) { Notification.show(`错误: 精度误差计算指标为空,请选择指标`, { diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/utils/index.ts b/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/utils/index.ts index 6358dadc316fd50cb9f2d73727f0b9867927a5d7..d31fdc0448e4efbabb1bff5224db829cedef1a09 100644 --- a/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/utils/index.ts +++ b/plugins/tensorboard-plugins/tb_graph_ascend/fe/src/utils/index.ts @@ -31,7 +31,7 @@ export function fetchPbTxt(filepath: string): Promise { const removePrototypePollution = (obj: any): void => { if (obj && typeof obj === 'object') { for (let key in obj) { - if (key === '__proto__' || key === 'constructor') { + if (key === '__proto__' || key === 'constructor' || key === 'prototype') { delete obj[key]; } else if (typeof obj[key] === 'object') { removePrototypePollution(obj[key]); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/server/app/controllers/match_nodes_controller.py b/plugins/tensorboard-plugins/tb_graph_ascend/server/app/controllers/match_nodes_controller.py index 904247786c215a8232c71a4aa71d2cd980dbe3bd..588dcb16e0d8f12c8bc6e4ff77ffedec433615fe 100644 --- a/plugins/tensorboard-plugins/tb_graph_ascend/server/app/controllers/match_nodes_controller.py +++ b/plugins/tensorboard-plugins/tb_graph_ascend/server/app/controllers/match_nodes_controller.py @@ -54,10 +54,12 @@ class MatchNodesController: opposite_bench_node_name = MatchNodesController.get_opposite_node_name(bench_node_name) if task == 'md5': result = MatchNodesController.process_md5_task_add(graph_data, npu_node_name, bench_node_name) - opposite_result = MatchNodesController.process_md5_task_add(graph_data, opposite_npu_node_name, opposite_bench_node_name) + opposite_result = MatchNodesController.process_md5_task_add(graph_data, opposite_npu_node_name, + opposite_bench_node_name) elif task == 'summary': result = MatchNodesController.process_summary_task_add(graph_data, npu_node_name, bench_node_name) - opposite_result = MatchNodesController.process_summary_task_add(graph_data, opposite_npu_node_name, opposite_bench_node_name) + opposite_result = MatchNodesController.process_summary_task_add(graph_data, opposite_npu_node_name, + opposite_bench_node_name) else: result = { 'success': False, @@ -65,7 +67,7 @@ class MatchNodesController: } result['success'] = result.get('success') or opposite_result.get('success') if not result.get('success'): - result['error'] = f'当前节点:{result.get("error",'')}。对侧节点:{opposite_result.get("error")}' + result['error'] = f'当前节点:{result.get("error","")}。对侧节点:{opposite_result.get("error")}' return result @staticmethod @@ -76,10 +78,12 @@ class MatchNodesController: opposite_bench_node_name = MatchNodesController.get_opposite_node_name(bench_node_name) if task == 'md5': result = MatchNodesController.process_md5_task_delete(graph_data, npu_node_name, bench_node_name) - opposite_result = MatchNodesController.process_md5_task_delete(graph_data, opposite_npu_node_name, opposite_bench_node_name) + opposite_result = MatchNodesController.process_md5_task_delete(graph_data, opposite_npu_node_name, + opposite_bench_node_name) elif task == 'summary': result = MatchNodesController.process_summary_task_delete(graph_data, npu_node_name, bench_node_name) - opposite_result = MatchNodesController.process_summary_task_delete(graph_data, opposite_npu_node_name, opposite_bench_node_name) + opposite_result = MatchNodesController.process_summary_task_delete(graph_data, opposite_npu_node_name, + opposite_bench_node_name) else: result = { 'success': False, @@ -87,7 +91,7 @@ class MatchNodesController: } result['success'] = result.get('success') or opposite_result.get('success') if not result.get('success'): - result['error'] = f'当前节点:{result.get("error",'')}。对侧节点:{opposite_result.get("error")}' + result['error'] = f'当前节点:{result.get("error","")}。对侧节点:{opposite_result.get("error")}' return result @staticmethod diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/server/app/utils/graph_utils.py b/plugins/tensorboard-plugins/tb_graph_ascend/server/app/utils/graph_utils.py index 5e77cd88c58e206d742703f0d12102a905e23c2c..74ff3399d3bb7d0b95cda5a35cba6f82af60309d 100644 --- a/plugins/tensorboard-plugins/tb_graph_ascend/server/app/utils/graph_utils.py +++ b/plugins/tensorboard-plugins/tb_graph_ascend/server/app/utils/graph_utils.py @@ -132,7 +132,6 @@ class GraphUtils: try: result = json.loads(json_str) - GraphUtils.remove_prototype_pollution(result) return result except json.JSONDecodeError as e: logger.error(f"JSON decode error: {e}") @@ -141,29 +140,6 @@ class GraphUtils: logger.error(f"Unexpected error: {e}") return default_value - @staticmethod - def remove_prototype_pollution(obj, current_depth=1, max_depth=200): - """ - 递归删除对象中的原型污染字段,如 '__proto__', 'constructor', 'prototype'。 - - :param obj: 要清理的对象 - :param current_depth: 当前递归深度,默认从 1 开始 - :param max_depth: 最大允许递归深度 - """ - if current_depth > max_depth: - logger.warning(f"Reached maximum recursion depth of {max_depth}. Stopping further recursion.") - return - - if isinstance(obj, dict): - for key in list(obj.keys()): - if key in ('__proto__', 'constructor', 'prototype'): - del obj[key] - else: - GraphUtils.remove_prototype_pollution(obj[key], current_depth + 1, max_depth) - elif isinstance(obj, list): - for item in obj: - GraphUtils.remove_prototype_pollution(item, current_depth + 1, max_depth) - @staticmethod def remove_prefix(node_data, prefix): if node_data is None: