Python targets in this repository import one another under the
"tflite_micro" package namespace, which //:tflite_micro_shim synthesizes
at import time. The shim is required under Bzlmod, where the main
repository's runfiles root is the fixed name "_main" rather than the
module name, so the "tflite_micro" prefix no longer resolves on its own.
Every such target therefore had to list //:tflite_micro_shim in its
deps, which was repetitive and easy to forget.
Add tflm_py_library, tflm_py_test, and tflm_py_binary wrappers in a new
//python:py_rules.bzl that inject the shim dependency automatically,
following the naming convention of the existing tflm_cc_* wrappers, and
document the shim's rationale there. Convert every target that
previously listed the shim to the corresponding wrapper and drop the
explicit dependency. The dependency graph is unchanged; only the means
by which the shim is attached differs.
* Fix Python module shadowing in Docker CI
Applies legacy_create_init = False to Python rules in BUILD files to prevent Bazel from automatically generating __init__.py files. This prevents the root 'signal/' directory (which contains C++ kernels but no Python source) from being treated as a Python package, which was shadowing the standard library 'signal' module and causing psutil failures in the tflm-ci Docker container.
* Fix directory path in Docker workflows
* Sync files related to Reverse_V2 from TFLite
#3110
* PRelu Int16x8 support in RefC
* Fix code style in prelu_test.cc
* 1. Reverted the copyright year
* Resolved compilation error for Int8x8 test case
* Add Dynamic_Update_Slice support to TFLM
* Code style error correction
* Code style correction
* Replaced hard coded MaxDimensions to RuntimeShape::kMaxSmallSize
* 1. Added more test cases \n2.Removed unused code
* Updates for test failure on ARM
* Code style updates
* Updates on test case failure for ARM
* Updates on test case failure for ARM
* Code style updates
* Add Reduce_All reference operator support to TFLM
* Resolving HiFi build errors
---------
Co-authored-by: Esun Kim <veblush@google.com>
* Sync files related to Reverse_V2 from TFLite
#3110
* PRelu Int16x8 support in RefC
* Fix code style in prelu_test.cc
* 1. Reverted the copyright year
* Resolved compilation error for Int8x8 test case
* Add Dynamic_Update_Slice support to TFLM
* Code style error correction
* Code style correction
* Replaced hard coded MaxDimensions to RuntimeShape::kMaxSmallSize
* 1. Added more test cases \n2.Removed unused code
* Updates for test failure on ARM
* Code style updates
* Updates on test case failure for ARM
* Updates on test case failure for ARM
* Code style updates
---------
Co-authored-by: Esun Kim <veblush@google.com>
Add a comprehensive Jupyter notebook tutorial demonstrating TFLM's
compression pipeline using the MNIST dataset. The tutorial covers weight
clustering with TensorFlow Model Optimization toolkit, post-training
quantization, and TFLM's LUT-based compression.
Update documentation to reference the new tutorial from the main README,
Python interpreter guide, and compression documentation.
BUG=#2636
Co-authored-by: Esun Kim <veblush@google.com>
* Support for DECODE operator
@tensorflow/micro
Add initial support for DECODE operator.
Add reference implementation.
Add LUT decompression support.
Update op resolvers.
Update Makefiles and Bazel BUILD files.
Add kernel unit test.
bug=fixes #3131
* update copyright
* Don't use constructors with global objects (bluepill will not call them).
Cleanup unit test.
* return error if DecodeState cannot be created.
* Address review issues.
---------
Co-authored-by: Esun Kim <veblush@google.com>
Add build configuration for Python 3.12 and 3.13 to the PyPI package.
Update the BUILD file with new compatibility tags and config settings,
extend pypi_build.sh to accept the new Python versions, and add build
steps in the GitHub Actions workflow.
Fix whl_test.sh to rename wheels with unstamped variable names before
pip installation. The py_wheel rule creates the base :whl target with
literal stamp variables like _BUILD_EMBED_LABEL_ in the filename for
Bazel caching purposes. Pip 25.x, which ships with Python 3.12+,
strictly validates wheel filenames and rejects these as invalid version
specifiers. Use sed to replace the unstamped variables with a valid
placeholder version (0.0.0) for testing purposes.
Python 3.14 support is not included because Python 3.14 has not yet
been released (scheduled for October 2025).
Fixes: #3186
Co-authored-by: Esun Kim <veblush@google.com>
- 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
Enhance compress() function to automatically apply proper
FlatBuffer alignment after compression, eliminating the need for
users to manually run tflite_flatbuffer_align as a separate step.
Use the C++ alignment wrapper internally, as the Python
flatbuffers library doesn't respect force_align schema
attributes.
Keep the API unchanged - compress() still returns a bytearray,
but now the output is properly aligned for the TFLM interpreter.
Update documentation, and build dependencies of the Python
package.
BUG=#3125
@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
When a model contains COMPRESSION_METADATA but the interpreter was built
without compression support, throw a RuntimeError with a helpful message
directing users to build with --//:with_compression=true.
The implementation uses inline functions in compression_utils.h
that are optimized away when compression is disabled, ensuring
all code paths remain compile-checked, and readable without
preprocessor clutter.
Includes test_compression_unsupported.py to verify the error detection,
which only runs when compression is disabled.
BUG=#3125
Enable TFLM compression support in the official Python package builds
by adding --//:with_compression=true to the bazel commands in
pypi_build.sh.
This ensures that:
- Users who install tflite_micro from PyPI can use compressed models
- The compression module functionality is available out of the box
- Both the wheel build and tests run with compression enabled
The Python package is primarily used for testing and development
on desktop/server systems, not on embedded targets. There's no
benefit to disabling compression support to save a few kilobytes
when the package runs on machines with gigabytes of RAM. Enabling
compression by default provides a better developer experience
without any practical downside.
BUG=#3125
Add a fluent builder API for creating compression specifications
without writing YAML strings. This is useful in scripts and
Jupyter notebooks.
Example usage:
spec = (compression.SpecBuilder()
.add_tensor(subgraph=0, tensor=2)
.with_lut(index_bitwidth=4)
.build())
BUG=#3125
Co-authored-by: suleshahid <110432064+suleshahid@users.noreply.github.com>
* Sync files related to Reverse_V2 from TFLite
#3110
* Added Reverse_V2 changes
BUG=fixes #3110
* Using stable_sort instead of sort & format fixes
* Replace std::stable_sort with qsort
* fix format issues
* fix format issues
* fix format issues
* Updated the changes as per the review
---------
Co-authored-by: suleshahid <110432064+suleshahid@users.noreply.github.com>
feat(python): add compression module to tflite_micro Python package
Integrate the TFLM compression tools into the tflite_micro Python
package, allowing users to compress models directly from Python code
that imports the package.
Usage:
from tflite_micro import compression
Details:
- Add compress_lib py_library target in compression BUILD
- Create compression package with __init__.py exposing public API
- Include compression module in Python package dependencies
- Add compression dependencies to wheel requirements
BUG=see description
Remove the test that incorrectly asserts the output tensor is
initially all zeros. The tensor is allocated from a shared memory
arena, and its initial state is not guaranteed to be zero. This
test eventually failed due to variations in memory allocation
during build and runtime; see the failed checks in #2945.
BUG=#2636
Remove the check for sparse tensors in the Python interpreter wrapper.
This fixes a broken build when TF_LITE_STATIC_MEMORY is set, which
should always be the case in TFLM. TfLiteTensor objects don't have a
.sparsity member when TF_LITE_STATIC_MEMORY is set, so this check
can't be made.
This prepares for an upcoming commit setting TF_LITE_STATIC_MEMORY
during Bazel builds. This hasn't caused build failures in Make builds,
which have always set TF_LITE_STATIC_MEMORY, because Make builds don't
build the Python interpreter wrapper.
BUG=#2636
Mark whl_test as size "large", so that it, and other tests of a
similar size, can be excluded with the --test_size_filters
option.
For even more convenience, provide a hook for developers to add
local .bazlerc-style defaults and configurations in
$root/bazelrc.local and ../$root/bazelrc.local.
This gives a convenient means of explicitly excluding whl_test
during local, incremental development runs of `bazel test ...`,
while not surprising users who don't opt in, and without
affecting CI.
whl_test's cached result is invalidated, and the test rerun,
following most git activity, because the git hash appears in the
Python package's version number. This combined with its long
runtime and network dependency makes it a nuisance when running
`bazel test ...` incrementally during development. Of course,
this test be run when developing changes that affect the package,
before pushing commits to main, and in CI.
BUG=see description
* ci(bazel): simplify scripts and configuration in advance of additions
Simplify the Bazel-related CI scripts and BUILD configuration in
preparation for adding several more for the compression feature.
- Move CC=clang to .bazelrc
- Define CXX in case it's already defined in the environment, in
which case it overrides deferring to CC
- Replace --repo_env, which doesn't affect build, with --action_env
- Move commented-out ubsan invocation to its own CI job. Since
ubsan was commented out, Bazel invocations have moved to their
own jobs so they can run in parallel.
- Consistently test all targets, `...`, since TFLM is no longer
confined to the tensorflow/lite/micro directory. Filter out
inappropriate new targets with no.san tags.
- Don't run `bazel build ...` before `bazel test ...`; the latter
already builds all non-test targets.
- Remove obsolete filter for `no_oss`, there were no more
`no_oss` tags in the tree.
- Stop using readable_run: it has diverged from its original
meaning and now only redirects stderr to stdout. This is not
needed.
BUG=see description
* refactor: clarify intention to run at top and test entire project
Clarify that the scripts run from the root directory of the
project by restoring the change of directory at the top of the
script, even though CI runs from the root directory of the
project.
Also clarify the intention that all tests in the project be run
by specifying `//...`, rather than `...`, which means all targets
at or below the working directory.
Remove micro_copts() by replacing every cc_* target that used
them with a tflm_cc_* equivalent, and setting those common copts
in one place, inside the tflm_cc_* macro.
This is the first of several commits introducing tflm_cc_* macros
in place of cc_binary, cc_library, and cc_test. Motivated by the
upcoming need to support conditional compilation, the objective
is to centralize build configuration rather than requiring (and
remembering that) each cc_* target in the project add the same
common attributes such as compiler options and select()ed
Alternatives such as setting global options on the command line
or in .bazelrc, even if simplified with a --config option, fail
to preserve flags and hooks for configuration in the case TFLM is
used as an external repository by an application project. Nor is
it easy in that case for individual targets to override an
otherwise global setting.
BUG=#2636
Numpy 2.0 will explicitly downcast now, which casues us to see a regerssion in the conversion for the audio model.
BUG=[361070678](https://b.corp.google.com/issues/361070678)