Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1a13fa0f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
1a13fa0f
编写于
3月 18, 2022
作者:
F
furnace
提交者:
GitHub
3月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] fix fp16 (PART II) (#40537)
[NPU] fix fp16 (PART II)
上级
ef4ef154
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
255 addition
and
189 deletion
+255
-189
paddle/fluid/operators/conv_op_npu.cc
paddle/fluid/operators/conv_op_npu.cc
+1
-1
paddle/fluid/operators/pad_op_npu.cc
paddle/fluid/operators/pad_op_npu.cc
+1
-1
python/paddle/fluid/tests/unittests/npu/CMakeLists.txt
python/paddle/fluid/tests/unittests/npu/CMakeLists.txt
+1
-0
python/paddle/fluid/tests/unittests/npu/test_conv2d_op_depthwise_conv_npu.py
.../tests/unittests/npu/test_conv2d_op_depthwise_conv_npu.py
+69
-41
python/paddle/fluid/tests/unittests/npu/test_conv2d_op_npu.py
...on/paddle/fluid/tests/unittests/npu/test_conv2d_op_npu.py
+37
-26
python/paddle/fluid/tests/unittests/npu/test_elementwise_add_op_npu.py
.../fluid/tests/unittests/npu/test_elementwise_add_op_npu.py
+43
-20
python/paddle/fluid/tests/unittests/npu/test_elementwise_max_op_npu.py
.../fluid/tests/unittests/npu/test_elementwise_max_op_npu.py
+0
-12
python/paddle/fluid/tests/unittests/npu/test_elementwise_min_op_npu.py
.../fluid/tests/unittests/npu/test_elementwise_min_op_npu.py
+29
-20
python/paddle/fluid/tests/unittests/npu/test_elementwise_pow_op_npu.py
.../fluid/tests/unittests/npu/test_elementwise_pow_op_npu.py
+0
-8
python/paddle/fluid/tests/unittests/npu/test_expand_op_npu.py
...on/paddle/fluid/tests/unittests/npu/test_expand_op_npu.py
+5
-9
python/paddle/fluid/tests/unittests/npu/test_huber_loss_op_npu.py
...addle/fluid/tests/unittests/npu/test_huber_loss_op_npu.py
+0
-6
python/paddle/fluid/tests/unittests/npu/test_label_smooth_op_npu.py
...dle/fluid/tests/unittests/npu/test_label_smooth_op_npu.py
+4
-2
python/paddle/fluid/tests/unittests/npu/test_leaky_relu_op_npu.py
...addle/fluid/tests/unittests/npu/test_leaky_relu_op_npu.py
+4
-2
python/paddle/fluid/tests/unittests/npu/test_log_softmax_op_npu.py
...ddle/fluid/tests/unittests/npu/test_log_softmax_op_npu.py
+7
-3
python/paddle/fluid/tests/unittests/npu/test_lookup_table_v2_op_npu.py
.../fluid/tests/unittests/npu/test_lookup_table_v2_op_npu.py
+4
-2
python/paddle/fluid/tests/unittests/npu/test_nearest_interp_v2_op_npu.py
...luid/tests/unittests/npu/test_nearest_interp_v2_op_npu.py
+22
-3
python/paddle/fluid/tests/unittests/npu/test_pad_op_npu.py
python/paddle/fluid/tests/unittests/npu/test_pad_op_npu.py
+4
-3
python/paddle/fluid/tests/unittests/npu/test_relu_op_npu.py
python/paddle/fluid/tests/unittests/npu/test_relu_op_npu.py
+12
-25
python/paddle/fluid/tests/unittests/npu/test_slice_op_npu.py
python/paddle/fluid/tests/unittests/npu/test_slice_op_npu.py
+12
-5
未找到文件。
paddle/fluid/operators/conv_op_npu.cc
浏览文件 @
1a13fa0f
...
...
@@ -356,7 +356,7 @@ class NPUConvGradOpKernel : public framework::OpKernel<T> {
auto
stream
=
ctx
.
template
device_context
<
NPUDeviceContext
>().
stream
();
if
(
filter_grad
)
{
filter_grad
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
filter_grad
->
mutable_data
<
float
>
(
ctx
.
GetPlace
());
std
::
vector
<
int
>
filter_shape_vec
=
phi
::
vectorize
<
int
>
(
filter
->
dims
());
const
auto
&
runner
=
NpuOpRunner
(
...
...
paddle/fluid/operators/pad_op_npu.cc
浏览文件 @
1a13fa0f
...
...
@@ -90,5 +90,5 @@ namespace plat = paddle::platform;
REGISTER_OP_NPU_KERNEL
(
pad
,
ops
::
PadNPUKernel
<
plat
::
float16
>
,
ops
::
PadNPUKernel
<
float
>
,
ops
::
PadNPUKernel
<
int
>
);
REGISTER_OP_NPU_KERNEL
(
pad_grad
,
ops
::
PadNPUKernel
<
plat
::
float16
>
,
REGISTER_OP_NPU_KERNEL
(
pad_grad
,
ops
::
Pad
Grad
NPUKernel
<
plat
::
float16
>
,
ops
::
PadGradNPUKernel
<
float
>
);
python/paddle/fluid/tests/unittests/npu/CMakeLists.txt
浏览文件 @
1a13fa0f
...
...
@@ -22,4 +22,5 @@ if (WITH_ASCEND_CL)
set_tests_properties
(
test_conv2d_transpose_op_npu PROPERTIES TIMEOUT 200
)
set_tests_properties
(
test_conv2d_op_npu PROPERTIES TIMEOUT 300
)
set_tests_properties
(
test_matmulv2_op_npu PROPERTIES TIMEOUT 300
)
set_tests_properties
(
test_elementwise_add_op_npu PROPERTIES TIMEOUT 200
)
endif
()
python/paddle/fluid/tests/unittests/npu/test_conv2d_op_depthwise_conv_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -132,9 +132,13 @@ class TestDepthwiseConvNPU(OpTest):
self
.
check_output_with_place
(
self
.
place
,
atol
=
1e-2
)
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
if
self
.
dilations
[
0
]
==
1
and
self
.
dilations
[
1
]
==
1
:
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
{
'Input'
,
'Filter'
},
'Output'
,
max_relative_error
=
0.9
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
{
'Input'
,
'Filter'
},
'Output'
,
...
...
@@ -143,7 +147,12 @@ class TestDepthwiseConvNPU(OpTest):
def
test_check_grad_no_filter
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Output'
,
no_grad_set
=
set
([
'Filter'
]),
max_relative_error
=
0.9
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Output'
,
...
...
@@ -152,9 +161,14 @@ class TestDepthwiseConvNPU(OpTest):
numeric_place
=
paddle
.
CPUPlace
())
def
test_check_grad_no_input
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
if
self
.
dilations
[
0
]
==
1
and
self
.
dilations
[
1
]
==
1
:
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Filter'
],
'Output'
,
no_grad_set
=
set
([
'Input'
]),
max_relative_error
=
0.9
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Filter'
],
'Output'
,
...
...
@@ -267,7 +281,11 @@ class TestDepthwiseConvNPU_Padding(OpTest):
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
{
'Input'
,
'Filter'
},
'Output'
,
max_relative_error
=
1.2
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
{
'Input'
,
'Filter'
},
'Output'
,
...
...
@@ -276,7 +294,12 @@ class TestDepthwiseConvNPU_Padding(OpTest):
def
test_check_grad_no_filter
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Output'
,
max_relative_error
=
0.7
,
no_grad_set
=
set
([
'Filter'
]))
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Output'
,
...
...
@@ -286,7 +309,12 @@ class TestDepthwiseConvNPU_Padding(OpTest):
def
test_check_grad_no_input
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Filter'
],
'Output'
,
max_relative_error
=
0.8
,
no_grad_set
=
set
([
'Input'
]))
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Filter'
],
'Output'
,
...
...
python/paddle/fluid/tests/unittests/npu/test_conv2d_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -127,8 +127,6 @@ class TestConv2DOp(OpTest):
self
.
check_output_with_place
(
fluid
.
NPUPlace
(
0
),
atol
=
1e-2
)
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
fluid
.
NPUPlace
(
0
),
{
'Input'
,
'Filter'
},
'Output'
,
...
...
@@ -136,8 +134,6 @@ class TestConv2DOp(OpTest):
numeric_place
=
paddle
.
CPUPlace
())
def
test_check_grad_no_filter
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
fluid
.
NPUPlace
(
0
),
[
'Input'
],
'Output'
,
...
...
@@ -146,8 +142,6 @@ class TestConv2DOp(OpTest):
numeric_place
=
paddle
.
CPUPlace
())
def
test_check_grad_no_input
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
fluid
.
NPUPlace
(
0
),
[
'Filter'
],
'Output'
,
...
...
@@ -276,10 +270,13 @@ class TestConv2DOp_v2(OpTest):
def
set_npu
(
self
):
self
.
__class__
.
use_npu
=
True
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float32
def
setUp
(
self
):
self
.
set_npu
()
self
.
op_type
=
"conv2d"
self
.
dtype
=
np
.
float32
self
.
init_dtype
()
self
.
init_kernel_type
()
self
.
init_group
()
self
.
init_dilation
()
...
...
@@ -320,7 +317,11 @@ class TestConv2DOp_v2(OpTest):
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
paddle
.
NPUPlace
(
0
),
{
'Input'
,
'Filter'
},
'Output'
,
max_relative_error
=
1.1
)
else
:
self
.
check_grad_with_place
(
paddle
.
NPUPlace
(
0
),
{
'Input'
,
'Filter'
},
'Output'
,
...
...
@@ -329,7 +330,12 @@ class TestConv2DOp_v2(OpTest):
def
test_check_grad_no_filter
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
paddle
.
NPUPlace
(
0
),
[
'Input'
],
'Output'
,
max_relative_error
=
0.99
,
no_grad_set
=
set
([
'Filter'
]))
else
:
self
.
check_grad_with_place
(
paddle
.
NPUPlace
(
0
),
[
'Input'
],
'Output'
,
...
...
@@ -339,7 +345,12 @@ class TestConv2DOp_v2(OpTest):
def
test_check_grad_no_input
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
paddle
.
NPUPlace
(
0
),
[
'Filter'
],
'Output'
,
max_relative_error
=
0.99
,
no_grad_set
=
set
([
'Input'
]))
else
:
self
.
check_grad_with_place
(
paddle
.
NPUPlace
(
0
),
[
'Filter'
],
'Output'
,
...
...
python/paddle/fluid/tests/unittests/npu/test_elementwise_add_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -65,9 +65,16 @@ class TestElementwiseAddOp(OpTest):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
or
self
.
dtype
==
np
.
int64
:
if
self
.
dtype
==
np
.
int64
:
return
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
max_relative_error
=
0.15
,
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
...
...
@@ -75,9 +82,17 @@ class TestElementwiseAddOp(OpTest):
max_relative_error
=
0.006
,
)
def
test_check_grad_ingore_x
(
self
):
if
self
.
dtype
==
np
.
float16
or
self
.
dtype
==
np
.
int64
:
if
self
.
dtype
==
np
.
int64
:
return
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
'Out'
,
no_grad_set
=
set
(
"X"
),
max_relative_error
=
0.92
,
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
...
...
@@ -86,9 +101,17 @@ class TestElementwiseAddOp(OpTest):
max_relative_error
=
0.006
,
)
def
test_check_grad_ingore_y
(
self
):
if
self
.
dtype
==
np
.
float16
or
self
.
dtype
==
np
.
int64
:
if
self
.
dtype
==
np
.
int64
:
return
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
no_grad_set
=
set
(
"Y"
),
max_relative_error
=
0.8
,
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
...
...
python/paddle/fluid/tests/unittests/npu/test_elementwise_max_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -116,19 +116,13 @@ class TestElementwiseMaxOp(OpTest):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
)
def
test_check_grad_ingore_x
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
'Out'
,
no_grad_set
=
set
(
"X"
))
def
test_check_grad_ingore_y
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
no_grad_set
=
set
(
"Y"
))
...
...
@@ -213,15 +207,11 @@ class TestElementwiseMaxOp_broadcast_2(TestElementwiseMaxOp):
self
.
out
=
np
.
maximum
(
self
.
x
,
self
.
y
.
reshape
(
1
,
1
,
100
))
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
dx
,
dy
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
user_defined_grads
=
[
dx
,
dy
])
def
test_check_grad_ingore_x
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
_
,
dy
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
...
...
@@ -230,8 +220,6 @@ class TestElementwiseMaxOp_broadcast_2(TestElementwiseMaxOp):
user_defined_grads
=
[
dy
])
def
test_check_grad_ingore_y
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
dx
,
_
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
...
...
python/paddle/fluid/tests/unittests/npu/test_elementwise_min_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -64,8 +64,9 @@ class TestElementwiseMinOp(OpTest):
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
max_relative_error
=
0.5
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
...
...
@@ -73,8 +74,12 @@ class TestElementwiseMinOp(OpTest):
def
test_check_grad_ingore_x
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
'Out'
,
no_grad_set
=
set
(
"X"
),
max_relative_error
=
0.9
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
...
...
@@ -83,8 +88,12 @@ class TestElementwiseMinOp(OpTest):
def
test_check_grad_ingore_y
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
no_grad_set
=
set
(
"Y"
),
max_relative_error
=
0.1
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
...
...
python/paddle/fluid/tests/unittests/npu/test_elementwise_pow_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -114,8 +114,6 @@ class TestElementwisePow(OpTest):
self
.
out
=
np
.
power
(
self
.
x
,
self
.
y
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
dx
,
dy
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
user_defined_grads
=
[
dx
,
dy
])
...
...
@@ -184,8 +182,6 @@ class TestElementwisePowOp_broadcast_0(TestElementwisePow):
self
.
out
=
np
.
power
(
self
.
x
,
self
.
y
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
dx
,
dy
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
user_defined_grads
=
[
dx
,
dy
])
...
...
@@ -218,8 +214,6 @@ class TestElementwisePowOp_broadcast_1(TestElementwisePow):
self
.
out
=
np
.
power
(
self
.
x
,
self
.
y
.
reshape
(
1
,
100
,
1
))
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
dx
,
dy
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
user_defined_grads
=
[
dx
,
dy
])
...
...
@@ -252,8 +246,6 @@ class TestElementwisePowOp_broadcast_2(TestElementwisePow):
self
.
out
=
np
.
power
(
self
.
x
,
self
.
y
.
reshape
(
100
,
1
,
1
))
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
dx
,
dy
=
ComputeGrad
(
self
.
x
,
self
.
y
,
self
.
out
,
self
.
axis
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
user_defined_grads
=
[
dx
,
dy
])
...
...
python/paddle/fluid/tests/unittests/npu/test_expand_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -34,7 +34,7 @@ class TestExpand(OpTest):
self
.
init_dtype
()
np
.
random
.
seed
(
SEED
)
x
=
np
.
random
.
randn
(
3
,
1
,
7
).
astype
(
self
.
dtype
)
x
=
np
.
random
.
randn
(
3
0
,
1
,
7
).
astype
(
self
.
dtype
)
out
=
np
.
tile
(
x
,
[
1
,
10
,
1
])
self
.
inputs
=
{
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
)}
...
...
@@ -50,12 +50,8 @@ class TestExpand(OpTest):
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
# TODO(ascendrc): Add grad test
# def test_check_grad(self):
# if self.dtype == np.float16:
# return
# self.check_grad(['X'], 'Out')
#
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
class
TestExpandV2
(
TestExpand
):
...
...
@@ -66,7 +62,7 @@ class TestExpandV2(TestExpand):
self
.
init_dtype
()
np
.
random
.
seed
(
SEED
)
x
=
np
.
random
.
randn
(
3
,
1
,
7
).
astype
(
self
.
dtype
)
x
=
np
.
random
.
randn
(
3
0
,
1
,
7
).
astype
(
self
.
dtype
)
out
=
np
.
tile
(
x
,
[
1
,
10
,
1
])
expand_times
=
np
.
array
([
1
,
10
,
1
]).
astype
(
np
.
int32
)
...
...
@@ -145,7 +141,7 @@ class TestExpand_expand_times_all_one(TestExpand):
self
.
init_dtype
()
np
.
random
.
seed
(
SEED
)
x
=
np
.
random
.
randn
(
3
,
1
,
7
).
astype
(
self
.
dtype
)
x
=
np
.
random
.
randn
(
3
0
,
1
,
7
).
astype
(
self
.
dtype
)
out
=
np
.
tile
(
x
,
[
1
,
1
,
1
])
self
.
inputs
=
{
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
)}
...
...
python/paddle/fluid/tests/unittests/npu/test_huber_loss_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -81,13 +81,9 @@ class TestHuberLossOp(OpTest):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
)
def
test_check_grad_ingore_x
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
'Out'
,
...
...
@@ -95,8 +91,6 @@ class TestHuberLossOp(OpTest):
no_grad_set
=
set
(
"residual"
))
def
test_check_grad_ingore_y
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
...
...
python/paddle/fluid/tests/unittests/npu/test_label_smooth_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -78,7 +78,9 @@ class TestLabelSmoothOp(OpTest):
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
max_relative_error
=
0.5
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
...
...
python/paddle/fluid/tests/unittests/npu/test_leaky_relu_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -63,7 +63,9 @@ class TestLeadyRelu(OpTest):
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
max_relative_error
=
0.006
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
...
...
python/paddle/fluid/tests/unittests/npu/test_log_softmax_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -63,7 +63,11 @@ class TestLogSoftmaxNPUOp(OpTest):
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
[
'Out'
],
user_defined_grads
=
[
self
.
x_grad
],
max_relative_error
=
0.02
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
[
'Out'
],
user_defined_grads
=
[
self
.
x_grad
])
...
...
python/paddle/fluid/tests/unittests/npu/test_lookup_table_v2_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -77,7 +77,9 @@ class TestLookupTableV2(OpTest):
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'W'
],
'Out'
,
max_relative_error
=
0.01
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'W'
],
'Out'
)
...
...
python/paddle/fluid/tests/unittests/npu/test_nearest_interp_v2_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -39,10 +39,11 @@ class TestNearestInterpOp(OpTest):
self
.
set_npu
()
self
.
out_size
=
None
self
.
actual_shape
=
None
self
.
init_dtype
()
self
.
data_layout
=
'NCHW'
self
.
init_test_case
()
self
.
op_type
=
"nearest_interp_v2"
input_np
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
"float32"
)
input_np
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
self
.
dtype
)
if
self
.
data_layout
==
"NCHW"
:
in_h
=
self
.
input_shape
[
2
]
...
...
@@ -95,8 +96,21 @@ class TestNearestInterpOp(OpTest):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
in_place
=
True
,
max_relative_error
=
0.02
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
in_place
=
True
,
max_relative_error
=
0.006
)
self
.
place
,
[
'X'
],
'Out'
,
in_place
=
True
,
max_relative_error
=
0.006
)
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float32
def
init_test_case
(
self
):
self
.
interp_method
=
'nearest'
...
...
@@ -108,6 +122,11 @@ class TestNearestInterpOp(OpTest):
self
.
align_corners
=
False
class
TestNearestNeighborInterpFP16
(
TestNearestInterpOp
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
class
TestNearestNeighborInterpCase1
(
TestNearestInterpOp
):
def
init_test_case
(
self
):
self
.
interp_method
=
'nearest'
...
...
python/paddle/fluid/tests/unittests/npu/test_pad_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -50,8 +50,9 @@ class TestPadOp(OpTest):
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
max_relative_error
=
0.6
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
def
set_npu
(
self
):
...
...
python/paddle/fluid/tests/unittests/npu/test_relu_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -34,11 +34,12 @@ class TestRelu(OpTest):
self
.
init_dtype
()
np
.
random
.
seed
(
SEED
)
x
=
np
.
random
.
rand
(
3
,
2
).
astype
(
self
.
dtype
)
out
=
x
self
.
inputs
=
{
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
)}
self
.
attrs
=
{}
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
self
.
dtype
)
# The same reason with TestAbs
x
[
np
.
abs
(
x
)
<
0.005
]
=
0.02
out
=
np
.
maximum
(
x
,
0
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
out
}
def
set_npu
(
self
):
...
...
@@ -50,32 +51,18 @@ class TestRelu(OpTest):
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
max_relative_error
=
0.006
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
class
TestReluFp16
(
OpTest
):
def
setUp
(
self
):
self
.
set_npu
()
self
.
op_type
=
"relu"
self
.
place
=
paddle
.
NPUPlace
(
0
)
self
.
init_dtype
()
np
.
random
.
seed
(
SEED
)
x
=
np
.
random
.
rand
(
3
,
2
).
astype
(
self
.
dtype
)
out
=
x
self
.
inputs
=
{
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
)}
self
.
attrs
=
{}
self
.
outputs
=
{
'Out'
:
out
}
def
set_npu
(
self
):
self
.
__class__
.
use_npu
=
True
self
.
__class__
.
no_need_check_grad
=
True
class
TestReluFp16
(
TestRelu
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
,
atol
=
1e-5
)
class
TestReluNeg
(
OpTest
):
def
setUp
(
self
):
...
...
python/paddle/fluid/tests/unittests/npu/test_slice_op_npu.py
浏览文件 @
1a13fa0f
...
...
@@ -58,11 +58,16 @@ class TestSliceOp(OpTest):
self
.
place
=
paddle
.
NPUPlace
(
0
)
def
test_check_output
(
self
):
if
self
.
dtype
==
np
.
float16
:
self
.
check_output_with_place
(
self
.
place
)
else
:
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Out'
,
max_relative_error
=
0.02
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Out'
)
...
...
@@ -347,7 +352,9 @@ class TestSliceOpDecsDim(OpTest):
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Out'
,
max_relative_error
=
0.5
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Out'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录