- Upgraded the Bazel BuildTool to the latest version (8.2.1).
- Updated the `tflm-ci` Docker image and pushed the new tag (0.6.1) to the `ghcr.io/tflm-bot/tflm-ci registry`.
- Updated the WORKSPACE to load `rules_cc` and `rules_shell` explicitly
- Ran `buildifier` to ensure all BUILD files to have all the fixes.
BUG=Clean-up
@tensorflow/micro
Add the REDUCE_MiN operator to the reduce kernel.
Refactor reduce kernel to decrease number of methods in tflite namespace. Add REDUCE_MIN unit tests.
Fix unit test axis data to match tensor shape.
Make Xtensa reduce kernel use reference common code for REDUCE_MIN.
Update all op resolvers.
bug=fixes #3108
Add a development tool that prints compressed and uncompressed
.tflite models to stdout in a human-readable, searchable,
structured, text format. Helpful annotations (indexes of lists,
names of operators, etc.) derived from the model are added as
virtual fields with names beginning with an _underscore.
Add a unit test which simply ensures the viewer does not crash
when run on several models found in the source tree.
BUG=see description
Remove the hexdump of the compression metadata to the test log
during the Python compression metadata test, and the requirement
for the hexdump Python package. This dump was helpful during
development of the compression metadata flatbuffer schema to
assess how changes were represented, affecting the size and the
scaling of the size.
Unfortunately, requiring the hexdump module creates problems when
Google imports this code internally, so remove it for now.
The C++ metadata test still prints a hexdump; however, the C++
flatbuffer library writes the flatbuffer slightly differently.
Within the bounds of the flatbuffer specifications, different
library writers can make different, compatible implementation
choices.
BUG=see description
Add a module for reading YAML strings that specify how a model
should be compressed. Put an example in spec.EXAMPLE_YAML_SPEC.
specfiles are written during model development to specify which
tensors should be compressed, by what method, and according to
what parameters. specfiles are read by the compression tool. They
are not used by the TFLM interpreter.
Add a YAML parser to the python third-party package dependencies.
BUG=#2636
Upgrade the pinned packages used in the Bazel build environment to make
the Python extension module compatible with NumPy 2 in addition to NumPy
1. Modules built against NumPy 1 are not compatible with runtime
environments that use NumPy 2, but modules built against NumPy 2 should
be compatible with both.
The python_requirements.txt defining the Bazel build environment is was
upgraded via the command:
bazel run //third_party:python_requirements.update -- --upgrade
See third_party/python_requirements.in for details.
This change upgraded a number of other packages as well, notably
Tensorflow, from 2.17 to 2.18. In fact, Tensorflow 2.18 is also required
for compatibility with NumPy 2.
Also update the path to the header files within the NumPy wheel, used by
the :numpy_cc_deps target. Our method of including header files shipped
in Python packages is sensitive to the internal details of those
packages, and NumPy moved their headers during this major version
change.
This fixes#2731, in which //python/tflite_micro:whl_test began failing.
:whl_test installs the newly built tflite_micro package, which packages
our Python extension module, and its dependencies into a clean virtual
environment and performs tests. The tflite_micro package has unversioned
dependencies on the tensorflow and numpy packages. Within the last 24
hours, tensorflow in PyPI was upgraded from 2.17 to 2.18. The 2.18
release upgraded tensorflow's versioned dependency on numpy from 1 to 2,
forcing the environment created by :whl_test to use NumPy 2 instead of
NumPy 1; thereby exposing the incompatibility of the extension module
that was built against NumPy 1, and causing :whl_test to fail.
BUG=#2731
The CI sync from the upstream TF has been failing for the last month due
to the relocation of certain TFLite files. In particular, some schema
files were relocated to tensorflow/compiler/mlir/lite subfolder. This PR
mirrors the migration and adds a few redirection headers to ensure
source compatibility for now.
This PR also includes a TF sync as well to get us caught up again. While
that could have been done separately, this is done together to ensure
everything continues to build with the relocations.
BUG=b/351824449
The tensorflow-cpu package does not support MacOS or non-x86 hardware. Replacing the tensorflow-cpu python package requirement with the tensorflow meta package should enable the bazel build and the dependent python scripts to be used on those platforms.
BUG=#2367, #1781
Update the third_party flatbuffers library to v23.5.26, the
current version in upstream TF. Synchronize the override BUILD
and build_defs.bzl files with those from upstream TF at
e4485c98eae.
Also update the Makefile build, which downloads flatbuffers
separately. Rebase the patch applied to the download.
Regenerate the generated-and-checked-in schemas (see
ci/sync_from_upstream_tf.sh and codegen/preprocessor/
update_schema.sh), because they are stamped with the version of
the flatbuffers library, and fail a static_assert if they are
built with a different version of flatbuffers than they were
generated with.
BUG=unsuccessful attempt to fix warning in #2183
Update the hashes for the Py package wrapt in
third_party/python_requirements.txt. Make a minimal change by deleting the
record for wrapt in python_requirements.txt and then running
bazel run //third_party:python_requirements.update
See the comments in third_party/python_requirements.in on updating
python_requirements.txt.
BUG=fixes #2264
The optimized kernel selection expects a lib target to be present in third_party/xtensa/nnlib_hifi4 so provide an alias there that maps to an external repository.
Provide a build file to be used as the root of the nnlib_hifi4 repository and add to WORKSPACE. No build is done using this lib yet as there is no xtensa toolchain available in bazel just yet.
BUG=None
As the next step in the codegen experiment, we want to generate the invoke calls for each layer. This is slightly challenging with the existing sources, as kernels only expose a registration function, not their individual Eval functions. In an effort to keep the code churn to a minimum, this PR introduces an inference only registration structure and function. It includes just two function pointers: invoke and reset. For this CL, we've only introduced it for FullyConnected.
In the code generator, this PR creates a new op_table array in the generated source, with an enum for lookup. It also generates an invoke function for each subgraph, that calls each operator's invoke function.
BUG=295174388
Add a Bazel target `//python/tflite_micro:whl.publish` that publishes the
Python distribution package to PyPI. Require an authorization token in
the environment. See code comments for usage.
BUG=part of #1484
In order to maintain a single version for our Makefile and Bazel builds, we should use the same version of KISSFFT. In addition, the Makefile version is properly setup to support multiple resolutions with the patch, so we apply that to the Bazel version as well.
BUG=[201319430](http://b/201319430)
Upgrade the third party Python package dependencies. This
includes the most recent release of Tensorflow, 2.12. As a
byproduct, using Tensorflow 2.12 enables using the latest release
of Python, 3.11.
BUG=closes #1966
We need to block the following tests as they are making the CI test pipeline to be very slow.
The following tests are taking much longed in `hifi3z`.
```
feature_provider_mock_test 20.291s
feature_provider_test 20.877s
person_detection_test 21.654s
micro_features_generator_test 33.685s
simple_features_generator_test 129.49s
```
The following tests are taking much longed in `hifi5`
```
micro_features_generator_test 11.8s
simple_features_generator_test 98.411s
pytorch_to_tflite_test 173.542s
```
BUG=http://b/273538414
Change generated with the following command:
```bash
cd tensorflow/lite/micro/
sed -i 's/TfLiteRegistration/TfLiteRegistration_V1/g' `find . -name "*.h" -o -name "*.cc"`
cd -
cd third_party/hexagon/
sed -i 's/TfLiteRegistration/TfLiteRegistration_V1/g' `find . -name "*.h" -o -name "*.cc"`
cd -
tensorflow/lite/micro/tools/ci_build/test_code_style.sh --fix_formatting
```
BUG=http://b/272808609
Extend the Python repository_rule used to create external repositories, adding targets for C-language binary libraries shipped inside Python packages; e.g., that shipped in package tensorflow-gpu.
These targets are to be used as dependencies by C-language targets.
Note: when debugging the build, it can be helpful to examine the repository directory and BUILD file this repository_rule generates in the bazel cache.
Begin using a python/ directory at the root of the project for code that is specific to Python.
Upgrade to the latest version of rules_python first. Note that the unit test to keep requirements.in and requirements.txt is disabled (specifically with
ec6bdc5d4443285d28a44076f06c203d9582e4a1)
Add a unit test for this feature.
BUG=see description
Fix many if not all uses of `bazel aquery` by renaming the BUILD file, kept in our repo, used in the external flatbuffers repo. The old name implies it is a BUILD file for the
//third_party/flatbuffers package in our repo, which trips bazel up when running an aquery, e.g.:
bazel aquery @//... >/dev/null
BUG=cleanup, see description for the issue.
Fix problems with the Python extension module build:
- Explicitly build against downloaded NumPy headers instead of relying on the build OS implicitly via the compiler's built-in paths, fixing #1283.
- Use tagged, verified downloads of pybind11_bazel and pybind to silence noise in the bazel output and improve tamper resistance, reproducibility, and caching.
The underlying issue was that the extension module depends on header files from numpy but that dependency was not captured in the BUILD rules.
Upstream Tensorflow's solution is too complicated to import. They manage dependencies on Python runtimes and libraries via much more extensive system of [custom rules](https://github.com/tensorflow/tensorflow/tree/master/third_party/py), designed to meet their many additional requirements.
Background:
- [pybind/pybind11](https://github.com/pybind/pybind11) is a C++ library that helps in creating our extension's interface to CPython.
- [pybind/pybind11_bazel](https://github.com/pybind/pybind11_bazel) provides Bazel rules for building pybind-based extensions, but doesn't cover the unusual case of using C headers provided in another Python module (in our case, NumPy).
- Bazel's own [bazelbuild/rules_python](https://github.com/bazelbuild/rules_python) provides rules for fetching Python dependencies from PyPI for use when *running* Python code via Bazel, but doesn't directly help with the unusual case of *building* code using headers provided by Python packages from PyPI (again, in our case, NumPy).
- The standard way, in Bazel, to build against third-party code is to create an [external repository](https://bazel.build/docs/external) by writing and calling [repository rules](https://bazel.build/extending/repo).
This PR supplies the C headers from NumPy to the build of our extension by adding a repository (via the new repository rule `tflm_py_cc_headers`) that reuses the PyPI package downloaded by rules_python and wraps it in a `cc_library` target on which the build of the extension can depend.
BUG=fixes #1283