feat(compile-hlo): array-free external constants via BufferHandle.Floats, Long-safe sizing (#1247) - #1251
Merged
michalharakal merged 1 commit intoSep 2, 2026
Conversation
…ats, Long-safe sizing (#1247) The gemma3n tied embedding is 262144 x 2048 FP32 = Int.MAX_VALUE + 1 bytes: one byte over the JVM single-array ceiling, so no widening of the previous ByteArray round-trip could ever emit it. External FP32 constants now hand the aliased FloatArray straight to the packager as BufferHandle.Floats — zero copies from module weight to .irpa — with IrpaWriter streaming the values little-endian in 64 MiB chunks and DefaultBufferResolver reading through a chunked byte view. Constant element counts fold in Long (an Int fold of the embedding's byte count went negative, surfacing as NegativeArraySizeException inside the serializer and mistaken for a registry miss - the misleading "Unsupported op 'weight' ... Known names" comment). Oversized single-buffer serialization now throws ConstantTooLargeException with the remediation; deliberately not an IllegalArgumentException, so the converter's inline-emission fallback cannot catch it and try to format a multi-GiB tensor as text. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
michalharakal
merged commit Sep 2, 2026
d1f52a6
into
feat/1247-graph-constant-extraction
2 checks passed
This was referenced Sep 2, 2026
Merged
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.
Part of #1247. Stacked on #1250 (needs the aliased
FloatArrayreaching the converter) — after #1250 merges, this retargets todevelop.Root cause found while implementing: the gemma3n tied embedding is 262144 × 2048 FP32 =
Int.MAX_VALUE+ 1 bytes — one byte over the JVM single-array ceiling.ByteArray(count * 4)overflowed to a negative size, and the resultingNegativeArraySizeExceptionescaped into the converter's generic catch, producing the misleadingUnsupported op 'weight' … Known names: […]comment the issue quotes. No widening of the byte round-trip could ever emit this tensor; the external path must be array-free.BufferHandle.Floats(FloatArray)(lang-core): FP32 logical values as a primitive array — up to 2 Gi elements / 8 GiB logical, read-only, typically aliasing the live module weight.DefaultBufferResolverreads it through a chunked little-endian byte view;describelabels it.ConstantOperationsConverterhand the aliased array to the packager asFloatswith no byte serialization — zero copies from module weight to archive. Non-FP32 / under-filled values keep the padded byte path.IrpaWriterstreamsFloatslittle-endian in 64 MiB chunks — byte-identical output to the eagerOwnedserialization (parity-tested).elementCountFromShapefolds inLong; oversized single-buffer serialization throwsConstantTooLargeExceptionwith the remediation — deliberately notIllegalArgumentException, so the inline-emission fallback can't catch it and try to format a multi-GiB tensor as text.Testing: new
BigConstantMaterializationTest(Long fold incl. the exact embedding count, overflow refusal,Floatsidentity-aliasing with zero serialization, tied-weight → oneutil.global) +IrpaFloatsParityTest. lang-core / compile-hlo / iree-params suites green; apiDumps updated.Note for consumers: exhaustive
whens overBufferHandlegain a branch — in-repo consumers are updated here; SKaiNET-transformers'Gemma3nExportHarness.writeSafetensorsneeds aFloatsbranch (chunked bf16 streaming) once this ships.