API Rand #
Deterministic RNG helpers.
TorchLean treats randomness explicitly (via seeds/keys) so examples are reproducible.
PyTorch mapping (rough):
torch.Generatorand seed managementtorch.rand/ Bernoulli masks for dropout
Convenience wrappers for "PyTorch-like" dimension-first workflows.
uniform / mask are shape-indexed (Tensor α s) and are best used when s is already inferred.
When you start from a runtime dims list (e.g. CLI args), uniformND/maskND are the ergonomic
bridge.
Dimension-first wrapper: uniform random tensor at runtime dims.
Instances For
Dimension-first wrapper: Bernoulli keep-mask at runtime dims (useful for dropout-style masks).
Instances For
Deterministic uniform tensor at runtime dims, using (seed,counter) to derive a key.
Instances For
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 (ensures each draw is distinct).
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 TorchLean.Random.nextSeed as a small deterministic mixing function.
Instances For
Draw n fresh seeds.
Instances For
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.
So we define this seed builder directly (as a pure state monad), and run it in Type 2, which is
sufficient for the public API.
Instances For
Global seed stream used by rand.runGlobal / nn.runGlobal.
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.run) 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.