remove all control_vars in IR graph #46888
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
Others
Describe
去掉 IR 中增加 control_var 的逻辑。
本pr主要改动如下:
改动1:删除 graph::InitFromBlock 函数中容易使人误解的代码和注释
在
graph::InitFromBlock
函数中有这么一段话:给人的感觉就是如果模型中存在一个变量被多次写入,这个模型就是不合法的,会报错。但是其实不是,仔细阅读这个函数的实现就会发现:这部分只是检测一个Op中不允许出现两个同名输出变量。所以这段检测代码没有作用,而且容易给阅读者带来误解。
改动2:去掉 Graph::ResolveHazard() 的调用
本pr未删除该函数,但inference不再使用该函数。
该函数的目的是使得一些同名节点之间保持正确的执行顺序。
这可能是一种保证正确执行顺序的处理方式,但是引入了一些的 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)单测中的模型表示和相关断言。