Log Depth Recurrent Modeling - Pytorch
Explorations into the Log Depth Recurrent Modeling proposed by Yiqin Wang of Imperial College London.
Install
$ pip install log-depth-recurrent-modeling
Usage
import torch
from log_depth_recurrent_modeling import ARGRC
model = ARGRC(
num_tokens = 256,
dim = 128,
depth = 2,
max_seq_len = 65536,
shift_tokens = True
)
tokens = torch.randint(0, 256, (1, 65535))
# autoregressive loss
loss = model(tokens, return_loss = True)
loss.backward()
# forward for logits
logits = model(tokens) # (1, 65535, 256)
Standalone ARGRCLayer, which automatically pads the sequence to a multiple of max_seq_len (or the next power of two if unset) and strips the padding from the output:
import torch
from log_depth_recurrent_modeling import ARGRCLayer
layer = ARGRCLayer(
dim = 128,
max_seq_len = 65536,
prenorm = True,
shift_tokens = True,
separate_grc = False # shares up and down gated recursive cell
)
x = torch.randn(1, 65535, 128)
out = layer(x) + x # (1, 65535, 128)
Feed the sequence in chunks of varying length, carrying memory across calls (equivalent to one pass over the full sequence):
memory = None
for start, length in ((0, 3), (3, 5), (8, 2)):
chunk = x[:, start : start + length]
out, memory = layer(chunk, memory = memory, return_memory = True)
Tasks
Run parity task with length generalization:
$ python train_parity_extrapolation.py
Run character language modeling on enwik8 with memory caching during generation:
$ python train_enwik8.py
Citations
@misc{wang2026logdepthrecurrentlanguagemodeling,
title = {Log-Depth Recurrent Language Modeling},
author = {Yiqin Wang and Nuri Cingillioglu and Charles Pert},
year = {2026},
eprint = {2609.28212},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2609.28212},
}
@misc{shen2019orderedmemory,
title = {Ordered Memory},
author = {Yikang Shen and Shawn Tan and Arian Hosseini and Zhouhan Lin and Alessandro Sordoni and Aaron Courville},
year = {2019},
eprint = {1910.13466},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/1910.13466},
}
@misc{pert2026lengthgeneralizationlogdepthrecurrent,
title = {Length Generalization with Log-Depth Recurrent Units},
author = {Charles Pert and Dalal Alrajeh and Alessandra Russo},
year = {2026},
eprint = {2605.26035},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2605.26035},
}
@software{peng_bo_2021_5196578,
author = {PENG Bo},
title = {BlinkDL/RWKV-LM: 0.01},
month = {aug},
year = {2021},
publisher = {Zenodo},
version = {0.01},
doi = {10.5281/zenodo.5196578},
url = {https://doi.org/10.5281/zenodo.5196578}
}
Metadata
Release files for log-depth-recurrent-modeling 0.1.5
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 |
|---|---|---|---|---|
| log_depth_recurrent_modeling-0.1.5.tar.gz | 10.2 kB | Without provenance | Details for log_depth_recurrent_modeling-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| log_depth_recurrent_modeling-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for log_depth_recurrent_modeling-0.1.5-py3-none-any.whl |
Total release size: 23.6 kB
Release files / log_depth_recurrent_modeling-0.1.5.tar.gz
| Download URL | log_depth_recurrent_modeling-0.1.5.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a669875a538642a7fe13b684f8bbc25adfd3d6a8710ee7187c7bc50cbaddeb3
|
|
BLAKE2b-256 checksum How to use checksums |
0fba5c4998ad05dac13c07b430243a95616e7f5261cf6e9f940cb9c25aa704dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / log_depth_recurrent_modeling-0.1.5-py3-none-any.whl
| Download URL | log_depth_recurrent_modeling-0.1.5-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1693ab63ba4ad40f4c51ff89c5e0195c4812dab4fcd8b3f3c608d462caa5d5e7
|
|
BLAKE2b-256 checksum How to use checksums |
5f3118c824edf95d5bcac4047569522849b47f203dcf1fef7762a1115bb03084
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for log-depth-recurrent-modeling 0.1.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.