lrnnx: A library for Linear RNNs
A unified PyTorch library providing easy access to state-of-the-art Linear RNN architectures for sequence modeling. The technical report of this system was accepted to EACL Student Research Workshop 2026. We recommend reading the report before using / contributing to the library.
Installation
From PyPI
# standard installation
pip install lrnnx
# with optional causal-conv1d
pip install "lrnnx[conv1d]"
# for development
pip install "lrnnx[dev]"
We recommend installing PyTorch first, matching your specific CUDA version. After that, install our library using --no-build-isolation.
pip install lrnnx --no-build-isolation
From Source
We recommend installation with uv, though standard pip is also supported.
Using uv
git clone https://github.com/SforAiDl/lrnnx.git
cd lrnnx
# standard installation
uv sync
# with optional causal-conv1d
uv sync --extra conv1d
# for development
uv sync --extra dev
Using pip
git clone https://github.com/SforAiDl/lrnnx.git
cd lrnnx
# standard installation
pip install -e . --no-build-isolation
# with optional causal-conv1d
pip install -e ".[conv1d]" --no-build-isolation
# for development
pip install -e ".[dev]" --no-build-isolation
Note that since our library builds several custom CUDA kernels, it can take time for this installation to finish.
Along with causal-conv1d the full installation can take about 30 minutes, depending on the number of CPUs available.
Model Zoo
Our library provides implementations of the following Linear RNN architectures:
- S4
- S4D
- S5
- Event-SSM (inside
S5, use by passingintegration_timesteps) - LRU
- S6 (we implemented other discretizations)
- STREAM (inside
S6, use by passingintegration_timesteps) - RG-LRU
- S7
- aTENNuate
We expose several levels of API for each model, including a scan, a recurrent step, and a full layer API matching the paper. For S5 we implement both a convolution based approach and a parallel scan approach. The latter is more stable and faster for most use cases, but the convolution based approach can be faster for very long sequences.
Usage
Training
It is easy to instantiate a model from our library
from lrnnx.models.lti import LRU
from lrnnx.models.ltv import Mamba
model_lti = LRU(d_model, d_state).cuda()
x = torch.randn(
batch_size, seq_len, d_model, dtype=torch.float32, device="cuda"
)
output = model_lti(x)
model_ltv = Mamba(d_model, d_state).cuda()
x = torch.randn(
batch_size, seq_len, d_model, dtype=torch.float32, device="cuda"
)
output = model_ltv(x)
Inference
Linear RNNs in torch require special handling during inference, following mamba, we also implement CUDA graphs based inference which reduces CPU overheads, this leads to > 10x speedup compared to using a simple for loop over the sequence length. The main file is generation.py which provides a simple API for autoregressive generation with any of the models in our library. You can see a simple way to use it in our benchmarking script.
Reproducing the Benchmarks from the paper
This script will run both training and inference benchmarks.
python -m benchmarks.run_all
Architectures
We also implement some common architectures based on the models in our library, such as a U-Net (inspired from aTENNuate ) and a hierarchical classifier (inspired from Event-SSM). Additionally, there is a Language Model architecture inspired from Mamba and RG-LRU which can be used for language modeling tasks, with replaceable LRNN and attention layers. This can be used as
from lrnnx.models.language_model import LRNNLMHeadModel
model = LRNNLMHeadModel(
d_model, d_state, num_layers, vocab_size, mixer_types=["s5", "s6", "attn"]
)
input_ids = torch.randint(0, vocab_size, (batch_size, seq_len))
logits = model(input_ids)
Tutorial Overview
Based on the architectures, there are tutorials on how to use them for 2 very popular use cases:
Contributing
Please check out our Contributing Guide for details on how to contribute to this project.
Citation
If you use lrnnx in your research, please cite:
@misc{bania2026textttlrnnxlibrarylinearrnns,
title={$\texttt{lrnnx}$: A library for Linear RNNs},
author={Karan Bania and Soham Kalburgi and Manit Tanwar and Dhruthi and Aditya Nagarsekar and Harshvardhan Mestha and Naman Chibber and Raj Deshmukh and Anish Sathyanarayanan and Aarush Rathore and Pratham Chheda},
year={2026},
eprint={2602.08810},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2602.08810},
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This library builds upon the excellent work of researchers who developed the individual LRNN models. Please see individual model documentation for proper citations of the original papers.
Metadata
Release files for lrnnx 1.0.0.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lrnnx-1.0.0.post1.tar.gz | 169.6 kB | With provenance | Details for lrnnx-1.0.0.post1.tar.gz |
Release files / lrnnx-1.0.0.post1.tar.gz
| Download URL | lrnnx-1.0.0.post1.tar.gz |
|---|---|
| Size | 169.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11becc2b411046b14ebd54cf5455fee3ed0d96b3e1eab41ff75119607cc29555
|
|
BLAKE2b-256 checksum How to use checksums |
2dde9bc22023ae7bbf8a252a541f48876a728ad9b6c2b49521d7cb5b66697716
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency logSecurity for lrnnx 1.0.0.post1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for lrnnx-1.0.0.post1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.