local-attention
Local attention, window with lookback, for language modeling
What it is and what it does
Local-attention is a PyTorch module that implements local windowed attention—a restricted form of transformer attention where each query attends only to keys and values within a fixed window, rather than the entire sequence. This is useful for language modeling because it allows transformer models to use computationally cheaper local attention in lower layers while reserving global attention for higher layers to integrate information across the full context.
The package provides configurable windowed attention with support for causal (auto-regressive) masking, lookback/lookahead windows, shared query-key spaces (Reformer-style), and automatic padding. It depends on torch for tensor operations and einops for tensor reshaping, plus hyper-connections as a utility dependency. The implementation is described as battle-tested across multiple repositories.
Use it for:
- Building efficient language models where full-sequence attention is computationally prohibitive for long contexts.
- Implementing Reformer-style architectures with shared query-key spaces and local attention windows.
- Replacing standard attention in transformer layers to reduce memory and compute while maintaining reasonable model capacity.
- Prototyping sparse attention patterns in transformer research without writing custom CUDA kernels.
- Training models on long sequences (e.g., 8192 tokens) where quadratic attention complexity becomes a bottleneck.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements local windowed attention for transformer models, allowing efficient attention computation over fixed-size windows rather than full sequences.
Yes, if you are building or experimenting with transformer models and need efficient local attention. The package has low install friction, permissive licensing, and no known vulnerabilities. However, the 394-day gap since the last release and aging maintenance status suggest it is stable but not actively developed—suitable for production use in established architectures but not for cutting-edge research requiring frequent updates.
Install
local-attention on PyPI
pip
pip install local-attentionuv
uv add local-attentionpoetry
poetry add local-attentionInstalling local-attention
Before you install
Low install friction with a pure Python wheel. Maintenance status is aging—last release was 394 days ago—but the repository remains active and unarchived with recent commits, suggesting the package is stable rather than abandoned.
License in practice
MIT license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install local-attention
import torch
from local_attention import LocalAttention
q = torch.randn(2, 8, 2048, 64)
k = torch.randn(2, 8, 2048, 64)
v = torch.randn(2, 8, 2048, 64)
attn = LocalAttention(dim=64, window_size=512, causal=True)
out = attn(q, k, v)
Requires torch and einops as runtime dependencies; intended for use within transformer architectures.
Verify before relying
- Performance characteristics compared to standard attention or other sparse attention implementations
- Compatibility with recent PyTorch versions and whether Python 3.6 support is still maintained
- Whether the package is actively maintained or in maintenance-only mode given the 394-day release gap
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — einops, hyper-connections, torch |
| Maintenance | aging — 394 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 311,627/month — #7,728 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: local_attention-1.11.2-py3-none-any.whl
Keywords: transformers, attention, artificial intelligence
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI
axial-positional-embeddingProvides axial positional embeddings for…
permissive · top 15,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
x-transformersx-transformers provides modular transformer…
permissive · top 5,000 on PyPI
mamba-ssmMamba-ssm implements state-space model…
permissive · top 15,000 on PyPI
flash-attnProvides optimized GPU implementations of…
permissive · top 15,000 on PyPI
rotary-embedding-torchImplements rotary positional embeddings for…
permissive · top 15,000 on PyPI
transformer-lensTransformerLens loads and inspects the internal…
permissive · top 15,000 on PyPI
fla-coreProvides hardware-efficient implementations of…
permissive · top 15,000 on PyPI