-
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
Optimize the subgraph generated by BuildCinnPass #36503
Optimize the subgraph generated by BuildCinnPass #36503
Conversation
Thanks for your contribution! |
} | ||
|
||
// Deal with subgraph's parameter var node: | ||
// create a new input var node, it's data will get by scope, |
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.
参数变量为什么不也添加feed_op,这样符号执行时候都从feed_targets去获取输入变量的数据?参数变量在子图划分时会被视作输入变量吗
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.
- 参数变量是从
scope
中获取的,feed_targets
中只有非参数类型的输入变量。 - 参数变量在子图划分时是会被视作输入变量,所以需要保留其
Var
结点以便在符号执行时区分要从feed_targets
中拿还是scope
中拿
// Note that cluster_outputs var node maybe some subgraph op's input, | ||
// here we need remove them. |
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.
cluster_outputs中的var也不会是任何子图中Op的输入吧?如果是的话,那么这个var岂不是中间节点了?
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.
中间结点是指:输入输入都是子图结点,这意味着中间结点是某个子图结点的输出但一定不是某个外部结点的输入。若该结点是某个外部结点的输入,那么它是output
var->inputs = {op}; | ||
|
||
// link feed var to cluster op | ||
var->outputs.clear(); |
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.
新创建的OpNode和VarNode如果一定是空的,这些clear操作就不需要的。sub_node->inputs.clear();
等语句同理。
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.
的确不需要,这样是为了明确新创建的var
与之前的图没有任何关系
var->inputs.clear(); | ||
var->outputs.clear(); |
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.
同上。
var->inputs.clear(); | ||
var->outputs.clear(); |
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.
LGTM.
* add cinn graph symbolization * fix some bug * add paddle scope to cinn scope * add paddle scope to CINN scope in Symbolization, and add feed op when build cinn pass * fix some bug * fix some bug by review advices * optimize code problem * revert build_cinn_pass and move the change to #36503 * fix some bug after co-compilation * perfect single test script * remove scope and rename feed_target to input_tensor * using std::unordered_map instead of absl::flat_hash_map * fix single test bug * revert to preverion for WITH_CINN has add in later PR * full error information for CI * full enfore information for CI pass
PR types
Others
PR changes
APIs
Describe
如题, 基于 #36345 进一步优化
BuildCinnPass
生成的Cinn子图逻辑:feed
op来获取shape和dtype,因此需要额外添加一个feed
nodescope
中获取shape和dtype,无需增加一个feed
node用例
其输入为一个
Graph
,输出为std::vector<std::unique_ptr<Graph>>
,并通过cinn_subgraphs
属性返回。上述变量
cinn_subgraphs
即为我们筛选出的所有CINN支持的子图。示例
详情示例请见单测文件:
build_cinn_pass_test.cc
, 具体而言,分为如下几种情况:Graph中不含任何CINN支持的Op
Pass前后Graph保持不变,且
cinn_subgraphs
为空。Graph由全为CINN支持的OP组成
Pass后原Graph变为:
cinn_subgraphs
包含一个子图,注意子图中的所有结点都是新创建的,并非原Graph的结点:Graph含一个CINN子图
Pass后原Graph变为:
cinn_subgraphs
包含一个子图,注意子图中的所有结点都是新创建的,并非原Graph的结点:Graph包含多个分离的CINN子图
Pass后原Graph变为:
cinn_subgraphs
包含2个单op子图,注意子图中的所有结点都是新创建的,并非原Graph的结点: