(tensor)
return replica_ctx.all_reduce('sum', padded_tensor)
Aggregate a tensor across distributed replicas.

  If not running in a distributed context, this just returns the input tensor.

  Args:
    tensor: tensor aggregate.

  Returns:
    output: A single tensor with all values across different replicas
      concatenated along the first axis.  The output is in order of gpu index.
Aggregate a tensor across distributed replicas.
Aggregate a tensor across distributed replicas .
def aggregate(tensor):
  """Aggregate a tensor across distributed replicas.

  If not running in a distributed context, this just returns the input tensor.

  Args:
    tensor: tensor aggregate.

  Returns:
    output: A single tensor with all values across different replicas
      concatenated along the first axis.  The output is in order of gpu index.
  """

  replica_ctx = tf.distribute.get_replica_context()
  if not replica_ctx:
    return tensor
  num = tf.shape(tensor)[0:1]
  padded_num = _pad(num, replica_ctx.num_replicas_in_sync,
                    replica_ctx.replica_id_in_sync_group)
  all_num = replica_ctx.all_reduce('sum', padded_num)
  index_in_output = tf.gather(
      tf.cumsum(tf.concat([[0], all_num], axis=0)),
      replica_ctx.replica_id_in_sync_group)
  total_num = tf.reduce_sum(all_num)
  padded_tensor = _pad(tensor, total_num, index_in_output)
  return replica_ctx.all_reduce('sum', padded_tensor)
def aggregate ( tensor ) : replica_ctx = tf . distribute . get_replica_context ( ) if not replica_ctx : return tensor num = tf . shape ( tensor ) [ 0 : 1 ] padded_num = _pad ( num , replica_ctx . num_replicas_in_sync , replica_ctx . replica_id_in_sync_group ) all_num = replica_ctx . all_reduce ( 'sum' , padded_num ) index_in_output = tf . gather ( tf . cumsum ( tf . concat ( [ [ 0 ] , all_num ] , axis = 0 ) ) , replica_ctx . replica_id_in_sync_group ) total_num = tf . reduce_sum ( all_num ) padded_tensor = _pad ( tensor , total_num , index_in_output ) return replica_ctx . all_reduce ( 'sum' , padded_tensor )