From ace9a45dc23f4afa06dfe288509e0ff04d840a15 Mon Sep 17 00:00:00 2001 From: Github Executorch Date: Tue, 9 Dec 2025 18:27:57 -0800 Subject: [PATCH] Summary: Add rich context and throw exceptions when LLMModule load fails to aid in debugging/triaging Test Plan: Reviewers: Subscribers: Tasks: Tags: --- extension/android/jni/jni_layer_llama.cpp | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/extension/android/jni/jni_layer_llama.cpp b/extension/android/jni/jni_layer_llama.cpp index 25873a788b5..d162d199703 100644 --- a/extension/android/jni/jni_layer_llama.cpp +++ b/extension/android/jni/jni_layer_llama.cpp @@ -23,6 +23,8 @@ #include #include +#include + #if defined(ET_USE_THREADPOOL) #include #include @@ -404,12 +406,29 @@ class ExecuTorchLlmJni : public facebook::jni::HybridClass { } jint load() { + int result = -1; + std::stringstream ss; + if (model_type_category_ == MODEL_TYPE_CATEGORY_MULTIMODAL) { - return static_cast(multi_modal_runner_->load()); + result = static_cast(multi_modal_runner_->load()); + if (result != 0) { + ss << "Failed to load multimodal runner: [" << result << "]"; + } } else if (model_type_category_ == MODEL_TYPE_CATEGORY_LLM) { - return static_cast(runner_->load()); + result = static_cast(runner_->load()); + if (result != 0) { + ss << "Failed to load llm runner: [" << result << "]"; + } + } else { + ss << "Invalid model type category: " << model_type_category_ + << ". Valid values are: " << MODEL_TYPE_CATEGORY_LLM << " or " + << MODEL_TYPE_CATEGORY_MULTIMODAL; + } + if (result != 0) { + executorch::jni_helper::throwExecutorchException( + static_cast(Error::InvalidArgument), ss.str().c_str()); } - return static_cast(Error::InvalidArgument); + return result; // 0 on success to keep backward compatibility } static void registerNatives() {