Random Seeds #
Deterministic RNG helpers.
TorchLean treats randomness explicitly (via seeds/keys) so examples are reproducible.
PyTorch mapping:
torch.Generatorand seed managementtorch.rand/ Bernoulli masks for dropout
Deterministic seed stream (seed + monotone counter).
This is intended for model construction (parameter init keys, dropout keys, etc.) where you want PyTorch-like ergonomics but reproducible results.
- seed : ℕ
Base seed (think
torch.manual_seed). - counter : ℕ
Monotone counter mixed with the base seed for each draw.
Instances For
Instances For
Create a fresh stream from a base seed.
Instances For
Draw a fresh seed and advance the stream.
Implementation: we reuse Spec.Random.nextSeed as a small deterministic mixing function.
Instances For
State monad for deterministic seed allocation.
Lean's StateT/StateM ties the state/result universes together, while TorchLean model definitions
(e.g. nn.Sequential) live above Type 0.
This pure state-function representation preserves the result universe, including the higher universe used by model definitions.
Instances For
Global seed stream used by rand.runGlobal and nn.withModel.
This is a convenience for script-like code that wants PyTorch-style "set the seed once" ergonomics.
In proofs and reproducibility-sensitive code, prefer the pure interfaces (nn.build) and pass the
base seed explicitly.
Reset the global seed stream.
PyTorch analogue: torch.manual_seed.
Instances For
Draw one fresh seed from the global seed stream.