Skip to content

Commit

Permalink
Add alternative prettyprinting method to Graph
Browse files Browse the repository at this point in the history
ghstack-source-id: 06b05e5ae284ce026a6aa39c0933706d03a54f2a
Pull Request resolved: #50878
  • Loading branch information
Ansley Ussery committed Jan 21, 2021
1 parent 480bb7d commit 938bc10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
14 changes: 0 additions & 14 deletions torch/fx/examples/inspect_utils.py

This file was deleted.

16 changes: 16 additions & 0 deletions torch/fx/graph.py
Expand Up @@ -785,6 +785,22 @@ def format_node(n : Node) -> Optional[str]:
s += '\n ' + node_str
return s

def print_tabular(self):
"""
Prints the intermediate representation of the graph in tabular
format.
"""
try:
from tabulate import tabulate
except ImportError:
print("`print_tabular` relies on the library `tabulate`, "
"which could not be found on this machine. Run `pip "
"install tabulate` to install the library.")
node_specs = [[n.op, n.name, n.target, n.args, n.kwargs]
for n in self.nodes]
print(tabulate(node_specs,
headers=['opcode', 'name', 'target', 'args', 'kwargs']))

def lint(self, root : Optional[torch.nn.Module] = None):
"""
Runs various checks on this Graph to make sure it is well-formed. In
Expand Down

0 comments on commit 938bc10

Please sign in to comment.