tf.compat.v1.while_loop Repeat body while the condition cond is true.
tf.compat.v1.while_loop(
    cond, body, loop_vars, shape_invariants=None, parallel_iterations=10,
    back_prop=True, swap_memory=False, name=None, maximum_iterations=None,
    return_same_structure=False
)
 cond is a callable returning a boolean scalar tensor. body is a callable returning a (possibly nested) tuple, namedtuple or list of tensors of the same arity (length and structure) and types as loop_vars. loop_vars is a (possibly nested) tuple, namedtuple or list of tensors that is passed to both cond and body. cond and body both take as many arguments as there are loop_vars. In addition to regular Tensors or IndexedSlices, the body may accept and return TensorArray objects. The flows of the TensorArray objects will be appropriately forwarded between loops and during gradient calculations. Note that while_loop calls cond and body exactly once (inside the call to while_loop, and not at all during Session.run()). while_loop stitches together the graph fragments created during the cond and body calls with some additional graph nodes to create the graph flow that repeats body until cond returns false. For correctness, tf.while_loop() strictly enforces shape invariants for the loop variables. A shape invariant is a (possibly partial) shape that is unchanged across the iterations of the loop. An error will be raised if the shape of a loop variable after an iteration is determined to be more general than or incompatible with its shape invariant. For example, a shape of [11, None] is more general than a shape of [11, 17], and [11, 21] is not compatible with [11, 17]. By default (if the argument shape_invariants is not specified), it is assumed that the initial shape of each tensor in loop_vars is the same in every iteration. The shape_invariants argument allows the caller to specify a less specific shape invariant for each loop variable, which is needed if the shape varies between iterations. The tf.Tensor.set_shape function may also be used in the body function to indicate that the output loop variable has a particular shape. The shape invariant for SparseTensor and IndexedSlices are treated specially as follows: a) If a loop variable is a SparseTensor, the shape invariant must be TensorShape([r]) where r is the rank of the dense tensor represented by the sparse tensor. It means the shapes of the three tensors of the SparseTensor are ([None], [None, r], [r]). NOTE: The shape invariant here is the shape of the SparseTensor.dense_shape property. It must be the shape of a vector. b) If a loop variable is an IndexedSlices, the shape invariant must be a shape invariant of the values tensor of the IndexedSlices. It means the shapes of the three tensors of the IndexedSlices are (shape, [shape[0]], [shape.ndims]). while_loop implements non-strict semantics, enabling multiple iterations to run in parallel. The maximum number of parallel iterations can be controlled by parallel_iterations, which gives users some control over memory consumption and execution order. For correct programs, while_loop should return the same result for any parallel_iterations > 0. For training, TensorFlow stores the tensors that are produced in the forward inference and are needed in back propagation. These tensors are a main source of memory consumption and often cause OOM errors when training on GPUs. When the flag swap_memory is true, we swap out these tensors from GPU to CPU. This for example allows us to train RNN models with very long sequences and large batches.

 Args
  cond   A callable that represents the termination condition of the loop.
  body   A callable that represents the loop body.
  loop_vars   A (possibly nested) tuple, namedtuple or list of numpy array, Tensor, and TensorArray objects.
  shape_invariants   The shape invariants for the loop variables.
  parallel_iterations   The number of iterations allowed to run in parallel. It must be a positive integer.
  back_prop   Whether backprop is enabled for this while loop.
  swap_memory   Whether GPU-CPU memory swap is enabled for this loop.
  name   Optional name prefix for the returned tensors.
  maximum_iterations   Optional maximum number of iterations of the while loop to run. If provided, the cond output is AND-ed with an additional condition ensuring the number of iterations executed is no greater than maximum_iterations.
  return_same_structure   If True, output has same structure as loop_vars. If eager execution is enabled, this is ignored (and always treated as True).

 Returns   The output tensors for the loop variables after the loop. If return_same_structure is True, the return value has the same structure as loop_vars. If return_same_structure is False, the return value is a Tensor, TensorArray or IndexedSlice if the length of loop_vars is 1, or a list otherwise.

 Raises
  TypeError   if cond or body is not callable.
  ValueError   if loop_vars is empty.    Example: i = tf.constant(0)
c = lambda i: tf.less(i, 10)
b = lambda i: tf.add(i, 1)
r = tf.while_loop(c, b, [i])
 Example with nesting and a namedtuple: import collections
Pair = collections.namedtuple('Pair', 'j, k')
ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2)))
c = lambda i, p: i < 10
b = lambda i, p: (i + 1, Pair((p.j + p.k), (p.j - p.k)))
ijk_final = tf.while_loop(c, b, ijk_0)
 Example using shape_invariants: i0 = tf.constant(0)
m0 = tf.ones([2, 2])
c = lambda i, m: i < 10
b = lambda i, m: [i+1, tf.concat([m, m], axis=0)]
tf.while_loop(
    c, b, loop_vars=[i0, m0],
    shape_invariants=[i0.get_shape(), tf.TensorShape([None, 2])])
 Example which demonstrates non-strict semantics: In the following example, the final value of the counter i does not depend on x. So the while_loop can increment the counter parallel to updates of x. However, because the loop counter at one loop iteration depends on the value at the previous iteration, the loop counter itself cannot be incremented in parallel. Hence if we just want the final value of the counter (which we print on the line print(sess.run(i))), then x will never be incremented, but the counter will be updated on a single thread. Conversely, if we want the value of the output (which we print on the line print(sess.run(out).shape)), then the counter may be incremented on its own thread, while x can be incremented in parallel on a separate thread. In the extreme case, it is conceivable that the thread incrementing the counter runs until completion before x is incremented even a single time. The only thing that can never happen is that the thread updating x can never get ahead of the counter thread because the thread incrementing x depends on the value of the counter. import tensorflow as tf

n = 10000
x = tf.constant(list(range(n)))
c = lambda i, x: i < n
b = lambda i, x: (tf.compat.v1.Print(i + 1, [i]), tf.compat.v1.Print(x + 1,
[i], "x:"))
i, out = tf.while_loop(c, b, (0, x))
with tf.compat.v1.Session() as sess:
    print(sess.run(i))  # prints [0] ... [9999]

    # The following line may increment the counter and x in parallel.
    # The counter thread may get ahead of the other thread, but not the
    # other way around. So you may see things like
    # [9996] x:[9987]
    # meaning that the counter thread is on iteration 9996,
    # while the other thread is on iteration 9987
    print(sess.run(out).shape)


tf.compat.v1.WholeFileReader A Reader that outputs the entire contents of a file as a value. Inherits From: ReaderBase
tf.compat.v1.WholeFileReader(
    name=None
)
 To use, enqueue filenames in a Queue. The output of Read will be a filename (key) and the contents of that file (value). See ReaderBase for supported methods.

 Args
  name   A name for the operation (optional).    Eager Compatibility Readers are not compatible with eager execution. Instead, please use tf.data to get data into your model.

 Attributes
  reader_ref   Op that implements the reader.
  supports_serialize   Whether the Reader implementation can serialize its state.    Methods num_records_produced View source
num_records_produced(
    name=None
)
 Returns the number of records this reader has produced. This is the same as the number of Read executions that have succeeded.

 Args
  name   A name for the operation (optional).

 Returns   An int64 Tensor.
 num_work_units_completed View source
num_work_units_completed(
    name=None
)
 Returns the number of work units this reader has finished processing.

 Args
  name   A name for the operation (optional).

 Returns   An int64 Tensor.
 read View source
read(
    queue, name=None
)
 Returns the next record (key, value) pair produced by a reader. Will dequeue a work unit from queue if necessary (e.g. when the Reader needs to start reading from a new file since it has finished with the previous file).

 Args
  queue   A Queue or a mutable string Tensor representing a handle to a Queue, with string work items.
  name   A name for the operation (optional).

 Returns   A tuple of Tensors (key, value).     key   A string scalar Tensor.
  value   A string scalar Tensor.    read_up_to View source
read_up_to(
    queue, num_records, name=None
)
 Returns up to num_records (key, value) pairs produced by a reader. Will dequeue a work unit from queue if necessary (e.g., when the Reader needs to start reading from a new file since it has finished with the previous file). It may return less than num_records even before the last batch.

 Args
  queue   A Queue or a mutable string Tensor representing a handle to a Queue, with string work items.
  num_records   Number of records to read.
  name   A name for the operation (optional).

 Returns   A tuple of Tensors (keys, values).     keys   A 1-D string Tensor.
  values   A 1-D string Tensor.    reset View source
reset(
    name=None
)
 Restore a reader to its initial clean state.

 Args
  name   A name for the operation (optional).

 Returns   The created Operation.
 restore_state View source
restore_state(
    state, name=None
)
 Restore a reader to a previously saved state. Not all Readers support being restored, so this can produce an Unimplemented error.

 Args
  state   A string Tensor. Result of a SerializeState of a Reader with matching type.
  name   A name for the operation (optional).

 Returns   The created Operation.
 serialize_state View source
serialize_state(
    name=None
)
 Produce a string tensor that encodes the state of a reader. Not all Readers support being serialized, so this can produce an Unimplemented error.

 Args
  name   A name for the operation (optional).

 Returns   A string Tensor.


tf.compat.v1.wrap_function Wraps the TF 1.x function fn into a graph function.
tf.compat.v1.wrap_function(
    fn, signature, name=None
)
 The python function fn will be called once with symbolic arguments specified in the signature, traced, and turned into a graph function. Any variables created by fn will be owned by the object returned by wrap_function. The resulting graph function can be called with tensors which match the signature. def f(x, do_add):
  v = tf.Variable(5.0)
  if do_add:
    op = v.assign_add(x)
  else:
    op = v.assign_sub(x)
  with tf.control_dependencies([op]):
    return v.read_value()

f_add = tf.compat.v1.wrap_function(f, [tf.TensorSpec((), tf.float32), True])

assert float(f_add(1.0)) == 6.0
assert float(f_add(1.0)) == 7.0

# Can call tf.compat.v1.wrap_function again to get a new trace, a new set
# of variables, and possibly different non-template arguments.
f_sub= tf.compat.v1.wrap_function(f, [tf.TensorSpec((), tf.float32), False])

assert float(f_sub(1.0)) == 4.0
assert float(f_sub(1.0)) == 3.0
 Both tf.compat.v1.wrap_function and tf.function create a callable TensorFlow graph. But while tf.function runs all stateful operations (e.g. tf.print) and sequences operations to provide the same semantics as eager execution, wrap_function is closer to the behavior of session.run in TensorFlow 1.x. It will not run any operations unless they are required to compute the function's outputs, either through a data dependency or a control dependency. Nor will it sequence operations. Unlike tf.function, wrap_function will only trace the Python function once. As with placeholders in TF 1.x, shapes and dtypes must be provided to wrap_function's signature argument. Since it is only traced once, variables and state may be created inside the function and owned by the function wrapper object.

 Args
  fn   python function to be wrapped
  signature   the placeholder and python arguments to be passed to the wrapped function
  name   Optional. The name of the function.

 Returns   the wrapped graph function.


Module: tf.compat.v1.xla Public API for tf.xla namespace. Modules experimental module: Public API for tf.xla.experimental namespace.


Module: tf.compat.v1.xla.experimental Public API for tf.xla.experimental namespace. Functions compile(...): Builds an operator that compiles and runs computation with XLA. (deprecated) jit_scope(...): Enable or disable JIT compilation of operators within the scope.


tf.compat.v1.zeros_like Creates a tensor with all elements set to zero.
tf.compat.v1.zeros_like(
    tensor, dtype=None, name=None, optimize=True
)
 See also tf.zeros. Given a single tensor (tensor), this operation returns a tensor of the same type and shape as tensor with all elements set to zero. Optionally, you can use dtype to specify a new type for the returned tensor. Examples:
tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.zeros_like(tensor)
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
array([[0, 0, 0],
       [0, 0, 0]], dtype=int32)>

tf.zeros_like(tensor, dtype=tf.float32)
<tf.Tensor: shape=(2, 3), dtype=float32, numpy=
array([[0., 0., 0.],
       [0., 0., 0.]], dtype=float32)>

 Args
  tensor   A Tensor.
  dtype   A type for the returned Tensor. Must be float16, float32, float64, int8, uint8, int16, uint16, int32, int64, complex64, complex128, bool or string. (optional)
  name   A name for the operation (optional).
  optimize   if True, attempt to statically determine the shape of tensor and encode it as a constant. (optional, defaults to True)

 Returns   A Tensor with all elements set to zero.


tf.concat     View source on GitHub    Concatenates tensors along one dimension.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.concat
tf.concat(
    values, axis, name='concat'
)
 See also tf.tile, tf.stack, tf.repeat. Concatenates the list of tensors values along dimension axis. If values[i].shape = [D0, D1, ... Daxis(i), ...Dn], the concatenated result has shape [D0, D1, ... Raxis, ...Dn]
 where Raxis = sum(Daxis(i))
 That is, the data from the input tensors is joined along the axis dimension. The number of dimensions of the input tensors must match, and all dimensions except axis must be equal. For example:
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0)
<tf.Tensor: shape=(4, 3), dtype=int32, numpy=
array([[ 1,  2,  3],
       [ 4,  5,  6],
       [ 7,  8,  9],
       [10, 11, 12]], dtype=int32)>

tf.concat([t1, t2], 1)
<tf.Tensor: shape=(2, 6), dtype=int32, numpy=
array([[ 1,  2,  3,  7,  8,  9],
       [ 4,  5,  6, 10, 11, 12]], dtype=int32)>
 As in Python, the axis could also be negative numbers. Negative axis are interpreted as counting from the end of the rank, i.e., axis + rank(values)-th dimension. For example:
t1 = [[[1, 2], [2, 3]], [[4, 4], [5, 3]]]
t2 = [[[7, 4], [8, 4]], [[2, 10], [15, 11]]]
tf.concat([t1, t2], -1)
<tf.Tensor: shape=(2, 2, 4), dtype=int32, numpy=
  array([[[ 1,  2,  7,  4],
          [ 2,  3,  8,  4]],
         [[ 4,  4,  2, 10],
          [ 5,  3, 15, 11]]], dtype=int32)>

Note: If you are concatenating along a new axis consider using stack. E.g.

tf.concat([tf.expand_dims(t, axis) for t in tensors], axis)
 can be rewritten as tf.stack(tensors, axis=axis)

 Args
  values   A list of Tensor objects or a single Tensor.
  axis   0-D int32 Tensor. Dimension along which to concatenate. Must be in the range [-rank(values), rank(values)). As in Python, indexing for axis is 0-based. Positive axis in the rage of [0, rank(values)) refers to axis-th dimension. And negative axis refers to axis + rank(values)-th dimension.
  name   A name for the operation (optional).

 Returns   A Tensor resulting from concatenation of the input tensors.


tf.cond     View source on GitHub    Return true_fn() if the predicate pred is true else false_fn().
tf.cond(
    pred, true_fn=None, false_fn=None, name=None
)
 true_fn and false_fn both return lists of output tensors. true_fn and false_fn must have the same non-zero number and type of outputs. Warning: Any Tensors or Operations created outside of true_fn and false_fn will be executed regardless of which branch is selected at runtime. Although this behavior is consistent with the dataflow model of TensorFlow, it has frequently surprised users who expected a lazier semantics. Consider the following simple program: z = tf.multiply(a, b)
result = tf.cond(x < y, lambda: tf.add(x, z), lambda: tf.square(y))
 If x < y, the tf.add operation will be executed and tf.square operation will not be executed. Since z is needed for at least one branch of the cond, the tf.multiply operation is always executed, unconditionally. Note that cond calls true_fn and false_fn exactly once (inside the call to cond, and not at all during Session.run()). cond stitches together the graph fragments created during the true_fn and false_fn calls with some additional graph nodes to ensure that the right branch gets executed depending on the value of pred. tf.cond supports nested structures as implemented in tensorflow.python.util.nest. Both true_fn and false_fn must return the same (possibly nested) value structure of lists, tuples, and/or named tuples. Singleton lists and tuples form the only exceptions to this: when returned by true_fn and/or false_fn, they are implicitly unpacked to single values.
Note: It is illegal to "directly" use tensors created inside a cond branch outside it, e.g. by storing a reference to a branch tensor in the python state. If you need to use a tensor created in a branch function you should return it as an output of the branch function and use the output from tf.cond instead.

 Args
  pred   A scalar determining whether to return the result of true_fn or false_fn.
  true_fn   The callable to be performed if pred is true.
  false_fn   The callable to be performed if pred is false.
  name   Optional name prefix for the returned tensors.

 Returns   Tensors returned by the call to either true_fn or false_fn. If the callables return a singleton list, the element is extracted from the list.

 Raises
  TypeError   if true_fn or false_fn is not callable.
  ValueError   if true_fn and false_fn do not return the same number of tensors, or return tensors of different types.    Example: x = tf.constant(2)
y = tf.constant(5)
def f1(): return tf.multiply(x, 17)
def f2(): return tf.add(y, 23)
r = tf.cond(tf.less(x, y), f1, f2)
# r is set to f1().
# Operations in f2 (e.g., tf.add) are not executed.


Module: tf.config Public API for tf.config namespace. Modules experimental module: Public API for tf.config.experimental namespace. optimizer module: Public API for tf.config.optimizer namespace. threading module: Public API for tf.config.threading namespace. Classes class LogicalDevice: Abstraction for a logical device initialized by the runtime. class LogicalDeviceConfiguration: Configuration class for a logical devices. class PhysicalDevice: Abstraction for a locally visible physical device. Functions experimental_connect_to_cluster(...): Connects to the given cluster. experimental_connect_to_host(...): Connects to a single machine to enable remote execution on it. experimental_functions_run_eagerly(...): Returns the value of the experimental_run_functions_eagerly setting. (deprecated) experimental_run_functions_eagerly(...): Enables / disables eager execution of tf.functions. (deprecated) functions_run_eagerly(...): Returns the value of the run_functions_eagerly setting. get_logical_device_configuration(...): Get the virtual device configuration for a tf.config.PhysicalDevice. get_soft_device_placement(...): Get if soft device placement is enabled. get_visible_devices(...): Get the list of visible physical devices. list_logical_devices(...): Return a list of logical devices created by runtime. list_physical_devices(...): Return a list of physical devices visible to the host runtime. run_functions_eagerly(...): Enables / disables eager execution of tf.functions. set_logical_device_configuration(...): Set the logical device configuration for a tf.config.PhysicalDevice. set_soft_device_placement(...): Set if soft device placement is enabled. set_visible_devices(...): Set the list of visible devices.


Module: tf.config.experimental Public API for tf.config.experimental namespace. Classes class ClusterDeviceFilters: Represent a collection of device filters for the remote workers in cluster. class VirtualDeviceConfiguration: Configuration class for a logical devices. Functions disable_mlir_bridge(...): Disables experimental MLIR-Based TensorFlow Compiler Bridge. disable_mlir_graph_optimization(...): Disables experimental MLIR-Based TensorFlow Compiler Optimizations. enable_mlir_bridge(...): Enables experimental MLIR-Based TensorFlow Compiler Bridge. enable_mlir_graph_optimization(...): Enables experimental MLIR-Based TensorFlow Compiler Optimizations. enable_tensor_float_32_execution(...): Enable or disable the use of TensorFloat-32 on supported hardware. get_device_details(...): Returns details about a physical devices. get_device_policy(...): Gets the current device policy. get_memory_growth(...): Get if memory growth is enabled for a PhysicalDevice. get_memory_usage(...): Get the memory usage, in bytes, for the chosen device. get_synchronous_execution(...): Gets whether operations are executed synchronously or asynchronously. get_virtual_device_configuration(...): Get the virtual device configuration for a tf.config.PhysicalDevice. get_visible_devices(...): Get the list of visible physical devices. list_logical_devices(...): Return a list of logical devices created by runtime. list_physical_devices(...): Return a list of physical devices visible to the host runtime. set_device_policy(...): Sets the current thread device policy. set_memory_growth(...): Set if memory growth should be enabled for a PhysicalDevice. set_synchronous_execution(...): Specifies whether operations are executed synchronously or asynchronously. set_virtual_device_configuration(...): Set the logical device configuration for a tf.config.PhysicalDevice. set_visible_devices(...): Set the list of visible devices. tensor_float_32_execution_enabled(...): Returns whether TensorFloat-32 is enabled.


tf.config.experimental.ClusterDeviceFilters Represent a collection of device filters for the remote workers in cluster.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.ClusterDeviceFilters
tf.config.experimental.ClusterDeviceFilters()

Note: this is an experimental API and subject to changes.
 Set device filters for selective jobs and tasks. For each remote worker, the device filters are a list of strings. When any filters are present, the remote worker will ignore all devices which do not match any of its filters. Each filter can be partially specified, e.g. "/job:ps", "/job:worker/replica:3", etc. Note that a device is always visible to the worker it is located on. For example, to set the device filters for a parameter server cluster: cdf = tf.config.experimental.ClusterDeviceFilters()
for i in range(num_workers):
  cdf.set_device_filters('worker', i, ['/job:ps'])
for i in range(num_ps):
  cdf.set_device_filters('ps', i, ['/job:worker'])

tf.config.experimental_connect_to_cluster(cluster_def,
                                          cluster_device_filters=cdf)
 The device filters can be partically specified. For remote tasks that do not have device filters specified, all devices will be visible to them. Methods set_device_filters View source
set_device_filters(
    job_name, task_index, device_filters
)
 Set the device filters for given job name and task id.


tf.config.experimental.disable_mlir_bridge Disables experimental MLIR-Based TensorFlow Compiler Bridge.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.disable_mlir_bridge
tf.config.experimental.disable_mlir_bridge()


tf.config.experimental.disable_mlir_graph_optimization Disables experimental MLIR-Based TensorFlow Compiler Optimizations.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.disable_mlir_graph_optimization
tf.config.experimental.disable_mlir_graph_optimization()


tf.config.experimental.enable_mlir_bridge Enables experimental MLIR-Based TensorFlow Compiler Bridge.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.enable_mlir_bridge
tf.config.experimental.enable_mlir_bridge()
 DO NOT USE, DEV AND TESTING ONLY AT THE MOMENT.
Note: MLIR-Based TensorFlow Compiler is under active development and has missing features, please refrain from using. This API exists for development and testing only.
 TensorFlow Compiler Bridge (TF Bridge) is responsible for translating parts of TensorFlow graph into a form that can be accepted as an input by a backend compiler such as XLA.


tf.config.experimental.enable_mlir_graph_optimization Enables experimental MLIR-Based TensorFlow Compiler Optimizations.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.enable_mlir_graph_optimization
tf.config.experimental.enable_mlir_graph_optimization()
 DO NOT USE, DEV AND TESTING ONLY AT THE MOMENT.
Note: MLIR-Based TensorFlow Compiler is under active development and has missing features, please refrain from using. This API exists for development and testing only.
 TensorFlow Compiler Optimizations are responsible general graph level optimizations that in the current stack mostly done by Grappler graph optimizers.


tf.config.experimental.enable_tensor_float_32_execution Enable or disable the use of TensorFloat-32 on supported hardware.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.enable_tensor_float_32_execution
tf.config.experimental.enable_tensor_float_32_execution(
    enabled
)
 TensorFloat-32, or TF32 for short, is a math mode for NVIDIA Ampere GPUs. TensorFloat-32 execution causes certain float32 ops, such as matrix multiplications and convolutions, to run much faster on Ampere GPUs but with reduced precision. This reduced precision should not impact convergence of deep learning models in practice. TensorFloat-32 is enabled by default. TensorFloat-32 is only supported on Ampere GPUs, so all other hardware will use the full float32 precision regardless of whether TensorFloat-32 is enabled or not. If you want to use the full float32 precision on Ampere, you can disable TensorFloat-32 execution with this function. For example: x = tf.fill((2, 2), 1.0001)
y = tf.fill((2, 2), 1.)
# TensorFloat-32 is enabled, so matmul is run with reduced precision
print(tf.linalg.matmul(x, y))  # [[2., 2.], [2., 2.]]
tf.config.experimental.enable_tensor_float_32_execution(False)
# Matmul is run with full precision
print(tf.linalg.matmul(x, y))  # [[2.0002, 2.0002], [2.0002, 2.0002]]
 To check whether TensorFloat-32 execution is currently enabled, use tf.config.experimental.tensor_float_32_execution_enabled. If TensorFloat-32 is enabled, float32 inputs of supported ops, such as tf.linalg.matmul, will be rounded from 23 bits of precision to 10 bits of precision in most cases. This allows the ops to execute much faster by utilizing the GPU's tensor cores. TensorFloat-32 has the same dynamic range as float32, meaning it is no more likely to underflow or overflow than float32. Ops still use float32 accumulation when TensorFloat-32 is enabled. Enabling or disabling TensorFloat-32 only affects Ampere GPUs and subsequent GPUs that support TensorFloat-32. Note TensorFloat-32 is not always used in supported ops, as only inputs of certain shapes are supported. Support for more input shapes and more ops may be added in the future. As a result, precision of float32 ops may decrease in minor versions of TensorFlow. TensorFloat-32 is also used for some complex64 ops. Currently, TensorFloat-32 is used in fewer cases for complex64 as it is for float32.

 Args
  enabled   Bool indicating whether to enable TensorFloat-32 execution.


tf.config.experimental.get_device_details Returns details about a physical devices.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.get_device_details
tf.config.experimental.get_device_details(
    device
)
 This API takes in a tf.config.PhysicalDevice returned by tf.config.list_physical_devices. It returns a dict with string keys containing various details about the device. Each key is only supported by a subset of devices, so you should not assume the returned dict will have any particular key.
gpu_devices = tf.config.list_physical_devices('GPU')
if gpu_devices:
  details = tf.config.experimental.get_device_details(gpu_devices[0])
  details.get('device_name', 'Unknown GPU')
 Currently, details are only returned for GPUs. This function returns an empty dict if passed a non-GPU device. The returned dict may have the following keys:
'device_name': A human-readable name of the device as a string, e.g. "Titan V". Unlike tf.config.PhysicalDevice.name, this will be the same for multiple devices if each device is the same model. Currently only available for GPUs.
'compute_capability': The compute capability of the device as a tuple of two ints, in the form (major_version, minor_version). Only available for NVIDIA GPUs
Note: This is similar to tf.sysconfig.get_build_info in that both functions can return information relating to GPUs. However, this function returns run-time information about a specific device (such as a GPU's compute capability), while tf.sysconfig.get_build_info returns compile-time information about how TensorFlow was built (such as what version of CUDA TensorFlow was built for).

 Args
  device   A tf.config.PhysicalDevice returned by tf.config.list_physical_devices or tf.config.get_visible_devices.

 Returns   A dict with string keys.


tf.config.experimental.get_device_policy     View source on GitHub    Gets the current device policy.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.get_device_policy
tf.config.experimental.get_device_policy()
 The device policy controls how operations requiring inputs on a specific device (e.g., on GPU:0) handle inputs on a different device (e.g. GPU:1). This function only gets the device policy for the current thread. Any subsequently started thread will again use the default policy.

 Returns   Current thread device policy


tf.config.experimental.get_memory_growth     View source on GitHub    Get if memory growth is enabled for a PhysicalDevice.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.get_memory_growth
tf.config.experimental.get_memory_growth(
    device
)
 If memory growth is enabled for a PhysicalDevice, the runtime initialization will not allocate all memory on the device. For example:
physical_devices = tf.config.list_physical_devices('GPU')
try:
  tf.config.experimental.set_memory_growth(physical_devices[0], True)
  assert tf.config.experimental.get_memory_growth(physical_devices[0])
except:
  # Invalid device or cannot modify virtual devices once initialized.
  pass

 Args
  device   PhysicalDevice to query

 Returns   A boolean indicating the memory growth setting for the PhysicalDevice.

 Raises
  ValueError   Invalid PhysicalDevice specified.


tf.config.experimental.get_memory_usage Get the memory usage, in bytes, for the chosen device.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.get_memory_usage
tf.config.experimental.get_memory_usage(
    device
)
 See https://www.tensorflow.org/api_docs/python/tf/device for specifying device strings. For example:
gpu_devices = tf.config.list_physical_devices('GPU')
if gpu_devices:
  tf.config.experimental.get_memory_usage('GPU:0')
 Does not work for CPU.

 Args
  device   Device string to get the bytes in use for.

 Returns   Total memory usage in bytes.

 Raises
  ValueError   Non-existent or CPU device specified.


tf.config.experimental.get_synchronous_execution     View source on GitHub    Gets whether operations are executed synchronously or asynchronously.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.get_synchronous_execution
tf.config.experimental.get_synchronous_execution()
 TensorFlow can execute operations synchronously or asynchronously. If asynchronous execution is enabled, operations may return "non-ready" handles.

 Returns   Current thread execution mode


tf.config.experimental.set_device_policy     View source on GitHub    Sets the current thread device policy.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.set_device_policy
tf.config.experimental.set_device_policy(
    device_policy
)
 The device policy controls how operations requiring inputs on a specific device (e.g., on GPU:0) handle inputs on a different device (e.g. GPU:1). When using the default, an appropriate policy will be picked automatically. The default policy may change over time. This function only sets the device policy for the current thread. Any subsequently started thread will again use the default policy.

 Args
  device_policy   A device policy. Valid values:  None: Switch to a system default. 'warn': Copies the tensors which are not on the right device and logs a warning. 'explicit': Raises an error if the placement is not as required. 'silent': Silently copies the tensors. Note that this may hide performance problems as there is no notification provided when operations are blocked on the tensor being copied between devices. 'silent_for_int32': silently copies int32 tensors, raising errors on the other ones.

 Raises
  ValueError   If an invalid device_policy is passed.


tf.config.experimental.set_memory_growth     View source on GitHub    Set if memory growth should be enabled for a PhysicalDevice.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.set_memory_growth
tf.config.experimental.set_memory_growth(
    device, enable
)
 If memory growth is enabled for a PhysicalDevice, the runtime initialization will not allocate all memory on the device. Memory growth cannot be configured on a PhysicalDevice with virtual devices configured. For example:
physical_devices = tf.config.list_physical_devices('GPU')
try:
  tf.config.experimental.set_memory_growth(physical_devices[0], True)
except:
  # Invalid device or cannot modify virtual devices once initialized.
  pass

 Args
  device   PhysicalDevice to configure
  enable   (Boolean) Whether to enable or disable memory growth

 Raises
  ValueError   Invalid PhysicalDevice specified.
  RuntimeError   Runtime is already initialized.


tf.config.experimental.set_synchronous_execution     View source on GitHub    Specifies whether operations are executed synchronously or asynchronously.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.set_synchronous_execution
tf.config.experimental.set_synchronous_execution(
    enable
)
 TensorFlow can execute operations synchronously or asynchronously. If asynchronous execution is enabled, operations may return "non-ready" handles. When enable is set to None, an appropriate value will be picked automatically. The value picked may change between TensorFlow releases.

 Args
  enable   Whether operations should be dispatched synchronously. Valid values:  None: sets the system default. True: executes each operation synchronously. False: executes each operation asynchronously.


tf.config.experimental.tensor_float_32_execution_enabled Returns whether TensorFloat-32 is enabled.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental.tensor_float_32_execution_enabled
tf.config.experimental.tensor_float_32_execution_enabled()
 By default, TensorFloat-32 is enabled, but this can be changed with tf.config.experimental.enable_tensor_float_32_execution.

 Returns   True if TensorFloat-32 is enabled (the default) and False otherwise


tf.config.experimental_connect_to_cluster     View source on GitHub    Connects to the given cluster.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental_connect_to_cluster
tf.config.experimental_connect_to_cluster(
    cluster_spec_or_resolver, job_name='localhost', task_index=0,
    protocol=None, make_master_device_default=True, cluster_device_filters=None
)
 Will make devices on the cluster available to use. Note that calling this more than once will work, but will invalidate any tensor handles on the old remote devices. If the given local job name is not present in the cluster specification, it will be automatically added, using an unused port on the localhost. Device filters can be specified to isolate groups of remote tasks to avoid undesired accesses between workers. Workers accessing resources or launching ops / functions on filtered remote devices will result in errors (unknown devices). For any remote task, if no device filter is present, all cluster devices will be visible; if any device filter is specified, it can only see devices matching at least one filter. Devices on the task itself are always visible. Device filters can be particially specified. For example, for a cluster set up for parameter server training, the following device filters might be specified: cdf = tf.config.experimental.ClusterDeviceFilters()
# For any worker, only the devices on PS nodes and itself are visible
for i in range(num_workers):
  cdf.set_device_filters('worker', i, ['/job:ps'])
# Similarly for any ps, only the devices on workers and itself are visible
for i in range(num_ps):
  cdf.set_device_filters('ps', i, ['/job:worker'])

tf.config.experimental_connect_to_cluster(cluster_def,
                                          cluster_device_filters=cdf)

 Args
  cluster_spec_or_resolver   A ClusterSpec or ClusterResolver describing the cluster.
  job_name   The name of the local job.
  task_index   The local task index.
  protocol   The communication protocol, such as "grpc". If unspecified, will use the default from python/platform/remote_utils.py.
  make_master_device_default   If True and a cluster resolver is passed, will automatically enter the master task device scope, which indicates the master becomes the default device to run ops. It won't do anything if a cluster spec is passed. Will throw an error if the caller is currently already in some device scope.
  cluster_device_filters   an instance of tf.train.experimental/ClusterDeviceFilters that specify device filters to the remote tasks in cluster.


tf.config.experimental_connect_to_host     View source on GitHub    Connects to a single machine to enable remote execution on it.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental_connect_to_host
tf.config.experimental_connect_to_host(
    remote_host=None, job_name='worker'
)
 Will make devices on the remote host available to use. Note that calling this more than once will work, but will invalidate any tensor handles on the old remote devices. Using the default job_name of worker, you can schedule ops to run remotely as follows: # When eager execution is enabled, connect to the remote host.
tf.config.experimental_connect_to_host("exampleaddr.com:9876")

with ops.device("job:worker/replica:0/task:1/device:CPU:0"):
  # The following tensors should be resident on the remote device, and the op
  # will also execute remotely.
  x1 = array_ops.ones([2, 2])
  x2 = array_ops.ones([2, 2])
  y = math_ops.matmul(x1, x2)

 Args
  remote_host   a single or a list the remote server addr in host-port format.
  job_name   The job name under which the new server will be accessible.

 Raises
  ValueError   if remote_host is None.


tf.config.experimental_functions_run_eagerly Returns the value of the experimental_run_functions_eagerly setting. (deprecated)  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental_functions_run_eagerly
tf.config.experimental_functions_run_eagerly()
 Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use tf.config.functions_run_eagerly instead of the experimental version.


tf.config.experimental_run_functions_eagerly     View source on GitHub    Enables / disables eager execution of tf.functions. (deprecated)  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.experimental_run_functions_eagerly
tf.config.experimental_run_functions_eagerly(
    run_eagerly
)
 Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use tf.config.run_functions_eagerly instead of the experimental version. Calling tf.config.experimental_run_functions_eagerly(True) will make all invocations of tf.function run eagerly instead of running as a traced graph function. See tf.config.run_functions_eagerly for an example.
Note: This flag has no effect on functions passed into tf.data transformations as arguments. tf.data functions are never executed eagerly and are always executed as a compiled Tensorflow Graph.

 Args
  run_eagerly   Boolean. Whether to run functions eagerly.


tf.config.functions_run_eagerly Returns the value of the run_functions_eagerly setting.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.functions_run_eagerly
tf.config.functions_run_eagerly()


tf.config.get_logical_device_configuration Get the virtual device configuration for a tf.config.PhysicalDevice.  View aliases  Main aliases
tf.config.experimental.get_virtual_device_configuration Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.experimental.get_virtual_device_configuration, tf.compat.v1.config.get_logical_device_configuration
tf.config.get_logical_device_configuration(
    device
)
 Returns the list of tf.config.LogicalDeviceConfiguration objects previously configured by a call to tf.config.set_logical_device_configuration. For example:
physical_devices = tf.config.list_physical_devices('CPU')
assert len(physical_devices) == 1, "No CPUs found"
configs = tf.config.get_logical_device_configuration(
  physical_devices[0])
try:
  assert configs is None
  tf.config.set_logical_device_configuration(
    physical_devices[0],
    [tf.config.LogicalDeviceConfiguration(),
     tf.config.LogicalDeviceConfiguration()])
  configs = tf.config.get_logical_device_configuration(
    physical_devices[0])
  assert len(configs) == 2
except:
  # Cannot modify virtual devices once initialized.
  pass

 Args
  device   PhysicalDevice to query

 Returns   List of tf.config.LogicalDeviceConfiguration objects or None if no virtual device configuration has been set for this physical device.


tf.config.get_soft_device_placement     View source on GitHub    Get if soft device placement is enabled.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.get_soft_device_placement
tf.config.get_soft_device_placement()
 If enabled, an op will be placed on CPU if any of the following are true  there's no GPU implementation for the OP no GPU devices are known or registered need to co-locate with reftype input(s) which are from CPU

 Returns   If soft placement is enabled.


tf.config.get_visible_devices Get the list of visible physical devices.  View aliases  Main aliases
tf.config.experimental.get_visible_devices Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.experimental.get_visible_devices, tf.compat.v1.config.get_visible_devices
tf.config.get_visible_devices(
    device_type=None
)
 Returns the list of PhysicalDevices currently marked as visible to the runtime. A visible device will have at least one LogicalDevice associated with it once the runtime is initialized. The following example verifies all visible GPUs have been disabled:
physical_devices = tf.config.list_physical_devices('GPU')
try:
  # Disable all GPUS
  tf.config.set_visible_devices([], 'GPU')
  visible_devices = tf.config.get_visible_devices()
  for device in visible_devices:
    assert device.device_type != 'GPU'
except:
  # Invalid device or cannot modify virtual devices once initialized.
  pass

 Args
  device_type   (optional string) Only include devices matching this device type. For example "CPU" or "GPU".

 Returns   List of visible PhysicalDevices


tf.config.list_logical_devices Return a list of logical devices created by runtime.  View aliases  Main aliases
tf.config.experimental.list_logical_devices Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.experimental.list_logical_devices, tf.compat.v1.config.list_logical_devices
tf.config.list_logical_devices(
    device_type=None
)
 Logical devices may correspond to physical devices or remote devices in the cluster. Operations and tensors may be placed on these devices by using the name of the tf.config.LogicalDevice. Calling tf.config.list_logical_devices triggers the runtime to configure any tf.config.PhysicalDevice visible to the runtime, thereby preventing further configuration. To avoid runtime initialization, call tf.config.list_physical_devices instead. For example:
logical_devices = tf.config.list_logical_devices('GPU')
if len(logical_devices) > 0:
  # Allocate on GPU:0
  with tf.device(logical_devices[0].name):
    one = tf.constant(1)
  # Allocate on GPU:1
  with tf.device(logical_devices[1].name):
    two = tf.constant(2)

 Args
  device_type   (optional string) Only include devices matching this device type. For example "CPU" or "GPU".

 Returns   List of initialized LogicalDevices


tf.config.list_physical_devices Return a list of physical devices visible to the host runtime.  View aliases  Main aliases
tf.config.experimental.list_physical_devices Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.experimental.list_physical_devices, tf.compat.v1.config.list_physical_devices
tf.config.list_physical_devices(
    device_type=None
)
 Physical devices are hardware devices present on the host machine. By default all discovered CPU and GPU devices are considered visible. This API allows querying the physical hardware resources prior to runtime initialization. Thus, giving an opportunity to call any additional configuration APIs. This is in contrast to tf.config.list_logical_devices, which triggers runtime initialization in order to list the configured devices. The following example lists the number of visible GPUs on the host.
physical_devices = tf.config.list_physical_devices('GPU')
print("Num GPUs:", len(physical_devices))
Num GPUs: ...
 However, the number of GPUs available to the runtime may change during runtime initialization due to marking certain devices as not visible or configuring multiple logical devices.

 Args
  device_type   (optional string) Only include devices matching this device type. For example "CPU" or "GPU".

 Returns   List of discovered tf.config.PhysicalDevice objects


tf.config.LogicalDevice Abstraction for a logical device initialized by the runtime.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.LogicalDevice
tf.config.LogicalDevice(
    name, device_type
)
 A tf.config.LogicalDevice corresponds to an initialized logical device on a tf.config.PhysicalDevice or a remote device visible to the cluster. Tensors and operations can be placed on a specific logical device by calling tf.device with a specified tf.config.LogicalDevice. Fields:
name: The fully qualified name of the device. Can be used for Op or function placement.
device_type: String declaring the type of device such as "CPU" or "GPU".

 Attributes
  name

  device_type


tf.config.LogicalDeviceConfiguration Configuration class for a logical devices.  View aliases  Main aliases
tf.config.experimental.VirtualDeviceConfiguration Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.LogicalDeviceConfiguration, tf.compat.v1.config.experimental.VirtualDeviceConfiguration
tf.config.LogicalDeviceConfiguration(
    memory_limit=None, experimental_priority=None
)
 The class specifies the parameters to configure a tf.config.PhysicalDevice as it is initialized to a tf.config.LogicalDevice during runtime initialization. Not all fields are valid for all device types. See tf.config.get_logical_device_configuration and tf.config.set_logical_device_configuration for usage examples. Fields:
memory_limit: (optional) Maximum memory (in MB) to allocate on the virtual device. Currently only supported for GPUs.
experimental_priority: (optional) Priority to assign to a virtual device. Lower values have higher priorities and 0 is the default. Within a physical GPU, the GPU scheduler will prioritize ops on virtual devices with higher priority. Currently only supported for Nvidia GPUs.

 Attributes
  memory_limit

  experimental_priority


Module: tf.config.optimizer Public API for tf.config.optimizer namespace. Functions get_experimental_options(...): Get experimental optimizer options. get_jit(...): Get if JIT compilation is enabled. set_experimental_options(...): Set experimental optimizer options. set_jit(...): Set if JIT compilation is enabled.


tf.config.optimizer.get_experimental_options     View source on GitHub    Get experimental optimizer options.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.optimizer.get_experimental_options
tf.config.optimizer.get_experimental_options()
 Refer to tf.config.optimizer.set_experimental_options for a list of current options. Note that optimizations are only applied in graph mode, (within tf.function). In addition, as these are experimental options, the list is subject to change.

 Returns   Dictionary of configured experimental optimizer options


tf.config.optimizer.get_jit     View source on GitHub    Get if JIT compilation is enabled.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.optimizer.get_jit
tf.config.optimizer.get_jit()
 Note that optimizations are only applied to code that is compiled into a graph. In eager mode, which is the TF2 API default, that means only code that is defined under a tf.function decorator.

 Returns   If JIT compilation is enabled.


tf.config.optimizer.set_experimental_options     View source on GitHub    Set experimental optimizer options.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.optimizer.set_experimental_options
tf.config.optimizer.set_experimental_options(
    options
)
 Note that optimizations are only applied in graph mode, (within tf.function). In addition, as these are experimental options, the list is subject to change.

 Args
  options   Dictionary of experimental optimizer options to configure. Valid keys:  layout_optimizer: Optimize tensor layouts e.g. This will try to use NCHW layout on GPU which is faster. constant_folding: Fold constants Statically infer the value of tensors when possible, and materialize the result using constants. shape_optimization: Simplify computations made on shapes. remapping: Remap subgraphs onto more efficient implementations. arithmetic_optimization: Simplify arithmetic ops with common sub-expression elimination and arithmetic simplification. dependency_optimization: Control dependency optimizations. Remove redundant control dependencies, which may enable other optimization. This optimizer is also essential for pruning Identity and NoOp nodes. loop_optimization: Loop optimizations. function_optimization: Function optimizations and inlining. debug_stripper: Strips debug-related nodes from the graph. disable_model_pruning: Disable removal of unnecessary ops from the graph scoped_allocator_optimization: Try to allocate some independent Op outputs contiguously in order to merge or eliminate downstream Ops. pin_to_host_optimization: Force small ops onto the CPU. implementation_selector: Enable the swap of kernel implementations based on the device placement. auto_mixed_precision: Change certain float32 ops to float16 on Volta GPUs and above. Without the use of loss scaling, this can cause numerical underflow (see keras.mixed_precision.experimental.LossScaleOptimizer). disable_meta_optimizer: Disable the entire meta optimizer. min_graph_nodes: The minimum number of nodes in a graph to optimizer. For smaller graphs, optimization is skipped.


tf.config.optimizer.set_jit     View source on GitHub    Set if JIT compilation is enabled.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.optimizer.set_jit
tf.config.optimizer.set_jit(
    enabled
)
 Note that optimizations are only applied to code that is compiled into a graph. In eager mode, which is the TF2 API default, that means only code that is defined under a tf.function decorator.

 Args
  enabled   Whether to enable JIT compilation.


tf.config.PhysicalDevice Abstraction for a locally visible physical device.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.PhysicalDevice
tf.config.PhysicalDevice(
    name, device_type
)
 TensorFlow can utilize various devices such as the CPU or multiple GPUs for computation. Before initializing a local device for use, the user can customize certain properties of the device such as it's visibility or memory configuration. Once a visible tf.config.PhysicalDevice is initialized one or more tf.config.LogicalDevice objects are created. Use tf.config.set_visible_devices to configure the visibility of a physical device and tf.config.set_logical_device_configuration to configure multiple tf.config.LogicalDevice objects for a tf.config.PhysicalDevice. This is useful when separation between models is needed or to simulate a multi-device environment. Fields:
name: Unique identifier for device.
device_type: String declaring the type of device such as "CPU" or "GPU".

 Attributes
  name

  device_type


tf.config.run_functions_eagerly Enables / disables eager execution of tf.functions.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.run_functions_eagerly
tf.config.run_functions_eagerly(
    run_eagerly
)
 Calling tf.config.run_functions_eagerly(True) will make all invocations of tf.function run eagerly instead of running as a traced graph function. This can be useful for debugging.
def my_func(a):
 print("Python side effect")
 return a + a
a_fn = tf.function(my_func)

# A side effect the first time the function is traced
a_fn(tf.constant(1))
Python side effect
<tf.Tensor: shape=(), dtype=int32, numpy=2>

# No further side effect, as the traced function is called
a_fn(tf.constant(2))
<tf.Tensor: shape=(), dtype=int32, numpy=4>

# Now, switch to eager running
tf.config.run_functions_eagerly(True)
# Side effect, as the function is called directly
a_fn(tf.constant(2))
Python side effect
<tf.Tensor: shape=(), dtype=int32, numpy=4>

# Turn this back off
tf.config.run_functions_eagerly(False)

Note: This flag has no effect on functions passed into tf.data transformations as arguments. tf.data functions are never executed eagerly and are always executed as a compiled Tensorflow Graph.

 Args
  run_eagerly   Boolean. Whether to run functions eagerly.


tf.config.set_logical_device_configuration Set the logical device configuration for a tf.config.PhysicalDevice.  View aliases  Main aliases
tf.config.experimental.set_virtual_device_configuration Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.experimental.set_virtual_device_configuration, tf.compat.v1.config.set_logical_device_configuration
tf.config.set_logical_device_configuration(
    device, logical_devices
)
 A visible tf.config.PhysicalDevice will by default have a single tf.config.LogicalDevice associated with it once the runtime is initialized. Specifying a list of tf.config.LogicalDeviceConfiguration objects allows multiple devices to be created on the same tf.config.PhysicalDevice. The following example splits the CPU into 2 logical devices:
physical_devices = tf.config.list_physical_devices('CPU')
assert len(physical_devices) == 1, "No CPUs found"
# Specify 2 virtual CPUs. Note currently memory limit is not supported.
try:
  tf.config.set_logical_device_configuration(
    physical_devices[0],
    [tf.config.LogicalDeviceConfiguration(),
     tf.config.LogicalDeviceConfiguration()])
  logical_devices = tf.config.list_logical_devices('CPU')
  assert len(logical_devices) == 2

  tf.config.set_logical_device_configuration(
    physical_devices[0],
    [tf.config.LogicalDeviceConfiguration(),
     tf.config.LogicalDeviceConfiguration(),
     tf.config.LogicalDeviceConfiguration(),
     tf.config.LogicalDeviceConfiguration()])
except:
  # Cannot modify logical devices once initialized.
  pass
 The following example splits the GPU into 2 logical devices with 100 MB each:
physical_devices = tf.config.list_physical_devices('GPU')
try:
  tf.config.set_logical_device_configuration(
    physical_devices[0],
    [tf.config.LogicalDeviceConfiguration(memory_limit=100),
     tf.config.LogicalDeviceConfiguration(memory_limit=100)])

  logical_devices = tf.config.list_logical_devices('GPU')
  assert len(logical_devices) == len(physical_devices) + 1

  tf.config.set_logical_device_configuration(
    physical_devices[0],
    [tf.config.LogicalDeviceConfiguration(memory_limit=10),
     tf.config.LogicalDeviceConfiguration(memory_limit=10)])
except:
  # Invalid device or cannot modify logical devices once initialized.
  pass

 Args
  device   The PhysicalDevice to configure.
  logical_devices   (optional) List of tf.config.LogicalDeviceConfiguration objects to allocate for the specified PhysicalDevice. If None, the default configuration will be used.

 Raises
  ValueError   If argument validation fails.
  RuntimeError   Runtime is already initialized.


tf.config.set_soft_device_placement     View source on GitHub    Set if soft device placement is enabled.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.set_soft_device_placement
tf.config.set_soft_device_placement(
    enabled
)
 If enabled, an op will be placed on CPU if any of the following are true  there's no GPU implementation for the OP no GPU devices are known or registered need to co-locate with reftype input(s) which are from CPU

 Args
  enabled   Whether to enable soft placement.


tf.config.set_visible_devices Set the list of visible devices.  View aliases  Main aliases
tf.config.experimental.set_visible_devices Compat aliases for migration See Migration guide for more details. tf.compat.v1.config.experimental.set_visible_devices, tf.compat.v1.config.set_visible_devices
tf.config.set_visible_devices(
    devices, device_type=None
)
 Specifies which PhysicalDevice objects are visible to the runtime. TensorFlow will only allocate memory and place operations on visible physical devices, as otherwise no LogicalDevice will be created on them. By default all discovered devices are marked as visible. The following example demonstrates disabling the first GPU on the machine.
physical_devices = tf.config.list_physical_devices('GPU')
try:
  # Disable first GPU
  tf.config.set_visible_devices(physical_devices[1:], 'GPU')
  logical_devices = tf.config.list_logical_devices('GPU')
  # Logical device was not created for first GPU
  assert len(logical_devices) == len(physical_devices) - 1
except:
  # Invalid device or cannot modify virtual devices once initialized.
  pass

 Args
  devices   List of PhysicalDevices to make visible
  device_type   (optional) Only configure devices matching this device type. For example "CPU" or "GPU". Other devices will be left unaltered.

 Raises
  ValueError   If argument validation fails.
  RuntimeError   Runtime is already initialized.


Module: tf.config.threading Public API for tf.config.threading namespace. Functions get_inter_op_parallelism_threads(...): Get number of threads used for parallelism between independent operations. get_intra_op_parallelism_threads(...): Get number of threads used within an individual op for parallelism. set_inter_op_parallelism_threads(...): Set number of threads used for parallelism between independent operations. set_intra_op_parallelism_threads(...): Set number of threads used within an individual op for parallelism.


tf.config.threading.get_inter_op_parallelism_threads     View source on GitHub    Get number of threads used for parallelism between independent operations.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.threading.get_inter_op_parallelism_threads
tf.config.threading.get_inter_op_parallelism_threads()
 Determines the number of threads used by independent non-blocking operations. 0 means the system picks an appropriate number.

 Returns   Number of parallel threads


tf.config.threading.get_intra_op_parallelism_threads     View source on GitHub    Get number of threads used within an individual op for parallelism.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.threading.get_intra_op_parallelism_threads
tf.config.threading.get_intra_op_parallelism_threads()
 Certain operations like matrix multiplication and reductions can utilize parallel threads for speed ups. A value of 0 means the system picks an appropriate number.

 Returns   Number of parallel threads


tf.config.threading.set_inter_op_parallelism_threads     View source on GitHub    Set number of threads used for parallelism between independent operations.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.threading.set_inter_op_parallelism_threads
tf.config.threading.set_inter_op_parallelism_threads(
    num_threads
)
 Determines the number of threads used by independent non-blocking operations. 0 means the system picks an appropriate number.

 Args
  num_threads   Number of parallel threads


tf.config.threading.set_intra_op_parallelism_threads     View source on GitHub    Set number of threads used within an individual op for parallelism.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.config.threading.set_intra_op_parallelism_threads
tf.config.threading.set_intra_op_parallelism_threads(
    num_threads
)
 Certain operations like matrix multiplication and reductions can utilize parallel threads for speed ups. A value of 0 means the system picks an appropriate number.

 Args
  num_threads   Number of parallel threads


tf.constant     View source on GitHub    Creates a constant tensor from a tensor-like object.
tf.constant(
    value, dtype=None, shape=None, name='Const'
)

Note: All eager tf.Tensor values are immutable (in contrast to tf.Variable). There is nothing especially constant about the value returned from tf.constant. This function it is not fundamentally different from tf.convert_to_tensor. The name tf.constant comes from the value being embeded in a Const node in the tf.Graph. tf.constant is useful for asserting that the value can be embedded that way.
 If the argument dtype is not specified, then the type is inferred from the type of value.
# Constant 1-D Tensor from a python list.
tf.constant([1, 2, 3, 4, 5, 6])
<tf.Tensor: shape=(6,), dtype=int32,
    numpy=array([1, 2, 3, 4, 5, 6], dtype=int32)>
# Or a numpy array
a = np.array([[1, 2, 3], [4, 5, 6]])
tf.constant(a)
<tf.Tensor: shape=(2, 3), dtype=int64, numpy=
  array([[1, 2, 3],
         [4, 5, 6]])>
 If dtype is specified the resulting tensor values are cast to the requested dtype.
tf.constant([1, 2, 3, 4, 5, 6], dtype=tf.float64)
<tf.Tensor: shape=(6,), dtype=float64,
    numpy=array([1., 2., 3., 4., 5., 6.])>
 If shape is set, the value is reshaped to match. Scalars are expanded to fill the shape:
tf.constant(0, shape=(2, 3))
  <tf.Tensor: shape=(2, 3), dtype=int32, numpy=
  array([[0, 0, 0],
         [0, 0, 0]], dtype=int32)>
tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3])
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
  array([[1, 2, 3],
         [4, 5, 6]], dtype=int32)>
 tf.constant has no effect if an eager Tensor is passed as the value, it even transmits gradients:
v = tf.Variable([0.0])
with tf.GradientTape() as g:
    loss = tf.constant(v + v)
g.gradient(loss, v).numpy()
array([2.], dtype=float32)
 But, since tf.constant embeds the value in the tf.Graph this fails for symbolic tensors:
with tf.compat.v1.Graph().as_default():
  i = tf.compat.v1.placeholder(shape=[None, None], dtype=tf.float32)
  t = tf.constant(i)
Traceback (most recent call last):

TypeError: ...
 tf.constant will always create CPU (host) tensors. In order to create tensors on other devices, use tf.identity. (If the value is an eager Tensor, however, the tensor will be returned unmodified as mentioned above.) Related Ops:
tf.convert_to_tensor is similar but:  It has no shape argument. Symbolic tensors are allowed to pass through.

with tf.compat.v1.Graph().as_default():
  i = tf.compat.v1.placeholder(shape=[None, None], dtype=tf.float32)
  t = tf.convert_to_tensor(i)

tf.fill: differs in a few ways:
tf.constant supports arbitrary constants, not just uniform scalar Tensors like tf.fill.
tf.fill creates an Op in the graph that is expanded at runtime, so it can efficiently represent large tensors. Since tf.fill does not embed the value, it can produce dynamically sized outputs.

 Args
  value   A constant value (or list) of output type dtype.
  dtype   The type of the elements of the resulting tensor.
  shape   Optional dimensions of resulting tensor.
  name   Optional name for the tensor.

 Returns   A Constant Tensor.

 Raises
  TypeError   if shape is incorrectly specified or unsupported.
  ValueError   if called on a symbolic tensor.


tf.constant_initializer Initializer that generates tensors with constant values.
tf.constant_initializer(
    value=0
)
 Initializers allow you to pre-specify an initialization strategy, encoded in the Initializer object, without knowing the shape and dtype of the variable being initialized. tf.constant_initializer returns an object which when called returns a tensor populated with the value specified in the constructor. This value must be convertible to the requested dtype. The argument value can be a scalar constant value, or a list of values. Scalars broadcast to whichever shape is requested from the initializer. If value is a list, then the length of the list must be equal to the number of elements implied by the desired shape of the tensor. If the total number of elements in value is not equal to the number of elements required by the tensor shape, the initializer will raise a TypeError. Examples:
def make_variables(k, initializer):
  return (tf.Variable(initializer(shape=[k], dtype=tf.float32)),
          tf.Variable(initializer(shape=[k, k], dtype=tf.float32)))
v1, v2 = make_variables(3, tf.constant_initializer(2.))
v1
<tf.Variable ... shape=(3,) ... numpy=array([2., 2., 2.], dtype=float32)>
v2
<tf.Variable ... shape=(3, 3) ... numpy=
array([[2., 2., 2.],
       [2., 2., 2.],
       [2., 2., 2.]], dtype=float32)>
make_variables(4, tf.random_uniform_initializer(minval=-1., maxval=1.))
(<tf.Variable...shape=(4,) dtype=float32...>, <tf.Variable...shape=(4, 4) ...

value = [0, 1, 2, 3, 4, 5, 6, 7]
init = tf.constant_initializer(value)
# Fitting shape
tf.Variable(init(shape=[2, 4], dtype=tf.float32))
<tf.Variable ...
array([[0., 1., 2., 3.],
       [4., 5., 6., 7.]], dtype=float32)>
# Larger shape
tf.Variable(init(shape=[3, 4], dtype=tf.float32))
Traceback (most recent call last):

TypeError: ...value has 8 elements, shape is (3, 4) with 12 elements...
# Smaller shape
tf.Variable(init(shape=[2, 3], dtype=tf.float32))
Traceback (most recent call last):

TypeError: ...value has 8 elements, shape is (2, 3) with 6 elements...

 Args
  value   A Python scalar, list or tuple of values, or a N-dimensional numpy array. All elements of the initialized variable will be set to the corresponding value in the value argument.

 Raises
  TypeError   If the input value is not one of the expected types.    Methods from_config View source
@classmethod
from_config(
    config
)
 Instantiates an initializer from a configuration dictionary. Example: initializer = RandomUniform(-1, 1)
config = initializer.get_config()
initializer = RandomUniform.from_config(config)

 Args
  config   A Python dictionary. It will typically be the output of get_config.

 Returns   An Initializer instance.
 get_config View source
get_config()
 Returns the configuration of the initializer as a JSON-serializable dict.

 Returns   A JSON-serializable Python dict.
 __call__ View source
__call__(
    shape, dtype=None, **kwargs
)
 Returns a tensor object initialized as specified by the initializer.

 Args
  shape   Shape of the tensor.
  dtype   Optional dtype of the tensor. If not provided the dtype of the tensor created will be the type of the inital value.
  **kwargs   Additional keyword arguments.

 Raises
  TypeError   If the initializer cannot create a tensor of the requested dtype.


tf.control_dependencies     View source on GitHub    Wrapper for Graph.control_dependencies() using the default graph.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.control_dependencies
tf.control_dependencies(
    control_inputs
)
 See tf.Graph.control_dependencies for more details.
Note: In TensorFlow 2 with eager and/or Autograph, you should not require this method, as code executes in the expected order. Only use tf.control_dependencies when working with v1-style code or in a graph context such as inside Dataset.map.
 When eager execution is enabled, any callable object in the control_inputs list will be called.

 Args
  control_inputs   A list of Operation or Tensor objects which must be executed or computed before running the operations defined in the context. Can also be None to clear the control dependencies. If eager execution is enabled, any callable object in the control_inputs list will be called.

 Returns   A context manager that specifies control dependencies for all operations constructed within the context.


tf.convert_to_tensor     View source on GitHub    Converts the given value to a Tensor.
tf.convert_to_tensor(
    value, dtype=None, dtype_hint=None, name=None
)
 This function converts Python objects of various types to Tensor objects. It accepts Tensor objects, numpy arrays, Python lists, and Python scalars. For example:
import numpy as np
def my_func(arg):
  arg = tf.convert_to_tensor(arg, dtype=tf.float32)
  return arg

# The following calls are equivalent.

value_1 = my_func(tf.constant([[1.0, 2.0], [3.0, 4.0]]))
print(value_1)
tf.Tensor(
  [[1. 2.]
   [3. 4.]], shape=(2, 2), dtype=float32)
value_2 = my_func([[1.0, 2.0], [3.0, 4.0]])
print(value_2)
tf.Tensor(
  [[1. 2.]
   [3. 4.]], shape=(2, 2), dtype=float32)
value_3 = my_func(np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32))
print(value_3)
tf.Tensor(
  [[1. 2.]
   [3. 4.]], shape=(2, 2), dtype=float32)
 This function can be useful when composing a new operation in Python (such as my_func in the example above). All standard Python op constructors apply this function to each of their Tensor-valued inputs, which allows those ops to accept numpy arrays, Python lists, and scalars in addition to Tensor objects.
Note: This function diverges from default Numpy behavior for float and string types when None is present in a Python list or scalar. Rather than silently converting None values, an error will be thrown.

 Args
  value   An object whose type has a registered Tensor conversion function.
  dtype   Optional element type for the returned tensor. If missing, the type is inferred from the type of value.
  dtype_hint   Optional element type for the returned tensor, used when dtype is None. In some cases, a caller may not have a dtype in mind when converting to a tensor, so dtype_hint can be used as a soft preference. If the conversion to dtype_hint is not possible, this argument has no effect.
  name   Optional name to use if a new Tensor is created.

 Returns   A Tensor based on value.

 Raises
  TypeError   If no conversion function is registered for value to dtype.
  RuntimeError   If a registered conversion function returns an invalid value.
  ValueError   If the value is a tensor not of given dtype in graph mode.


tf.CriticalSection     View source on GitHub    Critical section.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.CriticalSection
tf.CriticalSection(
    name=None, shared_name=None, critical_section_def=None, import_scope=None
)
 A CriticalSection object is a resource in the graph which executes subgraphs in serial order. A common example of a subgraph one may wish to run exclusively is the one given by the following function: v = resource_variable_ops.ResourceVariable(0.0, name="v")

def count():
  value = v.read_value()
  with tf.control_dependencies([value]):
    with tf.control_dependencies([v.assign_add(1)]):
      return tf.identity(value)
 Here, a snapshot of v is captured in value; and then v is updated. The snapshot value is returned. If multiple workers or threads all execute count in parallel, there is no guarantee that access to the variable v is atomic at any point within any thread's calculation of count. In fact, even implementing an atomic counter that guarantees that the user will see each value 0, 1, ..., is currently impossible. The solution is to ensure any access to the underlying resource v is only processed through a critical section: cs = CriticalSection()
f1 = cs.execute(count)
f2 = cs.execute(count)
output = f1 + f2
session.run(output)
 The functions f1 and f2 will be executed serially, and updates to v will be atomic. NOTES All resource objects, including the critical section and any captured variables of functions executed on that critical section, will be colocated to the same device (host and cpu/gpu). When using multiple critical sections on the same resources, there is no guarantee of exclusive access to those resources. This behavior is disallowed by default (but see the kwarg exclusive_resource_access). For example, running the same function in two separate critical sections will not ensure serial execution: v = tf.compat.v1.get_variable("v", initializer=0.0, use_resource=True)
def accumulate(up):
  x = v.read_value()
  with tf.control_dependencies([x]):
    with tf.control_dependencies([v.assign_add(up)]):
      return tf.identity(x)
ex1 = CriticalSection().execute(
  accumulate, 1.0, exclusive_resource_access=False)
ex2 = CriticalSection().execute(
  accumulate, 1.0, exclusive_resource_access=False)
bad_sum = ex1 + ex2
sess.run(v.initializer)
sess.run(bad_sum)  # May return 0.0

 Attributes
  name
   Methods execute View source
execute(
    fn, exclusive_resource_access=True, name=None
)
 Execute function fn() inside the critical section. fn should not accept any arguments. To add extra arguments to when calling fn in the critical section, create a lambda: critical_section.execute(lambda: fn(*my_args, **my_kwargs))

 Args
  fn   The function to execute. Must return at least one tensor.
  exclusive_resource_access   Whether the resources required by fn should be exclusive to this CriticalSection. Default: True. You may want to set this to False if you will be accessing a resource in read-only mode in two different CriticalSections.
  name   The name to use when creating the execute operation.

 Returns   The tensors returned from fn().

 Raises
  ValueError   If fn attempts to lock this CriticalSection in any nested or lazy way that may cause a deadlock.
  ValueError   If exclusive_resource_access == True and another CriticalSection has an execution requesting the same resources as fn. Note, even ifexclusive_resource_accessisTrue, if another execution in anotherCriticalSectionwas created withoutexclusive_resource_access=True, aValueError` will be raised.


tf.custom_gradient     View source on GitHub    Decorator to define a function with a custom gradient.  View aliases  Compat aliases for migration
See Migration guide for more details. tf.compat.v1.custom_gradient
tf.custom_gradient(
    f=None
)
 This decorator allows fine grained control over the gradients of a sequence for operations. This may be useful for multiple reasons, including providing a more efficient or numerically stable gradient for a sequence of operations. For example, consider the following function that commonly occurs in the computation of cross entropy and log likelihoods: def log1pexp(x):
  return tf.math.log(1 + tf.exp(x))
 Due to numerical instability, the gradient of this function evaluated at x=100 is NaN. For example: x = tf.constant(100.)
y = log1pexp(x)
dy = tf.gradients(y, x) # Will be NaN when evaluated.
 The gradient expression can be analytically simplified to provide numerical stability: @tf.custom_gradient
def log1pexp(x):
  e = tf.exp(x)
  def grad(dy):
    return dy * (1 - 1 / (1 + e))
  return tf.math.log(1 + e), grad
 With this definition, the gradient at x=100 will be correctly evaluated as 1.0. The variable dy is defined as the upstream gradient. i.e. the gradient from all the layers or functions originating from this layer. By chain rule we know that dy/dx = dy/x_0 * dx_0/dx_1 * ... * dx_i/dx_i+1 * ... * dx_n/dx In this case the gradient of our current function defined as dx_i/dx_i+1 = (1 - 1 / (1 + e)). The upstream gradient dy would be dx_i+1/dx_i+2 * dx_i+2/dx_i+3 * ... * dx_n/dx. The upstream gradient multiplied by the current gradient is then passed downstream. In case the function takes multiple variables as input, the grad function must also return the same number of variables. We take the function z = x * y as an example.
@tf.custom_gradient
def bar(x, y):
  def grad(upstream):
    dz_dx = y
    dz_dy = x
    return upstream * dz_dx, upstream * dz_dy
  z = x * y
  return z, grad
x = tf.constant(2.0, dtype=tf.float32)
y = tf.constant(3.0, dtype=tf.float32)
with tf.GradientTape(persistent=True) as tape:
  tape.watch(x)
  tape.watch(y)
  z = bar(x, y)
z
<tf.Tensor: shape=(), dtype=float32, numpy=6.0>
tape.gradient(z, x)
<tf.Tensor: shape=(), dtype=float32, numpy=3.0>
tape.gradient(z, y)
<tf.Tensor: shape=(), dtype=float32, numpy=2.0>
 Nesting custom gradients can lead to unintuitive results. The default behavior does not correspond to n-th order derivatives. For example @tf.custom_gradient
def op(x):
  y = op1(x)
  @tf.custom_gradient
  def grad_fn(dy):
    gdy = op2(x, y, dy)
    def grad_grad_fn(ddy):  # Not the 2nd order gradient of op w.r.t. x.
      return op3(x, y, dy, ddy)
    return gdy, grad_grad_fn
  return y, grad_fn
 The function grad_grad_fn will be calculating the first order gradient of grad_fn with respect to dy, which is used to generate forward-mode gradient graphs from backward-mode gradient graphs, but is not the same as the second order gradient of op with respect to x. Instead, wrap nested @tf.custom_gradients in another function: @tf.custom_gradient
def op_with_fused_backprop(x):
  y, x_grad = fused_op(x)
  def first_order_gradient(dy):
    @tf.custom_gradient
    def first_order_custom(unused_x):
      def second_order_and_transpose(ddy):
        return second_order_for_x(...), gradient_wrt_dy(...)
      return x_grad, second_order_and_transpose
    return dy * first_order_custom(x)
  return y, first_order_gradient
 Additional arguments to the inner @tf.custom_gradient-decorated function control the expected return values of the innermost function. See also tf.RegisterGradient which registers a gradient function for a primitive TensorFlow operation. tf.custom_gradient on the other hand allows for fine grained control over the gradient computation of a sequence of operations. Note that if the decorated function uses Variables, the enclosing variable scope must be using ResourceVariables.

 Args
  f   function f(*x) that returns a tuple (y, grad_fn) where:
x is a sequence of (nested structures of) Tensor inputs to the function.
y is a (nested structure of) Tensor outputs of applying TensorFlow operations in f to x.
grad_fn is a function with the signature g(*grad_ys) which returns a list of Tensors the same size as (flattened) x - the derivatives of Tensors in y with respect to the Tensors in x. grad_ys is a sequence of Tensors the same size as (flattened) y holding the initial value gradients for each Tensor in y.  In a pure mathematical sense, a vector-argument vector-valued function f's derivatives should be its Jacobian matrix J. Here we are expressing the Jacobian J as a function grad_fn which defines how J will transform a vector grad_ys when left-multiplied with it (grad_ys * J, the vector-Jacobian product, or VJP). This functional representation of a matrix is convenient to use for chain-rule calculation (in e.g. the back-propagation algorithm). If f uses Variables (that are not part of the inputs), i.e. through get_variable, then grad_fn should have signature g(*grad_ys, variables=None), where variables is a list of the Variables, and return a 2-tuple (grad_xs, grad_vars), where grad_xs is the same as above, and grad_vars is a list<Tensor> with the derivatives of Tensors in y with respect to the variables (that is, grad_vars has one Tensor per variable in variables).

 Returns   A function h(x) which returns the same value as f(x)[0] and whose gradient (as calculated by tf.gradients) is determined by f(x)[1].


Module: tf.data tf.data.Dataset API for input pipelines. See Importing Data for an overview. Modules experimental module: Experimental API for building input pipelines. Classes class Dataset: Represents a potentially large set of elements. class DatasetSpec: Type specification for tf.data.Dataset. class FixedLengthRecordDataset: A Dataset of fixed-length records from one or more binary files. class Iterator: Represents an iterator of a tf.data.Dataset. class IteratorSpec: Type specification for tf.data.Iterator. class Options: Represents options for tf.data.Dataset. class TFRecordDataset: A Dataset comprising records from one or more TFRecord files. class TextLineDataset: A Dataset comprising lines from one or more text files.

 Other Members
  AUTOTUNE   -1
  INFINITE_CARDINALITY   -1
  UNKNOWN_CARDINALITY   -2