Spaces:
Running
on
Zero
Running
on
Zero
File size: 370 Bytes
a249588 |
1 2 3 4 5 6 7 8 9 10 11 12 |
# Copyright (c) OpenMMLab. All rights reserved.
import torch.distributed as dist
def reduce_mean(tensor):
""""Obtain the mean of tensor on different GPUs."""
if not (dist.is_available() and dist.is_initialized()):
return tensor
tensor = tensor.clone()
dist.all_reduce(tensor.div_(dist.get_world_size()), op=dist.ReduceOp.SUM)
return tensor
|