Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
84058952
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看板
提交
84058952
编写于
7月 31, 2020
作者:
P
pkuliuliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add error check of clip_mech
上级
85a2a4e2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
3 deletion
+16
-3
mindarmour/diff_privacy/train/model.py
mindarmour/diff_privacy/train/model.py
+16
-3
未找到文件。
mindarmour/diff_privacy/train/model.py
浏览文件 @
84058952
...
...
@@ -78,9 +78,13 @@ class DPModel(Model):
original data. Default: 1.0.
noise_mech (Mechanisms): The object can generate the different type of
noise. Default: None.
clip_mech (Mechanisms): The object is used to update the adaptive clip
.
clip_mech (Mechanisms): The object is used to update the adaptive clip.
Default: None.
Raises:
ValueError: If DPOptimizer and noise_mecn are both None or not None.
ValueError: If noise_mech or DPOtimizer's mech method is adaptive while clip_mech is not None.
Examples:
>>> norm_bound = 1.0
>>> initial_noise_multiplier = 0.01
...
...
@@ -127,16 +131,25 @@ class DPModel(Model):
norm_bound
=
Tensor
(
norm_bound
,
mstype
.
float32
)
self
.
_norm_bound
=
Parameter
(
norm_bound
,
'norm_bound'
)
if
noise_mech
is
not
None
and
"DPOptimizer"
in
kwargs
[
'optimizer'
].
__class__
.
__name__
:
opt
=
kwargs
[
'optimizer'
]
opt_name
=
opt
.
__class__
.
__name__
# Check whether noise_mech and DPOptimizer are both None or not None, if so, raise ValueError.
# And check whether noise_mech or DPOtimizer's mech method is adaptive while clip_mech is not None,
# if so, rasie ValuerError too.
if
noise_mech
is
not
None
and
"DPOptimizer"
in
opt_name
:
msg
=
'DPOptimizer is not supported while noise_mech is not None'
LOGGER
.
error
(
TAG
,
msg
)
raise
ValueError
(
msg
)
if
noise_mech
is
None
:
if
"DPOptimizer"
in
kwargs
[
'optimizer'
].
__class__
.
__name__
:
if
"DPOptimizer"
in
opt_name
:
if
context
.
get_context
(
'mode'
)
!=
context
.
PYNATIVE_MODE
:
msg
=
'DPOptimizer just support pynative mode currently.'
LOGGER
.
error
(
TAG
,
msg
)
raise
ValueError
(
msg
)
if
'Ada'
in
opt
.
_mech
.
__class__
.
__name__
and
clip_mech
is
not
None
:
msg
=
"When DPOptimizer's mech method is adaptive, clip_mech must be None."
LOGGER
.
error
(
TAG
,
msg
)
raise
ValueError
(
msg
)
else
:
msg
=
'DPModel should set noise_mech or DPOptimizer configure, '
\
'please refer to example.'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录