File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 4
4
sys .path .append (os .path .join (now_dir ))
5
5
sys .path .append (os .path .join (now_dir , "train" ))
6
6
import utils
7
+ import datetime
7
8
8
9
hps = utils .get_hparams ()
9
10
os .environ ["CUDA_VISIBLE_DEVICES" ] = hps .gpus .replace ("-" , "," )
50
51
51
52
global_step = 0
52
53
54
+ class EpochRecorder :
55
+ def __init__ (self ):
56
+ self .last_time = ttime ()
57
+
58
+
59
+ def record (self ):
60
+ now_time = ttime ()
61
+ elapsed_time = now_time - self .last_time
62
+ self .last_time = now_time
63
+ elapsed_time_str = str (datetime .timedelta (seconds = elapsed_time ))
64
+ current_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
65
+ return f"[{ current_time } ] | ({ elapsed_time_str } )"
53
66
54
67
def main ():
55
68
# n_gpus = torch.cuda.device_count()
@@ -323,6 +336,7 @@ def train_and_evaluate(
323
336
data_iterator = enumerate (train_loader )
324
337
325
338
# Run steps
339
+ epoch_recorder = EpochRecorder ()
326
340
for batch_idx , info in data_iterator :
327
341
# Data
328
342
## Unpack
@@ -542,7 +556,7 @@ def train_and_evaluate(
542
556
)
543
557
544
558
if rank == 0 :
545
- logger .info ("====> Epoch: {}" .format (epoch ))
559
+ logger .info ("====> Epoch: {} {} " .format (epoch , epoch_recorder . record () ))
546
560
if epoch >= hps .total_epoch and rank == 0 :
547
561
logger .info ("Training is done. The program is closed." )
548
562
You can’t perform that action at this time.
0 commit comments