Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
049ac56c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2297
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
049ac56c
编写于
8月 18, 2020
作者:
L
Leo Chen
提交者:
GitHub
8月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Print user-friendly error message in core.ops [part 2] (#26377)
上级
fd0051b4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
7 deletion
+32
-7
paddle/fluid/pybind/op_function.h
paddle/fluid/pybind/op_function.h
+24
-3
paddle/fluid/pybind/op_function_generator.cc
paddle/fluid/pybind/op_function_generator.cc
+8
-4
未找到文件。
paddle/fluid/pybind/op_function.h
浏览文件 @
049ac56c
...
@@ -90,15 +90,36 @@ CastPyHandleToVarBaseList(const std::string& op_type,
...
@@ -90,15 +90,36 @@ CastPyHandleToVarBaseList(const std::string& op_type,
return
result
;
return
result
;
}
// namespace pybind
}
// namespace pybind
static
inline
void
ConstructAttrMapFromPyArgs
(
framework
::
AttributeMap
*
attrs
,
static
inline
void
ConstructAttrMapFromPyArgs
(
const
std
::
string
&
op_type
,
int
start_idx
,
framework
::
AttributeMap
*
attrs
,
const
py
::
args
&
args
)
{
const
py
::
args
&
args
)
{
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
args
.
size
()
%
2
,
0
,
args
.
size
()
%
2
,
0
,
platform
::
errors
::
InvalidArgument
(
platform
::
errors
::
InvalidArgument
(
"The number of arguments for arributes should be even."
));
"The number of arguments for arributes should be even."
));
for
(
size_t
i
=
0
;
i
<
args
.
size
();
i
+=
2
)
{
for
(
size_t
i
=
0
;
i
<
args
.
size
();
i
+=
2
)
{
auto
name
=
args
[
i
].
cast
<
std
::
string
>
();
std
::
string
name
;
auto
value
=
args
[
i
+
1
].
cast
<
framework
::
Attribute
>
();
framework
::
Attribute
value
;
try
{
name
=
args
[
i
].
cast
<
std
::
string
>
();
}
catch
(
std
::
exception
&
e
)
{
PyObject
*
py_obj
=
args
[
i
].
ptr
();
// get underlying PyObject
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"%s(): argument (position %d) must be str, but got "
"%s"
,
op_type
,
start_idx
+
i
,
Py_TYPE
(
py_obj
)
->
tp_name
));
}
try
{
value
=
args
[
i
+
1
].
cast
<
framework
::
Attribute
>
();
}
catch
(
std
::
exception
&
e
)
{
PyObject
*
py_obj
=
args
[
i
+
1
].
ptr
();
// get underlying PyObject
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"%s(): argument (position %d) must be "
"Attribute type (one of str, bool, int, int64, float, or list of "
"them), but got %s"
,
op_type
,
start_idx
+
i
+
1
,
Py_TYPE
(
py_obj
)
->
tp_name
));
}
(
*
attrs
)[
name
]
=
value
;
(
*
attrs
)[
name
]
=
value
;
}
}
}
}
...
...
paddle/fluid/pybind/op_function_generator.cc
浏览文件 @
049ac56c
...
@@ -146,7 +146,7 @@ R"(
...
@@ -146,7 +146,7 @@ R"(
{
{
%s
%s
framework::AttributeMap attrs;
framework::AttributeMap attrs;
ConstructAttrMapFromPyArgs(&attrs, args);
ConstructAttrMapFromPyArgs(
"%s", %d,
&attrs, args);
{
{
py::gil_scoped_release release;
py::gil_scoped_release release;
auto tracer = imperative::GetCurrentTracer();
auto tracer = imperative::GetCurrentTracer();
...
@@ -204,6 +204,7 @@ GenerateOpFunctions(const std::string& module_name) {
...
@@ -204,6 +204,7 @@ GenerateOpFunctions(const std::string& module_name) {
std
::
string
ins_initializer_with_null
=
""
;
std
::
string
ins_initializer_with_null
=
""
;
std
::
string
py_arg
=
""
;
std
::
string
py_arg
=
""
;
int
arg_idx
=
0
;
int
arg_idx
=
0
;
int
input_args_num
=
0
;
std
::
string
ins_cast_str
=
""
;
std
::
string
ins_cast_str
=
""
;
for
(
auto
&
input
:
op_proto
->
inputs
())
{
for
(
auto
&
input
:
op_proto
->
inputs
())
{
auto
&
in_name
=
input
.
name
();
auto
&
in_name
=
input
.
name
();
...
@@ -216,6 +217,7 @@ GenerateOpFunctions(const std::string& module_name) {
...
@@ -216,6 +217,7 @@ GenerateOpFunctions(const std::string& module_name) {
paddle
::
string
::
Sprintf
(
ARG_TEMPLATE
,
in_type
,
TempName
(
in_name
));
paddle
::
string
::
Sprintf
(
ARG_TEMPLATE
,
in_type
,
TempName
(
in_name
));
input_args
+=
input_arg
;
input_args
+=
input_arg
;
input_args
+=
","
;
input_args
+=
","
;
input_args_num
++
;
const
auto
in_cast_type
=
const
auto
in_cast_type
=
input
.
duplicable
()
?
CAST_VAR_LIST_TEMPLATE
:
CAST_VAR_TEMPLATE
;
input
.
duplicable
()
?
CAST_VAR_LIST_TEMPLATE
:
CAST_VAR_TEMPLATE
;
ins_cast_str
+=
ins_cast_str
+=
...
@@ -269,6 +271,7 @@ GenerateOpFunctions(const std::string& module_name) {
...
@@ -269,6 +271,7 @@ GenerateOpFunctions(const std::string& module_name) {
}
}
input_args
+=
out_type
;
input_args
+=
out_type
;
input_args
+=
out_name
;
input_args
+=
out_name
;
input_args_num
++
;
if
(
output
.
dispensable
())
{
if
(
output
.
dispensable
())
{
const
auto
out_template
=
const
auto
out_template
=
...
@@ -295,6 +298,7 @@ GenerateOpFunctions(const std::string& module_name) {
...
@@ -295,6 +298,7 @@ GenerateOpFunctions(const std::string& module_name) {
auto
out_num_str
=
paddle
::
string
::
Sprintf
(
ARG_OUT_NUM
,
out_name
);
auto
out_num_str
=
paddle
::
string
::
Sprintf
(
ARG_OUT_NUM
,
out_name
);
input_args
+=
ARG_OUT_NUM_TYPE
;
input_args
+=
ARG_OUT_NUM_TYPE
;
input_args
+=
out_num_str
;
input_args
+=
out_num_str
;
input_args_num
++
;
outs_initializer
+=
paddle
::
string
::
Sprintf
(
outs_initializer
+=
paddle
::
string
::
Sprintf
(
OUT_DUPLICABLE_INITIALIZER_TEMPLATE
,
out_name
,
out_num_str
);
OUT_DUPLICABLE_INITIALIZER_TEMPLATE
,
out_name
,
out_num_str
);
}
else
{
}
else
{
...
@@ -334,9 +338,9 @@ GenerateOpFunctions(const std::string& module_name) {
...
@@ -334,9 +338,9 @@ GenerateOpFunctions(const std::string& module_name) {
// generate op funtcion body
// generate op funtcion body
auto
op_function_str
=
paddle
::
string
::
Sprintf
(
auto
op_function_str
=
paddle
::
string
::
Sprintf
(
OP_FUNCTION_TEMPLATE
,
return_type
,
func_name
,
function_args
,
OP_FUNCTION_TEMPLATE
,
return_type
,
func_name
,
function_args
,
ins_cast_str
,
o
uts_initializer
,
in
s_initializer
,
ins_cast_str
,
o
p_type
,
input_args_num
,
out
s_initializer
,
ins_initializer
_with_null
+
outs_initializer_with_null
,
op_type
,
ins_initializer
,
ins_initializer_with_null
+
outs_initializer_with_null
,
return_str
);
op_type
,
return_str
);
// generate pybind item
// generate pybind item
auto
bind_function_str
=
paddle
::
string
::
Sprintf
(
auto
bind_function_str
=
paddle
::
string
::
Sprintf
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录