diff options
author | Todd Wang <toddw@google.com> | 2018-10-05 12:09:01 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-10-05 12:13:29 -0700 |
commit | 0541a277d5c74cf8e99c9f5a7a015926d1a05214 (patch) | |
tree | a4c1c9af3f370a793ef3b4be6efd15b57e11f61d /tensorflow/python/framework | |
parent | 03b4161326897453fa6b2803b873954607f7623b (diff) |
Do 2 warmup runs in assert_no_new_pyobjects_executing_eagerly.
PiperOrigin-RevId: 215944829
Diffstat (limited to 'tensorflow/python/framework')
-rw-r--r-- | tensorflow/python/framework/test_util.py | 15 |
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(): |