Obtain the mean of tensor on different GPUs.
(tensor)
| 2 | |
| 3 | |
| 4 | def reduce_mean(tensor): |
| 5 | """"Obtain the mean of tensor on different GPUs.""" |
| 6 | if not (dist.is_available() and dist.is_initialized()): |
| 7 | return tensor |
| 8 | tensor = tensor.clone() |
| 9 | dist.all_reduce(tensor.div_(dist.get_world_size()), op=dist.ReduceOp.SUM) |
| 10 | return tensor |
no test coverage detected