Skip to content

Commit

Permalink
[Executor] Debug Graph Executor - Dumping output tensors include topo…
Browse files Browse the repository at this point in the history
…graphical ordering (apache#9557)
  • Loading branch information
AndrewZhaoLuo authored and ylc committed Jan 13, 2022
1 parent e86ba83 commit 84ed10d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions python/tvm/contrib/debugger/debug_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import collections
import json
import os

import numpy as np
import tvm

Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 84ed10d

Please sign in to comment.