[Dy2Stat]Enhance Python if-else by pruning usless no_return variable #43880
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
APIs
Describe
What's New?
优化了在执行 Python if-else后未正确移除框架中的 NO_RETURN_VAR 的逻辑。
后续优化
长期来看,我们不应该支持变长的提前return。虽然Python是支持控制流中可以分别返回不同长度的变量,但是在深度学习框架中,是要求每个true_branch 和 false_branch 返回相同的structure。
从普适性和鲁棒性上来看,在代码转写时不需要对变长的return语句做padding处理的。在执行期间,如果是不依赖控制流的非控制流IF,只需要保持和Python一致的执行即可。如果是依赖控制流的控制流IF,则执行期间需要添加强检查,并抛出详尽的报错信息。