def _get_best_rank(metric, func=_torch.argmin) -> int:
    """
    Get best rank of a particular metric according to a specified function.
    """
    if _dist.is_available() and _dist.is_initialized():
        distributed_world_size = _dist.get_world_size()
        if distributed_world_size > 1:
            tensor_list = [_torch.zeros_like(metric) for _ in range(distributed_world_size)]
            _dist.all_gather(tensor_list, metric)
            bcast_rank = func(_torch.Tensor(tensor_list))

            return bcast_rank

    return None

    Get best rank of a particular metric according to a specified function.
    
coremltools/optimize/torch/palettization/_partitioner.py