vitis_quantize.VitisQuantizer.get_qat_model - 2.0 English

Vitis AI User Guide (UG1414)

Document ID
UG1414
Release Date
2022-01-20
Version
2.0 English

This function gets the float model for QAT.


vitis_quantize.VitisQuantizer.get_qat_model(
    init_quant=False,
    calib_dataset=None,
    calib_batch_size=None,
    calib_steps=None,
    train_with_bn=False,
    freeze_bn_delay=-1,
    replace_sigmoid=True,
    replace_relu6=True,
    include_cle=True,
    cle_steps=10,
    forced_cle=False)

Arguments

init_quant
A bool object to notify whether or not to run initial quantization before QAT. Running an initial PTQ quantization yields an improved initial state for the quantizer parameters, especially for 8bit_tqt strategy. Otherwise, the training may not converge.
calib_dataset
A tf.data.Dataset, keras.utils.Sequence or np.numpy object, the representative dataset for calibration. Must be set when "init_quant" is set True. You can use full or part of eval_dataset, train_dataset or other datasets as calib_dataset.
calib_steps
An int object, the total number of steps for initial PTQ. Ignored with the default value of None. If "calib_dataset" is a tf.data dataset, generator or keras.utils.Sequence instance and steps is None, calibration will run until the dataset is exhausted. This argument is not supported with array inputs.
calib_batch_size
An int object, the number of samples per batch for initial PTQ. If the "calib_dataset" is in the form of a dataset, generator or keras.utils.Sequence instances, the batch size is controlled by the dataset itself. If the "calib_dataset" is in the form of a numpy.array object, the default batch size is 32.
train_with_bn
A bool object, whether to keep bn layers during QAT. If set to True, bn parameters are updated during quantize-aware training and help the model to converge. These trained bn layers are then fused into previous convolution-like layers in the get_deploy_model() function. If the float model has no bn layers, this option has have no affect. The default value is False.
freeze_bn_delay
An int object, the train steps before freezing the bn parameters. After the delayed steps, model will switch inference bn parameters to avoid instability in training. Only take effect when train_with_bn is True. Default value is -1, which means never do bn freezing.
replace_sigmoid
A bool object, whether to replace the Activation(activation='sigmoid') layers into hard sigmoid layers and do quantization. If not, the sigmoid layers will be left unquantized and will be scheduled on CPU.
replace_relu6
A bool object, whether to replace the Relu6 layers with Relu layers.
include_cle
A bool object, whether to do Cross Layer Equalization before quantization.
cle_steps
An int object, the iteration steps to do Cross Layer Equalization.
forced_cle
A bool object, whether to do forced Cross Layer Equalization for relu6 layers.