def get_rank() -> int:
    """
    Returns the rank of the current worker.

    Returns:
        int: ``rank`` if torch.distributed is initialized, otherwise ``-1``
    """
    if _is_xla_distributed_initialized():
        return xm.get_ordinal()
    elif _is_torch_distributed_initialized():
        return dist.get_rank()
    else:
        return -1

    Returns the rank of the current worker.

    Returns:
        int: ``rank`` if torch.distributed is initialized, otherwise ``-1``
    
catalyst/utils/distributed.py