1load("@flatbuffers//:build_defs.bzl", "flatbuffer_py_library")
2load("//tensorflow:tensorflow.bzl", "get_compatible_with_portable")
3
4package(
5    default_visibility = ["//tensorflow:internal"],
6    licenses = ["notice"],  # Apache 2.0
7)
8
9exports_files(["tflite_convert.py"])
10
11flatbuffer_py_library(
12    name = "schema_py",
13    srcs = ["//tensorflow/lite/schema:schema.fbs"],
14)
15
16py_library(
17    name = "interpreter",
18    srcs = [
19        "interpreter.py",
20    ],
21    compatible_with = get_compatible_with_portable(),
22    srcs_version = "PY3",
23    visibility = ["//visibility:public"],
24    deps = [
25        "//tensorflow/lite/python/interpreter_wrapper:_pywrap_tensorflow_interpreter_wrapper",
26        "//tensorflow/python:util",
27        "//third_party/py/numpy",
28    ],
29)
30
31py_test(
32    name = "interpreter_test",
33    srcs = ["interpreter_test.py"],
34    data = [
35        "//tensorflow/lite:testdata/sparse_tensor.bin",
36        "//tensorflow/lite/python/testdata:interpreter_test_data",
37        "//tensorflow/lite/python/testdata:test_delegate.so",
38    ],
39    python_version = "PY3",
40    srcs_version = "PY3",
41    tags = [
42        "noasan",  # TODO(b/137568139): enable after this is fixed.
43        "nomsan",  # TODO(b/137568139): enable after this is fixed.
44    ],
45    deps = [
46        ":interpreter",
47        "//tensorflow/lite/python/testdata:_pywrap_test_registerer",
48        "//tensorflow/python:client_testlib",
49        "//tensorflow/python:framework_test_lib",
50        "//tensorflow/python:platform",
51        "//third_party/py/numpy",
52        "@six_archive//:six",
53    ],
54)
55
56py_binary(
57    name = "tflite_convert",
58    srcs = ["tflite_convert.py"],
59    python_version = "PY3",
60    srcs_version = "PY3",
61    visibility = ["//visibility:public"],
62    deps = [
63        ":tflite_convert_main_lib",
64        "//tensorflow:tensorflow_py",
65        "@six_archive//:six",
66    ],
67)
68
69py_library(
70    name = "tflite_convert_main_lib",
71    srcs = ["tflite_convert.py"],
72    srcs_version = "PY3",
73    visibility = ["//visibility:public"],
74    deps = [
75        ":tflite_convert_lib",
76        "//tensorflow:tensorflow_py",
77        "@six_archive//:six",
78    ],
79)
80
81py_library(
82    name = "tflite_convert_lib",
83    srcs = ["tflite_convert.py"],
84    srcs_version = "PY3",
85    visibility = ["//visibility:public"],
86    deps = [
87        ":lite",
88        "//tensorflow/lite/toco/logging:gen_html",
89        "//tensorflow/lite/toco/logging:toco_conversion_log_proto_py",
90        "//tensorflow/python:util",
91        "@six_archive//:six",
92    ],
93)
94
95py_library(
96    name = "test_util",
97    srcs = ["test_util.py"],
98    srcs_version = "PY3",
99    deps = [
100        ":lite",
101        ":schema_util",
102        "//tensorflow/lite/tools:visualize",
103        "//tensorflow/python:framework",
104    ],
105)
106
107py_test(
108    name = "test_util_test",
109    srcs = ["test_util_test.py"],
110    data = [
111        "//tensorflow/lite:testdata/add.bin",
112        "//tensorflow/lite:testdata/softplus_flex.bin",
113    ],
114    python_version = "PY3",
115    deps = [
116        ":test_util",
117    ],
118)
119
120py_test(
121    name = "tflite_convert_test",
122    srcs = ["tflite_convert_test.py"],
123    data = [
124        ":tflite_convert.par",
125        "@tflite_mobilenet_ssd_quant_protobuf//:tflite_graph.pb",
126    ],
127    python_version = "PY3",
128    # Increased thread count for reducing timeout failures.
129    shard_count = 10,
130    srcs_version = "PY3",
131    tags = [
132        "no_oss",
133        "no_pip",
134        "no_windows",
135        "noasan",  # b/144707533
136        "notsan",  # b/160824139
137    ],
138    deps = [
139        ":convert",
140        ":test_util",
141        ":tflite_convert",
142        "//tensorflow:tensorflow_py",
143        "//tensorflow/python:array_ops",
144        "//tensorflow/python:client_testlib",
145        "//tensorflow/python:constant_op",
146        "//tensorflow/python:dtypes",
147        "//tensorflow/python:framework",
148        "//tensorflow/python:framework_ops",
149        "//tensorflow/python:framework_test_lib",
150        "//tensorflow/python:platform",
151        "//tensorflow/python:random_ops",
152        "//tensorflow/python:session",
153        "//tensorflow/python:tf2",
154        "//tensorflow/python/eager:def_function",
155        "//tensorflow/python/saved_model",
156        "//tensorflow/python/saved_model:save",
157        "//tensorflow/python/training:training_util",
158        "//tensorflow/python/training/tracking",
159        "//third_party/py/numpy",
160    ],
161)
162
163py_library(
164    name = "lite",
165    srcs = ["lite.py"],
166    srcs_version = "PY3",
167    visibility = ["//visibility:public"],
168    deps = [
169        ":convert",
170        ":convert_saved_model",
171        ":interpreter",
172        ":lite_constants",
173        ":op_hint",
174        ":util",
175        "//tensorflow/lite/experimental/examples/lstm:tflite_lstm_ops",
176        "//tensorflow/lite/experimental/microfrontend:audio_microfrontend_py",
177        "//tensorflow/lite/experimental/tensorboard:ops_util",
178        "//tensorflow/lite/python/optimize:calibrator",
179        "//tensorflow/python:graph_util",
180        "//tensorflow/python/saved_model:constants",
181        "//tensorflow/python/saved_model:loader",
182        "@six_archive//:six",
183    ],
184)
185
186py_test(
187    name = "lite_test",
188    srcs = ["lite_test.py"],
189    data = [
190        "//tensorflow/lite/python/testdata:control_flow_v1.pbtxt",
191        "@tflite_mobilenet_ssd_quant_protobuf//:tflite_graph.pb",
192    ],
193    python_version = "PY3",
194    shard_count = 4,
195    srcs_version = "PY3",
196    tags = [
197        "no_windows",
198    ],
199    deps = [
200        ":lite",
201        "//tensorflow:tensorflow_py",
202        "//tensorflow/python:client_testlib",
203        "//tensorflow/python:framework_test_lib",
204        "@six_archive//:six",
205    ],
206)
207
208py_test(
209    name = "lite_v2_test",
210    srcs = ["lite_v2_test.py"],
211    data = [
212        "//tensorflow/lite/python/testdata/control_flow_v1_saved_model:saved_model.pb",
213    ],
214    python_version = "PY3",
215    shard_count = 12,
216    srcs_version = "PY3",
217    tags = [
218        "no_windows",
219    ],
220    deps = [
221        ":lite",
222        ":lite_v2_test_util",
223        "//tensorflow:tensorflow_py",
224        "//tensorflow/lite/kernels/hashtable:pywrap_hashtable_ops",
225        "//tensorflow/python:client_testlib",
226        "//tensorflow/python:framework_test_lib",
227        "@six_archive//:six",
228    ],
229)
230
231py_library(
232    name = "lite_v2_test_util",
233    testonly = 1,
234    srcs = ["lite_v2_test_util.py"],
235    srcs_version = "PY3",
236    tags = [
237        "no_windows",
238    ],
239    deps = [
240        ":lite",
241        "//tensorflow/python:client_testlib",
242        "//tensorflow/python:framework_test_lib",
243        "@six_archive//:six",
244    ],
245)
246
247py_test(
248    name = "lite_flex_test",
249    srcs = ["lite_flex_test.py"],
250    python_version = "PY3",
251    srcs_version = "PY3",
252    deps = [
253        ":lite",
254        ":test_util",
255        "//tensorflow/lite/python/testdata:double_op",
256        "//tensorflow/python:client_testlib",
257        "//tensorflow/python:framework_test_lib",
258    ],
259)
260
261py_library(
262    name = "util",
263    srcs = ["util.py"],
264    srcs_version = "PY3",
265    visibility = [
266        "//tensorflow/lite:__subpackages__",
267    ],
268    deps = [
269        ":op_hint",
270        ":schema_py",
271        ":schema_util",
272        "//tensorflow/lite/python:tflite_keras_util",
273        "//tensorflow/lite/toco:toco_flags_proto_py",
274        "//tensorflow/python:convert_to_constants",
275        "//tensorflow/python:dtypes",
276        "//tensorflow/python:error_interpolation",
277        "//tensorflow/python:graph_util",
278        "//tensorflow/python:tf_optimizer",
279        "//tensorflow/python/eager:function",
280        "//tensorflow/python/training:saver",
281        "@absl_py//absl/logging",
282        "@flatbuffers//:runtime_py",
283        "@six_archive//:six",
284    ],
285)
286
287py_test(
288    name = "util_test",
289    srcs = ["util_test.py"],
290    python_version = "PY3",
291    srcs_version = "PY3",
292    tags = [
293        "no_windows",
294    ],
295    deps = [
296        ":lite_constants",
297        ":util",
298        "//tensorflow:tensorflow_py",
299        "//tensorflow/python:array_ops",
300        "//tensorflow/python:client_testlib",
301        "//tensorflow/python:control_flow_ops",
302        "//tensorflow/python:convert_to_constants",
303        "//tensorflow/python:dtypes",
304        "//tensorflow/python:framework_ops",
305        "//tensorflow/python:framework_test_lib",
306        "//tensorflow/python:math_ops",
307        "//tensorflow/python:session",
308        "//third_party/py/numpy",
309        "@absl_py//absl/testing:parameterized",
310        "@six_archive//:six",
311    ],
312)
313
314py_library(
315    name = "tflite_keras_util",
316    srcs = [
317        "tflite_keras_util.py",
318    ],
319    srcs_version = "PY3",
320    deps = [
321        "//tensorflow/python:util",
322        "//tensorflow/python/eager:def_function",
323    ],
324)
325
326py_library(
327    name = "wrap_toco",
328    srcs = [
329        "wrap_toco.py",
330    ],
331    srcs_version = "PY3",
332    deps = [
333        "//tensorflow/python:_pywrap_toco_api",
334        "//tensorflow/python:pywrap_tensorflow",
335        "//tensorflow/python:util",
336    ],
337)
338
339py_library(
340    name = "lite_constants",
341    srcs = ["lite_constants.py"],
342    srcs_version = "PY3",
343    deps = [
344        "//tensorflow/lite/toco:toco_flags_proto_py",
345        "//tensorflow/python:dtypes",
346    ],
347)
348
349py_library(
350    name = "convert",
351    srcs = ["convert.py"],
352    srcs_version = "PY3",
353    visibility = ["//visibility:public"],
354    deps = [
355        ":lite_constants",
356        ":util",
357        ":wrap_toco",
358        "//tensorflow/lite/toco:model_flags_proto_py",
359        "//tensorflow/lite/toco:toco_flags_proto_py",
360        "//tensorflow/lite/toco/python:toco_from_protos",
361        "//tensorflow/python:dtypes",
362        "//tensorflow/python:platform",
363        "@six_archive//:six",
364    ],
365)
366
367py_library(
368    name = "op_hint",
369    srcs = ["op_hint.py"],
370    srcs_version = "PY3",
371    visibility = ["//visibility:public"],
372    deps = [
373        "//tensorflow/core:protos_all_py",
374        "//tensorflow/python:graph_util",
375        "//tensorflow/python:platform",
376        "//tensorflow/python:util",
377    ],
378)
379
380py_test(
381    name = "convert_test",
382    srcs = ["convert_test.py"],
383    python_version = "PY3",
384    srcs_version = "PY3",
385    deps = [
386        ":convert",
387        ":interpreter",
388        ":op_hint",
389        "//tensorflow/python:array_ops",
390        "//tensorflow/python:client_testlib",
391        "//tensorflow/python:dtypes",
392        "//tensorflow/python:platform_test",
393        "//tensorflow/python:session",
394    ],
395)
396
397py_library(
398    name = "convert_saved_model",
399    srcs = ["convert_saved_model.py"],
400    srcs_version = "PY3",
401    visibility = [
402        "//tensorflow/lite:__subpackages__",
403    ],
404    deps = [
405        ":util",
406        "//tensorflow/python:graph_util",
407        "//tensorflow/python:platform",
408        "//tensorflow/python/saved_model",
409    ],
410)
411
412py_test(
413    name = "convert_saved_model_test",
414    srcs = ["convert_saved_model_test.py"],
415    python_version = "PY3",
416    srcs_version = "PY3",
417    tags = [
418        "no_windows",
419    ],
420    visibility = ["//visibility:public"],
421    deps = [
422        ":convert_saved_model",
423        "//tensorflow/python:client_testlib",
424        "//tensorflow/python:layers",
425        "//tensorflow/python:nn",
426        "//tensorflow/python:platform_test",
427        "//tensorflow/python:session",
428        "//tensorflow/python/ops/losses",
429        "//tensorflow/python/saved_model",
430    ],
431)
432
433py_binary(
434    name = "convert_file_to_c_source",
435    srcs = ["convert_file_to_c_source.py"],
436    python_version = "PY3",
437    srcs_version = "PY3",
438    visibility = ["//visibility:public"],
439    deps = [
440        ":util",
441        "@absl_py//absl:app",
442        "@absl_py//absl/flags",
443    ],
444)
445
446sh_test(
447    name = "convert_file_to_c_source_test",
448    srcs = ["convert_file_to_c_source_test.sh"],
449    data = [":convert_file_to_c_source"],
450)
451
452py_library(
453    name = "schema_util",
454    srcs = ["schema_util.py"],
455    srcs_version = "PY3",
456    visibility = ["//tensorflow/lite/schema:utils_friends"],
457    deps = [
458        "//tensorflow/python:util",
459    ],
460)
461