Attzoo 🔍
A modern, extensible PyTorch library for attention mechanisms in transformer models and deep learning architectures. Designed for educational and research purposes with clean, well-documented, and modular code.
📋 Attention Mechanisms
✅ Currently Implemented
| Mechanism | Class | Description | Use Case |
|---|---|---|---|
| Vanilla Self-Attention | VanillaSelfAttention |
Standard scaled dot-product self-attention | Basic transformer building block |
| Multi-Head Self-Attention | MultiHeadSelfAttention |
Parallel attention heads with different representations | Standard transformer layers |
| Local Self-Attention | LocalSelfAttention |
Windowed attention with configurable window size | Long sequences, O(n×w) complexity |
| Grouped Self-Attention | GroupedSelfAttention |
Memory-efficient attention with shared K,V heads | Efficient transformers (GQA/MQA) |
| Dilated Self-Attention | DilatedSelfAttention |
Sparse attention with dilation patterns | Structured sequences, long-range deps |
| Linear Self-Attention | LinearSelfAttention |
Linear complexity attention using kernel methods | O(n) complexity for very long sequences |
| Block Self-Attention | BlockSelfAttention |
Block-wise sparse attention patterns | Hierarchical attention, document modeling |
| ALiBi Self-Attention | ALiBiSelfAttention |
Attention with linear bias for positions | Length extrapolation capabilities |
| LSH Self-Attention | LSHSelfAttention |
Hash-based bucketed attention within buckets | Approximate global attention for long sequences |
| Gated Self-Attention (Residual) | GatedSelfAttention |
Highway-style gate mixing attention output with the input | Learnable residual strength per token |
| Combined Attention (Mixture) | CombinedAttention |
Learned gate mixes outputs of two attention modules | Softly combine local/global or different patterns |
🚀 Quick Start
Installation
# Install from source
git clone https://github.com/yourusername/attzoo.git
cd attzoo
uv sync
# For development
uv sync --all-extras --dev
Install from PyPI
Install the latest release from PyPI:
uv add attzoo
Notes:
- For a brand-new project on PyPI, use an account-scoped token for the first upload.
- Bump
versioninpyproject.tomlbefore every release.
Basic Usage
import torch
from attzoo import MultiHeadSelfAttention
# Initialize model and input
d_model = 128
seq_len = 512
batch_size = 4
attn = MultiHeadSelfAttention(d_model=d_model, num_heads=8)
x = torch.randn(batch_size, seq_len, d_model)
# Forward pass
out, weights = attn(x)
print(out.shape) # [4, 512, 128]
print(weights.shape) # [4, 8, 512, 512]
📝 Documentation
-
Browse the generated docs locally:
uv run -m mkdocs serve
The site is served at
http://127.0.0.1:8000/with hot reload enabled. -
Produce a production build:
uv run -m mkdocs build
Static assets are written to
site/and published automatically by CI as part of the GitHub workflow.
📊 Performance Comparison
| Mechanism | Time Complexity | Memory Complexity | Best Use Case |
|---|---|---|---|
| Vanilla | O(n²) | O(n²) | Short sequences (< 512) |
| Multi-Head | O(n²) | O(n²) | Standard transformer layers |
| Local | O(n×w) | O(n×w) | Long sequences with local patterns |
| Grouped | O(n²) | O(n²/g) | Memory-constrained scenarios |
| Dilated | O(n×d) | O(n×d) | Structured/periodic patterns |
| Linear | O(n) | O(n) | Very long sequences (> 4K tokens) |
| Block | O(b×(n/b)²) | O(b×(n/b)²) | Memory-efficient long sequences |
| ALiBi | O(n²) | O(n²) | Length extrapolation tasks |
| LSH | Sub-quadratic (~O(n×w×h)) | Sub-quadratic | Approximate long-range attention |
Where n=sequence length, w=window size, g=group ratio, d=dilation connections, b=number of blocks
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for attzoo 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| attzoo-0.1.0.tar.gz | 22.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| attzoo-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 58.1 kB
Release files / attzoo-0.1.0.tar.gz
| Download URL | attzoo-0.1.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48006515651b947e3e9462642b47df76960ca441b7a91d61bc0ca5b69a4b99c2
|
|
BLAKE2b-256 checksum How to use checksums |
b566b9b2a45dea79f0dccff59183ae7e733b64ccb595de081b4f1cc099214d10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / attzoo-0.1.0-py3-none-any.whl
| Download URL | attzoo-0.1.0-py3-none-any.whl |
|---|---|
| Size | 35.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f67925955a57a155a79004623ac934f1768fef255842e1b35177daece5cb3e64
|
|
BLAKE2b-256 checksum How to use checksums |
5d1096e1b3c7607c8f3a9d835bad2c5a17d430c33a656e03921eb047586165fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for attzoo 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.