def METHOD_NAME(rank, *msgs):
    """
    Print to a log file of the given rank
    This is useful for debugging hanging in sync processes. Here is a possible workflow:
    1. Enable the force debug in say partitioning and zero3 files
    2. Override the usual versions of print_rank_0 in those files with ::
        def print_rank_0(message, debug=False, force=False):
            rank = deepspeed.comm.get_rank()
            log_rank_file(rank, message)
    3. run the program
    4. fix up the expected differences, e.g. different cuda numbers ::
        perl -pi -e 's|cuda:1|cuda:0|' log_rank_*
    5. now diff and see where names and ids diverge - you will find where the gpus don't do the same
    work (e.g. when some layers get conditionally skipped on one gpu but not all)
        diff -u log_rank_0.txt log_rank_1.txt | less
    """
    global fh
    if fh is None:
        fh = open(f"log_rank_{rank}.txt", "w")
    for m in msgs:
        fh.write(f"{m}\n")
    fh.flush()