From 0920a3c59ee85d1917e27fc69ed5cbd8e4b7a6c4 Mon Sep 17 00:00:00 2001 From: Igor Ganichev Date: Wed, 23 May 2018 13:45:14 -0700 Subject: [PATCH] Add a test to reproduce copy-on-read bug for variables PiperOrigin-RevId: 197781741 --- tensorflow/compiler/tests/eager_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tensorflow/compiler/tests/eager_test.py b/tensorflow/compiler/tests/eager_test.py index 52d8d6d..583a2c2 100644 --- a/tensorflow/compiler/tests/eager_test.py +++ b/tensorflow/compiler/tests/eager_test.py @@ -136,6 +136,23 @@ class EagerTest(XLATestCase): grads = backprop.implicit_grad(f)() self.assertEqual(2., grads[0][0].numpy()) + def testMultipleVariableReads(self): + # TODO(b/79715516): Currently, whenever we read a variable by going + # through XLA, we create a copy. This leads large memory usage. + self.skipTest('When variable is read through XLA, a copy is created.') + + with self.test_scope(): + # Create 128MiB variables + var = resource_variable_ops.ResourceVariable( + array_ops.ones([32, 1024, 1024])) + + # Read the same variable 100 times. If the underlying tensor + # is not copied, this is a trivial operation. If it is copied, + # this will eat over 13GB and OOM. + values = [] + for _ in range(100): + values.append(var.value()) + class EagerFunctionTest(XLATestCase): -- 2.7.4