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
This change broke some internal models, so reverting this until we can better understand why.
This also reverts PR #2383. When relanded, both should go back in together.
BUG=b/318738218
@tensorflow/micro
Update the output tensor shape during prepare phase when the computed shape does not match the shape in the flatbuffer.
Kernels:
- BATCH_TO_SPACE_ND
- SPACE_TO_BATCH_ND
- CONV
- RESHAPE
- EXPAND_DIMS
- DEPTHWISE_CONV
Update CMSIS_NN and ARC_MLI optimized kernels.
Add additional tests from TfLite for BATCH_TO_SPACE_ND and SPACE_TO_BATCH_ND.
Update existing tests.
Add tests for Keras model using convolution with dilation > 1.
Update memory_arena_threshold_test to increase total, tail, and persistent allocation sizes:
- Add 20 bytes for CONV output shape
- Add 15 bytes for arena allocation alignment
- x2 convolution layers
Update micro_speech_test arena size as per description in C++ code.
See #2319 for additional details.
Resolves [b/317362237](https://issuetracker.google.com/317362237)
bug=fixes #2368#1646#1629#1231#2338#2319
To package the module `runtime` as `tflite_micro.runtime`, put `runtime` under
a directory representing the Python namespace package `tflite_micro`. For
organization's sake, move it all to the top-level directory `python/`. Adjust
tests and docs to match.
Some code outside of the Python extension module has come to depend on
`python/tflite_micro:python_ops_resolver` as a replacement for
`all_ops_resolver` (e.g.:`t/l/m/integration_tests/seanet/add/integration_tests.cc`).
`python_ops_resolver` is intended to be a private implementation detail of the
Python extension module. For now, grandfather in the dependent code by updating
its references to the resolver's location; however, soon the dependent code
should be migrated away to a different resolver. (#2033,
https://issuetracker.google.com/286508251)
BUG=part of #1484
First Op for the TFLM Signal Processing Ops library.
Doc linked in bug.
The Window OP is a custom signal processing OP similar to what is found in tf.signal library, but specific for integer (int16) purposes.
You can directly use this as a builtin op via the op resolver as:
* `op_resolver.AddWindow()`
* or via python as shown in `window_op_test.py`
3 testing options are provided:
* Micro(C++): `bazel run signal/micro/kernels:window_test`
* Tensorflow/Micro(Python): `bazel run python/tflite_micro/signal:window_op_test`
* Makefile(C++): `make -f tensorflow/lite/micro/tools/make/Makefile test_kernel_window_test`
BUG=[259145369](http://b/259145369)
Rename extension module `interpreter_wrapper_pybind` to `_runtime`. It is
conventional for an extension module to use the same name as its corresponding
pure-Python wrapper module, but with a leading underscore.
BUG=part of #1484
Rename the Python package `tflm_runtime` to simply `runtime` in preparation for adding it under the new namespace package `tflite_micro`. Its full name will then be `tflite_micro.runtime`.
We have kept the `tflm_runtime` target as an alias in order to stage this change. More details in http://b/286456378
BUG=part of #1484
Remove the pybind_library() used only as a dependency to the
pybind_extension(), and instead simply make the pybind_extension() directly. A
pybind_library() may be useful if used in other palces in addition to a
pybind_extension(), but with no such use in our tree, it just adds
complication.
BUG=part of #1484
We would like to throw and exception on kTfLiteError (http://b/273622999) and pass-through all the other TfLiteStatus returned by calling interpreter->Invoke()
https://github.com/tensorflow/tflite-micro/pull/1907 changed the behavior to throw an exception on kTfLiteError but did not pass through all the other status.
In particular, this is important because streaming implementation with circular_buffers relies on kTfLiteAbort being appropriately propagated.
BUG=http://b/279055226
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
Cleanup of automatically calculating the number of resource variables in the python interpreter.
Removes the parameters from the two function calls to initialize the interpreter.
BUG=[251851084](https://b.corp.google.com/issues/251851084)
Continued work on automating resource variables from python. After removing usage of the parameter, this PR removes it completely from the function call.
In addition, we now print the number of resource variables if it is greater than zero, so the user can use it to get the count when doing C++.
BUG=[251851084](https://b.corp.google.com/issues/251851084)
BUG=http://b/247808903
Enable TAP for python interpreter test. Previous decision on disabling is due to the randomness of model parameters introduced by the training process. This issue will be addressed by b/248061370. This PR only relaxes the tolerance for test coverage considerations.
This PR reverts https://github.com/tensorflow/tflite-micro/pull/1436.
BUG=http://b/259572815
Currently, the default kernel usage of the TFlite interpreter is optimized ones. This creates test inconsistencies when comparing TFLM results (reference kernel) with TFL's. Inference results comparison is logically valid if both are using reference kernels.
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
This PR will suppress the `python/interpreter/tests:interpreter_test` temporarily as this needs some redesign in terms of making sure to test the right aspects added in https://github.com/tensorflow/tflite-micro/pull/1421.
The following bug will take care of the test changes-
BUG=http://b/247808903
BUG=b/248060722
Every random operation should be seeded to help debugging (deterministic outputs). Set the seed inside the conv net training code since random data is used as training inputs.
Also, testing criteria on the quantization parameters are relaxed before b/248061370 is ready.
Inference on a quantized model requires information about
* input tensor quantization parameters (dtype, scale, zero point): to convert the input float data into the quantized one
* output tensor quantization parameters: convert the quantized result back to float (i.e., sanity check with normal model output)
This PR allows users to access these information from the python interpreter.
It also refactored the error handling mechanism following TF and TFLite.
BUG=b/245831075, b/246651364
Some models such as LSTM are stateful, which requires state reset after each inference. This PR adds the model reset function, which has already been implemented in C++, into the TFLM python interpreter.
BUG=http://b/244330968
BUG=b/239225101
In the current Python interpreter, we do Py_DECREF(model_) in the body destructor of
InterpreterWrapper, which will be called first before member variables' destructors. This causes
an issue because destructing the MicroInterpreter (namely FreeSubgraphs) relies on some parts of
model_. This means that when the destructor of MicroInterpreter is called, the model may have
already been released, causing a segfault.
We can bypass this by not using a unique pointer for MicroInterpreter, and simply delete
interpreter_ before we call Py_DECREF(model_).
BUG=b/238459185
Some error codes are expected, such as cycles_until_run in the circular buffer op. The interpreter
wrapper shouldn't throw any exception in Python when invoke returns an error.
1. Make variable name c-style following python style guide
2. Move file IO out of convert_tflite_to_html function. File io make
testing this function hard
3. Avoid file write in test and other complaints discovered in importing
to internal
BUG=discovery these when importing
Since the html is not directly renderable by github, insert a png
to show the tool's output.
Also beautify the output slightly: calls out the number is for size
explicitly.
BUG=
* A tool to visualize tflite file with size info in html format
* remove redundant build target
* Add main to tflite_size and this allows the following usage:
bazel run flatbuffer_size -- input.tflite output.html
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Asan and msan are already disabled, ubsan should be as well but was
initially undetected because ubsan tests are already disabled on GitHub
CI. This was caught during the internal sync.
BUG=b/234879912
* First pass working with float input/output
* Numpy buffer input works. Got a sine graph for hello world output.
Copyright notice
* Remove static references
* Output tensors work
* Output tensors work
* bazel test works
bazel test tensorflow/lite/micro/tools:interpreter_test
--test_output=all
* Successfully built extension with Python setuptools
cd tensorflow/lite/micro/tools/interpreter_pypi
python -m build
pip install dist/example_tflm_interpreter_psho-0.0.3-cp39-cp39-linux_x86_64.whl --force-reinstall
python tests/test-interpreter.py
TestPyPi:
pip uninstall example-tflm-interpreter-psho
python -m twine upload --repository testpypi dist/example-tflm-interpreter-psho-0.0.3.tar.gz
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple example-tflm-interpreter-psho==0.0.3
python tests/test-interpreter.py
* Refactored some
* Cleaned for production and tested with conv model
* Fixed formatting
* Fixed numpy header issue for Docker. Need to fix double registration issue that's somehow only present in Docker.
* Test fix with changes in ci.yml
* Added sudo
* Added nomsan and noasan tags to python test
* Added -layering-check, used py_library instead of py_binary to generate conv model, added micro namespace
* Removed extra debug code
* Added new tests
* Changed reinterpret_steal to cast
* Addressed PR comments
* size log refactor (#1156)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Addressed PR and review comments
* adding documentation to log_binary* workflows. (#1161)
* Automated binary size log update (#1160)
* Create an allocator to manage persistent arena (#1174)
* Create an allocator to manage persistent arena
This PR corresponds to internal cl/452380512.
Create an allocator to manage persistent arena.
This is another step towards the feature of enabling the client to
have two separate memory arenas.
BUG=https://b/226971240
* Manually patch due to Makefile difference
* Fix virtual environment when building Vela for Arm Ethos-U (#1177)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Removed print statement
Co-authored-by: jwithers <jpwithers@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: TFLM-bot <tflm-github-bot@google.com>
Co-authored-by: deqiangc <86809673+deqiangc@users.noreply.github.com>
Co-authored-by: Måns Nilsson <mans.nilsson@arm.com>