docs: add Kotlin examples and fix MULTIMODAL alias note for Android LLM runner#20147
docs: add Kotlin examples and fix MULTIMODAL alias note for Android LLM runner#20147omkar-334 wants to merge 4 commits into
Conversation
…ISION Both constants share the same value (2) in LlmModuleConfig.java, so listing them as separate model types implied behavior that does not exist. Reword the available-model-types sentence to drop the misleading third entry and note the alias explicitly. Flagged on the original PR (pytorch#19611).
Mirrors the Java snippets in run-on-android.md with idiomatic Kotlin
equivalents (object expression for the LlmCallback, IntArray/FloatArray
for primitive arrays, Float.SIZE_BYTES, ByteBuffer.apply { ... },
trailing commas on multi-line calls). Follows the run-on-ios.md
convention of putting a language label above each fenced block rather
than tab-sets.
Requested in review on the original PR (pytorch#19611).
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20147
Note: Links to docs will display an error until the docs builds have been completed.
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Kotlin equivalents to the Android LLM runner documentation so readers can use the LlmModule API from either Java or Kotlin.
Changes:
- Added side-by-side Java/Kotlin snippets for imports, module construction, load/generate/stop/reset.
- Added Kotlin examples for multimodal prefill (images/audio) and combined image+prompt generation.
- Updated the text around model types to clarify
MODEL_TYPE_MULTIMODALbehavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val module = LlmModule( | ||
| "/data/local/tmp/llama-3.2-instruct.pte", | ||
| "/data/local/tmp/tokenizer.model", | ||
| 0.8f, | ||
| ) |
| val buffer = ByteBuffer.allocateDirect(3 * 336 * 336).apply { | ||
| put(rawBytes) | ||
| rewind() | ||
| } |
| val floatBuffer: ByteBuffer = ByteBuffer | ||
| .allocateDirect(3 * 336 * 336 * Float.SIZE_BYTES) | ||
| .order(ByteOrder.nativeOrder()) |
There was a problem hiding this comment.
Better to add import java.nio.ByteBuffer and import java.nio.ByteOrder stmt ?
This PR needs a
|
Address review feedback on the Android LLM runner page: * Add java.nio.ByteBuffer and java.nio.ByteOrder to the Java and Kotlin import blocks (with a one-line note that they are only used by the multimodal ByteBuffer paths), so the snippets in the Images section compile when copy-pasted. * Show floatBuffer.rewind() before prefillNormalizedImage in both the Java and Kotlin examples, matching the int-buffer example above and removing the asymmetry called out in review.
| val floatBuffer: ByteBuffer = ByteBuffer | ||
| .allocateDirect(3 * 336 * 336 * Float.SIZE_BYTES) | ||
| .order(ByteOrder.nativeOrder()) |
There was a problem hiding this comment.
Better to add import java.nio.ByteBuffer and import java.nio.ByteOrder stmt ?
| import java.nio.ByteOrder | ||
| ``` | ||
|
|
||
| ### LlmModule |
| @@ -139,6 +236,7 @@ For models declared as `MODEL_TYPE_TEXT_VISION` or `MODEL_TYPE_MULTIMODAL`, imag | |||
|
|
|||
Summary
Follow up to #8790, #19611 (comment)
Added Kotlin snippets next to every Java block in
docs/source/llm/run-on-android.md. Same shape asrun-on-ios.md, with aLanguage:label paragraph above each fenced block (no tab-set). Covers imports, the simpleLlmModuleconstructor, theLlmModuleConfigbuilder,load, theLlmCallbackobject expression,LlmGenerationConfig,stop,resetContext, image prefill (IntArray/ByteBuffer/FloatArray),prefillNormalizedImage,prefillAudio,prefillRawAudio, and the multimodalgenerateoverload. Uses idiomatic Kotlin (object : LlmCallback,IntArray/FloatArray,Float.SIZE_BYTES,ByteBuffer.apply { ... }, trailing commas).Reworded the available-model-types sentence so it no longer lists
MODEL_TYPE_MULTIMODALas a separate type. Both constants share the value2inLlmModuleConfig.java:53,56, so listing them implied behavior that does not exist. The new sentence notes the alias explicitly.cc @mergennachin @nil-is-all @larryliu0820 @cccclai @helunwencser @jackzhxng @digantdesai @byjlw