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.
我觉得分开写更清晰~多一行少一行无所谓
| } | ||
|
|
||
| if (out_ops.count(n) == 0) { | ||
| out_ops[n] = std::unordered_set<Node *>(); |
There was a problem hiding this comment.
感觉只对out_ops[n]进行初始化是不够的,比如第一个op n 有很多个输入 n1, n2 ,这里就会访问out_ops[n1]和out_ops[n2].
There was a problem hiding this comment.
如果只是为了初始化其实是没必要显式这么写的,unordered_map对于一个之前没遇到的key肯定先初始化再insert,这儿特意这样写的目的其实是为了确保out_ops和in_ops里会有所有的node。
There was a problem hiding this comment.
为表述清晰,已单独拎出来,并使用at替换[]确保没有未知op
| } | ||
|
|
||
| while (!q.empty()) { | ||
| auto cur_op = q.top(); |
There was a problem hiding this comment.
const auto cur_op = q.top();
| block = program_pb->add_blocks(); | ||
| block->set_idx(idx); | ||
| GraphToBlock(graph->GetSubGraph(idx), block); | ||
| } |
There was a problem hiding this comment.
这个for循环是否也应该放在 if (FLAGS_convert_all_blocks) { } 中
There was a problem hiding this comment.
可以的,之前我想的是如果没指定FLAGS_convert_all_blocks的话SubGraphSize的返回值应该是0,这样就不会走循环了。不过加上可以逻辑会更清晰点
paddle/fluid/framework/ir/node.h
Outdated
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> |
There was a problem hiding this comment.
注意到 id 是int类型的,如果desc_order也使用int类型,是不是就不用引入这个头文件了
There was a problem hiding this comment.
可以的,desc_order_用int或者size_t应该都行
paddle/fluid/framework/ir/node.h
Outdated
| int id_; | ||
|
|
||
| static constexpr size_t NO_DESC_ORDER = SIZE_MAX; | ||
| size_t desc_order_; |
There was a problem hiding this comment.
为什么不在这里赋默认值而是在构造函数的初始化列表中赋值呢。
There was a problem hiding this comment.
C++中非static const修饰的成员变量是不能在定义时赋初值的(有些编译器是直接报错有些是忽略这个初值),只能在构造函数里赋值。
There was a problem hiding this comment.
嗨,看到你们的讨论,插入一下。
查看了一下,似乎是C++ 11后引入的可以在header中定义赋值。
paddle/fluid/framework/ir/graph.h
Outdated
| } | ||
|
|
||
| size_t SubGraphSize() const { | ||
| // wait for https://github.com/PaddlePaddle/Paddle/pull/33320 merged |
… add_graph_to_program_toposort
… add_graph_to_program_toposort
PR types
Bug fixes
PR changes
APIs
Describe
This PR solve two problem:
convert_all_blocks)VarDescfor those nodes, this PR added it. The key code is line 98 ofgraph.cc.block_id_tonode.hand related functional code. The key code is line 440 ofgraph.hIsConstructedByPartialProgram()should return sub_graph'sis_partial_instead of returning this graph. The key code is line 107 ofgraph.hwhile_op_eager_deletion_passonly handles MainGraphAs before, we can convert graph and program by the following code:
The following are some examples: