Skip to content

Dump torch::jit::AliasDb objects as Graphviz files#50452

Closed
tlemo wants to merge 3 commits intopytorch:masterfrom
csarofeen:aliasdb_to_graphviz
Closed

Dump torch::jit::AliasDb objects as Graphviz files#50452
tlemo wants to merge 3 commits intopytorch:masterfrom
csarofeen:aliasdb_to_graphviz

Conversation

@tlemo
Copy link
Copy Markdown
Contributor

@tlemo tlemo commented Jan 13, 2021

This PR adds a simple debugging helper which exports the AliasDb state as a GraphViz graph definition. The generated files can be viewed with any Graphviz viewer (including online based, for example http://viz-js.com)

Usage:

  1. Call AliasDb::dumpToGraphvizFile() from a debugger. Using gdb for example:
    call aliasDb_->dumpToGraphvizFile("alias.dot")

  2. Add explicit calls to AliasDb::dumpToGraphvizFile(), which returns true if it succeeds.

An example output file is attached: example.zip

@facebook-github-bot facebook-github-bot added cla signed oncall: jit Add this issue/PR to JIT oncall triage queue labels Jan 13, 2021
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jan 13, 2021

💊 CI failures summary and remediations

As of commit 247381d (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

Extra GitHub checks: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 13, 2021

Codecov Report

Merging #50452 (247381d) into master (8b501df) will increase coverage by 0.04%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master   #50452      +/-   ##
==========================================
+ Coverage   80.66%   80.70%   +0.04%     
==========================================
  Files        1913     1909       -4     
  Lines      208091   207097     -994     
==========================================
- Hits       167849   167134     -715     
+ Misses      40242    39963     -279     

@tlemo
Copy link
Copy Markdown
Contributor Author

tlemo commented Jan 13, 2021

The clang-tidy & clang-format failures seem infrastructure related

Comment thread torch/csrc/jit/ir/alias_analysis.cpp Outdated
bool AliasDb::dumpToDot(const char* filename) const {
std::ofstream dot(filename);
if (!dot.good()) {
std::cout << "Failed to open the IR graph file: '" << filename << "'\n";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we typically use const std::string& and use exceptions for signaling errors rather than return values.

I think an even better (and more consistent with the rest of the JIT API) way would be to just define the op << .
Then the string dump (great idea) you mentioned on slack could use that in the string stream and opening the file yourself when dumping doesn't seem too much of a hassle (and then people can also dump to stdout or over the network or whatever if they want to).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I agree. One can also point out that printing an message to console and returning an error is bad form.

In this case, throwing an exception doesn't play nicely in a debugger, which is one of the intended use-cases. Normally in the debugger a simple message would do, but the return bool is a compromise to allow some basic composition (so the caller can still tell if it faild)

Same thing with the operator<< overloading - doesn't work well in debuggers.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good points. Happily I don't get to decide on it, anyways. But the string would be possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the string would be possible?

Using std::string for the filename parameter? Same story: from the C++ side, it seems a minor change, but for a debugger, evaluating foo("bar") when foo takes a const std::string& is far from trivial and not all the debugger support it (my workflow involves using gdb, lldb, windbg/cdb & visual studio regularly and I've learned the hard way to keep debugging helpers as simple as possible).

@mrshenli mrshenli added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jan 15, 2021
@mrshenli mrshenli requested a review from suo January 15, 2021 03:09
Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, LGTM!! Thanks for doing this.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@eellison merged this pull request in ca3ce77.

@csarofeen csarofeen deleted the aliasdb_to_graphviz branch June 9, 2021 13:48
@csarofeen csarofeen restored the aliasdb_to_graphviz branch June 9, 2021 13:48
@csarofeen csarofeen deleted the aliasdb_to_graphviz branch June 9, 2021 13:51
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
This PR adds a simple debugging helper which exports the AliasDb state as a [GraphViz](http://www.graphviz.org/) graph definition. The generated files can be viewed with any Graphviz viewer (including online based, for example http://viz-js.com)

Usage:

1. Call `AliasDb::dumpToGraphvizFile()` from a debugger. Using gdb for example:
`call aliasDb_->dumpToGraphvizFile("alias.dot")`

2. Add explicit calls to `AliasDb::dumpToGraphvizFile()`, which returns `true` if it succeeds.

An example output file is attached: [example.zip](https://github.com/pytorch/pytorch/files/5805840/example.zip)

Pull Request resolved: pytorch#50452

Reviewed By: ngimel

Differential Revision: D25980222

Pulled By: eellison

fbshipit-source-id: 47805a0a81ce73c6ba859340d37b9a806f9000d5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed Merged oncall: jit Add this issue/PR to JIT oncall triage queue open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants