Fix tape set leak, and hold a reference to the eager context since the __del__ function
requires an op to run. PiperOrigin-RevId: 253056291
This commit is contained in:
parent
2bff5d77e3
commit
c22bc79896
tensorflow/python
@ -1291,12 +1291,12 @@ static PyTypeObject TFE_Py_Tape_Type = {
|
||||
// revisit this if/when decide to not hold the GIL while manipulating the tape
|
||||
// stack.
|
||||
tensorflow::gtl::CompactPointerSet<TFE_Py_Tape*>* GetTapeSet() {
|
||||
thread_local tensorflow::gtl::CompactPointerSet<TFE_Py_Tape*>* tape_set{
|
||||
nullptr};
|
||||
thread_local std::unique_ptr<tensorflow::gtl::CompactPointerSet<TFE_Py_Tape*>>
|
||||
tape_set = nullptr;
|
||||
if (tape_set == nullptr) {
|
||||
tape_set = new tensorflow::gtl::CompactPointerSet<TFE_Py_Tape*>;
|
||||
tape_set.reset(new tensorflow::gtl::CompactPointerSet<TFE_Py_Tape*>);
|
||||
}
|
||||
return tape_set;
|
||||
return tape_set.get();
|
||||
}
|
||||
|
||||
// A safe copy of the current tapeset. Does not get affected by other python
|
||||
|
@ -254,6 +254,10 @@ class EagerResourceDeleter(object):
|
||||
"Tensor." % (handle,)))
|
||||
self._handle = handle
|
||||
self._handle_device = handle_device
|
||||
# This is held since the __del__ function runs an op, and if the context()
|
||||
# is collected before this object, there will be a segfault when running the
|
||||
# op.
|
||||
self._context = context.context()
|
||||
|
||||
def __del__(self):
|
||||
# Resources follow object-identity when executing eagerly, so it is safe to
|
||||
|
Loading…
Reference in New Issue
Block a user