diff --git a/mindarmour/diff_privacy/train/model.py b/mindarmour/diff_privacy/train/model.py index dcd02b17165bfa64db09ddbc3aba4c3fbd7ec837..3243de53eaa17838c1089515ac9839b3231484bd 100644 --- a/mindarmour/diff_privacy/train/model.py +++ b/mindarmour/diff_privacy/train/model.py @@ -143,7 +143,13 @@ class DPModel(Model): LOGGER.error(TAG, msg) raise ValueError(msg) 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 super(DPModel, self).__init__(**kwargs) diff --git a/tests/ut/python/diff_privacy/test_model_train.py b/tests/ut/python/diff_privacy/test_model_train.py index 892913c45182a128bd59cccd3cf6aa2e71a81df0..6a4b716de3e58a9b7fea3731b30c6f7ff57c0e19 100644 --- a/tests/ut/python/diff_privacy/test_model_train.py +++ b/tests/ut/python/diff_privacy/test_model_train.py @@ -134,11 +134,7 @@ def test_dp_model_with_graph_mode_ada_gaussian(): noise_mech = NoiseMechanismsFactory().create('AdaGaussian', norm_bound=norm_clip, initial_noise_multiplier=initial_noise_multiplier) - clip_mech = ClipMechanismsFactory().create('Gaussian', - decay_policy='Linear', - learning_rate=0.01, - target_unclipped_quantile=0.9, - fraction_stddev=0.01) + clip_mech = None net_opt = nn.Momentum(network.trainable_params(), learning_rate=0.1, momentum=0.9) model = DPModel(micro_batches=2,