Skip to main content

BDH-CQ (wip)

Implementation of BDH-CQ: In-Context Learning with Recurrent Latent Reasoning, proposed by Pathway Research

Install

$ pip install bdh-cq

Usage

import torch
from bdh_cq import BDH

model = BDH(
    dim = 512,
    num_tokens = 20_000
)

ids = torch.randint(0, 20_000, (2, 1024))

logits = model(ids) # (2, 1024, 20_000)

For recurrent latent reasoning, wrap the model and pass an interleaving of token chunks and latent reasoning steps:

from bdh_cq import BDH, BDHReasoningWrapper

model = BDH(
    dim = 512,
    num_tokens = 256
)

wrapper = BDHReasoningWrapper(model)

prompts = torch.randint(0, 256, (1, 64))
answers = torch.randint(0, 256, (1, 32))

# tensor stages are ingested, int stages are latent reasoning steps - any interleaving

loss, logits, memories = wrapper(prompts, 8, answers, return_loss = True, return_memory = True)

loss.backward()

# generate an answer

answer = wrapper.generate(prompts, 8, num_tokens = 32, stop_token = 0)

Citations

@misc{engdahl2026bdhcq,
    title   = {BDH-CQ: In-Context Learning with Recurrent Latent Reasoning},
    author  = {Björn Engdahl and Adrian Kosowski and Jan Chorowski and Zuzanna Stamirowska and Przemysław Uznański and Junlin Jiang and Rohan Phadke and Remigiusz Kinas and Richard Zhong},
    year    = {2026},
    eprint  = {2608.09888},
    archivePrefix = {arXiv},
    primaryClass = {cs.NE},
    url     = {https://arxiv.org/abs/2608.09888}
}
@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},
}
@misc{knupp2026depthrecurrentattentionmixturesgiving,
    title   = {Depth-Recurrent Attention Mixtures: Giving Latent Reasoning the Attention it Deserves},
    author  = {Jonas Knupp and Jan Hendrik Metzen and Jeremias Bohn and Georg Groh and Kristian Kersting},
    year    = {2026},
    eprint  = {2601.21582},
    archivePrefix = {arXiv},
    primaryClass = {cs.AI},
    url     = {https://arxiv.org/abs/2601.21582},
}
@inproceedings{chakrabarti2026poly,
    title   = {Poly-attention: a general scheme for higher-order self-attention},
    author  = {Chakrabarti, Sayak and Pitassi, Toniann and Alman, Josh},
    booktitle = {International Conference on Learning Representations (ICLR)},
    year    = {2026}
}
@misc{sieberling2026triadic,
    title   = {Triadic Linear Attention: Three-Dimensional Recurrent States for Long-Context Sequence Modeling},
    author  = {Oliver Sieberling and Bharat Runwal and David Jin and Ryan Chin and Rameswar Panda and Yoon Kim},
    year    = {2026},
    eprint  = {2609.36529},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2609.36529}
}

Metadata

Release files for bdh-cq 0.0.23

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

Source distribution (sdist)

Source distribution for bdh-cq 0.0.23
File Size Uploaded
bdh_cq-0.0.23.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bdh-cq 0.0.23
File Interpreter ABI Platform
bdh_cq-0.0.23-py3-none-any.whl Python 3 none any Details

Total release size: 37.1 kB

Release files / bdh_cq-0.0.23.tar.gz

Download URL bdh_cq-0.0.23.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
77fa2f75b0dca667c4bcc9cd6f653ed42707745f62c7784630e1336f3b390e7b
BLAKE2b-256 checksum
How to use checksums
4a609a46ceb14386c6264eb7cf8867886da1a3d18c4150234a9017116e14f98d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / bdh_cq-0.0.23-py3-none-any.whl

Download URL bdh_cq-0.0.23-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4678993fdff211c9f86ca061f16d756ba83951ff37007c0772e9fadc311c3aa5
BLAKE2b-256 checksum
How to use checksums
502134851dd4ef9252271f1c575347a1dea5a588769a268971c81e3ad08a1309
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

0.0.23 This release

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

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