Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
4760fd96
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看板
提交
4760fd96
编写于
3月 04, 2022
作者:
P
phlrain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable eager model; test=develop
上级
eaacf8bf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
120 addition
and
8 deletion
+120
-8
python/paddle/fluid/tests/unittests/test_imperative_ocr_attention_model.py
...id/tests/unittests/test_imperative_ocr_attention_model.py
+24
-2
python/paddle/fluid/tests/unittests/test_imperative_reinforcement.py
...le/fluid/tests/unittests/test_imperative_reinforcement.py
+22
-1
python/paddle/fluid/tests/unittests/test_imperative_se_resnext.py
...addle/fluid/tests/unittests/test_imperative_se_resnext.py
+40
-1
python/paddle/fluid/tests/unittests/test_imperative_transformer_sorted_gradient.py
.../unittests/test_imperative_transformer_sorted_gradient.py
+34
-4
未找到文件。
python/paddle/fluid/tests/unittests/test_imperative_ocr_attention_model.py
浏览文件 @
4760fd96
...
...
@@ -22,6 +22,7 @@ from paddle.fluid import core
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
Linear
,
BatchNorm
,
Embedding
,
GRUUnit
from
paddle.fluid.dygraph.base
import
to_variable
from
test_imperative_base
import
new_program_scope
from
paddle.fluid.framework
import
_test_eager_guard
class
Config
(
object
):
...
...
@@ -371,7 +372,7 @@ class OCRAttention(fluid.dygraph.Layer):
class
TestDygraphOCRAttention
(
unittest
.
TestCase
):
def
test_
while_op
(
self
):
def
test_
ocr_test
(
self
):
seed
=
90
epoch_num
=
1
if
core
.
is_compiled_with_cuda
():
...
...
@@ -400,7 +401,7 @@ class TestDygraphOCRAttention(unittest.TestCase):
i
*
Config
.
max_length
,
dtype
=
'int64'
).
reshape
([
1
,
Config
.
max_length
])))
with
fluid
.
dygraph
.
guard
():
def
run_dygraph
():
fluid
.
set_flags
({
'FLAGS_sort_sum_gradient'
:
True
})
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -452,6 +453,16 @@ class TestDygraphOCRAttention(unittest.TestCase):
for
param
in
ocr_attention
.
parameters
():
dy_param_value
[
param
.
name
]
=
param
.
numpy
()
return
dy_out
,
dy_param_init_value
,
dy_param_value
with
fluid
.
dygraph
.
guard
():
dy_out
,
dy_param_init_value
,
dy_param_value
=
run_dygraph
()
with
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
eager_out
,
eager_param_init_value
,
eager_param_value
=
run_dygraph
(
)
with
new_program_scope
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -537,6 +548,17 @@ class TestDygraphOCRAttention(unittest.TestCase):
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
self
.
assertTrue
(
np
.
allclose
(
value
,
dy_param_value
[
key
],
rtol
=
1e-05
))
# check eager here
self
.
assertTrue
(
np
.
allclose
(
static_out
,
eager_out
))
for
key
,
value
in
six
.
iteritems
(
static_param_init_value
):
self
.
assertTrue
(
np
.
array_equal
(
value
,
eager_param_init_value
[
key
]))
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
self
.
assertTrue
(
np
.
allclose
(
value
,
eager_param_value
[
key
],
rtol
=
1e-05
))
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_imperative_reinforcement.py
浏览文件 @
4760fd96
...
...
@@ -27,6 +27,7 @@ from paddle.fluid.dygraph.nn import Conv2D, Pool2D, Linear
import
paddle.fluid.dygraph.nn
as
nn
from
paddle.fluid.dygraph.base
import
to_variable
from
test_imperative_base
import
new_program_scope
from
paddle.fluid.framework
import
_test_eager_guard
class
Policy
(
fluid
.
dygraph
.
Layer
):
...
...
@@ -63,7 +64,7 @@ class TestImperativeMnist(unittest.TestCase):
mask_list
=
[[
0
,
1
]]
mask
=
np
.
array
(
mask_list
).
astype
(
"float32"
)
with
fluid
.
dygraph
.
guard
():
def
run_dygraph
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -104,6 +105,16 @@ class TestImperativeMnist(unittest.TestCase):
for
param
in
policy
.
parameters
():
dy_param_value
[
param
.
name
]
=
param
.
numpy
()
return
dy_out
,
dy_param_init_value
,
dy_param_value
with
fluid
.
dygraph
.
guard
():
dy_out
,
dy_param_init_value
,
dy_param_value
=
run_dygraph
()
with
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
eager_out
,
eager_param_init_value
,
eager_param_value
=
run_dygraph
(
)
with
new_program_scope
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -171,6 +182,16 @@ class TestImperativeMnist(unittest.TestCase):
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
self
.
assertTrue
(
np
.
equal
(
value
,
dy_param_value
[
key
]).
all
())
# check eager
for
key
,
value
in
six
.
iteritems
(
static_param_init_value
):
self
.
assertTrue
(
np
.
equal
(
value
,
eager_param_init_value
[
key
]).
all
())
self
.
assertTrue
(
np
.
equal
(
static_out
,
eager_out
).
all
())
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
self
.
assertTrue
(
np
.
equal
(
value
,
eager_param_value
[
key
]).
all
())
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_imperative_se_resnext.py
浏览文件 @
4760fd96
...
...
@@ -24,6 +24,7 @@ from paddle.fluid.layer_helper import LayerHelper
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
BatchNorm
,
Linear
from
paddle.fluid.dygraph.base
import
to_variable
from
test_imperative_base
import
new_program_scope
from
paddle.fluid.framework
import
_test_eager_guard
if
fluid
.
is_compiled_with_cuda
():
fluid
.
set_flags
({
'FLAGS_cudnn_deterministic'
:
True
})
...
...
@@ -310,7 +311,8 @@ class TestImperativeResneXt(unittest.TestCase):
batch_size
=
train_parameters
[
"batch_size"
]
batch_num
=
1
epoch_num
=
1
with
fluid
.
dygraph
.
guard
():
def
run_dygraph
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -371,6 +373,17 @@ class TestImperativeResneXt(unittest.TestCase):
for
param
in
se_resnext
.
parameters
():
dy_param_value
[
param
.
name
]
=
param
.
numpy
()
return
dy_out
,
dy_param_init_value
,
dy_param_value
,
dy_grad_value
with
fluid
.
dygraph
.
guard
():
dy_out
,
dy_param_init_value
,
dy_param_value
,
dy_grad_value
=
run_dygraph
(
)
with
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
eager_out
,
eager_param_init_value
,
eager_param_value
,
eager_grad_value
=
run_dygraph
(
)
with
new_program_scope
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -479,6 +492,32 @@ class TestImperativeResneXt(unittest.TestCase):
self
.
assertTrue
(
np
.
isfinite
(
value
.
all
()))
self
.
assertFalse
(
np
.
isnan
(
value
.
any
()))
# check eager
self
.
assertTrue
(
np
.
allclose
(
static_out
,
eager_out
),
"
\n
static_out: {}
\n
eager_out: {}"
.
format
(
static_out
,
eager_out
))
self
.
assertEqual
(
len
(
eager_param_init_value
),
len
(
static_param_init_value
))
for
key
,
value
in
six
.
iteritems
(
static_param_init_value
):
self
.
assertTrue
(
np
.
allclose
(
value
,
eager_param_init_value
[
key
]))
self
.
assertEqual
(
len
(
eager_grad_value
),
len
(
static_grad_value
))
for
key
,
value
in
six
.
iteritems
(
static_grad_value
):
self
.
assertTrue
(
np
.
allclose
(
value
,
eager_grad_value
[
key
]),
"
\n
static_grad_value: {}
\n
eager_grad_value: {}"
.
format
(
value
,
eager_grad_value
[
key
]))
self
.
assertEqual
(
len
(
eager_param_value
),
len
(
static_param_value
))
for
key
,
value
in
six
.
iteritems
(
static_param_value
):
self
.
assertTrue
(
np
.
allclose
(
value
,
eager_param_value
[
key
]),
"
\n
static_param_value: {}
\n
eagear_param_value: {}"
.
format
(
value
,
eager_param_value
[
key
]))
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_imperative_transformer_sorted_gradient.py
浏览文件 @
4760fd96
...
...
@@ -21,6 +21,7 @@ from paddle.fluid import Embedding, LayerNorm, Linear, Layer
from
paddle.fluid.dygraph
import
to_variable
,
guard
from
paddle.fluid.dygraph
import
TracedLayer
from
test_imperative_base
import
new_program_scope
from
paddle.fluid.framework
import
_test_eager_guard
from
paddle.fluid
import
core
import
numpy
as
np
import
six
...
...
@@ -314,7 +315,7 @@ use_py_reader = False
sync
=
False
# how many batches we use
batch_num
=
5
batch_num
=
2
np
.
random
.
seed
(
90
)
src_word_np
=
np
.
arange
(
1
,
TrainTaskConfig
.
batch_size
*
seq_len
+
1
).
reshape
(
...
...
@@ -949,8 +950,7 @@ class TestDygraphTransformerSortGradient(unittest.TestCase):
def
transformer_sort_gradient_float32
(
self
,
is_sparse
):
seed
=
90
with
guard
():
fluid
.
set_flags
({
'FLAGS_sort_sum_gradient'
:
True
})
def
run_dygraph
():
# NOTE(xiongkun03): In new executor, the inplace strategy is on by default, which will cause result of sumop have some differences. So we disable inplace.
fluid
.
set_flags
({
'FLAGS_new_executor_use_inplace'
:
False
})
paddle
.
seed
(
seed
)
...
...
@@ -998,7 +998,7 @@ class TestDygraphTransformerSortGradient(unittest.TestCase):
for
i
in
range
(
batch_num
):
enc_inputs
,
dec_inputs
,
label
,
weights
=
create_data
()
if
i
%
2
==
0
:
if
False
:
outs
,
traced_layer
=
TracedLayer
.
trace
(
transformer
,
[
enc_inputs
,
dec_inputs
,
label
,
weights
])
...
...
@@ -1036,6 +1036,14 @@ class TestDygraphTransformerSortGradient(unittest.TestCase):
dy_predict_value
=
dy_predict
.
numpy
()
dy_token_num_value
=
dy_token_num
.
numpy
()
return
dy_avg_cost_value
,
dy_sum_cost_value
,
dy_predict_value
,
dy_token_num_value
,
\
dy_param_init
,
dy_param_updated
with
guard
():
fluid
.
set_flags
({
'FLAGS_sort_sum_gradient'
:
True
})
dy_avg_cost_value
,
dy_sum_cost_value
,
dy_predict_value
,
dy_token_num_value
,
\
dy_param_init
,
dy_param_updated
=
run_dygraph
()
with
new_program_scope
():
paddle
.
seed
(
seed
)
paddle
.
framework
.
random
.
_manual_program_seed
(
seed
)
...
...
@@ -1122,6 +1130,28 @@ class TestDygraphTransformerSortGradient(unittest.TestCase):
for
key
,
value
in
six
.
iteritems
(
static_param_updated
):
self
.
assertTrue
(
np
.
array_equal
(
value
,
dy_param_updated
[
key
]))
# check eager result
with
guard
():
fluid
.
set_flags
({
'FLAGS_sort_sum_gradient'
:
False
})
dy_avg_cost_value
,
dy_sum_cost_value
,
dy_predict_value
,
dy_token_num_value
,
\
dy_param_init
,
dy_param_updated
=
run_dygraph
()
with
guard
():
with
_test_eager_guard
():
eager_avg_cost_value
,
eager_sum_cost_value
,
eager_predict_value
,
eager_token_num_value
,
\
eager_param_init
,
eager_param_updated
=
run_dygraph
()
self
.
assertTrue
(
np
.
allclose
(
dy_avg_cost_value
,
eager_avg_cost_value
))
self
.
assertTrue
(
np
.
allclose
(
dy_sum_cost_value
,
eager_sum_cost_value
))
self
.
assertTrue
(
np
.
allclose
(
dy_predict_value
,
eager_predict_value
))
self
.
assertTrue
(
np
.
allclose
(
dy_token_num_value
,
eager_token_num_value
))
for
key
,
value
in
six
.
iteritems
(
static_param_init
):
self
.
assertTrue
(
np
.
array_equal
(
value
,
eager_param_init
[
key
]))
for
key
,
value
in
six
.
iteritems
(
dy_param_updated
):
self
.
assertTrue
(
np
.
allclose
(
value
,
eager_param_updated
[
key
]))
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录