-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathlog_utils.py
More file actions
33 lines (28 loc) · 890 Bytes
/
log_utils.py
File metadata and controls
33 lines (28 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
import os
import sys
import dllogger
import horovod.mxnet as hvd
def format_step(step):
if isinstance(step, str):
return step
s = ""
if len(step) > 0:
s += "Epoch: {} ".format(step[0])
if len(step) > 1:
s += "Iteration: {} ".format(step[1])
if len(step) > 2:
s += "Validation Iteration: {} ".format(step[2])
if len(step) == 0:
s = "Summary:"
return s
def setup_logging(args):
logging.basicConfig(level=logging.DEBUG, format='{asctime}:{levelname}: {message}', style='{')
if hvd.rank() == 0:
dllogger.init(backends=[
dllogger.StdOutBackend(dllogger.Verbosity.DEFAULT, step_format=format_step),
dllogger.JSONStreamBackend(
dllogger.Verbosity.VERBOSE, os.path.join(args.workspace, args.dllogger_log)),
])
else:
dllogger.init([])