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

[dy2static] support fallback for whole graph. (stage 1) #50111

Merged
merged 5 commits into from
Feb 3, 2023

Conversation

2742195759
Copy link
Contributor

@2742195759 2742195759 commented Jan 31, 2023

PR types

New features

PR changes

Others

Describe

动转静整图Fallback机制:
给动转静添加了整图Fallback机制。如果在动转静过程中出现了语法错误、用户无法识别语法会进行fallback到动态图下执行。整个过程不修改任何的用户用法,除了会报 warning 之外,不会有任何的影响。

开启方法:

build_strategy 中传入 build_strategy.build_cinn_pass=True 就会默认开启。(TODO:后续会添加一个独立的开关进行启动)

运行截图:报warning

如果出现了动转静失败,同时开启了上述的pass,那么就会抛出一个warning,如下:
image

错误日志

如果报错,那么warning中会提示在 dy2static.error 文件中可以查看不支持的语法:例如:
image
可以看到上述的错误是因为调用了numpy函数,用户可以通过修改代码,或者是反馈来解决模型问题,当模型问题修复之后,就不会出现warning了。

设计架构:

image

局限性

当前只是支持整图fallback,所以整个模型都会到动态图下执行。因此无法进行 jit.save、jit.load 等用法,同时也不支持获取 program。如果使用了上述的不支持方法,会有 Exception 抛出,并拦截提示。(用户友好)
比如调用了如下代码:

print(u_net.forward.main_program)

如果 u_net 不支持动转静,那么会报如下错误:
image

@paddle-bot
Copy link

paddle-bot bot commented Jan 31, 2023

你的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.

python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/program_translator.py Outdated Show resolved Hide resolved
@2742195759 2742195759 closed this Feb 2, 2023
@2742195759 2742195759 reopened this Feb 2, 2023
Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

后续我们在to_static里加一个参数:fallback=True的开关是不是好一些?

@2742195759 2742195759 merged commit 5b993f2 into PaddlePaddle:develop Feb 3, 2023
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