Skip to main content

TorchRecurrent

PyPI codecov Build Docs !python-versions code style: black arXiv

TorchRecurrent is a PyTorch-compatible collection of recurrent neural network cells and layers from across the research literature. It aims to provide a unified, flexible interface that feels like native PyTorch while exposing more customization options.

Installation

pip install torchrecurrent

or on conda-forge

conda install -c conda-forge torchrecurrent

Features

  • 🔄 30+ recurrent cells (e.g. LSTMCell, GRUCell, and many specialized variants).
  • 🏗️ 30+ recurrent layers (e.g. LSTM, GRU, and counterparts for each cell).
  • 🧩 Unified API — all cells/layers follow the PyTorch interface but add extra options for initialization and customization.
  • 📚 Comprehensive documentation including API reference and a catalog of published models.

👉 Full model catalog: torchrecurrent Models

Quick Example

import torch
from torchrecurrent import MGU #minimal gated unit

# sequence: (time_steps, batch, input_size)
inp = torch.randn(5, 3, 10)

# initialize a MGU with hidden_size=20
rnn = MGU(input_size=10, hidden_size=20, num_layers=3)

# forward pass
out, hidden = rnn(inp)

print(out.shape)  # (time_steps, batch, hidden_size)

Citation

If you use TorchRecurrent in your work, please consider citing

@misc{martinuzzi2025unified,
  doi = {10.48550/ARXIV.2510.21252},
  url = {https://arxiv.org/abs/2510.21252},
  author = {Martinuzzi,  Francesco},
  keywords = {Machine Learning (cs.LG),  Software Engineering (cs.SE),  FOS: Computer and information sciences,  FOS: Computer and information sciences},
  title = {Unified Implementations of Recurrent Neural Networks in Multiple Deep Learning Frameworks},
  publisher = {arXiv},
  year = {2025},
  copyright = {Creative Commons Attribution 4.0 International}
}

See also

LuxRecurrentLayers.jl: Provides recurrent layers for Lux.jl in Julia.

RecurrentLayers.jl: Provides recurrent layers for Flux.jl in Julia.

ReservoirComputing.jl: Reservoir computing utilities for scientific machine learning. Essentially gradient free trained recurrent neural networks.

License

This project’s own code is distributed under the MIT License (see LICENSE). The primary intent of this software is academic research.

Third-party Attributions

Some cells are re-implementations of published methods that carry their own licenses:

Please consult each of those licenses for your obligations when using this code in commercial or closed-source settings.

⚠️ Disclaimer: TorchRecurrent is an independent project and is not affiliated with the PyTorch project or Meta AI. The name reflects compatibility with PyTorch, not any official endorsement.

Download files

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

Source Distribution

torchrecurrent-0.2.2.tar.gz (51.0 kB view details)

Uploaded Source

Built Distribution

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

torchrecurrent-0.2.2-py3-none-any.whl (108.6 kB view details)

Uploaded Python 3

File details

Details for the file torchrecurrent-0.2.2.tar.gz.

File metadata

  • Download URL: torchrecurrent-0.2.2.tar.gz
  • Upload date:
  • Size: 51.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torchrecurrent-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4284b57e7eece18262462b3203fc629a09f5909958fe0cca9065569f02759e38
MD5 97c49bf22745b42222aa05b2849883e6
BLAKE2b-256 4258ab3486c714a242ffaac63e8d24e61cfd8e138d54cf43bd311a923d05dd03

See more details on using hashes here.

File details

Details for the file torchrecurrent-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: torchrecurrent-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 108.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torchrecurrent-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea4e7cb74ec8c7691b18b21900c52d3d88b6c4d2f4afe2f7c419b3f29a4efb86
MD5 36362f5ca5a8906ef795a1793e4ad84d
BLAKE2b-256 8d9e36fa966015f31926410dc436e6b2a72b69923ea00670db86717527230cfa

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.3

2 files

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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