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 = 512,
    depth = 2,
    max_seq_len = 65536,
    shift_tokens = True
)

tokens = torch.randint(0, 256, (2, 65536))

# forward with parallel blelloch scan in log depth

logits = model(tokens) # (2, 65536, 256)

# autoregressive cross entropy loss

loss = model(tokens, return_loss = True)
loss.backward()

Standalone ARGRCLayer:

import torch
from log_depth_recurrent_modeling import ARGRCLayer

layer = ARGRCLayer(
    dim = 512,
    max_seq_len = 65536,
    prenorm = True,
    shift_tokens = True,
    separate_grc = False # shares up and down grc
)

x = torch.randn(2, 65536, 512)

out = layer(x) # (2, 65536, 512)

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.0

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.0
File Size Uploaded
log_depth_recurrent_modeling-0.1.0.tar.gz 8.8 kB Details

Built distribution (wheel)

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

Total release size: 17.1 kB

Release files / log_depth_recurrent_modeling-0.1.0.tar.gz

Download URL log_depth_recurrent_modeling-0.1.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c173fe00ce4cc7e8d7fa272a120e0d9fd4c6118be69011eaa006171c86fac4b9
BLAKE2b-256 checksum
How to use checksums
e3dfd1f781fdf55cc5af93318571ea923668e3a5e843f4be2269df0e33c0d9d7
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.0-py3-none-any.whl

Download URL log_depth_recurrent_modeling-0.1.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d21a425777617da85459dec3d986d94277c17fbc326d2ea9149ada43668091c
BLAKE2b-256 checksum
How to use checksums
b6d7818aa0d3efc18f14870b914222dcedf06a16ef7d827ee8215b6ab3ba239f
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

0.1.1

2 release files

This release

0.1.0 This release

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