Skip to content

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

Merged
merged 4 commits into from
May 16, 2025
Merged

Android check pte exists #10931

merged 4 commits into from
May 16, 2025

Conversation

kirklandsign
Copy link
Contributor

@kirklandsign kirklandsign commented May 15, 2025

Raise RuntimeException if not.

cc @cbilgin

Copy link

pytorch-bot bot commented May 15, 2025

🔗 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 (image):

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.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 15, 2025
@facebook-github-bot
Copy link
Contributor

@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@kirklandsign kirklandsign marked this pull request as ready for review May 15, 2025 23:54
@kirklandsign kirklandsign requested a review from Copilot May 15, 2025 23:55
Copy link

@Copilot Copilot AI left a 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 invoking initHybrid.
  • Refactors all other LlmModule constructors to delegate to this primary constructor.
  • Adds a file validation check in Module.load to throw a RuntimeException 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);

Comment on lines +51 to +58
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);
}
Copy link
Preview

Copilot AI May 15, 2025

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.

Suggested change
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()) {
Copy link
Preview

Copilot AI May 15, 2025

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.

@facebook-github-bot
Copy link
Contributor

@kirklandsign has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot merged commit e09f33c into main May 16, 2025
86 of 88 checks passed
@facebook-github-bot facebook-github-bot deleted the android-check-pte-exists branch May 16, 2025 02:19
@github-project-automation github-project-automation bot moved this from Todo to Done in ExecuTorch Android May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: android Issues related to Android code, build, and execution release notes: misc Miscellaneous
Projects
Development

Successfully merging this pull request may close these issues.

3 participants