-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[Inlined Callstack Fix] Fix inlined callstack for blocks of the node. #56562
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
Conversation
Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 0b8b13a (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks reasonable, I have a couple of question inline:
| for (Node* n : graph->nodes()) { | ||
| if (n->kind() == prim::If) { | ||
| for (Block* block : n->blocks()) { | ||
| for (Node* if_node : block->nodes()) { | ||
| if (if_node->kind() == aten::add) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this could be factored out as a function findNodeOfGivenKind or something like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, you could try to use subgraph matcher for this, but i'm not sure that with the required boilerplate code it would be beneficial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment still applies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. But looking at this, it looks like it is just a 10ish lines of code without much resuse. If more similar code is added I suppose we can refactor. So for now I will leave it as is unless you have a strong opinion about it.
torch/csrc/jit/ir/ir.cpp
Outdated
| InlinedCallStack* raw_callstack_ptr = | ||
| new_node_cs ? new_node_cs->get() : nullptr; | ||
|
|
||
| if (!new_cs_entires.count(raw_callstack_ptr)) { | ||
| if (new_node_cs) { | ||
| new_cs_entires[raw_callstack_ptr] = | ||
| c10::make_intrusive<InlinedCallStack>( | ||
| *new_node_cs, callee, to_replace->sourceRange(), m_info); | ||
| } else { | ||
| new_cs_entires[raw_callstack_ptr] = | ||
| c10::make_intrusive<InlinedCallStack>( | ||
| callee, to_replace->sourceRange(), m_info); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seem to duplicate the code from inlineCallTo almost identically. Would it be possible to get rid of that duplication by calling inlineCallStackOfBlock there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I was almost gonna do that, but wanted to move too fast. Let me refactor it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix what I assume is a typo: new_cs_entires -> new_cs_entries
Also, why is it possible that
!new_cs_entires.count(raw_callstack_ptr) is true
but if (new_node_cs) is false?
Wouldn't if (new_node_cs) false means that raw_callstack_ptr is nullptr, and that new_cs_entires.count(raw_callstack_ptr) would be zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why is it possible that !new_cs_entires.count(raw_callstack_ptr) is true but if (new_node_cs) is false?
So say you are inlining:
class B(..):
def forward(self, x):
return x + 3
class A(..):
def forward(self, y):
return self.b.forward(y)
Then when you are inlining A's forward method you replace
%something = prim::CallMethod(...) with %something = aten::add(..
This aten::add node is created by cloning B's forward method. At that time aten::add node's cs is null. And new_cs_entires may not have an entry for raw_callstack_ptr = nullptr so if (!new_cs_entires.count(raw_callstack_ptr)) would be true.
Although I wonder if there is a bug here: Meaning if all the node's that dont have callstack ptr get clobbered together in new_cs_entires. But that is ok because we keep replacing them? @ZolotukhinM to confirm.
torch/csrc/jit/ir/ir.cpp
Outdated
| new_node->setCallStack(new_callstack_entries.at(raw_callstack_ptr)); | ||
| // We updated the inlined callstack of new_node. | ||
| // Same must be done for the nodes of the blocks of new_nodes. | ||
| // For exampl If node's block otherwise is not annotated appropriately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: exampl -> example
torch/csrc/jit/ir/ir.cpp
Outdated
| InlinedCallStack* raw_callstack_ptr = | ||
| new_node_cs ? new_node_cs->get() : nullptr; | ||
|
|
||
| if (!new_cs_entires.count(raw_callstack_ptr)) { | ||
| if (new_node_cs) { | ||
| new_cs_entires[raw_callstack_ptr] = | ||
| c10::make_intrusive<InlinedCallStack>( | ||
| *new_node_cs, callee, to_replace->sourceRange(), m_info); | ||
| } else { | ||
| new_cs_entires[raw_callstack_ptr] = | ||
| c10::make_intrusive<InlinedCallStack>( | ||
| callee, to_replace->sourceRange(), m_info); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix what I assume is a typo: new_cs_entires -> new_cs_entries
Also, why is it possible that
!new_cs_entires.count(raw_callstack_ptr) is true
but if (new_node_cs) is false?
Wouldn't if (new_node_cs) false means that raw_callstack_ptr is nullptr, and that new_cs_entires.count(raw_callstack_ptr) would be zero?
test/cpp/jit/test_misc.cpp
Outdated
| ASSERT_NE(mul_ss.str().find("line 6"), std::string::npos); | ||
| ASSERT_NE( | ||
| mul_ss.str().find("return self.A0.forward(x, y, z)"), std::string::npos); | ||
| ASSERT_NE(add_ss.str().find("return x * y"), std::string::npos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is return x * y in add_ss and not mul_ss?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thats a typo. Althoug the reason this still passes is because I think source range prints a few lines (2 I think) around the actual source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so are you changing
ASSERT_NE(add_ss.str().find("return x * y"), std::string::npos);
to
ASSERT_NE(mul_ss.str().find("return x * y"), std::string::npos);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really thought I did.
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
test/cpp/jit/test_misc.cpp
Outdated
| ASSERT_NE(mul_ss.str().find("line 6"), std::string::npos); | ||
| ASSERT_NE( | ||
| mul_ss.str().find("return self.A0.forward(x, y, z)"), std::string::npos); | ||
| ASSERT_NE(add_ss.str().find("return x * y"), std::string::npos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so are you changing
ASSERT_NE(add_ss.str().find("return x * y"), std::string::npos);
to
ASSERT_NE(mul_ss.str().find("return x * y"), std::string::npos);
torch/csrc/jit/ir/ir.cpp
Outdated
|
|
||
| void inlineCallStackOfNode( | ||
| Node* new_node, | ||
| std::unordered_map<InlinedCallStack*, InlinedCallStackPtr>& new_cs_entires, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the name is really new_cs_entires? not new_cs_entries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. OK thanks for that catch. I missed that somehow.
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only a couple of minor remarks from me.
| for (Node* n : graph->nodes()) { | ||
| if (n->kind() == prim::If) { | ||
| for (Block* block : n->blocks()) { | ||
| for (Node* if_node : block->nodes()) { | ||
| if (if_node->kind() == aten::add) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment still applies.
test/cpp/jit/test_misc.cpp
Outdated
| auto graph = c.get_method("forward").graph(); | ||
| torch::jit::Inline(*graph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use optimized_graph() method you won't need to call Inline directly (similarly to how it was done in existing tests).
test/cpp/jit/test_misc.cpp
Outdated
| #include <torch/csrc/jit/passes/graph_fuser.h> | ||
| #include <torch/csrc/jit/passes/guard_elimination.h> | ||
| #include <torch/csrc/jit/passes/inline_autodiff_subgraphs.h> | ||
| #include <torch/csrc/jit/passes/inliner.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be unnecessary if we use optimized_graph instead of just graph.
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 715b76b Pull Request resolved: pytorch#56562
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: d67dba6 Pull Request resolved: pytorch#56562
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
…f the node." Summary: Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D27902516](https://our.internmc.facebook.com/intern/diff/D27902516) [ghstack-poisoned]
|
This pull request has been merged in 5326ec6. |
…pytorch#56562) Summary: Pull Request resolved: pytorch#56562 Earlier inlined callstack was annotated only nodes. This left out nodes such as If which have block of nodes. These nodes should also be updated similarly. Test Plan: Added test in test_misc Imported from OSS Reviewed By: ZolotukhinM Differential Revision: D27902516 fbshipit-source-id: 4e65c686fa6b4977e8719db45f71f7d2599d4d8e
Stack from ghstack:
generate_debug_handles#57156 [Pytorch Delegated Backend] Add python binding for generate_debug_handlesSummary:
Earlier inlined callstack was annotated only nodes. This left out nodes
such as If which have block of nodes. These nodes should also be updated
similarly.
Test Plan:
Added test in test_misc
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D27902516