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.

Release files for torchrecurrent 0.2.4

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

Source distribution (sdist)

Source distribution for torchrecurrent 0.2.4
File Size Uploaded
torchrecurrent-0.2.4.tar.gz 60.7 kB Details

Built distribution (wheel)

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

Total release size: 182.0 kB

Release files / torchrecurrent-0.2.4.tar.gz

Download URL torchrecurrent-0.2.4.tar.gz
Size 60.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bbf5250e7f9621489ec5e89ce9d177915446aff0e959308e527fd8023dec51f4
BLAKE2b-256 checksum
How to use checksums
e3b1dc995fe4f59ef8c343eb1ce52f8c6726d6d27f199434dda4973c6f7c3afe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / torchrecurrent-0.2.4-py3-none-any.whl

Download URL torchrecurrent-0.2.4-py3-none-any.whl
Size 121.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66b06e2e05970a07769a851f32bc4d721b1dd56d18c8e09768be2863828a7b24
BLAKE2b-256 checksum
How to use checksums
791ad6a5562fb2dc89b71991f64cca33dcb89842dc851bda2d81503d5f30308d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.2.5

2 release files

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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