Skip to content

Commit

Permalink
Fix a issue when running with graph_runtime_debug in python (apache#2271
Browse files Browse the repository at this point in the history
)

* fix a issue when running with graph_runtime_debug in python;

* add support to `debug_get_output` in python;

* comply with the linter;
  • Loading branch information
liangfu authored and tqchen committed Dec 12, 2018
1 parent 331abac commit aa1310d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
15 changes: 15 additions & 0 deletions python/tvm/contrib/debugger/debug_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ 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
"""
eid = 0
order = 0
output_tensors = {}
for node, time in 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)
output_tensors[key] = self._output_tensor_list[eid]
eid += 1
return output_tensors

def dump_output_tensor(self):
"""Dump the outputs to a temporary folder, the tensors are in numpy format
"""
Expand Down
28 changes: 28 additions & 0 deletions python/tvm/contrib/debugger/debug_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ def _run_debug(self):
for j in range(num_outputs):
out_tensor = self._get_output_by_layer(i, j)
self.debug_datum._output_tensor_list.append(out_tensor)

def debug_get_output(self, node, out):
"""Run graph upto node and get the output to out
Parameters
----------
node : int / str
The node index or name
out : NDArray
The output array container
"""
ret = None
if isinstance(node, str):
output_tensors = self.debug_datum.get_output_tensors()
try:
ret = output_tensors[node]
except:
node_list = output_tensors.keys()
raise RuntimeError("Node " + node + " not found, available nodes are: "
+ str(node_list) + ".")
elif isinstance(node, int):
output_tensors = self.debug_datum._output_tensor_list
ret = output_tensors[node]
else:
raise RuntimeError("Require node index or name only.")
return ret

def run(self, **input_dict):
"""Run forward execution of the graph with debug
Expand Down
12 changes: 2 additions & 10 deletions python/tvm/contrib/graph_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ def __init__(self, module):
self._get_output = module["get_output"]
self._get_input = module["get_input"]
self._get_num_outputs = module["get_num_outputs"]
try:
self._debug_get_output = module["debug_get_output"]
except AttributeError:
pass
self._load_params = module["load_params"]

def set_input(self, key=None, value=None, **params):
Expand Down Expand Up @@ -209,12 +205,8 @@ def debug_get_output(self, node, out):
out : NDArray
The output array container
"""
if hasattr(self, '_debug_get_output'):
self._debug_get_output(node, out)
else:
raise RuntimeError(
"Please compile runtime with USE_GRAPH_RUNTIME_DEBUG = 0")
return out
raise NotImplementedError(
"Please use debugger.debug_runtime as graph_runtime instead.")

def load_params(self, params_bytes):
"""Load parameters from serialized byte array of parameter dict.
Expand Down

0 comments on commit aa1310d

Please sign in to comment.