Skip to content

docs: add Kotlin examples and fix MULTIMODAL alias note for Android LLM runner#20147

Open
omkar-334 wants to merge 4 commits into
pytorch:mainfrom
omkar-334:docs-android-kotlin
Open

docs: add Kotlin examples and fix MULTIMODAL alias note for Android LLM runner#20147
omkar-334 wants to merge 4 commits into
pytorch:mainfrom
omkar-334:docs-android-kotlin

Conversation

@omkar-334

@omkar-334 omkar-334 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow up to #8790, #19611 (comment)

  1. Added Kotlin snippets next to every Java block in docs/source/llm/run-on-android.md. Same shape as run-on-ios.md, with a Language: label paragraph above each fenced block (no tab-set). Covers imports, the simple LlmModule constructor, the LlmModuleConfig builder, load, the LlmCallback object expression, LlmGenerationConfig, stop, resetContext, image prefill (IntArray / ByteBuffer / FloatArray), prefillNormalizedImage, prefillAudio, prefillRawAudio, and the multimodal generate overload. Uses idiomatic Kotlin (object : LlmCallback, IntArray/FloatArray, Float.SIZE_BYTES, ByteBuffer.apply { ... }, trailing commas).

  2. Reworded the available-model-types sentence so it no longer lists MODEL_TYPE_MULTIMODAL as a separate type. Both constants share the value 2 in LlmModuleConfig.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

omkar-334 added 2 commits June 9, 2026 16:38
…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).
Copilot AI review requested due to automatic review settings June 9, 2026 12:43
@omkar-334 omkar-334 requested a review from mergennachin as a code owner June 9, 2026 12:43
@pytorch-bot

pytorch-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🔗 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.

⚠️ 12 Awaiting Approval

As of commit 87694e9 with merge base ceda793 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 9, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 9, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@github-actions github-actions Bot added docathon-2026 medium Medium Difficulty for issues as part of PyTorch Docathon H1 2026 module: doc Issues related to documentation, both in docs/ and inlined in code module: llm Issues related to LLM examples and apps, and to the extensions/llm/ code module: user experience Issues related to reducing friction for users triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_MULTIMODAL behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/source/llm/run-on-android.md
Comment on lines +53 to +57
val module = LlmModule(
"/data/local/tmp/llama-3.2-instruct.pte",
"/data/local/tmp/tokenizer.model",
0.8f,
)
Comment on lines +250 to +253
val buffer = ByteBuffer.allocateDirect(3 * 336 * 336).apply {
put(rawBytes)
rewind()
}
Comment on lines +276 to +278
val floatBuffer: ByteBuffer = ByteBuffer
.allocateDirect(3 * 336 * 336 * Float.SIZE_BYTES)
.order(ByteOrder.nativeOrder())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add import java.nio.ByteBuffer and import java.nio.ByteOrder stmt ?

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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.
Comment on lines +276 to +278
val floatBuffer: ByteBuffer = ByteBuffer
.allocateDirect(3 * 336 * 336 * Float.SIZE_BYTES)
.order(ByteOrder.nativeOrder())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add import java.nio.ByteBuffer and import java.nio.ByteOrder stmt ?

Copilot AI review requested due to automatic review settings June 10, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

import java.nio.ByteOrder
```

### LlmModule
@@ -139,6 +236,7 @@ For models declared as `MODEL_TYPE_TEXT_VISION` or `MODEL_TYPE_MULTIMODAL`, imag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. docathon-2026 medium Medium Difficulty for issues as part of PyTorch Docathon H1 2026 module: doc Issues related to documentation, both in docs/ and inlined in code module: llm Issues related to LLM examples and apps, and to the extensions/llm/ code module: user experience Issues related to reducing friction for users triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants