tf.distribute.InputContext

A class wrapping information needed by an input function.

This is a context class that is passed to the user's input function and contains information about the compute replicas and input pipelines. The number of compute replicas (in sync training) helps compute the local batch size from the desired global batch size for each replica. The input pipeline information can be used to return a different subset of the input in each replica (for e.g. shard the input pipeline, use a different input source etc).

num_input_pipelinesthe number of input pipelines in a cluster.
input_pipeline_idthe current input pipeline id, should be an int in [0,num_input_pipelines).
num_replicas_in_syncthe number of replicas that are in sync.

input_pipeline_idReturns the input pipeline ID.
num_input_pipelinesReturns the number of input pipelines.
num_replicas_in_syncReturns the number of compute replicas in sync.

Methods

get_per_replica_batch_size

View source

Returns the per-replica batch size.

Args
global_batch_sizethe global batch size which should be divisible by num_replicas_in_sync.

Returns
the per-replica batch size.

Raises
ValueErrorif global_batch_size not divisible by num_replicas_in_sync.