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

Cache scope in While Op during Inference. #49083

Closed
wants to merge 3 commits into from

Conversation

carryyu
Copy link
Contributor

@carryyu carryyu commented Dec 14, 2022

PR types

Performance optimization

PR changes

Others

Describe

Cache scope in While Op during Inference.

  1. While Op每次会new一个scope,使用完后再delete掉,存在情况:本次new的scope和上一次delete的scope地址相同,此时op会复用上一次的RuntimeContext,但实际上一次RuntimeContext中的var已经被释放,此时会导致报错。 之前的Paddle不存在这个问题是因为默认While Op内部的Op都不做缓存复用。
    解决方法:a. While Op不再每次运行完后就释放掉scope。 b. 使While Op中的Op不进行复用(同之前的做法)。
  2. 该PR使While Op在推理阶段可以复用第一次new的scope,不再重复创建scope。这样While Op中的Op都可以进行RuntimeContext和scope的复用。
  3. 暂时不能merge,在分布式场景下每次跑完会做垃圾回收,会把部分var释放掉,被释放掉的var对应的op就不能做RuntimeContext的复用。

@paddle-bot
Copy link

paddle-bot bot commented Dec 14, 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.

@paddle-bot
Copy link

paddle-bot bot commented Dec 14, 2022

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@carryyu carryyu changed the title Cache scope in While Op when Inference. Cache scope in While Op during Inference. Dec 15, 2022
}
}

private:
mutable std::shared_ptr<framework::Executor> executor_{nullptr};
mutable std::unique_ptr<framework::ExecutorPrepareContext> ctx_{nullptr};
mutable std::shared_ptr<framework::InterpreterCore> core_{nullptr};
mutable framework::Scope *inference_cache_scope_ = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. while op是训练推理共用的,这里叫inference_xxx不太合理
  2. 当前的修改逻辑对训练有没有影响 @zhhsplendid 看下?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. while op是训练推理共用的,这里叫inference_xxx不太合理
  2. 当前的修改逻辑对训练有没有影响 @zhhsplendid 看下?
  1. 当前暂时只针对旧执行器上的推理阶段做了scope复用,这样影响面可以限制在推理侧,因为担心对训练侧产生没发现的问题。
  2. 如果训练侧也可以复用scope 这里可以修改的更通用一些,暂时只针对推理做了scope缓存~

@carryyu carryyu closed this Jan 30, 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.

4 participants