Skip to content

Conversation

@SigureMo
Copy link
Member

@SigureMo SigureMo commented Jan 19, 2024

PR types

Others

PR changes

Others

Description

移除动转静控制流不必要的 UndefinedVar,将各种 flag 提前

# return
# 修改前
def foo():
    __return_0 = UndefinedVar() # 后面的 transformer 发现外层作用域(被转写为函数形式)没有 __return_0,就会插入这个 UndefinedVar
    if x:
        __return_0_value = x
        __return_0 = True

# 修改后
def foo():
    __return_0 = False # 直接在这里插一个等于 False
    if x:
        __return_0_value = x
        __return_0 = True
# break
# 修改前
def foo():
    __break_0 = UndefinedVar() # 理由同上
    if xxx:
        __break_0 = False
        while x and not __break_0:
            if not __break_0:
                ...

# 修改后
def foo():
    __break_0 = False # 直接最前面插 False,不会有 UndefinedVar
    if xxx:
        # 注意是直接挪到上面了,这里不插了
        while x and not __break_0:
            if not __break_0:
                ...
# continue
# 修改前
def foo():
    __continue_0 = UndefinedVar() # 理由同上
    while x:
        __continue_0 = False
        if not __continue_0:
            ...

# 修改后
def foo():
    __continue_0 = False # 同样移到最前面
    while x:
        __continue_0 = False # 但这里仍然需要保留,因为每次都需要 reset 回 False,因为 Python 跑的时候会跑多次
        if not __continue_0:
            ...

并启用以下控制流单测理想态监控

  • TestDygraphIfTensor
  • TestDy2StIfElseRetInt1
  • TestDy2StIfElseRetInt3
  • TestDy2StIfElseRetInt4

PCard-66972

@paddle-bot
Copy link

paddle-bot bot commented Jan 19, 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.

@SigureMo SigureMo changed the title [Dy2St] Add basic support for control flow [Dy2St] Remove UndefinedVar for break, continue and return Jan 23, 2024
@SigureMo SigureMo changed the title [Dy2St] Remove UndefinedVar for break, continue and return [Dy2St] Remove UndefinedVar for break, continue and return flag Jan 23, 2024
Copy link
Contributor

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

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

LGTM

@SigureMo SigureMo changed the title [Dy2St] Remove UndefinedVar for break, continue and return flag [Dy2St] Remove UndefinedVar for break, continue and return flag Jan 24, 2024
@SigureMo SigureMo merged commit 6385649 into PaddlePaddle:develop Jan 24, 2024
@SigureMo SigureMo deleted the dy2st/add-basic-support-for-control-flow branch January 24, 2024 18:28
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