Commit Graph

61 Commits

Author SHA1 Message Date
TensorFlower Gardener
3d868aa1c6 Merge pull request from wwwind:interface_16x8
PiperOrigin-RevId: 317232781
2020-06-18 19:47:52 -07:00
Jian Li
2e33100312 Add quantization test for transpose.
PiperOrigin-RevId: 317117545
Change-Id: I81c4f9583f29205bcbdaae175eac59439cd19047
2020-06-18 09:29:54 -07:00
Elena Zhelezina
b6c7284053
Merge branch 'master' into interface_16x8 2020-03-30 10:45:04 +01:00
A. Unique TensorFlower
a4c2fcf05b Add indirection layer for selecting cmath functions from global namespace.
There can be functions beyond round() that aren't present within the std::
namespace depending on libstdc++ version. This CL adds an indirection layer
using a new TF_MICRO_USE_GLOBAL_CMATH_FUNCTIONS flag to select these functions
and converts TfLiteRound() to use this layer.

Other similar indirections will be added in future CLs.

PiperOrigin-RevId: 303425632
Change-Id: Idfe14924329827f71742ab6aedfd6ead9bcb0dbb
2020-03-27 16:06:11 -07:00
Elena Zhelezina
fe806513ad
Merge branch 'master' into interface_16x8 2020-03-24 10:38:37 +00:00
Jian Li
b8054c93d0 Create a helper function to change a float models's interface to uint8. This is for users to use on inputs, rather than relying on infererence_input and inference_output type in the 2.0 converter.
PiperOrigin-RevId: 302452948
Change-Id: I4b5a71f48046c3392b09675ddef3e30d845ce4ca
2020-03-23 09:51:46 -07:00
Elena Zhelezina
5b9a467e3d
Merge branch 'master' into interface_16x8 2020-03-17 16:17:33 +00:00
Jian Li
adc1b86230 Add API to overwrite the float interface of quantized tflite model. Currently supports int8 and uint8.
Also Added standalone C++ main function.

PiperOrigin-RevId: 299841432
Change-Id: I0fc01bbc929e8ee232f0cf2356ac83294aeafada
2020-03-09 08:04:43 -07:00
Elena Zhelezina
792f553fd0 Added non-strict mode for 16x8 quantization 2020-02-20 15:44:29 +00:00
Pete Warden
d3b87da9de Fix for MacOS absl build problem
PiperOrigin-RevId: 291426489
Change-Id: I7e8b1868a28973ee4b0821332259a2012e0171cd
2020-01-24 13:09:28 -08:00
Pete Warden
adf6e22e4a Enable visualization script to work from pip install
Current the visualization script for TensorFlow Lite files only works if you build through Bazel. To make it more accessible, this change uses Flatbuffer's new Python interface to extract the information from the file, rather than calling out to an external tool. It also adds some tests.
A lot of the changes here are related to upgrading to the latest version of Flatbuffers, which has an impact on other parts of the code.

PiperOrigin-RevId: 291255530
Change-Id: I28a64a182e6197a58926d02c41988e4791c60fce
2020-01-23 15:20:03 -08:00
Smit Hinsu
0b2d7049ac Enable visualization script to work from pip install
Current the visualization script for TensorFlow Lite files only works if you build through Bazel. To make it more accessible, this change uses Flatbuffer's new Python interface to extract the information from the file, rather than calling out to an external tool. It also adds some tests.
A lot of the changes here are related to upgrading to the latest version of Flatbuffers, whi...

PiperOrigin-RevId: 290887928
Change-Id: I90403c1f4233f472ee5d7c4d21eed8233cb7d008
2020-01-21 21:54:42 -08:00
Pete Warden
1219c0ba8d Enable visualization script to work from pip install
Current the visualization script for TensorFlow Lite files only works if you build through Bazel. To make it more accessible, this change uses Flatbuffer's new Python interface to extract the information from the file, rather than calling out to an external tool. It also adds some tests.
A lot of the changes here are related to upgrading to the latest version of Flatbuffers, which has an impact on other parts of the code.

PiperOrigin-RevId: 290788860
Change-Id: I4db3442110c48e01da2b5696b693562c806735fd
2020-01-21 11:47:07 -08:00
TensorFlower Gardener
68cbb78a53 Merge pull request from wwwind:fix_pack
PiperOrigin-RevId: 287779568
2020-01-01 18:58:16 -08:00
Jian Li
c2670013c8 Add quantizer for SVDF.
- state is quantized to 16 bits.
- time weight is also quantized to 16bits but the target range is [-512, 512] instead of [-32767, 32767] because there is a "reduce" operation right after element-wise mul between state and time weight. The "reduce" can be as high as 30 so we reserve 6 bits (64) for the summation, leaving only 10 bits for time weight.

PiperOrigin-RevId: 286920154
Change-Id: I45104b69452a1033db230d1db6bd280fa289b733
2019-12-23 11:26:02 -08:00
Suharsh Sivakumar
42de76d1e0 Fix incorrect min/max models to be float instead of uint8.
PiperOrigin-RevId: 286225461
Change-Id: Iaabb7ed02e34bd36ed19cf774e79872255714356
2019-12-18 11:08:46 -08:00
Jeremy Lau
75effc1812 Temporarily disable a failing test under asan.
PiperOrigin-RevId: 286090321
Change-Id: I5a560ace9189881e77d03d817aec4e21cd6ff45d
2019-12-17 17:01:32 -08:00
Elena Zhelezina
1cc444cb0f
Merge branch 'master' into fix_pack 2019-12-17 10:33:24 +00:00
TensorFlower Gardener
ea12cc726d Merge pull request from wwwind:fix_minimum_maximum
PiperOrigin-RevId: 285789493
2019-12-16 10:12:03 -08:00
Suharsh Sivakumar
6c9422d7d6 Skip over optional bias tensors.
PiperOrigin-RevId: 285242904
Change-Id: Ie063daa9ff1707ba562eb28f4f053df128037f12
2019-12-12 12:16:00 -08:00
Elena Zhelezina
df97287959 Fix Ubuntu sanity check.
Change-Id: I1e15495f001d2fe56326c8b056a73756a5e5e04b
2019-12-11 11:16:53 +00:00
Elena Zhelezina
fe404e66b0 Fixed sanity check.
Change-Id: Ife08ec56980a71e778ea86cf34c5a9fc2153a3f0
2019-12-11 11:13:05 +00:00
Elena Zhelezina
47735cb347
Merge branch 'master' into fix_pack 2019-12-09 10:06:00 +00:00
Elena Zhelezina
ec5d3a0603
Merge branch 'master' into fix_minimum_maximum 2019-12-09 10:05:03 +00:00
Jian Li
8a2ad877e9 Add quantization support to all variants of LSTM.
- peephole coefficients are quantized to 16 bits symmetric. Int16 is used because the calculation is a 16x16 vector vector elementwise multiplication.
- without projection, hidden tensor becomes the output and reuses the quantization parameters of the output
- with layer normalization, the gate matmul uses intermediate result as output; without layer normalization, gate matmul is fed into activation directly so 2^(-12) is the output scale.

PiperOrigin-RevId: 284230412
Change-Id: Ibfa66dc6fc2614de28b0ba92e8fb2d42a338aab4
2019-12-06 11:53:15 -08:00
Elena Zhelezina
811c2a08ff
Merge branch 'master' into fix_minimum_maximum 2019-12-04 10:11:32 +00:00
Elena Zhelezina
27f132a155
Merge branch 'master' into fix_pack 2019-12-04 10:03:19 +00:00
TensorFlower Gardener
5638b86e4e Merge pull request from MohamedNourArm:int8UnpackSupport
PiperOrigin-RevId: 283630005
Change-Id: I77061d9ec16d6ac0f24b77940f17ea202307ffa5
2019-12-03 15:08:15 -08:00
Elena Zhelezina
e71a586359 Merge branch 'upstream/master' into fix_minimum_maximum
Change-Id: Iaaf36acdc6df7194336d76d26ded8a2f03ce56d9
2019-11-27 15:26:02 +00:00
Elena Zhelezina
4d19a5b462 [tflite] Fix and tests for the operator PACK
There is a bug in the current implementation of the operator PACK.
The multiple inputs should be requantized.
The current PR fixes this bug and adds a test for the quantization of the PACK operator.

Change-Id: Id829a6c62ea35b6b1b64c41797c02a924c14064a
2019-11-27 12:41:38 +00:00
Jared Duke
4ce6a9b7a4 Rename lite/c/c_api_internal.h to lite/c/common.h
The C types in lite/c/c_api_internal.h are not actually internal,
rather, they are common types used throughout the C++ and C APIs.
Rename the header accordingly.

PiperOrigin-RevId: 282494601
Change-Id: Ia784f35724d774db256ffcbbcdc5bb00e6574417
2019-11-25 21:49:25 -08:00
Elena Zhelezina
2c5dbcd296 Fix for minimum/maximum quantization problem
Problem description:
MINIMUM and MAXIMUM operations were not quantized properly. Specifically, the problem was that only one of the inputs was quantized while another one was left in the original data type. Because of this reason, TFLite interpreter was failing to prepare since quantization params of ops did not match.

Problem cause:
MINIMUM and MAXIMUM operators were created in the way that they only had one input, not two. Hence when looping through inputs while quantizing them, only one of two inputs was quantized.

Problem fix:
Change the definition of the aforementioned properties.

This patch contains fixes for the problem described above.

    Properties of MINIMUM and MAXIMUM operators were altered to have
    two inputs rather than one. This is safe since both 1.* and 2.* branches
    have only two inputs for these ops
    Test suite for testing Minimum and Maximum ops quantization is added
    Two small binaries have been added for testing purposes

Change-Id: Ibcbfbf7bb7118a9f2cdd8ddc03e990015ba539d7
2019-11-21 11:23:21 +00:00
Mohamed Nour Abouelseoud
51cec9092e [Lite] Support Int8 Unpack Operator
Added support for Unpack Operator
Added relevant tests.
2019-11-20 22:39:38 +00:00
Jian Li
fa0fb0d4f6 Add utility functions for integration. This supports the calibration case that the model is initialized multiple times.
(1) quatization_wrapper is the external interface to help calibration and quantization. The interface is string and bool so the dependencies are minimal. It has two functions:
- CreateCalibrationModel copies a model to a new location and adds intermediate tensors if any of the op need that.
- CreateQuantizedModel quantizes a model in place.

(2) quatization wrapper_utils is the helper function for quatization_wrapper
- added function to load model
- added function to write model

PiperOrigin-RevId: 280510873
Change-Id: I58891d6e8d6d3b485242f321466ac91ce2fdffda
2019-11-14 15:03:39 -08:00
Jian Li
fd4ad2ebdc Add LSTM quantization spec and add quantizer support for LSTM.
Test data are generated manually with dummy data.

PiperOrigin-RevId: 279857476
Change-Id: I2ac46bf3836d5eb89688b5127c23b9b0ec5cbafd
2019-11-11 18:01:33 -08:00
Jian Li
2b78c1e722 Add capability to insert intermediate tensors into a model. This is to support quantized lstm.
PiperOrigin-RevId: 278713731
Change-Id: Id38a708db4e6678dc7bfce46dd66a8b66480dc35
2019-11-05 15:31:27 -08:00
A. Unique TensorFlower
265126ca30 Added post-calibration recording of the max and min values for all input tensors.
PiperOrigin-RevId: 275090636
Change-Id: If3f1aa0f48ba24fe9041b397624cdb5dcb8b81ce
2019-10-16 12:41:40 -07:00
Suharsh Sivakumar
3c2be61e68 Add support for ops with multiple outputs (i.e. Split).
PiperOrigin-RevId: 266053965
2019-08-28 20:41:30 -07:00
Suharsh Sivakumar
9e36fea5ff Add support to only quantize specified operators in the quantization tool.
The operators are keys by their first output tensor name.

PiperOrigin-RevId: 265096821
2019-08-23 12:02:18 -07:00
Suharsh Sivakumar
a495211a78 Use tflite::SafeCast when casting float to int32.
PiperOrigin-RevId: 251571788
2019-06-04 20:57:48 -07:00
A. Unique TensorFlower
4469ed4ed8 Apply 'buildozer fix moveLicensesAndDistribs movePackageToTop' to all BUILD files.
PiperOrigin-RevId: 249807024
2019-05-24 03:53:05 -07:00
A. Unique TensorFlower
3742faa90c Support quantization to float16
PiperOrigin-RevId: 248790891
2019-05-17 14:57:42 -07:00
Suharsh Sivakumar
9e668b3d69 Add support for partially quantizing models.
PiperOrigin-RevId: 245479701
2019-04-26 14:38:08 -07:00
Jian Li
da56f874ef Add version to op property and set version during quantization.
PiperOrigin-RevId: 244284444
2019-04-18 18:32:12 -07:00
Suharsh Sivakumar
0ef2e0526f Support quantized FC layer (with biases).
This required adding support for quantizing per-layer biases.

PiperOrigin-RevId: 243709827
2019-04-15 16:59:28 -07:00
Jian Li
1f8cabfdd7 Remove subgraph quantizer.
PiperOrigin-RevId: 243645816
2019-04-15 10:58:50 -07:00
Suharsh Sivakumar
a41e83060f Add support for Argmax in quantize_model.
Also fix error message to say what operation is unsupported.

PiperOrigin-RevId: 243547677
2019-04-14 21:01:13 -07:00
Jian Li
d134aaf807 Improve post-training quantizer
PiperOrigin-RevId: 243332194
2019-04-12 15:01:00 -07:00
Jian Li
7e4c43bbe8 Add utility methods to quantization utils for model quantization.
PiperOrigin-RevId: 243201849
2019-04-11 21:58:55 -07:00
Jian Li
331de448bf Move subgraph level tests to model level.
PiperOrigin-RevId: 242704466
2019-04-09 11:59:19 -07:00