File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
tensorflow_privacy/privacy/keras_models Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -231,16 +231,19 @@ def train_step(self, data):
231231 self ._num_microbatches ,
232232 )
233233 )
234- grads = gradient_clipping_utils .add_aggregate_noise (
235- self ,
236- clipped_grads ,
237- eff_num_microbatches ,
238- self ._l2_norm_clip ,
239- self ._noise_multiplier ,
240- )
234+ if self ._noise_multiplier > 0 :
235+ grads = gradient_clipping_utils .add_aggregate_noise (
236+ self ,
237+ clipped_grads ,
238+ eff_num_microbatches ,
239+ self ._l2_norm_clip ,
240+ self ._noise_multiplier ,
241+ )
242+ else :
243+ grads = clipped_grads
241244 output_metrics [privatized_loss_name ] = weighted_loss
242245 else :
243- logging .info ('Computing gradients using microbatching .' )
246+ logging .info ('Computing gradients using original clipping algorithm .' )
244247 # Computes per-example clipped gradients directly. This is called
245248 # if at least one of the layers cannot use the "fast" gradient clipping
246249 # algorithm.
You can’t perform that action at this time.
0 commit comments