Skip to content

Commit defad29

Browse files
committed
Squashed commit of the following:
commit 414a55a Author: ddavis-2015 <[email protected]> Date: Thu Nov 21 18:15:40 2024 -0800 last merge missed xtensa.inc file commit 1110543 Author: ddavis-2015 <[email protected]> Date: Thu Nov 21 18:06:45 2024 -0800 Squashed commit of the following: commit 300751d Author: ddavis-2015 <[email protected]> Date: Wed Nov 20 12:03:16 2024 -0800 Update to latest Cadence code. Int8 any bitwidth on normal quant axis updated. commit 0a49b2a Author: ddavis-2015 <[email protected]> Date: Wed Nov 20 10:50:30 2024 -0800 Add input tensor CRC to Generic Benchmark application. Only use -O3 -LNO:simd with the xtensa decompress.cc target. commit 83dafce Author: ddavis-2015 <[email protected]> Date: Mon Nov 18 17:23:58 2024 -0800 cleanup commit 2f8cead Author: ddavis-2015 <[email protected]> Date: Mon Nov 18 13:29:33 2024 -0800 Revert FakeMicroContext changes for alternate profiler. Add default alternate profiler implementation to MicroContext. commit fddf003 Author: ddavis-2015 <[email protected]> Date: Mon Nov 18 12:29:26 2024 -0800 Fix typo. commit ae6a207 Author: ddavis-2015 <[email protected]> Date: Mon Nov 18 12:29:06 2024 -0800 Implement alternate profiler for MicroInterpreter. Enable use of alternate profiler by decompression code. Enable use of alternate profiler by Generic Benchmark application. commit 5e1a1c9 Author: ddavis-2015 <[email protected]> Date: Sun Nov 10 18:24:02 2024 -0800 changes to make the memory planner debug output easier to interpret commit f651c88 Author: ddavis-2015 <[email protected]> Date: Sun Nov 10 04:27:29 2024 -0800 single pending ops queue process pending ops recursively commit cfd9890 Author: ddavis-2015 <[email protected]> Date: Sun Nov 10 00:26:14 2024 -0800 expand model_facade redo var handle tracking commit 7776cda Author: ddavis-2015 <[email protected]> Date: Tue Nov 5 13:24:58 2024 -0800 remove [[maybe_unused]] commit 40e7530 Author: ddavis-2015 <[email protected]> Date: Mon Nov 4 11:17:43 2024 -0800 fix arena commit 0d889e0 Author: ddavis-2015 <[email protected]> Date: Sat Nov 2 14:18:55 2024 -0700 Fix MicroProfiler bug with ClearEvents(). Add pre-inference profiling to the Generic Benchmark. commit bd04eb2 Author: ddavis-2015 <[email protected]> Date: Wed Nov 20 18:40:42 2024 -0800 Pre-rebase empty commit commit 661ad5e Author: Ryan Kuester <[email protected]> Date: Thu Nov 14 11:31:23 2024 -0600 feat(compression): update model compression tools commit 6eac102 Author: Ryan Kuester <[email protected]> Date: Thu Nov 14 00:31:56 2024 -0600 feat: add model compression draft Add a feature-complete draft of the model compression feature in a single commit. This commit isn't intended for merging into mainline; it exists solely for reviewers and testers to take an early look. commit f91dd91 Author: Ryan Kuester <[email protected]> Date: Wed Nov 13 16:46:20 2024 -0600 build(codegen): suppress noise in console output (tensorflow#2742) build(codegen): suppress noise in console output Redirect output from the code_generator binary so that when it's used within the build system, it doesn't print unexpected, distracting noise to the console. Generally, compiler or generator commands don't print output unless there's an error. This reverts "build(codegen): suppress noise in console output (tensorflow#2708)", commit d249577, which attempted to fix the same problem by adding a --quiet flag. A subsequent upgrade to the Tensorflow Python package caused new noise that wasn't possible to suppress with the flag. BUG=description commit 182c8c7 Author: Adrian Lundell <[email protected]> Date: Tue Nov 12 23:34:09 2024 +0100 Update CMSIS-NN Transpose conv function call (tensorflow#2760) Also removes OPTIMIZE_FOR_SIZE compiler option as the new implementation is more space efficient. BUG=CMSIS-NN update commit d7c42b9 Author: suleshahid <[email protected]> Date: Tue Nov 12 12:40:15 2024 -0800 Add SQRT to Requantize Flatbuffer. (tensorflow#2756) BUG=Add more support for tool. commit 26ada36 Author: Jae H. Yoo <[email protected]> Date: Tue Nov 12 12:14:54 2024 -0800 Update numpy_utils.cc to support ml_dtypes.bfloat16 (tensorflow#2758) This commit adds NPY_USERDEF for ml_dtypes.bfloat16 only. Other types are not supported yet. BUG=tensorflow#2759 BUG=2759 commit 79c3fde Author: Ryan Kuester <[email protected]> Date: Tue Nov 12 13:40:59 2024 -0600 ci(bazel): improve logging of bazel CI tests (tensorflow#2749) Improve the logging of Bazel commands run in CI by setting several options that turn off, e.g., progress messages intended for interactive shells, and turn on, e.g., more verbose output when something fails. BUG=tensorflow#2742 commit 9245002 Author: Ryan OShea <[email protected]> Date: Wed Nov 6 20:18:28 2024 +0100 Fix issue with transposing shape in CMSIS-NN batch matmul (tensorflow#2741) BUG=tensorflow#2740 commit 4bb78c7 Author: Ryan Kuester <[email protected]> Date: Tue Nov 5 19:11:45 2024 -0600 fix(create_tflm_tree): remove recent tests from exported tree (tensorflow#2751) Remove the recently added span_test.cc and static_vector_test.cc from the files exported by the create_tflm_tree.py project generation process by adding them to the list of tests in the Makefile. Unit tests are not meant to be included in exported trees; they may include files that are not exported. This change also ensures that these tests are included when `make test` is run. BUG=fixes tensorflow#2718 commit 45cd79b Author: Måns Nilsson <[email protected]> Date: Tue Nov 5 23:13:20 2024 +0100 Replace CoreDebug with DCB (tensorflow#2746) BUG=The CMSIS CoreDebug macro is deprecated. commit 694d250 Author: Ryan Kuester <[email protected]> Date: Tue Nov 5 15:48:52 2024 -0600 chore: remove obsolete ci/temp_patches (tensorflow#2744) chore: remove obsolete ci/temp_patches Remove ci/temp_patches, which was obsoleted in 23f608f once it was no longer used by the sync script. It should have been deleted then. Remove it not only to clean up dead code, but because it contains a reference to `micro_copts`, which is about to be refactored away, and we don't want to leave stray references to it in the tree. BUG=tensorflow#2636 commit 8eb6b23 Author: Ryan Kuester <[email protected]> Date: Fri Nov 1 17:10:05 2024 -0500 build(bazel): add integrity check to nnlib_hifi4 download (tensorflow#2743) build(bazel): add integrity check to nnlib_hifi4 download Add an integrity check to the http_archive() download of nnlib_hifi4 in order to make the build more hermetic, reduce the security risk that a remote file changes, and silence the noisy warning on the console during the build: DEBUG: Rule 'nnlib_hifi4' indicated that a canonical reproducible form can be obtained by modifying arguments integrity[....] BUG=description commit 5a46ab0 Author: Måns Nilsson <[email protected]> Date: Fri Nov 1 20:57:00 2024 +0100 Add kernels optimized for size flag to FC and SVDF (tensorflow#2734) The kernels optimized for size flag provides an alternative implementation where size is prioritized over latency. For size option (speed option is default) it means the CMSIS-NN kernels are calculating kernel sums during inference. BUG=no bug but this will let users prioritize speed vs size even more commit 389e775 Author: suleshahid <[email protected]> Date: Tue Oct 29 13:57:29 2024 -0700 Fix upstream sync (tensorflow#2728) * . * nl add * Sync from upstream TF. * fix include --------- Co-authored-by: TFLM-bot <[email protected]> commit e440f0a Author: Måns Nilsson <[email protected]> Date: Mon Oct 28 20:16:43 2024 +0100 Update CMSIS third party download (tensorflow#2716) CMSIS is updated from CMSIS_5 to CMSIS_6. BUG=It is recommended to upgrade from CMSIS_5 to CMSIS_6 commit 1b975d9 Author: suleshahid <[email protected]> Date: Mon Oct 28 11:27:23 2024 -0700 Update deprecated mergify rules (tensorflow#2732) * . * nl add * update mergify commit 78e5467 Author: Ryan Kuester <[email protected]> Date: Fri Oct 25 18:27:21 2024 -0500 fix(python): add compatibility with NumPy 2 (tensorflow#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 tensorflow#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=tensorflow#2731 commit e86d97b Author: RJ Ascani <[email protected]> Date: Mon Oct 7 10:36:26 2024 -0700 Replace rascani with suleshahid on OWNERS (tensorflow#2715) BUG=none commit e3f6dc1 Author: David Davis <[email protected]> Date: Thu Oct 3 10:45:00 2024 -0700 Compression documentation (tensorflow#2711) @tensorflow/micro Add documentation describing some compression/decompression internals and makefile build procedures. bug=tensorflow#2710 commit b3967a9 Author: Ryan Kuester <[email protected]> Date: Wed Oct 2 13:36:01 2024 -0500 style: add .style.yapf to control yapf styling of Python code (tensorflow#2709) Add a .style.yapf file so yapf can be used to style Python code without passing the project's style via command line option. Remove the corresponding patch to pigweed's call to yapf, used by CI, and instead let it too rely on .style.yapf. Remove the developer documentation's instruction to use the command line option. BUG=description commit d249577 Author: Ryan Kuester <[email protected]> Date: Tue Oct 1 16:16:45 2024 -0500 build(codegen): suppress noise in console output (tensorflow#2708) Add a --quiet option to the code_generator binary so that when it's used within the build system, it doesn't print unexpected, distracting noise to the console. Generally, compiler or generator commands don't print output unless there's an error. BUG=description
1 parent a6dc3e0 commit defad29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1875
-1435
lines changed

.bazelrc

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ build --cxxopt -std=c++17
3333
# Treat warnings as errors
3434
build --copt -Werror
3535

36+
# Common options for --config=ci
37+
build:ci --curses=no
38+
build:ci --color=no
39+
build:ci --noshow_progress
40+
build:ci --noshow_loading_progress
41+
build:ci --show_timestamps
42+
build:ci --terminal_columns=0
43+
build:ci --verbose_failures
44+
3645
# When building with the address sanitizer
3746
# E.g., bazel build --config asan
3847
build:asan --repo_env CC=clang

.github/mergify.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ queue_rules:
22
- name: default
33
checks_timeout: 2 h
44
branch_protection_injection_mode: queue
5+
merge_method: squash
56
conditions:
67
- base=main
78
- label=ci:ready_to_merge
9+
commit_message_template: |
10+
{{ title }} (#{{ number }})
11+
{{ body_raw }}
812
913
1014
pull_request_rules:
@@ -15,10 +19,6 @@ pull_request_rules:
1519
actions:
1620
queue:
1721
name: default
18-
method: squash
19-
commit_message_template: |
20-
{{ title }} (#{{ number }})
21-
{{ body_raw }}
2222

2323
- name: remove ci:ready_to_merge label
2424
conditions:

WORKSPACE

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ load("//python:py_pkg_cc_deps.bzl", "py_pkg_cc_deps")
8686

8787
py_pkg_cc_deps(
8888
name = "numpy_cc_deps",
89-
includes = ["numpy/core/include"],
89+
includes = ["numpy/_core/include"],
9090
pkg = requirement("numpy"),
9191
)
9292

@@ -101,6 +101,7 @@ py_pkg_cc_deps(
101101
http_archive(
102102
name = "nnlib_hifi4",
103103
build_file = "@tflite_micro//third_party/xtensa/nnlib_hifi4:nnlib_hifi4.BUILD",
104+
integrity = "sha256-ulZ+uY4dRsbDUMZbZtD972eghclWQrqYRb0Y4Znfyyc=",
104105
strip_prefix = "nnlib-hifi4-34f5f995f28d298ae2b6e2ba6e76c32a5cb34989",
105106
urls = ["https://github.com/foss-xtensa/nnlib-hifi4/archive/34f5f995f28d298ae2b6e2ba6e76c32a5cb34989.zip"],
106107
)

codegen/build_def.bzl

+17-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ def tflm_inference_library(
1818
native.genrule(
1919
name = generated_target,
2020
srcs = [tflite_model],
21-
outs = [name + ".h", name + ".cc"],
21+
outs = [
22+
name + ".h",
23+
name + ".cc",
24+
name + ".log",
25+
],
2226
tools = ["//codegen:code_generator"],
23-
cmd = "$(location //codegen:code_generator) --quiet " +
24-
"--model=$< --output_dir=$(RULEDIR) --output_name=%s" % name,
27+
cmd = """
28+
# code_generator (partially because it uses Tensorflow) outputs
29+
# much noise to the console. Intead, write output to a logfile to
30+
# prevent noise in the error-free bazel output.
31+
NAME=%s
32+
LOGFILE=$(RULEDIR)/$$NAME.log
33+
$(location //codegen:code_generator) \
34+
--model=$< \
35+
--output_dir=$(RULEDIR) \
36+
--output_name=$$NAME \
37+
>$$LOGFILE 2>&1
38+
""" % name,
2539
visibility = ["//visibility:private"],
2640
)
2741

python/tflite_micro/numpy_utils.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ int TfLiteTypeToPyArrayType(TfLiteType tf_lite_type) {
4141
case kTfLiteFloat16:
4242
return NPY_FLOAT16;
4343
case kTfLiteBFloat16:
44-
// TODO(b/329491949): NPY_BFLOAT16 currently doesn't exist
45-
return NPY_FLOAT16;
44+
// TODO(b/329491949): Supports other ml_dtypes user-defined types.
45+
return NPY_USERDEF;
4646
case kTfLiteFloat64:
4747
return NPY_FLOAT64;
4848
case kTfLiteInt32:
@@ -114,6 +114,10 @@ TfLiteType TfLiteTypeFromPyType(int py_type) {
114114
return kTfLiteComplex64;
115115
case NPY_COMPLEX128:
116116
return kTfLiteComplex128;
117+
case NPY_USERDEF:
118+
// User-defined types are defined in ml_dtypes. (bfloat16, float8, etc.)
119+
// Fow now, we only support bfloat16.
120+
return kTfLiteBFloat16;
117121
// Avoid default so compiler errors created when new types are made.
118122
}
119123
return kTfLiteNoType;

tensorflow/lite/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cc_library(
88
srcs = ["array.cc"],
99
hdrs = ["array.h"],
1010
deps = [
11+
"//tensorflow/lite/c:common",
1112
"//tensorflow/lite/core/c:common",
1213
],
1314
)

tensorflow/lite/array.cc

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ limitations under the License.
1515

1616
#include "tensorflow/lite/array.h"
1717

18+
#include "tensorflow/lite/c/common.h"
19+
1820
namespace tflite {
1921
namespace array_internal {
2022

tensorflow/lite/kernels/internal/reference/batch_matmul.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ inline void BatchMatMul(const RuntimeShape& lhs_shape, const int8_t* lhs_data,
111111
const float* scaling_factors,
112112
const int32_t* input_offset, int32_t* row_sums,
113113
const RuntimeShape& output_shape, float* output_data,
114-
bool* compute_row_sums) {
114+
bool* compute_row_sums,
115+
const float* per_channel_scales) {
115116
const RuntimeShape extended_lhs_shape =
116117
RuntimeShape::ExtendedShape(5, lhs_shape);
117118
const RuntimeShape extended_rhs_shape =
@@ -188,7 +189,11 @@ inline void BatchMatMul(const RuntimeShape& lhs_shape, const int8_t* lhs_data,
188189
int32_t row_sum = woff_ptr2[i];
189190
total -= row_sum * batch_offset;
190191
int idx = lhs_rows * j + i;
191-
out_ptr[idx] += batch_scaling_factor * total;
192+
float scale = batch_scaling_factor;
193+
if (per_channel_scales) {
194+
scale *= per_channel_scales[i];
195+
}
196+
out_ptr[idx] += scale * total;
192197
}
193198
}
194199
}

tensorflow/lite/micro/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ tflm_cc_library(
177177
tflm_cc_library(
178178
name = "micro_allocator",
179179
srcs = [
180+
"compression.h",
180181
"micro_allocation_info.cc",
181182
"micro_allocator.cc",
182183
],

tensorflow/lite/micro/compression/BUILD

+22-19
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ py_binary(
7373
"compress.py",
7474
],
7575
deps = [
76-
":lib",
7776
":metadata_py",
77+
":model_facade",
78+
":spec",
7879
"//tensorflow/lite/python:schema_py",
7980
"@absl_py//absl:app",
8081
"@absl_py//absl/flags",
@@ -93,6 +94,7 @@ py_test(
9394
],
9495
deps = [
9596
":compress",
97+
":model_facade",
9698
requirement("tensorflow"),
9799
],
98100
)
@@ -150,24 +152,6 @@ sh_test(
150152
],
151153
)
152154

153-
py_library(
154-
name = "lib",
155-
srcs = ["lib.py"],
156-
deps = [
157-
"model_facade",
158-
],
159-
)
160-
161-
py_test(
162-
name = "lib_test",
163-
size = "small",
164-
srcs = ["lib_test.py"],
165-
deps = [
166-
"lib",
167-
requirement("tensorflow"),
168-
],
169-
)
170-
171155
py_library(
172156
name = "model_facade",
173157
srcs = ["model_facade.py"],
@@ -183,6 +167,7 @@ py_library(
183167
deps = [
184168
"//tensorflow/lite/python:schema_py",
185169
requirement("flatbuffers"),
170+
requirement("numpy"),
186171
],
187172
)
188173

@@ -219,3 +204,21 @@ py_binary(
219204
"@absl_py//absl/flags",
220205
],
221206
)
207+
208+
py_library(
209+
name = "spec",
210+
srcs = ["spec.py"],
211+
deps = [
212+
requirement("pyyaml"),
213+
],
214+
)
215+
216+
py_test(
217+
name = "spec_test",
218+
size = "small",
219+
srcs = ["spec_test.py"],
220+
deps = [
221+
":spec",
222+
requirement("tensorflow"),
223+
],
224+
)

0 commit comments

Comments
 (0)