Skip to content

[Dy2St][PIR] Allow expand UndefinedVar to multiple values in control flow #69210

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

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Nov 6, 2024

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

允许一个 UndefindVar 经过 loop body 之后变为多个 Value 的情况

def loop_with_inner_mutate_list(x):
    out = 100
    # a is an UndefinedVar
    for i in range(x):
        a = []
        a.append(x)
        a.append(x + 1)
        out += a[0]
        # After the loop, a is [x, x], which will be flattened to 2 elements
    return out

比如对于如上 case,最开始 a 是一个 UndefinedVar,经过 loop body 后变成了 [Value(), Value()],这会导致 while op 的输入输出不匹配,因为如果输入是 UndefinedVar 我们会创建一个 FakeValue,而输出则是两个

因此新的方案对控制流进行了重写,在 build_while_op 时不再提前创建 FakeValue,而是在跑完 loop body 后,根据输出来 infer 输入里的 UndefinedVar 的 type,此时才创建 FakeValue

比如

  • UndefindVar() -> Value(type1),会将输入变为 Value(type1)
  • UndefindVar() -> [Value(type1), Value(type2)],会将输入变为 [Value(type1), Value(type2)]

新增的 FakeValue 会作为 PyWhileOpextra_inputs_,会在 OptimizeUpdate 的时候创建新的 WhileOp,以更新输入输出

PCard-66972

Copy link

paddle-bot bot commented Nov 6, 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][PIR] Allow expand UndefinedVar to multiple values in control flow [Dy2St][PIR] Allow expand UndefinedVar to multiple values in control flow Nov 6, 2024
@@ -679,6 +680,77 @@ def has_shape_diff(x_var, y_var):
paddle.assign(input, output)


def create_fake_value_for_undefined_var(while_op, value):
# Create a fake value for create WhileOp, it's type will be reset after body is executed.
Copy link
Member Author

Choose a reason for hiding this comment

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

这里注释已经不准确了,之后 PR 清理下

@SigureMo SigureMo merged commit 1a6c134 into PaddlePaddle:develop Nov 8, 2024
28 checks passed
@SigureMo SigureMo deleted the dy2st/allow-expand-undefined-var-to-multiple-values-in-control-flow branch November 8, 2024 02:45
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.

3 participants