From 063e019940ad06f319c2d2c06a12e93dfe83f715 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Fri, 11 Sep 2026 14:16:08 -0700 Subject: [PATCH 1/2] Decouple recipes and testdata tests from tensorflow.python test framework --- tensorflow/lite/micro/examples/recipes/BUILD | 1 + .../examples/recipes/resource_variables_test.py | 17 ++++++++--------- .../testdata/lstm_test_data_generator_test.py | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tensorflow/lite/micro/examples/recipes/BUILD b/tensorflow/lite/micro/examples/recipes/BUILD index 95da345a21e..d1dfda7c947 100644 --- a/tensorflow/lite/micro/examples/recipes/BUILD +++ b/tensorflow/lite/micro/examples/recipes/BUILD @@ -37,6 +37,7 @@ tflm_py_test( target_compatible_with = INCOMPATIBLE_WITH_WINDOWS, deps = [ ":resource_variables_lib", + requirement("numpy"), "//python/tflite_micro:runtime", ], ) diff --git a/tensorflow/lite/micro/examples/recipes/resource_variables_test.py b/tensorflow/lite/micro/examples/recipes/resource_variables_test.py index d059bec1094..ef1a4093dfc 100644 --- a/tensorflow/lite/micro/examples/recipes/resource_variables_test.py +++ b/tensorflow/lite/micro/examples/recipes/resource_variables_test.py @@ -12,18 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================= +import unittest import numpy as np -from tensorflow.python.framework import test_util -from tensorflow.python.platform import test +from tflite_micro.python.tflite_micro import runtime as tflm_runtime from tflite_micro.tensorflow.lite.micro.examples.recipes import ( resource_variables_lib, ) -from tflite_micro.python.tflite_micro import runtime as tflm_runtime - -class ResourceVariablesTest(test_util.TensorFlowTestCase): +class ResourceVariablesTest(unittest.TestCase): # Tests the custom accumulator model. Input conditional is [True], and # accumulator value is array of 5.0. Given these inputs, we expect the output # (variable value), to be accumulated by 5.0 each invoke. @@ -34,7 +32,7 @@ def test_resource_variables_model(self): tflm_interpreter.set_input([[True]], 0) tflm_interpreter.set_input([np.full((100,), 15.0, dtype=np.float32)], 1) tflm_interpreter.invoke() - self.assertAllEqual( + np.testing.assert_array_equal( tflm_interpreter.get_output(0), np.full((1, 100), 15.0, dtype=np.float32), ) @@ -42,7 +40,7 @@ def test_resource_variables_model(self): tflm_interpreter.set_input([[False]], 0) tflm_interpreter.set_input([np.full((100,), 9.0, dtype=np.float32)], 1) tflm_interpreter.invoke() - self.assertAllEqual( + np.testing.assert_array_equal( tflm_interpreter.get_output(0), np.full((1, 100), 6.0, dtype=np.float32), ) @@ -52,11 +50,12 @@ def test_resource_variables_model(self): tflm_interpreter.set_input([[True]], 0) tflm_interpreter.set_input([np.full((100,), 5.0, dtype=np.float32)], 1) tflm_interpreter.invoke() - self.assertAllEqual( + np.testing.assert_array_equal( tflm_interpreter.get_output(0), np.full((1, 100), 5.0, dtype=np.float32), ) if __name__ == "__main__": - test.main() + unittest.main() + diff --git a/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py b/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py index 9b82c66632f..d90a1e388d7 100644 --- a/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py +++ b/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================= +import unittest import numpy as np import tensorflow as tf -from tensorflow.python.framework import test_util -from tensorflow.python.platform import test from tflite_micro.tensorflow.lite.micro.kernels.testdata import ( lstm_test_data_utils, ) @@ -78,7 +77,8 @@ def create_keras_lstm(stateful=True): return tf.keras.Model(input_layer, lstm_output, name="LSTM") -class QuantizedLSTMDebuggerTest(test_util.TensorFlowTestCase): +class QuantizedLSTMDebuggerTest(unittest.TestCase): + # only the float output from the debugger is used to setup the test data in .cc def testFloatCompareWithKeras(self): keras_lstm = create_keras_lstm() @@ -102,8 +102,8 @@ def testFloatCompareWithKeras(self): output_keras, _, _ = keras_lstm.predict(test_data.reshape(1, 1, 2)) diff = abs(output_float.flatten() - output_keras.flatten()) - self.assertAllLess(diff, 1e-6) + self.assertTrue(np.all(diff < 1e-6)) if __name__ == "__main__": - test.main() + unittest.main() From 79bb5301f1a7c7c9700bc233f770ee710e5c17e5 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Fri, 11 Sep 2026 14:45:47 -0700 Subject: [PATCH 2/2] Fix formatting in resource_variables_test.py --- .../lite/micro/examples/recipes/resource_variables_test.py | 1 - .../lite/micro/kernels/testdata/lstm_test_data_generator_test.py | 1 - 2 files changed, 2 deletions(-) diff --git a/tensorflow/lite/micro/examples/recipes/resource_variables_test.py b/tensorflow/lite/micro/examples/recipes/resource_variables_test.py index ef1a4093dfc..108751b1f90 100644 --- a/tensorflow/lite/micro/examples/recipes/resource_variables_test.py +++ b/tensorflow/lite/micro/examples/recipes/resource_variables_test.py @@ -58,4 +58,3 @@ def test_resource_variables_model(self): if __name__ == "__main__": unittest.main() - diff --git a/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py b/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py index d90a1e388d7..58a209bccec 100644 --- a/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py +++ b/tensorflow/lite/micro/kernels/testdata/lstm_test_data_generator_test.py @@ -78,7 +78,6 @@ def create_keras_lstm(stateful=True): class QuantizedLSTMDebuggerTest(unittest.TestCase): - # only the float output from the debugger is used to setup the test data in .cc def testFloatCompareWithKeras(self): keras_lstm = create_keras_lstm()