Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7e0bada3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
7e0bada3
编写于
8月 23, 2022
作者:
C
Chen Weihang
提交者:
GitHub
8月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Ci] Add kernel dtype check py script (#45329)
* add kernel dtype check py * add kernel dtype check py, test=document_fix
上级
db937b5a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
123 addition
and
0 deletion
+123
-0
tools/check_op_kernel_same_dtypes.py
tools/check_op_kernel_same_dtypes.py
+123
-0
未找到文件。
tools/check_op_kernel_same_dtypes.py
0 → 100644
浏览文件 @
7e0bada3
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Print all registered kernels of a python module in alphabet order.
Usage:
python check_op_kernel_same_dtypes.py > all_kernels.txt
python check_op_kernel_same_dtypes.py OP_KERNEL_DTYPE_DEV.spec OP_KERNEL_DTYPE_PR.spec > is_valid
"""
from
__future__
import
print_function
import
sys
import
re
import
collections
import
paddle
def
get_all_kernels
():
all_kernels_info
=
paddle
.
framework
.
core
.
_get_all_register_op_kernels
()
print
(
all_kernels_info
)
# [u'{data_type[float]; data_layout[Undefined(AnyLayout)]; place[Place(gpu:0)]; library_type[PLAIN]}']
op_kernel_types
=
collections
.
defaultdict
(
list
)
for
op_type
,
op_infos
in
all_kernels_info
.
items
():
# is_grad_op = op_type.endswith("_grad")
# if is_grad_op: continue
pattern
=
re
.
compile
(
r
'data_type\[([^\]]+)\]'
)
for
op_info
in
op_infos
:
infos
=
pattern
.
findall
(
op_info
)
if
infos
is
None
or
len
(
infos
)
==
0
:
continue
register_type
=
infos
[
0
].
split
(
":"
)[
-
1
]
op_kernel_types
[
op_type
].
append
(
register_type
.
lower
())
for
(
op_type
,
op_kernels
)
in
sorted
(
op_kernel_types
.
items
(),
key
=
lambda
x
:
x
[
0
]):
print
(
op_type
,
" "
.
join
(
sorted
(
op_kernels
)))
def
read_file
(
file_path
):
with
open
(
file_path
,
'r'
)
as
f
:
content
=
f
.
read
()
content
=
content
.
splitlines
()
return
content
def
print_diff
(
op_type
,
op_kernel_dtype_set
,
grad_op_kernel_dtype_set
):
if
len
(
op_kernel_dtype_set
)
>
len
(
grad_op_kernel_dtype_set
):
lack_dtypes
=
list
(
op_kernel_dtype_set
-
grad_op_kernel_dtype_set
)
print
(
"{} supports [{}] now, but its grad op kernel not supported."
.
format
(
op_type
,
" "
.
join
(
lack_dtypes
)))
else
:
lack_dtypes
=
list
(
grad_op_kernel_dtype_set
-
op_kernel_dtype_set
)
print
(
"{} supports [{}] now, but its forward op kernel not supported."
.
format
(
op_type
+
"_grad"
,
" "
.
join
(
lack_dtypes
)))
def
check_change_or_add_op_kernel_dtypes_valid
():
origin
=
read_file
(
sys
.
argv
[
1
])
new
=
read_file
(
sys
.
argv
[
2
])
origin_all_kernel_dtype_dict
=
dict
()
for
op_msg
in
origin
:
op_info
=
op_msg
.
split
()
origin_all_kernel_dtype_dict
[
op_info
[
0
]]
=
set
(
op_info
[
1
:])
new_all_kernel_dtype_dict
=
dict
()
for
op_msg
in
new
:
op_info
=
op_msg
.
split
()
new_all_kernel_dtype_dict
[
op_info
[
0
]]
=
set
(
op_info
[
1
:])
added_or_changed_op_info
=
dict
()
for
op_type
,
dtype_set
in
new_all_kernel_dtype_dict
.
items
():
if
op_type
in
origin_all_kernel_dtype_dict
:
origin_dtype_set
=
origin_all_kernel_dtype_dict
[
op_type
]
# op kernel changed
if
origin_dtype_set
!=
dtype_set
:
added_or_changed_op_info
[
op_type
]
=
dtype_set
else
:
# do nothing
continue
else
:
# op kernel added
added_or_changed_op_info
[
op_type
]
=
dtype_set
for
op_type
,
dtype_set
in
added_or_changed_op_info
.
items
():
# if changed forward op
if
not
op_type
.
endswith
(
"_grad"
):
# only support grad op
grad_op_type
=
op_type
+
"_grad"
if
grad_op_type
in
new_all_kernel_dtype_dict
:
grad_op_kernel_dtype_set
=
set
(
new_all_kernel_dtype_dict
[
grad_op_type
])
if
dtype_set
!=
grad_op_kernel_dtype_set
:
print_diff
(
op_type
,
dtype_set
,
grad_op_kernel_dtype_set
)
# if changed grad op
else
:
forward_op_type
=
op_type
.
rstrip
(
"_grad"
)
if
forward_op_type
in
new_all_kernel_dtype_dict
:
op_kernel_dtype_set
=
set
(
new_all_kernel_dtype_dict
[
forward_op_type
])
if
op_kernel_dtype_set
!=
dtype_set
:
print_diff
(
forward_op_type
,
op_kernel_dtype_set
,
dtype_set
)
if
len
(
sys
.
argv
)
==
1
:
get_all_kernels
()
elif
len
(
sys
.
argv
)
==
3
:
check_change_or_add_op_kernel_dtypes_valid
()
else
:
print
(
"Usage:
\n
"
\
"
\t
python check_op_kernel_same_dtypes.py > all_kernels.txt
\n
"
\
"
\t
python check_op_kernel_same_dtypes.py OP_KERNEL_DTYPE_DEV.spec OP_KERNEL_DTYPE_PR.spec > diff"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录