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][dynamic shape] add symbolic fallback when SymbolicVariable's handler not exists. #67786

Merged
merged 14 commits into from
Aug 30, 2024

Conversation

zrr1999
Copy link
Member

@zrr1999 zrr1999 commented Aug 28, 2024

PR Category

Execute Infrastructure

PR Types

Performance

Description

完善函数调用在参数包含 SymbolicVariable 时的 dispatch 机制,找不到 SymbolicVariable 对应的handler时,fallback到ConstantVariable 的。

Copy link

paddle-bot bot commented Aug 28, 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.

@zrr1999 zrr1999 changed the title Dispatch [SOT][dynamic shape] add fallback mechanism when SymbolicVariable's handler not exists. Aug 28, 2024
@zrr1999
Copy link
Member Author

zrr1999 commented Aug 28, 2024

image
目前 symbolic_inputs 里的计数还有一些问题

当进入动态shape之后,每次缓存都会命中,也就不会进行模拟执行,也就不会再加计数了。

#67789

@zrr1999 zrr1999 changed the title [SOT][dynamic shape] add fallback mechanism when SymbolicVariable's handler not exists. [SOT][dynamic shape] add symbolic fallback when SymbolicVariable's handler not exists. Aug 28, 2024
@paddle-bot paddle-bot bot added the contributor External developers label Aug 28, 2024
@zrr1999 zrr1999 assigned SigureMo and unassigned SigureMo Aug 29, 2024
Dispatcher.register(
operator.truth,
("ConstantVariable | SymbolicVariable",),
("ConstantVariable",),
lambda var: var.bool(),
)
Copy link
Member

Choose a reason for hiding this comment

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

这里可以将 VariableBaseoperator.truth 都转发到 bool 上嘛?会有什么问题吗?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@SigureMo SigureMo Aug 29, 2024

Choose a reason for hiding this comment

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

是这样

Dispatcher.register(
    operator.truth,
    ("VariableBase",),
    lambda var: Dispatcher.call(bool, var)
)

重新走 bool 这个方法的 dispatch,而不是 VariableBase 的 bool

这样这个文件里 operator.truth 只需要出现一次了,其他的都可以删掉了

@@ -953,6 +954,18 @@ def is_not_func(var: VariableBase, other: VariableBase):
("TensorVariable",),
raise_break_graph_fn,
)
Dispatcher.register(
unary_fn,
("SymbolicVariable",),
Copy link
Member

Choose a reason for hiding this comment

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

这里如果不给 SymbolicVariable dispatch,直接走 fallback 到静态的逻辑会有问题吗?

Copy link
Member Author

Choose a reason for hiding this comment

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

测了一下,应该是可以的

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

另外这个 PR 是不是没有设置 None 的操作?好像没有看到,是不是应该在 SymbolicVariable.get_py_value 时设置?

另外可以测一下中间变量的输入是否可以按照预期 fallback 到静态~

@zrr1999
Copy link
Member Author

zrr1999 commented Aug 29, 2024

另外这个 PR 是不是没有设置 None 的操作?好像没有看到,是不是应该在 SymbolicVariable.get_py_value 时设置?

另外可以测一下中间变量的输入是否可以按照预期 fallback 到静态~

是的,这个PR主药只改了dispatch部分

@zrr1999
Copy link
Member Author

zrr1999 commented Aug 29, 2024

TODO:

  • 后续需要进一步研究一下 operator.truth 的dispatch
  • need_guard_value 可能不需要了

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@SigureMo SigureMo merged commit 01be154 into PaddlePaddle:develop Aug 30, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants