Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
9649ab3d
M
mindarmour
项目概览
MindSpore
/
mindarmour
通知
4
Star
2
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindarmour
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9649ab3d
编写于
6月 23, 2020
作者:
Z
ZhidanLiu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update default value
上级
2905c9e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
12 deletion
+12
-12
example/mnist_demo/lenet5_config.py
example/mnist_demo/lenet5_config.py
+1
-1
example/mnist_demo/lenet5_dp.py
example/mnist_demo/lenet5_dp.py
+1
-1
mindarmour/diff_privacy/mechanisms/mechanisms.py
mindarmour/diff_privacy/mechanisms/mechanisms.py
+10
-10
未找到文件。
example/mnist_demo/lenet5_config.py
浏览文件 @
9649ab3d
...
...
@@ -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
...
...
example/mnist_demo/lenet5_dp.py
浏览文件 @
9649ab3d
...
...
@@ -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
,
...
...
mindarmour/diff_privacy/mechanisms/mechanisms.py
浏览文件 @
9649ab3d
...
...
@@ -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
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录