'Compute loss for all shards.'

def loss_sharded(self, sharded_top_out, sharded_targets, data_parallelism):

    (sharded_loss_num, sharded_loss_den) = data_parallelism(self.loss, sharded_top_out, sharded_targets)
    loss = (tf.add_n(sharded_loss_num) / tf.maximum(1.0, tf.add_n(sharded_loss_den)))
    return loss
