Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
6dcbe32b
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6dcbe32b
编写于
5月 22, 2020
作者:
H
huzhiqiang
提交者:
GitHub
5月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick][BUG FIX] fix the issue that opt can not convert quantized model (#3683)
上级
6acf04c6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
22 deletion
+24
-22
lite/core/program.cc
lite/core/program.cc
+24
-22
未找到文件。
lite/core/program.cc
浏览文件 @
6dcbe32b
...
@@ -73,7 +73,7 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
...
@@ -73,7 +73,7 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
std
::
unordered_map
<
std
::
string
,
cpp
::
VarDesc
>
origin_var_maps
;
std
::
unordered_map
<
std
::
string
,
cpp
::
VarDesc
>
origin_var_maps
;
auto
&
main_block
=
*
desc
->
GetBlock
<
cpp
::
BlockDesc
>
(
0
);
auto
&
main_block
=
*
desc
->
GetBlock
<
cpp
::
BlockDesc
>
(
0
);
auto
var_size
=
main_block
.
VarsSize
();
auto
var_size
=
main_block
.
VarsSize
();
for
(
size_
t
i
=
0
;
i
<
var_size
;
i
++
)
{
for
(
in
t
i
=
0
;
i
<
var_size
;
i
++
)
{
auto
v
=
main_block
.
GetVar
<
cpp
::
VarDesc
>
(
i
);
auto
v
=
main_block
.
GetVar
<
cpp
::
VarDesc
>
(
i
);
auto
name
=
v
->
Name
();
auto
name
=
v
->
Name
();
origin_var_maps
.
emplace
(
name
,
*
v
);
origin_var_maps
.
emplace
(
name
,
*
v
);
...
@@ -86,16 +86,12 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
...
@@ -86,16 +86,12 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
auto
*
scope
=
op
->
scope
();
auto
*
scope
=
op
->
scope
();
auto
in_names
=
op
->
op_info
()
->
input_names
();
auto
in_names
=
op
->
op_info
()
->
input_names
();
auto
out_names
=
op
->
op_info
()
->
output_names
();
auto
out_names
=
op
->
op_info
()
->
output_names
();
in_names
.
insert
(
in_names
.
end
(),
out_names
.
begin
(),
out_names
.
end
());
std
::
vector
<
std
::
string
>
var_names
;
std
::
sort
(
in_names
.
begin
(),
in_names
.
end
());
var_names
.
insert
(
var_names
.
end
(),
in_names
.
begin
(),
in_names
.
end
());
in_names
.
erase
(
std
::
unique
(
in_names
.
begin
(),
in_names
.
end
()),
var_names
.
insert
(
var_names
.
end
(),
out_names
.
begin
(),
out_names
.
end
());
in_names
.
end
());
std
::
sort
(
var_names
.
begin
(),
var_names
.
end
());
for
(
auto
&
in_name
:
in_names
)
{
var_names
.
erase
(
std
::
unique
(
var_names
.
begin
(),
var_names
.
end
()),
auto
it
=
origin_var_maps
.
find
(
in_name
);
var_names
.
end
());
for
(
auto
&
var_name
:
var_names
)
{
auto
it
=
origin_var_maps
.
find
(
var_name
);
if
(
it
!=
origin_var_maps
.
end
())
{
if
(
it
!=
origin_var_maps
.
end
())
{
auto
*
v
=
main_block
.
AddVar
<
cpp
::
VarDesc
>
();
auto
*
v
=
main_block
.
AddVar
<
cpp
::
VarDesc
>
();
v
->
SetName
((
it
->
second
).
Name
());
v
->
SetName
((
it
->
second
).
Name
());
...
@@ -108,30 +104,37 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
...
@@ -108,30 +104,37 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
}
else
{
}
else
{
// New created vars must be LOD_TENSOR
// New created vars must be LOD_TENSOR
auto
*
v
=
main_block
.
AddVar
<
cpp
::
VarDesc
>
();
auto
*
v
=
main_block
.
AddVar
<
cpp
::
VarDesc
>
();
v
->
SetName
(
var
_name
);
v
->
SetName
(
in
_name
);
v
->
SetType
(
cpp
::
VarDesc
::
Type
::
LOD_TENSOR
);
v
->
SetType
(
cpp
::
VarDesc
::
Type
::
LOD_TENSOR
);
std
::
string
in_arg_name
;
std
::
string
in_arg_name
;
op
->
op_info
()
->
GetInputArgname
(
var_name
,
&
in_arg_name
);
const
Type
*
type
;
auto
type
=
kernel
->
GetInputDeclType
(
in_arg_name
);
if
(
op
->
op_info
()
->
GetInputArgname
(
in_name
,
&
in_arg_name
))
{
type
=
kernel
->
GetInputDeclType
(
in_arg_name
);
}
else
{
op
->
op_info
()
->
GetOutputArgname
(
in_name
,
&
in_arg_name
);
type
=
kernel
->
GetOutputDeclType
(
in_arg_name
);
}
if
(
type
->
IsTensor
())
{
if
(
type
->
IsTensor
())
{
auto
tensor
=
scope
->
FindVar
(
var
_name
)
->
GetMutable
<
Tensor
>
();
auto
tensor
=
scope
->
FindVar
(
in
_name
)
->
GetMutable
<
Tensor
>
();
v
->
SetPersistable
(
tensor
->
persistable
());
v
->
SetPersistable
(
tensor
->
persistable
());
if
(
(
it
->
second
).
Name
()
!=
"feed"
&&
(
it
->
second
).
Name
()
!=
"fetch"
)
{
if
(
in_name
!=
"feed"
&&
in_name
!=
"fetch"
)
{
v
->
SetShape
(
tensor
->
dims
().
data
());
v
->
SetShape
(
tensor
->
dims
().
data
());
switch
(
tensor
->
precision
())
{
switch
(
tensor
->
precision
())
{
#define SET_DATATYPE(precision__, data_type) \
#define SET_DATATYPE(precision__, data_type) \
case PrecisionType::precision__: \
case PrecisionType::precision__: \
v->SetDataType(data_type); \
v->SetDataType(data_type); \
LOG(INFO) << "update var" << (it->second).Name() << "done"; \
break
break
SET_DATATYPE
(
kBool
,
VarDescAPI
::
VarDataType
::
BOOL
);
SET_DATATYPE
(
kFloat
,
VarDescAPI
::
VarDataType
::
FP32
);
SET_DATATYPE
(
kFloat
,
VarDescAPI
::
VarDataType
::
FP32
);
SET_DATATYPE
(
kFP16
,
VarDescAPI
::
VarDataType
::
FP16
);
SET_DATATYPE
(
kInt8
,
VarDescAPI
::
VarDataType
::
INT8
);
SET_DATATYPE
(
kInt8
,
VarDescAPI
::
VarDataType
::
INT8
);
SET_DATATYPE
(
kInt16
,
VarDescAPI
::
VarDataType
::
INT16
);
SET_DATATYPE
(
kInt16
,
VarDescAPI
::
VarDataType
::
INT16
);
SET_DATATYPE
(
kInt32
,
VarDescAPI
::
VarDataType
::
INT32
);
SET_DATATYPE
(
kInt32
,
VarDescAPI
::
VarDataType
::
INT32
);
SET_DATATYPE
(
kInt64
,
VarDescAPI
::
VarDataType
::
INT64
);
SET_DATATYPE
(
kInt64
,
VarDescAPI
::
VarDataType
::
INT64
);
#undef SET_DATATYPE
#undef SET_DATATYPE
default:
default:
LOG
(
FATAL
)
<<
"
unknown precision type"
;
VLOG
(
4
)
<<
"warning!
unknown precision type"
;
}
}
}
}
}
else
{
}
else
{
...
@@ -141,7 +144,6 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
...
@@ -141,7 +144,6 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
}
}
}
}
}
}
void
RuntimeProgram
::
Run
()
{
void
RuntimeProgram
::
Run
()
{
#ifdef LITE_WITH_PRECISION_PROFILE
#ifdef LITE_WITH_PRECISION_PROFILE
auto
inst_precision_profiler
=
paddle
::
lite
::
profile
::
PrecisionProfiler
();
auto
inst_precision_profiler
=
paddle
::
lite
::
profile
::
PrecisionProfiler
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录