Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
dbe189b1
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看板
未验证
提交
dbe189b1
编写于
4月 29, 2022
作者:
Y
YuanRisheng
提交者:
GitHub
4月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unit test for batch_norm and leaky_relu (#42369)
上级
5faf76b7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
2 deletion
+34
-2
paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py
...uto_code_generator/final_state_generator/codegen_utils.py
+1
-1
python/paddle/fluid/tests/unittests/test_activation_nn_grad.py
...n/paddle/fluid/tests/unittests/test_activation_nn_grad.py
+5
-0
python/paddle/fluid/tests/unittests/test_norm_nn_grad.py
python/paddle/fluid/tests/unittests/test_norm_nn_grad.py
+28
-1
未找到文件。
paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py
浏览文件 @
dbe189b1
...
...
@@ -27,7 +27,7 @@ ops_to_fill_zero_for_empty_grads = set([
"add_triple_grad"
,
"multiply_double_grad"
,
"multiply_triple_grad"
,
"conv2d_grad_grad"
,
"batch_norm_double_grad"
,
"tanh_double_grad"
,
"tanh_triple_grad"
,
"subtract_double_grad"
,
"divide_double_grad"
,
"log_double_grad"
,
"elu_double_grad"
"log_double_grad"
,
"elu_double_grad"
,
"leaky_relu_double_grad"
])
# For API dispatch used at python-level
...
...
python/paddle/fluid/tests/unittests/test_activation_nn_grad.py
浏览文件 @
dbe189b1
...
...
@@ -161,6 +161,9 @@ class TestReluDoubleGradCheck(unittest.TestCase):
class
TestLeakyReluDoubleGradCheck
(
unittest
.
TestCase
):
def
leaky_relu_wrapper
(
self
,
x
):
return
paddle
.
nn
.
functional
.
leaky_relu
(
x
[
0
],
negative_slope
=
0.2
)
@
prog_scope
()
def
func
(
self
,
place
):
shape
=
[
2
,
3
,
7
,
9
]
...
...
@@ -177,6 +180,8 @@ class TestLeakyReluDoubleGradCheck(unittest.TestCase):
gradient_checker
.
double_grad_check
(
[
x
],
y
,
x_init
=
x_arr
,
place
=
place
,
eps
=
eps
)
gradient_checker
.
double_grad_check_for_dygraph
(
self
.
leaky_relu_wrapper
,
[
x
],
y
,
x_init
=
x_arr
,
place
=
place
)
def
test_grad
(
self
):
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_norm_nn_grad.py
浏览文件 @
dbe189b1
...
...
@@ -43,6 +43,7 @@ class TestInstanceNormDoubleGradCheck(unittest.TestCase):
[
x
],
z
,
x_init
=
x_arr
,
atol
=
atol
,
place
=
place
,
eps
=
eps
)
def
test_grad
(
self
):
paddle
.
enable_static
()
places
=
[
fluid
.
CPUPlace
()]
if
core
.
is_compiled_with_cuda
():
places
.
append
(
fluid
.
CUDAPlace
(
0
))
...
...
@@ -77,6 +78,14 @@ class TestBatchNormDoubleGradCheck(unittest.TestCase):
self
.
data_layout
=
'NCHW'
self
.
use_global_stats
=
False
self
.
shape
=
[
2
,
3
,
4
,
5
]
self
.
channel_index
=
1
def
batch_norm_wrapper
(
self
,
x
):
batch_norm
=
paddle
.
nn
.
BatchNorm2D
(
self
.
shape
[
self
.
channel_index
],
data_format
=
self
.
data_layout
,
use_global_stats
=
self
.
use_global_stats
)
return
batch_norm
(
x
[
0
])
@
prog_scope
()
def
func
(
self
,
place
):
...
...
@@ -94,8 +103,15 @@ class TestBatchNormDoubleGradCheck(unittest.TestCase):
x_arr
=
np
.
random
.
uniform
(
-
1
,
1
,
self
.
shape
).
astype
(
dtype
)
gradient_checker
.
double_grad_check
(
[
x
],
z
,
x_init
=
x_arr
,
atol
=
atol
,
place
=
place
,
eps
=
eps
)
gradient_checker
.
double_grad_check_for_dygraph
(
self
.
batch_norm_wrapper
,
[
x
],
z
,
x_init
=
x_arr
,
atol
=
atol
,
place
=
place
)
def
test_grad
(
self
):
paddle
.
enable_static
()
places
=
[
fluid
.
CPUPlace
()]
if
core
.
is_compiled_with_cuda
():
places
.
append
(
fluid
.
CUDAPlace
(
0
))
...
...
@@ -108,6 +124,7 @@ class TestBatchNormDoubleGradCheckCase1(TestBatchNormDoubleGradCheck):
self
.
data_layout
=
'NHWC'
self
.
use_global_stats
=
False
self
.
shape
=
[
2
,
3
,
4
,
5
]
self
.
channel_index
=
3
class
TestBatchNormDoubleGradCheckCase2
(
TestBatchNormDoubleGradCheck
):
...
...
@@ -115,6 +132,7 @@ class TestBatchNormDoubleGradCheckCase2(TestBatchNormDoubleGradCheck):
self
.
data_layout
=
'NCHW'
self
.
use_global_stats
=
True
self
.
shape
=
[
2
,
3
,
4
,
5
]
self
.
channel_index
=
1
class
TestBatchNormDoubleGradCheckCase3
(
TestBatchNormDoubleGradCheck
):
...
...
@@ -122,6 +140,7 @@ class TestBatchNormDoubleGradCheckCase3(TestBatchNormDoubleGradCheck):
self
.
data_layout
=
'NHWC'
self
.
use_global_stats
=
True
self
.
shape
=
[
2
,
3
,
4
,
5
]
self
.
channel_index
=
3
class
TestBatchNormDoubleGradCheckCase4
(
TestBatchNormDoubleGradCheck
):
...
...
@@ -129,6 +148,14 @@ class TestBatchNormDoubleGradCheckCase4(TestBatchNormDoubleGradCheck):
self
.
data_layout
=
'NCHW'
self
.
use_global_stats
=
False
self
.
shape
=
[
2
,
2
,
3
,
4
,
5
]
self
.
channel_index
=
1
def
batch_norm_wrapper
(
self
,
x
):
batch_norm
=
paddle
.
nn
.
BatchNorm3D
(
self
.
shape
[
self
.
channel_index
],
data_format
=
self
.
data_layout
,
use_global_stats
=
self
.
use_global_stats
)
return
batch_norm
(
x
[
0
])
class
TestBatchNormDoubleGradCheckCase5
(
TestBatchNormDoubleGradCheck
):
...
...
@@ -165,8 +192,8 @@ class TestBatchNormDoubleGradCheckCase6(TestBatchNormDoubleGradCheckCase5):
self
.
data_layout
=
'NCHW'
self
.
use_global_stats
=
True
self
.
shape
=
[
2
,
3
,
4
,
5
]
self
.
channel_index
=
1
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录