architecture/network/onnx/export

Export-owned execution and payload types for NeatapticTS ONNX serialization.

This chapter holds the types that belong to the exporter implementation: export options, build/setup contexts, recurrent and Conv heuristics, and the dense/per-neuron layer-emission payloads used by the export helpers.

Shared runtime bridge types such as NodeInternals remain root-owned in network.onnx.utils.types.ts, and the persisted wire-format schema stays in schema/network.onnx.schema.types.ts.

flowchart LR
  Options[OnnxExportOptions] --> Setup[Setup and build contexts]
  Setup --> Heuristics[Conv and recurrent heuristics]
  Heuristics --> Layers[Layer emission payloads]
  Layers --> Model[Schema model and tensors]

architecture/network/onnx/export/network.onnx.export.types.ts

ActivationSquashFunction

ActivationSquashFunction(
  x: number,
  derivate: boolean | undefined,
): number

Activation function signature used by ONNX layer emission helpers for encoding activation operator type attributes.

AttentionMapping

Explicit export-only attention mapping for the Phase 5E shadow subset.

This contract keeps attention source-owned rather than heuristic: callers opt one target layer into a fixed-width self-attention shadow block while the stable dense path remains the canonical runtime behavior.

ConcatMapping

Explicit export-only concat mapping for the narrow Phase 5 merge subset.

This contract keeps concat source-owned instead of inferred: callers name one skipped source layer and one target layer, and export preserves the merge as a deterministic Concat -> Gemm path with the default adjacent-layer slice kept first in the merged input order.

ConvInferenceEvaluationContext

Width and shape evaluation context used by Conv inference helpers.

ConvInferenceKernelEvaluationContext

Kernel candidate context for one Conv inference evaluation pass, carrying kernel size and width bounds.

ConvInferenceResult

Collected inferred Conv metadata payload, holding inferred layer indices and their derived Conv2DMapping specs.

ConvInferenceTraversalContext

Traversal context for one hidden layer during Conv inference, including declared mappings and pool specs per layer.

ConvKernelConsistencyContext

Context for kernel-coordinate consistency checks at one output position, comparing representative weights with tolerance.

ConvLayerPairContext

Context for one resolved Conv mapping layer pair, supplying the Conv spec and adjacent layer node lists.

ConvOutputCoordinate

Coordinate for one Conv output neuron, encoding the output channel, row, and column indices together.

ConvRepresentativeKernelContext

Context for representative Conv kernel collection per output channel, supplying neuron lists and the Conv spec.

ConvSharingValidationContext

Context for validating Conv sharing across all declared mappings, holding layer nodes and mapping specifications.

ConvSharingValidationResult

Result of Conv sharing validation across declared mappings, reporting verified and mismatched layer indices.

DenseActivationContext

Dense activation emission context carrying layer index, tensor names, graph names, squash function, and opset version.

DenseActivationNodePayload

Strongly typed activation node payload used by dense export helpers.

DenseGemmNodePayload

Strongly typed Gemm node payload used by dense export helpers.

DenseGraphNames

Dense graph tensor names identifying the Gemm output and activation output tensors for one layer.

DenseInitializerValues

Dense initializer value arrays holding the flattened weight matrix values and bias vector for one layer.

DenseLayerContext

Dense layer context enriched with the resolved activation squash function derived from the current layer nodes.

DenseLayerParams

Parameters for dense layer emission, grouping model, layer index, node lists, ordering flag, and export options.

DenseOrderedNodePayload

Dense node payload union used by ordered append helpers, covering Gemm and activation node payloads.

DenseTensorNames

Dense initializer tensor names for one emitted layer, naming the weight and bias initializer tensors.

DenseWeightBuildContext

Context for building dense layer initializers from two adjacent layers.

DenseWeightBuildResult

Dense layer initializer fold output, containing the flattened weight matrix values and bias vector.

DenseWeightRow

One collected dense row before fold to flattened initializers, containing per-neuron weights and bias value.

DenseWeightRowCollectionContext

Context for collecting one dense row, supplying previous layer nodes and the target neuron internals.

DiagonalRecurrentBuildContext

Context for building a diagonal recurrent matrix from self-connections, supplying the current layer node list.

ExportNodeIndexAssignmentContext

Context for assigning a stable export index to one node.

FlattenAfterPoolingContext

Flatten emission context after optional pooling, carrying model, flatten flag, layer index, and source output name.

FusedRecurrentEmissionExecutionContext

Shared execution context for emitting one fused recurrent layer payload.

FusedRecurrentGraphNames

Context for ONNX fused recurrent node payload names, holding the graph node name and its output tensor name.

FusedRecurrentInitializerNames

Context for ONNX fused recurrent initializer names, grouping weight, recurrent-weight, and bias tensor name strings.

GruEmissionContext

Context for heuristic GRU emission when a layer matches expected shape.

HiddenLayerHeuristicContext

Context for one hidden layer during heuristic recurrent emission, tracking layer index and model state.

IndexedMetadataAppendContext

Append-an-index metadata context for JSON-array metadata keys, supplying model, key, and layer index.

LayerActivationContext

Activation analysis context for one layer, capturing whether the layer contains mixed activation functions.

LayerBuildContext

Layer build context used while emitting one ONNX graph layer segment.

LayerRecurrentDecisionContext

Context used to decide recurrent emission branch usage, carrying layer index and recurrent layer index list.

LayerTraversalContext

Layer traversal context with adjacent layers, output classification, and the full LayerBuildContext fields.

LstmCandidateContext

Candidate context for validating one LSTM-like hidden layer pattern against the expected node count.

LstmEmissionContext

Context for heuristic LSTM emission when a layer matches expected shape.

LstmLayerTraversalContext

Traversal context for one hidden layer during LSTM stub collection.

LstmPatternStub

Heuristic LSTM pattern stub for metadata output, holding the detected layer index and unit size.

OnnxBaseModelBuildContext

Context for constructing a base ONNX model shell, supplying input and output dimension arrays for the graph.

OnnxBuildResolvedOptions

Resolved options for ONNX model build orchestration, with all export option defaults already applied and normalized.

OnnxConvEmissionContext

Context used after resolving Conv mapping for one layer, extending OnnxConvEmissionParams with the resolved Conv2DMapping spec.

OnnxConvEmissionParams

Parameters accepted by Conv layer emission, grouping model, options, layer index, previous output, and adjacent node lists.

OnnxConvParameters

Flattened Conv parameters for ONNX initializers, containing weight and bias arrays derived from Conv layer neurons.

OnnxConvTensorNames

Tensor names generated for Conv parameters, holding weight and bias initializer name strings for one layer.

OnnxDynamicQuantizationOptions

Dynamic uint8 quantization request packet for the landed dense-guidance lane only.

The current subset is intentionally narrow:

Example:

const options: OnnxDynamicQuantizationOptions = {
  mode: 'dynamic-uint8',
  target: 'dense',
  representation: 'DynamicQuantizeLinear',
};

OnnxExportOptions

Options controlling ONNX-like export.

These options trade off strictness, portability, and fidelity:

Key fields (high-level):

OnnxGraphDimensionBuildContext

Context for constructing input/output ONNX graph dimensions, carrying width values and the batch-dimension flag.

OnnxGraphDimensions

Output dimensions used by ONNX graph input/output value info payloads.

OnnxLayerEmissionContext

Context for emitting non-input layers during model build, including layer list, options, and ordering flags.

OnnxLayerEmissionResult

Result of emitting non-input export layers, carrying the last output name and the layer output name map.

OnnxModelMetadataContext

Context for applying optional ONNX model metadata, carrying model reference, opset, producer info, and inclusion flags.

OnnxPostProcessingContext

Context for post-processing and export metadata finalization, holding model, layers, options, and layer emission result.

OnnxPrecisionOptions

Opt-in reduced-precision export controls for the Phase 7 storage lane.

OnnxQuantizationCalibrationLayerTarget

One explicitly calibrated layer target used to build deterministic parameter tensors.

OnnxQuantizationCalibrationOptions

External calibration packet for static quantization, grouping source tag, layer targets, and policy selections.

OnnxQuantizationCalibrationRange

External calibration packet for one quantization layer target, capturing min and max float bounds.

OnnxQuantizationCalibrationRoundingMode

Rounding policy for deterministic zero-point resolution; only 'nearest-even' is currently accepted by the exporter.

OnnxQuantizationCalibrationSymmetry

Symmetry policy for activation and weight quantization parameters; 'symmetric' or 'asymmetric' options are both accepted.

OnnxQuantizationCalibrationWeightRangePolicy

Supported weight-range reduction policy for the first calibration contract; only 'min-max' is accepted.

OnnxQuantizationCalibrationZeroInclusionPolicy

Zero-inclusion policy for exported calibration parameters; controls whether zero must fall within the quantization range.

OnnxQuantizationOptions

Supported quantization request packets for the narrow first Phase 7 lane.

OnnxRecurrentCollectionContext

Context for collecting recurrent layer indices during model build, providing the layer list and export options.

OnnxRecurrentInputValueInfoContext

Context for constructing one recurrent previous-state graph input payload, carrying name, hidden width, and batch flag.

OnnxRecurrentLayerProcessingContext

Execution context for processing one hidden recurrent layer during model build traversal and emission.

OnnxRecurrentLayerTraversalContext

Traversal context for one hidden layer during recurrent-input collection, supplying layer index and batch-dimension flag.

OnnxResolvedPrecisionOptions

Resolved reduced-precision packet for build orchestration, carrying the requested flag, mode, and metadata inclusion decision.

OnnxResolvedQuantizationCalibrationOptions

Resolved calibration packet with exporter-owned defaults applied; all optional policy fields are filled in before emission.

OnnxResolvedQuantizationOptions

Resolved quantization packet for build orchestration, covering unresolved, static-8bit, and dynamic-uint8 branches.

OnnxStaticQuantizationOptions

Static 8-bit quantization request packet for the current Phase 7 qlinear subset.

The landed exporter-owned subset is deliberately narrow:

Example:

const options: OnnxStaticQuantizationOptions = {
  mode: 'static-8bit',
  targets: ['conv'],
  calibration: {
    source: 'external',
    layerTargets: [
      {
        target: 'conv',
        layerIndex: 1,
        inputRange: { min: -1, max: 1 },
        outputRange: { min: -0.5, max: 0.75 },
      },
    ],
  },
  representation: 'qlinear',
};

OptionalLayerOutputParams

Shared parameters for optional pooling or flatten output emission after one dense layer output tensor.

OptionalPoolingAndFlattenParams

Parameters for optional pooling + flatten emission after a layer output.

PerNeuronConcatNodePayload

Per-neuron concat node payload used to merge individual neuron outputs into one combined layer tensor.

PerNeuronGraphNames

Per-neuron graph tensor names identifying the Gemm output and activation output for one neuron subgraph.

PerNeuronLayerContext

Per-neuron layer context alias for PerNeuronLayerParams, used at the per-neuron layer traversal boundary.

PerNeuronLayerParams

Parameters for per-neuron layer emission, grouping model, layer index, node lists, options, and batch-dimension flag.

PerNeuronNodeContext

Per-neuron normalized node context replacing raw Node references with resolved NodeInternals for safe emission.

PerNeuronSubgraphContext

Per-neuron subgraph emission context carrying layer index, neuron index, previous output name, and opset version.

PerNeuronTensorNames

Per-neuron initializer tensor names identifying weight and bias tensors for one neuron subgraph.

PoolingAttributes

Pooling tensor attributes for ONNX node payloads, grouping kernel shape, strides, and padding values.

PoolingEmissionContext

Pooling emission context resolved for one layer output, extending OptionalLayerOutputParams with the Pool2DMapping spec.

RecurrentActivationEmissionContext

Context for selecting and emitting recurrent activation node payload using the layer's dominant squash function.

RecurrentGateBlockCollectionContext

Context for collecting one gate parameter block, supplying gate nodes, previous layer, unit size, and diagonal flag.

RecurrentGateParameterCollectionResult

Flattened recurrent gate parameter vectors for one fused operator, grouping input, recurrent, and bias arrays.

RecurrentGateRow

One recurrent gate row payload before flatten fold, containing input weights, recurrent weights, and bias.

RecurrentGateRowCollectionContext

Context for collecting one recurrent gate row (one neuron), supplying the previous layer node list and unit size.

RecurrentGemmEmissionContext

Context for emitting one Gemm node for recurrent single-step export.

RecurrentGraphNames

Derived graph names for one recurrent single-step layer payload, with all tensor and node names resolved.

RecurrentHeuristicEmissionContext

Context for heuristic recurrent operator emission traversal, carrying model, layer list, and previous output tensor name.

RecurrentInitializerEmissionContext

Context for pushing recurrent initializers into ONNX graph state, carrying widths, tensor names, and value arrays.

RecurrentInitializerNames

Initializer tensor names for one single-step recurrent layer, naming weight, bias, and recurrent-weight tensors.

RecurrentInitializerValues

Collected initializer vectors for one single-step recurrent layer, storing weight matrix, biases, and recurrent weights.

RecurrentLayerEmissionContext

Derived execution context for single-step recurrent layer emission, extending params with layer slot and widths.

RecurrentLayerEmissionParams

Parameters for single-step recurrent layer emission, supplying model, layer index, and adjacent node lists.

RecurrentRowCollectionContext

Context for collecting one recurrent matrix row, supplying the layer node list and the row index to extract.

ResidualAddLayerParams

Parameters for one-hop residual-add dense layer emission, carrying source, residual, and merge node name strings.

SharedActivationNodeBuildParams

Shared parameters for constructing an activation node payload, carrying activation type and output name strings.

SharedGemmNodeBuildParams

Shared parameters for constructing a Gemm node payload, carrying weight, bias, output tensor names, and node name.

SpecMetadataAppendContext

Append-a-spec metadata context for JSON-array metadata keys, supplying model, key, and Conv or Pool spec.

WeightToleranceComparisonContext

Context for comparing two scalar weights with numeric tolerance, used by Conv sharing validation helpers.

architecture/network/onnx/export/network.onnx.export-flow.utils.ts

appendMetadataEntry

appendMetadataEntry(
  model: OnnxModel,
  key: string,
  value: string,
): void

Append one metadata entry to the model-level metadata registry.

Parameters:

Returns: Nothing.

appendPhaseSevenRequestMetadata

appendPhaseSevenRequestMetadata(
  model: OnnxModel,
  networkLayers: default[][],
  sourceOptions: OnnxExportOptions,
): void

Append Phase 7 request metadata without implying that reduced-precision lowering has landed.

Parameters:

Returns: Nothing.

appendQuantizationRequestMetadata

appendQuantizationRequestMetadata(
  model: OnnxModel,
  networkLayers: default[][],
  sourceOptions: OnnxExportOptions,
): void

Append quantization request metadata and explicit float32 fallback reasons.

Parameters:

Returns: Nothing.

buildPrecisionFallbackReasons

buildPrecisionFallbackReasons(
  networkLayers: default[][],
  sourceOptions: OnnxExportOptions,
): string[]

Build the explicit float32 fallback reasons for a Phase 7 precision request.

Parameters:

Returns: Ordered fallback reason codes.

buildQuantizationFallbackReasons

buildQuantizationFallbackReasons(
  model: OnnxModel,
  networkLayers: default[][],
  sourceOptions: OnnxExportOptions,
): string[]

Build the explicit float32 fallback reasons for a Phase 7 quantization request.

Parameters:

Returns: Ordered fallback reason codes.

hasAdvancedGraphBoundary

hasAdvancedGraphBoundary(
  sourceOptions: OnnxExportOptions,
): boolean

Detect whether the current export request crosses the explicit advanced-graph boundary.

Parameters:

Returns: True when explicit merge or attention mappings are requested.

hasRecurrentBoundary

hasRecurrentBoundary(
  networkLayers: default[][],
  sourceOptions: OnnxExportOptions,
): boolean

Detect whether the current export request crosses the recurrent boundary.

Parameters:

Returns: True when recurrent export is requested and a hidden layer carries self-state.

hasSpatialBoundary

hasSpatialBoundary(
  sourceOptions: OnnxExportOptions,
): boolean

Detect whether the current export request crosses the spatial boundary.

Parameters:

Returns: True when explicit Conv or pooling mappings are requested.

hasUnsupportedMultiOutputDenseQuantizationTarget

hasUnsupportedMultiOutputDenseQuantizationTarget(
  model: OnnxModel,
  quantizationPacket: OnnxStaticQuantizationOptions,
): boolean

Detect whether the current static request includes any targeted multi-output dense layer that stayed on float32.

Parameters:

Returns: True when a targeted dense layer is wider than the landed one-output qlinear subset.

resolveDenseQuantizationOutputWidth

resolveDenseQuantizationOutputWidth(
  model: OnnxModel,
  layerIndex: number,
): number

Resolve the dense output width for one targeted layer from its bias initializer.

Parameters:

Returns: Dense output width.

resolveEffectiveExportOptions

resolveEffectiveExportOptions(
  networkLayers: default[][],
  sourceOptions: OnnxExportOptions,
): OnnxExportOptions

Resolve effective export options without mutating caller-owned state.

Parameters:

Returns: Effective export options for this export pass.

resolveEffectiveQuantizationMode

resolveEffectiveQuantizationMode(
  model: OnnxModel,
  requestedQuantizationMode: "static-8bit" | "dynamic-uint8",
  quantizationFallbackReasons: string[],
): "static-8bit" | "dynamic-uint8" | "none"

Resolve the effective quantization mode from the emitted graph payload.

Parameters:

Returns: Effective quantization mode for metadata emission.

resolveStaticQuantizationFallbackReasons

resolveStaticQuantizationFallbackReasons(
  model: OnnxModel,
): string[]

Resolve static quantization fallback reasons after checking whether qlinear lowering landed.

Parameters:

Returns: Ordered static-quantization fallback reasons.

runOnnxExportFlow

runOnnxExportFlow(
  network: default,
  options: OnnxExportOptions,
): OnnxModel

Execute the complete ONNX export flow for one network instance.

High-level behavior:

  1. Rebuild runtime connection caches and assign stable export indices.
  2. Infer layered ordering and collect recurrent-pattern stubs.
  3. Validate structural constraints for the requested export options.
  4. Build ONNX graph payload and append inference-oriented metadata.

Parameters:

Returns: ONNX-like model payload.

architecture/network/onnx/export/network.onnx.export-build.utils.ts

buildOnnxModel

buildOnnxModel(
  network: default,
  layers: default[][],
  options: OnnxExportOptions | undefined,
): OnnxModel

Construct ONNX graph (initializers + nodes) from validated layered network structure.

Parameters:

Returns: ONNX model.

architecture/network/onnx/export/network.onnx.export-setup.utils.ts

appendRecurrentGraphInput

appendRecurrentGraphInput(
  model: OnnxModel,
  traversalContext: OnnxRecurrentLayerTraversalContext,
): void

Append one recurrent previous-state graph input for a hidden layer.

Parameters:

Returns: Nothing.

appendRecurrentLayerIndex

appendRecurrentLayerIndex(
  recurrentLayerIndices: number[],
  traversalContext: OnnxRecurrentLayerTraversalContext,
): void

Append one recurrent layer index to the collected index list.

Parameters:

Returns: Nothing.

applyModelMetadata

applyModelMetadata(
  context: OnnxModelMetadataContext,
): void

Attach producer, opset, and documentation metadata to a model when metadata emission is enabled for export diagnostics. Fallback values keep metadata deterministic even when optional producer fields are omitted.

Parameters:

Returns: Nothing.

collectRecurrentLayerIndices

collectRecurrentLayerIndices(
  context: OnnxRecurrentCollectionContext,
): number[]

Detect hidden layers with self-recurrence and add matching previous-state graph inputs required by single-step recurrent export. Collected indices are reused by metadata and recurrent post-processing lanes.

Parameters:

Returns: Export-layer indices with recurrent self-connections.

createBaseModel

createBaseModel(
  context: OnnxBaseModelBuildContext,
): OnnxModel

Create the base ONNX model shell with graph input and output declarations before operator emission starts. Initializer and node arrays are intentionally empty so later export phases append deterministic content.

Parameters:

Returns: Initialized ONNX model with empty initializer/node lists.

createGraphDimensions

createGraphDimensions(
  context: OnnxGraphDimensionBuildContext,
): OnnxGraphDimensions

Build tensor dimensions for model input and output boundaries, optionally prepending a symbolic batch axis for runtime-sized payloads. The result is reused by value-info generation so shape contracts stay deterministic.

Parameters:

Returns: Input and output dimension arrays for ONNX value info.

createGraphValueInfo

createGraphValueInfo(
  valueName: string,
  dimensions: OnnxDimension[],
): OnnxValueInfo

Create ONNX value info payload for one graph boundary tensor.

Parameters:

Returns: ONNX value info payload.

createHiddenLayerIndices

createHiddenLayerIndices(
  totalLayerCount: number,
): number[]

Build hidden layer indices excluding input and output layers.

Parameters:

Returns: Hidden layer indices.

createHiddenLayerTraversalContexts

createHiddenLayerTraversalContexts(
  context: OnnxRecurrentCollectionContext,
): OnnxRecurrentLayerTraversalContext[]

Build traversal contexts for all hidden layers.

Parameters:

Returns: Hidden layer traversal contexts.

createRecurrentInputValueInfo

createRecurrentInputValueInfo(
  context: OnnxRecurrentInputValueInfoContext,
): OnnxValueInfo

Build one recurrent previous-state graph input payload.

Parameters:

Returns: ONNX value info payload for recurrent state input.

createRecurrentInputValueInfoContext

createRecurrentInputValueInfoContext(
  traversalContext: OnnxRecurrentLayerTraversalContext,
): OnnxRecurrentInputValueInfoContext

Build recurrent input context for one hidden recurrent layer.

Parameters:

Returns: Recurrent input value-info context.

createTensorDimensions

createTensorDimensions(
  width: number,
  batchDimension: boolean,
): OnnxDimension[]

Build one tensor shape dimension payload for dense vectors.

Parameters:

Returns: ONNX dimensions for the vector payload.

CURRENT_ONNX_REFERENCE_OPSET

Current upstream ONNX reference opset version for the ai.onnx standard domain.

hasLayerSelfRecurrence

hasLayerSelfRecurrence(
  hiddenLayerNodes: default[],
): boolean

Detect whether a hidden layer contains at least one self-recurrent node.

Parameters:

Returns: True when a node has a self-connection.

isRecurrentCollectionEnabled

isRecurrentCollectionEnabled(
  context: OnnxRecurrentCollectionContext,
): boolean

Determine whether recurrent layer collection should execute.

Parameters:

Returns: True when recurrent collection is enabled.

ONNX_IR_VERSION

Current ONNX IR version used by the repo's declared binary subset.

ONNX_STANDARD_DOMAIN

Canonical ONNX standard-operator domain name used by opset metadata, schema annotations, and exporter compatibility checks across baseline graph emission paths.

ONNX_STANDARD_DOMAIN_ALIAS

Canonical empty-string alias for the ONNX standard operator-set domain identifier.

processHiddenLayerRecurrence

processHiddenLayerRecurrence(
  context: OnnxRecurrentLayerProcessingContext,
): void

Process one hidden layer for recurrent self-connections.

Parameters:

Returns: Nothing.

architecture/network/onnx/export/network.onnx.export-attention.utils.ts

emitShadowAttentionMappings

emitShadowAttentionMappings(
  model: OnnxModel,
  layers: default[][],
  options: OnnxExportOptions,
  layerOutputNamesByLayerIndex: ReadonlyMap<number, string>,
  includeMetadata: boolean,
): void

Emit explicit shadow attention blocks for the Phase 5E fixed-width subset.

The current runtime does not execute native attention semantics, so this pass follows the same strategy used by the fused recurrent heuristics: emit a deterministic ONNX attention subgraph without replacing the stable dense path that the importer already round-trips.

Parameters:

Returns: Nothing.

architecture/network/onnx/export/network.onnx.export-build.emit.utils.ts

applyPostProcessing

applyPostProcessing(
  context: OnnxPostProcessingContext,
): void

Applies all post-processing passes (recurrent heuristics, attention mappings, export metadata) to the model in place.

collectRecurrentIndices

collectRecurrentIndices(
  context: OnnxRecurrentCollectionContext,
): number[]

Collects the layer indices of all recurrent layers present in the export context.

createInitializedModel

createInitializedModel(
  networkLayers: default[][],
  currentOptions: OnnxBuildResolvedOptions,
): OnnxModel

Creates an initialized ONNX model with graph dimensions and metadata derived from the resolved build options.

emitNonInputLayers

emitNonInputLayers(
  context: OnnxLayerEmissionContext,
): OnnxLayerEmissionResult

Emits ONNX graph nodes for every layer after the input layer and returns the accumulated emission result.

architecture/network/onnx/export/network.onnx.export-postprocess.utils.ts

appendConvLayerValidationResult

appendConvLayerValidationResult(
  result: ConvSharingValidationResult,
  layerIndex: number,
  isConsistent: boolean,
): void

Append one Conv-layer validation outcome and optional warning

appendConvSharingMetadata

appendConvSharingMetadata(
  model: OnnxModel,
  result: ConvSharingValidationResult,
): void

Append Conv-sharing validation metadata arrays.

appendFusedRecurrentInitializers

appendFusedRecurrentInitializers(
  model: OnnxModel,
  initializerNames: FusedRecurrentInitializerNames,
  parameters: RecurrentGateParameterCollectionResult,
  gateCount: number,
  unitSize: number,
  previousSize: number,
): void

Append fused recurrent initializer tensors to the ONNX graph

appendFusedRecurrentNode

appendFusedRecurrentNode(
  graph: OnnxGraph,
  operatorType: "LSTM" | "GRU",
  previousOutputName: string,
  initializerNames: FusedRecurrentInitializerNames,
  graphNames: FusedRecurrentGraphNames,
  unitSize: number,
): void

Append fused recurrent operator node to the ONNX graph

appendIndexMetadata

appendIndexMetadata(
  model: OnnxModel,
  key: string,
  layerIndex: number,
): void

Append a unique layer index to metadata array key

appendMetadataProperty

appendMetadataProperty(
  model: OnnxModel,
  metadataProperty: OnnxMetadataProperty,
): void

Append metadata property to model metadata_props list

appendRecurrentSingleStepMetadata

appendRecurrentSingleStepMetadata(
  model: OnnxModel,
  recurrentLayerIndices: number[],
): void

Append recurrent single-step metadata when recurrent layers exist

areWeightsWithinTolerance

areWeightsWithinTolerance(
  context: WeightToleranceComparisonContext,
): boolean

Compare two scalar weights using configured tolerance

asNodeInternals

asNodeInternals(
  node: default,
): NodeInternals

Resolve runtime node internals in one typed helper

buildFusedGruExecutionContext

buildFusedGruExecutionContext(
  context: GruEmissionContext,
): FusedRecurrentEmissionExecutionContext

Build shared fused-recurrent execution context for GRU

buildFusedLstmExecutionContext

buildFusedLstmExecutionContext(
  context: LstmEmissionContext,
): FusedRecurrentEmissionExecutionContext

Build shared fused-recurrent execution context for LSTM

buildFusedRecurrentGraphNames

buildFusedRecurrentGraphNames(
  nodePrefix: string,
  outputSuffix: string,
  layerIndex: number,
): FusedRecurrentGraphNames

Build fused recurrent graph names for node and output

buildFusedRecurrentInitializerNames

buildFusedRecurrentInitializerNames(
  operatorType: "LSTM" | "GRU",
  layerIndex: number,
): FusedRecurrentInitializerNames

Build fused recurrent initializer names for the current layer

buildGruEmissionContext

buildGruEmissionContext(
  context: HiddenLayerHeuristicContext,
): GruEmissionContext

Build GRU emission context from one hidden-layer traversal record

buildHiddenLayerHeuristicContext

buildHiddenLayerHeuristicContext(
  context: RecurrentHeuristicEmissionContext,
  layerIndex: number,
): HiddenLayerHeuristicContext

Build one hidden-layer traversal context.

buildLstmEmissionContext

buildLstmEmissionContext(
  context: HiddenLayerHeuristicContext,
): LstmEmissionContext

Build LSTM emission context from one hidden-layer traversal record

buildMetadataProperty

buildMetadataProperty(
  key: string,
  value: unknown,
): OnnxMetadataProperty

Build a metadata key/value property with JSON string serialization

buildRecurrentHeuristicEmissionContext

buildRecurrentHeuristicEmissionContext(
  model: OnnxModel,
  layers: default[][],
  previousOutputName: string,
): RecurrentHeuristicEmissionContext

Build reusable context for recurrent heuristic traversal

buildSharedInitializerSignature

buildSharedInitializerSignature(
  initializerEntry: OnnxTensor,
  initializerKind: "dense_weight" | "dense_bias" | "per_neuron_weight" | "per_neuron_bias",
): string

Build an exact-match signature for dense-family alias reuse

classifySharedInitializerKind

classifySharedInitializerKind(
  initializerName: string,
): "dense_weight" | "dense_bias" | "per_neuron_weight" | "per_neuron_bias" | null

Classify the dense-family initializer kinds supported by the Phase 5B alias subset

collectConvKernelCoordinates

collectConvKernelCoordinates(
  convSpec: Conv2DMapping,
): OnnxConvKernelCoordinate[]

Collect kernel coordinates for one Conv kernel traversal

collectConvOutputCoordinates

collectConvOutputCoordinates(
  convSpec: Conv2DMapping,
): ConvOutputCoordinate[]

Collect output coordinates for full Conv traversal

collectGruGateNodeGroups

collectGruGateNodeGroups(
  context: GruEmissionContext,
): default[][]

Collect GRU gate node groups in canonical export order

collectHiddenLayerIndices

collectHiddenLayerIndices(
  layers: default[][],
): number[]

Collect hidden-layer indices for recurrent traversal

collectLstmGateNodeGroups

collectLstmGateNodeGroups(
  context: LstmEmissionContext,
): default[][]

Collect LSTM gate node groups in canonical export order

collectRecurrentGateBlockParameters

collectRecurrentGateBlockParameters(
  context: RecurrentGateBlockCollectionContext,
): RecurrentGateParameterCollectionResult

Collect flattened parameter vectors for one gate node block

collectRecurrentGateRow

collectRecurrentGateRow(
  context: RecurrentGateRowCollectionContext,
): RecurrentGateRow

Collect one recurrent gate row payload (inputs, recurrent slice, and bias)

collectRepresentativeKernelForChannel

collectRepresentativeKernelForChannel(
  context: ConvRepresentativeKernelContext & { sourceLayout: ResolvedConvSourceLayout; },
): number[]

Collect one representative kernel by reading the first output position for a channel

collectRepresentativeKernels

collectRepresentativeKernels(
  context: ConvLayerPairContext,
  sourceLayout: ResolvedConvSourceLayout,
): number[][]

Collect representative kernels for each output channel

collectRepresentativeKernelWeight

collectRepresentativeKernelWeight(
  convSpec: Conv2DMapping,
  previousLayerNodes: default[],
  representativeInternal: NodeInternals,
  kernelCoordinate: OnnxConvKernelCoordinate,
  sourceLayout: ResolvedConvSourceLayout,
): number

Collect representative kernel value using top-left receptive field indexing

emitFallbackRecurrentPatternMetadata

emitFallbackRecurrentPatternMetadata(
  context: HiddenLayerHeuristicContext,
): void

Emit fallback metadata for recurrent-size ambiguity

emitFusedRecurrentHeuristics

emitFusedRecurrentHeuristics(
  model: OnnxModel,
  layers: default[][],
  allowRecurrent: boolean | undefined,
  previousOutputName: string,
): void

Append heuristic fused recurrent nodes for hidden layers that match GRU/LSTM sizing patterns.

The pass is a metadata-guided postprocess step: it inspects hidden-layer widths, emits compatible recurrent operators, and keeps legacy output-name threading intact.

Parameters:

emitFusedRecurrentLayer

emitFusedRecurrentLayer(
  context: FusedRecurrentEmissionExecutionContext,
): void

Emit shared fused recurrent payload (initializers, node, metadata)

ensureMetadataProps

ensureMetadataProps(
  model: OnnxModel,
): OnnxMetadataProperty[]

Ensure metadata_props array exists and return it

finalizeExportMetadata

finalizeExportMetadata(
  model: OnnxModel,
  layers: default[][],
  options: OnnxExportOptions,
  includeMetadata: boolean,
  hiddenSizesMetadata: number[],
  recurrentLayerIndices: number[],
): void

Finalize model metadata after graph emission, including alias reuse and optional Conv sharing diagnostics.

Parameters:

findMetadataPropertyIndex

findMetadataPropertyIndex(
  metadataProperties: OnnxMetadataProperty[],
  key: string,
): number

Find metadata property index by key

foldRecurrentGateBlocks

foldRecurrentGateBlocks(
  gateParameterBlocks: RecurrentGateParameterCollectionResult[],
): RecurrentGateParameterCollectionResult

Fold gate blocks into a single fused parameter payload

foldRecurrentGateRows

foldRecurrentGateRows(
  gateRows: RecurrentGateRow[],
): RecurrentGateParameterCollectionResult

Fold recurrent gate rows into flattened ONNX initializer vectors

hasNoIgnoredSourceWeights

hasNoIgnoredSourceWeights(
  context: ConvLayerPairContext,
  sourceLayout: ResolvedConvSourceLayout,
): boolean

Ensure weights outside the Conv-addressable source slice remain zero.

Parameters:

Returns: True when ignored dense source nodes carry no extra weight.

isConvLayerPairConsistent

isConvLayerPairConsistent(
  context: ConvLayerPairContext,
  options: OnnxExportOptions | undefined,
): boolean

Validate one Conv layer pair against representative kernel sharing

isConvMappingWeightShared

isConvMappingWeightShared(
  layers: default[][],
  convSpec: Conv2DMapping,
  options: OnnxExportOptions | undefined,
): boolean

Determine whether one Conv mapping behaves like a shared kernel layer.

Parameters:

Returns: True when representative kernels stay consistent across outputs.

isEligibleForGruHeuristic

isEligibleForGruHeuristic(
  currentSize: number,
): boolean

Check GRU heuristic eligibility by size and gate divisibility

isEligibleForLstmHeuristic

isEligibleForLstmHeuristic(
  currentSize: number,
): boolean

Check LSTM heuristic eligibility by size and gate divisibility

isFallbackRecurrentPatternSize

isFallbackRecurrentPatternSize(
  currentSize: number,
): boolean

Check whether hidden size should emit recurrent fallback metadata

isInputPositionInsideBounds

isInputPositionInsideBounds(
  convSpec: Conv2DMapping,
  inputRow: number,
  inputColumn: number,
): boolean

Check whether input row/column falls inside Conv input bounds

isKernelCoordinateConsistent

isKernelCoordinateConsistent(
  context: ConvKernelConsistencyContext & { sourceLayout: ResolvedConvSourceLayout; },
): boolean

Validate one kernel coordinate against its representative channel value

isOutputCoordinateConsistent

isOutputCoordinateConsistent(
  context: ConvLayerPairContext,
  outputCoordinate: ConvOutputCoordinate,
  representativeKernels: number[][],
  tolerance: number,
  sourceLayout: ResolvedConvSourceLayout,
): boolean

Validate one output coordinate against channel representative kernel weights

parseMetadataLayerIndices

parseMetadataLayerIndices(
  metadataValue: string,
): number[]

Parse metadata JSON value into a numeric layer-index array

resolveConvLayerPairContext

resolveConvLayerPairContext(
  layers: default[][],
  layerIndex: number,
  convSpec: Conv2DMapping,
): ConvLayerPairContext | undefined

Resolve one Conv mapping layer pair or return undefined for invalid layout

resolveGruPreviousOutputName

resolveGruPreviousOutputName(
  layerIndex: number,
): string

Resolve previous output naming semantics for GRU heuristic emission

resolveIncomingWeight

resolveIncomingWeight(
  targetNodeInternal: NodeInternals,
  sourceNode: default,
): number

Resolve incoming connection weight from a specific source node

resolveInputPosition

resolveInputPosition(
  context: ConvKernelConsistencyContext,
): { inputRow: number; inputColumn: number; }

Resolve input row/column projected by output and kernel coordinates

resolveNeuronInternalAtOutputCoordinate

resolveNeuronInternalAtOutputCoordinate(
  context: ConvLayerPairContext,
  outputCoordinate: ConvOutputCoordinate,
): NodeInternals | undefined

Resolve runtime internals for output coordinate neuron, if present

resolveRecurrentRowWeight

resolveRecurrentRowWeight(
  context: RecurrentGateRowCollectionContext,
  columnIndex: number,
): number

Resolve one recurrent row value at the requested column

resolveSelfConnectionWeight

resolveSelfConnectionWeight(
  targetNodeInternal: NodeInternals,
): number

Resolve self-connection weight for diagonal recurrent matrix entries

resolveSourceNodeAtInputPosition

resolveSourceNodeAtInputPosition(
  convSpec: Conv2DMapping,
  previousLayerNodes: default[],
  inChannelIndex: number,
  inputRow: number,
  inputColumn: number,
  sourceLayout: ResolvedConvSourceLayout,
): default | undefined

Resolve source node by Conv input position coordinates

reuseSharedInitializers

reuseSharedInitializers(
  model: OnnxModel,
): SharedInitializerAliasRecord[]

Canonicalize byte-identical dense initializers and rewrite node inputs to shared tensor names.

rewriteInitializerInputs

rewriteInitializerInputs(
  graph: OnnxGraph,
  aliasTensorNameByRemovedTensorName: Map<string, string>,
): void

Rewrite graph-node initializer inputs after later aliases collapse into one canonical tensor

shouldValidateConvSharing

shouldValidateConvSharing(
  options: OnnxExportOptions,
): boolean

Determine whether Conv2D sharing validation is enabled and configured

tryEmitFusedGru

tryEmitFusedGru(
  context: HiddenLayerHeuristicContext,
): void

Try emitting heuristic fused GRU node and metadata

tryEmitFusedLstm

tryEmitFusedLstm(
  context: HiddenLayerHeuristicContext,
): void

Try emitting heuristic fused LSTM node and metadata

upsertLayerIndexMetadataValue

upsertLayerIndexMetadataValue(
  metadataProperties: OnnxMetadataProperty[],
  metadataIndex: number,
  layerIndex: number,
): void

Upsert one layer index into metadata array-like JSON value

validateConvSharingAcrossMappings

validateConvSharingAcrossMappings(
  context: ConvSharingValidationContext,
): ConvSharingValidationResult

Validate Conv2D sharing across all declared Conv mappings

architecture/network/onnx/export/network.onnx.export-optimization.utils.ts

pruneIdentityActivationNodes

pruneIdentityActivationNodes(
  model: OnnxModel,
): void

Remove exporter-owned Identity activation nodes and rewire all dependent consumers.

Parameters:

Returns: Nothing.

architecture/network/onnx/export/network.onnx.export-build.options.utils.ts

resolveBuildOptions

resolveBuildOptions(
  sourceOptions: OnnxExportOptions,
  networkLayerCount: number,
): OnnxBuildResolvedOptions

Resolve export options with all defaults required by model construction.

Parameters:

Returns: Resolved options used by this builder.

resolvePrecisionOptions

resolvePrecisionOptions(
  sourceOptions: OnnxExportOptions,
): OnnxResolvedPrecisionOptions

Resolve precision options with stable defaults and supported modes only.

Parameters:

Returns: Normalized precision packet.

resolveQuantizationOptions

resolveQuantizationOptions(
  sourceOptions: OnnxExportOptions,
  networkLayerCount: number,
): OnnxResolvedQuantizationOptions

Resolve quantization options with stable defaults and supported first-wave modes only.

Parameters:

Returns: Normalized quantization packet.

architecture/network/onnx/export/network.onnx.export-orchestrators.utils.ts

appendConvInferenceMetadata

appendConvInferenceMetadata(
  model: OnnxModel,
  layers: default[][],
  options: OnnxExportOptions,
): void

Append heuristic conv inference metadata when requested. Inferred metadata records spatial interpretation hints for downstream tooling while leaving declared mapping behavior untouched, so diagnostics can improve without silently changing emitted operator topology.

Parameters:

Returns: Nothing.

appendLstmPatternStubMetadata

appendLstmPatternStubMetadata(
  model: OnnxModel,
  lstmPatternStubs: LstmPatternStub[],
): void

Append LSTM pattern stub metadata. Stub metadata gives import-side or diagnostics tools a lightweight recurrent hint surface when full fused recurrent emission is not enabled for the active export pass.

Parameters:

Returns: Nothing.

appendMetadataProperties

appendMetadataProperties(
  model: OnnxModel,
  metadataProperties: OnnxMetadataProperty[],
): void

Append metadata properties in a single, normalized path.

Parameters:

Returns: Nothing.

applyExportNodeIndexAssignments

applyExportNodeIndexAssignments(
  assignmentContexts: ExportNodeIndexAssignmentContext[],
): void

Apply prepared node/index assignment contexts.

Parameters:

Returns: Nothing.

applySingleExportNodeIndexAssignment

applySingleExportNodeIndexAssignment(
  assignmentContext: ExportNodeIndexAssignmentContext,
): void

Apply one export index assignment.

Parameters:

Returns: Nothing.

assignExportNodeIndices

assignExportNodeIndices(
  network: default,
): void

Assign stable sequential index values to nodes for ONNX export diagnostics.

Parameters:

Returns: Nothing.

calculateSpatialOutputSize

calculateSpatialOutputSize(
  inputSize: number,
  kernelSize: number,
  strideSize: number,
  leadingPadding: number,
  trailingPadding: number,
): number

Calculate one spatial output size from kernel, stride, and padding metadata.

Parameters:

Returns: Derived spatial output size.

canPromoteInferredConvSpec

canPromoteInferredConvSpec(
  layers: default[][],
  options: OnnxExportOptions,
  convSpec: Conv2DMapping & { note?: string | undefined; },
  availableConvSpecs: Conv2DMapping[],
): boolean

Decide whether an inferred Conv specification is still safe to promote.

Promotion eligibility only checks the shared-kernel safety gate. Pooling and flatten boundaries are resolved earlier during inference so only spatially valid candidates reach this step.

Parameters:

Returns: True when the inferred Conv can be promoted safely.

collectCandidateInputChannelCounts

collectCandidateInputChannelCounts(
  previousWidth: number,
): number[]

Collect candidate input-channel counts that evenly partition the previous width.

Parameters:

Returns: Candidate input-channel counts.

collectInferredConvMetadata

collectInferredConvMetadata(
  context: { layers: default[][]; declaredMappings: Conv2DMapping[] | undefined; flattenAfterPooling: boolean | undefined; poolMappings: Pool2DMapping[] | undefined; },
): ConvInferenceResult

Collect inferred Conv metadata from hidden-layer traversals.

Parameters:

Returns: Inferred Conv metadata result.

collectLstmPatternStubs

collectLstmPatternStubs(
  layers: default[][],
  allowRecurrent: boolean | undefined,
): LstmPatternStub[]

Collect heuristic LSTM grouping stubs from hidden layers. Stub collection is intentionally conservative and side-effect free so exporter metadata can communicate likely recurrent structure without committing to fused recurrent graph emission.

Parameters:

Returns: Candidate LSTM pattern stubs.

collectLstmPatternStubsFromLayers

collectLstmPatternStubsFromLayers(
  layers: default[][],
): LstmPatternStub[]

Collect LSTM pattern stubs from hidden layers.

Parameters:

Returns: LSTM pattern stubs.

createConvInferenceEvaluationContext

createConvInferenceEvaluationContext(
  params: { allowsExactFitKernel: boolean; layerIndex: number; currentWidth: number; inputChannels: number; inputHeight: number; inputWidth: number; },
): ConvInferenceEvaluationContext | undefined

Create one width/square-evaluation context for a specific channel partition.

Parameters:

Returns: Conv evaluation context when the per-channel input width is square.

createConvInferenceEvaluationContexts

createConvInferenceEvaluationContexts(
  traversalContext: ConvInferenceTraversalContext,
): ConvInferenceEvaluationContext[]

Create width/square-evaluation contexts for Conv inference.

Parameters:

Returns: Conv evaluation contexts.

createConvTraversalContexts

createConvTraversalContexts(
  context: { layers: default[][]; declaredMappings: Conv2DMapping[] | undefined; flattenAfterPooling: boolean | undefined; poolMappings: Pool2DMapping[] | undefined; },
): ConvInferenceTraversalContext[]

Create Conv traversal contexts for hidden layers.

Parameters:

Returns: Conv traversal contexts.

createExportNodeIndexAssignmentContexts

createExportNodeIndexAssignmentContexts(
  network: default,
): ExportNodeIndexAssignmentContext[]

Create node/index assignment contexts for export diagnostics.

Parameters:

Returns: Assignment contexts.

createHiddenLayerTraversalContexts

createHiddenLayerTraversalContexts(
  layers: default[][],
): LstmLayerTraversalContext[]

Create traversal contexts for hidden layers only.

Parameters:

Returns: Hidden layer contexts.

createLstmCandidateContext

createLstmCandidateContext(
  hiddenLayerContext: LstmLayerTraversalContext,
): LstmCandidateContext

Build LSTM candidate context for one hidden layer.

Parameters:

Returns: LSTM candidate context.

createPooledConvInferenceEvaluationContext

createPooledConvInferenceEvaluationContext(
  traversalContext: ConvInferenceTraversalContext,
): ConvInferenceEvaluationContext | undefined

Resolve one pooled previous-layer evaluation context when pooling keeps the graph spatial.

Parameters:

Returns: Evaluation context anchored to the derived pooled shape, if usable.

hasInferredConvMetadata

hasInferredConvMetadata(
  inferenceResult: ConvInferenceResult,
): boolean

Check whether inferred Conv metadata exists.

Parameters:

Returns: True when inferred metadata exists.

hasRequiredSelfConnectionCount

hasRequiredSelfConnectionCount(
  nodeItem: default,
): boolean

Check whether one node has the required self-connection count.

Parameters:

Returns: True when self-connection count matches requirement.

hasUpstreamPoolingBoundary

hasUpstreamPoolingBoundary(
  traversalContext: ConvInferenceTraversalContext,
): boolean

Check whether the immediately previous layer has pooling configured.

Parameters:

Returns: True when the previous layer changes spatial shape through pooling.

isConvInferenceEvaluationContext

isConvInferenceEvaluationContext(
  evaluationContext: ConvInferenceEvaluationContext | undefined,
): boolean

Type guard for defined Conv inference evaluation contexts.

Parameters:

Returns: True when the context is defined.

isDeclaredConvLayer

isDeclaredConvLayer(
  traversalContext: ConvInferenceTraversalContext,
): boolean

Check whether a traversal layer already has declared Conv mapping.

Parameters:

Returns: True when mapping is already declared.

isInferredConvSpec

isInferredConvSpec(
  specification: (Conv2DMapping & { note?: string | undefined; }) | undefined,
): boolean

Type guard for inferred Conv specifications.

Parameters:

Returns: True when specification is defined.

isValidLstmCandidateContext

isValidLstmCandidateContext(
  candidateContext: LstmCandidateContext,
): boolean

Determine whether a candidate context satisfies heuristic LSTM conditions.

Parameters:

Returns: True when the candidate is a valid LSTM stub.

mapLstmCandidateToStub

mapLstmCandidateToStub(
  candidateContext: LstmCandidateContext,
): LstmPatternStub

Map a valid candidate context to metadata stub.

Parameters:

Returns: LSTM pattern stub.

resolveConvInferenceForLayer

resolveConvInferenceForLayer(
  traversalContext: ConvInferenceTraversalContext,
): (Conv2DMapping & { note?: string | undefined; }) | undefined

Resolve inferred Conv specification for one hidden layer.

Parameters:

Returns: Inferred Conv specification when matched.

resolveConvSpecForKernel

resolveConvSpecForKernel(
  kernelContext: ConvInferenceKernelEvaluationContext,
  allowExactFitKernel: boolean,
): (Conv2DMapping & { note?: string | undefined; }) | undefined

Resolve Conv specification for one kernel candidate.

Parameters:

Returns: Inferred Conv specification when matched.

resolveConvSpecFromKernelCandidates

resolveConvSpecFromKernelCandidates(
  evaluationContext: ConvInferenceEvaluationContext,
): (Conv2DMapping & { note?: string | undefined; }) | undefined

Resolve Conv specification using ordered kernel candidates.

Parameters:

Returns: Inferred Conv specification when matched.

resolveEffectiveConvMappings

resolveEffectiveConvMappings(
  layers: default[][],
  options: OnnxExportOptions,
): Conv2DMapping[] | undefined

Resolve the effective Conv mapping list after optional heuristic promotion. Promotion merges user-declared mappings with vetted inferred candidates only when safety gates pass, preserving explicit caller intent while enabling ergonomic auto-discovery for compatible layouts.

Parameters:

Returns: Declared mappings plus any safety-gated promoted inferred mappings.

resolveSingleInferredConvSpec

resolveSingleInferredConvSpec(
  inferredSpecs: (Conv2DMapping & { note?: string | undefined; })[],
): (Conv2DMapping & { note?: string | undefined; }) | undefined

Keep multi-channel Conv inference conservative when multiple layouts fit.

Parameters:

Returns: The single usable spec, otherwise undefined.

resolveSquareSpatialWidth

resolveSquareSpatialWidth(
  previousWidth: number,
  inputChannels: number,
): number

Resolve the per-channel square width when a dense width can be partitioned evenly.

Parameters:

Returns: Resolved square spatial width, or zero when the partition is not square.

safelyCollectLstmPatternStubs

safelyCollectLstmPatternStubs(
  layers: default[][],
): LstmPatternStub[]

Collect LSTM pattern stubs with heuristic error isolation.

Parameters:

Returns: LSTM pattern stubs.

stripInferredConvNote

stripInferredConvNote(
  convSpec: Conv2DMapping & { note?: string | undefined; },
): Conv2DMapping

Remove inference-only note fields before promoted specs become real mappings.

Parameters:

Returns: Clean Conv mapping suitable for real Conv emission.

supportsFlattenedPostPoolConvSubset

supportsFlattenedPostPoolConvSubset(
  traversalContext: ConvInferenceTraversalContext,
  previousConvSpec: Conv2DMapping,
  inputHeight: number,
  inputWidth: number,
): boolean

Check whether the current flatten-after-pool bridge fits the narrow supported subset.

Parameters:

Returns: True when the flattened pooled bridge can still feed one final later Conv-like stage.

architecture/network/onnx/export/network.onnx.export-advanced-graph.utils.ts

appendAdvancedGraphMetadata

appendAdvancedGraphMetadata(
  model: OnnxModel,
  network: default,
  layers: default[][],
  includeMetadata: boolean,
): void

Append deterministic advanced-graph metadata for cross-layer feed-forward edges.

Phase 5 starts by making skip-style ancestry visible instead of silently dropping it. The current exporter still serializes adjacent-layer dense paths only, so this metadata is an audit seam: it records the exact non-adjacent feed-forward edges that later residual, concat, and attention passes can promote into explicit ONNX graph structure.

Parameters:

Returns: Nothing.

appendConcatMergeMetadata

appendConcatMergeMetadata(
  model: OnnxModel,
  concatMerge: AdvancedGraphConcatMerge,
  includeMetadata: boolean,
): void

Append concat-merge metadata for an emitted explicit concat branch while preserving prior metadata entries. The fallback parsing logic guarantees concat records stay recoverable even after unexpected metadata payload drift.

Parameters:

Returns: Nothing.

appendMetadataProperty

appendMetadataProperty(
  model: OnnxModel,
  metadataProperty: OnnxMetadataProperty,
): void

Append one metadata property to the ONNX model.

Parameters:

Returns: Nothing.

appendResidualAddMetadata

appendResidualAddMetadata(
  model: OnnxModel,
  residualAdd: AdvancedGraphResidualAdd,
  includeMetadata: boolean,
): void

Append residual-add metadata for an emitted one-hop merge while preserving existing metadata arrays deterministically. This keeps advanced graph records append-only and resilient when previous metadata payloads are malformed.

Parameters:

Returns: Nothing.

buildBranchTensorName

buildBranchTensorName(
  context: { sourceLayerIndex: number; targetLayerIndex: number; sourceNodeIndex: number; targetNodeIndex: number; },
): string

Build the reserved branch tensor name for one cross-layer edge.

Parameters:

Returns: Deterministic branch tensor name.

buildConcatMergeNodeName

buildConcatMergeNodeName(
  sourceLayerIndex: number,
  targetLayerIndex: number,
): string

Build the deterministic concat merge node name for one layer pair in the explicit concat-branch subset. Consistent naming makes emitted merge structure easier to audit from metadata and exported graph nodes.

Parameters:

Returns: Concat merge node name.

buildConcatMergeOutputName

buildConcatMergeOutputName(
  sourceLayerIndex: number,
  targetLayerIndex: number,
): string

Build the deterministic concat merge output tensor name for one layer pair used by advanced graph promotion. The output name contract allows import diagnostics to map concat merges back to source and target layers.

Parameters:

Returns: Concat merge output tensor name.

buildLayerIndexByNode

buildLayerIndexByNode(
  layers: default[][],
): Map<default, number>

Build a stable node->layer index lookup for the resolved layered ordering.

Parameters:

Returns: Node-to-layer lookup.

buildMetadataProperty

buildMetadataProperty(
  key: string,
  value: AdvancedGraphCrossLayerConnection[] | AdvancedGraphResidualAdd[] | AdvancedGraphConcatMerge[],
): OnnxMetadataProperty

Build one metadata property with a JSON payload.

Parameters:

Returns: Metadata property.

buildResidualBranchTensorName

buildResidualBranchTensorName(
  sourceLayerIndex: number,
  targetLayerIndex: number,
): string

Build the reserved residual-branch tensor name for one layer pair in the explicit one-hop residual export subset. Deterministic naming keeps metadata, emitted nodes, and import reconstruction aligned across repeated exports.

Parameters:

Returns: Deterministic residual branch tensor name.

buildResidualMergeNodeName

buildResidualMergeNodeName(
  targetLayerIndex: number,
): string

Build the deterministic residual merge node name for one target layer in the residual-add emission path. Stable node identifiers simplify metadata correlation and reduce ambiguity during diagnostics.

Parameters:

Returns: Residual merge node name.

buildResidualMergeOutputName

buildResidualMergeOutputName(
  targetLayerIndex: number,
): string

Build the deterministic residual merge output tensor name for one target layer in advanced graph metadata. The naming contract ensures import-side residual mapping can trace merged outputs without heuristics.

Parameters:

Returns: Residual merge output tensor name.

collectCrossLayerConnections

collectCrossLayerConnections(
  network: default,
  layers: default[][],
): AdvancedGraphCrossLayerConnection[]

Collect deterministic cross-layer feed-forward edges.

Parameters:

Returns: Sorted cross-layer connection descriptors.

collectSourceNodeCrossLayerConnections

collectSourceNodeCrossLayerConnections(
  sourceNode: default,
  layerIndexByNode: Map<default, number>,
): AdvancedGraphCrossLayerConnection[]

Collect cross-layer feed-forward edges from one source node.

Parameters:

Returns: Cross-layer descriptors for this source node.

compareCrossLayerConnections

compareCrossLayerConnections(
  left: AdvancedGraphCrossLayerConnection,
  right: AdvancedGraphCrossLayerConnection,
): number

Keep metadata emission order deterministic.

Parameters:

Returns: Sort comparison result.

createCrossLayerConnectionDescriptor

createCrossLayerConnectionDescriptor(
  sourceNodeInternal: NodeInternalsWithExportIndex,
  sourceLayerIndex: number,
  targetNode: default,
  layerIndexByNode: Map<default, number>,
): AdvancedGraphCrossLayerConnection | undefined

Create one cross-layer descriptor when the target is non-adjacent.

Parameters:

Returns: Descriptor when the edge skips one or more layers.

isAdvancedGraphCrossLayerConnection

isAdvancedGraphCrossLayerConnection(
  descriptor: AdvancedGraphCrossLayerConnection | undefined,
): boolean

Type guard for optional cross-layer descriptors.

Parameters:

Returns: Whether the descriptor exists.

resolveNodeIndex

resolveNodeIndex(
  nodeInternal: NodeInternalsWithExportIndex,
): number

Resolve a stable node export index.

Parameters:

Returns: Stable export index.

resolveOneHopResidualSourceLayerIndex

resolveOneHopResidualSourceLayerIndex(
  currentLayerNodes: default[],
  layers: default[][],
  targetLayerIndex: number,
): number | null

Resolve the single one-hop residual source layer for a target layer.

The first explicit residual-add subset stays narrow and deterministic: exactly one non-adjacent source layer may feed the target layer, and that source must skip exactly one intermediate layer.

Parameters:

Returns: One-hop residual source layer index, or null when the layer stays on fallback.

architecture/network/onnx/export/network.onnx.export-shape-validation.utils.ts

validateOnnxModelShapes

validateOnnxModelShapes(
  model: OnnxModel,
): void

Validate the exporter-owned ONNX tensor ledger before the model leaves the builder.

This validator is intentionally conservative and repo-shaped rather than a full protobuf-level ONNX checker. It understands the operator subset that the exporter already emits and verifies that the graph stays dimensionally coherent across dense, residual, concat, recurrent, spatial, and attention helper paths.

Parameters:

Returns: Nothing.

architecture/network/onnx/export/network.onnx.export-build.quantization.utils.ts

applyDynamicDenseQuantizationGuidancePostProcessing

applyDynamicDenseQuantizationGuidancePostProcessing(
  model: OnnxModel,
  sourceOptions: OnnxExportOptions,
  resolvedQuantization: OnnxResolvedQuantizationOptions,
  recurrentLayerIndices: number[],
): void

Wraps each dense GEMM node with DynamicQuantizeLinear/DequantizeLinear guidance nodes for dynamic UINT8 quantization.

applyStaticConvQuantizationPostProcessing

applyStaticConvQuantizationPostProcessing(
  model: OnnxModel,
  sourceOptions: OnnxExportOptions,
  resolvedQuantization: OnnxResolvedQuantizationOptions,
  recurrentLayerIndices: number[],
): void

Rewrites Conv graph nodes to QLinearConv sequences and appends quantized weight and bias initializers for static INT8 lowering.

applyStaticDenseQuantizationPostProcessing

applyStaticDenseQuantizationPostProcessing(
  model: OnnxModel,
  sourceOptions: OnnxExportOptions,
  resolvedQuantization: OnnxResolvedQuantizationOptions,
  recurrentLayerIndices: number[],
): void

Rewrites dense GEMM graph nodes to QLinearMatMul sequences and appends quantized weight initializers for static INT8 lowering.

applyStaticQuantizationCalibrationPostProcessing

applyStaticQuantizationCalibrationPostProcessing(
  model: OnnxModel,
  sourceOptions: OnnxExportOptions,
  resolvedQuantization: OnnxResolvedQuantizationOptions,
  recurrentLayerIndices: number[],
): void

Appends calibrated static INT8 scale and zero-point initializers to the model graph for each supported layer target.

architecture/network/onnx/export/network.onnx.export-build.storage-fp16.utils.ts

applyStorageFp16PostProcessing

applyStorageFp16PostProcessing(
  model: OnnxModel,
  sourceOptions: OnnxExportOptions,
  recurrentLayerIndices: number[],
): void

Rewrites eligible weight and bias initializers from FP32 to FP16 storage and prepends Cast-to-FP32 bridge nodes.

Generated from source JSDoc • GitHub