Skip to content

dp_optimizer_keras - get_config() returns l2_norm_clip, noise_multiplier, num_microbatches #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tensorflow_privacy/privacy/optimizers/dp_optimizer_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
l2_norm_clip, l2_norm_clip * noise_multiplier)
self._global_state = None
self._was_dp_gradients_called = False
self._base_optimizer_class = cls

def _compute_gradients(self, loss, var_list, grad_loss=None, tape=None):
"""DP version of superclass method."""
Expand Down Expand Up @@ -169,6 +170,23 @@ def apply_gradients(self, grads_and_vars, global_step=None, name=None):
return super(DPOptimizerClass,
self).apply_gradients(grads_and_vars, global_step, name)

def get_config(self):
"""Creates configuration for Keras serialization.
This method will be called when Keras creates model checkpoints
and is necessary so that deserialization can be performed.
Returns:
A dict object storing arguments to be passed to the __init__ method
upon deserialization.
"""

config = self._base_optimizer_class.get_config(self)
config.update({
'l2_norm_clip': self._l2_norm_clip,
'noise_multiplier': self._noise_multiplier,
'num_microbatches': self._num_microbatches})

return config

return DPOptimizerClass


Expand Down