RLT (Recurrent Looped Transformer)
Unofficial implementation of the Recurrent Looped Transformer proposed by Yifan Zhang of Princeton.
Will also do some exploration of the Recurrent Transformer proposed by Costin-Andrei Oncescu et al. of Harvard, if I have any remaining time
Install
$ pip install rlt-pytorch
Usage
import torch
from RLT import RLT
model = RLT(
num_tokens = 256,
dim = 512,
enc_depth = 4,
dec_depth = 4,
dec_sliding_window_size = 16,
tbptt_step_size = 16 # optional truncated bptt
)
tokens = torch.randint(0, 256, (2, 1024))
# forward for loss
loss = model(tokens, return_loss = True)
loss.backward()
# generate
prompt = torch.randint(0, 256, (2, 32))
sampled = model.generate(prompt, max_len = 128) # (2, 96)
Test
Train on enwik8
$ uv run train_enwik8.py
Citations
@techreport{zhang2026recurrentlooped,
title = {Recurrent Looped Transformer},
author = {Zhang, Yifan},
year = {2026},
month = {Sep},
url = {https://github.com/yifanzhang-pro/recurrent-looped-tranformer}
}
@misc{oncescu2026recurrenttransformergreatereffective,
title = {The Recurrent Transformer: Greater Effective Depth and Efficient Decoding},
author = {Costin-Andrei Oncescu and Depen Morwani and Samy Jelassi and Alexandru Meterez and Mujin Kwun and Sham Kakade},
year = {2026},
eprint = {2604.21215},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2604.21215},
}
@misc{kimiteam2026attentionresiduals,
title = {Attention Residuals},
author = {Kimi Team and Guangyu Chen and Yu Zhang and Jianlin Su and Weixin Xu and Siyuan Pan and Yaoyu Wang and Yucheng Wang and Guanduo Chen and Bohong Yin and Yutian Chen and Junjie Yan and Ming Wei and Y. Zhang and Fanqing Meng and Chao Hong and Xiaotong Xie and Shaowei Liu and Enzhe Lu and Yunpeng Tai and Yanru Chen and Xin Men and Haiqing Guo and Y. Charles and Haoyu Lu and Lin Sui and Jinguo Zhu and Zaida Zhou and Weiran He and Weixiao Huang and Xinran Xu and Yuzhi Wang and Guokun Lai and Yulun Du and Yuxin Wu and Zhilin Yang and Xinyu Zhou},
year = {2026},
eprint = {2603.15031},
archivePrefix = {arXiv},
primaryClass = {cs.CL},
url = {https://arxiv.org/abs/2603.15031},
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rlt_pytorch-0.0.14.tar.gz
(10.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rlt_pytorch-0.0.14.tar.gz.
File metadata
- Download URL: rlt_pytorch-0.0.14.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
116aa7affbe5dd3f45035bf9680ef5bd67b3cfe312722bc8deeef0150be0b9b4
|
|
| MD5 |
8ad995ad5c7e473cdc7b7b785b9ee45c
|
|
| BLAKE2b-256 |
8e94854ed64d545a41f2850a33dd6366a9cacc9d991d3856afcd56d76728724c
|
File details
Details for the file rlt_pytorch-0.0.14-py3-none-any.whl.
File metadata
- Download URL: rlt_pytorch-0.0.14-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d77a3062395b8a655afe80f5b7e6dff3a860fa5b5518884aaef1ed3d4b7aff1
|
|
| MD5 |
be0f390eab3db980cf3b11095b4ac6b2
|
|
| BLAKE2b-256 |
8d7034897088c222d60bc6d56b7a66aba7f26a139d30addfaab79f8c160288a1
|