perf(compile-dag)!: alias weight constants, fail loudly on packed frozen params (#1247) - #1250
Merged
Merged
Conversation
…zen params (#1247) extractFloatArray copied every frozen float weight into the graph while the originals stayed live in the module tree and TraceSession — double residency that OOMed the Gemma 3n E2B export at a 46 GB heap. The constant now aliases the live buffer (documented read-only contract; the HLO serializer and inline emitters only read it). BF16/FP16 dense weights widen to one FP32 copy via copyToFloatArray, static shapes only. A frozen parameter with packed storage previously fell through to the 'input' placeholder branch, silently turning model weights into function arguments — an unservable module with exit 0 (the 190+-arg gemma3n export). finalize now throws PackedConstantException naming the tensor and encoding; PackedConstantHandling.DEQUANTIZE (new, threaded through toComputeGraph and the ExecutionTape extension) opts into dense FP32 dequant-on-extract via PackedBlockStorage.toFloatArray instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…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>
…-external-constants feat(compile-hlo): array-free external constants via BufferHandle.Floats, Long-safe sizing (#1247)
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
…1247) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ion' into feat/1247-graph-constant-extraction
…nstant-extraction # Conflicts: # CHANGELOG.md
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…nstant-extraction
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
2 similar comments
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
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 (defect 2:
extractFloatArraycopies every frozen weight into the graph — double residency, OOM at a 46 GB heap infinalize; defect 3: packed tensors silently become function arguments).extractFloatArrayreturns the liveFloatArrayTensorData.bufferaliased instead ofcopyOf()— the module tree andTraceSessionkeep the original alive for the whole build anyway, so the copy was pure double residency. Documented read-only contract oninitial_value/weights(verified: the HLO serializer and inline emitters only read).copyToFloatArray(static shapes only).PackedBlockStorage) no longer falls through to theinputplaceholder branch — that silently produced the 190+-arg unservable gemma3n module with exit 0.finalizenow throwsPackedConstantExceptionnaming the tensor and encoding; newPackedConstantHandling.DEQUANTIZE(threaded throughtoComputeGraphand theExecutionTapeextension) opts into dense FP32 dequant-on-extract viaPackedBlockStorage.toFloatArray. Genuine graph inputs (inputTensorIds, dynamic shapes, mapped storage) still synthesize inputs.Testing: new
ConstantExtractionTest— alias identity (initial_value === buffer), packed-FAIL message (tensor + encoding + remediation), packed-DEQUANTIZE values with encoding dropped, narrow-float widening, forced-input preservation. Full compile-dag + compile-hlo suites green.Verified against the gemma3n repro: full-E2B constant extraction completes under 46 GB (previously OOMed in exactly this code).