Skip to main content

Brain-inspired torch utilities and models for neuromorphic research.

Project description

Btorch

English | 简体中文

PyPI version Python versions CI Coverage Docs License Ruff

Brain-inspired differentiable PyTorch toolkit for neuromorphic and computational neuroscience research.

Use btorch if you need:

  • Recurrent SNN modelling
  • stateful neuron/synapse modules with explicit memory handling
  • practical support for sparse/connectome-style network structure
  • torch native training features (torch.compile, checkpointing, truncated BPTT)
  • solid runtime performance and ONNX export support
  • connectome import/export via SONATA, and flexible network definition coming soon

Heavily influenced by brainstate. Evolved from spikingjelly. We thank the developers of both libraries for the inspirations.

Enhancement from spikingjelly:

  • heterogenous parameters
  • enhanced check of shape and dtype of register_memory
  • torch.compile compatibility
  • gradient checkpoint and truncated BPTT
  • Sparse connectivity matrix
  • More neuron and synapse models
  • Memory state with static size and managed by torch buffer
    • onnx export is easy (note: sparse matrix is not supported by onnx)

Installation

pip/uv

Install the latest released package from PyPI:

pip install btorch

or

uv pip install btorch

conda or mamba

conda env create -n ENV_NAME -f https://github.com/Criticality-Cognitive-Computation-Lab/btorch/raw/refs/heads/main/environment.yml

Install from source control

Btorch is fast evolving. If you want the latest unreleased changes, install directly from the repository:

pip install git+https://github.com/Criticality-Cognitive-Computation-Lab/btorch.git

Gitee mirror alternative:

pip install git+https://gitee.com/alexfanqi/btorch.git

For setup instructions, see docs/installation.md.
For development workflow and contributing guidelines, see docs/development.md.

Documentation

Live docs: https://criticality-cognitive-computation-lab.github.io/btorch/

Documentation is built with Zensicle and mkdocstrings for API auto-generation from docstrings.

Build locally:

python scripts/docs.py command=build-all

The generated site is written to site/.

Preview a specific language:

python scripts/docs.py command=live language=en

If you want a clean rebuild:

rm -rf site/
python scripts/docs.py command=build-all

Skills

The skills/ directory contains usage patterns and tips for using btorch with AI agents. Install them with npx skills:

npx skills add https://github.com/Criticality-Cognitive-Computation-Lab/btorch/tree/main/skills/btorch-snn-modelling

Road Map

  • support multi-dim batch size and neuron
  • cleaner connectome import, network param management and manipulation lib
    • support full SONATA format (both BlueBrain and AIBS variants)
    • flexible like neuroarch and tiny to integrate. thinking about using DuckDB
  • verify numerical accuracy. align with Neuron and Brainstate
  • support automatic conversion between stateful and pure functions
    • similar to make_functional in torchopt
    • consider migrate to pure memory states instead of register_memory. gradient checkpointing + torch.compile struggles with mutating self
  • sparse matrix multiplication optimisation on GPU
  • large scale multi-device training and simulation
    • integrate large-scale training support with torchtitan
    • work distribution and balancing
  • compat with neurobench, Tonic
  • NIR import and export

Design and Development Principles

  • provide solid foundation of stateful Modules
  • usability over performance, simple over easy, and customizability over abstractions
    • single file/folder principle on network model
    • see Diffusers' philosophy
    • WIP to align current implementation with these principles

Contributors

alexfanqi
alexfanqi

💻
CFXTGJD
CFXTGJD

💻
gaozh0814
gaozh0814

💻
msy79lucky
msy79lucky

💻
yulaugh
yulaugh

💻

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

btorch-0.1.0.tar.gz (927.7 kB view details)

Uploaded Source

Built Distribution

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

btorch-0.1.0-py3-none-any.whl (306.6 kB view details)

Uploaded Python 3

File details

Details for the file btorch-0.1.0.tar.gz.

File metadata

  • Download URL: btorch-0.1.0.tar.gz
  • Upload date:
  • Size: 927.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for btorch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 72e55cd45999d2376dc6512dfaad2a959e637e4232a96c2f9d2f6defae9bb77c
MD5 a53865427ffcd765007919f27b3befbf
BLAKE2b-256 7c6b29e63a7a72c7072c851bd83e1ab56aadc6bcc84d52dc75a288501fbe3512

See more details on using hashes here.

Provenance

The following attestation bundles were made for btorch-0.1.0.tar.gz:

Publisher: release.yml on Criticality-Cognitive-Computation-Lab/btorch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file btorch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: btorch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 306.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for btorch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4516cf850e835820ecd3d11d57bb66d4c8bb2a59b559f27a67eeca550e09afe4
MD5 eb6a4313f76543d64877e8acbd8f20c5
BLAKE2b-256 ed2e2cfd9c7ab954b6f552022b1ed019d609d5885f016105a4ebf360102d2471

See more details on using hashes here.

Provenance

The following attestation bundles were made for btorch-0.1.0-py3-none-any.whl:

Publisher: release.yml on Criticality-Cognitive-Computation-Lab/btorch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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