aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tensorflow/python/framework/test_util.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/tensorflow/python/framework/test_util.py b/tensorflow/python/framework/test_util.py
index 4ec4b41b5e..95925bb471 100644
--- a/tensorflow/python/framework/test_util.py
+++ b/tensorflow/python/framework/test_util.py
@@ -506,9 +506,9 @@ def disable_control_flow_v2(unused_msg):
def assert_no_new_pyobjects_executing_eagerly(f):
"""Decorator for asserting that no new Python objects persist after a test.
- Runs the test multiple times executing eagerly, first as a warmup and then
- several times to let objects accumulate. The warmup helps ignore caches which
- do not grow as the test is run repeatedly.
+ Runs the test multiple times executing eagerly, first as a warmup and then to
+ let objects accumulate. The warmup helps ignore caches which do not grow as
+ the test is run repeatedly.
Useful for checking that there are no missing Py_DECREFs in the C exercised by
a bit of Python.
@@ -518,7 +518,14 @@ def assert_no_new_pyobjects_executing_eagerly(f):
"""Warms up, gets an object count, runs the test, checks for new objects."""
with context.eager_mode():
gc.disable()
- f(self, **kwargs)
+ # Run the test 2 times as warmup, in an attempt to fill up caches, which
+ # should not grow as the test is run repeatedly below.
+ #
+ # TODO(b/117156879): Running warmup twice is black magic; we have seen
+ # tests that fail with 1 warmup run, and pass with 2, on various versions
+ # of python2.7.x.
+ for _ in range(2):
+ f(self, **kwargs)
gc.collect()
previous_count = len(gc.get_objects())
if ops.has_default_graph():