Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
db41e39e
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
db41e39e
编写于
3月 23, 2022
作者:
W
Weilong Wu
提交者:
GitHub
3月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support test_layers(group_norm,while_loop) with eager mode (#40816)
上级
fdafbc7b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
4 deletion
+19
-4
paddle/fluid/pybind/op_function_generator.h
paddle/fluid/pybind/op_function_generator.h
+1
-0
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+6
-0
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+12
-4
未找到文件。
paddle/fluid/pybind/op_function_generator.h
浏览文件 @
db41e39e
...
@@ -89,6 +89,7 @@ std::map<std::string, std::set<std::string>> op_ins_map = {
...
@@ -89,6 +89,7 @@ std::map<std::string, std::set<std::string>> op_ins_map = {
{
"Input"
,
"Label"
,
"Weight"
,
"Bias"
,
"SampleWeight"
,
"CustomDistProbs"
,
{
"Input"
,
"Label"
,
"Weight"
,
"Bias"
,
"SampleWeight"
,
"CustomDistProbs"
,
"CustomDistAlias"
,
"CustomDistAliasProbs"
}},
"CustomDistAlias"
,
"CustomDistAliasProbs"
}},
{
"check_finite_and_unscale"
,
{
"X"
,
"Scale"
,
"FloatStatus"
}},
{
"check_finite_and_unscale"
,
{
"X"
,
"Scale"
,
"FloatStatus"
}},
{
"group_norm"
,
{
"X"
,
"Scale"
,
"Bias"
}},
};
};
// NOTE(zhiqiu): Like op_ins_map.
// NOTE(zhiqiu): Like op_ins_map.
...
...
python/paddle/fluid/dygraph/nn.py
浏览文件 @
db41e39e
...
@@ -2986,6 +2986,12 @@ class GroupNorm(layers.Layer):
...
@@ -2986,6 +2986,12 @@ class GroupNorm(layers.Layer):
is_bias
=
True
)
is_bias
=
True
)
def
forward
(
self
,
input
):
def
forward
(
self
,
input
):
if
in_dygraph_mode
():
attrs
=
(
'epsilon'
,
self
.
_epsilon
,
'groups'
,
self
.
_groups
)
out
,
_
,
_
=
_C_ops
.
group_norm
(
input
,
self
.
weight
,
self
.
bias
,
*
attrs
)
return
dygraph_utils
.
_append_activation_in_dygraph
(
out
,
self
.
_act
)
inputs
=
{
'X'
:
input
}
inputs
=
{
'X'
:
input
}
if
self
.
bias
is
not
None
:
if
self
.
bias
is
not
None
:
inputs
[
'Bias'
]
=
self
.
bias
inputs
[
'Bias'
]
=
self
.
bias
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
db41e39e
...
@@ -1819,7 +1819,7 @@ class TestLayer(LayerTest):
...
@@ -1819,7 +1819,7 @@ class TestLayer(LayerTest):
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
static_ret2
))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
static_ret2
))
def
test
_group_norm
(
self
):
def
func
_group_norm
(
self
):
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
place
=
core
.
CUDAPlace
(
0
)
place
=
core
.
CUDAPlace
(
0
)
else
:
else
:
...
@@ -1873,7 +1873,6 @@ class TestLayer(LayerTest):
...
@@ -1873,7 +1873,6 @@ class TestLayer(LayerTest):
with_lod
=
True
)[
0
]
with_lod
=
True
)[
0
]
with
self
.
dynamic_graph
():
with
self
.
dynamic_graph
():
# TODO(wuweilong): Add with _test_eager_guard():
groupNorm
=
nn
.
GroupNorm
(
groupNorm
=
nn
.
GroupNorm
(
channels
=
shape
[
1
],
channels
=
shape
[
1
],
groups
=
2
,
groups
=
2
,
...
@@ -1886,6 +1885,11 @@ class TestLayer(LayerTest):
...
@@ -1886,6 +1885,11 @@ class TestLayer(LayerTest):
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
dy_rlt_value
))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
dy_rlt_value
))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
static_ret2
))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
static_ret2
))
def
test_group_norm
(
self
):
with
_test_eager_guard
():
self
.
func_group_norm
()
self
.
func_group_norm
()
def
test_instance_norm
(
self
):
def
test_instance_norm
(
self
):
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
place
=
core
.
CUDAPlace
(
0
)
place
=
core
.
CUDAPlace
(
0
)
...
@@ -2348,7 +2352,7 @@ class TestLayer(LayerTest):
...
@@ -2348,7 +2352,7 @@ class TestLayer(LayerTest):
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
(
TypeError
):
layers
.
eye
(
num_rows
=
3
,
batch_shape
=
[
-
1
])
layers
.
eye
(
num_rows
=
3
,
batch_shape
=
[
-
1
])
def
test
_while_loop
(
self
):
def
func
_while_loop
(
self
):
with
self
.
static_graph
():
with
self
.
static_graph
():
i
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
0
)
i
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
0
)
ten
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
10
)
ten
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
10
)
...
@@ -2363,7 +2367,6 @@ class TestLayer(LayerTest):
...
@@ -2363,7 +2367,6 @@ class TestLayer(LayerTest):
static_ret
=
self
.
get_static_graph_result
(
feed
=
{},
fetch_list
=
out
)
static_ret
=
self
.
get_static_graph_result
(
feed
=
{},
fetch_list
=
out
)
with
self
.
dynamic_graph
():
with
self
.
dynamic_graph
():
# TODO(wuweilong): Add with _test_eager_guard():
i
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
0
)
i
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
0
)
ten
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
10
)
ten
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
10
)
...
@@ -2384,6 +2387,11 @@ class TestLayer(LayerTest):
...
@@ -2384,6 +2387,11 @@ class TestLayer(LayerTest):
self
.
assertTrue
(
np
.
array_equal
(
static_ret
[
0
],
dy_ret
[
0
].
numpy
()))
self
.
assertTrue
(
np
.
array_equal
(
static_ret
[
0
],
dy_ret
[
0
].
numpy
()))
def
test_while_loop
(
self
):
with
_test_eager_guard
():
self
.
func_while_loop
()
self
.
func_while_loop
()
def
test_compare
(
self
):
def
test_compare
(
self
):
value_a
=
np
.
arange
(
3
)
value_a
=
np
.
arange
(
3
)
value_b
=
np
.
arange
(
3
)
value_b
=
np
.
arange
(
3
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录