def reduce_mean(tensor):
    """"Obtain the mean of tensor on different GPUs."""
    if not (dist.get_world_size() and dist.is_initialized()):
        return tensor
    tensor = tensor.clone()
    dist.all_reduce(
        tensor.divide(
            paddle.to_tensor(
                dist.get_world_size(), dtype='float32')),
        op=dist.ReduceOp.SUM)
    return tensor
"Obtain the mean of tensor on different GPUs.
ppdet/modeling/heads/petr_head.py