[Frontend][TFLite] Fix undefined symbols and Relay API remnants in TFLite frontend#18929
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness and clarity of the TFLite frontend by resolving numerous issues related to undefined symbols and outdated Relay API usages. The changes focus on porting existing functionalities to native Relax operations, providing explicit error handling for unsupported features, and improving overall code quality and maintainability. The goal is to ensure a more stable and predictable conversion process for TFLite models within the Relax framework. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the TFLite frontend, notably simplifying the flatten_to_nd function and significantly overhauling the convert_batch_matmul logic to use relax.op.matmul with improved shape handling and broadcasting. It also updates NotImplementedError messages for quantized operators and vision-related operations (DETECTION_POSTPROCESS, NON_MAX_SUPPRESSION_V5), adding placeholders for tracking issues. Other changes include minor import adjustments, a more Pythonic attribute check, and a fix for relax.Constant usage. New test cases for batch matrix multiplication have been added. The reviewer suggests replacing the XXXX placeholders in the NotImplementedError messages with actual GitHub issue numbers for better tracking.
| raise NotImplementedError( | ||
| "DETECTION_POSTPROCESS requires vision ops (multibox_transform_loc, " | ||
| "non_max_suppression, get_valid_counts) not yet available in Relax. " | ||
| "See https://github.com/apache/tvm/issues/XXXX" |
There was a problem hiding this comment.
| raise NotImplementedError( | ||
| "NON_MAX_SUPPRESSION_V5 requires vision ops (get_valid_counts, " | ||
| "non_max_suppression) not yet available in Relax. " | ||
| "See https://github.com/apache/tvm/issues/XXXX" |
Summary
The TFLite frontend (#18868) was ported from Relay but contains several undefined symbols and Relay-specific APIs that cause runtime errors. This PR cleans up these issues so that working code paths are clean and broken paths fail with clear
NotImplementedErrorinstead ofNameError.Changes
Fixed (now working):
convert_batch_matmul: Rewrote to userelax.op.matmulandstruct_info.shapeinstead of Relay'sshape_of/_fold_constant/
_infer_type/_qnn.op.batch_matmulflatten_to_nd: Rewrote to usestruct_info.shapeinstead of_infer_type/_fold_constantconvert_shape: Replaced undefinedshape_of()withrelax.op.shape_of()get_scalar_from_constant: Replaced_expr.Constantwithrelax.Constant_convert_resize: Fixed undefinedtflite.BuiltinOptionsreferencefrom tflite.TensorType import TensorTypeinconvert_gather,convert_sparse_to_dense,convert_transpose_conv,convert_dequantizeGuarded with explicit
NotImplementedError:convert_detection_postprocess: Referencesrelax.op.vision.{multibox_transform_loc, non_max_suppression, get_valid_counts}which don't exist yetconvert_nms_v5: Same issueconvert_batch_matmulpath: References_qnn.op.batch_matmulLint cleanup:
F821noqa retained only for_qnn/_exprin unreachable code paths (guarded byNotImplementedError), with commentexplaining why
noqa: F841for standard dataflow context variabledf