Seeded model builders #
Layer constructors draw deterministic initialization seeds from an explicit seed stream.
Model Builders and Seeding #
TorchLean keeps initialization randomness explicit so examples are reproducible.
Layer constructors return nn.M, a deterministic state computation over the initialization seed
stream. Call nn.run seed to construct a model reproducibly.
Note: nn.Sequential lives in Type 2, so it cannot be returned directly from IO. We keep
model building pure by drawing a base seed in IO and then calling nn.run.
Set the global seed used by nn.runGlobal and nn.nextSeed.
Prefer nn.run seed when the seed belongs in the model definition itself.
Instances For
Build global average pooling over the supplied nonempty spatial dimensions without consuming a seed.
Instances For
Seeded builder monad: a state monad over TorchLean.rand.SeedStream.
Instances For
Run a seeded builder starting from a base seed.
Instances For
Lift a pure value into the seeded builder (consumes no seeds).
Instances For
Apply a model independently over an arbitrary collection of leading dimensions.
Instances For
Consume one fresh seed and pass it to k.
Instances For
Build an elementwise ReLU layer without consuming an initialization seed.
Instances For
Build an elementwise SiLU layer without consuming an initialization seed.
Instances For
Build an elementwise GELU layer without consuming an initialization seed.
Instances For
Build an elementwise sigmoid layer without consuming an initialization seed.
Instances For
Build an elementwise hyperbolic-tangent layer without consuming an initialization seed.
Instances For
Build a softmax layer over a tensor shape without consuming an initialization seed.
Instances For
Build a reduction that sums every tensor entry to a scalar.
Instances For
Build a layer that flattens the entire input shape into one vector.
Instances For
Build a layer that preserves the batch axis while flattening each example.
Instances For
Build max pooling over arbitrary spatial rank using the supplied pooling configuration.
Instances For
Build average pooling over arbitrary spatial rank using the supplied pooling configuration.
Instances For
Build an affine layer, consuming independent seeds for its weight and bias initializers.
Instances For
Seeded affine layer with an explicit initialization policy.
Instances For
Vector-only linear layer, specialized to the scalar prefix shape.
Instances For
Construct a linear layer with explicit parameter-initialization seeds.
Instances For
Build a seeded recurrent neural network over a fixed sequence length.
Instances For
Build a seeded gated recurrent unit over a fixed sequence length.
Instances For
Build a seeded Mamba-style state-space sequence layer.
Instances For
Build a seeded long short-term memory layer over a fixed sequence length.
Instances For
Build an arbitrary-rank convolution, allocating separate kernel and bias seeds.
Instances For
Build batch normalization with seeded scale and offset parameters.
Instances For
Build instance normalization with seeded scale and offset parameters.
Instances For
Build group normalization after checking the positive group count and channel divisibility.
Instances For
Build an embedding lookup layer from a freshly seeded embedding table.
Instances For
Build deterministic sinusoidal positional encoding for a batched sequence.
Instances For
Build deterministic rotary positional encoding for multi-head sequence features.
Instances For
Build learned positional embeddings from a freshly allocated parameter seed.
Instances For
Build layer normalization with independently seeded scale and offset parameters.
Instances For
Build seeded multi-head self-attention with an optional fixed attention mask.
Instances For
Build one seeded transformer encoder block, optionally applying a fixed attention mask.
Instances For
Build a seeded stack of transformer encoder blocks with an optional attention mask.
Instances For
Build dropout with a fresh deterministic mask seed from the builder stream.
Instances For
Run a seeded builder using the global seed stream set by nn.manualSeed (results in Type).
Note: model values like nn.Sequential live in Type 2, so they cannot be returned from IO.
For models, use nn.run with an explicit base seed (obtained from nn.nextSeed).
Instances For
Draw a fresh base seed from the global seed stream set by nn.manualSeed.
Instances For
Naming Convenience #
nn.run / nn.nextSeed are the core primitives, but in user code it is often clearer to read:
- “build a model from this seed” (
nn.run) - “draw a fresh init seed” (
nn.freshSeed) - “build a model using the next global init seed” (
nn.withModel)
Draw a fresh base seed from the global seed stream.
Instances For
Build a model using the next global seed, then run a continuation.
nn.Sequential lives in Type 2, so executable code passes the model to a continuation rather than
returning it directly from IO.