Commit graph

1687 commits

Author SHA1 Message Date
Ryan Kuester
bbf70db499
feat(compression): add SpecBuilder for programmatic compression specs (#3133)
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>
2025-07-10 16:32:57 -04:00
Kunasi Ramesh
41a9c8a6c3
Porting Reverse_V2 operator from TFLite (#3123)
* 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>
2025-07-10 15:47:37 -04:00
Ryan Kuester
f50a6eaafd
feat(python): add compression module to tflite_micro Python package (#3129)
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
2025-07-08 20:18:04 +00:00
TFLM-bot
f60e4fa400
Automated sync from github.com/tensorflow/tensorflow (#3124)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-07-08 19:28:19 +00:00
TFLM-bot
3200ccd182
Automated sync from github.com/tensorflow/tensorflow (#3122)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-06-17 16:12:57 +00:00
Kunasi Ramesh
40cf8cbd47
CI changes for REVERSE_V2 Operator (#3121)
Added  reverse.h file changes in CI to pull from TFLite.

BUG=fixes #3110
2025-06-16 16:54:27 +00:00
TFLM-bot
c1b551ccee
Automated sync from github.com/tensorflow/tensorflow (#3118)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-06-11 18:01:17 +00:00
Hemanth Sai Garladinne
686df2db9f
Add INT32 support to SUB (#3037)
- Add INT32 support in sub
- Add Tflite tests in sub_test.cc

bug=fixes #2720
2025-06-04 16:34:13 +00:00
TFLM-bot
0bf295625b
Automated sync from github.com/tensorflow/tensorflow (#3111)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-06-03 23:53:59 +00:00
David Davis
0511ac7174
Fix set_external_context() during state kInit (#3102)
@tensorflow/micro

Fixes MicroInterpreterContext::set_external_context so that it can be called during InterpreterState::kInit.

Add unit test for kInit state.
Cleanup other external context tests.

bug=fixes #3101
2025-06-03 22:38:37 +00:00
Shlomi Regev
3c0b1e3091
Add a Makefile option to a Cortex-M FPU (#3105)
Only controls the ARM GCC -mfpu.

BUG=409898188
2025-05-20 17:37:28 +00:00
TFLM-bot
9d35a74b03
Automated sync from github.com/tensorflow/tensorflow (#3100)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-05-13 18:15:33 +00:00
Shlomi Regev
15b55b7afd
Revert back from C/C++17 to C/C++11 (#3095)
There are older toolchains that don't support C++17 and are still used in shipping products.
Rewrite hexdump.cc to not use C++17 features (std::byte and Class Template Argument Deduction). Also remove forcing of -std=libc for xtensa targets, which was added because stdlib isn't supported with -std=c++17.

BUG=410831256
2025-05-13 04:37:10 +00:00
TFLM-bot
c3cded749e
Automated sync from github.com/tensorflow/tensorflow (#3097)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-04-21 19:08:45 +00:00
suleshahid
a5f2923f49
Missing build dep for hexdump. (#3096)
Build fail in some cases because missing dep.

BUG=simple fix
2025-04-20 14:44:45 +00:00
Shlomi Regev
80472ee88e
Remove hexdump_test.cc from source list (#3094)
As a unit test, it belongs on MICROLITE_TEST_SRCS, which gets filtered out of MICROLITE_CC_SRCS. Keeping it on the source list results in it being compiled into the tflm archive, where its main() function conflicts with the application's main.
Also, since hexdump.cc calls DebugVsnprintf(), we need to define it in debug_log.cc, also when TF_LITE_STRIP_ERROR_STRINGS is #defined, else compilation fails. Move the #ifdef TF_LITE_STRIP_ERROR_STRINGS to be inside the function implementation, rather around the whole function.

BUG=384562154
2025-04-16 19:22:32 +00:00
TFLM-bot
5f0db3464d
Automated sync from github.com/tensorflow/tensorflow (#3060)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-04-16 17:56:33 +00:00
suleshahid
12eee9b54b
add deps (#3093) 2025-04-15 13:53:55 -07:00
suleshahid
bc68d362d6
Remove deprecated BUILD tags (#3091)
These tags have been deprecated and are unused now. Syncing with upstream and removing them from the BUILD files.

BUG=remove deprecated tags
2025-04-08 19:21:25 +00:00
vp-cad
12cd995e72
Added checks to ensure input, output quantization params are same. (#3056)
Added checks to ensure input, output quantization parameters are same.
Without this check, pooling ops would silently ignore even if the IO quantization parameters are different.

bug=fixes
2025-04-04 17:16:17 +00:00
Adrian Lundell
bf42f03951
Makefile updates for Arm(R) CPU targets (#3064)
Removing redundant assignments for CMSIS_PATH and adding the possibility to override Device Family Pack (DFP) path with a new CORTEX_DFP_PATH make variable.

This allows flexibility in where the CMSIS and DFP sources reside.

BUG=More flexible build structure
2025-03-26 16:58:42 +00:00
Andres O. Vela
b78bb7e31f
Add int16 support to RELU (#2727)
This PR adds int16 support to RELU

bug=#2726
2025-03-21 21:20:40 +00:00
Adrian Lundell
392b78f2f3
Add support for CMSIS-NN int8 transpose and padding operators (#2757)
BUG=New operator support
2025-03-20 22:27:29 +00:00
David Davis
b15beb9d49
unchecked pointer fix (#3058)
@tensorflow/micro 

Handle the failure to allocate temporary memory for a TfLiteTensor in a more graceful way.  This allows most kernels in the Prepare phase to not crash due to a DCHECK on memory allocation failure.

bug=fixes #3057
2025-03-17 17:12:26 +00:00
Kunasi Ramesh
39209b412a
Add 16bit support for unpack, transpose and comparisons operators (#3028)
Added 16bit operator support for below operators:

1. unpack
2. transpose
3. comparison

BUG=fixes #3044
2025-03-17 16:44:48 +00:00
TFLM-bot
6fc405dd65
Automated sync from github.com/tensorflow/tensorflow (#3033)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-03-07 18:05:46 +00:00
Andres O. Vela
db51e8dd3b
Print invoke status on unsuccessful invocation (#2762)
bug=#2761
2025-03-05 19:19:36 +00:00
Måns Nilsson
ef64591270
Fix quant specific op registration for some ops (#2770)
BUG=Quantization specific registration for BatchMatmul, SVDF and LSTM were not working correctly.
2025-02-07 03:02:49 +00:00
Ryan OShea
740cef3881
CMSIS-NN Min Max int8 support (#2753)
* Moves common functions to new maximum_minimum.h
  * Creates cmsis-nn/maximum_minimum.cc

BUG=#2752
Change-Id: Ifbb3fedf53043b2f8d4c48d73c2ca44c7f0f87ca
2025-02-05 01:33:16 +00:00
chase
9b79b9faf2
Allow signed char for Cortex M cores (#3035)
BUG=384562154
2025-01-16 21:56:18 +00:00
TFLM-bot
10ebaab9fc
Automated sync from github.com/tensorflow/tensorflow (#3031)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2025-01-07 19:10:40 +00:00
TFLM-bot
87d5152c92
Automated sync from github.com/tensorflow/tensorflow (#3027)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2024-12-23 18:01:07 +00:00
Ryan Kuester
01e31b7493
fix(compress.py): use single value table for per-tensor quantized tensors (#3025)
Compress using a single value table when a tensor is per-tensor
quantized, as indicated by the presence of only one quantization
scale and zero point. Update unit tests accordingly and augment
`test_models` to accommodate additional quantization fields.

Abandon the logic that a tensor should be compressed along the
NHWC channel dimension if the quantization parameters do not
specify an axis. Instead, fail with an error if the compression
axis cannot be inferred from the quantization parameters.

The interpreter already expects a single value table when a
tensor is per-tensor quantized.

BUG=part of #2636
2024-12-19 18:20:46 +00:00
suleshahid
e3ac890725
Fix missing includes for printf (#3023)
BUG=quick fix for missing includes
2024-12-19 00:21:00 +00:00
Ryan Kuester
e425abb60e
docs: update generic benchmark tool documentation (#3021)
Add instructions for using the tool with compressed models,
including profiling timing for decompression and alternate memory
regions. Update the tested targets list to include additional
Xtensa architectures. Provide example build and run commands for
compressed models with alternate decompression memory. Correct
typos and improve clarity in build instructions and example
outputs. Update compiler flags and example output to reflect
recent changes.

BUG=part of #2636
2024-12-18 02:17:24 +00:00
Ryan Kuester
478bb78ca4
feat(compression): check metadata schema version (#3022)
Add a check in `micro_allocator.cc` to verify the compression
metadata schema version. If the schema version in the metadata is
greater than the expected version, log a schema version mismatch
error and return a `nullptr`. This prevents potential issues
arising from using a newer, unsupported schema version.

BUG=part of #2636
2024-12-18 00:10:49 +00:00
Ryan Kuester
cc09a49b9b
docs: update compression documentation (#3020)
Clarify the usage of `MicroContext::AllocateDecompressionScratchBuffer`
and`tflite::micro::GetTensorData` for handling decompressed tensor
data.

Add a section on alternate decompression memory regions,
explaining how to specify and use specialized memory for
decompression.

Update instructions for compressing models using a YAML
specification.

Simplify the model compression and alignment command examples.

Spin off new Generic Benchmark Application documentation.

BUG=part of #2636
2024-12-17 23:37:12 +00:00
Ryan Kuester
b1d8a0802a
feat(compression): implement tensor decompression in op depthwise conv (#3017)
Implement tensor decompression in op depthwise conv. Extend tests
to validate operation on compressed tensors.

BUG=part of #2636
2024-12-16 23:16:35 +00:00
Ryan Kuester
099774d98b
feat(compression): implement tensor decompression in op transpose conv (#3018)
Implement tensor decompression in op transpose conv. Extend tests
to validate operation on compressed tensors.

BUG=part of #2636
2024-12-16 21:42:02 +00:00
Ryan Kuester
f9fecab84e
feat(compression): implement tensor decompression in op conv (#3015)
Implement tensor decompression in op conv. Extend tests to
validate operation on compressed tensors.

BUG=part of #2636
2024-12-16 20:01:05 +00:00
Ryan Kuester
50e7e5dbd8
feat(compression): implement tensor decompression in op concatenation (#3014)
Implement tensor decompression in op concatenation. Extend
tests to validate operation on compressed tensors.

BUG=part of #2636
2024-12-16 17:46:34 +00:00
Ryan Kuester
9a32964be9
feat(compression): allocate resource variables in persistent buffer (#3013)
Allocate resource variables in a persistent buffer when the input
tensor is compressed. Extend tests to validate operation.

BUG=part of #2636
2024-12-16 16:48:04 +00:00
Ryan Kuester
b2f27186d2
feat: enhance profiling and benchmarking (#3012)
Modify `PrintMemoryPlan` in `greedy_memory_planner.cc` for better
handling of tensor indices and scratch buffers.

Fix `total_ticks_per_tag_` usage in `micro_profiler.cc` and add
`ClearEvents` method.

Update `Makefile.inc` and `generic_model_benchmark.cc` to support
alternate memory regions and CRC32 checks for data integrity.

Include compression data in `metrics.cc` allocation records and
handle architecture-specific directives in
`show_meta_data.cc.template`.

BUG=see description
2024-12-14 19:00:55 +00:00
Ryan Kuester
a535080858
feat(compression): handle tensor compression in RecordingMicroAllocator (#3011)
Add `AllocateCompressedTensorsList` method to manage compressed
tensor allocations. Update `RecordedAllocationType` to include
`kCompressionData` for tracking compression-related allocations.
Add `TestCompressedModel` test case to validate compressed tensor
allocation functionality.

BUG=part of #2636
2024-12-13 23:37:19 +00:00
TFLM-bot
2baa918da7
Automated sync from github.com/tensorflow/tensorflow (#3010)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2024-12-13 20:18:22 +00:00
cad-audio
3bd1dd3083
Fixed scratch size calculation for conv for HiFi targets for scenarios when input, filter and output heights are 1. (#3004)
Fixed scratch size calculation for conv for HiFi targets for scenarios when input, filter and output heights are 1.
BUG=conv_hifi_scratch_size
2024-12-13 19:46:57 +00:00
suleshahid
aa3f6f3a5a
Add missing include in test_helper_custom_ops (#3009)
BUG=add missing include.
2024-12-13 18:28:08 +00:00
Ryan Kuester
a9c6e6a448
feat(compression): implement tensor decompression in op fully_connected (#3006)
Implement tensor decompression in op fully_connected. Extend
tests to validate operation on compressed tensors.

Include Xtensa extensions for decompression, as they are required
by the tests.

Fix the effect on memory_arena_threshold_test by setting a
different expected value for the persistent buffer allocation
when compression is configured in. The allocation was allowed to
vary by 3%; however, compression adds ~10%. Set the expected
value to the measured value when compression is configured in.

BUG=part of #2636
2024-12-13 04:47:55 +00:00
TFLM-bot
c4979643f3
Automated sync from github.com/tensorflow/tensorflow (#2723)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2024-12-12 23:03:52 +00:00
suleshahid
048c954652
Compression target build fixes (#3008)
Decompress_test has some issues internally due to compatibility checking.

Changed define to 1 line for easier regex for internal change.

BUG=compression BUILD fix internal
2024-12-12 21:53:12 +00:00