@@ -210,23 +210,25 @@ def apply_gradients(self, grads_and_vars, *args, **kwargs):
210210 with ModelPhase (ModelPhase .APPLY ):
211211 if not apply_opt :
212212 apply_fn = lambda : fn (self , grads_and_vars , * args , ** kwargs )
213- elif zero_enabled ():
214- apply_fn = lambda : apply_zero (self , fn , grads_and_vars ,
215- global_step , ga_iters ,
216- num_apply_group , name )
217213 elif ga_enabled ():
218214 apply_fn = lambda : apply_ga (self , fn , grads_and_vars ,
219215 global_step , ga_iters ,
220216 num_apply_group , name )
221- elif num_apply_group > 1 :
222- apply_fn = lambda : apply_grad_group (self , fn , grads_and_vars ,
223- num_apply_group ,
224- global_step , name = name )
225217 else :
226- apply_fn = lambda : fn (self , grads_and_vars , * args , ** kwargs )
218+ if zero_enabled ():
219+ apply_fn = lambda : apply_zero (self , fn , grads_and_vars ,
220+ global_step , ga_iters ,
221+ num_apply_group , name )
222+
223+ elif num_apply_group > 1 :
224+ apply_fn = lambda : apply_grad_group (self , fn , grads_and_vars ,
225+ num_apply_group ,
226+ global_step , name = name )
227+ else :
228+ apply_fn = lambda : fn (self , grads_and_vars , * args , ** kwargs )
227229
228- if apply_opt and amp_enabled () and Env .get ().config .amp .loss_scale == "dynamic" :
229- return amp_update (grads_and_vars , apply_fn , name )
230+ if amp_enabled () and Env .get ().config .amp .loss_scale == "dynamic" :
231+ return amp_update (grads_and_vars , apply_fn , name )
230232 return apply_fn ()
231233 return apply_gradients
232234
@@ -578,7 +580,8 @@ def restore(self, sess, save_path):
578580 # TODO(wangang.wa): This code will be removed after merging
579581 # variables for split strategy.
580582 if Graph .get ().first_constructor_rank == Env .get ().cluster .worker_index or \
581- any (taskgraph .strategy_context .split_strategy is not None for taskgraph in Graph .get ().taskgraphs ):
583+ any (taskgraph .strategy_context .split_strategy is not None for taskgraph in Graph .get ().taskgraphs ) or \
584+ not Graph .get ().need_parallel :
582585 with ModelPhase (ModelPhase .SAVE_AND_RESTORE ):
583586 ret = fn (self , sess , save_path )
584587 return ret
0 commit comments