From 21dce8727675de018d630beb8288a2929f78972d Mon Sep 17 00:00:00 2001 From: Laura Pak Date: Wed, 13 Nov 2024 11:48:34 -0800 Subject: [PATCH] Warn if tf.lite.interpreter is used instead of ai-edge-litert.interpreter PiperOrigin-RevId: 696217271 --- RELEASE.md | 2 ++ tensorflow/lite/python/interpreter.py | 8 ++++++++ tensorflow/opensource_only.files | 1 + 3 files changed, 11 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index bb07d6fdb89..6dd59c031b0 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -74,6 +74,8 @@ This release contains contributions from many people at Google, as well as: ### Breaking Changes * `tf.lite` + * Interpreter: + * `tf.lite.Interpreter` gives a deprecation warning and a redirection notice to its new location at `ai_edge_litert.interpreter`. See the [migration guide](https://ai.google.dev/edge/litert/migration) for details. * C API: * An optional, fourth parameter was added `TfLiteOperatorCreate` as a step forward towards a cleaner API for `TfLiteOperator`. Function `TfLiteOperatorCreate` was added recently, in TensorFlow Lite version 2.17.0, released on 7/11/2024, and we do not expect there will be much code using this function yet. Any code breakages can be easily resolved by passing nullptr as the new, 4th parameter. diff --git a/tensorflow/lite/python/interpreter.py b/tensorflow/lite/python/interpreter.py index 64f7d1dac8d..27c0366738e 100644 --- a/tensorflow/lite/python/interpreter.py +++ b/tensorflow/lite/python/interpreter.py @@ -18,6 +18,7 @@ import enum import os import platform import sys +import warnings import numpy as np @@ -40,6 +41,12 @@ else: # pylint: enable=g-import-not-at-top +_INTERPRETER_DEPRECATION_WARNING = """\ + Warning: Please use the LiteRT interpreter from the ai_edge_litert package. + See the [migration guide](https://ai.google.dev/edge/litert/migration) + for details. + """ + class Delegate: """Python wrapper class to manage TfLiteDelegate objects. @@ -441,6 +448,7 @@ class Interpreter: Raises: ValueError: If the interpreter was unable to create. """ + warnings.warn(_INTERPRETER_DEPRECATION_WARNING) if not hasattr(self, '_custom_op_registerers'): self._custom_op_registerers = [] diff --git a/tensorflow/opensource_only.files b/tensorflow/opensource_only.files index 8344a9b4dc0..23a4111d130 100644 --- a/tensorflow/opensource_only.files +++ b/tensorflow/opensource_only.files @@ -118,6 +118,7 @@ tf_staging/tensorflow/lite/lib_package/BUILD: tf_staging/tensorflow/lite/model.h: tf_staging/tensorflow/lite/model_builder.h: tf_staging/tensorflow/lite/namespace.h: +tf_staging/tensorflow/lite/python/interpreter.py: tf_staging/tensorflow/lite/schema/conversion_metadata_generated.h: tf_staging/tensorflow/lite/schema/schema_generated.h: tf_staging/tensorflow/lite/signature_runner.h: