Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
832e58d6
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看板
未验证
提交
832e58d6
编写于
5月 06, 2022
作者:
J
Jiabin Yang
提交者:
GitHub
5月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix stray error (#42509)
* fix @ stray error in dygraph * fix @ stray error in dygraph
上级
06927016
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
147 addition
and
91 deletion
+147
-91
paddle/fluid/eager/auto_code_generator/eager_generator.cc
paddle/fluid/eager/auto_code_generator/eager_generator.cc
+97
-62
paddle/fluid/pybind/eager_op_function_generator.cc
paddle/fluid/pybind/eager_op_function_generator.cc
+20
-12
paddle/fluid/pybind/op_function_generator.cc
paddle/fluid/pybind/op_function_generator.cc
+30
-17
未找到文件。
paddle/fluid/eager/auto_code_generator/eager_generator.cc
浏览文件 @
832e58d6
此差异已折叠。
点击以展开。
paddle/fluid/pybind/eager_op_function_generator.cc
浏览文件 @
832e58d6
...
...
@@ -36,6 +36,11 @@
// phi
#include "paddle/phi/kernels/declarations.h"
static
std
::
string
LegalizeVarName
(
const
std
::
string
&
var_name
)
{
std
::
string
ret
=
var_name
;
std
::
replace
(
ret
.
begin
(),
ret
.
end
(),
'@'
,
'_'
);
// replace all '-' to '_'
return
ret
;
}
// clang-format off
const
char
*
OUT_INITIALIZER_TEMPLATE
=
R"({"%s", {std::shared_ptr<imperative::VarBase>(new imperative::VarBase("auto_"+std::to_string(VarBaseUniqueNameID++)+"_"))}})"
;
...
...
@@ -185,18 +190,19 @@ std::string GenerateOpFunctionsBody(
continue
;
}
const
auto
in_type
=
input
.
duplicable
()
?
IN_VAR_LIST_TYPE
:
IN_VAR_TYPE
;
auto
input_arg
=
paddle
::
string
::
Sprintf
(
ARG_TEMPLATE
,
in_type
,
TempName
(
in_name
));
auto
input_arg
=
paddle
::
string
::
Sprintf
(
ARG_TEMPLATE
,
in_type
,
TempName
(
LegalizeVarName
(
in_name
)
));
input_args
+=
input_arg
;
input_args
+=
","
;
input_args_num
++
;
const
auto
in_cast_type
=
input
.
duplicable
()
?
CAST_VAR_LIST_TEMPLATE
:
CAST_VAR_TEMPLATE
;
auto
dispensable
=
input
.
dispensable
()
?
"true"
:
"false"
;
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
in_name
,
op_type
,
in_name
,
arg_idx
++
,
dispensable
);
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
LegalizeVarName
(
in_name
),
op_type
,
in_name
,
arg_idx
++
,
dispensable
);
call_api_str
+=
in_name
+
", "
;
call_api_str
+=
LegalizeVarName
(
in_name
)
+
", "
;
}
if
(
!
input_args
.
empty
()
&&
input_args
.
back
()
==
','
)
{
...
...
@@ -224,7 +230,7 @@ std::string GenerateOpFunctionsBody(
input_args
+=
","
;
}
input_args
+=
out_type
;
input_args
+=
out_name
;
input_args
+=
LegalizeVarName
(
out_name
)
;
input_args_num
++
;
if
(
output
.
dispensable
())
{
...
...
@@ -237,18 +243,19 @@ std::string GenerateOpFunctionsBody(
const
auto
out_template
=
output
.
duplicable
()
?
INPUT_LIST_INITIALIZER_TEMPLATE
:
INPUT_INITIALIZER_TEMPLATE
;
outs_initializer
+=
paddle
::
string
::
Sprintf
(
out_template
,
out_name
,
out_name
);
outs_initializer
+=
paddle
::
string
::
Sprintf
(
out_template
,
out_name
,
LegalizeVarName
(
out_name
)
);
outs_initializer
+=
","
;
}
const
auto
in_cast_type
=
output
.
duplicable
()
?
CAST_VAR_PTR_LIST_TEMPLATE
:
CAST_VAR_PTR_TEMPLATE
;
auto
dispensable
=
output
.
dispensable
()
?
"true"
:
"false"
;
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
out_name
,
op_type
,
out_name
,
arg_idx
++
,
dispensable
);
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
LegalizeVarName
(
out_name
),
op_type
,
out_name
,
arg_idx
++
,
dispensable
);
call_api_str
+=
out_name
+
", "
;
call_api_str
+=
LegalizeVarName
(
out_name
)
+
", "
;
}
else
{
// There are few Operators that have duplicable output, like `Out` in
// split op. We need to specify the number of variables for the
...
...
@@ -257,7 +264,8 @@ std::string GenerateOpFunctionsBody(
if
(
input_args
!=
""
)
{
input_args
+=
","
;
}
auto
out_num_str
=
paddle
::
string
::
Sprintf
(
ARG_OUT_NUM
,
out_name
);
auto
out_num_str
=
paddle
::
string
::
Sprintf
(
ARG_OUT_NUM
,
LegalizeVarName
(
out_name
));
input_args
+=
ARG_OUT_NUM_TYPE
;
input_args
+=
out_num_str
;
input_args_num
++
;
...
...
paddle/fluid/pybind/op_function_generator.cc
浏览文件 @
832e58d6
...
...
@@ -35,6 +35,12 @@
// phi
#include "paddle/phi/kernels/declarations.h"
static
std
::
string
LegalizeVarName
(
const
std
::
string
&
var_name
)
{
std
::
string
ret
=
var_name
;
std
::
replace
(
ret
.
begin
(),
ret
.
end
(),
'@'
,
'_'
);
// replace all '-' to '_'
return
ret
;
}
// NOTE(pangyoki): Inplace OP with duplicable input.
// The set includes inplace ops that have duplicable input.
// The first Varbase in input needs to be specified for the inplace strategy
...
...
@@ -201,28 +207,31 @@ std::string GenerateOpFunctionsBody(
continue
;
}
const
auto
in_type
=
input
.
duplicable
()
?
IN_VAR_LIST_TYPE
:
IN_VAR_TYPE
;
auto
input_arg
=
paddle
::
string
::
Sprintf
(
ARG_TEMPLATE
,
in_type
,
TempName
(
in_name
));
auto
input_arg
=
paddle
::
string
::
Sprintf
(
ARG_TEMPLATE
,
in_type
,
LegalizeVarName
(
TempName
(
in_name
)
));
input_args
+=
input_arg
;
input_args
+=
","
;
input_args_num
++
;
const
auto
in_cast_type
=
input
.
duplicable
()
?
CAST_VAR_LIST_TEMPLATE
:
CAST_VAR_TEMPLATE
;
auto
dispensable
=
input
.
dispensable
()
?
"true"
:
"false"
;
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
in_name
,
in_name
,
arg_idx
++
,
dispensable
);
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
LegalizeVarName
(
in_name
),
in_name
,
arg_idx
++
,
dispensable
);
if
(
input
.
dispensable
())
{
const
auto
in_template
=
input
.
duplicable
()
?
INPUT_INITIALIZER_TEMPLATE_WITH_NULL_LIST
:
INPUT_INITIALIZER_TEMPLATE_WITH_NULL
;
ins_initializer_with_null
+=
paddle
::
string
::
Sprintf
(
in_template
,
in_name
,
in_name
,
in_name
);
paddle
::
string
::
Sprintf
(
in_template
,
LegalizeVarName
(
in_name
),
in_name
,
LegalizeVarName
(
in_name
));
}
else
{
const
auto
in_template
=
input
.
duplicable
()
?
INPUT_LIST_INITIALIZER_TEMPLATE
:
INPUT_INITIALIZER_TEMPLATE
;
ins_initializer
+=
paddle
::
string
::
Sprintf
(
in_template
,
in_name
,
in_name
);
ins_initializer
+=
paddle
::
string
::
Sprintf
(
in_template
,
in_name
,
LegalizeVarName
(
in_name
));
ins_initializer
+=
","
;
}
}
...
...
@@ -259,7 +268,7 @@ std::string GenerateOpFunctionsBody(
input_args
+=
","
;
}
input_args
+=
out_type
;
input_args
+=
out_name
;
input_args
+=
LegalizeVarName
(
out_name
)
;
input_args_num
++
;
if
(
output
.
dispensable
())
{
...
...
@@ -272,16 +281,17 @@ std::string GenerateOpFunctionsBody(
const
auto
out_template
=
output
.
duplicable
()
?
INPUT_LIST_INITIALIZER_TEMPLATE
:
INPUT_INITIALIZER_TEMPLATE
;
outs_initializer
+=
paddle
::
string
::
Sprintf
(
out_template
,
out_name
,
out_name
);
outs_initializer
+=
paddle
::
string
::
Sprintf
(
out_template
,
out_name
,
LegalizeVarName
(
out_name
)
);
outs_initializer
+=
","
;
}
const
auto
in_cast_type
=
output
.
duplicable
()
?
CAST_VAR_LIST_TEMPLATE
:
CAST_VAR_TEMPLATE
;
auto
dispensable
=
output
.
dispensable
()
?
"true"
:
"false"
;
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
out_name
,
out_name
,
arg_idx
++
,
dispensable
);
ins_cast_str
+=
paddle
::
string
::
Sprintf
(
in_cast_type
,
LegalizeVarName
(
out_name
),
out_name
,
arg_idx
++
,
dispensable
);
}
else
if
(
use_inplace_strategy
&&
inplace_map
.
count
(
out_name
))
{
PADDLE_ENFORCE_NE
(
inplace_map
[
out_name
],
""
,
...
...
@@ -307,11 +317,13 @@ std::string GenerateOpFunctionsBody(
// Leaf Var that doesn't stop gradient can't use inplace strategy.
// Increase inplace_version.
inplace_strategy_str
+=
paddle
::
string
::
Sprintf
(
INPLACE_STRATEGY_TEMPLATE
,
inplace_input_name
,
inplace_input_name
,
INPLACE_LEAF_ERROR_MESSAGE
,
inplace_input_name
,
inplace_input_name
,
inplace_input_name
);
outs_initializer
+=
paddle
::
string
::
Sprintf
(
out_template
,
out_name
,
inplace_input_name
);
INPLACE_STRATEGY_TEMPLATE
,
LegalizeVarName
(
inplace_input_name
),
LegalizeVarName
(
inplace_input_name
),
INPLACE_LEAF_ERROR_MESSAGE
,
LegalizeVarName
(
inplace_input_name
),
LegalizeVarName
(
inplace_input_name
),
LegalizeVarName
(
inplace_input_name
));
outs_initializer
+=
paddle
::
string
::
Sprintf
(
out_template
,
out_name
,
LegalizeVarName
(
inplace_input_name
));
outs_initializer
+=
","
;
}
else
{
// There are few Operators that have duplicable output, like `Out` in
...
...
@@ -321,7 +333,8 @@ std::string GenerateOpFunctionsBody(
if
(
input_args
!=
""
)
{
input_args
+=
","
;
}
auto
out_num_str
=
paddle
::
string
::
Sprintf
(
ARG_OUT_NUM
,
out_name
);
auto
out_num_str
=
paddle
::
string
::
Sprintf
(
ARG_OUT_NUM
,
LegalizeVarName
(
out_name
));
input_args
+=
ARG_OUT_NUM_TYPE
;
input_args
+=
out_num_str
;
input_args_num
++
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录