Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
4b761774
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4b761774
编写于
11月 29, 2018
作者:
Y
Yan Chunwei
提交者:
GitHub
11月 29, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix container not cleared (#14231)
上级
44debca8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
9 deletion
+51
-9
paddle/fluid/inference/analysis/analysis_pass.h
paddle/fluid/inference/analysis/analysis_pass.h
+0
-2
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+8
-4
paddle/fluid/inference/api/api_impl.cc
paddle/fluid/inference/api/api_impl.cc
+3
-3
paddle/fluid/inference/api/details/reset_tensor_array.cc
paddle/fluid/inference/api/details/reset_tensor_array.cc
+23
-0
paddle/fluid/inference/api/details/reset_tensor_array.h
paddle/fluid/inference/api/details/reset_tensor_array.h
+17
-0
未找到文件。
paddle/fluid/inference/analysis/analysis_pass.h
浏览文件 @
4b761774
...
...
@@ -46,8 +46,6 @@ class AnalysisPass {
protected:
// User should implement these.
virtual
void
RunImpl
(
Argument
*
argument
)
=
0
;
Argument
*
argument_
{
nullptr
};
};
}
// namespace analysis
...
...
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
4b761774
...
...
@@ -190,9 +190,13 @@ bool AnalysisPredictor::Run(const std::vector<PaddleTensor> &inputs,
}
VLOG
(
3
)
<<
"predict cost: "
<<
timer
.
toc
()
<<
"ms"
;
// Fix TensorArray reuse not cleaned bug.
tensor_array_batch_cleaner_
.
CollectTensorArrays
(
scope_
.
get
());
tensor_array_batch_cleaner_
.
ResetTensorArray
();
// All the containers in the scope will be hold in inference, but the
// operators assume that the container will be reset after each batch.
// Here is a bugfix, collect all the container variables, and reset then to a
// bool; the next time, the operator will call MutableData and construct a new
// container again, so that the container will be empty for each batch.
tensor_array_batch_cleaner_
.
CollectNoTensorVars
(
sub_scope_
);
tensor_array_batch_cleaner_
.
ResetNoTensorVars
();
return
true
;
}
...
...
@@ -417,7 +421,7 @@ std::unique_ptr<ZeroCopyTensor> AnalysisPredictor::GetOutputTensor(
bool
AnalysisPredictor
::
ZeroCopyRun
()
{
executor_
->
Run
();
// Fix TensorArray reuse not cleaned bug.
tensor_array_batch_cleaner_
.
CollectTensorArrays
(
s
cope_
.
get
()
);
tensor_array_batch_cleaner_
.
CollectTensorArrays
(
s
ub_scope_
);
tensor_array_batch_cleaner_
.
ResetTensorArray
();
return
true
;
}
...
...
paddle/fluid/inference/api/api_impl.cc
浏览文件 @
4b761774
...
...
@@ -154,9 +154,9 @@ bool NativePaddlePredictor::Run(const std::vector<PaddleTensor> &inputs,
}
VLOG
(
3
)
<<
"predict cost: "
<<
timer
.
toc
()
<<
"ms"
;
// F
ix TensorArray reuse not cleaned bug
.
tensor_array_batch_cleaner_
.
Collect
TensorArray
s
(
scope_
.
get
());
tensor_array_batch_cleaner_
.
Reset
TensorArray
();
// F
or some other vector like containers not cleaned after each batch
.
tensor_array_batch_cleaner_
.
Collect
NoTensorVar
s
(
scope_
.
get
());
tensor_array_batch_cleaner_
.
Reset
NoTensorVars
();
return
true
;
}
...
...
paddle/fluid/inference/api/details/reset_tensor_array.cc
浏览文件 @
4b761774
...
...
@@ -46,5 +46,28 @@ void TensorArrayBatchCleaner::ResetTensorArray() {
}
}
void
TensorArrayBatchCleaner
::
CollectNoTensorVars
(
framework
::
Scope
*
scope
)
{
if
(
no_tensor_flag_
)
{
for
(
auto
&
var_name
:
scope
->
LocalVarNames
())
{
auto
*
var
=
scope
->
FindVar
(
var_name
);
if
(
!
var
->
IsInitialized
())
continue
;
if
(
!
valid_types_
.
count
(
var
->
Type
()))
{
no_tensor_vars_
.
insert
(
var
);
}
}
for
(
auto
*
kid
:
scope
->
kids
())
{
CollectTensorArrays
(
kid
);
}
no_tensor_flag_
=
false
;
// Only collect one time.
}
}
void
TensorArrayBatchCleaner
::
ResetNoTensorVars
()
{
for
(
auto
*
var
:
no_tensor_vars_
)
{
var
->
Clear
();
}
}
}
// namespace details
}
// namespace paddle
paddle/fluid/inference/api/details/reset_tensor_array.h
浏览文件 @
4b761774
...
...
@@ -14,9 +14,11 @@
#pragma once
#include <unordered_set>
#include <vector>
#include "paddle/fluid/framework/lod_tensor_array.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/variable.h"
namespace
paddle
{
namespace
details
{
...
...
@@ -24,13 +26,28 @@ namespace details {
// Clean the TensorArray each batch to make the behavior the same with the
// training phase.
struct
TensorArrayBatchCleaner
{
TensorArrayBatchCleaner
()
{
valid_types_
.
insert
(
typeid
(
framework
::
Tensor
));
valid_types_
.
insert
(
typeid
(
framework
::
LoDTensor
));
}
// Collect the variables that are not Tensor or LoDTensor, and reset them to a
// bool(trick), because some of them are containers, and some operators just
// keep inserting new items without clearing the containers first; So the
// memory grow larger and larger in inference service deployed online.
void
CollectNoTensorVars
(
framework
::
Scope
*
scope
);
void
ResetNoTensorVars
();
// Fix the tensor array not clear in the inference scenarios.
void
CollectTensorArrays
(
framework
::
Scope
*
scope
);
void
ResetTensorArray
();
private:
bool
flag_
{
true
};
bool
no_tensor_flag_
{
true
};
std
::
vector
<
framework
::
LoDTensorArray
*>
arrays_
;
std
::
unordered_set
<
std
::
type_index
>
valid_types_
;
std
::
unordered_set
<
framework
::
Variable
*>
no_tensor_vars_
;
};
}
// namespace details
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录