This repository contains the official implementation for the paper "Spike-based alignment learning solves the weight transport problem" (Gierlich et al., 2025, arXiv:2503.02642).
The paper presents a solution to the well-known weight transport problem -- a long-standing problem in computational neuroscience and neuromorphic computing. Many well-established learning algorithms from machine learning such as backpropagation require some form of weight symmetry, which effectively means that weight information has to be copied from one synapse to another -- an operation that violates locality in physical computing.
In our paper, we present spike-based alignment learning (SAL), a missing piece for constructing purely local online learning rules for both the brain and brain-inspired spiking hardware.
This repository contains the python code to reproduce the experiments presented in the paper. We demonstrate the effectiveness of SAL in various families of models:
- Spiking sampling networks (SSN): In this spiking model for brain-inspired Bayesian inference, we show that SAL increases the robustness against parameter and plasticity noise
- cortical microcircuits: In a spiking model for physically plausible error transport, SAL enables the alignment of feedback weights to the forward pathway, thus allowing the backpropagation of correct learning signal.
- Deep convolutional networks: A standard image classification task serves as framework to benchmark SAL against other spiking and non-spiking weight symmetrization algorithms
The software is purely written in Python (>= 3.11) and requires the packages listed in requirements.txt.
- Modern multicore CPU with 8 cores and >8GB RAM
- For the SymmNet (deep learning) experiments, we recommend a GPU (the experiments in the paper were executed on Nvidia RTX4090)
Typical setup time: ca. 5 min
- Clone the repo.
- Set up your local Python environment using your favorite tool:
- The code is tested for python versions >= 3.11 only.
- Using
venv:python -m venv <name_of_env>and activate it:source ./<name_of_env>/bin/activate - Or using
conda:conda create -n <name_of_env> --no-default-packages(it's recommended to add the python version: python=3.X) and activate it:conda activate <name_of_env>
- install the dependencies:
python -m pip install -r requirements.txt - Register the ipykernel with
python -m ipykernel install --user --name <name-of-env> - Install the pip package for the STDD-calculator:
python -m pip install -e stdd_calculator. This installs the packagestddc. - Install the pip package for the spiking sampling network:
python -m pip install -e spiking_sampling_network. This installs the packageneuralsampling. - Install the pip package for the spiking microcircuits:
python -m pip install -e spiking_microcircuits. This installs the packagemicrocircuits. - Install the pip package for the SymmNet deep-learning experiments:
python -m pip install -e symmnet. This installs the packagesymmnet.
The scripts for executing the experiments are located in scripts/.
- The spike-timing difference distributions (fig. 2c) are generated by the jupyter notebook
scripts/sal_principle/stdd.ipynb. - The weight evolution of the two neuron system (fig. 2d) and the phase plane diagram (fig. 2e) is generated by the jupyter notebook
scripts/sal_principle/ppd.ipynb.
A minimal working example for a simulation of a spiking sampling network is provided by scripts/ssn/train_bm.py and the corresponding parameter file minimal_working_example.yaml. It can be executed by python train_bm.py minimal_working_example.yaml; the results are stored in results/minimal_working_example/
To reproduce the raw data for figure 4 and 5, the scripts and directories in scripts/ssn are available. A single simulation can be executed on a single CPU core and typically takes 30 minutes. For each of the six experiment types (i.e. synaptic noise and plasticity noise scenario each with and without SAL and Kolen-Pollack), a total of 120 independent runs are required. We therefore recommend the simulations to be run in parallel on a HPC cluster. The raw data is then saved in the folder results.
Each subdirectory of scripts/ssn/ contains a exp.yaml parameter file and a change_params.py python script.
- Run
bash run.shto start the simulations. It will first callchange_parameters.pyand then spawn the simulations. - The raw data can be plotted with
scripts/ssn/plot_fig.ipynb.
A minimal working example for a simulation of a spiking microcircuits student teacher network is provided by scripts/microcircuits/train_mc.py and the corresponding parameter file example.yaml. It can be executed by python train_mc.py example.yaml.
To reproduce the raw data for figure 6, follow the same steps as for the sampling networks.
- In each subdirectory of
scripts/microcircuits(i.e.bpfor backpropagation,fafor feedback alignment,salfor SAL), executerun.sh. This creates the parameter YAML files for 20 runs with individual seeds and spawns 20 parallel processes. A single simulation takes ca. 4 hours to finish. The raw simulation results are stored inresults/microcircuits. - The raw data can be plotted with
scripts/microcircuits/plot_fig.ipynb.
To reproduce the data and plots for figure 7 (i.e., the weight scatter plots comparing two layers symmetrized by SAL, RDD and STDWI), execute the notebook scripts/symm_net/scatter_stdwi_rdd_sal.ipynb.
A minimal working example for the deep learning experiment is provided by scripts/symm_net/main_salnet.py and the corresponding parameter file exp_settings.yaml.
As forward training of the convolutional neural networks is implemented in pytorch, we highly recommend to use a GPU.
Usage: python main_salnet.py -f exp_settings.yaml -s <type_of_experiment> --dataset <dataset> --tags <tag1,tag2>
type_of_experiment: choose the learning algorithm (equivalent to the section names inexp_settings.yaml)dataset: choose one the following datasets:cifar10,svhn,mnist,fmnist- optionally, you can pass a list of descriptive tags to keep track of your runs.
Typical execution time per run: ~15 min (BP/FA/KP), ~30–45 min (SAL), ~2 h (RDD).
For conveniently reproducing any of the data shown in figure 8, we provide two workflows:
sweep.py: suitable for small-scale parameter sweeps. It directly launches the required sub-processes. Example usage:python sweep.py --datasets cifar10 --algos bp fa sal. Seepython sweep.py --helpfor all available settings.- For large scale parameter sweeps (for instance to reproduce the 105 runs for all datasets, algorithms and seeds) on an HPC cluster (with SLURM), we provided the following workflow that needs only minimal adaptation to the available system.
- Run
sweep_creator.py: It createsjobs.shwhich contains allmain_salnet.py-calls with the relevant settings. Seepython sweep_creator.py --helpfor all available settings (the default settings will rerun the original simulations). - Modify
slurm.shto specify the relevant settings for your HPC cluster. - Run
bash slurm_submit.sh. It will callslurm.shinternally and start a SLURM array job. - The data can be plotted with
scripts/symm_net/plots.ipynb
- Run
A minimal working example for the time evolution of SAL in the SALNet is provided by scripts/symm_net/salnet_symm.py.
Example usage: python salnet_symm.py --lr 0.01 --n_epochs 200 --len_epoch 500.
For conveniently reproducing the data shown in figure 9, we provide the same workflows as explained above with the files sweep_symm.py for quick small-scale scans and sweep_creator_symm.py to launch all 20 runs as a SLURM array job.
The "Dale's law" experiment can be reproduced by scripts/dales_law/EI-system.ipynb.
The data for figure 11 can be reproduced by scripts/psp_shapes.ipynb. Note that this notebook typically requires a lot of memory (> 8GB).
Figure 12 can be reproduced by scripts/plots_for_proof.ipynb.
The test suite lives in tests/ and is run with pytest.
It contains two layers of tests:
Fast smoke tests (run automatically in CI, no GPU required):
pytest tests/These verify that all four packages import correctly and that main_salnet.py, traim_mc.py and train_bm.py complete a minimal
run without errors.
PyTorch training tests (opt-in, GPU recommended):
pytest tests/ --pytorch # bp section only (default)
pytest tests/ --pytorch --sections bp,fa,sal # specific subset
pytest tests/ --pytorch --sections all # test all seven algorithms These run main_salnet.py end-to-end for one epoch per selected algorithm
section. They are skipped by default because they require PyTorch CNN training.
See CHANGELOG.md for a full version history and changes between arXiv versions.
