Convert to Fixed-Point Model
After the pseudo-quantization accuracy meets the standard through the series of processes described above, the relevant processes for model deployment can be executed, mainly including operations such as exporting the HBIR model (export) and converting to a fixed-point model (convert).
Export HBIR Model
Model deployment requires exporting the pseudo-quantization model as a HBIR model firstly. A set of example_inputs needs to be provided. The tool executes the complete forward logic of the model using these inputs, and converts each operator encountered during execution into an HBIR node or subgraph one by one.
- The exported HBIR does not only contain quantized operators, but all operators executed in the model’s forward pass. Therefore, when exporting HBIR, please ensure that the model’s forward logic is consistent with the required deployment logic.
- HBIR does not support dynamic shapes. The shape of each part in the computation graph is determined by the shape of the tensors in the model at the time of export. If you need to use different batch sizes for simulation and on-board deployment, please export HBIR models separately using different
example_inputs. - You can also choose to skip the quantization accuracy tuning process. After the initial completion of calibration, first directly verify the model deployment process to ensure that there are no operations in the model that cannot be exported or compiled.
Accuracy Description
The exported hbir model is theoretically consistent with the torch model in terms of calculation logic, but there are the following differences that lead to numerical inconsistency:
-
Most nonlinear elementwise operators in the torch model are converted to a lookup table implementation in hbir.
-
Operators with accumulation calculations, such as reduce_sum and gemm, will cause numerical fluctuations due to different accumulation orders.
Convert to Fixed-point Model
After exporting the model to the HBIR model, the model can be converted to a fixed-point model. The results of the fixed-point model are generally considered to be identical to those of the compiled model.
- HBIR models support only a single
TensororTuple[Tensor]as input, and onlyTuple[Tensor]as output. - It is not possible to achieve complete numerical agreement between the fixed-point model and the pseudo-quantization model, so please take the accuracy of the fixed-point model as the standard. If the fixed-point accuracy is not up to standard, you need to continue the quantized awareness training.
Accuracy Description
After convert, the model changes from floating-point pseudo-quantization computation to int computation, which will lead to numerical fluctuations.
