def log_single_rank(logger: logging.Logger, *args, rank=0, **kwargs):
    """If torch distributed is initialized, log only on rank

    Args:
        logger (logging.Logger): The logger to write the logs

        rank (int, optional): The rank to write on. Defaults to 0.
    """
    if torch.distributed.is_initialized():
        if torch.distributed.get_rank() == rank:
            logger.log(*args, **kwargs)
    else:
        logger.log(*args, **kwargs)
If torch distributed is initialized, log only on rank

    Args:
        logger (logging.Logger): The logger to write the logs

        rank (int, optional): The rank to write on. Defaults to 0.
    
finetune/core/datasets/utils.py