Skip to content

[python] Include 'per_channel' attribute when calibrating #19223

@Johansmm

Description

@Johansmm

Describe the issue

Currently, calibration algorithms compute scalar ranges, i.e. a single value for each calibration tensor. Unfortunately, there is no option for per_channel = True when calibrating.

It would be interesting to have a 'per_channel' option in the initialization parameters of any 'Calibrater' class to produce a set of calibration vectors instead of a single scalar.

Motivation

Some models could improve their performance if the quantization parameters (zero_point/scale) are vectors instead of scalars.

What is expected ?

Include for CalibraterBase class the attribute per_channel = False:

class CalibraterBase:
    def __init__(
        self,
        model,
        op_types_to_calibrate: Optional[Sequence[str]] = None,
        augmented_model_path="augmented_model.onnx",
        symmetric=False,
        use_external_data_format=False,
        per_channel=False,
    ):
        """
        :param model: ONNX model to calibrate. It can be a ModelProto or a model path
        :param op_types_to_calibrate: operator types to calibrate. By default, calibrate all the float32/float16 tensors.
        :param augmented_model_path: save augmented model to this path.
        :param symmetric: make range of tensor symmetric (central point is 0).
        :param use_external_data_format: use external data format to store model which size is >= 2Gb.
        :param per_channel: whether to compute range as vector.
        """
    ...

And update calibration algorithms in order to reproduce the new feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    quantizationissues related to quantizationstaleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions