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] Dont use get_py_value from Tensor default in MAKE_FUNCTION to avoid breakgraph #71048

Merged

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Feb 7, 2025

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

#71040 是在 DiT 上发现的问题

目前在 make function 且有 kwdefault 的情况下,如果默认值包含 tensor,会因为直接 get_py_value 触发 BreakGraphError 而挂掉,因为 MAKE_FUNCTION 并没有捕获 BreakGraphError,导致抛到了最外层

但因为 MAKE_FUNCTION 自身的特殊性,在 python 3.13 下是 MAKE_FUNCTION 后跟随若干 SET_FUNCTION_ATTRIBUTE 实现的,如果在 MAKE_FUNCTION 处打断,可能会产生一个非法的 Function(在 python 端还不确定),因此此处打断可能不太行

不过这里注意到在之前的实现里,只有 kwdefault 会有问题,普通的 default 没有问题,因为该分支使用了 get_wrapped_items,将 Variable 作为生成函数的 defaults,这样做在大多数情况没有问题,因为这个函数会 inline call,后面这些 defaults 也会转成 Variable

因此在 kwdefault 里也用 get_wrapped_items,但从长期来看,仍然是将 FunctionVariable 表示改为持有多个 Variable 的形式(含 code、closure 等对应的 Variable),使得 MAKE_FUNCTION 不可能发生 BreakGraph,因为只是 Variable 的组合,这样才是理想的状态

PCard-66972

@SigureMo SigureMo merged commit d71159b into PaddlePaddle:develop Feb 8, 2025
33 checks passed
@SigureMo SigureMo deleted the sot/dont-get-py-value-in-make-fn branch February 8, 2025 02:31
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