Commit graph

77 commits

Author SHA1 Message Date
Esun Kim
399e48b8a9
[CI] Clean up bzl (#3478)
* Removed unused

* Unused
2026-02-12 14:05:54 -08:00
Esun Kim
807c35d6a9
Bazel Module (#3364)
* Work

* Review update

* Enabled tests

* Bazel: Suppress warnings from external repositories

* Fixed whl_test

* Formatted

* More format
2026-02-11 14:11:47 -08:00
Esun Kim
ab68b206b0
Refactor t2-20 (#3387) 2026-01-30 18:27:00 +00:00
Esun Kim
41a80afaa4
[Dep] Upgraded Flatbuffer to 25.9.23 (#3296)
* flatbuffer-25.9.23

* Patch 1

* No dynamic allocation patch to Flatbuffer

* Individual ModelBuilder

* Fix

* Patch

* One more removal
2026-01-27 22:12:21 +00:00
Esun Kim
b46e68e79f
Bazel clean-up (#3359) 2026-01-26 17:20:18 -08:00
Esun Kim
dd0f1894a2
Clean-up Bazel (#3355) 2026-01-26 13:35:11 -08:00
Esun Kim
fd33340e06
Revert "[CI] Replaced tensorflow with tensorflow-cpu (#3261)" (#3290)
This reverts commit 9cbf6e0403.
2026-01-12 11:19:37 -08:00
Esun Kim
9cbf6e0403
[CI] Replaced tensorflow with tensorflow-cpu (#3261)
* Replaced tensorflow with tensorflow-cpu

* Use tensorflow-cpu for bazel targets
2025-12-03 13:43:14 -08:00
Esun Kim
858f5a3edd
[CI] Removed six, updated absl_py (#3203)
* Removed ci/install_qemu.sh

* Removed six from direct deps

* Removed six from tflm-ci docker

* Use requirement(absl_py)

* New qemu-user
2025-09-25 14:37:39 -07:00
Esun Kim
ba753cef3e
[CI] Fix build (#3194)
- 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
2025-09-19 20:48:22 +00:00
David Davis
3d4cdc19fb
Add REDUCE_MIN to reduce kernel (#3113)
@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
2025-08-05 22:11:17 +00:00
Ryan Kuester
2fa2e03ab0
feat: add tool for visualizing compressed (and uncompressed) models (#3099)
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
2025-08-04 20:09:49 +00:00
Ryan Kuester
e2cc052c4f
test(compression): remove the test log hexdump of the Python metadata (#2941)
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
2024-11-27 00:12:18 +00:00
Ryan Kuester
233e936fdf
feat(compression): add model compression tool (#2939)
Add a library and CLI for compressing models.

Add bitarray to the Python third-party package dependencies.

BUG=#2636
2024-11-26 22:12:48 +00:00
Ryan Kuester
77f707106e
feat(compression): add YAML format for specifying compression (#2795)
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
2024-11-19 19:20:03 +00:00
Ryan Kuester
78e5467d18
fix(python): add compatibility with NumPy 2 (#2733)
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
2024-10-25 16:27:21 -07:00
RJ Ascani
6411584e33
Revert "update the tensorflow.lite to use ai-edge-litert for all python based…" (#2705)
Reverts tensorflow/tflite-micro#2702

BUG=#2703
2024-09-27 17:44:05 +00:00
RJ Ascani
bf2ba11d93
update the tensorflow.lite to use ai-edge-litert for all python based… (#2702) 2024-09-26 09:11:38 -07:00
Måns Nilsson
0ad56e1cec
Update third_party/python_requirements.txt (#2692)
BUG=https://github.com/tensorflow/tflite-micro/issues/2672
2024-09-23 16:30:25 +00:00
Ryan Kuester
569ed29b9d
build(py): add hexdump requirement (#2637)
Add the Python distribution package `hexdump`, to be used in tests
and utilities which display raw memory.

BUG=#2636
2024-07-24 18:49:24 +00:00
RJ Ascani
ff5c090eca
Fix upstream TF sync (#2625)
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
2024-07-15 13:04:01 -07:00
Steven Toribio
79e3f35f3c
Remove the output_to_genfiles = True parameter from Starlark rules (#2512)
corresponding [g3 cl](https://critique.corp.google.com/cl/616227359)

BUG=N/A
2024-03-19 21:56:48 +00:00
RJ Ascani
29526e413b
Replace tensorflow-cpu usage with tensorflow (#2396)
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
2024-02-23 00:35:22 +00:00
Steven Toribio
e38f488234
renaming Flatbuffers BUILD (#2294)
renaming BUILD.external to BUILD.oss to fix github -> googel3 sync. More context in bug below .

BUG=[b/308446984](https://b.corp.google.com/issues/308446984)
2023-10-30 20:16:05 +00:00
Ryan Kuester
6bb1e3a635
build: update flatbuffers dependency to v23.5.26 (#2274)
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
2023-10-18 21:01:22 +00:00
Ryan Kuester
7b5bd336d6
build(bazel): fix hashes for Py package wrapt for Python 3.11 (#2265)
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
2023-10-09 15:52:07 +00:00
Austin Foxley
4bcc144fc8
xtensa: Add BUILD file and workspace for nnlib_hifi4 (#2239)
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
2023-09-22 19:54:38 +00:00
RJ Ascani
a0f8970856
Generate op table and subgraph invoke functions (#2176)
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
2023-08-18 20:38:16 +00:00
Ryan Kuester
3bd11ea33b
build(py): add target that publishes to PyPI (#2172)
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
2023-08-17 00:22:13 +00:00
RJ Ascani
a7b6b8551b
Remove LICENSE export for non-existent file (#2173)
There is no LICENSE file in the //third_party/ruy folder.

Context: http://cl/557522005
BUG=cleanup
2023-08-16 22:56:03 +00:00
Advait Jain
699c5178b9
Explicit load for py_library. (#2127)
BUG=http://b/291306662
2023-07-14 21:59:36 +00:00
suleshahid
9bc9deab8d
Update KISSFFT Bazel version to match Makefile version (#2044)
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)
2023-06-13 21:08:48 +00:00
TANMAY DAS
101d2bb935
TFLM swapping TfLiteRegistration_V1 struct to a new more embedded friendly api in the TFLMRegistration struct (#2001)
BUG=http://b/279811848
2023-05-26 06:48:51 +00:00
Steven Toribio
e344f4b6bb
Regenerates Integration_Test and depricates AllOpsResolver (#1969)
This PR does the following: 

This cl finishes the depreciation of AllOpsResolver in TFLM and then regenerate generate_per_layer test using PythonOpsResolver instead of AllOpsResolver after adding it to the MakoTemplate. 

[command used to regenerate integration_test](https://b.corp.google.com/issues/245770006#comment1)

[doc for changes](https://docs.google.com/document/d/1vafCGaFGGBauAssAdFABtmgpiRju2V3isioZfLMgeEc/edit?resourcekey=0-pc-aJl3TPZ7NcO9RxrNsrA#)

BUG=[b/276918689](https://b.corp.google.com/issues/276918689)
2023-05-15 17:36:16 +00:00
Ryan Kuester
4592777dc7
feat(python): upgrade Python dependencies including TF 2.12 (#1964)
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
2023-05-12 17:49:55 +00:00
Steven Toribio
6a1803eae7
remove usage of AllOpsResolver (#1947)
Gets rid of all references/usage of AllOpsResolver in the TFLM repo

[corresponding google3 cl](https://critique.corp.google.com/cl/528512732)

BUG=[b/280326818](https://b.corp.google.com/issues/280326818)
2023-05-03 02:07:45 +00:00
TANMAY DAS
c369762160
Block slow tests for hifi5 and hifi3z. (#1827)
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
2023-03-15 07:28:18 +00:00
Advait Jain
29b683a35b
Explicitly use TfLiteRegistration_V1 in TFLM. (#1817)
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
2023-03-11 01:12:03 +00:00
TANMAY DAS
20d202fa43
Fixing google3 presubmit buildify errors. (#1809)
This changes are required to import the files to google3. They are failing the checks in presubmit.
BUG=http://b/271870585
2023-03-08 21:06:49 +00:00
Ryan Kuester
17aae9e35d
build: add means of linking with C libs in Py packages (#1668)
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
2023-03-05 06:25:58 +00:00
Ryan Kuester
c82e7908f6
build: fix broken bazel aquery
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.
2023-01-11 23:54:20 +00:00
TANMAY DAS
c4df142c4e
Remove HIFI4_INTERNAL from the code completely.
BUG=https://b.corp.google.com/issues/239852051

This PR when land on google3, will not fail any CI build (this is a experimental CL to support this : https://critique.corp.google.com/cl/492504595)
2022-12-04 10:22:05 +00:00
suleshahid
a2b27b82f7
Update deprecated keyword for cfg = "host" (#1559) 2022-11-17 04:08:09 +00:00
Pauline Sho
3b186151ba
Pull in the latest version of pybind11_bazel (#1520) 2022-11-03 13:54:59 -07:00
Ryan Kuester
f050eec7e3
python: fix problems with extension module build
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
2022-10-03 22:22:08 +00:00
TANMAY DAS
680b3356d2
Change the xtensa tests to be able to run from the parent of tflm-micro/ directory.
This is a follow up PR for [1446](https://github.com/tensorflow/tflite-micro/pull/1446). Once [1446](https://github.com/tensorflow/tflite-micro/pull/1446) is merged, this pr is going to run xtensa tests from the  /opt (parent of the tflite-micro directory) and we are doing this to be consistent with our internal CI Build. 

BUG=http://b/244204467
2022-09-28 03:30:00 +00:00
Vamsi Krishna Manchala
6fdade1aed
Update TFLM examples, kernels and integration tests to clean-up the usage of ErrorReporter
This PR updates remainder of the TFLM examples, all the kernels and integration tests to remove the usage of ErrorReporter as per the changes made to the TFLM Framework API in https://github.com/tensorflow/tflite-micro/pull/1415; replaces TF_LITE_REPORT_ERROR with MicroPrintf.

BUG=http://b/192091017, http://b/245802069
2022-09-20 20:46:26 +00:00
suleshahid
1e74475fde
Update Flatbuffer version to 2.0.6 and generate schema local. (#1374) 2022-08-25 18:01:35 +00:00
suleshahid
bea1192371
Change current flatbuffer library name to represent version. (#1366) 2022-08-18 22:01:41 +00:00
Steven Toribio
dfaeaf54a8
remove TF_LITE_KERNEL_LOG test (#1251) 2022-08-03 21:31:25 +00:00