Skip to content

remove all control_vars in IR graph #46888

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

Merged
merged 1 commit into from
Oct 12, 2022
Merged

remove all control_vars in IR graph #46888

merged 1 commit into from
Oct 12, 2022

Conversation

weishengying
Copy link
Contributor

@weishengying weishengying commented Oct 11, 2022

PR types

Bug fixes

PR changes

Others

Describe

去掉 IR 中增加 control_var 的逻辑。

本pr主要改动如下:

改动1:删除 graph::InitFromBlock 函数中容易使人误解的代码和注释

graph::InitFromBlock 函数中有这么一段话:

PADDLE_ENFORCE_EQ(out_arg_set.count(each_var_name),
                          0,
                          platform::errors::InvalidArgument(
                              "The input Program is invalid. Variable %s occurs"
                              " in output of %s multiple times.",
                              each_var_name,
                              op->Type()));

给人的感觉就是如果模型中存在一个变量被多次写入,这个模型就是不合法的,会报错。但是其实不是,仔细阅读这个函数的实现就会发现:这部分只是检测一个Op中不允许出现两个同名输出变量。所以这段检测代码没有作用,而且容易给阅读者带来误解。

改动2:去掉 Graph::ResolveHazard() 的调用
本pr未删除该函数,但inference不再使用该函数。
该函数的目的是使得一些同名节点之间保持正确的执行顺序。

image

image

image

image

这可能是一种保证正确执行顺序的处理方式,但是引入了一些的 contol_var 来保证算子之间的依赖关系,这会使得某些 op 的输入或者输出多一个变量,影响 pass 中的匹配逻辑。

框架中实际并不需要通过这种方式保证执行顺序,而是通过 op 自带的执行顺序来保证(根据创建 op node的顺序,在拓扑排序中做一些改动,可参考推理时如何保证正确的执行顺序)。真是因为框架中有其他方式保证了执行顺序,所以ir_graph_clean_pass中去掉ir_graph_build_pass中构建 IR 时增加的所有的 control_var 变量。

我猜测是后面的开发人员通过另一种方式保证了执行顺序后,想删掉 control_var b变量,但是没找到这些变量是在哪里创建的,所以特意写了一个 pass 来删除 control_var 变量。因此 该pr顺利合入之后,ir_graph_clean_pass可以删除

其他改动
修改影响的单测:TEST(GraphTest, WriteAfterRead) ,TEST(GraphTest, WriteAfterWrite), 删除了增加 control_var 变量的逻辑后,不再需要这两个单测

修改TEST(GraphTest, TestMultiBlock)单测中的模型表示和相关断言。

@paddle-bot
Copy link

paddle-bot bot commented Oct 11, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot
Copy link

paddle-bot bot commented Oct 11, 2022

✅ This PR's description meets the template requirements!
Please wait for other CI results.

Copy link
Contributor

@hp03 hp03 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jiweibo jiweibo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@zhangjun zhangjun left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants