Enhance ONNX importer with better error handling and output support. #3971
+57
−37
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.
This pull request enhances the ONNX importer for torch-mlir by improving error handling, resource management, and output feedback. It addresses potential edge cases in file handling and provides a more user-friendly experience during the import process.
Key Changes
Improved Error Handling:
Added detailed error messages for input file parsing and output file saving.
Checked file streams for proper opening and handling edge cases gracefully.
Resource Management:
Utilized RAII for managing MLIR context and module lifecycle, ensuring proper cleanup.
Enhanced Feedback:
Added meaningful console logs for various stages of the import process.
Highlighted issues during the import with clear error messages.
Optional Output File Support:
Enabled saving the MLIR module to a specified output file for further processing or debugging.
Testing
Tested with multiple ONNX files to verify successful parsing and importing.
Verified proper error messages when provided invalid or missing files.
Ensured output MLIR module is correctly written to a file or displayed as per the command-line arguments.
Why Merge This?
This improvement makes the ONNX importer more robust and user-friendly, reducing the likelihood of user errors and improving debugging capabilities. The changes align with best practices for C++ development and maintainability.