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

fix detach_ bug #57394

Merged
merged 1 commit into from
Sep 18, 2023
Merged

Conversation

wanghuancoder
Copy link
Contributor

PR types

Bug fixes

PR changes

Others

Description

detach_对PyObject*的引用计数处理错误。本PR修复
Pcard-74613

@paddle-bot
Copy link

paddle-bot bot commented Sep 15, 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.

@@ -1118,7 +1118,7 @@ static PyObject* tensor_method_detach_(TensorObject* self,
autograd_meta->SetPersistable(
egr::EagerUtils::autograd_meta(&(self->tensor))->Persistable());
self->tensor.set_autograd_meta(autograd_meta);

Py_INCREF(reinterpret_cast<PyObject*>(self));
Copy link
Contributor

Choose a reason for hiding this comment

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

这里我不太了解,为什么需要把引用计数加1呢?需要添加对应的 Py_DECREF吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

因为self返回作为result返回后,在Python端相当于多了一个object。而这个object析构,会触发一次引用计数--。
如果这里不加1,引用计数归零,这个对象就被释放了。但Python端还有一个object没有系统。在Python运行结束,这个object析构时,就double free了。

Copy link
Contributor

@kangguangli kangguangli left a comment

Choose a reason for hiding this comment

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

LGTM

@wanghuancoder wanghuancoder merged commit 9f52c9c into PaddlePaddle:develop Sep 18, 2023
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 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