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

Release lambda function to reuse tensor memory #5266

Merged
merged 5 commits into from
Jun 22, 2021

Conversation

wyg1997
Copy link
Contributor

@wyg1997 wyg1997 commented Jun 22, 2021

FunctionNode计算后立即释放掉lambda backward function,使lambda里捕获的tensor可以及时释放,节省显存。
在resnet50上测试,输入为 (32, 3, 224, 224) 时,显存优化情况为:4400MB -> 4178MB

@wyg1997 wyg1997 requested a review from hjchen2 June 22, 2021 08:50
@@ -110,7 +110,6 @@ void StackFunctionNode::ReleaseOutTensorArgs() {
void StackFunctionNode::ReleaseData() {
// Releases backward function and makes useless tensors release as early as possible
if (!input_meta_datas_.empty()) { backward_fn_.reset(); }
next_functions_->clear();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里不能清理,避免 lambda 中没有捕获input tensor导致FunctionNode提前释放。

@oneflow-ci-bot oneflow-ci-bot self-requested a review June 22, 2021 15:52
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 22, 2021 16:42
@oneflow-ci-bot oneflow-ci-bot merged commit 2b5662c into master Jun 22, 2021
@oneflow-ci-bot oneflow-ci-bot deleted the perf-autograd_memory2 branch June 22, 2021 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants