Skip to main content

Deep Cross Attention

Implementation of the proposed DeepCrossAttention by Mike Heddes while at Google research, in Pytorch

My analysis is although I still prefer Hyper Connections, they have an important idea here that I have been trying concurrently. Mainly the queries, keys, values can be routed from different layers of the past. The reason this is cool is because it generalizes the recent value residual learning improvement. It may (or may not) also address an issue for neural memories

Appreciation

  • Minh Hoang for spotting some issues with the GRN

Install

$ pip install deep-cross-attention

Usage

import torch
from deep_cross_attention import DCAGPT

gpt = DCAGPT(
    num_tokens = 256,
    dim = 512,
    depth = 6,
    heads = 8,
    dim_head = 64,
    past_layers_k = 2
)

ids = torch.randint(0, 256, (2, 4096))

logits = gpt(ids) # (2, 4096, 256)

Example

First

$ pip install .[examples]

Next

$ python train.py

Citations

@inproceedings{Heddes2025DeepCrossAttentionST,
    title   = {DeepCrossAttention: Supercharging Transformer Residual Connections},
    author  = {Mike Heddes and Adel Javanmard and Kyriakos Axiotis and Gang Fu and MohammadHossein Bateni and Vahab S. Mirrokni},
    year    = {2025},
    url     = {https://api.semanticscholar.org/CorpusID:276250576}
}

Metadata

Release files for deep-cross-attention 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 deep-cross-attention 0.1.1
File Size Uploaded
deep_cross_attention-0.1.1.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deep-cross-attention 0.1.1
File Interpreter ABI Platform
deep_cross_attention-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / deep_cross_attention-0.1.1.tar.gz

Download URL deep_cross_attention-0.1.1.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
69b26a96168b28c7f59fce83c3d63d097f54df61cda623c789df169b3609cfb9
BLAKE2b-256 checksum
How to use checksums
fa38f01ac08faba268f6ae89699dbaa94b8c46fd0b43983001a63f7e00839dfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.13

Release files / deep_cross_attention-0.1.1-py3-none-any.whl

Download URL deep_cross_attention-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74f9483a12ebe836386e69dc84a8b4abee8818defc246bb33ac920d13f05eb71
BLAKE2b-256 checksum
How to use checksums
9e7b32e9d5ba04915d10b2d8ac692047f350981fcd1cc9ca0cd63a1217beaebd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.13

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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

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