Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
c47ae621
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看板
未验证
提交
c47ae621
编写于
3月 04, 2022
作者:
H
hong
提交者:
GitHub
3月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add eager test in rnn and fc; test=develop (#40149)
上级
d50fb43e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
0 deletion
+58
-0
python/paddle/fluid/tests/unittests/test_imperative_deepcf.py
...on/paddle/fluid/tests/unittests/test_imperative_deepcf.py
+34
-0
python/paddle/fluid/tests/unittests/test_imperative_recurrent_usage.py
.../fluid/tests/unittests/test_imperative_recurrent_usage.py
+24
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_imperative_deepcf.py
浏览文件 @
c47ae621
...
...
@@ -24,6 +24,7 @@ import paddle.fluid.core as core
from
test_imperative_base
import
new_program_scope
from
paddle.fluid.dygraph.base
import
to_variable
from
paddle.fluid.dygraph
import
Linear
from
paddle.fluid.framework
import
_test_eager_guard
# Can use Amusic dataset as the DeepCF describes.
DATA_PATH
=
os
.
environ
.
get
(
'DATA_PATH'
,
''
)
...
...
@@ -294,9 +295,42 @@ class TestDygraphDeepCF(unittest.TestCase):
sys
.
stderr
.
write
(
'dynamic loss: %s %s
\n
'
%
(
slice
,
dy_loss2
))
with
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
deepcf
=
DeepCF
(
num_users
,
num_items
,
matrix
)
adam
=
fluid
.
optimizer
.
AdamOptimizer
(
0.01
,
parameter_list
=
deepcf
.
parameters
())
for
e
in
range
(
NUM_EPOCHES
):
sys
.
stderr
.
write
(
'epoch %d
\n
'
%
e
)
for
slice
in
range
(
0
,
BATCH_SIZE
*
NUM_BATCHES
,
BATCH_SIZE
):
if
slice
+
BATCH_SIZE
>=
users_np
.
shape
[
0
]:
break
prediction
=
deepcf
(
to_variable
(
users_np
[
slice
:
slice
+
BATCH_SIZE
]),
to_variable
(
items_np
[
slice
:
slice
+
BATCH_SIZE
]))
loss
=
fluid
.
layers
.
reduce_sum
(
fluid
.
layers
.
log_loss
(
prediction
,
to_variable
(
labels_np
[
slice
:
slice
+
BATCH_SIZE
])))
loss
.
backward
()
adam
.
minimize
(
loss
)
deepcf
.
clear_gradients
()
eager_loss
=
loss
.
numpy
()
sys
.
stderr
.
write
(
'eager loss: %s %s
\n
'
%
(
slice
,
eager_loss
))
self
.
assertEqual
(
static_loss
,
dy_loss
)
self
.
assertEqual
(
static_loss
,
dy_loss2
)
self
.
assertEqual
(
static_loss
,
eager_loss
)
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_imperative_recurrent_usage.py
浏览文件 @
c47ae621
...
...
@@ -16,9 +16,11 @@ from __future__ import print_function
import
unittest
import
paddle.fluid
as
fluid
import
paddle
import
paddle.fluid.core
as
core
from
paddle.fluid.dygraph.nn
import
Embedding
import
paddle.fluid.framework
as
framework
from
paddle.fluid.framework
import
_test_eager_guard
from
paddle.fluid.optimizer
import
SGDOptimizer
from
paddle.fluid.dygraph.base
import
to_variable
from
test_imperative_base
import
new_program_scope
...
...
@@ -60,6 +62,25 @@ class TestRecurrentFeed(unittest.TestCase):
original_in1
.
stop_gradient
=
True
rt
.
clear_gradients
()
with
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
original_in1
=
to_variable
(
original_np1
)
original_in2
=
to_variable
(
original_np2
)
original_in1
.
stop_gradient
=
False
original_in2
.
stop_gradient
=
False
rt
=
RecurrentTest
(
"RecurrentTest"
)
for
i
in
range
(
3
):
sum_out
,
out
=
rt
(
original_in1
,
original_in2
)
original_in1
=
out
eager_sum_out_value
=
sum_out
.
numpy
()
sum_out
.
backward
()
eager_dyout
=
out
.
gradient
()
original_in1
.
stop_gradient
=
True
rt
.
clear_gradients
()
with
new_program_scope
():
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
...
...
@@ -88,8 +109,11 @@ class TestRecurrentFeed(unittest.TestCase):
original_np1
=
static_out_value
self
.
assertTrue
(
np
.
array_equal
(
static_sum_out
,
sum_out_value
))
self
.
assertTrue
(
np
.
array_equal
(
static_sum_out
,
eager_sum_out_value
))
self
.
assertTrue
(
np
.
array_equal
(
static_dout
,
dyout
))
self
.
assertTrue
(
np
.
array_equal
(
static_dout
,
eager_dyout
))
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录