Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QuantConv2D binarized activations with tf.int32 bitpacked output (#611)
* added function strip_lcedequantize_ops: - strips the output LceDequantize operators of a model such that the output is a bitpacked tf.int32 tensor - usually the lce_converter dequantizes the bitpacked output back to tf.float32 resulting in an identity tensor - use cases: larq.layers.QuantConv2D followed by a sign operation (ie. larq.math.sign or larq.quantizers.SteSign()) - import using `from larq_compute_engine.mlir.python.util import strip_lcedequantize_ops` * reformatted using black code style * added pytest module for verifying lce_dequantize_ops * fixed larq import errors and renamed unit test function * fix PyFlakes error due to typo when defining toy_model * using Interpreter from larq_compute_engine.tflite.python.interpreter instead of tf.lite * reformatted strip_lcedequantize_test.py using black code style * added function strip_lcedequantize_ops: - strips the output LceDequantize operators of a model such that the output is a bitpacked tf.int32 tensor - usually the lce_converter dequantizes the bitpacked output back to tf.float32 resulting in an identity tensor - use cases: larq.layers.QuantConv2D followed by a sign operation (ie. larq.math.sign or larq.quantizers.SteSign()) - import using `from larq_compute_engine.mlir.python.util import strip_lcedequantize_ops` * reformatted using black code style * added pytest module for verifying lce_dequantize_ops * fixed larq import errors and renamed unit test function * fix PyFlakes error due to typo when defining toy_model * using Interpreter from larq_compute_engine.tflite.python.interpreter instead of tf.lite * reformatted strip_lcedequantize_test.py using black code style * Remove dependency of compute engine interpreter * Add bazel target for dequantize test * Update strip_lcedequantize_test.py fixed test_strip_lcedequantize_ops function test as only models with tf.float32 output will result in tf.int32 tensor outputs when used with strip_lcedequantize_ops * Update strip_lcedequantize_test.py refactored if-else statement * Update strip_lcedequantize_test.py deactivate setting default int8 ranges for `tf.float32` models as the strip_lcedequantize_ops function will not remove `LceDequantize` ops * fix: accidentally added merge indicators * Update strip_lcedequantize_test.py Testing strip_lcedequantize_ops for tf.float32 output: - fix double allocation of Interpreter, using tf.lite.Interpreter instead - fix typo when converting model to TFLite model * Update strip_lcedequantize_test.py removed import of Larq interpreter due to Lint tests failing * Adapt unit test for output type checking - only validate output after LceDequantize ops have been stripped, input type tests already validated in end2end_test.py * Update strip_lcedequantize_test.py fix: setting inference_input_type statically to tf.float32 as we're only validating the output * set tf.float32 as parametrized input type * Updated strip_lcedequantize_ops() to support more models: - updated signature defs for TF2.5 compatibility - support int8-quantized models when stripping LceDequantize op for int8 output - support int8-quantized models when using dequantized tf.float32 output, strips Dequantize operator first then LceDequantize * Unit tests for tf.int8 input/output models * Correction in toy_model_int8_sign - fake quantize before QuantConv2D * Extended Unit tests for test_strip_lcedequantize_ops() to parametrize experimental_enable_bitpacked_activations * Clean up using black code style Co-authored-by: Lukas Geiger <[email protected]>
- Loading branch information