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

Run_program_op add scope cache & reuse #45813

Merged
merged 5 commits into from
Sep 9, 2022

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Sep 6, 2022

PR types

Performance optimization

PR changes

OPs

Describe

动转静调用run_program_op的执行过程中,每个step都会传入新的scope,在动转静接入新执行器,新执行器替换scope的开销较大,本pr设计了scope的cache和reuse策略,使得每个step无需传入新的scope,节省新执行器替换scope的开销。

Scope缓存的原则:
run_program_op内部通过program_id对执行器(interpretercore)进行缓存,为保证执行器与scope一致,因此,python 端的 partial_program 同样根据 program_id 对 scope 进行缓存,保证每个 program 对应同一套 执行器及 scope。
Scope复用的原则:

  • 普通训练场景下,每个step前反向是连续执行的,因此不同step间的scope是可以复用的,所以1个program就对应1个scope;
  • 强化学习场景下,需要连续执行N个前向step,然后才执行反向,因此每个前向step需要使用新的scope,所以一个program对应N个scope。

图片

@paddle-bot
Copy link

paddle-bot bot commented Sep 6, 2022

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

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@zhangbo9674 zhangbo9674 merged commit 369a235 into PaddlePaddle:develop Sep 9, 2022
zhangbo9674 added a commit to zhangbo9674/Paddle that referenced this pull request Sep 19, 2022
* add scope cache & reuse

* add gc scope for end of each train step

* del scope reuse for jit

* refine code

* test
phlrain pushed a commit that referenced this pull request Sep 20, 2022
* add scope cache & reuse

* add gc scope for end of each train step

* del scope reuse for jit

* refine code

* test
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