[RFC][Android] Consolidate LlmModule constructor and generate() overloads
@mergennachin is already working on this.
Since Feb 23, 2026.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
🐛 Describe the bug
Problem
LlmModule has 8 constructors and 10 generate() overloads. A codebase-wide search (executorch + executorch-examples) shows most are unused.
Constructors — 4 of 8 have zero call sites
| Constructor | Call sites |
|---|---|
(String, String, float) |
3 (benchmark, instrumentation test, sanity check) |
(int, String, String, float) |
1 (LlamaDemo, no dataPath) |
(int, String, String, float, String) |
1 (LlamaDemo, with dataPath) |
(int, String, String, float, List<String>) |
2 (LlamaDemo LoRA) |
(int, String, String, float, List<String>, int, int) |
0 (only internal delegate target) |
(int, String, String, float, String, int, int) |
0 |
(String, String, float, String) |
0 |
(LlmModuleConfig) |
0 |
generate() — 7 of 10 have zero call sites
| Overload | Call sites |
|---|---|
(String, LlmCallback) |
2 |
(String, int, LlmCallback) |
2 |
(String, int, LlmCallback, boolean) |
4 |
(String, LlmCallback, boolean) |
0 |
(String, int, LlmCallback, boolean, float, int, int) |
0 (native JNI entry, only internal) |
(String, LlmGenerationConfig, LlmCallback) |
0 |
All 4 image (int[], int, int, int, String, ...) variants |
0 (image input now goes through prefillImages() + text-only generate()) |
LlmModuleConfig and LlmGenerationConfig builder classes exist but neither is used anywhere — all callers use the direct constructors/overloads instead.
Proposal
Phase 1: Deprecate and redirect
-
Keep one constructor:
LlmModule(LlmModuleConfig). Deprecate all others with@Deprecatedpointing to the config builder. -
Keep two generate() signatures:
generate(String prompt, LlmGenerationConfig config, LlmCallback callback)— the config-based entry pointgenerate(String prompt, int seqLen, LlmCallback callback, boolean echo, float temperature, int numBos, int numEos)— the native JNI method (package-private or private)
Deprecate all other
generate()overloads. -
Remove all image-based generate() overloads — they are dead code. Multimodal input already uses the
prefillImages()/prefillAudio()/prefillPrompt()→generate()flow. -
Fix
LlmModuleConfig.getDataPath()to returnList<String>instead ofString, matching what the constructor actually needs. -
Deduplicate model type constants — remove
MODEL_TYPE_*fromLlmModule, keep only inLlmModuleConfig.
Phase 2: Remove (next release)
Remove all deprecated overloads.
Migration
All existing call sites migrate to:
// Before
LlmModule module = new LlmModule(MODEL_TYPE_TEXT, modelPath, tokenizerPath, 0.8f);
module.generate(prompt, seqLen, callback, false);
// After
LlmModule module = new LlmModule(
LlmModuleConfig.create()
.modulePath(modelPath)
.tokenizerPath(tokenizerPath)
.temperature(0.8f)
.build());
module.generate(prompt, LlmGenerationConfig.create()
.seqLen(seqLen)
.echo(false)
.build(), callback);
Compatibility
LlmModule is annotated @Experimental ("subject to change without notice"), so breaking changes are acceptable. A deprecation phase is still recommended since external apps may use these APIs.
Scope
Java-only change. No JNI or C++ changes needed — the single native generate() method stays as-is.
Versions
0d9799f
cc @cbilgin
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.