Skip to content

[SOT][DynamicShape] Add basic constraint mechanism #72250

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

Merged

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Apr 14, 2025

PR Category

Execute Infrastructure

PR Types

Performance

Description

添加全新的约束机制,确保在 if symbol 时候能够将 symbol 状态放到约束,相关符号最后会根据约束来生成 guard

比如

def fn(x):
    s0 = x.shape[0]
    if s0 > 4:  # 此时可以根据 example value 确定当前轮次走哪个分支的,但是代价是将 s0 > 4 或者 not (s0 > 4) 加到 guard 里,以确保后续走其他分支的时候能够触发重新组网
        return 1
    return 2

@SigureMo SigureMo requested review from zrr1999 and gouzil as code owners April 14, 2025 13:16
Copy link

paddle-bot bot commented Apr 14, 2025

你的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 requested a review from DrRyanHuang April 14, 2025 13:17
@SigureMo SigureMo changed the title [SOT][DynamicShape] Add basic constraint mechanism [SOT][DynamicShape][3.13] Add basic constraint mechanism Apr 14, 2025
if not all(
var.value.is_backed() for var in symbolic_vars.values()
):
raise BreakGraphError(
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO:这里的打断会导致下面 except Fallback,但实际上希望的是和 Tensor 一样的打断,这需要在 if_break_graph_decorator 感知到包含 unbacked symbol 并视为等同于 Tensor 的 DDCF

@SigureMo SigureMo changed the title [SOT][DynamicShape][3.13] Add basic constraint mechanism [SOT][DynamicShape] Add basic constraint mechanism Apr 15, 2025
Copy link
Member Author

@SigureMo SigureMo Apr 15, 2025

Choose a reason for hiding this comment

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

另一个 TODO:目前约束专为 SOT guard 设计,因此表示上类似 GE(Sub(Add(S0, 1), 2), 3) 这种,目前还没有传递给编译器,传给编译器的仍然只有固有约束 S0 >= 2,后续会逐步考虑这些(上面的求解出约束 S0 >= 4 也不是那么好实现)

@SigureMo SigureMo merged commit c849c7e into PaddlePaddle:develop Apr 15, 2025
38 of 40 checks passed
@SigureMo SigureMo deleted the sot/add-basic-constraint-mechanism branch April 15, 2025 03:04
YqGe585 pushed a commit to YqGe585/Paddle that referenced this pull request May 7, 2025
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.

4 participants