def METHOD_NAME(params):
    buffer = self.buffer
    nonzero_buffer = False
    if len(params) > 1:
        offset = 0
        for p in params:
            sz = p.numel()
            if p.grad is not None:
                buffer[offset : offset + sz].copy_(p.grad.data.view(-1))
                nonzero_buffer = True
            else:
                buffer[offset : offset + sz].zero_()
            offset += sz
    else:
        # we only have a single grad to all-reduce
        p = params[0]
        if p.grad is not None:
            buffer = p.grad.data
            nonzero_buffer = True
        elif p.numel() <= self.buffer.numel():
            buffer = buffer[: p.numel()]
            buffer.zero_()
        else:
            buffer = torch.zeros_like(p)
    if nonzero_buffer:
        buffer.div_(self.world_size)
    utils.all_reduce(buffer, self.process_group)
    # copy all-reduced grads back into their original place
    offset = 0
    for p in params:
        sz = p.numel()
        if p.grad is not None:
            p.grad.data.copy_(buffer[offset : offset + sz].view_as(p))
        else:
            p.grad = buffer[offset : offset + sz].view_as(p).clone()
        offset += sz