-
Notifications
You must be signed in to change notification settings - Fork 602
Android check pte exists #10931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android check pte exists #10931
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/10931
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 905ccd0 with merge base 24789c8 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds explicit file existence and readability checks for the model and tokenizer paths in both LlmModule
and Module.load
, and centralizes constructor logic in LlmModule
by delegating to a primary constructor.
- Introduces a primary
LlmModule
constructor that validates file paths before invokinginitHybrid
. - Refactors all other
LlmModule
constructors to delegate to this primary constructor. - Adds a file validation check in
Module.load
to throw aRuntimeException
if the model file is missing or unreadable.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmModule.java | Added file existence/readability checks and refactored constructors to delegate to a single primary constructor. |
extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java | Added model file validation in load(...) before initializing the native peer. |
Comments suppressed due to low confidence (4)
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmModule.java:53
- There are no tests covering the scenario where the model or tokenizer file is invalid; adding unit tests for these exception paths would improve test coverage.
throw new RuntimeException("Cannot load model path " + modulePath);
extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java:58
- No tests currently exercise the failure path when the model file is unreadable or missing; adding tests for this case would enhance reliability.
throw new RuntimeException("Cannot load model path " + modelPath);
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm/LlmModule.java:53
- [nitpick] Throwing a generic RuntimeException makes it harder to handle specific error cases; consider using FileNotFoundException or IllegalArgumentException for clearer intent.
throw new RuntimeException("Cannot load model path " + modulePath);
extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java:58
- [nitpick] Using a generic RuntimeException for file load failures may be too broad; consider a more specific exception type such as FileNotFoundException to signal the root cause.
throw new RuntimeException("Cannot load model path " + modelPath);
File modelFile = new File(modulePath); | ||
if (!modelFile.canRead() || !modelFile.isFile()) { | ||
throw new RuntimeException("Cannot load model path " + modulePath); | ||
} | ||
File tokenizerFile = new File(tokenizerPath); | ||
if (!tokenizerFile.canRead() || !tokenizerFile.isFile()) { | ||
throw new RuntimeException("Cannot load tokenizer path " + tokenizerPath); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file existence and readability check is duplicated in Module.java; consider extracting this into a shared utility method to reduce duplication.
File modelFile = new File(modulePath); | |
if (!modelFile.canRead() || !modelFile.isFile()) { | |
throw new RuntimeException("Cannot load model path " + modulePath); | |
} | |
File tokenizerFile = new File(tokenizerPath); | |
if (!tokenizerFile.canRead() || !tokenizerFile.isFile()) { | |
throw new RuntimeException("Cannot load tokenizer path " + tokenizerPath); | |
} | |
validateFile(modulePath, "model path"); | |
validateFile(tokenizerPath, "tokenizer path"); |
Copilot uses AI. Check for mistakes.
@@ -52,6 +53,10 @@ public static Module load(final String modelPath, int loadMode) { | |||
if (!NativeLoader.isInitialized()) { | |||
NativeLoader.init(new SystemDelegate()); | |||
} | |||
File modelFile = new File(modelPath); | |||
if (!modelFile.canRead() || !modelFile.isFile()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate file validation logic appears here and in LlmModule.java; extracting a shared helper method could improve maintainability.
Copilot uses AI. Check for mistakes.
@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Raise RuntimeException if not.
cc @cbilgin