Runtime Core #
Core exports for NN.API.TorchLean: execution options, tensor operations, losses, optimizers,
RL helpers, sequential model types, and deterministic runtime RNG helpers.
Core Exports #
Most of this namespace is a curated re-export of _root_.Runtime.Autograd.TorchLean.*, so users can
import NN.API.Runtime and get a stable API surface without chasing implementation modules.
The exported names fall into these groups:
- execution control:
Backend,Options - program interface:
Ops,RefTy,Program,CompiledOut,CompiledScalar, ... - primitive tensor ops:
add,matmul,reshape, elementwise activations, pooling, ... - training utilities:
trainCycle*,meanLoss
Public name for TorchLean's shape-indexed tensor-pack / typed tuple representation.
Instances For
Construct a one-tensor pack.
Instances For
Construct a two-tensor pack.
Instances For
Construct a three-tensor pack.
Instances For
Construct a four-tensor pack.
Instances For
Unpack a 2-element RefList into a pair.
Instances For
Optimizer Handles (PyTorch-Like) #
TorchLean optimizers are purely functional in their state: opt.step returns a new state.
This small wrapper stores the optimizer state in an IO.Ref so users can write:
let h ← API.TorchLean.Optim.handle m (TorchLean.Optim.sgd lr)
h.step sample
without manually threading the optimizer state through the training loop.
A mutable optimizer handle bound to a concrete TorchLean ScalarModule.
The optimizer state is stored in an IO.Ref and updated when you call h.step sample.
- module : Runtime.Autograd.TorchLean.ScalarModule α paramShapes inputShapes
The module whose parameters will be updated in-place.
- state : IO.Ref State
Mutable optimizer state.
One training step on a single sample, updating the optimizer state.
Instances For
Create an optimizer handle for a module by initializing optimizer state from the module's current parameters.
Instances For
Adapter typeclass used by the seq! macro to treat both layers and already-sequential models as
composable building blocks.
This exists purely for ergonomics: it lets examples mix LayerDef and Seq in the same seq!
expression without relying on Lean's coercion insertion heuristics.
- asSeq {σ τ : Spec.Shape} : F σ τ → Seq σ τ
Convert a layer-like thing into a
Seqsoseq!can compose it.
Instances
A single LayerDef can always be viewed as a 1-layer sequential model (seq1).
A sequential model is already a sequential model (identity).
Compose either layers or sequential models without relying on coercions.
This is the helper used by the seq! ... macro so examples can write
seq! layer1, model2, layer3 while still mirroring PyTorch's "stack layers" style.
Instances For
Deterministic RNG helpers re-exported for runtime callers.
These are deterministic utilities used by examples and training loops (keyOf, nextSeed,
uniform, mask).