Skip to main content

Lookahead Keys Attention

Project description

Lookahead Keys Attention (wip)

Causal Attention with Lookahead Keys

Installation

pip install lookahead-keys-attention

Usage

import torch
from lookahead_keys_attention import Castle

# Initialize the Castle attention module
model = Castle(
    dim=512,           # input dimension
    heads=8,           # number of attention heads
    dim_head=64,       # dimension per head
    use_triton=None    # auto-detect CUDA for Triton optimization
)

# Example with CUDA sequence
batch_size = 2
seq_len = 128
dim = 512

# Move to CUDA if available
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device)

# Input sequence
x = torch.randn(batch_size, seq_len, dim).to(device)

# Forward pass
output = model(x)  # Shape: [batch_size, seq_len, dim]

# For inference with caching (single token generation)
cache = None
for i in range(seq_len):
    token = x[:, i:i+1, :]  # Single token
    output, cache = model(token, cache=cache, return_next_cache=True)

Citations

@inproceedings{Song2025CausalAW,
    title   = {Causal Attention with Lookahead Keys},
    author  = {Zhuoqing Song and Peng Sun and Huizhuo Yuan and Quanquan Gu},
    year    = {2025},
    url     = {https://api.semanticscholar.org/CorpusID:281218151}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lookahead_keys_attention-0.0.3.tar.gz (154.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lookahead_keys_attention-0.0.3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file lookahead_keys_attention-0.0.3.tar.gz.

File metadata

  • Download URL: lookahead_keys_attention-0.0.3.tar.gz
  • Upload date:
  • Size: 154.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for lookahead_keys_attention-0.0.3.tar.gz
Algorithm Hash digest
SHA256 82a20f9f0abd905e2e3d7fb10b8726519b2ba24c54b8b99fe38ccb7d050c4be1
MD5 6abf4ffa8c2d5c5925456efcd3f0c155
BLAKE2b-256 f865d7c70c5b8c2aca5f8b8a6d6cc62794d53cca319ce8081a50dbd579459bf8

See more details on using hashes here.

File details

Details for the file lookahead_keys_attention-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for lookahead_keys_attention-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 218f0fde06983bd9f8671e6a20cf089478ba15d234e6e76f33886b36d12ce417
MD5 2a5435c8445735ecf21b79db82735e9b
BLAKE2b-256 4e3d68f274f8c12860ec13f23abc25247e458f9e2a61ff7d8831d3ca4e6e7b64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page