Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
911cb2ea
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
911cb2ea
编写于
2月 22, 2022
作者:
Z
Zhanlue Yang
提交者:
GitHub
2月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support NoNeedBuffer for final state codegen (#39628)
* Support NoNeedBuffer for final state codegen * Replaced pten with phi
上级
8d1d0bdf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
8 deletion
+43
-8
paddle/fluid/eager/auto_code_generator/final_state_generator/eager_gen.py
...er/auto_code_generator/final_state_generator/eager_gen.py
+25
-6
paddle/fluid/eager/tensor_wrapper.h
paddle/fluid/eager/tensor_wrapper.h
+18
-2
未找到文件。
paddle/fluid/eager/auto_code_generator/final_state_generator/eager_gen.py
浏览文件 @
911cb2ea
...
...
@@ -127,6 +127,15 @@ def ReadBwdFile(filepath):
######################
### Yaml Parsers ###
######################
def
ParseNoNeedBuffer
(
string
):
# string: "x, y"
no_need_buffer_set
=
set
()
for
name
in
string
.
split
(
","
):
no_need_buffer_set
.
add
(
name
.
strip
())
return
no_need_buffer_set
def
ParseYamlArgs
(
string
):
# Example: const Tensor& x, const Tensor& y, bool transpose_x, bool transpose_y
...
...
@@ -397,7 +406,7 @@ def SlotNameMatching(backward_inputs_list, backward_returns_list,
def
GenerateNodeDeclaration
(
fwd_api_name
,
backward_fwd_input_map
,
backward_attrs_list
):
backward_attrs_list
,
no_need_buffer_set
):
# Inputs:
# fwd_api_name = ""
# backward_fwd_input_map = { "name" : [type, is_fwd_input, orig_position] ...}
...
...
@@ -410,15 +419,20 @@ def GenerateNodeDeclaration(fwd_api_name, backward_fwd_input_map,
set_tensor_wrapper_methods_str
=
""
tensor_wrapper_members_str
=
""
for
tname
,
(
ttype
,
is_fwd_input
,
_
)
in
backward_fwd_input_map
.
items
():
if
tname
in
no_need_buffer_set
:
no_need_buffer
=
"true"
else
:
no_need_buffer
=
"false"
tensor_wrapper_name
=
GetSavedName
(
tname
)
if
IsPlainTensorType
(
ttype
):
SET_PLAIN_TENSOR_WRAPPER_TEMPLATE
=
"""
void SetTensorWrapper{}(const paddle::experimental::Tensor& {}, bool full_reserved) {{
{} = egr::TensorWrapper({}, full_reserved);
{} = egr::TensorWrapper({}, full_reserved
, {}
);
}}
"""
set_tensor_wrapper_methods_str
+=
SET_PLAIN_TENSOR_WRAPPER_TEMPLATE
.
format
(
tname
,
tname
,
tensor_wrapper_name
,
tname
)
tname
,
tname
,
tensor_wrapper_name
,
tname
,
no_need_buffer
)
PLAIN_TENSOR_MEMBER_TEMPLATE
=
"""
egr::TensorWrapper {};
...
...
@@ -430,12 +444,12 @@ def GenerateNodeDeclaration(fwd_api_name, backward_fwd_input_map,
SET_VECTOR_TENSOR_WRAPPER_TEMPLATE
=
"""
void SetTensorWrapper{}(const std::vector<paddle::experimental::Tensor>& {}, bool full_reserved) {{
for(const auto& eager_tensor : {}) {{
{}.emplace_back( egr::TensorWrapper(eager_tensor, full_reserved) );
{}.emplace_back( egr::TensorWrapper(eager_tensor, full_reserved
, {}
) );
}};
}}
"""
set_tensor_wrapper_methods_str
+=
SET_VECTOR_TENSOR_WRAPPER_TEMPLATE
.
format
(
tname
,
tname
,
tname
,
tensor_wrapper_name
)
tname
,
tname
,
tname
,
tensor_wrapper_name
,
no_need_buffer
)
VECTOR_TENSOR_MEMBER_TEMPLATE
=
"""
std::vector<egr::TensorWrapper> {};
...
...
@@ -997,6 +1011,10 @@ if __name__ == "__main__":
assert
'output'
in
fwd_api
.
keys
()
assert
'backward'
in
fwd_api
.
keys
()
no_need_buffer_set
=
set
()
if
'no_need_buffer'
in
fwd_api
.
keys
():
no_need_buffer_set
=
ParseNoNeedBuffer
(
fwd_api
[
'no_need_buffer'
])
fwd_api_name
=
fwd_api
[
'api'
]
fwd_args_str
=
fwd_api
[
'args'
]
fwd_returns_str
=
fwd_api
[
'output'
]
...
...
@@ -1062,7 +1080,8 @@ if __name__ == "__main__":
# Node Declaration Generation
node_declaration_str
+=
GenerateNodeDeclaration
(
fwd_api_name
,
backward_fwd_input_map
,
backward_attrs_list
)
fwd_api_name
,
backward_fwd_input_map
,
backward_attrs_list
,
no_need_buffer_set
)
print
(
"Generated Node Declaration: "
,
node_declaration_str
)
node_definition_str
+=
GenerateNodeDefinition
(
...
...
paddle/fluid/eager/tensor_wrapper.h
浏览文件 @
911cb2ea
...
...
@@ -34,7 +34,8 @@ class TensorWrapper {
public:
TensorWrapper
()
=
default
;
explicit
TensorWrapper
(
const
paddle
::
experimental
::
Tensor
&
tensor
,
bool
full_reserved
=
false
)
{
bool
full_reserved
=
false
,
bool
no_need_buffer
=
false
)
{
/**
* Normally, we should fully reserved all non-output or non-leaf fwd tensor
* here. And for fwd output tensor, we should not reserve its autogradmeta,
...
...
@@ -48,7 +49,22 @@ class TensorWrapper {
}
// shallow copy tensor_impl here
intermidiate_tensor_
.
set_impl
(
tensor
.
impl
());
if
(
no_need_buffer
)
{
if
(
phi
::
DenseTensor
::
classof
(
tensor
.
impl
().
get
()))
{
// Only Copy Meta
phi
::
DenseTensor
*
dense_tensor
=
static_cast
<
phi
::
DenseTensor
*>
(
tensor
.
impl
().
get
());
auto
tw_dense_tensor
=
std
::
make_shared
<
phi
::
DenseTensor
>
();
tw_dense_tensor
->
set_meta
(
dense_tensor
->
meta
());
intermidiate_tensor_
.
set_impl
(
tw_dense_tensor
);
}
else
{
PADDLE_THROW
(
paddle
::
platform
::
errors
::
Fatal
(
"Unrecognized tensor type for no_need_buffer feature"
));
}
}
else
{
intermidiate_tensor_
.
set_impl
(
tensor
.
impl
());
}
intermidiate_tensor_
.
set_name
(
tensor
.
name
()
+
"@Saved"
);
PADDLE_ENFORCE_NOT_NULL
(
EagerUtils
::
unsafe_autograd_meta
(
tensor
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录