[POT] Skip per channel quantizers allining before concats (#12483)

* Skip per channel quantizers allining before concats

* Test coverage
This commit is contained in:
Daniil Lyakhov authored and GitHub committed 2022-08-29 13:55:37 +04:00
1 parent ee86968bbb
commit d0d88fa1ec
8 files changed
+94 -6

No files matched your search

@@ -290,6 +290,15 @@ def find_fqs_to_unify(model, config):
unified_scales_ops_.append(hw_op)
return unified_scales_ops_
def _get_quantizable_per_ch_ops(hw_cfg_):
_quantizable_per_ch_ops = []
for hw_layer_cfg in hw_cfg_:
if 'quantization' in hw_layer_cfg and \
all(config['granularity'] == 'perchannel'
for config in hw_layer_cfg['quantization']['activations']):
_quantizable_per_ch_ops.append(hw_layer_cfg['type'])
return _quantizable_per_ch_ops
def _is_special_unify_conditions(node):
check_map = {
'Concat': _is_concat_unify_condition
@@ -310,6 +319,18 @@ def find_fqs_to_unify(model, config):
return True
return False
def _is_followed_by_quantizable_per_channel(input_node):
if _is_quantize_agnostic_op(input_node):
concat_stack.extend(get_all_node_outputs(input_node))
else:
hw_op_type = get_hardware_config_operation_type(input_node, [hw_op['type'] for hw_op in hw_ops])
if hw_op_type in per_channel_quantizable:
concat_stack.clear()
logger.debug('Found per channel quantizible op %s %s as Concat %s output',
input_node.type, input_node.fullname, node.fullname)
return True
return False
res = False
concat_inputs = get_node_inputs(node)
for concat_input in concat_inputs:
@@ -317,10 +338,17 @@ def find_fqs_to_unify(model, config):
logger.debug('Concat %s without FQ or Concat as input will not unified',
node.fullname)
return res
concat_stack = [node]
while concat_stack:
node_to_check = concat_stack.pop()
res = _is_followed_by_conv(node_to_check)
if res:
concat_stack = [node]
while concat_stack:
node_to_check = concat_stack.pop()
res = not _is_followed_by_quantizable_per_channel(node_to_check)
return res
def _is_agnostic_branching_op(node_):
@@ -360,6 +388,7 @@ def find_fqs_to_unify(model, config):
stack_.append(parent)
hardware_config = load_hardware_config(config)
per_channel_quantizable = _get_quantizable_per_ch_ops(hardware_config)
hw_ops = get_operation_list(hardware_config)
quantize_agnostic_ops = [op[1] for op in find_operation_matches(QUANTIZE_AGNOSTIC_OPERATIONS, hw_ops)]
unified_scales_ops = _get_unified_scales_ops(hw_ops)
@@ -0,0 +1,47 @@
{
"launchers": [
{
"framework": "openvino",
"adapter": "classification"
}
],
"datasets": [
{
"name": "imagenet_1001_classes",
"annotation_conversion": {
"converter": "imagenet",
"annotation_file": "val.txt",
"has_background": true
},
"annotation": "imagenet1001.pickle",
"data_source": "ILSVRC2012_img_val",
"metrics": [
{
"name": "accuracy@top1",
"type": "accuracy",
"top_k": 1,
"reference": 0.7185
},
{
"name": "accuracy@top5",
"type": "accuracy",
"top_k": 5,
"reference": 0.9069
}
],
"preprocessing": [
{
"type": "crop",
"central_fraction": 0.875
},
{
"type": "resize",
"size": 224
}
],
"_command_line_mapping": {
"annotation_file": null
}
}
]
}
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e771874a16658b9899576e3c877b54a2277272c176edcd0c897906a658981c03
size 168
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b6d6eed00903c057a4770b28645b549201f143c8eab91e756e5d19121f3a7d5a
size 1119
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e5c5f76b57e5972208a4ee862208daa1b56938f77996774c9d8d76c6134bbfea
size 30782
+2 -1
View File
@@ -17,7 +17,8 @@ from .utils.config import merge_configs
TEST_MODELS = [
('resnet_example', 'pytorch', 'DefaultQuantization', 'CPU'),
('resnet_example', 'pytorch', 'RangeSupervision', 'ANY'),
('act_act_example', 'pytorch', 'DefaultQuantization', 'GNA')
('act_act_example', 'pytorch', 'DefaultQuantization', 'GNA'),
('concat_depthwise_model', 'pytorch', 'MinMaxQuantization', 'CPU'),
]
+6 -5
View File
@@ -17,9 +17,10 @@ from .utils.config import get_engine_config, merge_configs
from .utils.path import TEST_ROOT
TEST_MODELS = [
('mobilenet-v2-pytorch', 'pytorch', 'MinMaxQuantization', 'performance'),
('resnet-50-tf', 'tf', 'DefaultQuantization', 'performance'),
('octave-resnet-26-0.25', 'mxnet', 'DefaultQuantization', 'accuracy'),
('mobilenet-v2-pytorch', 'pytorch', 'MinMaxQuantization', 'performance', 'VPU'),
('resnet-50-tf', 'tf', 'DefaultQuantization', 'performance', 'VPU'),
('octave-resnet-26-0.25', 'mxnet', 'DefaultQuantization', 'accuracy', 'VPU'),
('concat_depthwise_model', 'pytorch', 'MinMaxQuantization', 'accuracy', 'CPU'),
]
REFERENCES_PATH = TEST_ROOT / 'data/reference_unify'
@@ -32,13 +33,13 @@ def _params(request):
def test_unify_scales(_params, tmp_path, models):
model_name, model_framework, algorithm, preset = _params
model_name, model_framework, algorithm, preset, device = _params
algorithm_config = Dict({
'algorithms': [{
'name': algorithm,
'params': {
'target_device': 'VPU',
'target_device': device,
'preset': preset,
'stat_subset_size': 2
}