Skip to content
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

[SOT] Always generate false_fn when POP_JUMP_* breakgraph #62424

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Mar 5, 2024

PR types

Others

PR changes

Others

Description

Python 3.12 单测引申问题,当 POP_JUMP_* breakgraph 时,false_fn 不存在时不可以直接 gen_return,虽然结果可能正确,但其实是未定义行为,debug 版 Python 会直接挂掉

单测 jump_if_false_or_pop

3.8 原始字节码如下:

 41           0 LOAD_FAST                0 (x)
              2 JUMP_IF_FALSE_OR_POP    10
              4 LOAD_FAST                1 (y)
              6 LOAD_CONST               1 (1)
              8 BINARY_ADD
        >>   10 RETURN_VALUE

3.12 原始字节码如下:

 39           0 RESUME                   0

 41           2 LOAD_FAST                0 (x)
              4 COPY                     1
              6 POP_JUMP_IF_FALSE        5 (to 18)
              8 POP_TOP
             10 LOAD_FAST                1 (y)
             12 LOAD_CONST               1 (1)
             14 BINARY_OP                0 (+)
        >>   18 RETURN_VALUE

3.8 原始字节码是 JUMP_IF_FALSE_OR_POP,因此生成的「跳转分支」可以直接 RETURN_VALUE,因为该分支没有 pop,栈上是保留结果的,RETURN_VALUE 没问题

3.12 原始字节码变成了 POP_JUMP_IF_FALSE,跳转目标仍然是 RETURN_VALUE,但是提前 COPY 将栈上变量 x2 了,这样生成的分支当然不能直接 RETURN_VALUE,仍然需要将变量 load 到栈上等操作

Pcard-67164

Copy link

paddle-bot bot commented Mar 5, 2024

你的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.

gouzil
gouzil previously approved these changes Mar 5, 2024
@SigureMo SigureMo changed the title [SOT] Always generate false_fn when breakgraph [SOT] Always generate false_fn when POP_JUMP_* breakgraph Mar 5, 2024
@SigureMo SigureMo requested a review from gouzil March 5, 2024 13:19
@SigureMo SigureMo merged commit 0d98d15 into PaddlePaddle:develop Mar 6, 2024
30 checks passed
@SigureMo SigureMo deleted the sot/always-generate-false-fn-when-breakgraph branch March 6, 2024 02:09
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.

2 participants