| From dcaa5c749abd49ecc8fd9cba755e86d53ce4919b Mon Sep 17 00:00:00 2001 |
| From: Tommy Chiang <ototot@google.com> |
| Date: Mon, 7 Oct 2024 02:04:45 -0700 |
| Subject: [PATCH] Stop validation if no delegates have been applied |
| |
| Some tests like StablehloPadModelTest.DefaultModelFails doesn't run |
| model inference at all, which triggers a null pointer deference when |
| validating acceleration. |
| |
| Force the validation to be stopped if no delegates have been applied to |
| avoid such the case. |
| |
| PiperOrigin-RevId: 683090747 |
| |
| PATCH_NAME=stop-dts-validation-early |
| --- |
| .../experimental/stable_delegate/kernel_test_main.cc | 8 ++++---- |
| 1 file changed, 4 insertions(+), 4 deletions(-) |
| |
| diff --git a/tensorflow/lite/delegates/utils/experimental/stable_delegate/kernel_test_main.cc b/tensorflow/lite/delegates/utils/experimental/stable_delegate/kernel_test_main.cc |
| index f3fe76d3..c45a0e4e 100644 |
| --- a/tensorflow/lite/delegates/utils/experimental/stable_delegate/kernel_test_main.cc |
| +++ b/tensorflow/lite/delegates/utils/experimental/stable_delegate/kernel_test_main.cc |
| @@ -90,11 +90,11 @@ void ValidateAcceleration(const SingleOpModel& model) { |
| // We only want to check the delegate is working properly, so an error due |
| // to incompatibility between the model and the delegate is not considered a |
| // failure here. |
| - EXPECT_THAT(model.GetDelegateApplicationStatus().value_or(kTfLiteOk), |
| + ASSERT_THAT(model.GetDelegateApplicationStatus().value_or(kTfLiteOk), |
| testing::AnyOf(kTfLiteOk, kTfLiteApplicationError)); |
| return; |
| } else { |
| - EXPECT_EQ(model.GetDelegateApplicationStatus().value_or(kTfLiteOk), |
| + ASSERT_EQ(model.GetDelegateApplicationStatus().value_or(kTfLiteOk), |
| kTfLiteOk); |
| } |
| |
| @@ -108,10 +108,10 @@ void ValidateAcceleration(const SingleOpModel& model) { |
| return; |
| } |
| TFLITE_LOG(INFO) << "Validating acceleration with the stable delegate"; |
| - EXPECT_EQ(model.CountNumberOfDelegatedPartitions(), 1) |
| + ASSERT_GT(num_applied_delegates, 0) << "No delegates were applied."; |
| + ASSERT_EQ(model.CountNumberOfDelegatedPartitions(), 1) |
| << "Expecting operation to be accelerated but cannot find a partition " |
| "associated to the stable delegate"; |
| - EXPECT_GT(num_applied_delegates, 0) << "No delegates were applied."; |
| } |
| |
| bool InitKernelTest(int* argc, char** argv) { |