Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
810ccf80
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
810ccf80
编写于
4年前
作者:
W
wangnan39@huawei.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix_bug_in_check_lamb_warmup_step
上级
fb7e4eac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
15 deletion
+13
-15
mindspore/nn/optim/lamb.py
mindspore/nn/optim/lamb.py
+1
-2
tests/ut/python/nn/optim/test_lamb.py
tests/ut/python/nn/optim/test_lamb.py
+12
-13
未找到文件。
mindspore/nn/optim/lamb.py
浏览文件 @
810ccf80
...
...
@@ -111,7 +111,6 @@ def _update_run_op(beta1, beta2, eps, lr, weight_decay_tensor, global_step, para
def
_check_param_value
(
decay_steps
,
warmup_steps
,
start_learning_rate
,
end_learning_rate
,
power
,
beta1
,
beta2
,
eps
,
weight_decay
,
prim_name
):
"""Check the type of inputs."""
_
=
warmup_steps
validator
.
check_float_positive
(
'start_learning_rate'
,
start_learning_rate
,
prim_name
)
validator
.
check_float_legal_value
(
'start_learning_rate'
,
start_learning_rate
,
prim_name
)
validator
.
check_value_type
(
"end_learning_rate"
,
end_learning_rate
,
[
float
],
prim_name
)
...
...
@@ -119,7 +118,7 @@ def _check_param_value(decay_steps, warmup_steps, start_learning_rate,
validator
.
check_float_positive
(
'power'
,
power
,
prim_name
)
validator
.
check_float_legal_value
(
'power'
,
power
,
prim_name
)
validator
.
check_integer
(
'decay_steps'
,
decay_steps
,
0
,
Rel
.
GT
,
prim_name
)
validator
.
check_integer
(
'warmup_steps'
,
decay_steps
,
0
,
Rel
.
GT
,
prim_name
)
validator
.
check_integer
(
'warmup_steps'
,
warmup_steps
,
0
,
Rel
.
GE
,
prim_name
)
validator
.
check_value_type
(
"beta1"
,
beta1
,
[
float
],
prim_name
)
validator
.
check_value_type
(
"beta2"
,
beta2
,
[
float
],
prim_name
)
validator
.
check_value_type
(
"eps"
,
eps
,
[
float
],
prim_name
)
...
...
This diff is collapsed.
Click to expand it.
tests/ut/python/nn/optim/test_lamb.py
浏览文件 @
810ccf80
...
...
@@ -14,6 +14,7 @@
# ============================================================================
""" test lamb """
import
numpy
as
np
import
pytest
import
mindspore.nn
as
nn
from
mindspore
import
Tensor
,
Parameter
...
...
@@ -50,29 +51,27 @@ class NetWithoutWeight(nn.Cell):
return
x
def
test_lamb_
1
():
""" test_Lamb_
1
"""
def
test_lamb_
compile
():
""" test_Lamb_
compile
"""
inputs
=
Tensor
(
np
.
ones
([
1
,
64
]).
astype
(
np
.
float32
))
label
=
Tensor
(
np
.
zeros
([
1
,
10
]).
astype
(
np
.
float32
))
net
=
Net
()
net
.
set_train
()
loss
=
nn
.
SoftmaxCrossEntropyWithLogits
()
optimizer
=
Lamb
(
net
.
trainable_params
(),
decay_steps
=
10
,
warmup_steps
=
5
)
optimizer
=
Lamb
(
net
.
trainable_params
(),
decay_steps
=
10
)
net_with_loss
=
WithLossCell
(
net
,
loss
)
train_network
=
TrainOneStepCell
(
net_with_loss
,
optimizer
)
_executor
.
compile
(
train_network
,
inputs
,
label
)
def
test_lamb_2
():
""" test_Lamb_2 """
inputs
=
Tensor
(
np
.
ones
([
1
,
64
]).
astype
(
np
.
float32
))
label
=
Tensor
(
np
.
zeros
([
1
,
10
]).
astype
(
np
.
float32
))
def
test_lamb_error
():
net
=
Net
()
net
.
set_train
()
loss
=
nn
.
SoftmaxCrossEntropyWithLogits
()
optimizer
=
Lamb
(
net
.
trainable_params
(),
decay_steps
=
10
,
warmup_steps
=
0
)
with
pytest
.
raises
(
TypeError
):
Lamb
(
net
.
get_parameters
(),
decay_steps
=
6
,
warmup_steps
=
5.0
)
net_with_loss
=
WithLossCell
(
net
,
loss
)
train_network
=
TrainOneStepCell
(
net_with_loss
,
optimizer
)
_executor
.
compile
(
train_network
,
inputs
,
label
)
with
pytest
.
raises
(
TypeError
):
Lamb
(
net
.
get_parameters
(),
decay_steps
=
1.0
)
with
pytest
.
raises
(
ValueError
):
Lamb
(
net
.
get_parameters
(),
decay_steps
=
0
)
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部