Port FunctionGemma's eager facade to androidNativeArm32 - #319
Merged
Merged
Conversation
Ports FunctionGemma.kt's eager facade (fromGguf().call()) to a target that didn't exist before: androidNativeArm32. Same gemmaNetwork() DSL, DirectCpuExecutionContext, chat template, and tool-call parser as every other path — only the file-access layer differs (createRandomAccessSource + SystemFileSystem/kotlinx-io instead of JvmRandomAccessSource/java.io). Needed androidNativeArm32 added to llm-inference:gemma and llm-runtime:gemma-iree first (both had it missing entirely). CLI entry point lives in its own package (cli.android, not cli) so it doesn't collide with the existing nativeMain stub shared by linux/macos. Board-verified on the actual device (SKaiNET-functiongemma's docs/DEVICE-BRINGUP.md): linked ELF 32-bit ARM EABI5 executable, real 260MB checkpoint, correct output (set_lights), no host involvement at runtime. Eager throughput is a known, root-caused separate gap (DIRECT mode cost + a graph-tracing bug in OPTIMIZED mode) — not blocking here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NativeFunctionGemma(llm-runtime:kgemma,androidNativeArm32Main) — same contract as the existing JVMFunctionGemma.fromGguf(path).call(text), samegemmaNetwork()DSL /DirectCpuExecutionContext/ chat template / tool-call parser. Only the file-access layer differs:createRandomAccessSource+SystemFileSystem/kotlinx-io instead ofJvmRandomAccessSource/java.io.File.cli.android, notcli) so it doesn't collide with the existingnativeMainstub shared by the linux/macos targets (that one stays a stub, unchanged — this is additive).llm-inference:gemmaandllm-runtime:gemma-ireeneededandroidNativeArm32added — neither had it at all (onlyllm-inference:functiongemma's host-only export tooling is not pulled in here; that's compile-leg, out of scope for an on-device eager binary).-PuseLocalSkainet=trueagainst that branch to build this one until it's merged/released).Verified on real hardware
Linked a genuine
ELF 32-bit ARM EABI5executable, pushed it + a real 260 MB FunctionGemma-270M checkpoint to the actual device (no Docker, no IREE, no host involvement at runtime beyondadb push/shell), ran it standalone:Correct. Full writeup incl. a follow-up perf investigation (root-caused why it takes ~35 min:
DIRECTmode's inherent cost + a separate, real bug inOPTIMIZEDmode's graph tracing for this model —Node 'n1_mulScalar' has 0 outputs but index 0 was requested, reproduces on JVM/x64,llm-core, not filed/fixed in this PR): https://github.com/... (SKaiNET-functiongemma's docs/DEVICE-BRINGUP.md, private repo).Test plan
:llm-runtime:kgemma:compileKotlinAndroidNativeArm32— compiles clean:llm-runtime:kgemma:linkReleaseExecutableAndroidNativeArm32— links a real binaryllm-inference:gemma,llm-runtime:gemma-iree,llm-runtime:kgemma) still compiles — no regressions