-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
Thanks for your contribution! |
create_test_value_numpy_fp32(TestSetValueItemSlice2) | ||
create_test_value_numpy_fp32(TestSetValueItemSlice3) | ||
create_test_value_numpy_fp32(TestSetValueItemSlice4) | ||
# class TestSetValueItemSliceInWhile(TestSetValueApi): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these uts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the final version.
paddle/fluid/pybind/imperative.cc
Outdated
if (PyTuple_Check(_index.ptr())) { | ||
index_ptr = _index.ptr(); | ||
} else { | ||
index_ptr = PyTuple_New(1); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
paddle/fluid/pybind/imperative.cc
Outdated
PyObject *index = !PyTuple_Check(_index) ? PyTuple_Pack(1, _index) : _index; | ||
DEFINE_PADDLE_SCOPE_GUARD([&index, &_index]() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same above.
PR types
Bug fixes
PR changes
Others
Describe
fix potential tensor leak in tensor.setitem. Expected to close #34752, #34868
see example below: