Skip to content

functiongemma export: write externals from any BufferHandle (Owned or Floats) — fixes #405 - #414

Merged
michalharakal merged 2 commits into
developfrom
functiongemma-export-floats-cast
Sep 4, 2026
Merged

michalharakal merged 2 commits into
developfrom
functiongemma-export-floats-cast

Conversation

@michalharakal

@michalharakal michalharakal commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #405.

FunctionGemmaExportHarness.writeSafetensors and writeQuantizedSafetensors cast every external to BufferHandle.Owned; with the 0.53.0 engine loader the large constants (the 262144×640 tied embedding) arrive as BufferHandle.Floats, so every FunctionGemmaExportCli run died with ClassCastException: BufferHandle$Floats cannot be cast to BufferHandle$Owned — the cast #396 removed from the Gemma 3n harness was still here.

Change

  • writeHandle(os, handle, bf16): streams any handle as raw f32 or truncating bf16 (core parity) in 1 MiB chunks, dispatching on the subtype.
  • ownedBytes(handle): little-endian bytes + base offset for the quantizer, which reads rows by byte offset (a Floats handle is materialised once).
  • Behaviour for Owned handles is byte-identical to before.

Verification

  • :llm-inference:functiongemma:compileKotlinJvm green.
  • Exported FunctionGemma-270M redecode/prefill/with-past graphs (SEQ 64 and 1024, FP32 and INT8) with the CLI; the arm32 build of the redecode graph is byte-identical to the host oracle on an arm32 Android device (ids [32691, 10492, 23688, 6824, …]).

… Floats) — fixes the ClassCastException on the 0.53.0 engine loader (#405)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…rt-floats-cast

# Conflicts:
#	llm-inference/functiongemma/src/jvmMain/kotlin/sk/ainet/models/functiongemma/FunctionGemmaExportHarness.kt
@michalharakal
michalharakal merged commit fc234e6 into develop Sep 4, 2026
1 of 2 checks passed
@michalharakal
michalharakal deleted the functiongemma-export-floats-cast branch September 4, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

functiongemma export: writeSafetensors casts every external to BufferHandle.Owned — ClassCastException on BufferHandle.Floats with engine 0.53.0

1 participant