Skip to content

Commit 5309d68

Browse files
authored
Fix model/tokenizer path consistency (#135)
* Fix Load Model button availability * Prevent unnecessary "select model" message
1 parent 4c4aec0 commit 5309d68

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ protected void onResume() {
381381
// If users change the model file, but not pressing loadModelButton, we won't load the new
382382
// model
383383
checkForUpdateAndReloadModel(updatedSettingsFields);
384-
} else {
384+
} else if (mModule == null) {
385+
// Only ask user to select model if no model is currently loaded
385386
askUserToSelectModel();
386387
}
387388
} else {
@@ -392,7 +393,8 @@ protected void onResume() {
392393
askUserToSelectModel();
393394
}
394395
}
395-
} else {
396+
} else if (mModule == null) {
397+
// Only ask user to select model if no model is currently loaded
396398
askUserToSelectModel();
397399
}
398400
}

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/SettingsActivity.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,12 @@ private void setupSettings() {
145145
view -> {
146146
setupModelTypeSelectorDialog();
147147
});
148-
mModelFilePath = mSettingsFields.getModelFilePath();
149-
if (!mModelFilePath.isEmpty()) {
148+
if (mModelFilePath != null && !mModelFilePath.isEmpty()) {
150149
mModelTextView.setText(getFilenameFromPath(mModelFilePath));
151150
}
152-
mTokenizerFilePath = mSettingsFields.getTokenizerFilePath();
153-
if (!mTokenizerFilePath.isEmpty()) {
151+
if (mTokenizerFilePath != null && !mTokenizerFilePath.isEmpty()) {
154152
mTokenizerTextView.setText(getFilenameFromPath(mTokenizerFilePath));
155153
}
156-
mDataPath = mSettingsFields.getDataPath();
157154
if (mDataPath != null && !mDataPath.isEmpty()) {
158155
mDataPathTextView.setText(getFilenameFromPath(mDataPath));
159156
}
@@ -180,8 +177,8 @@ private void setupSettings() {
180177

181178
private void setupLoadModelButton() {
182179
mLoadModelButton = requireViewById(R.id.loadModelButton);
183-
// Disable by default until settings change
184-
mLoadModelButton.setEnabled(false);
180+
// Enable button if valid pre-filled paths are available from previous session
181+
updateLoadModelButtonState();
185182
mLoadModelButton.setOnClickListener(
186183
view -> {
187184
new AlertDialog.Builder(this)
@@ -520,9 +517,10 @@ private boolean hasSettingsChanged() {
520517
}
521518

522519
private void updateLoadModelButtonState() {
523-
boolean hasModelPath = mModelFilePath != null && !mModelFilePath.isEmpty();
524-
boolean hasTokenizerPath = mTokenizerFilePath != null && !mTokenizerFilePath.isEmpty();
525-
mLoadModelButton.setEnabled(hasSettingsChanged() && hasModelPath && hasTokenizerPath);
520+
// Enable button if settings changed OR if valid pre-filled paths are available
521+
boolean hasValidPaths = mModelFilePath != null && !mModelFilePath.isEmpty()
522+
&& mTokenizerFilePath != null && !mTokenizerFilePath.isEmpty();
523+
mLoadModelButton.setEnabled(hasSettingsChanged() || hasValidPaths);
526524
}
527525

528526
private void setBackendSettingMode() {

0 commit comments

Comments
 (0)