Add a test to reproduce copy-on-read bug for variables
authorIgor Ganichev <iga@google.com>
Wed, 23 May 2018 20:45:14 +0000 (13:45 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 23 May 2018 20:50:22 +0000 (13:50 -0700)
PiperOrigin-RevId: 197781741

tensorflow/compiler/tests/eager_test.py

index 52d8d6d..583a2c2 100644 (file)
@@ -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):