Refactor t2-14 (#3381)

This commit is contained in:
Esun Kim 2026-01-30 10:13:09 -08:00 committed by GitHub
parent 6d906db645
commit 0389008cd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 44 deletions

View file

@ -17,7 +17,7 @@ limitations under the License.
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/micro/kernels/kernel_runner.h"
#include "tensorflow/lite/micro/test_helpers.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"
namespace tflite {
namespace testing {
@ -50,12 +50,12 @@ void TestLogicalOp(const TFLMRegistration& registration, int* input1_dims_data,
outputs_array,
/*builtin_data=*/nullptr);
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare());
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke());
EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare());
EXPECT_EQ(kTfLiteOk, runner.Invoke());
TF_LITE_MICRO_EXPECT_EQ(output_dims_count, 4);
EXPECT_EQ(output_dims_count, 4);
for (int i = 0; i < output_dims_count; ++i) {
TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]);
EXPECT_EQ(expected_output_data[i], output_data[i]);
}
}
@ -63,9 +63,7 @@ void TestLogicalOp(const TFLMRegistration& registration, int* input1_dims_data,
} // namespace testing
} // namespace tflite
TF_LITE_MICRO_TESTS_BEGIN
TF_LITE_MICRO_TEST(LogicalOr) {
TEST(LogicalTest, LogicalOr) {
int shape[] = {4, 1, 1, 1, 4};
const bool input1[] = {true, false, false, true};
const bool input2[] = {true, false, true, false};
@ -75,7 +73,7 @@ TF_LITE_MICRO_TEST(LogicalOr) {
shape, input2, shape, golden, output_data);
}
TF_LITE_MICRO_TEST(BroadcastLogicalOr) {
TEST(LogicalTest, BroadcastLogicalOr) {
int input1_shape[] = {4, 1, 1, 1, 4};
const bool input1[] = {true, false, false, true};
int input2_shape[] = {4, 1, 1, 1, 1};
@ -87,7 +85,7 @@ TF_LITE_MICRO_TEST(BroadcastLogicalOr) {
golden, output_data);
}
TF_LITE_MICRO_TEST(LogicalAnd) {
TEST(LogicalTest, LogicalAnd) {
int shape[] = {4, 1, 1, 1, 4};
const bool input1[] = {true, false, false, true};
const bool input2[] = {true, false, true, false};
@ -97,7 +95,7 @@ TF_LITE_MICRO_TEST(LogicalAnd) {
shape, input2, shape, golden, output_data);
}
TF_LITE_MICRO_TEST(BroadcastLogicalAnd) {
TEST(LogicalTest, BroadcastLogicalAnd) {
int input1_shape[] = {4, 1, 1, 1, 4};
const bool input1[] = {true, false, false, true};
int input2_shape[] = {4, 1, 1, 1, 1};
@ -109,4 +107,4 @@ TF_LITE_MICRO_TEST(BroadcastLogicalAnd) {
golden, output_data);
}
TF_LITE_MICRO_TESTS_END
TF_LITE_MICRO_TESTS_MAIN

View file

@ -17,7 +17,7 @@ limitations under the License.
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/micro/kernels/kernel_runner.h"
#include "tensorflow/lite/micro/test_helpers.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"
namespace tflite {
namespace testing {
@ -149,11 +149,11 @@ void ValidateLogisticGoldens(TfLiteTensor* tensors, const int tensor_count,
micro::KernelRunner runner(registration, tensors, tensor_count, inputs_array,
outputs_array, nullptr);
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare());
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke());
EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare());
EXPECT_EQ(kTfLiteOk, runner.Invoke());
for (int i = 0; i < output_dims_count; ++i) {
TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], tolerance);
EXPECT_NEAR(golden[i], output_data[i], tolerance);
}
}
@ -208,16 +208,14 @@ void TestLogisticQuantized(int* input_dims_data, const float* input_data,
} // namespace testing
} // namespace tflite
TF_LITE_MICRO_TESTS_BEGIN
TF_LITE_MICRO_TEST(LogisticFloatBasicShouldMatchGolden) {
TEST(LogisticTest, LogisticFloatBasicShouldMatchGolden) {
float output_data[tflite::testing::flat_size_basic];
tflite::testing::TestLogisticFloat(
tflite::testing::shape_basic, tflite::testing::input_data_basic,
tflite::testing::golden_basic, tflite::testing::shape_basic, output_data);
}
TF_LITE_MICRO_TEST(LogisticQuantizedInt8BasicShouldMatchGolden) {
TEST(LogisticTest, LogisticQuantizedInt8BasicShouldMatchGolden) {
const float input_scale = 0.1;
const int input_zero_point = 0;
int8_t input_quantized[tflite::testing::flat_size_basic];
@ -233,7 +231,7 @@ TF_LITE_MICRO_TEST(LogisticQuantizedInt8BasicShouldMatchGolden) {
tflite::testing::quantized_output_zero_point_int8, output_data, 1.0f);
}
TF_LITE_MICRO_TEST(LogisticFloatWideRangeShouldMatchGolden) {
TEST(LogisticTest, LogisticFloatWideRangeShouldMatchGolden) {
float output_data[tflite::testing::flat_size_wide_range];
tflite::testing::TestLogisticFloat(
tflite::testing::shape_wide_range, tflite::testing::input_data_wide_range,
@ -241,7 +239,7 @@ TF_LITE_MICRO_TEST(LogisticFloatWideRangeShouldMatchGolden) {
output_data);
}
TF_LITE_MICRO_TEST(LogisticQuantizedInt8WideRangeShouldMatchGolden) {
TEST(LogisticTest, LogisticQuantizedInt8WideRangeShouldMatchGolden) {
const float input_scale = 1.0;
const int input_zero_point = 0;
int8_t input_quantized[tflite::testing::flat_size_wide_range];
@ -257,7 +255,7 @@ TF_LITE_MICRO_TEST(LogisticQuantizedInt8WideRangeShouldMatchGolden) {
tflite::testing::quantized_output_zero_point_int8, output_data, 1.0f);
}
TF_LITE_MICRO_TEST(LogisticQuantizedInt16ShouldMatchGolden) {
TEST(LogisticTest, LogisticQuantizedInt16ShouldMatchGolden) {
const float input_scale = 32.f / 65536.f;
const int input_zero_point = 0;
const float output_scale = 2.f / 65536.f;
@ -274,4 +272,4 @@ TF_LITE_MICRO_TEST(LogisticQuantizedInt16ShouldMatchGolden) {
output_data, 16.0f);
}
TF_LITE_MICRO_TESTS_END
TF_LITE_MICRO_TESTS_MAIN

View file

@ -25,7 +25,7 @@ limitations under the License.
#include "tensorflow/lite/micro/kernels/lstm_shared.h"
#include "tensorflow/lite/micro/kernels/testdata/lstm_test_data.h"
#include "tensorflow/lite/micro/test_helpers.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"
// TODO(b/230666079) enable below tests for xtensa when the xtensa
// kernel is reconciled with reference kernel
@ -36,11 +36,10 @@ constexpr float kTestFloatTolerance = 1e-6f;
} // namespace
#endif // !defined(XTENSA)
TF_LITE_MICRO_TESTS_BEGIN
// TODO(b/230666079) enable below tests for xtensa when the xtensa
// kernel is reconciled with reference kernel
#if !defined(XTENSA)
TF_LITE_MICRO_TEST(CheckGateOutputFloat) {
TEST(LstmEvalTest, CheckGateOutputFloat) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<float, float, float, float, 2, 3, 2, 2>
@ -107,7 +106,7 @@ TF_LITE_MICRO_TEST(CheckGateOutputFloat) {
gate_output_data.expected_cell_gate_output, kTestFloatTolerance);
}
TF_LITE_MICRO_TEST(CheckGateOutputInt8) {
TEST(LstmEvalTest, CheckGateOutputInt8) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int8_t, int8_t, int32_t, int16_t, 2, 3, 2, 2>
@ -194,7 +193,7 @@ TF_LITE_MICRO_TEST(CheckGateOutputInt8) {
gate_output_data.expected_cell_gate_output, tolerance);
}
TF_LITE_MICRO_TEST(CheckGateOutputInt16) {
TEST(LstmEvalTest, CheckGateOutputInt16) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int16_t, int8_t, int64_t, int16_t, 2, 3, 2,
@ -285,7 +284,7 @@ TF_LITE_MICRO_TEST(CheckGateOutputInt16) {
gate_output_data.expected_cell_gate_output, tolerance);
}
TF_LITE_MICRO_TEST(CheckCellStateUpdateFloat) {
TEST(LstmEvalTest, CheckCellStateUpdateFloat) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<float, float, float, float, 2, 3, 2, 2>
@ -297,7 +296,7 @@ TF_LITE_MICRO_TEST(CheckCellStateUpdateFloat) {
gate_output_data, float_node_contents, kTestFloatTolerance);
}
TF_LITE_MICRO_TEST(CheckCellStateUpdateInt8) {
TEST(LstmEvalTest, CheckCellStateUpdateInt8) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int8_t, int8_t, int32_t, int16_t, 2, 3, 2, 2>
@ -313,7 +312,7 @@ TF_LITE_MICRO_TEST(CheckCellStateUpdateInt8) {
int8_node_contents, tolerance);
}
TF_LITE_MICRO_TEST(CheckCellStateUpdateInt16) {
TEST(LstmEvalTest, CheckCellStateUpdateInt16) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int16_t, int8_t, int64_t, int16_t, 2, 3, 2,
@ -329,7 +328,7 @@ TF_LITE_MICRO_TEST(CheckCellStateUpdateInt16) {
int16_node_contents, tolerance);
}
TF_LITE_MICRO_TEST(CheckHiddenStateUpdateFloat) {
TEST(LstmEvalTest, CheckHiddenStateUpdateFloat) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<float, float, float, float, 2, 3, 2, 2>
@ -341,7 +340,7 @@ TF_LITE_MICRO_TEST(CheckHiddenStateUpdateFloat) {
gate_output_data, float_node_contents, kTestFloatTolerance);
}
TF_LITE_MICRO_TEST(CheckHiddenStateUpdateInt8) {
TEST(LstmEvalTest, CheckHiddenStateUpdateInt8) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int8_t, int8_t, int32_t, int16_t, 2, 3, 2, 2>
@ -355,7 +354,7 @@ TF_LITE_MICRO_TEST(CheckHiddenStateUpdateInt8) {
int8_node_contents, tolerance);
}
TF_LITE_MICRO_TEST(CheckHiddenStateUpdateInt16) {
TEST(LstmEvalTest, CheckHiddenStateUpdateInt16) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int16_t, int8_t, int64_t, int16_t, 2, 3, 2,
@ -369,7 +368,7 @@ TF_LITE_MICRO_TEST(CheckHiddenStateUpdateInt16) {
int16_node_contents, tolerance);
}
TF_LITE_MICRO_TEST(CheckOneStepLSTMFloat) {
TEST(LstmEvalTest, CheckOneStepLSTMFloat) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<float, float, float, float, 2, 3, 2, 2>
@ -380,7 +379,7 @@ TF_LITE_MICRO_TEST(CheckOneStepLSTMFloat) {
kTestFloatTolerance, float_node_contents);
}
TF_LITE_MICRO_TEST(CheckOneStepLSTMInt8) {
TEST(LstmEvalTest, CheckOneStepLSTMInt8) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int8_t, int8_t, int32_t, int16_t, 2, 3, 2, 2>
@ -396,7 +395,7 @@ TF_LITE_MICRO_TEST(CheckOneStepLSTMInt8) {
int8_node_contents);
}
TF_LITE_MICRO_TEST(CheckOneStepLSTMInt16) {
TEST(LstmEvalTest, CheckOneStepLSTMInt16) {
const tflite::testing::GateOutputCheckData<4, 4> gate_output_data =
tflite::testing::Get2X2GateOutputCheckData();
tflite::testing::LstmNodeContent<int16_t, int8_t, int64_t, int16_t, 2, 3, 2,
@ -413,7 +412,7 @@ TF_LITE_MICRO_TEST(CheckOneStepLSTMInt16) {
int16_node_contents);
}
TF_LITE_MICRO_TEST(TestLSTMEvalFloat) {
TEST(LstmEvalTest, TestLSTMEvalFloat) {
const tflite::testing::LstmEvalCheckData<12, 4, 12> kernel_eval_data =
tflite::testing::Get2X2LstmEvalCheckData();
tflite::testing::LstmNodeContent<float, float, float, float, 2, 3, 2, 2>
@ -424,7 +423,7 @@ TF_LITE_MICRO_TEST(TestLSTMEvalFloat) {
kTestFloatTolerance, float_node_contents);
}
TF_LITE_MICRO_TEST(TestLSTMEvalInt8) {
TEST(LstmEvalTest, TestLSTMEvalInt8) {
const tflite::testing::LstmEvalCheckData<12, 4, 12> kernel_eval_data =
tflite::testing::Get2X2LstmEvalCheckData();
tflite::testing::LstmNodeContent<int8_t, int8_t, int32_t, int16_t, 2, 3, 2, 2>
@ -439,7 +438,7 @@ TF_LITE_MICRO_TEST(TestLSTMEvalInt8) {
int8_node_contents);
}
TF_LITE_MICRO_TEST(TestLSTMEvalInt16) {
TEST(LstmEvalTest, TestLSTMEvalInt16) {
const tflite::testing::LstmEvalCheckData<12, 4, 12> kernel_eval_data =
tflite::testing::Get2X2LstmEvalCheckData();
tflite::testing::LstmNodeContent<int16_t, int8_t, int64_t, int16_t, 2, 3, 2,
@ -456,4 +455,4 @@ TF_LITE_MICRO_TEST(TestLSTMEvalInt16) {
}
#endif // !defined(XTENSA)
TF_LITE_MICRO_TESTS_END
TF_LITE_MICRO_TESTS_MAIN

View file

@ -22,7 +22,7 @@ limitations under the License.
#include "tensorflow/lite/micro/kernels/lstm_eval.h"
#include "tensorflow/lite/micro/kernels/testdata/lstm_test_data.h"
#include "tensorflow/lite/micro/test_helpers.h"
#include "tensorflow/lite/micro/testing/micro_test.h"
#include "tensorflow/lite/micro/testing/micro_test_v2.h"
namespace tflite {
namespace testing {
@ -326,7 +326,7 @@ template <typename T>
void ValidateResultGoldens(const T* golden, const T* output_data,
const int output_len, const float tolerance) {
for (int i = 0; i < output_len; ++i) {
TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], tolerance);
EXPECT_NEAR(golden[i], output_data[i], tolerance);
}
}