(inputs, group_size=None)
return tf.contrib.tpu.cross_replica_sum(inputs, group_assignment) / tf.cast(
      group_size, inputs.dtype)
Calculates the average value of inputs tensor across TPU replicas.
Calculates the average value of inputs tensor across TPU replicas.
Calculates the average value of inputs tensor across TPU replicas .
def cross_replica_mean(inputs, group_size=None):
  """Calculates the average value of inputs tensor across TPU replicas."""
  num_replicas = tpu_function.get_tpu_context().number_of_shards
  if not group_size:
    group_size = num_replicas
  if group_size == 1:
    return inputs
  if group_size != num_replicas:
    group_assignment = []
    assert num_replicas % group_size == 0
    for g in range(num_replicas // group_size):
      replica_ids = [g * group_size + i for i in range(group_size)]
      group_assignment.append(replica_ids)
  else:
    group_assignment = None
  return tf.contrib.tpu.cross_replica_sum(inputs, group_assignment) / tf.cast(
      group_size, inputs.dtype)
def cross_replica_mean ( inputs , group_size = None ) : num_replicas = tpu_function . get_tpu_context ( ) . number_of_shards if not group_size : group_size = num_replicas if group_size == 1 : return inputs if group_size != num_replicas : group_assignment = [ ] assert num_replicas % group_size == 0 for g in range ( num_replicas // group_size ) : replica_ids = [ g * group_size + i for i in range ( group_size ) ] group_assignment . append ( replica_ids ) else : group_assignment = None return tf . contrib . tpu . cross_replica_sum ( inputs , group_assignment ) / tf . cast ( group_size , inputs . dtype )