Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b4806644
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看板
未验证
提交
b4806644
编写于
9月 12, 2021
作者:
J
joanna.wozna.intel
提交者:
GitHub
9月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update scales when var is unsigned (#35599)
上级
83424033
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
5 deletion
+17
-5
python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py
...luid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py
+16
-4
python/paddle/fluid/contrib/slim/tests/CMakeLists.txt
python/paddle/fluid/contrib/slim/tests/CMakeLists.txt
+1
-1
未找到文件。
python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py
浏览文件 @
b4806644
...
...
@@ -215,7 +215,8 @@ class Quant2Int8MkldnnPass(object):
for
op
in
graph
.
all_op_nodes
():
if
op
.
op
().
has_attr
(
"out_threshold"
):
attr_scale
=
op
.
op
().
attr
(
"out_threshold"
)
if
attr_scale
==
0.0
:
continue
if
attr_scale
==
0.0
:
continue
scale
=
np
.
array
(
1.0
/
attr_scale
).
astype
(
np
.
float64
)
scale
[
scale
==
np
.
Inf
]
=
0.0
scale_lod_tensor
=
self
.
_convert_scale2tensor
(
scale
)
...
...
@@ -559,15 +560,26 @@ class Quant2Int8MkldnnPass(object):
out_name
=
op
.
output
(
op_out_name
)[
0
]
if
out_name
in
self
.
_var_quant_scales
and
predicate
(
op
.
op
(
)):
_
,
tensor
=
self
.
_var_quant_scales
[
out_name
]
is_unsigned
,
tensor
=
self
.
_var_quant_scales
[
out_name
]
if
is_unsigned
is
False
:
# If the variable is signed, it means that the scales for this var
# were computed for signed data, so the scale must be multiplied by 2
# to fill the entire range of uint8
scale
=
np
.
array
(
tensor
)
*
2
tensor
=
self
.
_convert_scale2tensor
(
scale
.
astype
(
np
.
float64
))
self
.
_var_quant_scales
[
out_name
]
=
(
True
,
tensor
)
return
graph
conv_predicate
=
lambda
op
:
op
.
attr
(
"fuse_activation"
)
in
self
.
_relu_ops
def
conv_predicate
(
op
):
return
op
.
attr
(
"fuse_activation"
)
in
self
.
_relu_ops
graph
=
_set_unsigned_scale
(
graph
,
self
.
_conv_ops
,
"Output"
,
conv_predicate
)
fc_predicate
=
lambda
op
:
op
.
attr
(
"activation_type"
)
in
self
.
_relu_ops
def
fc_predicate
(
op
):
return
op
.
attr
(
"activation_type"
)
in
self
.
_relu_ops
graph
=
_set_unsigned_scale
(
graph
,
self
.
_fc_ops
,
"Out"
,
fc_predicate
)
graph
=
_set_unsigned_scale
(
graph
,
self
.
_relu_ops
,
'Out'
,
...
...
python/paddle/fluid/contrib/slim/tests/CMakeLists.txt
浏览文件 @
b4806644
...
...
@@ -71,7 +71,7 @@ function(inference_quant2_int8_image_classification_test target quant_model_dir
ARGS --quant_model
${
quant_model_dir
}
--fp32_model
${
fp32_model_dir
}
--infer_data
${
dataset_path
}
--batch_size
1
0
--batch_size
5
0
--batch_num 2
--acc_diff_threshold 0.1
)
endfunction
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录