Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
92081e1d
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
92081e1d
编写于
6月 09, 2021
作者:
L
Leo Chen
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix undefined variable in optimizer (#33416)
上级
2af23549
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
4 deletion
+41
-4
python/paddle/fluid/optimizer.py
python/paddle/fluid/optimizer.py
+2
-2
python/paddle/fluid/tests/unittests/test_adam_op.py
python/paddle/fluid/tests/unittests/test_adam_op.py
+39
-2
未找到文件。
python/paddle/fluid/optimizer.py
浏览文件 @
92081e1d
...
...
@@ -257,11 +257,11 @@ class Optimizer(object):
assert
model_np
.
shape
==
load_para_np
.
shape
,
\
"Parameter shape not match, Dygraph Parameter [ {} ] need tensor with shape {} but load tensor with shape {}"
.
format
(
ite
m
.
name
,
model_np
.
shape
,
load_para_np
.
shape
)
para
m
.
name
,
model_np
.
shape
,
load_para_np
.
shape
)
assert
model_np
.
dtype
==
load_para_np
.
dtype
,
\
"Parameter dtype not match, Dygraph Parameter [ {} ] need tensor with dtype {} but load tensor with dtype {}"
.
format
(
ite
m
.
name
,
model_np
.
dtype
,
load_para_np
.
dtype
)
para
m
.
name
,
model_np
.
dtype
,
load_para_np
.
dtype
)
tensor
.
set
(
load_para_np
,
framework
.
_current_expected_place
())
...
...
python/paddle/fluid/tests/unittests/test_adam_op.py
浏览文件 @
92081e1d
...
...
@@ -804,11 +804,48 @@ class TestNetWithEpsilonTensor(unittest.TestCase):
adam
.
minimize
(
b
)
state_dict
=
adam
.
state_dict
()
fluid
.
save_dygraph
(
state_dict
,
"paddle_dy"
)
para_state_dict
,
opt
i
_state_dict
=
fluid
.
load_dygraph
(
"paddle_dy"
)
adam
.
set_state_dict
(
opt
i
_state_dict
)
para_state_dict
,
opt_state_dict
=
fluid
.
load_dygraph
(
"paddle_dy"
)
adam
.
set_state_dict
(
opt_state_dict
)
paddle
.
enable_static
()
def
test_adam_save_load_error
(
self
):
paddle
.
disable_static
()
def
get_opt
(
dtype
,
shape
):
with
paddle
.
utils
.
unique_name
.
guard
():
paddle
.
set_default_dtype
(
dtype
)
a
=
paddle
.
rand
([
4
,
10
])
linear
=
paddle
.
nn
.
Linear
(
10
,
10
)
b
=
linear
(
a
)
state_dict
=
linear
.
state_dict
()
fluid
.
save_dygraph
(
state_dict
,
"paddle_dy"
)
scheduler
=
paddle
.
optimizer
.
lr
.
NoamDecay
(
d_model
=
0.01
,
warmup_steps
=
100
,
verbose
=
True
)
adam
=
paddle
.
fluid
.
optimizer
.
Adam
(
learning_rate
=
scheduler
,
parameter_list
=
linear
.
parameters
(),
use_global_beta_pow
=
True
)
adam
.
minimize
(
b
)
return
adam
adam
=
get_opt
(
'float32'
,
[
10
,
10
])
state_dict
=
adam
.
state_dict
()
fluid
.
save_dygraph
(
state_dict
,
"paddle_dy"
)
para_state_dict
,
opt_state_dict
=
fluid
.
load_dygraph
(
"paddle_dy"
)
adam
.
set_state_dict
(
opt_state_dict
)
adam2
=
get_opt
(
'float64'
,
[
10
,
10
])
# dtype not match
self
.
assertRaises
(
AssertionError
,
adam2
.
set_state_dict
,
opt_state_dict
)
adam3
=
get_opt
(
'float32'
,
[
10
,
10
])
# shape not match
opt_state_dict
[
'beta1_pow_acc_0'
]
=
np
.
array
(
[
0.9
,
0.9
],
dtype
=
'float32'
)
self
.
assertRaises
(
AssertionError
,
adam3
.
set_state_dict
,
opt_state_dict
)
paddle
.
enable_static
()
class
TestAdamOpV2Group
(
TestAdamOpV2
):
def
test_adam_op
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录