Skip to content

Commit 8b5caf0

Browse files
psiddhGithub Executorch
andauthored
Add detailed error / context logs & info in thr event of LLMModule load failures (#118)
- adb logcat to capture extra verbose detailed errors - Dilaog to show useful error information Co-authored-by: Github Executorch <github_executorch@arm.com>
1 parent 9d0db45 commit 8b5caf0

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

  • llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.concurrent.Executors;
5858
import org.json.JSONException;
5959
import org.json.JSONObject;
60+
import org.pytorch.executorch.ExecutorchRuntimeException;
6061
import org.pytorch.executorch.extension.llm.LlmCallback;
6162
import org.pytorch.executorch.extension.llm.LlmModule;
6263

@@ -184,45 +185,46 @@ private void setLocalModel(
184185
temperature,
185186
dataPath);
186187
}
187-
int loadResult = mModule.load();
188+
int loadResult = 0;
188189
long loadDuration = System.currentTimeMillis() - runStartTime;
189190
String modelLoadError = "";
190191
String modelInfo = "";
191-
if (loadResult != 0) {
192-
// TODO: Map the error code to a reason to let the user know why model loading failed
193-
modelInfo = "*Model could not load (Error Code: " + loadResult + ")*" + "\n";
194-
loadDuration = 0;
195-
AlertDialog.Builder builder = new AlertDialog.Builder(this);
196-
builder.setTitle("Load failed: " + loadResult);
197-
runOnUiThread(
198-
() -> {
199-
AlertDialog alert = builder.create();
200-
alert.show();
201-
});
202-
} else {
192+
try {
193+
loadResult = mModule.load();
203194
String[] segments = modelPath.split("/");
204195
String pteName = segments[segments.length - 1];
205196
segments = tokenizerPath.split("/");
206197
String tokenizerName = segments[segments.length - 1];
207198
modelInfo =
208-
"Successfully loaded model. "
209-
+ pteName
210-
+ " and tokenizer "
211-
+ tokenizerName
212-
+ " in "
213-
+ (float) loadDuration / 1000
214-
+ " sec."
215-
+ " You can send text or image for inference";
199+
"Successfully loaded model. "
200+
+ pteName
201+
+ " and tokenizer "
202+
+ tokenizerName
203+
+ " in "
204+
+ (float) loadDuration / 1000
205+
+ " sec."
206+
+ " You can send text or image for inference";
216207

217208
if (mCurrentSettingsFields.getModelType() == ModelType.LLAVA_1_5) {
218209
ETLogging.getInstance().log("Llava start prefill prompt");
219210
mModule.prefillPrompt(PromptFormat.getLlavaPresetPrompt());
220211
ETLogging.getInstance().log("Llava completes prefill prompt");
221212
}
222-
}
213+
} catch (ExecutorchRuntimeException e) {
214+
modelInfo = e.getMessage() + "\n";
215+
String errorLog = e.getDetailedError();
216+
ETLogging.getInstance().log("Error while loading model " + errorLog);
223217

218+
loadDuration = 0;
219+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
220+
builder.setTitle("Model Load failure: " + modelInfo);
221+
runOnUiThread(
222+
() -> {
223+
AlertDialog alert = builder.create();
224+
alert.show();
225+
});
226+
}
224227
Message modelLoadedMessage = new Message(modelInfo, false, MessageType.SYSTEM, 0);
225-
226228
String modelLoggingInfo =
227229
modelLoadError
228230
+ "Model path: "

0 commit comments

Comments
 (0)