-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
graph_to_program topology sort #33949
graph_to_program topology sort #33949
Conversation
Thanks for your contribution! |
for (auto *op : program.Block(0).AllOps()) { | ||
ir::Node *node = CreateOpNode(op); | ||
node->SetDescOrder(desc_order); | ||
++desc_order; |
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.
45行可以和44行合并。
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 (out_ops.count(n) == 0) { | ||
out_ops[n] = std::unordered_set<Node *>(); |
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.
感觉只对out_ops[n]进行初始化是不够的,比如第一个op n 有很多个输入 n1, n2 ,这里就会访问out_ops[n1]和out_ops[n2].
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.
如果只是为了初始化其实是没必要显式这么写的,unordered_map
对于一个之前没遇到的key肯定先初始化再insert
,这儿特意这样写的目的其实是为了确保out_ops
和in_ops
里会有所有的node。
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.
为表述清晰,已单独拎出来,并使用at
替换[]
确保没有未知op
} | ||
|
||
while (!q.empty()) { | ||
auto cur_op = q.top(); |
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.
const auto cur_op = q.top();
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.
done
block = program_pb->add_blocks(); | ||
block->set_idx(idx); | ||
GraphToBlock(graph->GetSubGraph(idx), block); | ||
} |
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.
这个for循环是否也应该放在 if (FLAGS_convert_all_blocks) { } 中
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.
可以的,之前我想的是如果没指定FLAGS_convert_all_blocks
的话SubGraphSize的返回值应该是0,这样就不会走循环了。不过加上可以逻辑会更清晰点
paddle/fluid/framework/ir/node.h
Outdated
@@ -14,6 +14,7 @@ limitations under the License. */ | |||
|
|||
#pragma once | |||
|
|||
#include <cstdint> |
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.
注意到 id 是int类型的,如果desc_order也使用int类型,是不是就不用引入这个头文件了
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.
可以的,desc_order_
用int
或者size_t
应该都行
paddle/fluid/framework/ir/node.h
Outdated
@@ -146,10 +156,17 @@ class Node { | |||
Type type_; | |||
int id_; | |||
|
|||
static constexpr size_t NO_DESC_ORDER = SIZE_MAX; | |||
size_t desc_order_; |
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.
为什么不在这里赋默认值而是在构造函数的初始化列表中赋值呢。
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.
C++中非static const
修饰的成员变量是不能在定义时赋初值的(有些编译器是直接报错有些是忽略这个初值),只能在构造函数里赋值。
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.
嗨,看到你们的讨论,插入一下。
查看了一下,似乎是C++ 11后引入的可以在header中定义赋值。
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.
是的,后续有一些讨论我和姜程在如流上沟通了
paddle/fluid/framework/ir/graph.h
Outdated
} | ||
|
||
size_t SubGraphSize() const { | ||
// wait for https://github.com/PaddlePaddle/Paddle/pull/33320 merged |
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.
这里需要的接口,在#33320 中写一个comment吧
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.
done
… add_graph_to_program_toposort
… add_graph_to_program_toposort
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
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 for graph&node
PR types
Bug fixes
PR changes
APIs
Describe
This PR solve two problem:
convert_all_blocks
)VarDesc
for those nodes, this PR added it. The key code is line 98 ofgraph.cc
.block_id_
tonode.h
and related functional code. The key code is line 440 ofgraph.h
IsConstructedByPartialProgram()
should return sub_graph'sis_partial_
instead of returning this graph. The key code is line 107 ofgraph.h
while_op_eager_deletion_pass
only handles MainGraphAs before, we can convert graph and program by the following code:
The following are some examples: