-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TFLite] Support quantised SQUARED_DIFFERENCE operator #11249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,7 @@ def compare_tflite_with_tvm( | |
| input_range=None, | ||
| mode="graph_executor", | ||
| experimental_new_converter=False, | ||
| experimental_new_quantizer=False, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate line. |
||
| fp16_quantized=False, | ||
| ): | ||
| """Generic function to generate and compare TFLite and TVM output""" | ||
|
|
@@ -286,6 +287,7 @@ def compare_tflite_with_tvm( | |
| # convert to tflite model | ||
| converter = tf.lite.TFLiteConverter.from_session(sess, input_tensors, output_tensors) | ||
| converter.experimental_new_converter = experimental_new_converter | ||
| converter.experimental_new_quantizer = experimental_new_quantizer | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate line. |
||
| if quantized: | ||
| converter.inference_type = tf.lite.constants.QUANTIZED_UINT8 | ||
| input_arrays = converter.get_input_arrays() | ||
|
|
@@ -2076,6 +2078,7 @@ def _test_elemwise( | |
| quantized=False, | ||
| qnn_op=None, | ||
| same_qnn_params=False, | ||
| experimental_new_quantizer=True, | ||
| ): | ||
| """One iteration of elemwise""" | ||
|
|
||
|
|
@@ -2135,6 +2138,7 @@ def __test_elemwise(in_data): | |
| quantized=True, | ||
| input_range=input_range, | ||
| experimental_new_converter=same_qnn_params, | ||
| experimental_new_quantizer=experimental_new_quantizer, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the previous line should be removed. |
||
| ) | ||
| else: | ||
| out = math_op( | ||
|
|
@@ -2312,9 +2316,17 @@ def _test_not_equal(data): | |
| # ------------------ | ||
|
|
||
|
|
||
| def _test_squared_difference(data): | ||
| def _test_squared_difference(data, fused_activation_function=None, quantized=False, qnn_op=None): | ||
| """One iteration of squared difference""" | ||
| return _test_elemwise(math_ops.squared_difference, data) | ||
| return _test_elemwise( | ||
| math_ops.squared_difference, | ||
| data, | ||
| fused_activation_function, | ||
| quantized, | ||
| qnn_op, | ||
| same_qnn_params=True, | ||
| experimental_new_quantizer=False, | ||
| ) | ||
|
|
||
|
|
||
| ####################################################################### | ||
|
|
@@ -2378,6 +2390,7 @@ def _test_elemwise_qnn_out_range(qnn_op): | |
| _test_mul: (-5e3, 5e3), | ||
| _test_maximum: (-112, 111), | ||
| _test_minimum: (-128, 127), | ||
| _test_squared_difference: (0, 225e2), | ||
| } | ||
|
|
||
| return qnn_out_range[qnn_op] | ||
|
|
@@ -2408,6 +2421,7 @@ def test_all_elemwise(): | |
| _test_forward_elemwise_quantized(_test_minimum) | ||
| _test_forward_elemwise(_test_greater) | ||
| _test_forward_elemwise(_test_squared_difference) | ||
| _test_forward_elemwise_quantized(_test_squared_difference) | ||
| _test_forward_elemwise(_test_greater_equal) | ||
| _test_forward_elemwise(_test_less) | ||
| _test_forward_elemwise(_test_less_equal) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be a check like the following?