Run locally#
The experiments/ folder of the
ChronoProp repository has one Python
script per figure. Each script trains that figure’s networks from scratch with the
paper’s settings. To redraw the figures without training, use
Reproduce figures; a laptop is enough there.
Requirements#
An NVIDIA GPU with 11 GB of memory or more. The paper trained on 12 GB slices of H100 GPUs, and every script also runs on an 11 GB GeForce RTX 2080 Ti. A CPU runs the scripts too, but too slowly for full runs.
Python 3.10 or newer.
pip install -e .(below) installs PyTorch, NumPy, SciPy, h5py, scikit-learn and matplotlib. The Fig. 2 scripts also need torchvision, whichpip install -e ".[images]"adds.From minutes to about 4 hours of GPU time per network (see Run times).
The scripts cover all of the paper’s runs on SHD, MNIST and Fashion-MNIST, but not those on SSC. Each dataset downloads the first time it is used.
Quick test#
git clone https://github.com/Poirazi-Lab/chronoprop && cd chronoprop
pip install -e .
python experiments/fig3_temporal.py --arch rec --timestep coarse --seeds 1234 --epochs 2 --out runs/test
python experiments/summarize.py runs/test
This trains one recurrent network per method for 2 epochs, in a few minutes, most of
them spent downloading SHD. Each epoch prints its loss, accuracies and duration.
summarize.py then prints, for every condition, the test accuracy at the epoch of
best validation accuracy (mean ± s.d. over seeds) next to the paper’s value, which
2 epochs are far from reaching. The test writes to its own folder, runs/test, so it
never mixes with full runs.
Scripts#
Script |
Figure |
What it trains |
|---|---|---|
|
Fig. 2 |
ChronoProp and BPTT on MNIST or Fashion-MNIST, Δt = 1, 0.5 or 0.1 ms |
|
Fig. 2c–f |
the networks whose time, memory, operations and firing are measured, from 50 to 2,000 steps per image |
|
Fig. 3 |
temporal ChronoProp and BPTT on SHD, feedforward or recurrent, Δt = 1 or 0.1 ms |
|
Fig. 4 |
the same with adaptive neurons |
|
Supp. Fig. 7 |
the same with two-compartment neurons on addSHD |
|
Figs. 5 and 6 |
the network of Fig. 5 at any width and recurrent density, and Fig. 6’s two BPTT networks |
|
Fig. 6 |
training with a hardware defect (HIL), or testing trained networks at every defect level (PTP) |
Full figure runs#
These commands train every network of a figure with the paper’s seeds and epochs.
# Fig. 2
python experiments/fig2_images.py --dataset mnist fmnist --timestep 1.0 0.5 0.1
# Fig. 2c-f; then add --summary to print the cost table
python experiments/fig2_cost.py
# Fig. 3, Fig. 4 and Supp. Fig. 7
python experiments/fig3_temporal.py --arch ff rec --timestep coarse fine
python experiments/fig4a_adaptive.py --arch ff rec --timestep coarse fine
python experiments/fig4b_dendritic.py --arch ff rec --timestep coarse fine
# Fig. 5, and the two BPTT networks of Fig. 6
python experiments/fig5_grid.py --hidden 128 256 512 --density 0 0.25 0.5 0.75 1
python experiments/fig5_grid.py --arm bptt bptt_star
# Fig. 6, training with each defect (HIL)
python experiments/fig6_defects.py train --arm chronoprop bptt bptt_star --defect membrane_noise --level 0.3 0.5 0.75 1 1.5 2 2.5 3
python experiments/fig6_defects.py train --arm chronoprop bptt bptt_star --defect weight_noise --level 0.03 0.05 0.07 0.1 0.15 0.2 0.3
python experiments/fig6_defects.py train --arm chronoprop bptt bptt_star --defect weight_bits --level 2 3 4 5 6 7 8
python experiments/fig6_defects.py train --arm chronoprop bptt bptt_star --defect tau_mismatch --level 0.025 0.05 0.1 0.15 0.2 0.25 0.3
# Supp. Fig. 10, the defect-free networks tested at each defect (PTP), one command per defect
python experiments/fig6_defects.py ptp --arm chronoprop bptt bptt_star --defect membrane_noise
Then python experiments/summarize.py runs/<figure> compares the results with the
paper’s (runs/fig2, runs/fig3, runs/fig4, runs/fig4b, runs/fig5,
runs/fig6). For Fig. 6, the paper’s number is the test at the defect that each run
prints at its end (retest in its results.pkl), as a percentage of the
defect-free network’s accuracy. PTP tests the paper’s released networks, which it
downloads, or your own with --checkpoint, and writes runs/fig6/ptp_<arm>_<defect>.json.
Options#
Options choose what to train; everything else, from the network to the training
schedule, is the paper’s setting. An option given several values runs every
combination, so --arch ff rec --timestep coarse fine trains all four conditions of
Fig. 3. python experiments/<script>.py --help lists a script’s options with
examples.
Script |
Options for the condition |
Default |
|---|---|---|
|
|
MNIST at 1 and 0.1 ms |
|
|
all seven |
|
|
recurrent, 0.1 ms |
|
|
ChronoProp, 512 neurons, density 0.25 |
|
|
|
Option, in every script |
What it sets |
Default |
|---|---|---|
|
|
|
|
|
|
|
|
both |
|
a learning rate in place of the paper’s |
the paper’s |
|
|
a GPU if there is one |
|
the folder for the results |
|
|
the folder for the datasets |
|
|
data-loading processes |
the paper’s |
|
run without TorchScript compilation |
off |
Learning-rate search#
For every condition, the paper trained its seeds at several learning rates (7 in Fig. 2, 5 in Fig. 3, 4 or 5 in Fig. 4, 3 in Supplementary Fig. 7 and Fig. 5) and kept the one with the highest seed mean of peak validation accuracy. Fig. 6 and its two BPTT networks used one learning rate per method. The scripts train only the learning rates the paper kept.
To run the search yourself, add --lr. Each learning rate gets its own folder (for
example chronoprop_lr0.001), and summarize.py prints one row per learning rate
with its seed mean of peak validation accuracy (peak val). As in the paper, keep
the row where it is highest and report its test accuracy.
python experiments/fig3_temporal.py --lr 1e-3
python experiments/fig3_temporal.py --lr 5e-4
python experiments/summarize.py runs/fig3
Run times#
Training times recorded by the paper’s runs, on one 12 GB H100 slice (about a seventh of the GPU), for the networks of Full figure runs:
Script |
Networks |
Hours per network |
GPU hours in all |
|---|---|---|---|
|
120 |
0.1–1 |
36 |
|
42 |
0.03–2 |
22 |
|
80 |
0.4–3.5 |
129 |
|
80 |
not recorded |
not recorded |
|
80 |
0.7–4.3 |
192 |
|
170 |
0.5–3.4 |
311 |
|
870 |
0.5–3.7 |
1,716 |
All |
1,442 |
about 2,500 |
The timestep sets most of the cost. A network at Δt = 0.1 ms takes 5–9 times longer
than at 1 ms, and BPTT always takes longer than ChronoProp. Fig. 4 did not record its
times; expect about those of Fig. 3, as the total does. PTP trains nothing and takes minutes. On your
own GPU, a run with --epochs 2 gives the time of one epoch; multiply it by the
number of epochs (120 in Fig. 2, 60 in Fig. 2c–f, 500 in Supplementary Fig. 7, 400 elsewhere).
Expected results#
On the paper’s GPU and software, a script repeats the paper’s run for each seed,
epoch by epoch. Elsewhere the random numbers (initial weights, the order of the
examples, input spikes) and the rounding differ, because they depend on the GPU
model and on the versions of PyTorch and CUDA; running uncompiled (--eager) also
changes the rounding on a GPU. Each run then takes its own course from the first
epoch. A single seed ends up away from the paper’s value, while the mean over the
seeds should come close to the paper’s mean.
Before release, each script ran next to the paper’s code on the PC below, with the same settings and seed, and every epoch came out identical.
The paper’s runs |
Our check |
|
|---|---|---|
GPU |
NVIDIA H100 NVL, one MIG slice (1g.12gb) |
NVIDIA GeForce RTX 2080 Ti |
PyTorch |
2.6.0 |
2.4.1 |
CUDA |
12.6 |
12.1 |
Machine |
the lab’s SLURM cluster |
a desktop PC (Intel Core i7-9700) |
The paper’s versions are those recorded by the runs of Figs. 2 and 3 and Supplementary Fig. 7; the runs of Figs. 4 to 6 recorded none. To come as close as possible to the paper’s runs, install PyTorch 2.6.0 built for CUDA 12.6 (and its torchvision) before ChronoProp.
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu126
The paper’s runs, and every check above, compiled the networks with TorchScript.
PyTorch has since deprecated TorchScript, and recent versions (such as 2.14, which
Colab uses) can no longer compile the surrogate gradient of the BPTT baseline. Every
neuron model contains it, so no network compiles there, ChronoProp’s included.
ChronoProp then runs the networks uncompiled and says so once. The results are the same up to rounding, but a run no
longer repeats the paper’s epoch by epoch, and it can be slower. We plan to port the
code to torch.compile, PyTorch’s new compiler.
Resuming and parallel runs#
Starting a command again resumes every unfinished run from its last epoch and skips
the finished ones (done already); a new --out folder starts over. One command
trains its networks one after the other. To use several GPUs, start one command per
seed (--seeds 1234, --seeds 5678, …) with the same --out, after the first test
has downloaded the data. Each run writes a results.pkl with its settings and its
losses and accuracies per epoch, in a folder named after its condition, its seed and,
with --lr, its learning rate.
To repeat the paper’s runs, keep the default --workers as well. The input jitter of
Figs. 5 and 6 is drawn in the data-loading workers, so it changes with their number.