Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
00b0344b
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看板
未验证
提交
00b0344b
编写于
7月 16, 2020
作者:
M
MaxwellDing
提交者:
GitHub
7月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MLU] fix: use new scale api, test=develop (#3942)
上级
42ab4d55
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
24 addition
and
21 deletion
+24
-21
lite/kernels/mlu/bridges/conv_op.cc
lite/kernels/mlu/bridges/conv_op.cc
+2
-3
lite/kernels/mlu/bridges/conv_op_test.cc
lite/kernels/mlu/bridges/conv_op_test.cc
+6
-4
lite/kernels/mlu/bridges/fc_op.cc
lite/kernels/mlu/bridges/fc_op.cc
+2
-2
lite/kernels/mlu/bridges/fc_op_test.cc
lite/kernels/mlu/bridges/fc_op_test.cc
+6
-5
lite/kernels/mlu/bridges/lrn_op.cc
lite/kernels/mlu/bridges/lrn_op.cc
+1
-2
lite/kernels/mlu/bridges/lrn_op_test.cc
lite/kernels/mlu/bridges/lrn_op_test.cc
+4
-3
lite/kernels/mlu/subgraph_compute.h
lite/kernels/mlu/subgraph_compute.h
+3
-2
未找到文件。
lite/kernels/mlu/bridges/conv_op.cc
浏览文件 @
00b0344b
...
...
@@ -107,8 +107,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
CNML_FILTER
,
CNML_NCHW
,
graph
->
FPType
());
const
auto
weight_scale
=
op_info
->
GetAttr
<
std
::
vector
<
float
>>
(
"weight_scale"
);
const
auto
weight_scale
=
op_info
->
GetInputScale
(
filter_var_name
);
if
(
filter
->
precision
()
==
PrecisionType
::
kUnk
||
filter
->
precision
()
==
PrecisionType
::
kInt8
)
{
...
...
@@ -162,7 +161,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
graph
->
BindConstData
(
bias_var_name
,
bias
);
}
const
auto
input_scale
=
op_info
->
Get
Attr
<
float
>
(
"input_scale"
)
;
const
auto
input_scale
=
op_info
->
Get
InputScale
(
input_var_name
)[
0
]
;
bool
use_first_conv
=
false
;
if
(
lite
::
TargetWrapperMlu
::
UseFirstConv
()
&&
input_dims
[
1
]
==
3
)
{
...
...
lite/kernels/mlu/bridges/conv_op_test.cc
浏览文件 @
00b0344b
...
...
@@ -224,8 +224,10 @@ void test_conv(int bs,
opdesc_mlu
.
SetAttr
(
"groups"
,
groups
);
opdesc_mlu
.
SetAttr
(
"fuse_relu"
,
static_cast
<
bool
>
(
fuse_relu
));
opdesc_mlu
.
SetAttr
(
"weight_scale"
,
std
::
vector
<
float
>
(
oc
,
filter_scale
));
opdesc_mlu
.
SetAttr
(
"input_scale"
,
input_scale
);
OpInfo
op_info
(
opdesc_mlu
);
op_info
.
SetInputScale
(
filter_int_var_name
,
std
::
vector
<
float
>
(
oc
,
filter_scale
));
op_info
.
SetInputScale
(
input_var_name
,
{
input_scale
});
if
(
has_bias
)
{
if
(
is_channel_bias
)
{
...
...
@@ -234,7 +236,7 @@ void test_conv(int bs,
bias
->
Resize
({
output_shape
});
}
FillTensor
<
float
>
(
bias
);
op
desc_mlu
.
SetInput
(
"Bias"
,
{
bias_var_name
});
op
_info
.
SetInput
(
"Bias"
,
{
bias_var_name
});
}
for
(
int
i
=
0
;
i
<
bs
;
i
++
)
{
...
...
@@ -248,7 +250,7 @@ void test_conv(int bs,
}
// create and convert op to MLU model, then run it on MLU
auto
op
=
CreateOp
<
operators
::
ConvOpLite
>
(
op
desc_mlu
,
&
scope
);
auto
op
=
CreateOp
<
operators
::
ConvOpLite
>
(
op
_info
,
&
scope
);
LaunchOp
(
op
,
{
input_var_name
},
{
output_var_name
});
// compare results
auto
*
output_data
=
output
->
mutable_data
<
float
>
();
...
...
lite/kernels/mlu/bridges/fc_op.cc
浏览文件 @
00b0344b
...
...
@@ -68,7 +68,7 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto
w_tensor
=
graph
->
AddNode
(
w_var_name
,
cnml_w_shape
,
CNML_FILTER
,
CNML_NCHW
,
graph
->
FPType
());
auto
input_scale
=
op_info
->
Get
Attr
<
float
>
(
"input_scale"
)
;
auto
input_scale
=
op_info
->
Get
InputScale
(
x_var_name
)[
0
]
;
auto
output_tensor
=
graph
->
AddNode
(
output_var_name
,
output
->
dims
().
Vectorize
(),
...
...
@@ -101,7 +101,7 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) {
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
));
graph
->
SetComputingDataType
(
fc_op
,
graph
->
GetNode
(
x_var_name
)
->
mlu_tensor
(),
1
/
input_scale
);
auto
weight_scale
=
op_info
->
Get
Attr
<
std
::
vector
<
float
>>
(
"weight_scale"
);
auto
weight_scale
=
op_info
->
Get
InputScale
(
w_var_name
);
// LOG(INFO) << "W precision " << int(w->precision());
if
(
w
->
precision
()
==
PrecisionType
::
kUnk
||
...
...
lite/kernels/mlu/bridges/fc_op_test.cc
浏览文件 @
00b0344b
...
...
@@ -131,14 +131,15 @@ void test_fc(const std::vector<int64_t>& input_shape,
fc_op_desc_mlu
.
SetOutput
(
"Out"
,
{
out_var_name
});
fc_op_desc_mlu
.
SetAttr
(
"in_num_col_dims"
,
static_cast
<
int
>
(
in_num_col_dims
));
fc_op_desc_mlu
.
SetAttr
(
"weight_scale"
,
std
::
vector
<
float
>
(
w_shape
[
1
],
w_scale
));
fc_op_desc_mlu
.
SetAttr
(
"input_scale"
,
input_scale
);
OpInfo
op_info
(
fc_op_desc_mlu
);
op_info
.
SetInputScale
(
w_int_var_name
,
std
::
vector
<
float
>
(
w_shape
[
1
],
w_scale
));
op_info
.
SetInputScale
(
input_var_name
,
{
input_scale
});
if
(
has_bias
)
{
fc_op_desc_mlu
.
SetInput
(
"Bias"
,
{
bias_var_name
});
op_info
.
SetInput
(
"Bias"
,
{
bias_var_name
});
}
auto
fc_op_mlu
=
CreateOp
<
operators
::
FcOpLite
>
(
fc_op_desc_mlu
,
&
scope
);
auto
fc_op_mlu
=
CreateOp
<
operators
::
FcOpLite
>
(
op_info
,
&
scope
);
Tensor
input_tmp
,
out_tmp
;
input_tmp
.
Resize
(
input_shape
);
...
...
lite/kernels/mlu/bridges/lrn_op.cc
浏览文件 @
00b0344b
...
...
@@ -49,8 +49,7 @@ int LrnConverter(void* ctx, OpLite* op, KernelBase* kernel) {
<<
"Unsuport WithinChannel"
;
}
auto
local_size
=
op_info
->
GetAttr
<
int
>
(
"n"
);
CHECK
(
op_info
->
HasAttr
(
"input_scale"
));
auto
input_scale
=
op_info
->
GetAttr
<
float
>
(
"input_scale"
);
auto
input_scale
=
op_info
->
GetInputScale
(
x_var_name
)[
0
];
VLOG
(
5
)
<<
"lrn input scale: "
<<
input_scale
;
cnmlLrnOpParam_t
param
;
...
...
lite/kernels/mlu/bridges/lrn_op_test.cc
浏览文件 @
00b0344b
...
...
@@ -178,9 +178,10 @@ void test_lrn(float alpha,
opdesc
.
SetAttr
(
"k"
,
k
);
opdesc
.
SetAttr
(
"n"
,
local_size
);
opdesc
.
SetAttr
(
"norm_region"
,
norm_region
);
opdesc
.
SetAttr
<
float
>
(
"input_scale"
,
(
*
dmax
-
*
dmin
)
/
255.
f
);
OpInfo
op_info
(
opdesc
);
op_info
.
SetInputScale
(
x_var_name
,
{(
*
dmax
-
*
dmin
)
/
255.
f
});
auto
op
=
CreateOp
<
operators
::
LrnOpLite
>
(
op
desc
,
&
scope
);
auto
op
=
CreateOp
<
operators
::
LrnOpLite
>
(
op
_info
,
&
scope
);
// baseline
lrn_compute_ref
(
op
);
...
...
@@ -213,7 +214,7 @@ void test_lrn(float alpha,
auto
output_data
=
output_trans
.
mutable_data
<
float
>
();
auto
*
output_ref_data
=
out_ref
->
mutable_data
<
float
>
();
for
(
size_t
i
=
0
;
i
<
out
->
data_size
();
i
++
)
{
EXPECT_NEAR
(
output_data
[
i
],
output_ref_data
[
i
],
1
e-4
);
EXPECT_NEAR
(
output_data
[
i
],
output_ref_data
[
i
],
5
e-4
);
}
}
...
...
lite/kernels/mlu/subgraph_compute.h
浏览文件 @
00b0344b
...
...
@@ -54,10 +54,11 @@ class SubgraphEngine : public subgraph::Engine {
VLOG
(
4
)
<<
"[MLU] PADDLE_LITE_MLU_SAVE_OFFLINE_MODEL is "
<<
GetBoolFromEnv
(
"PADDLE_LITE_MLU_SAVE_OFFLINE_MODEL"
);
VLOG
(
4
)
<<
"[MLU] PADDLE_LITE_MLU_DISABLE_BATCH_SIZE_CHANGEABLE is "
<<
GetBoolFromEnv
(
"PADDLE_LITE_MLU_DISABLE_BATCH_SIZE_CHANGEABLE"
);
<<
GetBoolFromEnv
(
"PADDLE_LITE_MLU_DISABLE_BATCH_SIZE_CHANGEABLE"
,
true
);
VLOG
(
4
)
<<
"[MLU] LITE_DISABLE_MLU_CAST is "
<<
GetBoolFromEnv
(
"LITE_DISABLE_MLU_CAST"
);
if
(
GetBoolFromEnv
(
"PADDLE_LITE_MLU_DISABLE_BATCH_SIZE_CHANGEABLE"
))
{
if
(
GetBoolFromEnv
(
"PADDLE_LITE_MLU_DISABLE_BATCH_SIZE_CHANGEABLE"
,
true
))
{
disable_batch_size_changeable_
=
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录