From 9649ab3d8d9fd45b9ae8228cb6ccd66bc12b4e27 Mon Sep 17 00:00:00 2001 From: ZhidanLiu Date: Tue, 23 Jun 2020 17:08:12 +0800 Subject: [PATCH] update default value --- example/mnist_demo/lenet5_config.py | 2 +- example/mnist_demo/lenet5_dp.py | 2 +- .../diff_privacy/mechanisms/mechanisms.py | 20 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/example/mnist_demo/lenet5_config.py b/example/mnist_demo/lenet5_config.py index 69e8efa..e9ac048 100644 --- a/example/mnist_demo/lenet5_config.py +++ b/example/mnist_demo/lenet5_config.py @@ -33,7 +33,7 @@ mnist_cfg = edict({ 'dataset_sink_mode': False, # whether deliver all training data to device one time 'micro_batches': 16, # the number of small batches split from an original batch 'norm_clip': 1.0, # the clip bound of the gradients of model's training parameters - 'initial_noise_multiplier': 0.2, # the initial multiplication coefficient of the noise added to training + 'initial_noise_multiplier': 1.5, # the initial multiplication coefficient of the noise added to training # parameters' gradients 'mechanisms': 'AdaGaussian', # the method of adding noise in gradients while training 'optimizer': 'Momentum' # the base optimizer used for Differential privacy training diff --git a/example/mnist_demo/lenet5_dp.py b/example/mnist_demo/lenet5_dp.py index c86bf1b..bf62fd3 100644 --- a/example/mnist_demo/lenet5_dp.py +++ b/example/mnist_demo/lenet5_dp.py @@ -87,7 +87,7 @@ def generate_mnist_dataset(data_path, batch_size=32, repeat_size=1, if __name__ == "__main__": # This configure can run both in pynative mode and graph mode - context.set_context(mode=context.PYNATIVE_MODE, device_target=cfg.device_target) + context.set_context(mode=context.GRAPH_MODE, device_target=cfg.device_target) network = LeNet5() net_loss = nn.SoftmaxCrossEntropyWithLogits(is_grad=False, sparse=True, reduction="mean") config_ck = CheckpointConfig(save_checkpoint_steps=cfg.save_checkpoint_steps, diff --git a/mindarmour/diff_privacy/mechanisms/mechanisms.py b/mindarmour/diff_privacy/mechanisms/mechanisms.py index cdcf3a5..d58724f 100644 --- a/mindarmour/diff_privacy/mechanisms/mechanisms.py +++ b/mindarmour/diff_privacy/mechanisms/mechanisms.py @@ -37,8 +37,8 @@ class MechanismsFactory: """ Args: policy(str): Noise generated strategy, could be 'Gaussian' or - 'AdaGaussian'. Noise would be decayed with 'AdaGaussian' mechanism while - be constant with 'Gaussian' mechanism. Default: 'AdaGaussian'. + 'AdaGaussian'. Noise would be decayed with 'AdaGaussian' mechanism + while be constant with 'Gaussian' mechanism. args(Union[float, str]): Parameters used for creating noise mechanisms. kwargs(Union[float, str]): Parameters used for creating noise @@ -74,7 +74,7 @@ class GaussianRandom(Mechanisms): Args: norm_bound(float): Clipping bound for the l2 norm of the gradients. - Default: 1.0. + Default: 0.5. initial_noise_multiplier(float): Ratio of the standard deviation of Gaussian noise divided by the norm_bound, which will be used to calculate privacy spent. Default: 1.5. @@ -86,14 +86,14 @@ class GaussianRandom(Mechanisms): Examples: >>> gradients = Tensor([0.2, 0.9], mstype.float32) - >>> norm_bound = 1.0 - >>> initial_noise_multiplier = 0.1 + >>> norm_bound = 0.5 + >>> initial_noise_multiplier = 1.5 >>> net = GaussianRandom(norm_bound, initial_noise_multiplier) >>> res = net(gradients) >>> print(res) """ - def __init__(self, norm_bound=1.0, initial_noise_multiplier=1.5, mean=0.0, seed=0): + def __init__(self, norm_bound=0.5, initial_noise_multiplier=1.5, mean=0.0, seed=0): super(GaussianRandom, self).__init__() self._norm_bound = check_value_positive('norm_bound', norm_bound) self._norm_bound = Tensor(norm_bound, mstype.float32) @@ -128,10 +128,10 @@ class AdaGaussianRandom(Mechanisms): Args: norm_bound(float): Clipping bound for the l2 norm of the gradients. - Default: 1.5. + Default: 1.0. initial_noise_multiplier(float): Ratio of the standard deviation of Gaussian noise divided by the norm_bound, which will be used to - calculate privacy spent. Default: 5.0. + calculate privacy spent. Default: 1.5. mean(float): Average value of random noise. Default: 0.0 noise_decay_rate(float): Hyper parameter for controlling the noise decay. Default: 6e-4. @@ -145,7 +145,7 @@ class AdaGaussianRandom(Mechanisms): Examples: >>> gradients = Tensor([0.2, 0.9], mstype.float32) >>> norm_bound = 1.0 - >>> initial_noise_multiplier = 5.0 + >>> initial_noise_multiplier = 1.5 >>> mean = 0.0 >>> noise_decay_rate = 6e-4 >>> decay_policy = "Time" @@ -155,7 +155,7 @@ class AdaGaussianRandom(Mechanisms): >>> print(res) """ - def __init__(self, norm_bound=1.5, initial_noise_multiplier=5.0, mean=0.0, + def __init__(self, norm_bound=1.0, initial_noise_multiplier=1.5, mean=0.0, noise_decay_rate=6e-4, decay_policy='Time', seed=0): super(AdaGaussianRandom, self).__init__() norm_bound = check_value_positive('norm_bound', norm_bound) -- GitLab