Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ec008a71
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看板
未验证
提交
ec008a71
编写于
4月 10, 2023
作者:
R
Roc
提交者:
GitHub
4月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[AMP OP & Test] Tril & Triu (#52411)
上级
648f58aa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
13 deletion
+82
-13
python/paddle/fluid/tests/unittests/test_tril_triu_op.py
python/paddle/fluid/tests/unittests/test_tril_triu_op.py
+82
-13
未找到文件。
python/paddle/fluid/tests/unittests/test_tril_triu_op.py
浏览文件 @
ec008a71
...
...
@@ -14,10 +14,11 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
from
paddle
import
fluid
,
tensor
from
paddle.fluid
import
core
from
paddle.fluid.framework
import
Program
,
program_guard
...
...
@@ -49,20 +50,58 @@ class TrilTriuOpDefaultTest(OpTest):
def
test_check_grad_normal
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float64
def
initTestCase
(
self
):
self
.
init_dtype
()
self
.
real_op_type
=
np
.
random
.
choice
([
'triu'
,
'tril'
])
self
.
diagonal
=
None
self
.
X
=
np
.
arange
(
1
,
101
,
dtype
=
self
.
dtype
).
reshape
([
10
,
-
1
])
class
TrilTriuOpDefaultTestFP16
(
TrilTriuOpDefaultTest
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
'not supported bf16'
,
)
class
TrilTriuOpDefaultTestBF16
(
TrilTriuOpDefaultTest
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
uint16
def
setUp
(
self
):
super
().
setUp
()
self
.
outputs
[
"Out"
]
=
convert_float_to_uint16
(
self
.
outputs
[
"Out"
])
self
.
inputs
[
'X'
]
=
convert_float_to_uint16
(
self
.
inputs
[
'X'
])
def
initTestCase
(
self
):
self
.
init_dtype
()
self
.
real_op_type
=
np
.
random
.
choice
([
'triu'
,
'tril'
])
self
.
diagonal
=
None
self
.
X
=
np
.
arange
(
1
,
101
,
dtype
=
"float64"
).
reshape
([
10
,
-
1
])
self
.
X
=
np
.
arange
(
1
,
101
,
dtype
=
"float32"
).
reshape
([
10
,
-
1
])
def
test_check_output
(
self
):
self
.
check_output_with_place
(
core
.
CUDAPlace
(
0
))
def
test_check_grad_normal
(
self
):
self
.
check_grad_with_place
(
core
.
CUDAPlace
(
0
),
[
'X'
],
'Out'
,
numeric_grad_delta
=
0.05
)
def
case_generator
(
op_type
,
Xshape
,
diagonal
,
expected
):
def
case_generator
(
op_type
,
Xshape
,
diagonal
,
expected
,
dtype
):
"""
Generate testcases with the params shape of X, diagonal and op_type.
If arg`expercted` is 'success', it will register an Optest case and expect to pass.
Otherwise, it will register an API case and check the expect failure.
"""
cls_name
=
"{}_{}_shape_{}_diag_{}"
.
format
(
expected
,
op_type
,
Xshape
,
diagonal
cls_name
=
"{}_{}_shape_{}_diag_{}
_dtype_{}
"
.
format
(
expected
,
op_type
,
Xshape
,
diagonal
,
dtype
)
errmsg
=
{
"diagonal: TypeError"
:
"diagonal in {} must be a python Int"
.
format
(
...
...
@@ -93,7 +132,34 @@ def case_generator(op_type, Xshape, diagonal, expected):
self
.
diagonal
=
diagonal
self
.
X
=
np
.
random
.
random
(
Xshape
).
astype
(
"float64"
)
CLASS
=
locals
()[
'SuccessCase'
if
expected
==
"success"
else
'FailureCase'
]
class
SuccessCaseFP16
(
TrilTriuOpDefaultTestFP16
):
def
initTestCase
(
self
):
self
.
init_dtype
()
self
.
real_op_type
=
op_type
self
.
diagonal
=
diagonal
self
.
X
=
np
.
random
.
random
(
Xshape
).
astype
(
"float16"
)
class
SuccessCaseBF16
(
TrilTriuOpDefaultTestBF16
):
def
initTestCase
(
self
):
self
.
init_dtype
()
self
.
real_op_type
=
op_type
self
.
diagonal
=
diagonal
self
.
X
=
np
.
random
.
random
(
Xshape
).
astype
(
"float32"
)
if
dtype
==
"float64"
:
CLASS
=
locals
()[
'SuccessCase'
if
expected
==
"success"
else
'FailureCase'
]
elif
dtype
==
"float16"
:
CLASS
=
locals
()[
'SuccessCaseFP16'
if
expected
==
"success"
else
'FailureCase'
]
elif
dtype
==
"bfloat16"
:
CLASS
=
locals
()[
'SuccessCaseBF16'
if
expected
==
"success"
else
'FailureCase'
]
else
:
raise
ValueError
(
f
"Not supported dtype
{
dtype
}
"
)
CLASS
.
__name__
=
cls_name
globals
()[
cls_name
]
=
CLASS
...
...
@@ -119,13 +185,16 @@ cases = {
(
2020
,):
[
None
],
},
}
for
_op_type
in
[
'tril'
,
'triu'
]:
for
_expected
,
_params
in
cases
.
items
():
for
_Xshape
,
_diaglist
in
_params
.
items
():
[
case_generator
(
_op_type
,
_Xshape
,
_diagonal
,
_expected
)
for
_diagonal
in
_diaglist
]
for
dtype
in
[
"float64"
,
"float16"
,
"bfloat16"
]:
for
_op_type
in
[
'tril'
,
'triu'
]:
for
_expected
,
_params
in
cases
.
items
():
for
_Xshape
,
_diaglist
in
_params
.
items
():
[
case_generator
(
_op_type
,
_Xshape
,
_diagonal
,
_expected
,
dtype
)
for
_diagonal
in
_diaglist
]
class
TestTrilTriuOpAPI
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录