PostTrainingQuantization

class paddle.fluid.contrib.slim.quantization.post_training_quantization. PostTrainingQuantization ( executor, model_dir, scope=None, model_filename=None, params_filename=None, batch_generator=None, sample_generator=None, data_loader=None, batch_size=10, batch_nums=None, algo='KL', hist_percent=0.99999, quantizable_op_type=['conv2d', 'depthwise_conv2d', 'mul'], round_type='round', learning_rate=0.001, is_full_quantize=False, bias_correction=False, activation_bits=8, weight_bits=8, activation_quantize_type='range_abs_max', weight_quantize_type='channel_wise_abs_max', onnx_format=False, freeze_model=True, optimize_model=False, is_use_cache_file=False, skip_tensor_list=None, same_scale_tensor_list=None, cache_dir=None, scale_dict=None, return_graph=False ) [source]

Utilizing post training quantization methon to quantize the FP32 model, and it uses calibrate data to get the quantization information for all quantized variables.

quantize ( )

quantize

Load the FP32 model, and use the calibrate data to calculate the forward-stage. Based on the sample data, we can get the quantization information, and obtain the final quantized model.

Parameters

None

Returns

the program of quantized model.

save_quantized_model ( save_model_path, model_filename=None, params_filename=None )

save_quantized_model

Save the quantized model to the disk.

Parameters
  • save_model_path (str) – The path to save the quantized model.

  • model_filename (str, optional) – If the model_filename is None, save the model to ‘__model__’. Otherwise, save the model to the specified filename. Default: None.

  • params_filename (str, optional) – If the params_filename is None, save params to separted files. Otherwise, save all params to the specified filename.

Returns

None