提交 7d478445 编写于 作者: Z ZhidanLiu

add a construct of clip_mech and noise_mech, when noise_mech is adaptive clip_mech must be none

上级 01d40e16
...@@ -143,7 +143,13 @@ class DPModel(Model): ...@@ -143,7 +143,13 @@ class DPModel(Model):
LOGGER.error(TAG, msg) LOGGER.error(TAG, msg)
raise ValueError(msg) raise ValueError(msg)
self._noise_mech = noise_mech self._noise_mech = noise_mech
if clip_mech is not None: if noise_mech is not None:
if 'Ada' in noise_mech.__class__.__name__ and clip_mech is not None:
msg = 'When noise_mech is Adaptive, clip_mech must be None.'
LOGGER.error(TAG, msg)
raise ValueError(msg)
if clip_mech is None or isinstance(clip_mech, Cell):
self._clip_mech = clip_mech self._clip_mech = clip_mech
super(DPModel, self).__init__(**kwargs) super(DPModel, self).__init__(**kwargs)
......
...@@ -134,11 +134,7 @@ def test_dp_model_with_graph_mode_ada_gaussian(): ...@@ -134,11 +134,7 @@ def test_dp_model_with_graph_mode_ada_gaussian():
noise_mech = NoiseMechanismsFactory().create('AdaGaussian', noise_mech = NoiseMechanismsFactory().create('AdaGaussian',
norm_bound=norm_clip, norm_bound=norm_clip,
initial_noise_multiplier=initial_noise_multiplier) initial_noise_multiplier=initial_noise_multiplier)
clip_mech = ClipMechanismsFactory().create('Gaussian', clip_mech = None
decay_policy='Linear',
learning_rate=0.01,
target_unclipped_quantile=0.9,
fraction_stddev=0.01)
net_opt = nn.Momentum(network.trainable_params(), learning_rate=0.1, net_opt = nn.Momentum(network.trainable_params(), learning_rate=0.1,
momentum=0.9) momentum=0.9)
model = DPModel(micro_batches=2, model = DPModel(micro_batches=2,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册