Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR: testing #2628

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
82a3b15
testing
ddavis-2015 Aug 8, 2024
9af664d
Add DEPTHWISE_CONV kernel unit test.
ddavis-2015 Aug 16, 2024
cc1a4a0
cleanup
ddavis-2015 Aug 16, 2024
13c5f71
Add DEPTHWISE_CONV compressed kernel unit tests.
ddavis-2015 Aug 17, 2024
8dbda0f
Fix XTENSA compiler warnings.
ddavis-2015 Aug 24, 2024
56cb57e
Add FULLY_CONNECTED compression support for XTENSA.
ddavis-2015 Aug 25, 2024
37bec9a
fix xtensa FULLY_CONNECTED copyright
ddavis-2015 Aug 25, 2024
3f1d113
Add DEPTHWISE_CONV compression support to XTENSA.
ddavis-2015 Aug 25, 2024
120bdbd
Change DecompressToBuffer API
ddavis-2015 Aug 27, 2024
7c406d7
Add compression support for DEPTHWISE_CONV for XTENSA P6.
ddavis-2015 Aug 27, 2024
f1a49ea
Add compression support for CONV2D for XTENSA P6.
ddavis-2015 Aug 27, 2024
404bd9c
Add compression support for FULLY_CONNECTED for XTENSA P6.
ddavis-2015 Aug 27, 2024
7fed169
fix copyright
ddavis-2015 Aug 27, 2024
23d2111
Add TFLM compression testing to XTENSA CI
ddavis-2015 Aug 27, 2024
26e53de
update micro speech test arena size
ddavis-2015 Aug 27, 2024
d458447
more viewer output
ddavis-2015 Aug 30, 2024
41dd3a3
update code style check exclusions
ddavis-2015 Aug 30, 2024
ff63716
Add profiling to decompression code using external context.
ddavis-2015 Sep 4, 2024
b392b6e
viewer works with more models
ddavis-2015 Sep 6, 2024
e85d9b7
compile without optimized kernel directory (reference kernels only)
ddavis-2015 Sep 6, 2024
7ac50a0
Update CONCATENATION kernel to more closely match TfLite.
ddavis-2015 Sep 7, 2024
e099723
Add TFLM compression support for CONCATENATION.
ddavis-2015 Sep 8, 2024
ab3cc79
Allow compression script to handle value tables of length 1.
ddavis-2015 Sep 8, 2024
37e8ee3
update copyright
ddavis-2015 Sep 9, 2024
4c6e6ad
Update compression script to support buffer sharing between tensors i…
ddavis-2015 Sep 9, 2024
a072400
Add TFLM compression support to the ASSIGN_VARIABLE kernel
ddavis-2015 Sep 9, 2024
c77d48e
model viewer also shows tensor is_variable value
ddavis-2015 Sep 11, 2024
307430f
make profilers static.
ddavis-2015 Sep 11, 2024
ac2054a
Handle \ (backslash) appearing within the metadata
ddavis-2015 Sep 11, 2024
5f26a6b
refactor bit width 4 decompression code.
ddavis-2015 Sep 19, 2024
be37537
Add TFLM compression README
ddavis-2015 Sep 19, 2024
14bc841
TFLM compression bitwidth 2 optimization
ddavis-2015 Sep 20, 2024
7cf87b5
TFLM compression bitwidth 2 improvements
ddavis-2015 Sep 21, 2024
2bac419
cleanup and fix issues with bitwidth 2 decompression optimization
ddavis-2015 Sep 21, 2024
46e8fe6
TFLM compression bitwidth 3 optimized
ddavis-2015 Sep 24, 2024
d51a035
compression document updates
ddavis-2015 Sep 24, 2024
1cf9c78
refactor and further optimize bitwidth 4 decompression.
ddavis-2015 Sep 24, 2024
e9b4621
Fix name of bitwidth 4 decompression method
ddavis-2015 Sep 26, 2024
8c0a01c
refactoring
ddavis-2015 Sep 27, 2024
24c1152
refactoring
ddavis-2015 Sep 28, 2024
3f901a7
add comment
ddavis-2015 Sep 28, 2024
445278f
Merge branch 'main' into bq-compression
ddavis-2015 Sep 29, 2024
d1a281e
Improve compression documentation
ddavis-2015 Oct 2, 2024
eb85180
add xtensa bit width 4 decompression code
ddavis-2015 Oct 4, 2024
487c17a
add xtensa any bit width decompression code
ddavis-2015 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tensorflow/lite/micro/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace tflite {
// Compressed tensors
//

static constexpr const char* kCompressionMetadataString = "TFLM_COMPRESSION";
static constexpr const char* kCompressionMetadataString =
"COMPRESSION_METADATA";

enum class CompressionScheme : uint8_t {
kBinQuant,
Expand Down Expand Up @@ -61,7 +62,7 @@ struct CompressedTensorList {
// Sparsely populated array with the same number of elements as there are
// tensors in the Subgraph. An alternative would include a tensor index in
// the struct for each and walk the list on look up. This could be slow.
CompressionTensorData** tensors;
const CompressionTensorData** tensors;
};

} // namespace tflite
Expand Down
204 changes: 204 additions & 0 deletions tensorflow/lite/micro/compression/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
load(
"@flatbuffers//:build_defs.bzl",
"flatbuffer_cc_library",
"flatbuffer_py_library",
)
load("@rules_python//python:defs.bzl", "py_test")
load("@tflm_pip_deps//:requirements.bzl", "requirement")

package(
default_visibility = [
"//visibility:public",
],
)

flatbuffer_cc_library(
# Generates the header-only library "metadata_generated.h", used to read
# the metadata flatbuffer.
name = "metadata_cc",
srcs = ["metadata.fbs"],
)

cc_library(
# The header-only library generated by flatc in ":metadata_cc" is saved to
# the source tree and comitted to git as "metadata_saved.h", which is used
# by code which builds via the Make build system, which has no means of
# generating the header on the fly. Code which builds via both bazel and
# Make should #include the saved header and use this target in its bazel
# BUILD deps. Code built exclusively via bazel would typically depend
# directly on ":metadata_cc", which would generate a header from the schema
# on the fly, during the build.
#
# When the schema definition "metadata.fbs" is changed, this saved header
# should be updated by running the script "./metadata_saved_update.sh",
# outside of bazel (because bazel cannot modify the source tree). The
# script regenerates the header from the schema and copies it to the source
# tree as "metadata_saved.h".
#
# Comitting the generated file risks inconsistency between the schema and
# the saved header, so consistency ensured by the unit test
# ":metadata_saved_test".
#
name = "metadata_saved",
hdrs = ["metadata_saved.h"],
)

flatbuffer_py_library(
# Generates the Python module "metadata_py_generated", used to read the
# metadata flatbuffer.
name = "metadata_py",
srcs = ["metadata.fbs"],
)

cc_test(
name = "metadata_test_cc",
size = "small",
srcs = ["metadata_test.cc"],
deps = [
":metadata_saved",
"//tensorflow/lite/micro:hexdump",
"//tensorflow/lite/micro/testing:micro_test",
"@flatbuffers//:runtime_cc",
],
)

py_binary(
name = "compress",
srcs = [
"compress.py",
],
deps = [
":lib",
":metadata_py",
"//tensorflow/lite/python:schema_py",
"@absl_py//absl:app",
"@absl_py//absl/flags",
"@absl_py//absl/logging",
"@flatbuffers//:runtime_py",
requirement("numpy"),
],
)

py_test(
name = "compress_test",
size = "small",
srcs = [
"compress_test.py",
],
deps = [
":compress",
requirement("tensorflow"),
],
)

py_binary(
name = "discretize",
srcs = [
"discretize.py",
],
deps = [
":metadata_py",
"//tensorflow/lite/python:schema_py",
"@absl_py//absl:app",
"@absl_py//absl/flags",
"@absl_py//absl/logging",
"@flatbuffers//:runtime_py",
requirement("numpy"),
],
)

py_binary(
name = "view",
srcs = [
"view.py",
],
deps = [
":metadata_py",
"//tensorflow/lite/python:schema_py",
"@absl_py//absl:app",
],
)

py_test(
name = "metadata_test_py",
size = "small",
srcs = ["metadata_test.py"],
main = "metadata_test.py",
deps = [
"metadata_py",
"@flatbuffers//:runtime_py",
requirement("hexdump"),
],
)

sh_test(
# Ensure consistency bewteen the schema and the saved generated header.
name = "metadata_saved_test",
size = "small",
srcs = ["metadata_saved_test.sh"],
args = [
"$(location metadata_saved.h)",
"$(location :metadata_cc_srcs)",
],
data = [
"metadata_saved.h",
":metadata_cc_srcs",
],
)

py_library(
name = "lib",
srcs = ["lib.py"],
deps = [
"model_facade",
],
)

py_test(
name = "lib_test",
size = "small",
srcs = ["lib_test.py"],
deps = [
"lib",
requirement("tensorflow"),
],
)

py_library(
name = "model_facade",
srcs = ["model_facade.py"],
deps = [
"//tensorflow/lite/python:schema_py",
requirement("flatbuffers"),
],
)

py_library(
name = "test_models",
srcs = ["test_models.py"],
deps = [
"//tensorflow/lite/python:schema_py",
requirement("flatbuffers"),
],
)

py_test(
name = "test_models_test",
size = "small",
srcs = ["test_models_test.py"],
deps = [
"test_models",
requirement("tensorflow"),
],
)

py_test(
name = "model_facade_test",
size = "small",
srcs = ["model_facade_test.py"],
deps = [
"model_facade",
"test_models",
requirement("tensorflow"),
],
)
Loading
Loading