def _reduce(input_):
    """All-reduce the the input tensor across model parallel group."""

    # Bypass the function if we are using only 1 GPU.
    if get_model_parallel_world_size()==1:
        return input_

    # All-reduce.
    torch.distributed.all_reduce(input_, group=get_model_parallel_group())

    return input_
All-reduce the the input tensor across model parallel group.
megatron_lm/megatron/mpu/mappings.py