Skip to main content

An extension to PyTorch: SNN layers that function on traces.

Project description

traceTorch Banner

License PyPI

traceTorch is a PyTorch-based library built on the principles of spiking neural networks, replacing the PyTorch default backpropagation through time with lightweight, per-layer input traces, enabling biologically inspired, constant time and memory consumption learning on arbitrarily long or even streaming sequences.

Documentation

It is highly recommended that you read the documentation first. It contains:

  1. Introduction: An introduction to traceTorch, how and why it works, it's founding principles. It's thoroughly recommended that you read through the entire introduction and gain an intuitive understanding before proceeding.
  2. Tutorials: Various tutorials to create your own traceTorch models. The resultant code can be found in tutorials/, complete with plotting and display of any useful metrics.
  3. Documentation: The actual documentation to all the modules included in traceTorch. It includes detailed explanations, examples and math to gain a full understanding of how traceTorch works behind the scenes.

Related work & acknowledgements

I built traceTorch from the ground up with the goal of exploring biologically inspired, constant-memory learning for spiking networks. Many projects and papers shaped the ideas here — the following helped the most and deserve acknowledgment.

Acknowledgements

  • snntorch — for introducing me to spiking neural networks and practical SNN tooling. The design choice in snntorch to build full autograd graphs was a helpful contrast that inspired traceTorch’s constant-memory approach.
  • Artem Kirsanov — for accessible presentations on computational neuroscience that influenced my thinking about spiking dynamics and simple, interpretable neuron models.
  • E-prop / eligibility propagation — the idea of maintaining decaying eligibility traces and combining them with modulatory signals heavily inspired the “trace” abstraction in traceTorch. While e-prop aims at approximating full RTRL, traceTorch focuses on a lighter-weight single-lifetime learning pipeline using local traces to obtain the average input and subsequently output for entirely local, small graph backpropagation.
  • Reward-modulated plasticity / three-factor rules — the biological and theoretical literature on reward-modulated STDP and three-factor learning (local eligibility × global reward) shaped the REFLECT concept: keep a lightweight trace and apply credit via a scalar reinforcement signal.

How traceTorch is different

traceTorch sits at the intersection of these ideas but with a different engineering emphasis:

  • Single-Lifetime Learning (SLL): the API and algorithms are designed to learn online during a single continuous run through the data/environment with constant memory usage (no BPTT or replay buffers).
  • Constant-memory trace mechanics: each layer maintains compact decaying traces (inputs, outputs, and log-prob traces) that approximate time-averages; these traces are used to build a tiny differentiable window at the time of update rather than building a long computational graph.
  • Practical policy-gradient for SNNs (REFLECT): a trace-based REINFORCE-style estimator that keeps an averaged log-prob trace of sampled actions and uses it to produce low-variance, correct learning signals for spiking layers.
  • Modular, pluggable design: lightweight LIF/LIS layers, Reflect learning modules, and a Sequential orchestration layer make it easy to build SNNs that learn online while remaining debuggable and serializable (state_dict friendly).

If you’re curious about specific papers: look into e-prop (Bellec et al.), eligibility traces and three-factor learning (Frémaux & Gerstner), and reward-modulated STDP literature (Izhikevich, Florian). These influenced the ideas here and are useful starting points if you want more theory.

Roadmap

  • Create the poisson click test example
  • Make dynamic LR
  • Finish writing the documentation
  • Move tutorial code to separate repository
  • Implement abstract graph based models, not just sequential

Installation

traceTorch is a PyPI library, which can be found here.

You can install it via pip. All the required packages for it to work are also downloaded automatically.

pip install tracetorch

To import, you can just do import tracetorch, although more frequently it will look like this:

import tracetorch as tt
from tracetorch import snn

Usage examples

tutorials/ contains all the tutorial files, ready to run and playtest. The tutorials themselves can be found here.

The tutorials make use of libraries that traceTorch doesn't necessarily use. To ensure that you have all the necessary packages for the tutorials installed, please install the packages listed in tutorials/requirements.txt

cd tutorials/
pip install -r requirements.txt

It's recommended to use an environment that does not have tracetorch installed if using the tutorials, tracetorch/ is structured identically to the library, but is of course a running release.

Authors

Contributing

Contributions are always welcome. Feel free to submit pull requests or report issues, I will occasionally check in on it.

You can also reach out to me via either email or Twitter:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tracetorch-0.3.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tracetorch-0.3.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file tracetorch-0.3.0.tar.gz.

File metadata

  • Download URL: tracetorch-0.3.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for tracetorch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2784edae2751d5977607116ba90345b090cae137c1db8303f4a9a3a4632ed3d3
MD5 8e4907a6722a870a548fde2dbe104e3d
BLAKE2b-256 e4bc08b146c24aaf7576c6d962b81c2caf74855f4086ecc4d396e06df0119c00

See more details on using hashes here.

File details

Details for the file tracetorch-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: tracetorch-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for tracetorch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21d278d334ecff56e2f15309bacb72cde4874d60dc17718f3405a1bb42effaa4
MD5 4e1c89814ccf9665cb14bdc4def6886e
BLAKE2b-256 e7100643959dd88d275d72b8fe9477126d4c64edca2308ebf6af56dbdcad8bb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page