Skip to content

perf(compile-dag)!: alias weight constants, fail loudly on packed frozen params (#1247) - #1250

Merged
michalharakal merged 8 commits into
developfrom
feat/1247-graph-constant-extraction
Sep 2, 2026
Merged

michalharakal merged 8 commits into
developfrom
feat/1247-graph-constant-extraction

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Part of #1247 (defect 2: extractFloatArray copies every frozen weight into the graph — double residency, OOM at a 46 GB heap in finalize; defect 3: packed tensors silently become function arguments).

  • extractFloatArray returns the live FloatArrayTensorData.buffer aliased instead of copyOf() — the module tree and TraceSession keep the original alive for the whole build anyway, so the copy was pure double residency. Documented read-only contract on initial_value/weights (verified: the HLO serializer and inline emitters only read).
  • BF16/FP16 dense weights widen to one FP32 copy via copyToFloatArray (static shapes only).
  • A frozen parameter with packed storage (PackedBlockStorage) no longer falls through to the input placeholder branch — that silently produced the 190+-arg unservable gemma3n module with exit 0. finalize now throws PackedConstantException naming the tensor and encoding; new PackedConstantHandling.DEQUANTIZE (threaded through toComputeGraph and the ExecutionTape extension) opts into dense FP32 dequant-on-extract via PackedBlockStorage.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).

michalharakal and others added 2 commits September 2, 2026 11:28
…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)
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-1250 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-1250 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

2 similar comments
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-1250 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-1250 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@michalharakal
michalharakal merged commit 662ddae into develop Sep 2, 2026
19 checks passed
@michalharakal
michalharakal deleted the feat/1247-graph-constant-extraction branch September 2, 2026 10:12
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.

1 participant