From 7cdcfafc91ff94a222e2bcbae1925418a85fd729 Mon Sep 17 00:00:00 2001 From: yelihua Date: Mon, 14 Sep 2020 12:01:27 +0800 Subject: [PATCH] delete tensor history in retrieve_node_by_bfs method --- mindinsight/debugger/debugger_server.py | 14 +++++++++++--- mindinsight/debugger/stream_cache/tensor.py | 1 + .../debugger/stream_handler/graph_handler.py | 7 +++---- .../debugger/stream_handler/tensor_handler.py | 3 ++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mindinsight/debugger/debugger_server.py b/mindinsight/debugger/debugger_server.py index 601f3ecd..98a5a834 100644 --- a/mindinsight/debugger/debugger_server.py +++ b/mindinsight/debugger/debugger_server.py @@ -713,7 +713,17 @@ class DebuggerServer: return {'metadata': {'state': 'pending'}} def retrieve_node_by_bfs(self, node_name, ascend=False): - """Get the graph and tensor history of the next node name according to node_name.""" + """ + Get the graph of the next node according to node_name. + + Args: + node_name (str): The name of current chosen leaf node. + ascend (bool): If True, traverse the input nodes; + If False, traverse the output nodes. Default is True. + + Returns: + dict, the next node information. + """ log.info("Retrieve node <%s> by bfs, `ascend` is :%s", node_name, ascend) reply = {} @@ -728,9 +738,7 @@ class DebuggerServer: 'single_node': True } search_graph = self._get_nodes_info(filter_condition) - tensor_history = self._get_tensor_history(next_node_name) reply = {'name': next_node_name} reply.update(search_graph) - reply.update(tensor_history) return reply diff --git a/mindinsight/debugger/stream_cache/tensor.py b/mindinsight/debugger/stream_cache/tensor.py index 01975254..a3cc41bf 100644 --- a/mindinsight/debugger/stream_cache/tensor.py +++ b/mindinsight/debugger/stream_cache/tensor.py @@ -148,6 +148,7 @@ class OpTensor(BaseTensor): """ tensor_value = self.get_tensor_value_by_shape(shape) res = {} + # the type of tensor_value is one of None, np.ndarray or str if isinstance(tensor_value, np.ndarray): statistics = TensorUtils.get_statistics_from_tensor(tensor_value) res['statistics'] = TensorUtils.get_statistics_dict(statistics) diff --git a/mindinsight/debugger/stream_handler/graph_handler.py b/mindinsight/debugger/stream_handler/graph_handler.py index adb31d25..8a54480e 100644 --- a/mindinsight/debugger/stream_handler/graph_handler.py +++ b/mindinsight/debugger/stream_handler/graph_handler.py @@ -229,13 +229,12 @@ class GraphHandler(StreamHandlerBase): Traverse the graph in order of breath-first search by given node. Args: - node_name (str): The node name which will be regarded - as the start node in graph. + node_name (str): The name of current chosen leaf node. ascend (bool): If True, traverse the input nodes; If False, traverse the output nodes. Default is True. Returns: - dict, including the searched node and its tensor value. + Union[None, dict], the next node object in dict type or None. """ self._graph_exists() bfs_order = self.bfs_order @@ -248,7 +247,7 @@ class GraphHandler(StreamHandlerBase): if node_name is None: if ascend is False: - next_node = bfs_order[-1] + next_node = None else: next_node = bfs_order[0] else: diff --git a/mindinsight/debugger/stream_handler/tensor_handler.py b/mindinsight/debugger/stream_handler/tensor_handler.py index e9b5dd91..d1484153 100644 --- a/mindinsight/debugger/stream_handler/tensor_handler.py +++ b/mindinsight/debugger/stream_handler/tensor_handler.py @@ -224,7 +224,7 @@ class TensorHandler(StreamHandlerBase): if prev_step < 0: return flag tensor = self._get_tensor(tensor_name, step=prev_step) - return bool(tensor and tensor.valule) + return bool(tensor and tensor.value) def get_tensor_value_by_name(self, tensor_name, prev=False): """Get tensor value by name in numpy type.""" @@ -283,6 +283,7 @@ class TensorHandler(StreamHandlerBase): if isinstance(tensor_info, dict): del tensor_info['has_prev_step'] del tensor_info['value'] + # the type of curr_tensor_slice is one of None, np.ndarray or str if isinstance(curr_tensor_slice, np.ndarray) and isinstance(prev_tensor_slice, np.ndarray): diff_tensor = TensorUtils.calc_diff_between_two_tensor(curr_tensor_slice, prev_tensor_slice, tolerance) result = np.stack([prev_tensor_slice, curr_tensor_slice, diff_tensor], axis=-1)