def __init__(self):
super(_EagerContext, self).__init__()
- self.device_spec = pydev.DeviceSpec.from_string(
- "/job:localhost/replica:0/task:0/device:CPU:0")
+ self.device_spec = pydev.DeviceSpec.from_string("")
self.device_name = self.device_spec.to_string()
self.mode = _default_mode
self.scope_name = ""
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
+from tensorflow.python.ops import array_ops
from tensorflow.python.ops import nn_ops
ctx.summary_writer_resource = 'mock'
self.assertEqual('mock', ctx.summary_writer_resource)
- self.assertEqual('/job:localhost/replica:0/task:0/device:CPU:0',
- ctx.device_name)
+ self.assertEqual('', ctx.device_name)
self.assertEqual(ctx.device_name, ctx.device_spec.to_string())
with ctx.device('GPU:0'):
self.assertEqual('/job:localhost/replica:0/task:0/device:GPU:0',
self.assertEqual(len(cpu_stats.node_stats), 1)
self.assertEqual(cpu_stats.node_stats[0].node_name, 'Add')
+ def testShouldCopy(self):
+ if not context.context().num_gpus():
+ self.skipTest('No devices other than CPUs found')
+ with ops.device('gpu:0'):
+ x = constant_op.constant(1.0)
+ y = array_ops.identity(x)
+ # The value we're testing y.device against will depend on what the behavior
+ # of not explicitly specifying a device in the context is. This behavior is
+ # subject to change (for example, in the future we may want to use GPUs, if
+ # available, when no device is explicitly provided)
+ self.assertEqual(y.device, '/job:localhost/replica:0/task:0/device:CPU:0')
+
def testContextStackContainsEagerMode(self):
# Eager execution has been enabled, and no other context
# switch has occurred, so `context_stack` should contain
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:
+ context_device = context.context().device_name
+ if not context_device:
+ context_device = "/job:localhost/replica:0/task:0/device:CPU:0"
+ if context_device != in_device:
return input._copy() # pylint: disable=protected-access
return input
# Copy the restored tensor to the variable's device.
with ops.device(self._var_device):
restored_tensor = array_ops.identity(restored_tensor)
- return resource_variable_ops.shape_safe_assign_variable_handle(
- self.handle_op, self._var_shape, restored_tensor)
+ return resource_variable_ops.shape_safe_assign_variable_handle(
+ self.handle_op, self._var_shape, restored_tensor)
def __init__(self, write_version=saver_pb2.SaverDef.V2):
self._write_version = write_version