Skip to main content

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)

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}
}

Release files for log-depth-recurrent-modeling 0.1.1

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

Source distribution (sdist)

Source distribution for log-depth-recurrent-modeling 0.1.1
File Size Uploaded
log_depth_recurrent_modeling-0.1.1.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for log-depth-recurrent-modeling 0.1.1
File Interpreter ABI Platform
log_depth_recurrent_modeling-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / log_depth_recurrent_modeling-0.1.1.tar.gz

Download URL log_depth_recurrent_modeling-0.1.1.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
853c1800448c6731da984c07d5a85be22aa5935f786118a37a12702eadb34568
BLAKE2b-256 checksum
How to use checksums
7b3618e0e57bd3ccee15e4a460d4d3abf22b0f365ba8d2238bff16308435ce29
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.1-py3-none-any.whl

Download URL log_depth_recurrent_modeling-0.1.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
029441158693f8f9a9846e13d3f222b29a0c5bdb9fb55e47946fa7125d0831df
BLAKE2b-256 checksum
How to use checksums
9b46aa5529cfd405ad0e719e523d757631d5b2abb9af61cbac2335d1d899820c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

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