Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ef5d216e
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看板
未验证
提交
ef5d216e
编写于
2月 16, 2022
作者:
Z
zyfncg
提交者:
GitHub
2月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change the format of api yaml (#39532)
上级
672def6c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
52 deletion
+58
-52
python/paddle/utils/code_gen/api.yaml
python/paddle/utils/code_gen/api.yaml
+21
-21
python/paddle/utils/code_gen/api_base.py
python/paddle/utils/code_gen/api_base.py
+27
-21
python/paddle/utils/code_gen/backward.yaml
python/paddle/utils/code_gen/backward.yaml
+10
-10
未找到文件。
python/paddle/utils/code_gen/api.yaml
浏览文件 @
ef5d216e
-
api
:
add
-
api
:
add
args
:
(
const Tensor& x, const Tensor&
y)
args
:
(
Tensor x, Tensor
y)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ElementwiseInferMeta
func
:
ElementwiseInferMeta
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
func
:
add
func
:
add
-
api
:
cast
-
api
:
cast
args
:
(
const Tensor&
x, DataType out_dtype)
args
:
(
Tensor
x, DataType out_dtype)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
CastInferMeta
func
:
CastInferMeta
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
-
api
:
concat
-
api
:
concat
args
:
(
const std::vector<Tensor>& x, const Scalar&
axis)
args
:
(
Tensor[] x, Scalar
axis)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ConcatInferMeta
func
:
ConcatInferMeta
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
func
:
concat
func
:
concat
-
api
:
conj
-
api
:
conj
args
:
(
const Tensor&
x)
args
:
(
Tensor
x)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
UnchangedInferMeta
func
:
UnchangedInferMeta
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
func
:
conj
func
:
conj
-
api
:
divide
-
api
:
divide
args
:
(
const Tensor& x, const Tensor&
y)
args
:
(
Tensor x, Tensor
y)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ElementwiseInferMeta
func
:
ElementwiseInferMeta
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
func
:
divide
func
:
divide
-
api
:
dot
-
api
:
dot
args
:
(
const Tensor& x, const Tensor&
y)
args
:
(
Tensor x, Tensor
y)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
DotInferMeta
func
:
DotInferMeta
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
func
:
dot
func
:
dot
-
api
:
empty
-
api
:
empty
args
:
(
const ScalarArray&
shape, DataType dtype=DataType::FLOAT32, Backend place=Backend::CPU, DataLayout layout=DataLayout::NCHW)
args
:
(
ScalarArray
shape, DataType dtype=DataType::FLOAT32, Backend place=Backend::CPU, DataLayout layout=DataLayout::NCHW)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
CreateInferMeta
func
:
CreateInferMeta
...
@@ -64,7 +64,7 @@
...
@@ -64,7 +64,7 @@
layout
:
layout
layout
:
layout
-
api
:
empty_like
-
api
:
empty_like
args
:
(
const Tensor&
x, DataType dtype = DataType::UNDEFINED, Backend place = Backend::UNDEFINED, DataLayout layout = DataLayout::UNDEFINED)
args
:
(
Tensor
x, DataType dtype = DataType::UNDEFINED, Backend place = Backend::UNDEFINED, DataLayout layout = DataLayout::UNDEFINED)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
CreateLikeInferMeta
func
:
CreateLikeInferMeta
...
@@ -77,7 +77,7 @@
...
@@ -77,7 +77,7 @@
layout
:
layout > x
layout
:
layout > x
-
api
:
flatten
-
api
:
flatten
args
:
(
const Tensor&
x, int start_axis, int stop_axis)
args
:
(
Tensor
x, int start_axis, int stop_axis)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
FlattenInferMeta
func
:
FlattenInferMeta
...
@@ -85,7 +85,7 @@
...
@@ -85,7 +85,7 @@
func
:
flatten
func
:
flatten
-
api
:
full
-
api
:
full
args
:
(
const ScalarArray& shape, const Scalar&
value, DataType dtype=DataType::FLOAT32, Backend place=Backend::CPU, DataLayout layout=DataLayout::NCHW)
args
:
(
ScalarArray shape, Scalar
value, DataType dtype=DataType::FLOAT32, Backend place=Backend::CPU, DataLayout layout=DataLayout::NCHW)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
CreateInferMeta
func
:
CreateInferMeta
...
@@ -98,7 +98,7 @@
...
@@ -98,7 +98,7 @@
layout
:
layout
layout
:
layout
-
api
:
full_like
-
api
:
full_like
args
:
(
const Tensor& x, const Scalar&
value, DataType dtype = DataType::UNDEFINED, Backend place = Backend::UNDEFINED, DataLayout layout = DataLayout::UNDEFINED)
args
:
(
Tensor x, Scalar
value, DataType dtype = DataType::UNDEFINED, Backend place = Backend::UNDEFINED, DataLayout layout = DataLayout::UNDEFINED)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
CreateLikeInferMeta
func
:
CreateLikeInferMeta
...
@@ -111,7 +111,7 @@
...
@@ -111,7 +111,7 @@
layout
:
layout > x
layout
:
layout > x
-
api
:
matmul
-
api
:
matmul
args
:
(
const Tensor& x, const Tensor&
y, bool transpose_x =
false
, bool transpose_y =
false
)
args
:
(
Tensor x, Tensor
y, bool transpose_x =
false
, bool transpose_y =
false
)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
MatmulInferMeta
func
:
MatmulInferMeta
...
@@ -120,7 +120,7 @@
...
@@ -120,7 +120,7 @@
backward
:
matmul_grad
backward
:
matmul_grad
-
api
:
mean
-
api
:
mean
args
:
(
const Tensor& x, const std::vector<int64_t>&
axis={}, bool keep_dim=false)
args
:
(
Tensor x, int64_t[]
axis={}, bool keep_dim=false)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ReduceInferMeta
func
:
ReduceInferMeta
...
@@ -128,7 +128,7 @@
...
@@ -128,7 +128,7 @@
func
:
mean
func
:
mean
-
api
:
multiply
-
api
:
multiply
args
:
(
const Tensor& x, const Tensor&
y)
args
:
(
Tensor x, Tensor
y)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ElementwiseInferMeta
func
:
ElementwiseInferMeta
...
@@ -136,12 +136,12 @@
...
@@ -136,12 +136,12 @@
func
:
multiply
func
:
multiply
-
api
:
ones_like
-
api
:
ones_like
args
:
(
const Tensor&
x, DataType dtype=DataType::UNDEFINED, Backend place=Backend::UNDEFINED, DataLayout layout=DataLayout::UNDEFINED)
args
:
(
Tensor
x, DataType dtype=DataType::UNDEFINED, Backend place=Backend::UNDEFINED, DataLayout layout=DataLayout::UNDEFINED)
output
:
Tensor
output
:
Tensor
invoke
:
full_like(x, 1, dtype, place, layout)
invoke
:
full_like(x, 1, dtype, place, layout)
-
api
:
reshape
-
api
:
reshape
args
:
(
const Tensor& x, const ScalarArray&
shape)
args
:
(
Tensor x, ScalarArray
shape)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ReshapeInferMeta
func
:
ReshapeInferMeta
...
@@ -149,7 +149,7 @@
...
@@ -149,7 +149,7 @@
func
:
reshape
func
:
reshape
-
api
:
scale
-
api
:
scale
args
:
(
const Tensor& x, const Scalar&
scale, float bias, bool bias_after_scale)
args
:
(
Tensor x, Scalar
scale, float bias, bool bias_after_scale)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
UnchangedInferMeta
func
:
UnchangedInferMeta
...
@@ -158,7 +158,7 @@
...
@@ -158,7 +158,7 @@
func
:
scale, scale_sr
func
:
scale, scale_sr
-
api
:
sign
-
api
:
sign
args
:
(
const Tensor&
x)
args
:
(
Tensor
x)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
UnchangedInferMeta
func
:
UnchangedInferMeta
...
@@ -166,7 +166,7 @@
...
@@ -166,7 +166,7 @@
func
:
sign
func
:
sign
-
api
:
subtract
-
api
:
subtract
args
:
(
const Tensor& x, const Tensor&
y)
args
:
(
Tensor x, Tensor
y)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
ElementwiseInferMeta
func
:
ElementwiseInferMeta
...
@@ -174,7 +174,7 @@
...
@@ -174,7 +174,7 @@
func
:
subtract
func
:
subtract
-
api
:
sum
-
api
:
sum
args
:
(
const Tensor& x, const std::vector<int64_t>&
axis={}, DataType dtype=DataType::UNDEFINED, bool keep_dim=false)
args
:
(
Tensor x, int64_t[]
axis={}, DataType dtype=DataType::UNDEFINED, bool keep_dim=false)
output
:
Tensor
output
:
Tensor
infer_meta
:
infer_meta
:
func
:
SumInferMeta
func
:
SumInferMeta
...
@@ -184,6 +184,6 @@
...
@@ -184,6 +184,6 @@
data_type
:
x
data_type
:
x
-
api
:
zeros_like
-
api
:
zeros_like
args
:
(
const Tensor&
x, DataType dtype=DataType::UNDEFINED, Backend place=Backend::UNDEFINED, DataLayout layout=DataLayout::UNDEFINED)
args
:
(
Tensor
x, DataType dtype=DataType::UNDEFINED, Backend place=Backend::UNDEFINED, DataLayout layout=DataLayout::UNDEFINED)
output
:
Tensor
output
:
Tensor
invoke
:
full_like(x, 0, dtype, place, layout)
invoke
:
full_like(x, 0, dtype, place, layout)
python/paddle/utils/code_gen/api_base.py
浏览文件 @
ef5d216e
...
@@ -71,23 +71,26 @@ class BaseAPI(object):
...
@@ -71,23 +71,26 @@ class BaseAPI(object):
f
"Args declaration should start with '(' and end with ')', please check the args of
{
api_name
}
in yaml."
f
"Args declaration should start with '(' and end with ')', please check the args of
{
api_name
}
in yaml."
args_str
=
args_str
[
1
:
-
1
]
args_str
=
args_str
[
1
:
-
1
]
args_list
=
args_str
.
split
(
','
)
args_list
=
args_str
.
split
(
','
)
input_types
=
[
input_types_map
=
{
'const Tensor&'
,
'const Tensor &'
,
'const std::vector<Tensor>&'
,
'Tensor'
:
'const Tensor&'
,
'const std::vector<Tensor> &'
'Tensor[]'
:
'const std::vector<Tensor>&'
]
}
attr_types
=
[
'const Scalar&'
,
'const Scalar &'
,
'const ScalarArray&'
,
'const ScalarArray &'
,
\
attr_types_map
=
{
'ScalarArray'
:
'const ScalarArray&'
,
'Scalar'
:
'const Scalar&'
,
\
'int'
,
'int32_t'
,
'int64_t'
,
'size_t'
,
'float'
,
'double'
,
'bool'
,
\
'int'
:
'int'
,
'int32_t'
:
'int32_t'
,
'int64_t'
:
'int64_t'
,
'size_t'
:
'size_t'
,
\
'const std::vector<int64_t>&'
,
'Backend'
,
'DataLayout'
,
'DataType'
]
'float'
:
'float'
,
'double'
:
'double'
,
'bool'
:
'bool'
,
\
'Backend'
:
'Backend'
,
'DataLayout'
:
'DataLayout'
,
'DataType'
:
'DataType'
,
\
'int64_t[]'
:
'const std::vector<int64_t>&'
,
'int[]'
:
'const std::vector<int>&'
}
args_declare_str
=
""
args_declare_str
=
""
args_define_str
=
""
args_define_str
=
""
for
item
in
args_list
:
for
item
in
args_list
:
item
=
item
.
strip
()
item
=
item
.
strip
()
type_and_name
=
item
.
split
(
' '
)
# match the input tensor
# match the input tensor
has_input
=
False
has_input
=
False
for
in_type
in
input_types
:
for
in_type
_symbol
,
in_type
in
input_types_map
.
items
()
:
if
item
.
startswith
(
in_type
)
:
if
type_and_name
[
0
]
==
in_type_symbol
:
input_name
=
item
[
len
(
in_type
):
].
strip
()
input_name
=
type_and_name
[
1
].
strip
()
assert
len
(
input_name
)
>
0
,
\
assert
len
(
input_name
)
>
0
,
\
f
"The input tensor name should not be empty. Please check the args of
{
api_name
}
in yaml."
f
"The input tensor name should not be empty. Please check the args of
{
api_name
}
in yaml."
assert
len
(
attrs
[
'names'
])
==
0
,
\
assert
len
(
attrs
[
'names'
])
==
0
,
\
...
@@ -103,9 +106,9 @@ class BaseAPI(object):
...
@@ -103,9 +106,9 @@ class BaseAPI(object):
continue
continue
# match the attribute
# match the attribute
for
attr_type
in
attr_types
:
for
attr_type
_symbol
,
attr_type
in
attr_types_map
.
items
()
:
if
item
.
startswith
(
attr_type
)
:
if
type_and_name
[
0
]
==
attr_type_symbol
:
attr_name
=
item
[
len
(
attr_type
):].
strip
()
attr_name
=
item
[
len
(
attr_type
_symbol
):].
strip
()
assert
len
(
attr_name
)
>
0
,
\
assert
len
(
attr_name
)
>
0
,
\
f
"The attribute name should not be empty. Please check the args of
{
api_name
}
in yaml."
f
"The attribute name should not be empty. Please check the args of
{
api_name
}
in yaml."
default_value
=
None
default_value
=
None
...
@@ -128,25 +131,28 @@ class BaseAPI(object):
...
@@ -128,25 +131,28 @@ class BaseAPI(object):
def
parse_output
(
self
,
api_name
,
output_config
):
def
parse_output
(
self
,
api_name
,
output_config
):
def
parse_output_item
(
output_item
):
def
parse_output_item
(
output_item
):
alllowd_output_types
=
[
'Tensor'
,
'std::vector<Tensor>'
]
output_type_map
=
{
'Tensor'
:
'Tensor'
,
'Tensor[]'
:
'std::vector<Tensor>'
}
if
re
.
search
(
r
'\(\w*\)'
,
output_item
):
if
re
.
search
(
r
'\(\w*\)'
,
output_item
):
result
=
re
.
search
(
result
=
re
.
search
(
r
"(?P<out_type>[a-zA-Z0-9_
<>
]+)\s*\((?P<name>\w+)\)"
,
r
"(?P<out_type>[a-zA-Z0-9_
[\]
]+)\s*\((?P<name>\w+)\)"
,
output_item
)
output_item
)
out_type
=
result
.
group
(
'out_type'
)
out_type
=
result
.
group
(
'out_type'
)
assert
out_type
in
alllowd_output_types
,
\
assert
out_type
in
output_type_map
,
\
f
"
{
api_name
}
: Output type error: the output type only support Tensor and
std::vector<Tensor>
,
\
f
"
{
api_name
}
: Output type error: the output type only support Tensor and
Tensor[]
,
\
but now is
{
out_type
}
."
but now is
{
out_type
}
."
return
out_type
,
result
.
group
(
'name'
)
return
out_type
,
result
.
group
(
'name'
)
else
:
else
:
if
output_item
.
strip
()
in
alllowd_output_types
:
if
output_item
.
strip
()
in
output_type_map
:
return
output_
item
.
strip
()
,
'out'
return
output_
type_map
[
output_item
.
strip
()]
,
'out'
else
:
else
:
raise
ValueError
(
raise
ValueError
(
"{} : Output type error: the output type only support Tensor and
std::vector<Tensor>
,
\
"{} : Output type error: the output type only support Tensor and
Tensor[]
,
\
but now is {}."
.
format
(
api_name
,
out
_type
))
but now is {}."
.
format
(
api_name
,
out
put_item
.
strip
()
))
temp_list
=
output_config
.
split
(
','
)
temp_list
=
output_config
.
split
(
','
)
...
...
python/paddle/utils/code_gen/backward.yaml
浏览文件 @
ef5d216e
-
backward_api
:
matmul_grad
-
backward_api
:
matmul_grad
forward
:
matmul (
const Tensor& x, const Tensor&
y, bool transpose_x=false, bool transpose_y=false) -> Tensor(out)
forward
:
matmul (
Tensor x, Tensor
y, bool transpose_x=false, bool transpose_y=false) -> Tensor(out)
args
:
(
const Tensor& x, const Tensor& y, const Tensor&
out_grad, bool transpose_x=false, bool transpose_y=false)
args
:
(
Tensor x, Tensor y, Tensor
out_grad, bool transpose_x=false, bool transpose_y=false)
output
:
Tensor(x_grad), Tensor(y_grad)
output
:
Tensor(x_grad), Tensor(y_grad)
infer_meta
:
infer_meta
:
func
:
GeneralBinaryGradInferMeta
func
:
GeneralBinaryGradInferMeta
...
@@ -9,26 +9,26 @@
...
@@ -9,26 +9,26 @@
func
:
matmul_grad
func
:
matmul_grad
-
backward_api
:
scale_grad
-
backward_api
:
scale_grad
forward
:
scale (
const Tensor& x, const Scalar&
scale, float bias, bool bias_after_scale) -> Tensor(out)
forward
:
scale (
Tensor x, Scalar
scale, float bias, bool bias_after_scale) -> Tensor(out)
args
:
(
const Tensor& out_grad, const Scalar&
scale, float bias=0.0, bool bias_after_scale=true)
args
:
(
Tensor out_grad, Scalar
scale, float bias=0.0, bool bias_after_scale=true)
output
:
Tensor(x_grad)
output
:
Tensor(x_grad)
invoke
:
scale(out_grad, scale, bias, bias_after_scale)
invoke
:
scale(out_grad, scale, bias, bias_after_scale)
# TODO(zhangyunfei) The config of double grad and triple grad will be supported in the future.
# TODO(zhangyunfei) The config of double grad and triple grad will be supported in the future.
#
#
# - backward_api : matmul_double_grad
# - backward_api : matmul_double_grad
# forward : matmul_grad (
const Tensor& x, const Tensor& y, const Tensor& out_grad, bool transpose_x, bool transpose_y) -> tuple<Tensor, Tensor>(dx,
dy)
# forward : matmul_grad (
Tensor x, Tensor y, Tensor out_grad, bool transpose_x, bool transpose_y) -> Tensor(dx), Tensor>(
dy)
# args : (
const Tensor& x, const Tensor& y, const Tensor& out_grad, const Tensor& dx_grad, const Tensor&
dy_grad, bool transpose_x, bool transpose_y)
# args : (
Tensor x, Tensor y, Tensor out_grad, Tensor dx_grad, Tensor
dy_grad, bool transpose_x, bool transpose_y)
# output :
tuple<Tensor, Tensor, Tensor> // d2x, d2y, dout_grad
# output :
Tensor(d2x), Tensor(d2y), Tensor(dout_grad)
# infer_meta :
# infer_meta :
# func : MatmulDoubleGradInferMeta
# func : MatmulDoubleGradInferMeta
# kernel :
# kernel :
# func : matmul_double_grad
# func : matmul_double_grad
# - backward_api : matmul_triple_grad
# - backward_api : matmul_triple_grad
# forward : matmul_double_grad (
const Tensor& x, const Tensor& y, const Tensor& out_grad, const Tensor& dx_grad, const Tensor& dy_grad, bool transpose_x, bool transpose_y) -> tuple<Tensor, Tensor, Tensor>(d2x, d2y,
dout_grad)
# forward : matmul_double_grad (
Tensor x, Tensor y, Tensor out_grad, Tensor dx_grad, Tensor dy_grad, bool transpose_x, bool transpose_y) -> Tensor(d2x), Tensor(d2y), Tensor(
dout_grad)
# args : (
const Tensor& x, const Tensor& y, const Tensor& out_grad, const Tensor& dx_grad, const Tensor& dy_grad, const Tensor& d2x_grad, const Tensor& d2y_grad, const Tensor&
dout_grad_grad, bool transpose_x, bool transpose_y)
# args : (
Tensor x, Tensor y, Tensor out_grad, Tensor dx_grad, Tensor dy_grad, Tensor d2x_grad, Tensor d2y_grad, Tensor
dout_grad_grad, bool transpose_x, bool transpose_y)
# output :
tuple<Tensor, Tensor, Tensor, Tensor, Tensor> // d3x, d3y, d2out_grad, ddx_grad, ddy_grad
# output :
Tensor(d3x), Tensor(d3y), Tensor(d2out_grad), Tensor(ddx_grad), Tensor(ddy_grad)
# infer_meta :
# infer_meta :
# func : MatmulTripleGradInferMeta
# func : MatmulTripleGradInferMeta
# kernel :
# kernel :
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录