|
57 | 57 | import java.util.concurrent.Executors; |
58 | 58 | import org.json.JSONException; |
59 | 59 | import org.json.JSONObject; |
| 60 | +import org.pytorch.executorch.ExecutorchRuntimeException; |
60 | 61 | import org.pytorch.executorch.extension.llm.LlmCallback; |
61 | 62 | import org.pytorch.executorch.extension.llm.LlmModule; |
62 | 63 |
|
@@ -184,45 +185,46 @@ private void setLocalModel( |
184 | 185 | temperature, |
185 | 186 | dataPath); |
186 | 187 | } |
187 | | - int loadResult = mModule.load(); |
| 188 | + int loadResult = 0; |
188 | 189 | long loadDuration = System.currentTimeMillis() - runStartTime; |
189 | 190 | String modelLoadError = ""; |
190 | 191 | 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(); |
203 | 194 | String[] segments = modelPath.split("/"); |
204 | 195 | String pteName = segments[segments.length - 1]; |
205 | 196 | segments = tokenizerPath.split("/"); |
206 | 197 | String tokenizerName = segments[segments.length - 1]; |
207 | 198 | 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"; |
216 | 207 |
|
217 | 208 | if (mCurrentSettingsFields.getModelType() == ModelType.LLAVA_1_5) { |
218 | 209 | ETLogging.getInstance().log("Llava start prefill prompt"); |
219 | 210 | mModule.prefillPrompt(PromptFormat.getLlavaPresetPrompt()); |
220 | 211 | ETLogging.getInstance().log("Llava completes prefill prompt"); |
221 | 212 | } |
222 | | - } |
| 213 | + } catch (ExecutorchRuntimeException e) { |
| 214 | + modelInfo = e.getMessage() + "\n"; |
| 215 | + String errorLog = e.getDetailedError(); |
| 216 | + ETLogging.getInstance().log("Error while loading model " + errorLog); |
223 | 217 |
|
| 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 | + } |
224 | 227 | Message modelLoadedMessage = new Message(modelInfo, false, MessageType.SYSTEM, 0); |
225 | | - |
226 | 228 | String modelLoggingInfo = |
227 | 229 | modelLoadError |
228 | 230 | + "Model path: " |
|
0 commit comments