S100 OpenExplorer

# #hmct.api.build_model

## #Interface Description

The model conversion function provided by HMCT, inputs an onnx model and outputs the quantized model after model conversion and quantization.

### #Interface Form

`def build_model( onnx_model: ModelProto, march: str, cali_data: Union[Sequence[np.ndarray], Dict[str, Sequence[np.ndarray]]], quant_config: Optional[Union[str, Dict[str, Any]]] = None, input_dict: Optional[Dict[str, Any]] = None, name_prefix: Optional[str] = None, verbose: Optional[bool] = True, ) -> ModelProto`

### #Return Value

Output a quantized onnx model that can be used for quantized model accuracy evaluation, as well as compiled into a deployment model via hbdk.

## #Parameter

Parameter | Type | Default Value | Description
onnx_model | ModelProto | Required, no default value | The input onnx model.
march | str | Required, no default value | Computing platform.
cali_data | Union[Sequence[np.ndarray], Dict[str, Sequence[np.ndarray]]] | Required, no default value | Calibration data: Single-input models can specify calibration data via Sequence[np.ndarray]. `cali_data = [sample0, sample1, ...]` Multi-input models require calibration data to be specified via Dict[str, Sequence[np.ndarray]]. `cali_data = {'input_name0': [sample0, sample1, ...], 'input_name1': [sample0, sample1, ...]}`
quant_config | Optional[Union[str, Dict[str, Any]]] | None | Specify quantized configuration parameters, detailed quantized parameter configuration description reference The quant_config Introduction。 Use the default quantization method. `quant_config = None` Quantization parameters can be configured via a json file. `quant_config = quant_config_json_file` Configure quantization parameters via a dict type. `quant_config = {'node_config' : {'Conv0', {'qtype', 'int16'}}}`
input_dict | Optional[Dict[str, Any]] | None | Modify the converted model inputs according to the specified parameters. Note: The caller needs to ensure that the modifications to the model inputs are legal. Modify the input_shape of the specified input: `input_dict = {'input_name0': {'input_shape':[x,x,x,x]}}` Modify the batch_size of the specified input: `input_dict = {'input_name0': {'input_batch': 4}}`
name_prefix | Optional[str] | None | Specify the save path for the generated object during the model conversion process. None, saved in the current directory. Specify a path relative to the current directory in which to save the generated objects during the conversion process. `# Saved in the current directory, saved files are prefixed with temp_; name_prefix = 'temp_' # Save in the . /tmp01 directory, saved files are prefixed with temp_; name_prefix = './tmp01/temp_'`
verbose | Optional[bool] | True | verbose=True/False, specify whether detailed information is printed during the model conversion.

## #Generator Description

Generator Name | Description
--- | ---
original_float_model.onnx | The output after the original model conversion, which is included in this phase of the conversion: opset, ir version conversion, input_shape modification operation.
optimized_float_model.onnx | The output of the model optimization phase, which is included in this phase of the conversion: constant folding, operator fusion, useless operator removal, operator replacement, and operator splitting.
calibrated_model.onnx | The output of the model calibration phase, which is included in this phase of the quantization: inserting calibration nodes, counting data distributions, and calculating quantization parameters.
ptq_model.onnx | The output of the model quantization phase, which is included in this phase of the quantization: tuning and converting the quantization parameters based on the specified march.

On This Page