|View source on GitHub|
Represents a (possibly partial) specification for a TensorFlow device.
tf.compat.v1.DeviceSpec( job=None, replica=None, task=None, device_type=None, device_index=None )
DeviceSpecs are used throughout TensorFlow to describe where state is stored
and computations occur. Using
DeviceSpec allows you to parse device spec
strings to verify their validity, merge them or compose them programmatically.
# Place the operations on device "GPU:0" in the "ps" job. device_spec = DeviceSpec(job="ps", device_type="GPU", device_index=0) with tf.device(device_spec.to_string()): # Both my_var and squared_var will be placed on /job:ps/device:GPU:0. my_var = tf.Variable(..., name="my_variable") squared_var = tf.square(my_var)
With eager execution disabled (by default in TensorFlow 1.x and by calling disable_eager_execution() in TensorFlow 2.x), the following syntax can be used: