skillfed

local-attention

Local attention, window with lookback, for language modeling

local-attention v1.11.2 311.6K downloads/30d#7,728 on PyPI503
Permissive license MIT AGING released

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-attention

uv

uv add local-attention

poetry

poetry add local-attention

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.6Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

local windowed attention transformerefficient attention mechanismsparse attention pytorchlocal attention language modelwindow-based transformer attentioncausal local attentionattention with lookback
transformer-attentionsparse-attentionlanguage-modeling

More Artificial Intelligence packages

Further reading