LostTech.TensorFlow : API Documentation

Type DeviceSpec

Namespace tensorflow

Parent DeviceSpec

Interfaces IDeviceSpec

Represents a (possibly partial) specification for a TensorFlow device.

`DeviceSpec`s 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.

Example: If a `DeviceSpec` is partially specified, it will be merged with other `DeviceSpec`s according to the scope in which it is defined. `DeviceSpec` components defined in inner scopes take precedence over those defined in outer scopes. A `DeviceSpec` consists of 5 components -- each of which is optionally specified:

* Job: The job name. * Replica: The replica index. * Task: The task index. * Device type: The device type string (e.g. "CPU" or "GPU"). * Device index: The device index.
Show Example
# 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):
              # 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) 

Methods

Properties

Public instance methods

object make_merged_spec(PythonClassContainer dev)

object make_merged_spec(object dev)

object make_merged_spec_dyn(object dev)

void merge_from(DeviceSpec dev)

Merge the properties of "dev" into this `DeviceSpec`.

Note: Will be removed in TensorFlow 2.x since DeviceSpecs will become immutable.
Parameters
DeviceSpec dev
a `DeviceSpec`.

object merge_from_dyn(object dev)

Merge the properties of "dev" into this `DeviceSpec`.

Note: Will be removed in TensorFlow 2.x since DeviceSpecs will become immutable.
Parameters
object dev
a `DeviceSpec`.

object parse_from_string(string spec)

Parse a `DeviceSpec` name into its components.

2.x behavior change: In TensorFlow 1.x, this function mutates its own state and returns itself. In 2.x, DeviceSpecs are immutable, and this function will return a DeviceSpec which contains the spec.

Recommended: ``` # my_spec and my_updated_spec are unrelated. my_spec = tf.DeviceSpec.from_string("/CPU:0") my_updated_spec = tf.DeviceSpec.from_string("/GPU:0") with tf.device(my_updated_spec): ... ```

Will work in 1.x and 2.x (though deprecated in 2.x): ``` my_spec = tf.DeviceSpec.from_string("/CPU:0") my_updated_spec = my_spec.parse_from_string("/GPU:0") with tf.device(my_updated_spec): ... ```

Will NOT work in 2.x: ``` my_spec = tf.DeviceSpec.from_string("/CPU:0") my_spec.parse_from_string("/GPU:0") # <== Will not update my_spec with tf.device(my_spec): ... ```

In general, `DeviceSpec.from_string` should completely replace `DeviceSpec.parse_from_string`, and `DeviceSpec.replace` should completely replace setting attributes directly.
Parameters
string spec
an optional string of the form /job:/replica:/task:/device:CPU: or /job:/replica:/task:/device:GPU: as cpu and gpu are mutually exclusive. All entries are optional.
Returns
object
The `DeviceSpec`.

object parse_from_string_dyn(object spec)

Parse a `DeviceSpec` name into its components.

2.x behavior change: In TensorFlow 1.x, this function mutates its own state and returns itself. In 2.x, DeviceSpecs are immutable, and this function will return a DeviceSpec which contains the spec.

Recommended: ``` # my_spec and my_updated_spec are unrelated. my_spec = tf.DeviceSpec.from_string("/CPU:0") my_updated_spec = tf.DeviceSpec.from_string("/GPU:0") with tf.device(my_updated_spec): ... ```

Will work in 1.x and 2.x (though deprecated in 2.x): ``` my_spec = tf.DeviceSpec.from_string("/CPU:0") my_updated_spec = my_spec.parse_from_string("/GPU:0") with tf.device(my_updated_spec): ... ```

Will NOT work in 2.x: ``` my_spec = tf.DeviceSpec.from_string("/CPU:0") my_spec.parse_from_string("/GPU:0") # <== Will not update my_spec with tf.device(my_spec): ... ```

In general, `DeviceSpec.from_string` should completely replace `DeviceSpec.parse_from_string`, and `DeviceSpec.replace` should completely replace setting attributes directly.
Parameters
object spec
an optional string of the form /job:/replica:/task:/device:CPU: or /job:/replica:/task:/device:GPU: as cpu and gpu are mutually exclusive. All entries are optional.
Returns
object
The `DeviceSpec`.

IList<string> to_string()

Return a string representation of this `DeviceSpec`.
Returns
IList<string>
a string of the form /job:/replica:/task:/device::.

object to_string_dyn()

Return a string representation of this `DeviceSpec`.
Returns
object
a string of the form /job:/replica:/task:/device::.

Public properties

Nullable<int> device_index get; set;

object device_index_dyn get; set;

string device_type get; set;

object device_type_dyn get; set;

string job get; set;

object job_dyn get; set;

object PythonObject get;

Nullable<int> replica get; set;

object replica_dyn get; set;

Nullable<int> task get; set;

object task_dyn get; set;