#
# Copyright (c) 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
-
  version:
    name: 'default'
    # (MXNet-specific): 
    # 'int8' for this version specifies quantization in general (both int8 and uint8), as 
    # quantization dtype is selected automatically for each quantized node according to the
    # calibration results: min_value < 0 => int8; min_value >= 0 => uint8.
    # 'int8' here means 'auto' in MXNet

  precisions: &common_precisions
    names: int8, fp32
    valid_mixed_precisions: []

  ops: &common_ops
    fp32: &fp32_ops [
            '_sg_mkldnn_conv', 'Convolution', 
            '_sg_mkldnn_fully_connected', 'FullyConnected', 
            '_sg_mkldnn_selfatt_qk', '_sg_mkldnn_selfatt_valatt',
            'Flatten', 'Pooling']
    int8:  ['quantize_output', *fp32_ops]

  capabilities: &common_capabilities
    int8: {
        'quantize_output': {
            'activation': {
                'dtype': ['int8'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
        }, 
        '_sg_mkldnn_conv': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
            'weight': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_channel'],
                'algorithm': ['minmax']}
        },
        'Convolution': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
            'weight': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_channel'],
                'algorithm': ['minmax']}
        },
        '_sg_mkldnn_fully_connected': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
            'weight': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax']}
        },
        'FullyConnected': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
            'weight': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax']}
        },
        '_sg_mkldnn_selfatt_qk': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
        },
        '_sg_mkldnn_selfatt_valatt': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']}
        },
        'Flatten': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']}
        },
        'Pooling': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']}
        },
        'default': {
            'activation': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax', 'kl']},
            'weight': {
                'dtype': ['int8', 'fp32'],
                'scheme': ['sym'],
                'granularity': ['per_tensor'],
                'algorithm': ['minmax']}
        }
      }

  patterns: &common_patterns
  # (MXNet-specific):
  # fusion patterns are hardcoded in the framework 
    fp32: [
        # conv + bn
        # conv + act + sum
        # conv + add
        # conv + bn + act
        # conv + bn + add + act
        # conv + bn + sum + act
        # fc + relu
    ]
    int8: []

-
  version:
    name: '1.6.0'

  precisions:
    <<: *common_precisions

  ops:
    <<: *common_ops

  capabilities:
    << : *common_capabilities

  patterns:
    << : *common_patterns

-
  version:
    name: '1.7.0'

  precisions:
    <<: *common_precisions

  ops:
    <<: *common_ops

  capabilities:
    << : *common_capabilities

  patterns:
    << : *common_patterns

-
  version:
    name: '1.8.0'

  precisions:
    <<: *common_precisions

  ops:
    <<: *common_ops

  capabilities:
    << : *common_capabilities

  patterns:
    << : *common_patterns

-
  version:
    name: '1.9.0'

  precisions:
    <<: *common_precisions

  ops:
    <<: *common_ops

  capabilities:
    << : *common_capabilities

  patterns:
    << : *common_patterns
