未验证 提交 c90ab602 编写于 作者: Z zhouzj 提交者: GitHub

[ACT] Rename 'Quantization' to 'QuantAware'. (#1536)

* [ACT] Rename 'Quantization' to 'QuantAware'.

* Fix examples.

* Fix tests.
上级 dfe5bb3e
......@@ -178,7 +178,7 @@ ac = AutoCompression(
params_filename="inference.pdiparams",
save_dir="MobileNetV1_quant",
config={"QuantPost": {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}},
### config={"Quantization": {}, "Distillation": {}}, ### 如果您的系统为Windows系统, 请使用当前这一行配置
### config={"QuantAware": {}, "Distillation": {}}, ### 如果您的系统为Windows系统, 请使用当前这一行配置
train_dataloader=train_loader,
eval_dataloader=train_loader)
ac.compress()
......
......@@ -18,7 +18,7 @@ Distillation:
- conv2d_154.tmp_1
- tmp_8
Quantization:
QuantAware:
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
weight_bits: 8
......
......@@ -11,7 +11,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
......
......@@ -11,7 +11,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
......
......@@ -13,7 +13,7 @@ Distillation:
- concat_2.tmp_0
- concat_1.tmp_0
Quantization:
QuantAware:
use_pact: True
weight_quantize_type: 'channel_wise_abs_max'
activation_quantize_type: 'moving_average_abs_max'
......
......@@ -12,7 +12,7 @@ Distillation:
node:
- conv2d_441.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
weight_quantize_type: 'channel_wise_abs_max' # 'abs_max' is layer wise quant
......
......@@ -13,7 +13,7 @@ Distillation:
- conv2d_85.tmp_0
- conv2d_86.tmp_0
Quantization:
QuantAware:
activation_quantize_type: 'range_abs_max'
quantize_op_types:
- conv2d
......
......@@ -3,11 +3,11 @@
## 1.1 各压缩方法超参解析
### 1.1.1 量化训练(quantization
### 1.1.1 量化训练(quant aware
量化参数主要设置量化比特数和量化op类型,其中量化op包含卷积层(conv2d, depthwise_conv2d)和全连接层(mul, matmul_v2)。以下为只量化卷积层的示例:
```yaml
Quantization:
QuantAware:
use_pact: false # 量化训练是否使用PACT方法
weight_quantize_type: 'channel_wise_abs_max' # 权重量化方式
quantize_op_types: [conv2d, depthwise_conv2d] # 量化OP列表
......
......@@ -11,7 +11,7 @@ Distillation:
node:
- softmax_1.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -10,7 +10,7 @@ Distillation:
loss: l2
node:
- softmax_0.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -12,7 +12,7 @@ Distillation:
loss: l2
node:
- softmax_1.tmp_0
Quantization:
QuantAware:
is_full_quantize: false
activation_quantize_type: moving_average_abs_max
weight_quantize_type: channel_wise_abs_max
......
......@@ -10,7 +10,7 @@ Distillation:
loss: l2
node:
- softmax_0.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -9,7 +9,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -11,7 +11,7 @@ Distillation:
node:
- softmax_1.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -11,7 +11,7 @@ Distillation:
node:
- softmax_1.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -10,7 +10,7 @@ Distillation:
loss: l2
node:
- softmax_1.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -11,7 +11,7 @@ Distillation:
node:
- softmax_0.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -10,7 +10,7 @@ Distillation:
loss: l2
node:
- softmax_0.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -10,7 +10,7 @@ Distillation:
loss: l2
node:
- softmax_0.tmp_0
Quantization:
QuantAware:
activation_bits: 8
is_full_quantize: false
activation_quantize_type: moving_average_abs_max
......
......@@ -10,7 +10,7 @@ Distillation:
loss: l2
node:
- softmax_48.tmp_0
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -9,7 +9,7 @@ Distillation:
alpha: 1.0
loss: l2
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -12,7 +12,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
......
......@@ -12,7 +12,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
activation_quantize_type: 'moving_average_abs_max'
quantize_op_types:
......
......@@ -13,7 +13,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
activation_quantize_type: 'moving_average_abs_max'
quantize_op_types:
......
......@@ -12,7 +12,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
activation_quantize_type: 'moving_average_abs_max'
quantize_op_types:
......
......@@ -12,7 +12,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
onnx_format: true
activation_quantize_type: 'moving_average_abs_max'
quantize_op_types:
......
......@@ -11,7 +11,7 @@ Distillation:
node:
- conv2d_103.tmp_1
Quantization:
QuantAware:
onnx_format: True
quantize_op_types:
- conv2d
......
......@@ -11,7 +11,7 @@ Distillation:
node:
- conv2d_123.tmp_1
Quantization:
QuantAware:
onnx_format: True
quantize_op_types:
- conv2d
......
......@@ -10,7 +10,7 @@ Distillation:
node:
- conv2d_613.tmp_1
Quantization:
QuantAware:
onnx_format: True
quantize_op_types:
- conv2d
......
......@@ -10,7 +10,7 @@ Distillation:
node:
- batch_norm_47.tmp_2
Quantization:
QuantAware:
onnx_format: True
quantize_op_types:
- conv2d
......
......@@ -10,7 +10,7 @@ Distillation:
node:
- conv2d_95.tmp_0
Quantization:
QuantAware:
onnx_format: True
quantize_op_types:
- conv2d
......
......@@ -10,7 +10,7 @@ Distillation:
node:
- conv2d_37.tmp_1
Quantization:
QuantAware:
onnx_format: True
quantize_op_types:
- conv2d
......
......@@ -38,7 +38,7 @@ Distillation:
- batch_norm_26.tmp_3
- conv2d_42.tmp_1
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
is_full_quantize: false
......
......@@ -9,7 +9,7 @@ Global:
Distillation:
alpha: 1.0
loss: soft_label
Quantization:
QuantAware:
use_pact: true
activation_bits: 8
activation_quantize_type: moving_average_abs_max
......
......@@ -15,7 +15,7 @@ PTQ: # Post Training Quantization
batch_size: 32
batch_nums: 10
Quantization: # Auto Compression
QuantAware: # Auto Compression
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
weight_bits: 8
......
......@@ -15,7 +15,7 @@ PTQ: # Post Training Quantization
batch_size: 32
batch_nums: 10
Quantization: # Auto Compression
QuantAware: # Auto Compression
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
weight_bits: 8
......
......@@ -20,7 +20,7 @@ Distillation:
alpha: 1.0
loss: soft_label
Quantization: # Auto Compression
QuantAware: # Auto Compression
onnx_format: true
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
......
......@@ -16,7 +16,7 @@ PTQ: # Post Training Quantization
batch_size: 10
batch_nums: 10
Quantization: # Auto Compression
QuantAware: # Auto Compression
onnx_format: true
use_pact: true
activation_quantize_type: 'moving_average_abs_max'
......
......@@ -20,7 +20,8 @@ from .utils import *
__all__ = [
"AutoCompression",
"Quantization",
"QuantAware",
"QuantPost",
"Distillation",
"MultiTeacherDistillation",
"HyperParameterOptimization",
......
......@@ -125,17 +125,17 @@ def create_strategy_config(strategy_str, model_type):
### only platform is linux can use smac to do hyperparameter optimization
### choose quant_aware to do quantization in other platform
if platform.system().lower() == 'linux':
quant_config = Quantization(**default_quant_config)
quant_config = QuantAware(**default_quant_config)
hpo_config = HyperParameterOptimization(**hpo_config_tester)
configs.append({
'QuantPost': quant_config,
'HyperParameterOptimization': hpo_config
})
else:
quant_config = Quantization(**default_quant_config)
quant_config = QuantAware(**default_quant_config)
dis_config = Distillation()
configs.append({
'Quantization': quant_config,
'QuantAware': quant_config,
'Distillation': dis_config
})
......@@ -248,7 +248,7 @@ def get_final_quant_config(ptq_loss, model_type=None):
return None
### if emd loss less than MAGIC_MAX_EMD_DISTANCE, select quant_post & hpo.
elif ptq_loss < MAGIC_MAX_EMD_DISTANCE:
quant_config = Quantization(**default_quant_config)
quant_config = QuantAware(**default_quant_config)
hpo_config = HyperParameterOptimization(**default_hpo_config)
configs = [{
'QuantPost': quant_config,
......@@ -257,9 +257,9 @@ def get_final_quant_config(ptq_loss, model_type=None):
### if emd loss greater than MAGIC_MAX_EMD_DISTANCE, select qat & dist.
else:
quant_config = Quantization(**default_quant_config)
quant_config = QuantAware(**default_quant_config)
dis_config = Distillation()
configs = [{'Quantization': quant_config, 'Distillation': dis_config}]
configs = [{'QuantAware': quant_config, 'Distillation': dis_config}]
_logger.info("Start Quantization and Distillation Training.")
return configs
......
......@@ -88,7 +88,7 @@ class AutoCompression:
Only one strategy(quant_post with hyperparameter optimization) can set train_config
to None. Default: None.
strategy_config(dict, list(dict), optional): The strategy config. You can set single config to get multi-strategy config, such as
1. set ``Quantization`` and ``Distillation`` to get quant_aware and distillation compress config.
1. set ``QuantAware`` and ``Distillation`` to get quant_aware and distillation compress config.
The Quantization config can reference `https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/auto_compression/strategy_config.py#L55`_ .
The Distillation config can reference `https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/auto_compression/strategy_config.py#L107`_ .
2. set ``QuantPost`` and ``HyperParameterOptimization`` to get quant_post and hyperparameter optimization compress config.
......@@ -350,7 +350,7 @@ class AutoCompression:
strategy = []
config = []
for strategy_c in strategy_config:
quant_config = strategy_c.get("Quantization", None)
quant_config = strategy_c.get("QuantAware", None)
hpo_config = strategy_c.get("HyperParameterOptimization", None)
ptq_config = strategy_c.get("QuantPost", None)
prune_config = strategy_c.get("ChannelPrune", None)
......
......@@ -16,7 +16,7 @@ from collections import namedtuple
__all__ = [
"BaseStrategy",
"Quantization",
"QuantAware",
"Distillation",
"MultiTeacherDistillation",
"HyperParameterOptimization",
......@@ -33,7 +33,7 @@ __all__ = [
]
SUPPORTED_CONFIG = [
"Quantization",
"QuantAware",
"Distillation",
"MultiTeacherDistillation",
"HyperParameterOptimization",
......@@ -52,7 +52,7 @@ class BaseStrategy:
self.name = name
class Quantization(BaseStrategy):
class QuantAware(BaseStrategy):
def __init__(self,
quantize_op_types=[
'conv2d', 'depthwise_conv2d', 'conv2d_transpose', 'mul',
......@@ -87,7 +87,7 @@ class Quantization(BaseStrategy):
onnx_format(bool): Whether to export the quantized model with format of ONNX. Default is False.
is_full_quantize(bool): If True, 'quantoze_op_types' will be TRANSFORM_PASS_OP_TYPES + QUANT_DEQUANT_PASS_OP_TYPES. Default: False.
"""
super(Quantization, self).__init__("Quantization")
super(QuantAware, self).__init__("QuantAware")
self.quantize_op_types = quantize_op_types
self.weight_bits = weight_bits
self.activation_bits = activation_bits
......
# For unittests
Quantization:
QuantAware:
quantize_op_types:
- conv2d
- depthwise_conv2d
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册