#
# 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: '1.7'

  precisions: &default_precisions
    names: int8, uint8, fp32
    valid_mixed_precisions: []

  ops:
    # For PyTorch, quantizable op list is provided by torch/quantization/quantization_mappings.py
    int8: ['BatchNorm2d', 'BatchNorm3d', 'ReLU', 'ReLU6', 'QuantStub', 'FloatFunctional',
           'BNReLU2d', 'BNReLU3d']
    uint8: ['Conv1d', 'Conv2d', 'Conv3d', 'BatchNorm2d', 'BatchNorm3d', 'Linear', 'ReLU', 'ReLU6',
            'QuantStub', 'FloatFunctional', 'ConvReLU2d', 'ConvReLU3d', 'LinearReLU', 'BNReLU2d',
            'BNReLU3d', 'ConvBn2d', 'ConvBnReLU2d']
    fp32: ['*'] # '*' means all op types
  
  capabilities: &1_7_capabilities
    int8: &cap_s8_1_7 {
          'Conv1d': &cap_s8_1_7_Conv1d {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym', 'sym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['kl', 'minmax']
                        },
                    },
          'Linear': *cap_s8_1_7_Conv1d,
          'Conv2d': *cap_s8_1_7_Conv1d,
          'Conv3d': *cap_s8_1_7_Conv1d,
          'EmbeddingBag': &cap_static_s8_1_7_EmbeddingBag {
            'weight': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym_float'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['placeholder'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
                    },
          # Embedding, LayerNorm, InstanceNorm3d have accuracy issue now,
          # So fallback to fp32, will remove when PyTorch fixed this issue.
          'Embedding': &cap_static_s8_1_7_Embedding {
            'activation': {
                        'dtype': ['fp32'],
                        },
            'weight': {
                        'dtype': ['fp32'],
                        },
                    },
          'LayerNorm': *cap_static_s8_1_7_Embedding,
          'InstanceNorm3d': *cap_static_s8_1_7_Embedding,
          'QuantStub': &cap_static_s8_1_7_QuantStub {
            'activation': {
                        'dtype': ['uint8'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        }
                    },
          'ConvTranspose1d': &cap_static_s8_1_7_ConvTranspose1d {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym', 'sym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['kl', 'minmax']
                        },
                    },
          'ConvTranspose2d': *cap_static_s8_1_7_ConvTranspose1d,
          'default': &cap_static_s8_1_7_default {
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['kl']
                        },
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
                     },
          }
    uint8: *cap_s8_1_7
    dynamic: &cap_dynamic_s8_1_7 {
          'Linear': &cap_dynamic_s8_1_7_Linear {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
                    },
          'LSTM': &cap_dynamic_s8_1_7_LSTM {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': [ 'sym', 'asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
                    },
          'EmbeddingBag': &cap_dynamic_s8_1_7_EmbeddingBag {
            'weight': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym_float'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
                    },
          'GRU': *cap_dynamic_s8_1_7_LSTM,
          'LSTMCell': *cap_dynamic_s8_1_7_LSTM,
          'RNNCell': *cap_dynamic_s8_1_7_LSTM,
          'GRUCell': *cap_dynamic_s8_1_7_LSTM,
          'Embedding': *cap_dynamic_s8_1_7_EmbeddingBag,
          'default': {
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
                    },
          }

  patterns:
    fp32: [ #TODO Add more patterns here to demonstrate our concept the results external engine should return.
        'Conv1d + BN1d',
        'Conv2d + BN2d',
        'Conv3d + BN3d',
        ]
    int8: &ref_1_7_s8 [
        'Conv1d + BN1d',
        'Conv2d + BN2d',
        'Conv3d + BN3d',
        'Conv1d + BN1d + Relu',
        'Conv2d + BN2d + Relu',
        'Conv3d + BN3d + Relu',
        'Conv1d + Relu',
        'Conv2d + Relu',
        'Conv3d + Relu',
        'Linear + Relu',
        'BN2d + Relu',
        'BN3d + Relu',
        ]
    uint8: *ref_1_7_s8

-
  version:
    name: '1.6'

  precisions:
    << : *default_precisions

  ops:
    # For PyTorch, quantizable op list is provided by torch/quantization/quantization_mappings.py
    int8: ['BatchNorm2d', 'BatchNorm3d', 'ReLU', 'ReLU6', 'QuantStub', 'FloatFunctional',
           'BNReLU2d', 'BNReLU3d']
    uint8: ['Conv1d', 'Conv2d', 'Conv3d', 'BatchNorm2d', 'BatchNorm3d', 'Linear', 'ReLU', 'ReLU6',
            'QuantStub', 'FloatFunctional', 'ConvReLU2d', 'ConvReLU3d', 'LinearReLU', 'BNReLU2d',
            'BNReLU3d', 'ConvBn2d', 'ConvBnReLU2d']
    fp32: ['*'] # '*' means all op types
  
  capabilities: &1_6_capabilities
    int8: &cap_s8_1_6 {
          'Conv1d': &cap_s8_1_6_Conv1d {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym', 'sym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['kl', 'minmax']
                        },
                    },
          'Linear': *cap_s8_1_6_Conv1d,
          'Conv2d': *cap_s8_1_6_Conv1d,
          'Conv3d': *cap_s8_1_6_Conv1d,
          'QuantStub': {
            'activation': {
                        'dtype': ['uint8'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        }
                    },
          'default': {
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['kl']
                        }
                    },
          }
    uint8: *cap_s8_1_6
    dynamic: &cap_dynamic_s8_1_6 {
          'Linear': &cap_dynamic_s8_1_6_Linear {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_channel'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
                    },
          'LSTM': &cap_dynamic_s8_1_6_LSTM {
            'weight': {
                        'dtype': ['int8', 'fp32'],
                        'scheme': ['sym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['sym', 'asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        },
                    },
          'GRU': *cap_dynamic_s8_1_6_LSTM,
          'LSTMCell': *cap_dynamic_s8_1_6_LSTM,
          'RNNCell': *cap_dynamic_s8_1_6_LSTM,
          'GRUCell': *cap_dynamic_s8_1_6_LSTM,
          'default': {
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        }
                    },
          }

  patterns:
    fp32: [ #TODO Add more patterns here to demonstrate our concept the results external engine should return.
        'Conv1d + BN1d',
        'Conv2d + BN2d',
        'Conv3d + BN3d',
        ]
    int8: &ref_1_6_s8 [
        'Conv1d + BN1d',
        'Conv2d + BN2d',
        'Conv3d + BN3d',
        'Conv1d + BN1d + Relu',
        'Conv2d + BN2d + Relu',
        'Conv3d + BN3d + Relu',
        'Conv1d + Relu',
        'Conv2d + Relu',
        'Conv3d + Relu',
        'Linear + Relu',
        'BN2d + Relu',
        'BN3d + Relu',
        ]
    uint8: *ref_1_6_s8

-
  version:
    name: '1.3'

  precisions:
    << : *default_precisions

  ops:
    # For PyTorch, quantizable op list is provided by torch/quantization/quantization_mappings.py
    int8: ['ReLU', 'QuantStub', 'FloatFunctional']
    uint8: ['Conv2d', 'Linear', 'ReLU', 'QuantStub', 'FloatFunctional', 'ConvReLU2d',
            'LinearReLU', 'ConvBn2d', 'ConvBnReLU2d']
    fp32: ['*'] # '*' means all op types
  
  capabilities: &1_3_capabilities
    int8: *cap_s8_1_6
    uint8: *cap_s8_1_6
    dynamic: &cap_dynamic_s8_1_3 {
          'Linear': *cap_dynamic_s8_1_6_Linear,
          'LSTM': *cap_dynamic_s8_1_6_LSTM,
          'default': {
            'activation': {
                        'dtype': ['uint8', 'fp32'],
                        'scheme': ['asym'],
                        'granularity': ['per_tensor'],
                        'algorithm': ['minmax']
                        }
                    },
          }

  patterns:
    fp32: [ #TODO Add more patterns here to demonstrate our concept the results external engine should return.
        'Conv2d + BN2d',
        ]
    int8: &ref_1_3_s8 [
        'Conv2D + BN2d',
        'Conv2D + BN2d + Relu',
        'Conv2D + Relu',
        'Linear + Relu',
        ]
    uint8: *ref_1_3_s8

-
  version:
    name: 'default'

  precisions:
    << : *default_precisions

  ops:
    # For PyTorch, quantizable op list is provided by torch/quantization/quantization_mappings.py
    int8: ['ReLU', 'QuantStub']
    uint8: ['Conv2d', 'Linear', 'ReLU', 'QuantStub']
    fp32: ['*'] # '*' means all op types

  capabilities:
    << : *1_6_capabilities

  patterns:
    fp32: [ #TODO Add more patterns here to demonstrate our concept the results external engine should return.
        'Conv2d + BN2d',
        ]
    int8: &ref_1_2_s8 [
        'Conv2D + BN2d',
        'Conv2D + BN2d + Relu',
        ]
    uint8: *ref_1_2_s8
