aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2017-12-04 17:04:45 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-12-04 17:10:34 -0800
commitcfc1de550abdfbc35083d0bd5f7fe84f8897282d (patch)
tree6499e2aaa83418d13393c3f891db971a5e57cecf
parentc414e2646f2e4c1ec9d67fa5ed06b91c2585e298 (diff)
Fix tf.identity(resource variable) with eager execution and a device
copy. PiperOrigin-RevId: 177891209
-rw-r--r--tensorflow/python/eager/BUILD3
-rw-r--r--tensorflow/python/eager/ops_test.py8
-rw-r--r--tensorflow/python/ops/array_ops.py7
3 files changed, 13 insertions, 5 deletions
diff --git a/tensorflow/python/eager/BUILD b/tensorflow/python/eager/BUILD
index b491a637ba..f470e18120 100644
--- a/tensorflow/python/eager/BUILD
+++ b/tensorflow/python/eager/BUILD
@@ -110,6 +110,7 @@ cuda_py_test(
"//tensorflow/python:array_ops",
"//tensorflow/python:math_ops",
"//tensorflow/python:nn_ops",
+ "//tensorflow/python:resource_variable_ops",
"//tensorflow/python:random_ops",
"//tensorflow/python:nn_grad",
"//tensorflow/python:training",
@@ -144,6 +145,7 @@ cuda_py_test(
":test",
"//tensorflow/python:clip_ops",
"//tensorflow/python:math_ops",
+ "//tensorflow/python:resource_variable_ops",
],
)
@@ -415,6 +417,7 @@ cuda_py_test(
"//tensorflow/python:layers",
"//tensorflow/python:math_ops",
"//tensorflow/python:random_ops",
+ "//tensorflow/python:resource_variable_ops",
"//tensorflow/python:sparse_ops",
"//tensorflow/python:tensor_shape",
],
diff --git a/tensorflow/python/eager/ops_test.py b/tensorflow/python/eager/ops_test.py
index 70e23b9311..48dcb4830c 100644
--- a/tensorflow/python/eager/ops_test.py
+++ b/tensorflow/python/eager/ops_test.py
@@ -33,6 +33,7 @@ from tensorflow.python.ops import array_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
+from tensorflow.python.ops import resource_variable_ops
from tensorflow.python.ops import sparse_ops
@@ -322,6 +323,13 @@ class OpsTest(test_util.TensorFlowTestCase):
def testIdentity(self):
self.assertAllEqual(2, array_ops.identity(2))
+ def testIdentityOnVariable(self):
+ if not context.context().num_gpus():
+ self.skipTest('No GPUs found')
+ with context.device('/gpu:0'):
+ v = resource_variable_ops.ResourceVariable(True)
+ self.assertAllEqual(True, array_ops.identity(v))
+
def testIncompatibleSetShape(self):
x = constant_op.constant(1)
with self.assertRaises(ValueError):
diff --git a/tensorflow/python/ops/array_ops.py b/tensorflow/python/ops/array_ops.py
index 73a19e7042..74b405681b 100644
--- a/tensorflow/python/ops/array_ops.py
+++ b/tensorflow/python/ops/array_ops.py
@@ -126,11 +126,8 @@ def identity(input, name=None): # pylint: disable=redefined-builtin
if context.in_graph_mode():
return gen_array_ops.identity(input, name=name)
else:
- try:
- in_device = input.device
- except AttributeError:
- input = ops.convert_to_tensor(input)
- in_device = input.device
+ input = ops.convert_to_tensor(input)
+ in_device = input.device
# TODO(ashankar): Does 'identity' need to invoke execution callbacks?
if context.context().device_name != in_device:
return input._copy() # pylint: disable=protected-access