TorchLean API

NN.GraphSpec.ToSequential

GraphSpec to Sequential Models #

This module converts a GraphSpec Chain to a TorchLean NN.Seq when every primitive supplies a Layer representation. The conversion packages deterministic parameter initialization and the parameter ABI expected by the sequential trainer.

This is a partial adapter, not the general GraphSpec execution path. Chain.toProgram interprets every supported GraphSpec primitive through the operation-polymorphic TorchLean.Program interface, including primitives with no Layer. By contrast, ToSequential.toSeq returns Except String and rejects a chain at the first primitive without a sequential-layer view.

The adapter threads a primitive occurrence index through the chain. Deterministic initializers use that index to derive stable per-layer seeds; the index is not part of GraphSpec's mathematical semantics.

Related modules:

For g : Chain ps σ τ:

Lower a chain to a TorchLean Seq, threading a “layer occurrence index”.

The index is incremented for primitives with countsAsLayer = true.

Instances For

    Try to lower a GraphSpec chain into a Runtime.Autograd.Model.Layers.Seq.

    Use this when you specifically want the Seq wrapper for training ergonomics. If all you need is an executable program, prefer Chain.toProgram: it is the more general path and does not require every primitive to have a Layer view.

    Instances For