TorchDyno is a PyTorch library for building models of temporal data from interchangeable parts, and training them with or without backpropagation. Reservoirs, state space models, oscillator and continuous-time networks, and random convolutions are all plain nn.Sequential compositions. Fit them with ridge regression, recursive least squares, FORCE, intrinsic plasticity or gradient descent.
TorchDyno is designed for researchers and practitioners studying unconventional recurrent models and learning rules.
Key features
- Compose models: a model is an
nn.Sequentialof parts from four levels: weight matrices, sequence processing, readout and objectives. Each part is replaceable on its own. - Structure the weights: use dense, diagonal, block-diagonal and skew-symmetric matrices, each with its own initialisers and spectral scaling.
nn.Linearworks anywhere a matrix is expected. - Process sequences: run any recurrent cell step by step or with a parallel scan, use ROCKET and MiniRocket kernels, and combine layers in series, side by side, residually, reversed or in a closed loop.
- Fit without gradients: use closed-form and online learners, alone or chained, next to backprop.
- Handle real data: feed sequences of different lengths in one batch, and run benchmarks across seeds on NARMA, Mackey-Glass, Lorenz, memory capacity and UCR/UEA data.
Fitted and trained
Fitted readouts freeze the dynamics and fit only the readout:
- in closed form, with ridge regression;
- online, with recursive least squares or FORCE.
Intrinsic plasticity can adapt a reservoir first, without gradients. Nothing is backpropagated through time, so a fit takes seconds.
End-to-end training trains every parameter that requires a gradient. Freeze any part with requires_grad_(False) to train the rest around it. The benchmark guide compares the two on the same model and seeds.
Installation
TorchDyno is available on PyPI and requires Python >=3.11,<3.15. Install it with pip:
pip install torchdyno
Or add it to a uv project:
uv add torchdyno
PyTorch is installed with it. See the installation guide to choose a CPU or CUDA build, and for development setup.
Quickstart
Save this as quickstart.py. It builds an echo state network, a frozen random reservoir with a linear readout, and forecasts the Lorenz system one step ahead. Ridge regression fits the readout, keeping the penalty that scores best on the validation split.
from torch import nn
from torchdyno import seed_all
from torchdyno.benchmark import lorenz_benchmark
from torchdyno.learners import Ridge, evaluate
from torchdyno.matrices import Dense, spectral, uniform
from torchdyno.sequence import LeakyCell, Recurrent
seed_all(0)
data = lorenz_benchmark(length=2000, target_delay=1, washout=100)
reservoir = Recurrent(
LeakyCell(
input=Dense(3, 300, init=uniform(1.0)),
recurrent=Dense(300, 300, init=spectral(uniform(1.0), 0.9)),
leak=0.5,
)
).requires_grad_(False)
esn = nn.Sequential(reservoir, nn.Linear(300, 3))
result = Ridge(
l2=[1e-8, 1e-6, 1e-4],
washout=data.washout,
score_fn=data.task.primary,
).fit(esn, data.train_loader, data.val_loader)
print("chosen l2:", result.best)
nrmse = evaluate(esn, data.eval_loader, data.task.primary, washout=data.washout)
print(f"test NRMSE: {nrmse:.2e}")
The Dense matrices take their initialisers: spectral rescales the recurrent matrix to a spectral radius of 0.9. Recurrent runs the leaky cell over time, and the washout leaves out the first 100 steps, while the reservoir forgets its initial state.
Run it:
python quickstart.py
It prints the chosen penalty with its validation score, then the test error:
chosen l2: {'l2': 1e-08, 'score': 0.0002468338643666357}
test NRMSE: 4.89e-06
The last digits can differ across machines and PyTorch versions.
To adapt this experiment, swap any part on its own:
- a ring reservoir with
init=cycle(0.9); - three reservoirs in a
Stack; IntrinsicPlasticitychained before the ridge readout.
Continue with reading out a reservoir and training a model end to end.
Examples
Each example composes a well-known model from TorchDyno's parts, fits it and prints its score, in seconds:
- Reservoirs:
- Online learning:
- Trained recurrent models:
- State space models:
- Random convolutions:
- Comparisons: readout, frozen and trained, one model trained three ways on the same seeds.
Runnable source is available in examples/. Run one from the repository root with python -m examples.<name>, for example python -m examples.esn.
Documentation
- Getting started: a reservoir read out by ridge, a model trained end to end, and benchmarks across seeds.
- Core concepts: matrices, sequence processing, readout, objectives and learners.
- API reference: public modules and interfaces.
- Changelog: release history.
Contributing
See CONTRIBUTING.md for development setup, tests, documentation checks, and pull request guidelines.
Remarks
If you use TorchDyno in your work, cite it with the metadata in CITATION.cff, or with GitHub's Cite this repository button.
TorchDyno is released under the MIT License and maintained by Valerio De Caro. To get in touch, drop me an e-mail!
Metadata
Release files for torchdyno 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torchdyno-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for torchdyno-0.3.0-py3-none-any.whl |
Release files / torchdyno-0.3.0-py3-none-any.whl
| Download URL | torchdyno-0.3.0-py3-none-any.whl |
|---|---|
| Size | 80.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
727086f67cc16ba6f8a36e80f7f91c975d87661715d24453cb15203e80d10a23
|
|
BLAKE2b-256 checksum How to use checksums |
3371354e7477d3b6996668737edf3440d8cc0be089436f7854342a9d1b1bb4fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for torchdyno 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.