Skip to content

Commit 84cd801

Browse files
ecalubaquibcopybara-github
authored andcommitted
Use pyrwap rules for LiteRT repo to fix duplicate registration errors
PiperOrigin-RevId: 758995263
1 parent 9455628 commit 84cd801

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed

tflite/python/BUILD

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
load("@flatbuffers//:build_defs.bzl", "flatbuffer_py_library")
22
load("@org_tensorflow//tensorflow:pytype.default.bzl", "pytype_strict_contrib_test", "pytype_strict_library")
33
load("@org_tensorflow//tensorflow:strict.default.bzl", "py_strict_binary", "py_strict_library", "py_strict_test")
4-
load("@org_tensorflow//tensorflow:tensorflow.default.bzl", "get_compatible_with_portable")
4+
load("@org_tensorflow//tensorflow:tensorflow.default.bzl", "get_compatible_with_portable", "pywrap_library")
5+
load("@org_tensorflow//tensorflow/core/platform:build_config_root.bzl", "if_pywrap")
56
load("@rules_shell//shell:sh_test.bzl", "sh_test")
67
load("//tflite:special_rules.bzl", "internal_visibility_allowlist")
78

@@ -633,3 +634,46 @@ py_strict_test(
633634
"@org_tensorflow//tensorflow/python/trackable:autotrackable",
634635
],
635636
)
637+
638+
pywrap_library(
639+
name = "pywrap_tflite",
640+
common_lib_linkopts = {
641+
"framework": select({
642+
"@bazel_tools//src/conditions:windows": [],
643+
"@bazel_tools//src/conditions:darwin": [],
644+
"//conditions:default": ["-z defs"],
645+
}),
646+
},
647+
common_lib_version_scripts = {
648+
"framework": select({
649+
"@bazel_tools//src/conditions:windows": None,
650+
"@bazel_tools//src/conditions:darwin": ":darwin_framework.lds",
651+
"//conditions:default": ":linux_framework.lds",
652+
}),
653+
},
654+
common_lib_versions = {
655+
"framework": "2",
656+
},
657+
pywrap_count = 4,
658+
visibility = ["//visibility:public"],
659+
deps = [
660+
"//tflite/python/analyzer_wrapper:_pywrap_analyzer_wrapper",
661+
"//tflite/python/interpreter_wrapper:_pywrap_tensorflow_interpreter_wrapper",
662+
"//tflite/python/metrics:_pywrap_tensorflow_lite_metrics_wrapper",
663+
"//tflite/python/optimize:_pywrap_tensorflow_lite_calibration_wrapper",
664+
],
665+
)
666+
667+
py_strict_test(
668+
name = "my_test",
669+
srcs = ["my_test.py"],
670+
visibility = ["//visibility:public"],
671+
deps = [
672+
"//tflite/python:lite",
673+
"@org_tensorflow//tensorflow:tensorflow_py",
674+
] + if_pywrap(
675+
if_true = [
676+
":pywrap_tflite",
677+
],
678+
),
679+
)

tflite/python/my_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Tests for mytest package."""
16+
17+
18+
import logging
19+
import traceback
20+
import unittest
21+
22+
# pylint: disable=g-import-not-at-top
23+
try:
24+
import tensorflow as tf
25+
except ImportError as e:
26+
logging.exception("Error during import: %s", e)
27+
logging.exception("\nImport stack trace:")
28+
traceback.print_exc()
29+
raise # Re-raise the exception so the test runner knows it failed
30+
except Exception as e:
31+
logging.exception("A different error occurred during import: %s", e)
32+
logging.exception("\nImport stack trace:")
33+
traceback.print_exc()
34+
raise
35+
36+
try:
37+
from tflite.python import lite
38+
except ImportError as e:
39+
logging.exception("Error during import: %s", e)
40+
logging.exception("\nImport stack trace:")
41+
traceback.print_exc()
42+
raise # Re-raise the exception so the test runner knows it failed
43+
except Exception as e:
44+
logging.exception("A different error occurred during import: %s", e)
45+
logging.exception("\nImport stack trace:")
46+
traceback.print_exc()
47+
raise
48+
# pylint: enable=g-import-not-at-top
49+
50+
51+
class TestArithmeticFunctions(unittest.TestCase):
52+
def test_add_positive_numbers(self):
53+
logging.info("hello")
54+
logging.info(tf.__version__)
55+
logging.info(lite)
56+
57+
if __name__ == "__main__":
58+
unittest.main()

tflite/testing/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@ edgetpu_ops = [
760760
"transpose_conv",
761761
]
762762

763+
# THIS IS A TEST
764+
763765
# copybara:uncomment_begin(google-only)
764766
# [gen_zipped_test_file(
765767
# name = "zip_%s_edgetpu" % op_name,

tflite/testing/string_util_wrapper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
15+
/* THIS IS A TEST COMMENT*/
1616
#include "pybind11/pybind11.h" // from @pybind11
1717
#include "pybind11/pytypes.h" // from @pybind11
1818
#include "tflite/python/interpreter_wrapper/numpy.h"

0 commit comments

Comments
 (0)