MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / printflock

Function printflock

deepspeed/utils/debug.py:65–94  ·  view source on GitHub ↗

For printing messages for all concurrent gpus w/o getting interleaved text. This is useful when debugging issues where multi-gpus don't sync. 1. Enable the force debug in say partitioning and zero3 files 2. Override the usual versions with :: def print_rank_0(message, de

(*msgs)

Source from the content-addressed store, hash-verified

63
64
65def printflock(*msgs):
66 """
67
68 For printing messages for all concurrent gpus w/o getting interleaved text.
69
70 This is useful when debugging issues where multi-gpus don't sync.
71
72 1. Enable the force debug in say partitioning and zero3 files
73 2. Override the usual versions with ::
74
75 def print_rank_0(message, debug=False, force=False):
76 rank = deepspeed.comm.get_rank()
77 printflock(f"[{rank}] {message}")
78 3. run the program and you get both logs non-interleaved
79
80 But this makes it very difficult to make sense of the output, so the ``log_rank_file`` helper
81 function might be more useful, as it's easier to send each log stream into a separate file and
82 then compare those.
83
84 """
85 global fcntl
86 if fcntl == None:
87 import fcntl
88
89 with open(__file__, "r") as fh:
90 fcntl.flock(fh, fcntl.LOCK_EX)
91 try:
92 print(*msgs)
93 finally:
94 fcntl.flock(fh, fcntl.LOCK_UN)
95
96
97fh = None

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected