Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
52575304
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
52575304
编写于
3月 18, 2020
作者:
L
Leo Chen
提交者:
GitHub
3月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
don't add unregisterd attr, test=develop (#23047)
* don't add unregisterd attr, test=develop * add some unittests,test=develop
上级
91a26272
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
8 deletion
+52
-8
python/paddle/fluid/dygraph_utils.py
python/paddle/fluid/dygraph_utils.py
+8
-8
python/paddle/fluid/tests/unittests/test_imperative_basic.py
python/paddle/fluid/tests/unittests/test_imperative_basic.py
+44
-0
未找到文件。
python/paddle/fluid/dygraph_utils.py
浏览文件 @
52575304
...
...
@@ -19,8 +19,8 @@ from .framework import dygraph_only
@
dygraph_only
def
_append_activation_in_dygraph
(
input
,
act
=
None
,
use_cudnn
=
Fals
e
,
use_mkldnn
=
Fals
e
):
use_cudnn
=
Non
e
,
use_mkldnn
=
Non
e
):
"""Append activation in dygraph mode.
Args:
...
...
@@ -33,8 +33,11 @@ def _append_activation_in_dygraph(input,
"""
if
not
act
:
return
input
attrs
=
{
'use_cudnn'
:
use_cudnn
,
'use_mkldnn'
:
use_mkldnn
}
attrs
=
{}
if
(
use_cudnn
is
not
None
)
and
use_cudnn
:
attrs
[
'use_cudnn'
]
=
use_cudnn
if
(
use_mkldnn
is
not
None
)
and
use_mkldnn
:
attrs
[
'use_mkldnn'
]
=
use_mkldnn
inputs
=
{
"X"
:
[
input
]}
act_op
=
getattr
(
core
.
ops
,
act
)
res
=
act_op
(
inputs
,
attrs
)
...
...
@@ -42,10 +45,7 @@ def _append_activation_in_dygraph(input,
@
dygraph_only
def
_append_bias_in_dygraph
(
input
,
bias
=
None
,
axis
=
1
,
):
def
_append_bias_in_dygraph
(
input
,
bias
=
None
,
axis
=
1
):
"""Append bias operation in dygraph mode.
Args:
...
...
python/paddle/fluid/tests/unittests/test_imperative_basic.py
浏览文件 @
52575304
...
...
@@ -20,6 +20,7 @@ import paddle.fluid as fluid
from
paddle.fluid
import
core
from
paddle.fluid
import
Linear
from
test_imperative_base
import
new_program_scope
import
paddle.fluid.dygraph_utils
as
dygraph_utils
class
MyLayer
(
fluid
.
Layer
):
...
...
@@ -536,5 +537,48 @@ class TestImperative(unittest.TestCase):
self
.
assertEqual
(
len
(
my_layer
.
sublayers
()),
0
)
class
TestDygraphUtils
(
unittest
.
TestCase
):
def
test_append_activation_in_dygraph_exception
(
self
):
with
new_program_scope
():
np_inp
=
np
.
random
.
random
(
size
=
(
10
,
20
,
30
)).
astype
(
np
.
float32
)
a
=
fluid
.
layers
.
data
(
"a"
,
[
10
,
20
])
func
=
dygraph_utils
.
_append_activation_in_dygraph
self
.
assertRaises
(
AssertionError
,
func
,
a
,
act
=
"sigmoid"
)
def
test_append_activation_in_dygraph1
(
self
):
a_np
=
np
.
random
.
random
(
size
=
(
10
,
20
,
30
)).
astype
(
np
.
float32
)
func
=
dygraph_utils
.
_append_activation_in_dygraph
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
res1
=
func
(
a
,
act
=
"hard_sigmoid"
)
res2
=
fluid
.
layers
.
hard_sigmoid
(
a
)
self
.
assertTrue
(
np
.
array_equal
(
res1
.
numpy
(),
res2
.
numpy
()))
def
test_append_activation_in_dygraph2
(
self
):
a_np
=
np
.
random
.
random
(
size
=
(
10
,
20
,
30
)).
astype
(
np
.
float32
)
func
=
dygraph_utils
.
_append_activation_in_dygraph
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
res1
=
func
(
a
,
act
=
"sigmoid"
,
use_mkldnn
=
True
,
use_cudnn
=
True
)
res2
=
fluid
.
layers
.
sigmoid
(
a
)
self
.
assertTrue
(
np
.
array_equal
(
res1
.
numpy
(),
res2
.
numpy
()))
def
test_append_bias_in_dygraph_exception
(
self
):
with
new_program_scope
():
np_inp
=
np
.
random
.
random
(
size
=
(
10
,
20
,
30
)).
astype
(
np
.
float32
)
a
=
fluid
.
layers
.
data
(
"a"
,
[
10
,
20
])
func
=
dygraph_utils
.
_append_bias_in_dygraph
self
.
assertRaises
(
AssertionError
,
func
,
a
)
def
test_append_bias_in_dygraph
(
self
):
a_np
=
np
.
random
.
random
(
size
=
(
10
,
20
,
30
)).
astype
(
np
.
float32
)
func
=
dygraph_utils
.
_append_bias_in_dygraph
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
res1
=
func
(
a
,
bias
=
a
)
res2
=
a
+
a
self
.
assertTrue
(
np
.
array_equal
(
res1
.
numpy
(),
res2
.
numpy
()))
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录