From ce6ccb168566067b542397b1fb0ae710631d2018 Mon Sep 17 00:00:00 2001 From: AndrewZhaoLuo Date: Fri, 3 Dec 2021 10:48:46 -0800 Subject: [PATCH] [Executor] Debug Graph Executor - Dumping output tensors include topographical ordering (#9557) --- python/tvm/contrib/debugger/debug_result.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/python/tvm/contrib/debugger/debug_result.py b/python/tvm/contrib/debugger/debug_result.py index 57c6851a109c..e53aa298a0f4 100644 --- a/python/tvm/contrib/debugger/debug_result.py +++ b/python/tvm/contrib/debugger/debug_result.py @@ -18,6 +18,7 @@ import collections import json import os + import numpy as np import tvm @@ -111,15 +112,18 @@ def get_graph_node_dtypes(self): return self._dtype_list def get_output_tensors(self): - """Dump the outputs to a temporary folder, the tensors are in numpy format""" + """Get the output tensors of each operation in numpy format""" eid = 0 order = 0 output_tensors = {} - for node, time in zip(self._nodes_list, self._time_list): + for i, (node, time) in enumerate(zip(self._nodes_list, self._time_list)): num_outputs = self.get_graph_node_output_num(node) for j in range(num_outputs): order += time[0] - key = node["name"] + "_" + str(j) + + # the node name is not unique, so we need a consistent + # indexing based on the list ordering in the nodes + key = f"{node['name']}____topo-index:{i}____output-num:{j}" output_tensors[key] = self._output_tensor_list[eid] eid += 1 return output_tensors @@ -141,14 +145,7 @@ def dump_output_tensor(self): """Dump the outputs to a temporary folder, the tensors are in numpy format""" # cleanup existing tensors before dumping self._cleanup_tensors() - eid = 0 - output_tensors = {} - for node in self._nodes_list: - num_outputs = self.get_graph_node_output_num(node) - for j in range(num_outputs): - key = node["name"] + "____" + str(j) - output_tensors[key] = self._output_tensor_list[eid] - eid += 1 + output_tensors = self.get_output_tensors() with open(os.path.join(self._dump_path, "output_tensors.params"), "wb") as param_f: param_f.write(save_tensors(output_tensors))