From e5a86455b5267ea11011b93cda34123d8f8f3a01 Mon Sep 17 00:00:00 2001 From: Siddartha Pothapragada Date: Sun, 24 May 2026 01:55:01 -0700 Subject: [PATCH 1/2] Fix LlamaDemo default temperature, lifecycle cleanup, and LLM memory support - Change DEFAULT_TEMPERATURE from 0.0 to 0.6 to prevent greedy decoding from hitting EOS token immediately on first generated token - Add onCleared() lifecycle handler to ChatViewModel for proper Module resource cleanup when ViewModel is destroyed - Update fbjni to 0.7.0 for main_exp AAR compatibility - Enable largeHeap in AndroidManifest for large LLM model support Authored with Claude. --- llm/android/LlamaDemo/app/build.gradle.kts | 2 +- llm/android/LlamaDemo/app/src/main/AndroidManifest.xml | 1 + .../java/com/example/executorchllamademo/ModuleSettings.kt | 2 +- .../executorchllamademo/ui/viewmodel/ChatViewModel.kt | 7 +++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/llm/android/LlamaDemo/app/build.gradle.kts b/llm/android/LlamaDemo/app/build.gradle.kts index 412f50b743..267064af39 100644 --- a/llm/android/LlamaDemo/app/build.gradle.kts +++ b/llm/android/LlamaDemo/app/build.gradle.kts @@ -268,7 +268,7 @@ dependencies { implementation("io.coil-kt:coil-compose:2.4.0") implementation("androidx.camera:camera-core:1.3.0") implementation("androidx.constraintlayout:constraintlayout:2.2.0") - implementation("com.facebook.fbjni:fbjni:0.5.1") + implementation("com.facebook.fbjni:fbjni:0.7.0") implementation("com.google.code.gson:gson:2.8.6") implementation("com.halilibo.compose-richtext:richtext-commonmark:1.0.0-alpha02") implementation("com.halilibo.compose-richtext:richtext-ui-material3:1.0.0-alpha02") diff --git a/llm/android/LlamaDemo/app/src/main/AndroidManifest.xml b/llm/android/LlamaDemo/app/src/main/AndroidManifest.xml index ecb2b52292..f9e4fc5316 100644 --- a/llm/android/LlamaDemo/app/src/main/AndroidManifest.xml +++ b/llm/android/LlamaDemo/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ m.close() } + loadedModules.clear() + } + init { // Check for clear chat history flag BEFORE loading saved messages val moduleSettings = demoSharedPreferences.getModuleSettings() From 6ffdd4a9ee981856a71ff9018783b6fdc360d571 Mon Sep 17 00:00:00 2001 From: Siddartha Pothapragada Date: Sun, 24 May 2026 16:19:58 -0700 Subject: [PATCH 2/2] Fix CI: remove onCleared (close() not in published AAR) and revert temperature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove onCleared() override — LlmModule.close() was added in the Kotlin conversion (#19211) but the published Maven AAR still ships the old Java version without it - Revert DEFAULT_TEMPERATURE to 0.0 — users can set temperature via the UI settings; no need to change the default Authored with Claude. --- .../java/com/example/executorchllamademo/ModuleSettings.kt | 2 +- .../executorchllamademo/ui/viewmodel/ChatViewModel.kt | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ModuleSettings.kt b/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ModuleSettings.kt index c6dc16985a..812d59053c 100644 --- a/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ModuleSettings.kt +++ b/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ModuleSettings.kt @@ -153,7 +153,7 @@ data class ModuleSettings( } companion object { - const val DEFAULT_TEMPERATURE = 0.6 + const val DEFAULT_TEMPERATURE = 0.0 val DEFAULT_MODEL = ModelType.LLAMA_3 val DEFAULT_BACKEND = BackendType.XNNPACK } diff --git a/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt b/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt index cf2179425b..3a1ccedbd9 100644 --- a/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt +++ b/llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt @@ -96,13 +96,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L private val executor: Executor = Executors.newSingleThreadExecutor() private val contentResolver = application.contentResolver - override fun onCleared() { - super.onCleared() - module?.close() - loadedModules.forEach { (_, m) -> m.close() } - loadedModules.clear() - } - init { // Check for clear chat history flag BEFORE loading saved messages val moduleSettings = demoSharedPreferences.getModuleSettings()