Skip to content

Commit fe90c33

Browse files
committed
Revert "[Android] Enable multi-model selection and fix Gemma image prefill"
This reverts commit 4ccc896.
1 parent 5eb4773 commit fe90c33

5 files changed

Lines changed: 11 additions & 89 deletions

File tree

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
@@ -12,7 +12,7 @@ package com.example.executorchllamademo
1212
* Holds module-specific settings for the current model/tokenizer configuration.
1313
*/
1414
data class ModuleSettings(
15-
val modelFilePath: List<String> = emptyList(),
15+
val modelFilePath: String = "",
1616
val tokenizerFilePath: String = "",
1717
val dataPath: String = "",
1818
val temperature: Double = DEFAULT_TEMPERATURE,

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,6 @@ object PromptFormat {
9393
return "USER: $USER_PLACEHOLDER ASSISTANT:"
9494
}
9595

96-
@JvmStatic
97-
fun getGemmaPreImagePrompt(): String {
98-
return "<start_of_turn>user\n"
99-
}
100-
101-
@JvmStatic
102-
fun getGemmaPostImagePrompt(): String {
103-
return "<end_of_image>"
104-
}
105-
106-
@JvmStatic
107-
fun getGemmaMultimodalUserPrompt(): String {
108-
return "$USER_PLACEHOLDER<end_of_turn>\n<start_of_turn>model"
109-
}
110-
11196
@JvmStatic
11297
fun getFormattedLlamaGuardPrompt(userPrompt: String): String {
11398
return getUserPromptTemplate(ModelType.LLAMA_GUARD_3)

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/screens/ModelSettingsScreen.kt

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,12 @@ private fun ModelDialog(viewModel: ModelSettingsViewModel) {
439439
}
440440
)
441441
} else {
442-
MultiChoiceDialog(
442+
SingleChoiceDialog(
443443
title = "Select model path",
444444
options = viewModel.modelFiles.toList(),
445-
selectedOptions = viewModel.moduleSettings.modelFilePath,
446445
onSelect = { selected ->
447-
viewModel.toggleModel(selected)
446+
viewModel.selectModel(selected)
447+
viewModel.showModelDialog = false
448448
},
449449
onDismiss = { viewModel.showModelDialog = false }
450450
)
@@ -658,51 +658,6 @@ private fun InvalidPromptDialog(viewModel: ModelSettingsViewModel) {
658658
}
659659
}
660660

661-
@Composable
662-
private fun MultiChoiceDialog(
663-
title: String,
664-
options: List<String>,
665-
selectedOptions: List<String>,
666-
onSelect: (String) -> Unit,
667-
onDismiss: () -> Unit
668-
) {
669-
AlertDialog(
670-
onDismissRequest = onDismiss,
671-
title = { Text(title) },
672-
text = {
673-
Column {
674-
options.forEach { option ->
675-
val isSelected = selectedOptions.contains(option)
676-
Row(
677-
modifier = Modifier
678-
.fillMaxWidth()
679-
.clickable { onSelect(option) }
680-
.padding(vertical = 8.dp),
681-
verticalAlignment = Alignment.CenterVertically
682-
) {
683-
androidx.compose.material3.Checkbox(
684-
checked = isSelected,
685-
onCheckedChange = { onSelect(option) }
686-
)
687-
Text(
688-
text = option.substringAfterLast('/'),
689-
modifier = Modifier
690-
.padding(start = 8.dp)
691-
.weight(1f),
692-
fontSize = 14.sp
693-
)
694-
}
695-
}
696-
}
697-
},
698-
confirmButton = {
699-
TextButton(onClick = onDismiss) {
700-
Text("Done")
701-
}
702-
}
703-
)
704-
}
705-
706661
@Composable
707662
private fun SingleChoiceDialog(
708663
title: String,

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,22 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
185185
}
186186

187187
private fun loadLocalModelAndParameters(
188-
modelFilePaths: List<String>,
188+
modelFilePath: String,
189189
tokenizerFilePath: String,
190190
dataPath: String,
191191
temperature: Float
192192
) {
193193
Thread {
194-
setLocalModel(modelFilePaths, tokenizerFilePath, dataPath, temperature)
194+
setLocalModel(modelFilePath, tokenizerFilePath, dataPath, temperature)
195195
}.start()
196196
}
197197

198198
private fun setLocalModel(
199-
modelPaths: List<String>,
199+
modelPath: String,
200200
tokenizerPath: String,
201201
dataPath: String,
202202
temperature: Float
203203
) {
204-
val modelPath = modelPaths.joinToString(separator = ",")
205204
val modelLoadingMessage = Message("Loading model...", false, MessageType.SYSTEM, 0)
206205
ETLogging.getInstance().log(
207206
"Loading model $modelPath with tokenizer $tokenizerPath data path $dataPath"
@@ -346,7 +345,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
346345
img.height,
347346
ModelUtils.VISION_MODEL_IMAGE_CHANNELS
348347
)
349-
module?.prefillPrompt(PromptFormat.getGemmaPostImagePrompt())
350348
}
351349
}
352350
}
@@ -387,9 +385,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
387385
} else if (currentSettingsFields.modelType == ModelType.GEMMA_3 && _selectedImages.isNotEmpty()) {
388386
finalPrompt = PromptFormat.getGemmaMultimodalUserPrompt()
389387
.replace(PromptFormat.USER_PLACEHOLDER, rawPrompt)
390-
} else if (currentSettingsFields.modelType == ModelType.GEMMA_3 && _selectedImages.isNotEmpty()) {
391-
finalPrompt = PromptFormat.getGemmaMultimodalUserPrompt()
392-
.replace(PromptFormat.USER_PLACEHOLDER, rawPrompt)
393388
} else {
394389
finalPrompt = (if (shouldAddSystemPrompt) currentSettingsFields.getFormattedSystemPrompt() else "") +
395390
currentSettingsFields.getFormattedUserPrompt(rawPrompt, thinkMode)

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ModelSettingsViewModel : ViewModel() {
8686
private fun applyBackendDefaults(settings: ModuleSettings): ModuleSettings {
8787
return if (settings.backendType == BackendType.MEDIATEK) {
8888
settings.copy(
89-
modelFilePath = if (settings.modelFilePath.isEmpty()) listOf("/in/mtk/llama/runner") else settings.modelFilePath,
89+
modelFilePath = settings.modelFilePath.ifEmpty { "/in/mtk/llama/runner" },
9090
tokenizerFilePath = settings.tokenizerFilePath.ifEmpty { "/in/mtk/llama/runner" }
9191
)
9292
} else {
@@ -95,18 +95,9 @@ class ModelSettingsViewModel : ViewModel() {
9595
}
9696

9797
// Model selection
98-
fun toggleModel(modelPath: String) {
99-
val currentModels = moduleSettings.modelFilePath.toMutableList()
100-
if (currentModels.contains(modelPath)) {
101-
currentModels.remove(modelPath)
102-
} else {
103-
currentModels.add(modelPath)
104-
}
105-
var newSettings = moduleSettings.copy(modelFilePath = currentModels)
106-
// Auto-select type based on the last added model or the first one
107-
if (currentModels.isNotEmpty()) {
108-
newSettings = autoSelectModelType(newSettings, modelPath)
109-
}
98+
fun selectModel(modelPath: String) {
99+
var newSettings = moduleSettings.copy(modelFilePath = modelPath)
100+
newSettings = autoSelectModelType(newSettings, modelPath)
110101
moduleSettings = newSettings
111102
}
112103

@@ -202,10 +193,6 @@ class ModelSettingsViewModel : ViewModel() {
202193
return if (path.isEmpty()) "" else path.substringAfterLast('/')
203194
}
204195

205-
fun getFilenameFromPath(paths: List<String>): String {
206-
return if (paths.isEmpty()) "" else paths.joinToString(", ") { it.substringAfterLast('/') }
207-
}
208-
209196
// Appearance mode selection (app-wide setting)
210197
fun selectAppearanceMode(mode: AppearanceMode) {
211198
appSettings = appSettings.copy(appearanceMode = mode)

0 commit comments

Comments
 (0)