Skip to content

Add demo_graph, hack to make IR scopes work again (fixing JIT passes)#10749

Closed
ml7 wants to merge 2 commits intopytorch:masterfrom
ml7:export-D9389809
Closed

Add demo_graph, hack to make IR scopes work again (fixing JIT passes)#10749
ml7 wants to merge 2 commits intopytorch:masterfrom
ml7:export-D9389809

Conversation

@ml7
Copy link
Copy Markdown

@ml7 ml7 commented Aug 21, 2018

Summary:
Added a demo_graph so that users can try out writing model graph visualization for TensorboardX with various models (VGG, ResNet, DenseNet, and some other toy examples).

Working implementation that generates the graph correctly without extraneous information. It's pretty hacky and I'm trying to clean it up, any comments on the code are appreciated!

The problem was that the JIT passes weren't preserving scopes when they were creating new nodes so nodes were ending up without scope names and this caused us to lose valuable information in visualization.

Sample graph visualization (ResNet model) generated below:

{F136387033}

Differential Revision: D9389809

…pytorch#10749)

Summary:
Pull Request resolved: pytorch#10749

Added a demo_graph so that users can try out writing model graph visualization for TensorboardX with various models (VGG, ResNet, DenseNet, and some other toy examples).

Working implementation that generates the graph correctly without extraneous information. It's pretty hacky and I'm trying to clean it up, any comments on the code are appreciated!

The problem was that the JIT passes weren't preserving scopes when they were creating new nodes so nodes were ending up without scope names and this caused us to lose valuable information in visualization.

Sample graph visualization (ResNet model) generated below:

{F136387033}

Differential Revision: D9389809

fbshipit-source-id: 5e21ca3fe7fea292ae126982180999bcc2041b45
@ml7 ml7 force-pushed the export-D9389809 branch from 83cea59 to 63f2aae Compare August 21, 2018 20:03
Copy link
Copy Markdown
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

insertConstantWithScope seems unnecessary and mostly duplicates the code of insertConstant. We should use Scope* more instead of passing around strings with scope names.

Comment thread torch/csrc/jit/passes/onnx.cpp Outdated
// Clone the node and add it to the new graph
auto cloneNode = [&](Node * node) {
auto n_ = ctx.block->appendNode(ctx.block->owningGraph()->createClone(node, envFn));
n_->setScopeFromString(node->scopeName());

This comment was marked as off-topic.

auto s = *constant_as<at::Scalar>(it->output());
WithInsertPoint guard(*it);
Value* r = block->owningGraph()->insertConstant(s.toTensor());
Value* r = block->owningGraph()->insertConstantWithScope(s.toTensor(), it->scopeName());

This comment was marked as off-topic.

Comment thread torch/csrc/jit/ir.h
std::string name2 = scope_root_.get()->name().toDisplayString();
if (name1.find(name2) < 0 &&
name2.find(name1) < 0 &&
scope->getRoot() != scope_root_.get()) {

This comment was marked as off-topic.

Remove insertConstantWithScope
@fmassa
Copy link
Copy Markdown
Member

fmassa commented Sep 11, 2018

ping @apaszke

@orionr
Copy link
Copy Markdown
Contributor

orionr commented Oct 3, 2018

Now that @ml7 is no longer an intern, I'm going to take this pull request over. Currently tensorboardX can't serialize PyTorch graphs, so hopefully we can figure out a good fix for this. cc @apaszke

@orionr
Copy link
Copy Markdown
Contributor

orionr commented Oct 3, 2018

Also cc @lanpa on this one.

orionr added a commit to orionr/pytorch that referenced this pull request Oct 5, 2018
Summary:
In order to support tensorboardX and other visualization tools, we need to make sure a non-empty scope is set on all nodes added by the JIT. This attempts to do this, but is still a WIP.

This is a new version of pytorch#10749

Differential Revision: D10224380

fbshipit-source-id: 3368f6d86e9f61dd699a868c41a8cb73a899ea26
@orionr
Copy link
Copy Markdown
Contributor

orionr commented Oct 5, 2018

Closing in favor of the new PR.

@orionr orionr closed this Oct 5, 2018
orionr added a commit to orionr/pytorch that referenced this pull request Oct 22, 2018
Summary:
In order to support tensorboardX and other visualization tools, we need to make sure a non-empty scope is set on all nodes added by the JIT. This attempts to do this, but is still a WIP.

This is a new version of pytorch#10749
Pull Request resolved: pytorch#12400

Differential Revision: D10224380

fbshipit-source-id: ae99180f98b71510e2a6261c5afe66fb79b1c857
facebook-github-bot pushed a commit that referenced this pull request Oct 24, 2018
Summary:
In order to support tensorboardX and other visualization tools, we need to make sure a non-empty scope is set on all nodes added by the JIT. This attempts to do this, but is still a WIP.

This is a new version of #10749
Pull Request resolved: #12400

Reviewed By: ezyang

Differential Revision: D10224380

Pulled By: orionr

fbshipit-source-id: d1bccd0eee9ef7c4354112c6a39a5987bfac2994
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
In order to support tensorboardX and other visualization tools, we need to make sure a non-empty scope is set on all nodes added by the JIT. This attempts to do this, but is still a WIP.

This is a new version of pytorch#10749
Pull Request resolved: pytorch#12400

Reviewed By: ezyang

Differential Revision: D10224380

Pulled By: orionr

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants