Name | lookahead-keys-attention JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | Lookahead Keys Attention |
upload_time | 2025-09-19 21:56:33 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License
Copyright (c) 2025 Phil Wang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. |
keywords |
artificial intelligence
attention mechanism
deep learning
multi-modal transformer
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<img src="./fig3.png" width="400px"></img>
## Lookahead Keys Attention (wip)
Causal Attention with [Lookahead Keys](https://arxiv.org/abs/2509.07301)
## Installation
```bash
pip install lookahead-keys-attention
```
## Usage
```python
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
```bibtex
@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}
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "lookahead-keys-attention",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "artificial intelligence, attention mechanism, deep learning, multi-modal transformer",
"author": null,
"author_email": "Phil Wang <lucidrains@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/34/29/dc91da07027b080d0f371e1e847d182faf8b257cb3b8502f92091f0d7bda/lookahead_keys_attention-0.0.4.tar.gz",
"platform": null,
"description": "<img src=\"./fig3.png\" width=\"400px\"></img>\n\n## Lookahead Keys Attention (wip)\n\nCausal Attention with [Lookahead Keys](https://arxiv.org/abs/2509.07301)\n\n## Installation\n\n```bash\npip install lookahead-keys-attention\n```\n\n## Usage\n\n```python\nimport torch\nfrom lookahead_keys_attention import Castle\n\n# Initialize the Castle attention module\nmodel = Castle(\n dim=512, # input dimension\n heads=8, # number of attention heads\n dim_head=64, # dimension per head\n use_triton=None # auto-detect CUDA for Triton optimization\n)\n\n# Example with CUDA sequence\nbatch_size = 2\nseq_len = 128\ndim = 512\n\n# Move to CUDA if available\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\nmodel = model.to(device)\n\n# Input sequence\nx = torch.randn(batch_size, seq_len, dim).to(device)\n\n# Forward pass\noutput = model(x) # Shape: [batch_size, seq_len, dim]\n\n# For inference with caching (single token generation)\ncache = None\nfor i in range(seq_len):\n token = x[:, i:i+1, :] # Single token\n output, cache = model(token, cache=cache, return_next_cache=True)\n```\n\n## Citations\n\n```bibtex\n@inproceedings{Song2025CausalAW,\n title = {Causal Attention with Lookahead Keys},\n author = {Zhuoqing Song and Peng Sun and Huizhuo Yuan and Quanquan Gu},\n year = {2025},\n url = {https://api.semanticscholar.org/CorpusID:281218151}\n}\n```\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2025 Phil Wang\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.",
"summary": "Lookahead Keys Attention",
"version": "0.0.4",
"project_urls": {
"Homepage": "https://pypi.org/project/lookahead-keys-attention/",
"Repository": "https://github.com/lucidrains/lookahead-keys-attention"
},
"split_keywords": [
"artificial intelligence",
" attention mechanism",
" deep learning",
" multi-modal transformer"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f0746b0c415a8c4bb6c17c9044bc873b4f057de2ffe2e2fc8485354f0da547a6",
"md5": "8ad70ed6af0ce419ef57faa6fe96d73d",
"sha256": "5542945613e10fd253cbb40ada7e92fd978a7fd4afc6adbd24c80b2f73ffc503"
},
"downloads": -1,
"filename": "lookahead_keys_attention-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ad70ed6af0ce419ef57faa6fe96d73d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10611,
"upload_time": "2025-09-19T21:56:31",
"upload_time_iso_8601": "2025-09-19T21:56:31.077901Z",
"url": "https://files.pythonhosted.org/packages/f0/74/6b0c415a8c4bb6c17c9044bc873b4f057de2ffe2e2fc8485354f0da547a6/lookahead_keys_attention-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "3429dc91da07027b080d0f371e1e847d182faf8b257cb3b8502f92091f0d7bda",
"md5": "b538982ef8b7e8cb5dfce2c0c8843c17",
"sha256": "91dddb6526e06d0590a0ebf9779a4dfeaa78e444cfde9cc96086e1ebb3c86291"
},
"downloads": -1,
"filename": "lookahead_keys_attention-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "b538982ef8b7e8cb5dfce2c0c8843c17",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 154150,
"upload_time": "2025-09-19T21:56:33",
"upload_time_iso_8601": "2025-09-19T21:56:33.254654Z",
"url": "https://files.pythonhosted.org/packages/34/29/dc91da07027b080d0f371e1e847d182faf8b257cb3b8502f92091f0d7bda/lookahead_keys_attention-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-19 21:56:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lucidrains",
"github_project": "lookahead-keys-attention",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "lookahead-keys-attention"
}