@@ -42,19 +42,14 @@ def fit(obj, tf_iter=0, newton_iter=0, batch_sz=None, newton_eager=True):
4242 for epoch in t :
4343 loss_value = train_op_fn (n_batches , obj )
4444 # Description will be displayed on the left
45- t .set_description ('Adam epoch %i' % (epoch + 1 ))
45+ t .set_description ('Adam epoch %i' % (epoch + 1 ))
4646 # Postfix will be displayed on the right,
4747 # formatted automatically based on argument's datatype
4848 if epoch % 10 == 0 :
49- elapsed = time .time () - start_time
5049 t .set_postfix (loss = loss_value .numpy ())
51- #
52- # print('It: %d, Time: %.2f, loss: %.6f' % (epoch, elapsed, loss_value.numpy()))
53- # tf.print(f"total loss: {loss_value}")
54- start_time = time .time ()
5550
56- # tf.profiler.experimental.stop()
5751
52+ # tf.profiler.experimental.stop()
5853
5954 # tf.profiler.experimental.start('../cache/tblogdir1')
6055 if newton_iter > 0 :
@@ -97,7 +92,7 @@ def lbfgs_op(func, init_params, newton_iter):
9792
9893
9994def train_op_inner (obj ):
100- @tf .function
95+ @tf .function ()
10196 def apply_grads (n_batches , obj = obj ):
10297 for _ in range (n_batches ):
10398 # unstack = tf.unstack(obj.u_model.trainable_variables, axis = 2)
@@ -126,7 +121,6 @@ def apply_grads(n_batches, obj=obj):
126121 return apply_grads
127122
128123
129-
130124def fit_dist (obj , tf_iter , newton_iter , batch_sz = None , newton_eager = True ):
131125 def train_epoch (dataset , STEPS ):
132126 total_loss = 0.0
@@ -180,17 +174,17 @@ def dist_loop(obj, STEPS):
180174 return train_loss
181175
182176 def train_loop (obj , tf_iter , STEPS ):
183-
177+ print_screen ( obj )
184178 start_time = time .time ()
185- for epoch in range (tf_iter ):
186- loss = dist_loop ( obj , STEPS )
187-
188- if epoch % 100 == 0 :
189- elapsed = time . time () - start_time
190- template = ( "Epoch {}, Time: {}, Loss: {}" )
191- print ( template . format ( epoch , elapsed , loss ))
192- # print('It: %d, Time: %.2f, loss: %.9f' % (epoch, elapsed, tf.get_static_value(loss)))
193- start_time = time .time ()
179+ with trange (tf_iter ) as t :
180+ for epoch in t :
181+ loss = dist_loop ( obj , STEPS )
182+ t . set_description ( 'Adam epoch %i' % ( epoch + 1 ))
183+ if epoch % 10 == 0 :
184+ elapsed = time . time () - start_time
185+ t . set_postfix ( loss = loss . numpy ( ))
186+ # print('It: %d, Time: %.2f, loss: %.9f' % (epoch, elapsed, tf.get_static_value(loss)))
187+ start_time = time .time ()
194188
195189 print ("starting Adam training" )
196190 STEPS = np .max ((obj .n_batches // obj .strategy .num_replicas_in_sync , 1 ))
0 commit comments