tf.distribute.CrossDeviceOps

Base class for cross-device reduction and broadcasting algorithms.

The main purpose of this class is to be passed to tf.distribute.MirroredStrategy in order to choose among different cross device communication implementations. Prefer using the methods of tf.distribute.Strategy instead of the ones of this class.

Implementations:

Methods

batch_reduce

View source

Reduce values to destinations in batches.

See tf.distribute.StrategyExtended.batch_reduce_to. This can only be called in the cross-replica context.

Args
reduce_opa tf.distribute.ReduceOp specifying how values should be combined.
value_destination_pairsa sequence of (value, destinations) pairs. See tf.distribute.CrossDeviceOps.reduce for descriptions.
optionsa tf.distribute.experimental.CommunicationOptions. See tf.distribute.experimental.CommunicationOptions for details.

Returns
A list of tf.Tensor or tf.distribute.DistributedValues, one per pair in value_destination_pairs.

Raises
ValueErrorif value_destination_pairs is not an iterable of tuples of tf.distribute.DistributedValues and destinations.

batch_reduce_implementation

View source

Implementation of batch_reduce.

Overriding this method is useful for subclass implementers.

Args
reduce_opa tf.distribute.ReduceOp specifying how values should be combined.
value_destination_pairsa sequence of (value, destinations) pairs. See reduce for descriptions.
optionsa tf.distribute.experimental.CommunicationOptions. See tf.distribute.experimental.CommunicationOptions for details.

Returns
A list of tf.Tensor or tf.distribute.DistributedValues, one per pair in value_destination_pairs.

Raises
ValueErrorif value_destination_pairs is not an iterable of tuples of tf.distribute.DistributedValues and destinations.

broadcast

View source

Broadcast tensor to destinations.

This can only be called in the cross-replica context.

Args
tensora tf.Tensor like object. The value to broadcast.
destinationsa tf.distribute.DistributedValues, a tf.Variable, a tf.Tensor alike object, or a device string. It specifies the devices to broadcast to. Note that if it's a tf.Variable, the value is broadcasted to the devices of that variable, this method doesn't update the variable.

Returns
A tf.Tensor or tf.distribute.DistributedValues.

broadcast_implementation

View source

Implementation of broadcast.

Args
tensora tf.Tensor like object. The value to broadcast.
destinationsa tf.distribute.DistributedValues, a tf.Variable, a tf.Tensor alike object, or a device string. It specifies the devices to broadcast to. destinations. Note that if it's a tf.Variable, the value is broadcasted to the devices of that variable, this method doesn't update the variable.

Returns
A tf.Tensor or tf.distribute.DistributedValues.

reduce

View source

Reduce per_replica_value to destinations.

See tf.distribute.StrategyExtended.reduce_to. This can only be called in the cross-replica context.

Args
reduce_opa tf.distribute.ReduceOp specifying how values should be combined.
per_replica_valuea tf.distribute.DistributedValues, or a tf.Tensor like object.
destinationsa tf.distribute.DistributedValues, a tf.Variable, a tf.Tensor alike object, or a device string. It specifies the devices to reduce to. To perform an all-reduce, pass the same to value and destinations. Note that if it's a tf.Variable, the value is reduced to the devices of that variable, and this method doesn't update the variable.
optionsa tf.distribute.experimental.CommunicationOptions. See tf.distribute.experimental.CommunicationOptions for details.

Returns
A tf.Tensor or tf.distribute.DistributedValues.

Raises
ValueErrorif per_replica_value can't be converted to a tf.distribute.DistributedValues or if destinations is not a string, tf.Variable or tf.distribute.DistributedValues.

reduce_implementation

View source

Implementation of reduce.

Overriding this method is useful for subclass implementers.

Args
reduce_opa tf.distribute.ReduceOp specifying how values should be combined.
per_replica_valuea tf.distribute.DistributedValues, or a tf.Tensor like object.
destinationsa tf.distribute.DistributedValues, a tf.Variable, a tf.Tensor alike object, or a device string. It specifies the devices to reduce to. To perform an all-reduce, pass the same to value and destinations. Note that if it's a tf.Variable, the value is reduced to the devices of that variable, this method doesn't update the variable.
optionsa tf.distribute.experimental.CommunicationOptions. See tf.distribute.experimental.CommunicationOptions for details.

Returns
A tf.Tensor or tf.distribute.DistributedValues.

Raises
ValueErrorif per_replica_value can't be converted to a tf.distribute.DistributedValues or if destinations is not a string, tf.Variable or tf.distribute.DistributedValues.