1818import time
1919import warnings
2020import numpy as np
21+ import logging
2122import paddle .fluid as fluid
2223
2324from paddlerec .core .utils import envs
2425from paddlerec .core .metric import Metric
2526
27+ logging .basicConfig (
28+ format = '%(asctime)s - %(levelname)s: %(message)s' , level = logging .INFO )
29+
2630__all__ = [
2731 "RunnerBase" , "SingleRunner" , "PSRunner" , "CollectiveRunner" , "PslibRunner"
2832]
@@ -140,8 +144,16 @@ def _executor_dataloader_train(self, model_dict, context):
140144
141145 metrics_varnames = []
142146 metrics_format = []
147+
148+ if context ["is_infer" ]:
149+ metrics_format .append ("\t [Infer]\t {}: {{}}" .format ("batch" ))
150+ else :
151+ metrics_format .append ("\t [Train]\t {}: {{}}" .format ("batch" ))
152+
153+ metrics_format .append ("{}: {{:.2f}}s" .format ("time_each_interval" ))
154+
143155 metrics_names = ["total_batch" ]
144- metrics_format . append ( "{}: {{}}" . format ( "batch" ))
156+
145157 for name , var in metrics .items ():
146158 metrics_names .append (name )
147159 metrics_varnames .append (var .name )
@@ -151,6 +163,7 @@ def _executor_dataloader_train(self, model_dict, context):
151163 reader = context ["model" ][model_dict ["name" ]]["model" ]._data_loader
152164 reader .start ()
153165 batch_id = 0
166+ begin_time = time .time ()
154167 scope = context ["model" ][model_name ]["scope" ]
155168 result = None
156169 with fluid .scope_guard (scope ):
@@ -160,16 +173,22 @@ def _executor_dataloader_train(self, model_dict, context):
160173 program = program ,
161174 fetch_list = metrics_varnames ,
162175 return_numpy = False )
163- metrics = [batch_id ]
164176
177+ metrics = [batch_id ]
165178 metrics_rets = [
166179 as_numpy (metrics_tensor )
167180 for metrics_tensor in metrics_tensors
168181 ]
169182 metrics .extend (metrics_rets )
170183
171184 if batch_id % fetch_period == 0 and batch_id != 0 :
172- print (metrics_format .format (* metrics ))
185+ end_time = time .time ()
186+ seconds = end_time - begin_time
187+ metrics_logging = metrics [:]
188+ metrics_logging = metrics .insert (1 , seconds )
189+ begin_time = end_time
190+
191+ logging .info (metrics_format .format (* metrics ))
173192 batch_id += 1
174193 except fluid .core .EOFException :
175194 reader .reset ()
0 commit comments