ConstantMaterializationPolicy

Policy governing how a constant tensor (a weight, a bias, a frozen parameter) is materialized into the emitted StableHLO text.

The intent is to decouple "what the converter sees" (a graph node with values) from "how those values reach the deployed runtime" (inline bytes vs external parameter archive). The seam exists so a caller can flip between modes without changing the graph, and so the converter does not grow a private weight-format.

Introduced as the load-bearing decision point of the architecture tracked in issue #523.

Inheritors

Types

Link copied to clipboard
data class ExternalAlways(val scope: String = "model") : ConstantMaterializationPolicy

Every candidate constant — currently tensor_constant, dense_constant, parameter, param, weight, bias — is lifted out of the IR. The converter emits a util.global module declaration and a util.global.load reference, and records an ExternalParameterRef on the resulting module. A downstream packager (e.g. the skainet-io-iree-params module planned in PR C) turns the refs into a .irpa sidecar that iree-compile --iree-opt-import-parameters=<path> resolves.

Link copied to clipboard

Every constant is written into the emitted text as stablehlo.constant dense<...>. Matches the historical behavior and is the default so existing callers are unaffected.

Link copied to clipboard
data class SizeThreshold(val bytes: Long, val scope: String = "model") : ConstantMaterializationPolicy

Hybrid policy: small constants stay inline, large ones go external. The threshold is measured in logical byteselementCount * bytesPerElement computed from the output sk.ainet.lang.tensor.ops.TensorSpec — not the MLIR text size. This keeps the decision independent of downstream splat / dense formatting.