Skip to main content

A strict, ergonomic, and powerful library for SNNs, RNNs and SSMs in PyTorch.

Project description

traceTorch Banner

Documentation PyPI version License GitHub issues PyPI Downloads

traceTorch

traceTorch is a PyTorch library for stateful recurrent layers, built primarily for spiking neural networks.

It gives you SNN, RNN, and SSM-style layers that behave like ordinary PyTorch modules: one tensor in, one tensor out, hidden states kept inside the layer. The difference is that those hidden states are still easy to manage. Inherit from tt.Model, call zero_states(), detach_states(), save_states(), load_states(), TTcompile(), or TTdecompile(), and traceTorch handles every traceTorch layer buried inside the model.

pip install tracetorch
import torch
from torch import nn
import tracetorch as tt


class Net(tt.Model):
    def __init__(self):
        super().__init__()
        self.net = nn.Sequential(
            nn.Flatten(),
            nn.Linear(784, 128),
            tt.snn.LIB(num_neurons=128),
            nn.Linear(128, 10),
            tt.snn.LI(num_neurons=10),
        )

    def forward(self, x):
        return self.net(x)


model = Net()
model.zero_states()
out = model(torch.rand(32, 1, 28, 28))

Why traceTorch?

  • Hidden states stay hidden. Layers own their states, so model code stays readable.
  • State management is explicit. Reset between sequences with zero_states(), truncate history with detach_states(), and save/load hidden states when needed.
  • SNNs are first-class. tt.snn contains 32 leaky-integrator-based layers with binary, ternary, scaled ternary, continuous, dual, synaptic, and recurrent variants.
  • PyTorch composition stays normal. Put traceTorch layers inside nn.Sequential, CNNs, MLPs, and custom PyTorch modules.
  • Feature dimensions are configurable. Use dim=-1 for MLP features, dim=-3 for image channels, or any other target dimension.
  • Parameters can be scalar, per-neuron, fixed, learnable, or tensor-initialized.

Layer Families

Module Layers
tt.snn LI, LIB, LIT, LITS families, including dual (D), synaptic (S), recurrent (R), and combined variants
tt.rnn SimpleRNN, LSTM, GRU
tt.ssm S4, S5, S6, Mamba adapted to traceTorch's one-timestep recurrent interface

traceTorch's main focus is SNN experimentation. The RNN and SSM layers exist because the same state-management design is useful there too, but the SSM implementations are not meant to replace the official optimized sequence-parallel versions.

Documentation

Read the full documentation at https://yegor-men.github.io/tracetorch/.

Recommended path:

  1. Installation: install the package or editable repository.
  2. Quickstart: build and train a minimal traceTorch model.
  3. Introduction: understand the state model, SNN naming scheme, and design choices.
  4. Examples: follow MNIST and Heidelberg Digits examples from examples/.
  5. Tutorials: learn saving/loading states, compiling/decompiling, and custom layer creation.
  6. Reference: inspect API docstrings.

Examples

Runnable examples live in examples/.

git clone https://github.com/Yegor-men/tracetorch.git
cd tracetorch
pip install -e .

cd examples/mnist
pip install -r requirements.txt
python rate_coded.py

Current examples:

  • examples/mnist/rate_coded.py: rate-coded MNIST over repeated Bernoulli timesteps.
  • examples/mnist/sequential.py: MNIST as a patch sequence.
  • examples/mnist/noisy.py: MNIST with noisy repeated observations.
  • examples/heidelberg_digits/main.py: Spiking Heidelberg Digits with Tonic.

These examples are written to show traceTorch mechanics clearly. They are not tuned as benchmark or SOTA training recipes.

Development Status

traceTorch is approaching its v1.0.0 release. The current focus is documentation, tests, examples, and API polish.

Author

Created by Yegor Menovchshikov.

License

MIT.

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.19.2.tar.gz (38.6 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.19.2-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tracetorch-0.19.2.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for tracetorch-0.19.2.tar.gz
Algorithm Hash digest
SHA256 480633ffcebce44aee53d4f798b802205c6e727783807ce8ab355588c6a9b44a
MD5 101c48a8cc76597289250900667f6d20
BLAKE2b-256 87634cd4d35b91273ae613819f559be6d74dfe54b16e61b1139fc16c75b86f77

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tracetorch-0.19.2-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for tracetorch-0.19.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc249b68f1eccf40f9c1d0fbf1abc2c77c62a9f08ca18489fc09fdc9d60e0ed
MD5 775c4f0864b1d6fa25da09cf75eddf31
BLAKE2b-256 cd2af4b89dff9d905abae52a492e7d1494dab050ce26c149ca09ccc4da057ad3

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