feat(flatbuffer_direct): add QLinear ops and quant-chain fusion#873
Merged
feat(flatbuffer_direct): add QLinear ops and quant-chain fusion#873
Conversation
Owner
Author
|
Supplement for additional commit Additional implementation (more INT8-oriented)
Tests
Real model verification (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends
flatbuffer_directfor quantized ONNX graphs and documents the updated support matrix.face_recognition_sface_2021dec_int8.onnx.zip
What was added
Added direct lowering for quantized operators in
flatbuffer_direct:QuantizeLinear->QUANTIZEDequantizeLinear->DEQUANTIZEQLinearAdd->ADDQLinearMul->MULQLinearConv->CONV_2D/DEPTHWISE_CONV_2DQLinearMatMul->FULLY_CONNECTEDAdded
flatbuffer_direct-only preprocess fusion:DequantizeLinear -> BatchNormalization -> PRelu -> QuantizeLinearMul + Addform before lowering.Added supporting direct builders and registry coverage:
BatchNormalizationdirect builder (MUL + ADDform)Flattendirect builder (RESHAPEform)Updated README support status section for
flatbuffer_direct.Implementation details
Quantized builder layer
onnx2tf/tflite_builder/op_builders/quantized.pyscale,zero_point,quantized_dimension) for both:QLinear*)DequantizeLinear/QuantizeLinear)input_scale * weight_scale)Dispatch/validation layer
onnx2tf/tflite_builder/op_registry.pywith newDispatchEntrys and validators:_validate_quantize_dequantize_linear_validate_qlinear_binary_validate_qlinear_conv_validate_qlinear_matmul_validate_batch_norm_validate_flattenPreprocess rules
onnx2tf/tflite_builder/preprocess/rules/quant_chain_fusion.pyonnx2tf/tflite_builder/preprocess/rules/__init__.pyonnx2tf/tflite_builder/preprocess/__init__.pyquant_chain_fusion_wave3Tests
Added/updated tests
tests/test_tflite_builder_direct.pytests/test_tflite_builder_preprocess.pytest_quant_chain_fusion_wave3_rewrites_dq_bn_prelu_q_chainTest results
pytest -q tests/test_tflite_builder_preprocess.py tests/test_tflite_builder_direct.py72 passedReal model verification
Validated with:
face_recognition_sface_2021dec_int8.onnxpython -m onnx2tf -i face_recognition_sface_2021dec_int8.onnx -o /tmp/onnx2tf_sface_pr_check -tb flatbuffer_direct --report_op_coverage -nCoverage report highlights:
conversion_error = nullgraph_summary.supported_nodes = 278 / 278graph_summary.unsupported_nodes = 0graph_summary.coverage_ratio = 1quant_chain_fusion_wave3applied (matched_patterns=26,rewritten_patterns=26)Additional updates
pyproject.toml:2.0.11onnx2tf/__init__.py:2.0.112.0.11.