Skip to main content

brc-pytorch

PyTorch implementation of the bistable recurrent cell (BRC) from the paper A bio-inspired bistable recurrent cell allows for long-lasting memory (Vecoven et al., 2020).

Install

pip install brc-pytorch

Usage

import torch

from brc_pytorch import utils
from brc_pytorch.modules import BRC, NBRC, StackedRNN

brc = StackedRNN(
    cell=BRC,  # NBRC for the neuromodulated version
    input_size=128,
    hidden_size=256,
    num_layers=3
).cuda()

# [ seq_len, batch_size, dim ]
x = torch.randn(64, 32, 128).cuda()

init_hidden = brc.init_hidden(batch_size=32)
out, hidden = brc(x, init_hidden)

# Detach hidden for next call
hidden = utils.detach_hidden(hidden)

Performance

The implementation is written in TorchScript (a subset of Python) and makes use of the PyTorch JIT compiler for a more efficient execution.

In my not really statistically significant experiments, the implementation seems to be about half as fast as the cuDNN based reference LSTM implementation with modest batch sizes and sequence lengths which can be considered pretty solid for a non-CUDA implementation.

Update (2023/07)

A lot has happened since the last real update of this repository. PyTorch 2.0 has introduced a new dynamic compilation system, which, to my understanding, should replace the old scripting API. After doing a quick test, it seems that the code is still working without issues with the scripting API and can in principle also be compiled with torch.compile. However, it does not seem to run faster, perhaps even slower, and would need an adaption to the new compilation system.

References

@misc{vecoven2020bioinspired,
    title={A bio-inspired bistable recurrent cell allows for long-lasting memory},
    author={Nicolas Vecoven and Damien Ernst and Guillaume Drion},
    year={2020},
    eprint={2006.05252},
    archivePrefix={arXiv},
    primaryClass={cs.NE}
}

Release files for brc 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brc 0.1.2
File Size Uploaded
brc-0.1.2.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for brc 0.1.2
File Interpreter ABI Platform
brc-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / brc-0.1.2.tar.gz

Download URL brc-0.1.2.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bb75986cce4be8c654d381f5932914bacd1b3e1ec109537b66917d1e26ecf6f4
BLAKE2b-256 checksum
How to use checksums
d58a28f3e85122f2a139b9bcc512ad4a6abc17c3d77c0a80d586241a99151875
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / brc-0.1.2-py3-none-any.whl

Download URL brc-0.1.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
100ef3badcafded18e627df843707de465dcf334da03845481ed55d8e294098d
BLAKE2b-256 checksum
How to use checksums
fa4ac5838d50e9b7ac4e23e8114353d3dd83967b07fb863eaa53d9d0af553dd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page