From e3d1a5a3b1e04e8d3f2eee9c9d3749dcb016b447 Mon Sep 17 00:00:00 2001 From: RJ Ascani Date: Mon, 14 Aug 2023 12:18:02 -0700 Subject: [PATCH 1/4] Add py load statement for codegen (#2166) The new codegen python build rules were added without properly loading the rules. BUG=b/295216390 --- codegen/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/BUILD b/codegen/BUILD index 042a1125f83..5473361484f 100644 --- a/codegen/BUILD +++ b/codegen/BUILD @@ -1,3 +1,4 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library") load("@tflm_pip_deps//:requirements.bzl", "requirement") package( From 46ccaf8fb3687d0f6b579f726400f81ab5fa7a81 Mon Sep 17 00:00:00 2001 From: RJ Ascani Date: Mon, 14 Aug 2023 12:50:55 -0700 Subject: [PATCH 2/4] Remove unused and combine similar loads (#2165) BUG=cleanup --- python/tflite_micro/signal/utils/BUILD | 3 +-- tensorflow/lite/micro/examples/person_detection/BUILD | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/python/tflite_micro/signal/utils/BUILD b/python/tflite_micro/signal/utils/BUILD index 16047dbffaf..a29cd9335db 100644 --- a/python/tflite_micro/signal/utils/BUILD +++ b/python/tflite_micro/signal/utils/BUILD @@ -1,6 +1,5 @@ # Signal python utilities. -load("@rules_python//python:defs.bzl", "py_library") -load("@rules_python//python:defs.bzl", "py_test") +load("@rules_python//python:defs.bzl", "py_library", "py_test") load("@tflm_pip_deps//:requirements.bzl", "requirement") load("@pybind11_bazel//:build_defs.bzl", "pybind_extension") diff --git a/tensorflow/lite/micro/examples/person_detection/BUILD b/tensorflow/lite/micro/examples/person_detection/BUILD index c18e024b268..449c4be11da 100644 --- a/tensorflow/lite/micro/examples/person_detection/BUILD +++ b/tensorflow/lite/micro/examples/person_detection/BUILD @@ -1,6 +1,5 @@ # Description: # TensorFlow Lite for Microcontrollers Vision Example. -load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") load("//tensorflow/lite/micro:build_def.bzl", "generate_cc_arrays") package( From 3c291cf7d495a83df1d515d8791f5febdcedb052 Mon Sep 17 00:00:00 2001 From: Advait Jain Date: Tue, 15 Aug 2023 17:32:03 -0700 Subject: [PATCH 3/4] Update int16 LSTM test case with zero_point=0 (#2171) * https://github.com/tensorflow/tflite-micro/commit/a76d1541b65c59f36fd0afff76c2443aaf261eb3 has the changes needed to create test data for the current PR. I reverted the changes back to have the script be mostly unchanged (except for some typos and trailing whitespaces). * To get the new quantization parameters: ```bash bazel run tensorflow/lite/micro/kernels/testdata:lstm_test_data_generator ``` And then manually copy over the parameters into `lstm_test_data.cc` BUG=http://b/296130372 --- .../lite/micro/kernels/testdata/lstm_test_data.cc | 14 ++++++++------ .../kernels/testdata/lstm_test_data_generator.py | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tensorflow/lite/micro/kernels/testdata/lstm_test_data.cc b/tensorflow/lite/micro/kernels/testdata/lstm_test_data.cc index 4d7d9d9edcb..8a89fe2b33d 100644 --- a/tensorflow/lite/micro/kernels/testdata/lstm_test_data.cc +++ b/tensorflow/lite/micro/kernels/testdata/lstm_test_data.cc @@ -251,12 +251,14 @@ NodeQuantizationParameters Get2X2Int16LstmQuantizationSettings() { // state quantization parameters quantization_settings.input = {/*scale=*/3.0518044e-5, /*zp=*/0, - /*symmetry=*/false}; - quantization_settings.output = {/*scale=*/1.8310826e-5, /*zp=*/-5461, - /*symmetry=*/false}; - quantization_settings.hidden_state = {/*scale=*/1.8310826e-5, /*zp=*/-5461, - /*symmetry=*/false}; - quantization_settings.cell_state = {/*scale=*/0.00024414062, /*zp=*/0, + /*symmetry=*/true}; + quantization_settings.output = {/*scale=*/2.1362956633198035e-05, /*zp=*/0, + /*symmetry=*/true}; + quantization_settings.hidden_state = {/*scale=*/2.1362956633198035e-05, + /*zp=*/0, + /*symmetry=*/true}; + quantization_settings.cell_state = {/*scale=*/0.00024414807580797754, + /*zp=*/0, /*symmetry=*/true}; // gate quantization parameters diff --git a/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator.py b/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator.py index 97c8798ef44..c6553fe2e4f 100644 --- a/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator.py +++ b/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator.py @@ -17,15 +17,15 @@ 2. Print the intermediate step outputs inside the LSTM for a single step LSTM invocation (Get2X2GateOutputCheckData in .cc) 3. Print the outputs for multi-step LSTM invocation (Get2X2LstmEvalCheckData in .cc) -Every invocation gives three types information: -1. Quantized output: kernel output in integer +Every invocation gives three types information: +1. Quantized output: kernel output in integer 2. Dequantized output: Quantized output in floating point representation 3. Float output: output from the floating point computation (i.e., float kernel) -Note: +Note: 1. Change quantization settings in _KERNEL_CONFIG to see the outcomes from various quantization schema (e.g., 8x8 Vs. 16x8) 2. Only single batch inference is supporte here. Change _GATE_TEST_DATA or _MULTISTEP_TEST_DATA to see kernel outputs on different input data -3. The quantization computation here is not the exact as the c++ implementation. The integer calculation is mimiced here using floating point. +3. The quantization computation here is not the exact as the c++ implementation. The integer calculation is emulated here using floating point. No fixed point math is implemented here. The purpose is to illustrate the computation procedure and possible quantization error accumulation, not for bit exactness. """ from absl import app @@ -88,7 +88,7 @@ _MULTISTEP_TEST_DATA = { 'init_hidden_state_vals': [0, 0], 'init_cell_state_vals': [0, 0], - 'input_data': [0.2, 0.3, 0.2, 0.3, 0.2, 0.3], # three time steps + 'input_data': [0.2, 0.3, 0.2, 0.3, 0.2, 0.3], # three time steps 'hidden_state_range': (-0.5, 0.7), 'cell_state_range': [-8, 8], 'input_data_range': [-1, 1] From f4c2d0870f13c95b2ecbdc98c88063d4595a4be0 Mon Sep 17 00:00:00 2001 From: Ryan Kuester Date: Wed, 16 Aug 2023 14:04:37 -0500 Subject: [PATCH 4/4] feat(py): give package a developmental version label (#2168) Use Bazel's workspace status mechanism, designed for "stamping" builds with identifying information from the build environment, to dynamically generate the version label of the Python distribution package. Generate stamps when Bazel runs via the --workspace_status_command option and command script. Then use these stamps in the version label. Guidelines for Python version labels are given in [PEP 440][]. TFLM does not currently tag and publish what PEP 440 calls "final releases". Instead, distribution packages will periodically be published from the tip of the main branch, and users will be expected to use the latest version or pin to a historical version of their choice. To facilitate such use, the build system needs to generate a unique, ascending version label for each commit on the main branch. Guided by [PEP 440][], use developmental version labels of the form *major[.minor].dev