-
Notifications
You must be signed in to change notification settings - Fork 603
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
Android check pte exists #10931
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ | |||||||||||||||||||||
import com.facebook.jni.annotations.DoNotStrip; | ||||||||||||||||||||||
import com.facebook.soloader.nativeloader.NativeLoader; | ||||||||||||||||||||||
import com.facebook.soloader.nativeloader.SystemDelegate; | ||||||||||||||||||||||
import java.io.File; | ||||||||||||||||||||||
import org.pytorch.executorch.annotations.Experimental; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
|
@@ -41,33 +42,49 @@ public class LlmModule { | |||||||||||||||||||||
private static native HybridData initHybrid( | ||||||||||||||||||||||
int modelType, String modulePath, String tokenizerPath, float temperature, String dataPath); | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* Constructs a LLM Module for a model with given type, model path, tokenizer, temperature, and | ||||||||||||||||||||||
* data path. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public LlmModule( | ||||||||||||||||||||||
int modelType, String modulePath, String tokenizerPath, float temperature, String dataPath) { | ||||||||||||||||||||||
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); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+51
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
mHybridData = initHybrid(modelType, modulePath, tokenizerPath, temperature, dataPath); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** Constructs a LLM Module for a model with given model path, tokenizer, temperature. */ | ||||||||||||||||||||||
public LlmModule(String modulePath, String tokenizerPath, float temperature) { | ||||||||||||||||||||||
mHybridData = initHybrid(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, null); | ||||||||||||||||||||||
this(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, null); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* Constructs a LLM Module for a model with given model path, tokenizer, temperature and data | ||||||||||||||||||||||
* path. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public LlmModule(String modulePath, String tokenizerPath, float temperature, String dataPath) { | ||||||||||||||||||||||
mHybridData = initHybrid(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, dataPath); | ||||||||||||||||||||||
this(MODEL_TYPE_TEXT, modulePath, tokenizerPath, temperature, dataPath); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** Constructs a LLM Module for a model with given path, tokenizer, and temperature. */ | ||||||||||||||||||||||
public LlmModule(int modelType, String modulePath, String tokenizerPath, float temperature) { | ||||||||||||||||||||||
mHybridData = initHybrid(modelType, modulePath, tokenizerPath, temperature, null); | ||||||||||||||||||||||
this(modelType, modulePath, tokenizerPath, temperature, null); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** Constructs a LLM Module for a model with the given LlmModuleConfig */ | ||||||||||||||||||||||
public LlmModule(LlmModuleConfig config) { | ||||||||||||||||||||||
mHybridData = | ||||||||||||||||||||||
initHybrid( | ||||||||||||||||||||||
config.getModelType(), | ||||||||||||||||||||||
config.getModulePath(), | ||||||||||||||||||||||
config.getTokenizerPath(), | ||||||||||||||||||||||
config.getTemperature(), | ||||||||||||||||||||||
config.getDataPath()); | ||||||||||||||||||||||
this( | ||||||||||||||||||||||
config.getModelType(), | ||||||||||||||||||||||
config.getModulePath(), | ||||||||||||||||||||||
config.getTokenizerPath(), | ||||||||||||||||||||||
config.getTemperature(), | ||||||||||||||||||||||
config.getDataPath()); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public void resetNative() { | ||||||||||||||||||||||
|
Oops, something went wrong.
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.
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.