The hb_verifier is a consistency verification tool that supports performing cosine similarity comparisons between ONNX models, between ONNX model and HBIR model, between HBIR model and HBIR model, and output consistency comparisons between HBIR model and HBM model.
The cosine similarity indicates the consistency between quantized models at different stages. As the cosine similarity gets closer to 1, it indicates that the outputs of the two quantized models being compared are closer to each other.
Consistency comparison prints output consistency information for the comparison models, including output name, consistency, number of inconsistent elements, maximum absolute error, and maximum relative error.

Fbc represents the floating-point HBIR model, which refers to the HBIR model before convert exported after the model conversion by PTQ API method or QAT pipeline.
Qbc represents the fixed-point HBIR model.
| Comparison Models | Comparison Scenarios | Whether the Model is from hb_compile | Input Data Requirement |
| Onnx vs Onnx | Cosine similarity comparison | Not interested | One original data |
| Onnx vs Fbc | Cosine similarity comparison | No | Two sets of data corresponding to the Onnx and Fbc models |
| Onnx vs Qbc | Cosine similarity comparison | Yes | One original data |
| Onnx vs Qbc | Cosine similarity comparison | No | One original data One runtime data |
| Fbc vs Qbc | Cosine similarity comparison | No | One original data One runtime data |
| Qbc vs Hbm | Output consistency comparison | Yes | One runtime data |
| Qbc vs Hbm | Output consistency comparison | No | One runtime data |
| Hbm vs Hbm | Output consistency comparison | Not interested | One runtime data |
For Fbc (floating-point HBIR model), if some preprocessing nodes have been inserted, the raw data needs to be modified to match the model inputs.
Currently, the hb_verifier tool does not support the cosine similarity comparison for the ptq_model.onnx model generated during the model quantization and compilation process when separate_batch or separate_name has been specified.
All models involved in the comparison must be the outputs of conversion and compilation from the same pipeline(PTQ/QAT).
| Parameter Name | Parameter Description |
-h, --help | Display help information and exit. |
--version | Display version information and exit. |
-m, --model | Specify the model input, supports ONNX model (*.onnx), HBIR model (*.bc) file, HBM model (*.hbm) file. |
-i, --input | Specify the data to be used for inference testing; only *.npy files are supported. For multi-input models, there are two ways to pass input data, separated by commas:
-i parameters.Attention:
|
-c, --compare_digits | Set the numerical precision of the comparison inference result (i.e. the number of decimal places to compare the value), if not specified, the tool will compare to five decimal places by default. |
--ip | Set the IP address of the development board, default is empty. Multiple entries need to be separated by commas. |
-u, --usename | Set the board SSH user name, defaults to root. Multiple entries need to be separated by commas. |
-p, --password | Set the board SSH password, default is empty. Multiple entries need to be separated by commas. |
--port | Set the board SSH port, default is 22. Multiple inputs need to be separated by commas. |
Cosine similarity comparisons were performed between the ONNX model and the ONNX model.
Take the model optimization stage model optimized_float_model.onnx and the model calibration stage model calibrated_model.onnx as an example:
Cosine similarity comparisons were performed between the ONNX model and the floating-point HBIR model.
Take the model optimization stage model optimized_float_model.onnx and the floating-point HBIR model float_model.bc as an example:
Cosine similarity comparisons were performed between the ONNX model and the fixed-point model HBIR model.
If the model is compiled by hb_compile, take the model optimization stage model optimized_float_model.onnx and the model quantization stage fixed-point model quantized_model.bc as an example:
If the model is compiled by hb_compile and there are multiple input data, take the model optimization stage model optimized_float_model.onnx and the model quantization stage fixed-point model quantized_model.bc as an example:
If the model is not compiled by hb_compile, take the original floating-model original_float_model.onnx and the fixed-point model quantized_model.bc as an example:
If the model is not compiled by hb_compile and there are multiple input data, take the original floating-model original_float_model.onnx and the fixed-point model quantized_model.bc as an example:
Cosine similarity comparisons were performed between the HBIR model and the HBIR model.
If the model is not compiled by hb_compile, take the floating-point model float_model.bc and the fixed-point model quantized_model.bc as an example:
If the model is not compiled by hb_compile and there are multiple input data, take the floating-point model float_model.bc and the fixed-point model quantized_model.bc as an example:
Output consistency comparisons were performed between the HBIR model and the HBM model.
Take the model quantization stage fixed-point model quantized_model.bc and the model compilation stage model googlenet.hbm as an example:
Take the model quantization stage fixed-point model quantized_model.bc and the model compilation stage model googlenet.hbm as an example,
and setting the ip to None indicates using the simulator:
Output consistency comparisons of HBM model across simulator and development board.
Take the model compilation stage model googlenet.hbm as an example. Setting the ip to None indicates using the simulator:
The cosine similarity information for the compared models will be printed within the terminal, as shown in the example below:
Among them:
Among them:
OutputName represents the output name.
Consistency represents whether the output is consistent or not.
Mismatched Elements represents the number and percentage of inconsistent elements.
Max Abs Diff represents the maximum absolute error.
Max Rel Diff represents the maximum relative error.