Fix RET_CHECK crash in tflite_weight_accessor by returning proper Status errors #6181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses a stability issue in
TfLiteWeightAccessorwhere loading incompatible or uninitialized models triggers aRET_CHECKfailure, causing the application to crash (SIGABRT).Context
As reported in #5600, using the Falcon CPU model on Android causes a hard crash due to dimension mismatches in quantized scale tensors. The current implementation uses
RET_CHECKmacros which terminate the process immediately upon failure.Implementation
This change refactors
LoadWeightandLoadTransposedWeightto replace fatal assertions with proper error handling:RET_CHECKmacros with standardabsl::InternalError(for uninitialized models) andabsl::InvalidArgumentError(for dimension mismatches).absl::Statusthat the caller can handle gracefully, rather than crashing the entire application.Fixed Issue
Fixes #5600
Type of Change
Test Plan
Static Verification: * Verified that the logic correctly implements
absl::Statusreturns and adheres to C++ best practices.Googlestyle compliance.CI/Build: * Relying on the repository's CI pipeline to verify the build against Android/iOS targets and run the regression suite, as the full cross-compilation environment is not available locally.