Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
f2275a4d
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看板
提交
f2275a4d
编写于
7月 22, 2020
作者:
Z
zhenghuanhuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename noise_update to decay_policy and update version 0.6.0
上级
16b4bcbc
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
49 addition
and
49 deletion
+49
-49
example/mnist_demo/lenet5_dp.py
example/mnist_demo/lenet5_dp.py
+1
-1
example/mnist_demo/lenet5_dp_ada_gaussian.py
example/mnist_demo/lenet5_dp_ada_gaussian.py
+1
-1
example/mnist_demo/lenet5_dp_pynative_model.py
example/mnist_demo/lenet5_dp_pynative_model.py
+1
-1
mindarmour/diff_privacy/mechanisms/mechanisms.py
mindarmour/diff_privacy/mechanisms/mechanisms.py
+24
-24
mindarmour/diff_privacy/optimizer/optimizer.py
mindarmour/diff_privacy/optimizer/optimizer.py
+2
-2
mindarmour/diff_privacy/train/model.py
mindarmour/diff_privacy/train/model.py
+4
-4
setup.py
setup.py
+1
-1
tests/ut/python/diff_privacy/test_mechanisms.py
tests/ut/python/diff_privacy/test_mechanisms.py
+14
-14
tests/ut/python/diff_privacy/test_model_train.py
tests/ut/python/diff_privacy/test_model_train.py
+1
-1
未找到文件。
example/mnist_demo/lenet5_dp.py
浏览文件 @
f2275a4d
...
@@ -116,7 +116,7 @@ if __name__ == "__main__":
...
@@ -116,7 +116,7 @@ if __name__ == "__main__":
noise_mech
=
NoiseMechanismsFactory
().
create
(
cfg
.
noise_mechanisms
,
noise_mech
=
NoiseMechanismsFactory
().
create
(
cfg
.
noise_mechanisms
,
norm_bound
=
cfg
.
norm_bound
,
norm_bound
=
cfg
.
norm_bound
,
initial_noise_multiplier
=
cfg
.
initial_noise_multiplier
,
initial_noise_multiplier
=
cfg
.
initial_noise_multiplier
,
noise_update
=
None
)
decay_policy
=
None
)
# Create a factory class of clip mechanisms, this method is to adaptive clip
# Create a factory class of clip mechanisms, this method is to adaptive clip
# gradients while training, decay_policy support 'Linear' and 'Geometric',
# gradients while training, decay_policy support 'Linear' and 'Geometric',
# learning_rate is the learning rate to update clip_norm,
# learning_rate is the learning rate to update clip_norm,
...
...
example/mnist_demo/lenet5_dp_ada_gaussian.py
浏览文件 @
f2275a4d
...
@@ -115,7 +115,7 @@ if __name__ == "__main__":
...
@@ -115,7 +115,7 @@ if __name__ == "__main__":
noise_mech
=
NoiseMechanismsFactory
().
create
(
cfg
.
noise_mechanisms
,
noise_mech
=
NoiseMechanismsFactory
().
create
(
cfg
.
noise_mechanisms
,
norm_bound
=
cfg
.
norm_bound
,
norm_bound
=
cfg
.
norm_bound
,
initial_noise_multiplier
=
cfg
.
initial_noise_multiplier
,
initial_noise_multiplier
=
cfg
.
initial_noise_multiplier
,
noise_update
=
'Exp'
)
decay_policy
=
'Exp'
)
net_opt
=
nn
.
Momentum
(
params
=
network
.
trainable_params
(),
net_opt
=
nn
.
Momentum
(
params
=
network
.
trainable_params
(),
learning_rate
=
cfg
.
lr
,
momentum
=
cfg
.
momentum
)
learning_rate
=
cfg
.
lr
,
momentum
=
cfg
.
momentum
)
...
...
example/mnist_demo/lenet5_dp_pynative_model.py
浏览文件 @
f2275a4d
...
@@ -111,7 +111,7 @@ if __name__ == "__main__":
...
@@ -111,7 +111,7 @@ if __name__ == "__main__":
dp_opt
.
set_mechanisms
(
cfg
.
noise_mechanisms
,
dp_opt
.
set_mechanisms
(
cfg
.
noise_mechanisms
,
norm_bound
=
cfg
.
norm_bound
,
norm_bound
=
cfg
.
norm_bound
,
initial_noise_multiplier
=
cfg
.
initial_noise_multiplier
,
initial_noise_multiplier
=
cfg
.
initial_noise_multiplier
,
noise_update
=
'Exp'
)
decay_policy
=
'Exp'
)
# Create a factory class of clip mechanisms, this method is to adaptive clip
# Create a factory class of clip mechanisms, this method is to adaptive clip
# gradients while training, decay_policy support 'Linear' and 'Geometric',
# gradients while training, decay_policy support 'Linear' and 'Geometric',
# learning_rate is the learning rate to update clip_norm,
# learning_rate is the learning rate to update clip_norm,
...
...
mindarmour/diff_privacy/mechanisms/mechanisms.py
浏览文件 @
f2275a4d
...
@@ -83,7 +83,7 @@ class NoiseMechanismsFactory:
...
@@ -83,7 +83,7 @@ class NoiseMechanismsFactory:
@
staticmethod
@
staticmethod
def
create
(
mech_name
=
'Gaussian'
,
norm_bound
=
0.5
,
initial_noise_multiplier
=
1.5
,
seed
=
0
,
noise_decay_rate
=
6e-6
,
def
create
(
mech_name
=
'Gaussian'
,
norm_bound
=
0.5
,
initial_noise_multiplier
=
1.5
,
seed
=
0
,
noise_decay_rate
=
6e-6
,
noise_update
=
None
):
decay_policy
=
None
):
"""
"""
Args:
Args:
mech_name(str): Noise generated strategy, could be 'Gaussian' or
mech_name(str): Noise generated strategy, could be 'Gaussian' or
...
@@ -97,7 +97,7 @@ class NoiseMechanismsFactory:
...
@@ -97,7 +97,7 @@ class NoiseMechanismsFactory:
random number. IF seed!=0 random normal will generate values using
random number. IF seed!=0 random normal will generate values using
given seed.
given seed.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
noise_update
(str): Mechanisms parameters update policy. Default: None, no
decay_policy
(str): Mechanisms parameters update policy. Default: None, no
parameters need update.
parameters need update.
Raises:
Raises:
...
@@ -141,13 +141,13 @@ class NoiseMechanismsFactory:
...
@@ -141,13 +141,13 @@ class NoiseMechanismsFactory:
return
NoiseGaussianRandom
(
norm_bound
=
norm_bound
,
return
NoiseGaussianRandom
(
norm_bound
=
norm_bound
,
initial_noise_multiplier
=
initial_noise_multiplier
,
initial_noise_multiplier
=
initial_noise_multiplier
,
seed
=
seed
,
seed
=
seed
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
if
mech_name
==
'AdaGaussian'
:
if
mech_name
==
'AdaGaussian'
:
return
NoiseAdaGaussianRandom
(
norm_bound
=
norm_bound
,
return
NoiseAdaGaussianRandom
(
norm_bound
=
norm_bound
,
initial_noise_multiplier
=
initial_noise_multiplier
,
initial_noise_multiplier
=
initial_noise_multiplier
,
seed
=
seed
,
seed
=
seed
,
noise_decay_rate
=
noise_decay_rate
,
noise_decay_rate
=
noise_decay_rate
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
raise
NameError
(
"The {} is not implement, please choose "
raise
NameError
(
"The {} is not implement, please choose "
"['Gaussian', 'AdaGaussian']"
.
format
(
mech_name
))
"['Gaussian', 'AdaGaussian']"
.
format
(
mech_name
))
...
@@ -176,7 +176,7 @@ class NoiseGaussianRandom(_Mechanisms):
...
@@ -176,7 +176,7 @@ class NoiseGaussianRandom(_Mechanisms):
seed(int): Original random seed, if seed=0 random normal will use secure
seed(int): Original random seed, if seed=0 random normal will use secure
random number. IF seed!=0 random normal will generate values using
random number. IF seed!=0 random normal will generate values using
given seed.
given seed.
noise_update
(str): Mechanisms parameters update policy. Default: None.
decay_policy
(str): Mechanisms parameters update policy. Default: None.
Returns:
Returns:
Tensor, generated noise with shape like given gradients.
Tensor, generated noise with shape like given gradients.
...
@@ -186,13 +186,13 @@ class NoiseGaussianRandom(_Mechanisms):
...
@@ -186,13 +186,13 @@ class NoiseGaussianRandom(_Mechanisms):
>>> norm_bound = 0.5
>>> norm_bound = 0.5
>>> initial_noise_multiplier = 1.5
>>> initial_noise_multiplier = 1.5
>>> seed = 0
>>> seed = 0
>>>
noise_update
= None
>>>
decay_policy
= None
>>> net = NoiseGaussianRandom(norm_bound, initial_noise_multiplier, seed,
noise_update
)
>>> net = NoiseGaussianRandom(norm_bound, initial_noise_multiplier, seed,
decay_policy
)
>>> res = net(gradients)
>>> res = net(gradients)
>>> print(res)
>>> print(res)
"""
"""
def
__init__
(
self
,
norm_bound
,
initial_noise_multiplier
,
seed
,
noise_update
=
None
):
def
__init__
(
self
,
norm_bound
,
initial_noise_multiplier
,
seed
,
decay_policy
=
None
):
super
(
NoiseGaussianRandom
,
self
).
__init__
()
super
(
NoiseGaussianRandom
,
self
).
__init__
()
self
.
_norm_bound
=
check_value_positive
(
'norm_bound'
,
norm_bound
)
self
.
_norm_bound
=
check_value_positive
(
'norm_bound'
,
norm_bound
)
self
.
_norm_bound
=
Tensor
(
norm_bound
,
mstype
.
float32
)
self
.
_norm_bound
=
Tensor
(
norm_bound
,
mstype
.
float32
)
...
@@ -200,9 +200,9 @@ class NoiseGaussianRandom(_Mechanisms):
...
@@ -200,9 +200,9 @@ class NoiseGaussianRandom(_Mechanisms):
initial_noise_multiplier
)
initial_noise_multiplier
)
self
.
_initial_noise_multiplier
=
Tensor
(
initial_noise_multiplier
,
mstype
.
float32
)
self
.
_initial_noise_multiplier
=
Tensor
(
initial_noise_multiplier
,
mstype
.
float32
)
self
.
_mean
=
Tensor
(
0
,
mstype
.
float32
)
self
.
_mean
=
Tensor
(
0
,
mstype
.
float32
)
if
noise_update
is
not
None
:
if
decay_policy
is
not
None
:
raise
ValueError
(
'
noise_update must be None in GaussianRandom class, but got {}.'
.
format
(
noise_update
))
raise
ValueError
(
'
decay_policy must be None in GaussianRandom class, but got {}.'
.
format
(
decay_policy
))
self
.
_
noise_update
=
noise_update
self
.
_
decay_policy
=
decay_policy
self
.
_seed
=
seed
self
.
_seed
=
seed
def
construct
(
self
,
gradients
):
def
construct
(
self
,
gradients
):
...
@@ -237,7 +237,7 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
...
@@ -237,7 +237,7 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
random number. IF seed!=0 random normal will generate values using
random number. IF seed!=0 random normal will generate values using
given seed.
given seed.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
noise_decay_rate(float): Hyper parameter for controlling the noise decay.
noise_update
(str): Noise decay strategy include 'Step', 'Time', 'Exp'.
decay_policy
(str): Noise decay strategy include 'Step', 'Time', 'Exp'.
Returns:
Returns:
Tensor, generated noise with shape like given gradients.
Tensor, generated noise with shape like given gradients.
...
@@ -248,13 +248,13 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
...
@@ -248,13 +248,13 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
>>> initial_noise_multiplier = 1.5
>>> initial_noise_multiplier = 1.5
>>> seed = 0
>>> seed = 0
>>> noise_decay_rate = 6e-4
>>> noise_decay_rate = 6e-4
>>>
noise_update
= "Time"
>>>
decay_policy
= "Time"
>>> net = NoiseAdaGaussianRandom(norm_bound, initial_noise_multiplier, seed, noise_decay_rate,
noise_update
)
>>> net = NoiseAdaGaussianRandom(norm_bound, initial_noise_multiplier, seed, noise_decay_rate,
decay_policy
)
>>> res = net(gradients)
>>> res = net(gradients)
>>> print(res)
>>> print(res)
"""
"""
def
__init__
(
self
,
norm_bound
,
initial_noise_multiplier
,
seed
,
noise_decay_rate
,
noise_update
):
def
__init__
(
self
,
norm_bound
,
initial_noise_multiplier
,
seed
,
noise_decay_rate
,
decay_policy
):
super
(
NoiseAdaGaussianRandom
,
self
).
__init__
(
norm_bound
=
norm_bound
,
super
(
NoiseAdaGaussianRandom
,
self
).
__init__
(
norm_bound
=
norm_bound
,
initial_noise_multiplier
=
initial_noise_multiplier
,
initial_noise_multiplier
=
initial_noise_multiplier
,
seed
=
seed
)
seed
=
seed
)
...
@@ -263,10 +263,10 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
...
@@ -263,10 +263,10 @@ class NoiseAdaGaussianRandom(NoiseGaussianRandom):
noise_decay_rate
=
check_param_type
(
'noise_decay_rate'
,
noise_decay_rate
,
float
)
noise_decay_rate
=
check_param_type
(
'noise_decay_rate'
,
noise_decay_rate
,
float
)
check_param_in_range
(
'noise_decay_rate'
,
noise_decay_rate
,
0.0
,
1.0
)
check_param_in_range
(
'noise_decay_rate'
,
noise_decay_rate
,
0.0
,
1.0
)
self
.
_noise_decay_rate
=
Tensor
(
noise_decay_rate
,
mstype
.
float32
)
self
.
_noise_decay_rate
=
Tensor
(
noise_decay_rate
,
mstype
.
float32
)
if
noise_update
not
in
[
'Time'
,
'Step'
,
'Exp'
]:
if
decay_policy
not
in
[
'Time'
,
'Step'
,
'Exp'
]:
raise
NameError
(
"The
noise_update
must be in ['Time', 'Step', 'Exp'], but "
raise
NameError
(
"The
decay_policy
must be in ['Time', 'Step', 'Exp'], but "
"get {}"
.
format
(
noise_update
))
"get {}"
.
format
(
decay_policy
))
self
.
_
noise_update
=
noise_update
self
.
_
decay_policy
=
decay_policy
class
_MechanismsParamsUpdater
(
Cell
):
class
_MechanismsParamsUpdater
(
Cell
):
...
@@ -274,7 +274,7 @@ class _MechanismsParamsUpdater(Cell):
...
@@ -274,7 +274,7 @@ class _MechanismsParamsUpdater(Cell):
Update mechanisms parameters, the parameters will refresh in train period.
Update mechanisms parameters, the parameters will refresh in train period.
Args:
Args:
noise_update
(str): Pass in by the mechanisms class, mechanisms parameters
decay_policy
(str): Pass in by the mechanisms class, mechanisms parameters
update policy.
update policy.
decay_rate(Tensor): Pass in by the mechanisms class, hyper parameter for
decay_rate(Tensor): Pass in by the mechanisms class, hyper parameter for
controlling the decay size.
controlling the decay size.
...
@@ -286,9 +286,9 @@ class _MechanismsParamsUpdater(Cell):
...
@@ -286,9 +286,9 @@ class _MechanismsParamsUpdater(Cell):
Returns:
Returns:
Tuple, next params value.
Tuple, next params value.
"""
"""
def
__init__
(
self
,
noise_update
,
decay_rate
,
cur_noise_multiplier
,
init_noise_multiplier
):
def
__init__
(
self
,
decay_policy
,
decay_rate
,
cur_noise_multiplier
,
init_noise_multiplier
):
super
(
_MechanismsParamsUpdater
,
self
).
__init__
()
super
(
_MechanismsParamsUpdater
,
self
).
__init__
()
self
.
_
noise_update
=
noise_update
self
.
_
decay_policy
=
decay_policy
self
.
_decay_rate
=
decay_rate
self
.
_decay_rate
=
decay_rate
self
.
_cur_noise_multiplier
=
cur_noise_multiplier
self
.
_cur_noise_multiplier
=
cur_noise_multiplier
self
.
_init_noise_multiplier
=
init_noise_multiplier
self
.
_init_noise_multiplier
=
init_noise_multiplier
...
@@ -308,12 +308,12 @@ class _MechanismsParamsUpdater(Cell):
...
@@ -308,12 +308,12 @@ class _MechanismsParamsUpdater(Cell):
Returns:
Returns:
Tuple, next step parameters value.
Tuple, next step parameters value.
"""
"""
if
self
.
_
noise_update
==
'Time'
:
if
self
.
_
decay_policy
==
'Time'
:
temp
=
self
.
_div
(
self
.
_init_noise_multiplier
,
self
.
_cur_noise_multiplier
)
temp
=
self
.
_div
(
self
.
_init_noise_multiplier
,
self
.
_cur_noise_multiplier
)
temp
=
self
.
_add
(
temp
,
self
.
_decay_rate
)
temp
=
self
.
_add
(
temp
,
self
.
_decay_rate
)
next_noise_multiplier
=
self
.
_assign
(
self
.
_cur_noise_multiplier
,
next_noise_multiplier
=
self
.
_assign
(
self
.
_cur_noise_multiplier
,
self
.
_div
(
self
.
_init_noise_multiplier
,
temp
))
self
.
_div
(
self
.
_init_noise_multiplier
,
temp
))
elif
self
.
_
noise_update
==
'Step'
:
elif
self
.
_
decay_policy
==
'Step'
:
temp
=
self
.
_sub
(
self
.
_one
,
self
.
_decay_rate
)
temp
=
self
.
_sub
(
self
.
_one
,
self
.
_decay_rate
)
next_noise_multiplier
=
self
.
_assign
(
self
.
_cur_noise_multiplier
,
next_noise_multiplier
=
self
.
_assign
(
self
.
_cur_noise_multiplier
,
self
.
_mul
(
temp
,
self
.
_cur_noise_multiplier
))
self
.
_mul
(
temp
,
self
.
_cur_noise_multiplier
))
...
...
mindarmour/diff_privacy/optimizer/optimizer.py
浏览文件 @
f2275a4d
...
@@ -127,8 +127,8 @@ class DPOptimizerClassFactory:
...
@@ -127,8 +127,8 @@ class DPOptimizerClassFactory:
self
.
_micro_float
=
Tensor
(
micro_batches
,
mstype
.
float32
)
self
.
_micro_float
=
Tensor
(
micro_batches
,
mstype
.
float32
)
self
.
_mech_param_updater
=
None
self
.
_mech_param_updater
=
None
if
self
.
_mech
is
not
None
and
self
.
_mech
.
_
noise_update
is
not
None
:
if
self
.
_mech
is
not
None
and
self
.
_mech
.
_
decay_policy
is
not
None
:
self
.
_mech_param_updater
=
_MechanismsParamsUpdater
(
noise_update
=
self
.
_mech
.
_noise_update
,
self
.
_mech_param_updater
=
_MechanismsParamsUpdater
(
decay_policy
=
self
.
_mech
.
_decay_policy
,
decay_rate
=
self
.
_mech
.
_noise_decay_rate
,
decay_rate
=
self
.
_mech
.
_noise_decay_rate
,
cur_noise_multiplier
=
cur_noise_multiplier
=
self
.
_mech
.
_noise_multiplier
,
self
.
_mech
.
_noise_multiplier
,
...
...
mindarmour/diff_privacy/train/model.py
浏览文件 @
f2275a4d
...
@@ -432,9 +432,9 @@ class _TrainOneStepWithLossScaleCell(Cell):
...
@@ -432,9 +432,9 @@ class _TrainOneStepWithLossScaleCell(Cell):
self
.
_cast
=
P
.
Cast
()
self
.
_cast
=
P
.
Cast
()
self
.
_noise_mech_param_updater
=
None
self
.
_noise_mech_param_updater
=
None
if
self
.
_noise_mech
is
not
None
and
self
.
_noise_mech
.
_
noise_update
is
not
None
:
if
self
.
_noise_mech
is
not
None
and
self
.
_noise_mech
.
_
decay_policy
is
not
None
:
self
.
_noise_mech_param_updater
=
_MechanismsParamsUpdater
(
self
.
_noise_mech_param_updater
=
_MechanismsParamsUpdater
(
noise_update
=
self
.
_noise_mech
.
_noise_update
,
decay_policy
=
self
.
_noise_mech
.
_decay_policy
,
decay_rate
=
self
.
_noise_mech
.
_noise_decay_rate
,
decay_rate
=
self
.
_noise_mech
.
_noise_decay_rate
,
cur_noise_multiplier
=
cur_noise_multiplier
=
self
.
_noise_mech
.
_noise_multiplier
,
self
.
_noise_mech
.
_noise_multiplier
,
...
@@ -636,9 +636,9 @@ class _TrainOneStepCell(Cell):
...
@@ -636,9 +636,9 @@ class _TrainOneStepCell(Cell):
self
.
_micro_float
=
Tensor
(
micro_batches
,
mstype
.
float32
)
self
.
_micro_float
=
Tensor
(
micro_batches
,
mstype
.
float32
)
self
.
_noise_mech_param_updater
=
None
self
.
_noise_mech_param_updater
=
None
if
self
.
_noise_mech
is
not
None
and
self
.
_noise_mech
.
_
noise_update
is
not
None
:
if
self
.
_noise_mech
is
not
None
and
self
.
_noise_mech
.
_
decay_policy
is
not
None
:
self
.
_noise_mech_param_updater
=
_MechanismsParamsUpdater
(
self
.
_noise_mech_param_updater
=
_MechanismsParamsUpdater
(
noise_update
=
self
.
_noise_mech
.
_noise_update
,
decay_policy
=
self
.
_noise_mech
.
_decay_policy
,
decay_rate
=
self
.
_noise_mech
.
_noise_decay_rate
,
decay_rate
=
self
.
_noise_mech
.
_noise_decay_rate
,
cur_noise_multiplier
=
cur_noise_multiplier
=
self
.
_noise_mech
.
_noise_multiplier
,
self
.
_noise_mech
.
_noise_multiplier
,
...
...
setup.py
浏览文件 @
f2275a4d
...
@@ -18,7 +18,7 @@ from setuptools import setup
...
@@ -18,7 +18,7 @@ from setuptools import setup
from
setuptools.command.egg_info
import
egg_info
from
setuptools.command.egg_info
import
egg_info
from
setuptools.command.build_py
import
build_py
from
setuptools.command.build_py
import
build_py
version
=
'0.
5
.0'
version
=
'0.
6
.0'
cur_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
cur_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
pkg_dir
=
os
.
path
.
join
(
cur_dir
,
'build'
)
pkg_dir
=
os
.
path
.
join
(
cur_dir
,
'build'
)
...
...
tests/ut/python/diff_privacy/test_mechanisms.py
浏览文件 @
f2275a4d
...
@@ -35,7 +35,7 @@ def test_graph_factory():
...
@@ -35,7 +35,7 @@ def test_graph_factory():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
alpha
=
0.5
alpha
=
0.5
noise_update
=
'Step'
decay_policy
=
'Step'
factory
=
NoiseMechanismsFactory
()
factory
=
NoiseMechanismsFactory
()
noise_mech
=
factory
.
create
(
'Gaussian'
,
noise_mech
=
factory
.
create
(
'Gaussian'
,
norm_bound
,
norm_bound
,
...
@@ -46,7 +46,7 @@ def test_graph_factory():
...
@@ -46,7 +46,7 @@ def test_graph_factory():
norm_bound
,
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
noise_decay_rate
=
alpha
,
noise_decay_rate
=
alpha
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
ada_noise
=
ada_noise_mech
(
grad
)
ada_noise
=
ada_noise_mech
(
grad
)
print
(
'ada noise: '
,
ada_noise
)
print
(
'ada noise: '
,
ada_noise
)
...
@@ -61,7 +61,7 @@ def test_pynative_factory():
...
@@ -61,7 +61,7 @@ def test_pynative_factory():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
alpha
=
0.5
alpha
=
0.5
noise_update
=
'Step'
decay_policy
=
'Step'
factory
=
NoiseMechanismsFactory
()
factory
=
NoiseMechanismsFactory
()
noise_mech
=
factory
.
create
(
'Gaussian'
,
noise_mech
=
factory
.
create
(
'Gaussian'
,
norm_bound
,
norm_bound
,
...
@@ -72,7 +72,7 @@ def test_pynative_factory():
...
@@ -72,7 +72,7 @@ def test_pynative_factory():
norm_bound
,
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
noise_decay_rate
=
alpha
,
noise_decay_rate
=
alpha
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
ada_noise
=
ada_noise_mech
(
grad
)
ada_noise
=
ada_noise_mech
(
grad
)
print
(
'ada noise: '
,
ada_noise
)
print
(
'ada noise: '
,
ada_noise
)
...
@@ -87,7 +87,7 @@ def test_pynative_gaussian():
...
@@ -87,7 +87,7 @@ def test_pynative_gaussian():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
alpha
=
0.5
alpha
=
0.5
noise_update
=
'Step'
decay_policy
=
'Step'
factory
=
NoiseMechanismsFactory
()
factory
=
NoiseMechanismsFactory
()
noise_mech
=
factory
.
create
(
'Gaussian'
,
noise_mech
=
factory
.
create
(
'Gaussian'
,
norm_bound
,
norm_bound
,
...
@@ -98,7 +98,7 @@ def test_pynative_gaussian():
...
@@ -98,7 +98,7 @@ def test_pynative_gaussian():
norm_bound
,
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
noise_decay_rate
=
alpha
,
noise_decay_rate
=
alpha
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
ada_noise
=
ada_noise_mech
(
grad
)
ada_noise
=
ada_noise_mech
(
grad
)
print
(
'ada noise: '
,
ada_noise
)
print
(
'ada noise: '
,
ada_noise
)
...
@@ -113,12 +113,12 @@ def test_graph_ada_gaussian():
...
@@ -113,12 +113,12 @@ def test_graph_ada_gaussian():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
noise_decay_rate
=
0.5
noise_decay_rate
=
0.5
noise_update
=
'Step'
decay_policy
=
'Step'
ada_noise_mech
=
NoiseAdaGaussianRandom
(
norm_bound
,
ada_noise_mech
=
NoiseAdaGaussianRandom
(
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
seed
=
0
,
seed
=
0
,
noise_decay_rate
=
noise_decay_rate
,
noise_decay_rate
=
noise_decay_rate
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
res
=
ada_noise_mech
(
grad
)
res
=
ada_noise_mech
(
grad
)
print
(
res
)
print
(
res
)
...
@@ -133,12 +133,12 @@ def test_pynative_ada_gaussian():
...
@@ -133,12 +133,12 @@ def test_pynative_ada_gaussian():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
noise_decay_rate
=
0.5
noise_decay_rate
=
0.5
noise_update
=
'Step'
decay_policy
=
'Step'
ada_noise_mech
=
NoiseAdaGaussianRandom
(
norm_bound
,
ada_noise_mech
=
NoiseAdaGaussianRandom
(
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
seed
=
0
,
seed
=
0
,
noise_decay_rate
=
noise_decay_rate
,
noise_decay_rate
=
noise_decay_rate
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
res
=
ada_noise_mech
(
grad
)
res
=
ada_noise_mech
(
grad
)
print
(
res
)
print
(
res
)
...
@@ -153,13 +153,13 @@ def test_graph_exponential():
...
@@ -153,13 +153,13 @@ def test_graph_exponential():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
alpha
=
0.5
alpha
=
0.5
noise_update
=
'Exp'
decay_policy
=
'Exp'
factory
=
NoiseMechanismsFactory
()
factory
=
NoiseMechanismsFactory
()
ada_noise
=
factory
.
create
(
'AdaGaussian'
,
ada_noise
=
factory
.
create
(
'AdaGaussian'
,
norm_bound
,
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
noise_decay_rate
=
alpha
,
noise_decay_rate
=
alpha
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
ada_noise
=
ada_noise
(
grad
)
ada_noise
=
ada_noise
(
grad
)
print
(
'ada noise: '
,
ada_noise
)
print
(
'ada noise: '
,
ada_noise
)
...
@@ -174,13 +174,13 @@ def test_pynative_exponential():
...
@@ -174,13 +174,13 @@ def test_pynative_exponential():
norm_bound
=
1.0
norm_bound
=
1.0
initial_noise_multiplier
=
0.1
initial_noise_multiplier
=
0.1
alpha
=
0.5
alpha
=
0.5
noise_update
=
'Exp'
decay_policy
=
'Exp'
factory
=
NoiseMechanismsFactory
()
factory
=
NoiseMechanismsFactory
()
ada_noise
=
factory
.
create
(
'AdaGaussian'
,
ada_noise
=
factory
.
create
(
'AdaGaussian'
,
norm_bound
,
norm_bound
,
initial_noise_multiplier
,
initial_noise_multiplier
,
noise_decay_rate
=
alpha
,
noise_decay_rate
=
alpha
,
noise_update
=
noise_update
)
decay_policy
=
decay_policy
)
ada_noise
=
ada_noise
(
grad
)
ada_noise
=
ada_noise
(
grad
)
print
(
'ada noise: '
,
ada_noise
)
print
(
'ada noise: '
,
ada_noise
)
...
...
tests/ut/python/diff_privacy/test_model_train.py
浏览文件 @
f2275a4d
...
@@ -136,7 +136,7 @@ def test_dp_model_with_graph_mode_ada_gaussian():
...
@@ -136,7 +136,7 @@ def test_dp_model_with_graph_mode_ada_gaussian():
norm_bound
=
norm_bound
,
norm_bound
=
norm_bound
,
initial_noise_multiplier
=
initial_noise_multiplier
,
initial_noise_multiplier
=
initial_noise_multiplier
,
noise_decay_rate
=
alpha
,
noise_decay_rate
=
alpha
,
noise_update
=
'Exp'
)
decay_policy
=
'Exp'
)
clip_mech
=
None
clip_mech
=
None
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
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录