Skip to content

Commit ace9a45

Browse files
author
Github Executorch
committed
Summary: Add rich context and throw exceptions when LLMModule load fails to aid in debugging/triaging
Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 8511b30 commit ace9a45

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

extension/android/jni/jni_layer_llama.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <executorch/runtime/platform/platform.h>
2424
#include <executorch/runtime/platform/runtime.h>
2525

26+
#include <executorch/extension/android/jni/jni_helper.h>
27+
2628
#if defined(ET_USE_THREADPOOL)
2729
#include <executorch/extension/threadpool/cpuinfo_utils.h>
2830
#include <executorch/extension/threadpool/threadpool.h>
@@ -404,12 +406,29 @@ class ExecuTorchLlmJni : public facebook::jni::HybridClass<ExecuTorchLlmJni> {
404406
}
405407

406408
jint load() {
409+
int result = -1;
410+
std::stringstream ss;
411+
407412
if (model_type_category_ == MODEL_TYPE_CATEGORY_MULTIMODAL) {
408-
return static_cast<jint>(multi_modal_runner_->load());
413+
result = static_cast<jint>(multi_modal_runner_->load());
414+
if (result != 0) {
415+
ss << "Failed to load multimodal runner: [" << result << "]";
416+
}
409417
} else if (model_type_category_ == MODEL_TYPE_CATEGORY_LLM) {
410-
return static_cast<jint>(runner_->load());
418+
result = static_cast<jint>(runner_->load());
419+
if (result != 0) {
420+
ss << "Failed to load llm runner: [" << result << "]";
421+
}
422+
} else {
423+
ss << "Invalid model type category: " << model_type_category_
424+
<< ". Valid values are: " << MODEL_TYPE_CATEGORY_LLM << " or "
425+
<< MODEL_TYPE_CATEGORY_MULTIMODAL;
426+
}
427+
if (result != 0) {
428+
executorch::jni_helper::throwExecutorchException(
429+
static_cast<uint32_t>(Error::InvalidArgument), ss.str().c_str());
411430
}
412-
return static_cast<jint>(Error::InvalidArgument);
431+
return result; // 0 on success to keep backward compatibility
413432
}
414433

415434
static void registerNatives() {

0 commit comments

Comments
 (0)