Brain-inspired torch utilities and models for neuromorphic research.
Project description
Btorch
English | 简体中文
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
- 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 💻 |
CFXTGJD 💻 |
gaozh0814 💻 |
msy79lucky 💻 |
yulaugh 💻 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e55cd45999d2376dc6512dfaad2a959e637e4232a96c2f9d2f6defae9bb77c
|
|
| MD5 |
a53865427ffcd765007919f27b3befbf
|
|
| BLAKE2b-256 |
7c6b29e63a7a72c7072c851bd83e1ab56aadc6bcc84d52dc75a288501fbe3512
|
Provenance
The following attestation bundles were made for btorch-0.1.0.tar.gz:
Publisher:
release.yml on Criticality-Cognitive-Computation-Lab/btorch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
btorch-0.1.0.tar.gz -
Subject digest:
72e55cd45999d2376dc6512dfaad2a959e637e4232a96c2f9d2f6defae9bb77c - Sigstore transparency entry: 1977014580
- Sigstore integration time:
-
Permalink:
Criticality-Cognitive-Computation-Lab/btorch@5c4dcd05aecc93837b85aef888bf6926f85ffdb4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Criticality-Cognitive-Computation-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5c4dcd05aecc93837b85aef888bf6926f85ffdb4 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4516cf850e835820ecd3d11d57bb66d4c8bb2a59b559f27a67eeca550e09afe4
|
|
| MD5 |
eb6a4313f76543d64877e8acbd8f20c5
|
|
| BLAKE2b-256 |
ed2e2cfd9c7ab954b6f552022b1ed019d609d5885f016105a4ebf360102d2471
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
btorch-0.1.0-py3-none-any.whl -
Subject digest:
4516cf850e835820ecd3d11d57bb66d4c8bb2a59b559f27a67eeca550e09afe4 - Sigstore transparency entry: 1977014717
- Sigstore integration time:
-
Permalink:
Criticality-Cognitive-Computation-Lab/btorch@5c4dcd05aecc93837b85aef888bf6926f85ffdb4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Criticality-Cognitive-Computation-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5c4dcd05aecc93837b85aef888bf6926f85ffdb4 -
Trigger Event:
push
-
Statement type: