Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
ece74c4c
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看板
未验证
提交
ece74c4c
编写于
9月 10, 2020
作者:
Z
Zhen Wang
提交者:
GitHub
9月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update the _get_fake_quant_type definition in imperative QAT. (#27222)
上级
f6be5989
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
14 deletion
+36
-14
python/paddle/fluid/contrib/slim/quantization/imperative/qat.py
.../paddle/fluid/contrib/slim/quantization/imperative/qat.py
+0
-1
python/paddle/fluid/contrib/slim/quantization/imperative/quant_nn.py
...le/fluid/contrib/slim/quantization/imperative/quant_nn.py
+36
-13
未找到文件。
python/paddle/fluid/contrib/slim/quantization/imperative/qat.py
浏览文件 @
ece74c4c
...
...
@@ -192,7 +192,6 @@ class ImperativeQuantAware(object):
assert
len
(
input_dtype
)
==
len
(
feed
),
"The length of input_shape should be equal to feed's."
prog_trans
=
dygraph
.
ProgramTranslator
()
with
dygraph
.
guard
():
model
.
eval
()
input_vars
=
[]
...
...
python/paddle/fluid/contrib/slim/quantization/imperative/quant_nn.py
浏览文件 @
ece74c4c
...
...
@@ -209,15 +209,24 @@ class FakeQuantAbsMax(layers.Layer):
return
quant_out
def
_get_fake_quant_type
(
quant_type
,
name
,
moving_rate
,
quant_bits
,
dtype
,
quant_on_weight
):
def
_get_fake_quant_type
(
quant_type
,
**
kwargs
):
call_args
=
{
"name"
:
kwargs
.
get
(
"name"
,
None
),
"quant_bits"
:
kwargs
.
get
(
"quant_bits"
,
8
),
"dtype"
:
kwargs
.
get
(
"dtype"
,
"float32"
)
}
if
quant_type
==
'abs_max'
:
call_args
[
"quant_on_weight"
]
=
kwargs
.
get
(
"quant_on_weight"
,
False
)
elif
quant_type
==
'moving_average_abs_max'
:
call_args
[
"moving_rate"
]
=
kwargs
.
get
(
"moving_rate"
,
0.9
)
fake_quant_map
=
{
'abs_max'
:
lambda
:
FakeQuantAbsMax
(
name
,
quant_bits
,
dtype
,
quant_on_weight
),
'moving_average_abs_max'
:
lambda
:
FakeQuantMovingAverage
(
name
,
moving_rate
,
quant_bits
,
dtype
)
'abs_max'
:
FakeQuantAbsMax
,
'moving_average_abs_max'
:
FakeQuantMovingAverage
}
return
fake_quant_map
[
quant_type
]()
return
fake_quant_map
[
quant_type
](
**
call_args
)
class
QuantizedConv2D
(
layers
.
Layer
):
...
...
@@ -247,11 +256,18 @@ class QuantizedConv2D(layers.Layer):
self
.
bias
=
getattr
(
layer
,
'bias'
)
# For FakeQuant
self
.
_fake_quant_weight
=
_get_fake_quant_type
(
weight_quantize_type
,
self
.
weight
.
name
,
moving_rate
,
weight_bits
,
self
.
_dtype
,
True
)
weight_quantize_type
,
name
=
self
.
weight
.
name
,
moving_rate
=
moving_rate
,
quant_bits
=
weight_bits
,
dtype
=
self
.
_dtype
,
quant_on_weight
=
True
)
self
.
_fake_quant_input
=
_get_fake_quant_type
(
activation_quantize_type
,
layer
.
full_name
(),
moving_rate
,
activation_bits
,
self
.
_dtype
,
False
)
name
=
layer
.
full_name
(),
moving_rate
=
moving_rate
,
quant_bits
=
activation_bits
,
dtype
=
self
.
_dtype
)
def
forward
(
self
,
input
):
quant_input
=
self
.
_fake_quant_input
(
input
)
...
...
@@ -326,11 +342,18 @@ class QuantizedLinear(layers.Layer):
self
.
bias
=
getattr
(
layer
,
'bias'
)
# For FakeQuant
self
.
_fake_quant_weight
=
_get_fake_quant_type
(
weight_quantize_type
,
self
.
weight
.
name
,
moving_rate
,
weight_bits
,
self
.
_dtype
,
True
)
weight_quantize_type
,
name
=
self
.
weight
.
name
,
moving_rate
=
moving_rate
,
quant_bits
=
weight_bits
,
dtype
=
self
.
_dtype
,
quant_on_weight
=
True
)
self
.
_fake_quant_input
=
_get_fake_quant_type
(
activation_quantize_type
,
layer
.
full_name
(),
moving_rate
,
activation_bits
,
self
.
_dtype
,
False
)
name
=
layer
.
full_name
(),
moving_rate
=
moving_rate
,
quant_bits
=
activation_bits
,
dtype
=
self
.
_dtype
)
def
forward
(
self
,
input
):
quant_input
=
self
.
_fake_quant_input
(
input
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录