Skip to content

Commit e5a8645

Browse files
committed
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.
1 parent c947b03 commit e5a8645

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

llm/android/LlamaDemo/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ dependencies {
268268
implementation("io.coil-kt:coil-compose:2.4.0")
269269
implementation("androidx.camera:camera-core:1.3.0")
270270
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
271-
implementation("com.facebook.fbjni:fbjni:0.5.1")
271+
implementation("com.facebook.fbjni:fbjni:0.7.0")
272272
implementation("com.google.code.gson:gson:2.8.6")
273273
implementation("com.halilibo.compose-richtext:richtext-commonmark:1.0.0-alpha02")
274274
implementation("com.halilibo.compose-richtext:richtext-ui-material3:1.0.0-alpha02")

llm/android/LlamaDemo/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<application
1313
android:name=".ETLogging"
1414
android:allowBackup="false"
15+
android:largeHeap="true"
1516
android:dataExtractionRules="@xml/data_extraction_rules"
1617
android:fullBackupContent="@xml/backup_rules"
1718
android:icon="@drawable/logo"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ data class ModuleSettings(
153153
}
154154

155155
companion object {
156-
const val DEFAULT_TEMPERATURE = 0.0
156+
const val DEFAULT_TEMPERATURE = 0.6
157157
val DEFAULT_MODEL = ModelType.LLAMA_3
158158
val DEFAULT_BACKEND = BackendType.XNNPACK
159159
}

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
9696
private val executor: Executor = Executors.newSingleThreadExecutor()
9797
private val contentResolver = application.contentResolver
9898

99+
override fun onCleared() {
100+
super.onCleared()
101+
module?.close()
102+
loadedModules.forEach { (_, m) -> m.close() }
103+
loadedModules.clear()
104+
}
105+
99106
init {
100107
// Check for clear chat history flag BEFORE loading saved messages
101108
val moduleSettings = demoSharedPreferences.getModuleSettings()

0 commit comments

Comments
 (0)