Conv2dQAT

Applicability

Product

Supported

Atlas A3 training series products/Atlas A3 inference series products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference product

Atlas inference series products

Atlas training products

Description

Constructs the QAT operator of Conv2d.

Prototype

  • API for construction from scratch:
    1
    qat = amct_pytorch.nn.module.quantization.conv2d.Conv2dQAT(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias, padding_mode, device, dtype, config)
    
  • API for construction based on the native operator:
    1
    qat = amct_pytorch.nn.module.quantization.conv2d.Conv2dQAT.from_float(mod, config)
    

Parameters

Table 1 Parameters in the API for operator construction from scratch

Parameter

Input/Output

Description

in_channels

Input

Number of input channels.

An int.

out_channels

Input

Number of output channels.

An int.

kernel_size

Input

Size of the convolution kernel.

An int or a tuple.

stride

Input

Convolution stride.

An int or a tuple.

Default: 1

padding

Input

Padding size.

An int or a tuple.

Default: 0

dilation

Input

Spacing between kernel elements.

An int or a tuple.

Default: 1

groups

Input

Connections between the inputs and outputs.

An int.

Default: 1

bias

Input

Whether to enable bias items to participate in learning.

A bool. Other data types (such as integers, strings, and lists) are converted based on the Python truth value judgment rules.

Default: True

padding_mode

Input

Padding mode.

Restrictions: Must be zeros.

device

Input

Running device.

Default: None

dtype

Input

Torch data type.

Torch data type. Only torch.float32 is supported.

config

Input

Quantization configuration. The following is a configuration example. For details about quantization configuration parameters, see Quantization Configuration Parameters.

config = {
    "retrain_enable":true,
    "retrain_data_config": {
        "dst_type": "INT8",
        "batch_num": 10,
        "fixed_min": False,
        "clip_min": -1.0,
        "clip_max": 1.0
    },
    "retrain_weight_config": {
        "dst_type": "INT8",
        "weights_retrain_algo": "arq_retrain",
        "channel_wise": False
    }
}

A dict.

Default: None

Table 2 Parameters in the API for construction based on the native operator

Parameter

Input/Output

Description

mod

Input

Native Conv2d operator to be quantized.

A torch.nn.Module.

config

Input

Quantization configuration. The following is a configuration example. For details about quantization configuration parameters, see Quantization Configuration Parameters.

config = {
    "retrain_enable":true,
    "retrain_data_config": {
        "dst_type": "INT8",
        "batch_num": 10,
        "fixed_min": False,
        "clip_min": -1.0,
        "clip_max": 1.0
    },
    "retrain_weight_config": {
        "dst_type": "INT8",
        "weights_retrain_algo": "arq_retrain",
        "channel_wise": False
    }
}

A dict.

Default: None

Returns

  • Construction from scratch: returns the constructed QAT single-operator instance.
  • Construction based on native operators: returns the QAT single-operator converted from torch.nn.Module.

Example

  • Construction from scratch:
    1
    2
    3
    4
    5
    from amct_pytorch.nn.module.quantization.conv2d import Conv2dQAT
    
    Conv2dQAT(in_channels=1, out_channels=1, kernel_size=1, stride=1,
              padding=0, dilation=1, groups=1, bias=True,
              padding_mode='zeros', device=None, dtype=None, config=None)
    
  • Construction based on the native operator:
    1
    2
    3
    4
    5
    6
    7
    8
    import torch
    
    from amct_pytorch.nn.module.quantization.conv2d import Conv2dQAT
    
    conv2d_op = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=1, stride=1,
                                padding=0, dilation=1, groups=1, bias=True,
                                padding_mode='zeros', device=None, dtype=None)
    Conv2dQAT.from_float(mod=conv2d_op, config=None)