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 potential tensor leak in tensor.__setitem__ #35013

Merged
merged 11 commits into from
Aug 25, 2021

Conversation

zhiqiu
Copy link
Contributor

@zhiqiu zhiqiu commented Aug 19, 2021

PR types

Bug fixes

PR changes

Others

Describe

fix potential tensor leak in tensor.setitem. Expected to close #34752, #34868

see example below:
0079c8665b1721138361a597c7c9948c

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

create_test_value_numpy_fp32(TestSetValueItemSlice2)
create_test_value_numpy_fp32(TestSetValueItemSlice3)
create_test_value_numpy_fp32(TestSetValueItemSlice4)
# class TestSetValueItemSliceInWhile(TestSetValueApi):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove these uts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not the final version.

if (PyTuple_Check(_index.ptr())) {
index_ptr = _index.ptr();
} else {
index_ptr = PyTuple_New(1);
Copy link
Collaborator

@sneaxiy sneaxiy Aug 23, 2021

Choose a reason for hiding this comment

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

I am rather curious when the index_ptr would be released (when the reference count of index_ptr decreases to zero)? Is there any risk that index_ptr causes memory leak?

I have tested that index_ptr would really cause memory leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is another problem and I'm working on it .

@sneaxiy
Copy link
Collaborator

sneaxiy commented Aug 23, 2021

@zhiqiu FYI. Always try to use RAII solution. Please see #35103 .

@zhiqiu
Copy link
Contributor Author

zhiqiu commented Aug 24, 2021

@zhiqiu FYI. Always try to use RAII solution. Please see #35103 .

Thanks, I refined the implementation using #35103.

sneaxiy
sneaxiy previously approved these changes Aug 24, 2021
Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

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

LGTM.

PyObject *index = !PyTuple_Check(_index) ? PyTuple_Pack(1, _index) : _index;
DEFINE_PADDLE_SCOPE_GUARD([&index, &_index]() {
Copy link
Collaborator

@sneaxiy sneaxiy Aug 24, 2021

Choose a reason for hiding this comment

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

NIT. You can use [index, _index] here since index and _index are pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thx.

PyObject *index_ptr = !PyTuple_Check(_index.ptr())
? PyTuple_Pack(1, _index.ptr())
: _index.ptr();
DEFINE_PADDLE_SCOPE_GUARD([&index_ptr, &_index]() {
if (!PyTuple_Check(_index.ptr())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same above.

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.

【论文复现】动态图自定义Python算子疑似显存泄露
2 participants