neural_compressor.adaptor.ox_utils.calibrator

Calibrator for onnx models.

Classes

CalibratorBase

Base calibrator class.

MinMaxCalibrator

MinMax calibrator class.

PercentileCalibrator

Percentile calibrator class.

KLCalibrator

KL calibrator class.

HistogramCollector

Histogram collctor class.

Functions

calib_registry(calib_method)

The class decorator used to register all Calibrator subclasses.

smooth_distribution(p[, eps])

Smooth distribution.

Module Contents

neural_compressor.adaptor.ox_utils.calibrator.calib_registry(calib_method)[source]

The class decorator used to register all Calibrator subclasses.

class neural_compressor.adaptor.ox_utils.calibrator.CalibratorBase[source]

Base calibrator class.

class neural_compressor.adaptor.ox_utils.calibrator.MinMaxCalibrator[source]

MinMax calibrator class.

class neural_compressor.adaptor.ox_utils.calibrator.PercentileCalibrator(num_bins=2048, percentile=99.999)[source]

Percentile calibrator class.

Parameters:
  • num_bins (int, optional) – number of bins to create a new histogram for collecting tensor values. Defaults to 2048.

  • percentile (float, optional) – A float number between [0, 100]. Defaults to 99.999.

class neural_compressor.adaptor.ox_utils.calibrator.KLCalibrator(num_bins=128, num_quantized_bins=128)[source]

KL calibrator class.

Parameters:
  • num_bins (int, optional) – number of bins to create a new histogram for collecting tensor values. Defaults to 128.

  • num_quantized_bins (int, optional) – number of quantized bins. Defaults to 128.

class neural_compressor.adaptor.ox_utils.calibrator.HistogramCollector(num_bins=2048)[source]

Histogram collctor class.

neural_compressor.adaptor.ox_utils.calibrator.smooth_distribution(p, eps=0.0001)[source]

Smooth distribution.

Given a discrete distribution (may have not been normalized to 1), smooth it by replacing zeros with eps multiplied by a scaling factor and taking the corresponding amount off the non-zero values. Ref: http://hanj.cs.illinois.edu/cs412/bk3/KL-divergence.pdf https://github.com//apache/incubator-mxnet/blob/master/python/mxnet/contrib/quantization.py https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/python/tools/quantization/calibrate.py

Parameters:
  • p (array) – distribution array

  • eps (float, optional) – a small probability. Defaults to 0.0001.

Returns:

smoothed distribution

Return type:

array