aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/framework
diff options
context:
space:
mode:
authorGravatar Allen Lavoie <allenl@google.com>2018-09-17 14:24:17 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-17 14:28:07 -0700
commit28dd4d9fcbf8cac1008b2ccd2b4be3fa3c25afd1 (patch)
tree68e901eec6d952589b5a69f3be37d7f04dac8373 /tensorflow/python/framework
parent4516558acc9763999b19d1af75ab1fcd6562e4f0 (diff)
Keep only weak references to variables in graph functions
This enables cleanup of the variables referenced in defunned methods of objects when the object is garbage collected. Since one PolymorphicFunction is created per @defun, decorated methods before this change held on to all of the variables referenced in that method for any instance of the class (i.e. variables which should have been object-scoped were scoped to the lifetime of the class definition). Raises an exception if variables used in the function have been deleted when it is called, which means no local variables. PiperOrigin-RevId: 213337256
Diffstat (limited to 'tensorflow/python/framework')
-rw-r--r--tensorflow/python/framework/ops_test.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/tensorflow/python/framework/ops_test.py b/tensorflow/python/framework/ops_test.py
index d59adf3d48..c3a3437743 100644
--- a/tensorflow/python/framework/ops_test.py
+++ b/tensorflow/python/framework/ops_test.py
@@ -2142,8 +2142,8 @@ class InitScopeTest(test_util.TensorFlowTestCase):
def function_with_variables():
with ops.init_scope():
- v = resource_variable_ops.ResourceVariable(3)
- return v.assign_add(1)
+ self.v = resource_variable_ops.ResourceVariable(3)
+ return self.v.assign_add(1)
with context.eager_mode():
# Each invocation of function_with_variables recreates a variable.
@@ -2188,13 +2188,13 @@ class InitScopeTest(test_util.TensorFlowTestCase):
def inner_function():
with ops.init_scope():
- v = resource_variable_ops.ResourceVariable(1)
- return v.assign_add(2)
+ self.v = resource_variable_ops.ResourceVariable(1)
+ return self.v.assign_add(2)
def outer_function(inner=None):
with ops.init_scope():
- v0 = resource_variable_ops.ResourceVariable(0)
- return v0.assign_add(1) + inner()
+ self.v0 = resource_variable_ops.ResourceVariable(0)
+ return self.v0.assign_add(1) + inner()
with context.eager_mode():
# Each invocation of outer_function recreates variables.