Examples#
Runnable example scripts live in the examples directory. The top-level scripts are grouped by filename prefix:
0xx-for spiking neural network examples1xx-for rate-based recurrent neural network examples
The directory also includes two tutorial-style example series:
examples/pp_prop/forbraintrace.pp_prop/ES_D_RTRLexamplesexamples/drtrl/forbraintrace.D_RTRLexamples
Most scripts can be run directly. For example:
python examples/001-gif-snn-for-dms.py
Spiking Neural Networks#
000-lif-snn-for-nmnist.py - Trains a recurrent LIF-delta SNN on the N-MNIST dataset, using framed event inputs from
tonicand the sharedOnlineTrainerimplementation based onIODimVjpAlgorithm.001-gif-snn-for-dms.py - Trains a GIF recurrent SNN on a delayed matching-to-sample task generated by
DMSDataset, using the sharedOnlineTrainerbased onIODimVjpAlgorithmfor online learning.002-coba-ei-rsnn.py - Trains an excitatory/inhibitory recurrent SNN on an evidence-accumulation task, with configurable CUBA or COBA synapses and online learning via
ES_D_RTRLorD_RTRL.003-snn-memory-and-speed-evaluation-all.py - Runs a synthetic benchmark over multiple sequence lengths and compares BPTT,
ES_D_RTRL, andD_RTRLin terms of training time and memory usage.003-snn-memory-and-speed-evaluation-batched.py - Trains and benchmarks an SNN on the DVSGesture dataset with the online algorithms running in
brainstate.mixin.Batching()mode, reporting accuracy, speed, and memory.003-snn-memory-and-speed-evaluation-vmap.py - Trains and benchmarks the same DVSGesture setup while keeping per-sample states under
vmap, reporting accuracy, speed, and memory.004-feedforward-conv-snn.py - Builds a feedforward convolutional SNN with
braintrace.nn.Conv2d,LayerNorm, IF neurons, andLeakyRateReadout. By default it trains on N-MNIST, and the script also includes SHD data loading plus both online and BPTT trainers.
Rate-Based Recurrent Neural Networks#
100-gru-on-copying-task.py - Trains a GRU on the copying task and compares online learning with
ParamDimVjpAlgorithmagainst BPTT.101-integrator-rnn.py - Trains a
MiniGRU-based RNN to integrate a white-noise input signal and compares onlineD_RTRLwith BPTT while plotting predictions and training losses.
Tutorial Series#
pp_prop/ - A tutorial-linear example suite for
braintrace.pp_prop(ES_D_RTRL/IODimVjpAlgorithm). The series covers neuron-model variants, batching withvmapversus batched primitives, single-step versus multi-step VJPs, sparse/LoRA/convolutional operators, Poisson-MNIST classification, anddecay_or_ranksweeps. Seeexamples/pp_prop/README.mdanddocs/tutorials/pp_prop.md.drtrl/ - A tutorial-linear example suite for
braintrace.D_RTRL. The series covers integrator basics, batching modes, VJP variants, LoRA and convolutional operators, row-scan MNIST classification, toy character-level language modeling, and thefast_solveplusnormalize_matrix_spectrumknobs. Seeexamples/drtrl/README.mdanddocs/tutorials/drtrl.md.
Supporting Files#
README.md - Brief overview of the examples directory and its extra Python dependencies.
snn_models.py - Shared SNN model and trainer definitions used by the
000and001examples.utils.py - Shared command-line parser utilities used by the
003-*benchmark scripts.