GraphSpec DAG model wrappers #
This module packages typed terms and blocks as parameterized single- and multi-output models, with pure forward semantics, inlining theorems, and executable program conversion.
Model wrapper #
A small “model” wrapper around DAG terms.
This mirrors the sequential Chain surface:
psare parameter tensor shapes (tracked at the type level),insare the shapes of non-parameter inputs (e.g. data tensors),τis the output shape.
The model body is a Term (ps ++ ins) τ, i.e. it expects an environment that starts with
parameters and then contains the actual inputs.
- initParams : TorchLean.TensorPack Float ps
Initial parameter values, one tensor per shape in
ps. Shipping the initialization with the model means aModelis runnable on its own, with no separate setup step. The computation itself, as a term over the environment
ps ++ ins: parameters first, then data inputs. That fixed ordering is what letsinitParamsbe typed bypsalone.
Instances For
Inline a model body into a larger graph using explicit parameter and input terms.
The result is still an ordinary DAG term: no primitive boundary is introduced, and subsequent lowering, differentiation, or numerical analysis can inspect every operation of the model.
Instances For
Pure forward semantics of a DAG model.
We build the full environment Γ = ps ++ ins by appending the parameter list and the input list,
then evaluate the body using Term.eval.
Instances For
Inlining a model into a larger DAG preserves the model's pure forward semantics.
Lower a DAG model to an execution-polymorphic TorchLean program.
The resulting program expects arguments in the order ps ++ ins (parameters first, then inputs),
matching the environment discipline used by specFwd.
Instances For
Models with several outputs #
A typed DAG model that returns several tensors.
Recurrent layers commonly return both an updated state and an observable output. Keeping these as
a typed list preserves their individual shapes and avoids flattening unrelated tensors into an
untyped buffer. The block body uses shared let1 bindings, so an updated state can be computed once
and returned alongside values derived from it.
- initParams : TorchLean.TensorPack Float ps
Default parameters, in the same ABI order used by
body. Shared computation ending in one well-typed term for every output shape.
Instances For
Inline a multi-output model into a larger graph.
Shared let bindings in the original block remain shared after substitution, so recurrent state
updates are not duplicated when both the state and a derived output are returned.
Instances For
Pure reference semantics of a multi-output DAG model.
Instances For
Inlining a multi-output model preserves every output and every shared intermediate in its pure reference semantics.
An execution-polymorphic program returning several shape-indexed tensor references.
Instances For
Lower every result of a multi-output model for the selected TorchLean execution target.