From 7e291776566a245662902366c0d23dd6d12e7125 Mon Sep 17 00:00:00 2001 From: wangshuide2020 <7511764+wangshuide2020@user.noreply.gitee.com> Date: Tue, 29 Sep 2020 11:10:46 +0800 Subject: [PATCH] change response of names interface from list to tree. --- .../datavisual/data_transform/graph/graph.py | 22 ---- .../data_transform/graph/msgraph.py | 123 ++++++++++++++++++ .../data_transform/graph/node_tree.py} | 0 .../datavisual/processors/graph_processor.py | 9 +- .../debugger/stream_cache/debugger_graph.py | 93 ------------- .../debugger/stream_handler/graph_handler.py | 2 +- .../test_search_nodes_success_result1.json | 2 +- .../search_unwatched_leaf_node.json | 2 +- ...e_names_with_offset_expected_results1.json | 2 +- ...with_search_content_expected_results1.json | 2 +- ...with_search_content_expected_results2.json | 2 +- .../processors/test_graph_processor.py | 4 +- .../expected_results/graph/search_node_1.json | 2 +- .../graph/search_nodes_0.json | 2 +- 14 files changed, 139 insertions(+), 128 deletions(-) rename mindinsight/{debugger/stream_cache/node.py => datavisual/data_transform/graph/node_tree.py} (100%) diff --git a/mindinsight/datavisual/data_transform/graph/graph.py b/mindinsight/datavisual/data_transform/graph/graph.py index 4616294f..dca6e833 100644 --- a/mindinsight/datavisual/data_transform/graph/graph.py +++ b/mindinsight/datavisual/data_transform/graph/graph.py @@ -147,28 +147,6 @@ class Graph: nodes.append(node.to_dict()) return nodes - def search_node_names(self, content, offset, limit): - """ - Search node names by content. - - Args: - content (Union[str, None]): This content can be the key content of the node to search, - if None, will get all node names. - offset (int): An offset for page. Ex, offset is 0, mean current page is 1. - limit (int): An offset for page. Ex, offset is 0, mean current page is 1. - - Returns: - list[str], a list of node names. - """ - if content is not None: - content = content.lower() - catch_names = [name for name in self._normal_node_map if content in name.lower()] - else: - catch_names = list(self._normal_node_map) - catch_names = sorted(catch_names) - real_offset = offset * limit - return catch_names[real_offset:real_offset+limit] - def search_single_node(self, node_name): """ Search node, and return every layer nodes until this node. diff --git a/mindinsight/datavisual/data_transform/graph/msgraph.py b/mindinsight/datavisual/data_transform/graph/msgraph.py index 772e911f..da51002b 100644 --- a/mindinsight/datavisual/data_transform/graph/msgraph.py +++ b/mindinsight/datavisual/data_transform/graph/msgraph.py @@ -16,6 +16,7 @@ from mindinsight.datavisual.common.log import logger from mindinsight.datavisual.proto_files.mindinsight_anf_ir_pb2 import DataType from mindinsight.datavisual.common.enums import PluginNameEnum +from .node_tree import NodeTree from .node import Node from .node import NodeTypeEnum from .graph import Graph @@ -205,6 +206,128 @@ class MSGraph(Graph): return data_type_name + def get_nodes(self, searched_node_list): + """ + Get node tree by a searched_node_list. + + Args: + searched_node_list (list[Node]): A list of nodes that + matches the given search pattern. + + Returns: + A list of dict including the searched nodes. + [{ + "name": "Default", + "type": "name_scope", + "nodes": [{ + "name": "Default/Conv2D1", + "type": "name_scope", + "nodes": [{ + ... + }] + }] + }, + { + "name": "Gradients", + "type": "name_scope", + "nodes": [{ + "name": "Gradients/Default", + "type": "name_scope", + "nodes": [{ + ... + }] + }] + """ + # save the node in the NodeTree + root = NodeTree() + for node in searched_node_list: + self._build_node_tree(root, node.name, node.type) + + # get the searched nodes in the NodeTree and reorganize them + searched_list = [] + self._traverse_node_tree(root, searched_list) + + return searched_list + + def search_leaf_nodes_by_pattern(self, pattern): + """ + Search leaf node by a given pattern. + + Args: + pattern (Union[str, None]): The pattern of the node to search, + if None, return all node names. + + Returns: + list[Node], a list of nodes. + """ + if pattern is not None: + pattern = pattern.lower() + searched_nodes = [ + node for name, node in self._leaf_nodes.items() + if pattern in name.lower() + ] + else: + searched_nodes = [node for node in self._leaf_nodes.values()] + return searched_nodes + + def search_nodes_by_pattern(self, pattern): + """ + Search node by a given pattern. + + Search node which pattern is the part of the last node. Example: pattern=ops, node1=default/ops, + node2=default/ops/weight, so node2 will be ignore and only node1 will be return. + + Args: + pattern (Union[str, None]): The pattern of the node to search. + + Returns: + list[Node], a list of nodes. + """ + searched_nodes = [] + if pattern and pattern != '/': + pattern = pattern.lower() + for name, node in self._normal_node_map.items(): + name = name.lower() + pattern_index = name.rfind(pattern) + if pattern_index >= 0 and name.find('/', pattern_index + len(pattern)) == -1: + searched_nodes.append(node) + return searched_nodes + + def _build_node_tree(self, root, node_name, node_type): + """ + Build node tree. + + Args: + root (NodeTree): Root node of node tree. + node_name (str): Node name. + node_type (str): Node type. + """ + scope_names = node_name.split('/') + cur_node = root + full_name = "" + for scope_name in scope_names[:-1]: + full_name = '/'.join([full_name, scope_name]) if full_name else scope_name + scope_node = self._get_normal_node(node_name=full_name) + sub_node = cur_node.get(scope_name) + if not sub_node: + sub_node = cur_node.add(scope_name, scope_node.type) + cur_node = sub_node + cur_node.add(scope_names[-1], node_type) + + def _traverse_node_tree(self, cur_node, search_node_list): + """Traverse the node tree and construct the searched nodes list.""" + if not cur_node.get_children(): + return + for _, sub_node in cur_node.get_children(): + sub_nodes = [] + self._traverse_node_tree(sub_node, sub_nodes) + sub_node_dict = { + 'name': sub_node.node_name, + 'type': sub_node.node_type, + 'nodes': sub_nodes + } + search_node_list.append(sub_node_dict) + def _parse_inputs(self, input_protos, node): """ Parse `anf_ir_pb2.InputProto` object. diff --git a/mindinsight/debugger/stream_cache/node.py b/mindinsight/datavisual/data_transform/graph/node_tree.py similarity index 100% rename from mindinsight/debugger/stream_cache/node.py rename to mindinsight/datavisual/data_transform/graph/node_tree.py diff --git a/mindinsight/datavisual/processors/graph_processor.py b/mindinsight/datavisual/processors/graph_processor.py index 3518e09a..c71e447c 100644 --- a/mindinsight/datavisual/processors/graph_processor.py +++ b/mindinsight/datavisual/processors/graph_processor.py @@ -103,12 +103,15 @@ class GraphProcessor(BaseProcessor): limit (int): The max data items for per page. Returns: - TypedDict('Names', {'names': list[str]}), {"names": ["node_names"]}. + Dict, the searched nodes. """ offset = Validation.check_offset(offset=offset) limit = Validation.check_limit(limit, min_value=1, max_value=1000) - names = self._graph.search_node_names(search_content, offset, limit) - return {"names": names} + nodes = self._graph.search_nodes_by_pattern(search_content) + real_offset = offset * limit + search_nodes = self._graph.get_nodes(nodes[real_offset:real_offset + limit]) + + return {"nodes": search_nodes} def search_single_node(self, name): """ diff --git a/mindinsight/debugger/stream_cache/debugger_graph.py b/mindinsight/debugger/stream_cache/debugger_graph.py index af2abb74..f0deea95 100644 --- a/mindinsight/debugger/stream_cache/debugger_graph.py +++ b/mindinsight/debugger/stream_cache/debugger_graph.py @@ -19,14 +19,10 @@ from mindinsight.datavisual.data_transform.graph.msgraph import MSGraph from mindinsight.debugger.common.exceptions.exceptions import \ DebuggerNodeNotInGraphError, DebuggerParamValueError from mindinsight.debugger.common.log import logger as log -from .node import NodeTree class DebuggerGraph(MSGraph): """The `DebuggerGraph` object provides interfaces to describe a debugger graph.""" - def __init__(self): - super(DebuggerGraph, self).__init__() - self._node_tree = None def get_node_name_by_full_name(self, full_name): """Get node name by full names.""" @@ -44,95 +40,6 @@ class DebuggerGraph(MSGraph): return node.full_name if node else '' - def get_nodes(self, searched_node_list): - """ - Search node names by a given pattern. - - Args: - searched_node_list (list[Node]): A list of leaf nodes that - matches the given search pattern. - - Returns: - A list of dict including the searched nodes. - [{ - "name": "Default", - "type": "name_scope", - "nodes": [{ - "name": "Default/Conv2D1", - "type": "name_scope", - "nodes": [{ - ... - }] - }] - }, - { - "name": "Gradients", - "type": "name_scope", - "nodes": [{ - "name": "Gradients/Default", - "type": "name_scope", - "nodes": [{ - ... - }] - }] - """ - # save the node in the NodeTree - self._node_tree = NodeTree() - for node in searched_node_list: - self._build_node_tree(node.name, node.type) - - # get the searched nodes in the NodeTree and reorganize them - searched_list = [] - self._traverse_node_tree(self._node_tree, searched_list) - - return searched_list - - def search_nodes_by_pattern(self, pattern): - """ - Search node by a given pattern. - - Args: - pattern (Union[str, None]): The pattern of the node to search, - if None, return all node names. - - Returns: - list[Node], a list of node. - """ - if pattern is not None: - pattern = pattern.lower() - searched_nodes = [ - node for name, node in self._leaf_nodes.items() - if pattern in name.lower() - ] - else: - searched_nodes = [node for _, node in self._leaf_nodes.items()] - return searched_nodes - - def _build_node_tree(self, node_name, node_type): - """Build node tree.""" - scope_names = node_name.split('/') - cur_node = self._node_tree - for scope_name in scope_names[:-1]: - sub_node = cur_node.get(scope_name) - if not sub_node: - sub_node = cur_node.add(scope_name) - cur_node = sub_node - cur_node.add(scope_names[-1], node_type) - - def _traverse_node_tree(self, cur_node, search_node_list): - """Traverse the watch nodes and update the total watched node list.""" - if not cur_node.get_children(): - return - for _, sub_node in cur_node.get_children(): - sub_nodes = [] - self._traverse_node_tree(sub_node, sub_nodes) - sub_node_dict = { - 'name': sub_node.node_name, - 'type': sub_node.node_type, - 'nodes': sub_nodes - } - search_node_list.append(sub_node_dict) - def get_node_type(self, node_name): """ Get the type of the node. diff --git a/mindinsight/debugger/stream_handler/graph_handler.py b/mindinsight/debugger/stream_handler/graph_handler.py index 5e716805..e9428031 100644 --- a/mindinsight/debugger/stream_handler/graph_handler.py +++ b/mindinsight/debugger/stream_handler/graph_handler.py @@ -153,7 +153,7 @@ class GraphHandler(StreamHandlerBase): Returns: list[Node], a list of node. """ - return self._graph.search_nodes_by_pattern(scope_name) + return self._graph.search_leaf_nodes_by_pattern(scope_name) def get_searched_node_list(self): """Get searched node list.""" diff --git a/tests/st/func/datavisual/graph/graph_results/test_search_nodes_success_result1.json b/tests/st/func/datavisual/graph/graph_results/test_search_nodes_success_result1.json index d8132275..0bb11faf 100644 --- a/tests/st/func/datavisual/graph/graph_results/test_search_nodes_success_result1.json +++ b/tests/st/func/datavisual/graph/graph_results/test_search_nodes_success_result1.json @@ -1 +1 @@ -{"names":["Default/bn1","Default/bn1-BatchNorm2d","Default/bn1-BatchNorm2d/Parameter[22]_3","Default/bn1-BatchNorm2d/Parameter[22]_3/conv1.weight","Default/bn1-BatchNorm2d/Parameter[22]_3/x","Default/bn1-BatchNorm2d/Parameter[22]_3/x1","Default/bn1-BatchNorm2d/Parameter[22]_3/x10","Default/bn1-BatchNorm2d/Parameter[22]_3/x11","Default/bn1-BatchNorm2d/Parameter[22]_3/x12","Default/bn1-BatchNorm2d/Parameter[22]_3/x13","Default/bn1-BatchNorm2d/Parameter[22]_3/x14","Default/bn1-BatchNorm2d/Parameter[22]_3/x15","Default/bn1-BatchNorm2d/Parameter[22]_3/x16","Default/bn1-BatchNorm2d/Parameter[22]_3/x17","Default/bn1-BatchNorm2d/Parameter[22]_3/x18","Default/bn1-BatchNorm2d/Parameter[22]_3/x19","Default/bn1-BatchNorm2d/Parameter[22]_3/x2","Default/bn1-BatchNorm2d/Parameter[22]_3/x20","Default/bn1-BatchNorm2d/Parameter[22]_3/x3","Default/bn1-BatchNorm2d/Parameter[22]_3/x4","Default/bn1-BatchNorm2d/Parameter[22]_3/x5","Default/bn1-BatchNorm2d/Parameter[22]_3/x6","Default/bn1-BatchNorm2d/Parameter[22]_3/x7","Default/bn1-BatchNorm2d/Parameter[22]_3/x8","Default/bn1-BatchNorm2d/Parameter[22]_3/x9","Default/bn1-BatchNorm2d/cst13","Default/bn1-BatchNorm2d/cst25","Default/bn1-BatchNorm2d/tuple_getitem105","Default/bn1-BatchNorm2d/tuple_getitem56","Default/bn1/Add[5]_0","Default/bn1/Add[5]_0/Add50","Default/bn1/Add[5]_0/Add51","Default/bn1/Add[5]_0/Add52","Default/bn1/Add[5]_0/Add53","Default/bn1/Add[5]_0/Add54","Default/bn1/Reshape[12]_1","Default/bn1/Reshape[12]_1/Reshape1","Default/bn1/Reshape[12]_1/Reshape10","Default/bn1/Reshape[12]_1/Reshape11","Default/bn1/Reshape[12]_1/Reshape12","Default/bn1/Reshape[12]_1/Reshape2","Default/bn1/Reshape[12]_1/Reshape3","Default/bn1/Reshape[12]_1/Reshape4","Default/bn1/Reshape[12]_1/Reshape5","Default/bn1/Reshape[12]_1/Reshape6","Default/bn1/Reshape[12]_1/Reshape7","Default/bn1/Reshape[12]_1/Reshape8","Default/bn1/Reshape[12]_1/Reshape9","Default/bn1/x","Default/bn1/x11"]} \ No newline at end of file +{"nodes": [{"name": "Default", "type": "name_scope", "nodes": [{"name": "Default/bn1-BatchNorm2d", "type": "name_scope", "nodes": []}, {"name": "Default/bn1", "type": "name_scope", "nodes": []}]}]} \ No newline at end of file diff --git a/tests/st/func/debugger/expect_results/restful_results/search_unwatched_leaf_node.json b/tests/st/func/debugger/expect_results/restful_results/search_unwatched_leaf_node.json index d5e6cba6..deb924c3 100644 --- a/tests/st/func/debugger/expect_results/restful_results/search_unwatched_leaf_node.json +++ b/tests/st/func/debugger/expect_results/restful_results/search_unwatched_leaf_node.json @@ -1 +1 @@ -{"nodes": [{"name": "Default", "type": null, "nodes": [{"name": "Default/optimizer-Momentum", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/Parameter[18]_7", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/Parameter[18]_7/moments.fc3.bias", "type": "Parameter", "nodes": [], "watched": 0}], "watched": 1}], "watched": 1}], "watched": 1}]} \ No newline at end of file +{"nodes": [{"name": "Default", "type": "name_scope", "nodes": [{"name": "Default/optimizer-Momentum", "type": "name_scope", "nodes": [{"name": "Default/optimizer-Momentum/Parameter[18]_7", "type": "aggregation_scope", "nodes": [{"name": "Default/optimizer-Momentum/Parameter[18]_7/moments.fc3.bias", "type": "Parameter", "nodes": [], "watched": 0}], "watched": 1}], "watched": 1}], "watched": 1}]} \ No newline at end of file diff --git a/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_offset_expected_results1.json b/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_offset_expected_results1.json index fcbe2e7c..10744e28 100644 --- a/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_offset_expected_results1.json +++ b/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_offset_expected_results1.json @@ -1 +1 @@ -{"names":["Default/bn1-BatchNorm2d/Parameter[22]_3/conv1.weight","Default/bn1-BatchNorm2d/Parameter[22]_3/x","Default/bn1-BatchNorm2d/Parameter[22]_3/x1"]} \ No newline at end of file +{"nodes": [{"name": "Default", "type": "name_scope", "nodes": [{"name": "Default/bn1", "type": "name_scope", "nodes": []}]}]} \ No newline at end of file diff --git a/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results1.json b/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results1.json index 2e47f1de..35f1ac3b 100644 --- a/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results1.json +++ b/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results1.json @@ -1 +1 @@ -{"names":["Default","Default/bn1","Default/bn1-BatchNorm2d","Default/bn1-BatchNorm2d/Parameter[22]_3","Default/bn1-BatchNorm2d/Parameter[22]_3/conv1.weight","Default/bn1-BatchNorm2d/Parameter[22]_3/x","Default/bn1-BatchNorm2d/Parameter[22]_3/x1","Default/bn1-BatchNorm2d/Parameter[22]_3/x10","Default/bn1-BatchNorm2d/Parameter[22]_3/x11","Default/bn1-BatchNorm2d/Parameter[22]_3/x12","Default/bn1-BatchNorm2d/Parameter[22]_3/x13","Default/bn1-BatchNorm2d/Parameter[22]_3/x14","Default/bn1-BatchNorm2d/Parameter[22]_3/x15","Default/bn1-BatchNorm2d/Parameter[22]_3/x16","Default/bn1-BatchNorm2d/Parameter[22]_3/x17","Default/bn1-BatchNorm2d/Parameter[22]_3/x18","Default/bn1-BatchNorm2d/Parameter[22]_3/x19","Default/bn1-BatchNorm2d/Parameter[22]_3/x2","Default/bn1-BatchNorm2d/Parameter[22]_3/x20","Default/bn1-BatchNorm2d/Parameter[22]_3/x3","Default/bn1-BatchNorm2d/Parameter[22]_3/x4","Default/bn1-BatchNorm2d/Parameter[22]_3/x5","Default/bn1-BatchNorm2d/Parameter[22]_3/x6","Default/bn1-BatchNorm2d/Parameter[22]_3/x7","Default/bn1-BatchNorm2d/Parameter[22]_3/x8","Default/bn1-BatchNorm2d/Parameter[22]_3/x9","Default/bn1-BatchNorm2d/cst13","Default/bn1-BatchNorm2d/cst25","Default/bn1-BatchNorm2d/tuple_getitem105","Default/bn1-BatchNorm2d/tuple_getitem56","Default/bn1/Add[5]_0","Default/bn1/Add[5]_0/Add50","Default/bn1/Add[5]_0/Add51","Default/bn1/Add[5]_0/Add52","Default/bn1/Add[5]_0/Add53","Default/bn1/Add[5]_0/Add54","Default/bn1/Reshape[12]_1","Default/bn1/Reshape[12]_1/Reshape1","Default/bn1/Reshape[12]_1/Reshape10","Default/bn1/Reshape[12]_1/Reshape11","Default/bn1/Reshape[12]_1/Reshape12","Default/bn1/Reshape[12]_1/Reshape2","Default/bn1/Reshape[12]_1/Reshape3","Default/bn1/Reshape[12]_1/Reshape4","Default/bn1/Reshape[12]_1/Reshape5","Default/bn1/Reshape[12]_1/Reshape6","Default/bn1/Reshape[12]_1/Reshape7","Default/bn1/Reshape[12]_1/Reshape8","Default/bn1/Reshape[12]_1/Reshape9","Default/bn1/x","Default/bn1/x11","Default/conv1-Conv2d","Default/conv1-Conv2d/Conv2D55","Default/conv1-Conv2d/Parameter[12]_2","Default/conv1-Conv2d/Parameter[12]_2/conv1.weight","Default/conv1-Conv2d/Parameter[12]_2/x","Default/conv1-Conv2d/Parameter[12]_2/x1","Default/conv1-Conv2d/Parameter[12]_2/x10","Default/conv1-Conv2d/Parameter[12]_2/x2","Default/conv1-Conv2d/Parameter[12]_2/x3","Default/conv1-Conv2d/Parameter[12]_2/x4","Default/conv1-Conv2d/Parameter[12]_2/x5","Default/conv1-Conv2d/Parameter[12]_2/x6","Default/conv1-Conv2d/Parameter[12]_2/x7","Default/conv1-Conv2d/Parameter[12]_2/x8","Default/conv1-Conv2d/Parameter[12]_2/x9"]} \ No newline at end of file +{"nodes": []} \ No newline at end of file diff --git a/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results2.json b/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results2.json index d8132275..0bb11faf 100644 --- a/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results2.json +++ b/tests/ut/datavisual/processors/graph_results/test_search_node_names_with_search_content_expected_results2.json @@ -1 +1 @@ -{"names":["Default/bn1","Default/bn1-BatchNorm2d","Default/bn1-BatchNorm2d/Parameter[22]_3","Default/bn1-BatchNorm2d/Parameter[22]_3/conv1.weight","Default/bn1-BatchNorm2d/Parameter[22]_3/x","Default/bn1-BatchNorm2d/Parameter[22]_3/x1","Default/bn1-BatchNorm2d/Parameter[22]_3/x10","Default/bn1-BatchNorm2d/Parameter[22]_3/x11","Default/bn1-BatchNorm2d/Parameter[22]_3/x12","Default/bn1-BatchNorm2d/Parameter[22]_3/x13","Default/bn1-BatchNorm2d/Parameter[22]_3/x14","Default/bn1-BatchNorm2d/Parameter[22]_3/x15","Default/bn1-BatchNorm2d/Parameter[22]_3/x16","Default/bn1-BatchNorm2d/Parameter[22]_3/x17","Default/bn1-BatchNorm2d/Parameter[22]_3/x18","Default/bn1-BatchNorm2d/Parameter[22]_3/x19","Default/bn1-BatchNorm2d/Parameter[22]_3/x2","Default/bn1-BatchNorm2d/Parameter[22]_3/x20","Default/bn1-BatchNorm2d/Parameter[22]_3/x3","Default/bn1-BatchNorm2d/Parameter[22]_3/x4","Default/bn1-BatchNorm2d/Parameter[22]_3/x5","Default/bn1-BatchNorm2d/Parameter[22]_3/x6","Default/bn1-BatchNorm2d/Parameter[22]_3/x7","Default/bn1-BatchNorm2d/Parameter[22]_3/x8","Default/bn1-BatchNorm2d/Parameter[22]_3/x9","Default/bn1-BatchNorm2d/cst13","Default/bn1-BatchNorm2d/cst25","Default/bn1-BatchNorm2d/tuple_getitem105","Default/bn1-BatchNorm2d/tuple_getitem56","Default/bn1/Add[5]_0","Default/bn1/Add[5]_0/Add50","Default/bn1/Add[5]_0/Add51","Default/bn1/Add[5]_0/Add52","Default/bn1/Add[5]_0/Add53","Default/bn1/Add[5]_0/Add54","Default/bn1/Reshape[12]_1","Default/bn1/Reshape[12]_1/Reshape1","Default/bn1/Reshape[12]_1/Reshape10","Default/bn1/Reshape[12]_1/Reshape11","Default/bn1/Reshape[12]_1/Reshape12","Default/bn1/Reshape[12]_1/Reshape2","Default/bn1/Reshape[12]_1/Reshape3","Default/bn1/Reshape[12]_1/Reshape4","Default/bn1/Reshape[12]_1/Reshape5","Default/bn1/Reshape[12]_1/Reshape6","Default/bn1/Reshape[12]_1/Reshape7","Default/bn1/Reshape[12]_1/Reshape8","Default/bn1/Reshape[12]_1/Reshape9","Default/bn1/x","Default/bn1/x11"]} \ No newline at end of file +{"nodes": [{"name": "Default", "type": "name_scope", "nodes": [{"name": "Default/bn1-BatchNorm2d", "type": "name_scope", "nodes": []}, {"name": "Default/bn1", "type": "name_scope", "nodes": []}]}]} \ No newline at end of file diff --git a/tests/ut/datavisual/processors/test_graph_processor.py b/tests/ut/datavisual/processors/test_graph_processor.py index da0d33f3..de601138 100644 --- a/tests/ut/datavisual/processors/test_graph_processor.py +++ b/tests/ut/datavisual/processors/test_graph_processor.py @@ -149,7 +149,7 @@ class TestGraphProcessor: graph_processor = GraphProcessor(self._train_id, self._mock_data_manager) results = graph_processor.search_node_names(search_content, test_offset, test_limit) if search_content == 'not_exist_search_content': - expected_results = {'names': []} + expected_results = {'nodes': []} assert results == expected_results else: expected_file_path = os.path.join(self.graph_results_dir, result_file) @@ -173,7 +173,7 @@ class TestGraphProcessor: """Test search node names with offset.""" test_search_content = "Default/bn1" test_offset = offset - test_limit = 3 + test_limit = 1 graph_processor = GraphProcessor(self._train_id, self._mock_data_manager) results = graph_processor.search_node_names(test_search_content, test_offset, test_limit) diff --git a/tests/ut/debugger/expected_results/graph/search_node_1.json b/tests/ut/debugger/expected_results/graph/search_node_1.json index 4d075eee..8ccafaa9 100644 --- a/tests/ut/debugger/expected_results/graph/search_node_1.json +++ b/tests/ut/debugger/expected_results/graph/search_node_1.json @@ -1 +1 @@ -{"nodes": [{"name": "Default", "type": null, "nodes": [{"name": "Default/network-WithLossCell", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst1", "type": "Const", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst2", "type": "Const", "nodes": []}]}]}, {"name": "Default/tuple_getitem[10]_0", "type": null, "nodes": [{"name": "Default/tuple_getitem[10]_0/cst3", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst4", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst5", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst6", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst7", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst27", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst28", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst32", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst33", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst37", "type": "Const", "nodes": []}]}, {"name": "Default/optimizer-Momentum", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/tuple_getitem[16]_2", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst9", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst10", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst12", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst13", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst15", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst16", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst18", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst19", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst21", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst22", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst24", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst25", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst29", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst30", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst34", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst35", "type": "Const", "nodes": []}]}, {"name": "Default/optimizer-Momentum/Depend[8]_4", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/Depend[8]_4/cst11", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst14", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst17", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst20", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst23", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst26", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst31", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst36", "type": "Const", "nodes": []}]}]}]}, {"name": "Gradients", "type": null, "nodes": [{"name": "Gradients/Default", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/cst8", "type": "Const", "nodes": []}]}]}]}]}]}]} \ No newline at end of file +{"nodes": [{"name": "Default", "type": "name_scope", "nodes": [{"name": "Default/network-WithLossCell", "type": "name_scope", "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": "name_scope", "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst1", "type": "Const", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst2", "type": "Const", "nodes": []}]}]}, {"name": "Default/tuple_getitem[10]_0", "type": "aggregation_scope", "nodes": [{"name": "Default/tuple_getitem[10]_0/cst3", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst4", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst5", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst6", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst7", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst27", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst28", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst32", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst33", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst37", "type": "Const", "nodes": []}]}, {"name": "Default/optimizer-Momentum", "type": "name_scope", "nodes": [{"name": "Default/optimizer-Momentum/tuple_getitem[16]_2", "type": "aggregation_scope", "nodes": [{"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst9", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst10", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst12", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst13", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst15", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst16", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst18", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst19", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst21", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst22", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst24", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst25", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst29", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst30", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst34", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst35", "type": "Const", "nodes": []}]}, {"name": "Default/optimizer-Momentum/Depend[8]_4", "type": "aggregation_scope", "nodes": [{"name": "Default/optimizer-Momentum/Depend[8]_4/cst11", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst14", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst17", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst20", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst23", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst26", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst31", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst36", "type": "Const", "nodes": []}]}]}]}, {"name": "Gradients", "type": "name_scope", "nodes": [{"name": "Gradients/Default", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/cst8", "type": "Const", "nodes": []}]}]}]}]}]}]} \ No newline at end of file diff --git a/tests/ut/debugger/expected_results/graph/search_nodes_0.json b/tests/ut/debugger/expected_results/graph/search_nodes_0.json index 44bb7437..1b3de008 100644 --- a/tests/ut/debugger/expected_results/graph/search_nodes_0.json +++ b/tests/ut/debugger/expected_results/graph/search_nodes_0.json @@ -1 +1 @@ -{"nodes": [{"name": "Default", "type": null, "nodes": [{"name": "Default/network-WithLossCell", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/OneHot-op0", "type": "OneHot", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/SoftmaxCrossEntropyWithLogits-op18", "type": "SoftmaxCrossEntropyWithLogits", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/ReduceMean-op60", "type": "ReduceMean", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/args1", "type": "Parameter", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst1", "type": "Const", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst2", "type": "Const", "nodes": []}]}]}]}, {"name": "Gradients", "type": null, "nodes": [{"name": "Gradients/Default", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/Mul-op20", "type": "Mul", "nodes": []}, {"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/cst8", "type": "Const", "nodes": []}]}]}]}]}]}]} \ No newline at end of file +{"nodes": [{"name": "Default", "type": "name_scope", "nodes": [{"name": "Default/network-WithLossCell", "type": "name_scope", "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": "name_scope", "nodes": []}]}]}, {"name": "Gradients", "type": "name_scope", "nodes": [{"name": "Gradients/Default", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": "name_scope", "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits", "type": "name_scope", "nodes": []}]}]}]}]}]} \ No newline at end of file