histogram — Model Optimizer 0.27.1 (original) (raw)

TensorRT Model Optimizer

Histogram based calibrators.

Classes

HistogramCalibrator Unified histogram calibrator.

Functions

calibrate_weights Calibrate weights of all child quantized modules.

class HistogramCalibrator

Bases: _Calibrator

Unified histogram calibrator.

Histogram will be only collected once. compute_amax() performs entropy, percentile, or mse

calibration based on arguments

Parameters:

__init__(num_bits=8, axis=None, unsigned=False, num_bins=2048, grow_method=None, skip_zeros=False, torch_hist=True)

Initialize.

collect(x)

Collect histogram.

compute_amax(method, *, stride=1, start_bin=128, percentile=99.99)

Compute the amax from the collected histogram.

Parameters:

Keyword Arguments:

Returns:

a tensor

Return type:

amax

reset()

Reset the collected histogram.

calibrate_weights(model, method='percentile', perchannel=True, percentile=99.99, num_bins=2048)

Calibrate weights of all child quantized modules.

Ideally, we would split calibration functionality to histogram collector and calibrator which takes histogram and compute amax. But since we haven’t decoupled collector and calibrator, it is easier to create a separate function to calibrate weight.

Note

This function uses method specified by the argument to decide which method to use, NOT the one specified by the calibrator embedded in weight_quantizer. We haven’t moved calibration to GPU, so everything is transfered to CPU

Parameters: