Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alternative prettyprinting method to Graph #50878

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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