etetoolkit /
ete
Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
78/100 healthLoading repository data…
MehrdadDastouri / repository
A comprehensive collection of attention mechanism implementations from seminal research papers, with complete mathematical derivations, PyTorch implementations, and educational Jupyter notebooks.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A comprehensive collection of attention mechanism implementations from seminal research papers, with complete mathematical derivations, PyTorch implementations, and educational Jupyter notebooks.
This repository provides production-ready implementations of 10 attention mechanisms, each with:
| Mechanism | Paper | Time Complexity | Space Complexity | Use Case |
|---|---|---|---|---|
| Scaled Dot-Product | Vaswani et al., 2017 | O(n²d) | O(n²) | Standard transformer attention |
| Multi-Head | Vaswani et al., 2017 | O(n²d) | O(n²h) | Parallel subspace attention |
| Cross-Attention | Vaswani et al., 2017 | O(nmd) | O(nm) | Encoder-decoder models |
| Causal (Masked) | Vaswani et al., 2017 | O(n²d) | O(n²) | Autoregressive generation |
| Sparse | Child et al., 2019 | O(n√n) | O(n√n) | Long sequences with patterns |
| Linear | Katharopoulos et al., 2020 | O(nd²) | O(nd) | Very long sequences |
| Flash | Dao et al., 2022 | O(n²d) | O(n) | Memory-efficient training |
| Multi-Query | Shazeer, 2019 | O(n²d) | O(n²) | Fast inference |
| Grouped-Query | Ainslie et al., 2023 | O(n²d) | O(n²) | Balance speed/quality |
| Sliding Window | Beltagy et al., 2020 | O(nwd) | O(nw) | Local context modeling |
Where: n = sequence length, d = model dimension, h = number of heads, m = encoder sequence length, w = window size
git clone https://github.com/yourusername/attention-mechanisms-zoo.git
cd attention-mechanisms-zoo
pip install -e .
import torch
from attention_zoo import (
ScaledDotProductAttention,
MultiHeadAttention,
CausalAttention,
LinearAttention,
)
# Initialize attention mechanism
attention = MultiHeadAttention(d_model=512, num_heads=8, dropout=0.1)
# Create sample input
batch_size, seq_len, d_model = 2, 128, 512
query = torch.randn(batch_size, seq_len, d_model)
key = torch.randn(batch_size, seq_len, d_model)
value = torch.randn(batch_size, seq_len, d_model)
# Forward pass
output, attention_weights = attention(query, key, value)
print(f"Output shape: {output.shape}") # (2, 128, 512)
print(f"Attention weights shape: {attention_weights.shape}") # (2, 8, 128, 128)
attention-mechanisms-zoo/
├── README.md
├── requirements.txt
├── setup.py
├── pyproject.toml
├── LICENSE
├── .gitignore
├── notebooks/
│ ├── 01_scaled_dot_product_attention.ipynb
│ ├── 02_multi_head_attention.ipynb
│ ├── 03_cross_attention.ipynb
│ ├── 04_masked_causal_attention.ipynb
│ ├── 05_sparse_attention.ipynb
│ ├── 06_linear_attention.ipynb
│ ├── 07_flash_attention.ipynb
│ ├── 08_multi_query_attention.ipynb
│ ├── 09_grouped_query_attention.ipynb
│ └── 10_sliding_window_attention.ipynb
├── src/
│ └── attention_zoo/
│ ├── __init__.py
│ ├── base.py
│ ├── scaled_dot_product.py
│ ├── multi_head.py
│ ├── cross_attention.py
│ ├── causal.py
│ ├── sparse.py
│ ├── linear.py
│ ├── flash.py
│ ├── multi_query.py
│ ├── grouped_query.py
│ ├── sliding_window.py
│ └── utils.py
├── tests/
│ ├── test_attention.py
│ └── test_equivalence.py
├── benchmarks/
│ └── benchmark_attention.py
└── figures/
└── .gitkeep
Each notebook provides:
Run benchmarks to compare performance:
python benchmarks/benchmark_attention.py
This will generate timing and memory comparisons across different sequence lengths.
Vaswani, A., et al. (2017). "Attention Is All You Need." NeurIPS. arXiv:1706.03762
Child, R., et al. (2019). "Generating Long Sequences with Sparse Transformers." arXiv:1904.10509
Katharopoulos, A., et al. (2020). "Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention." ICML. arXiv:2006.16236
Dao, T., et al. (2022). "FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness." NeurIPS. arXiv:2205.14135
Shazeer, N. (2019). "Fast Transformer Decoding: One Write-Head is All You Need." arXiv:1911.02150
Ainslie, J., et al. (2023). "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints." arXiv:2305.13245
Beltagy, I., et al. (2020). "Longformer: The Long-Document Transformer." arXiv:2004.05150
MIT License. See LICENSE for details.
If you use this repository in your research, please cite:
@software{attention_mechanisms_zoo,
title={Attention Mechanisms Zoo},
author=Mehrdaddastouri,
year={2024},
url={https://github.com/mehrdaddastouri/attention-mechanisms-zoo}
}
Selected from shared topics, language and repository description—not editorial ratings.
etetoolkit /
Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
78/100 healthshlomif /
A comprehensive, feature-rich, open source, and portable, collection of Solitaire games.
77/100 healthwr0x00 /
Lsploit is a comprehensive asset collection and vulnerability scanning tool. Lsploit是一款便携式综合资产分析及漏扫框架,拥有高性能,功能丰富,结合最新漏洞通告,嵌入ai,可自行组装exp,poc,方便红队快速打点
68/100 healthmstrYoda /
A comprehensive collection of practical machine learning examples using popular frameworks and libraries.
55/100 healthlux4rd0 /
The WeatherFlow Collector is a comprehensive data collection system that gathers weather data from local UDP broadcasts and remote APIs. It seamlessly feeds this data into InfluxDB V2, which can be visualized using a set of pre-configured Grafana dashboards. The application provides real-time current conditions and detailed forecasts.
68/100 healthRavikisha /
The Python Projects Repository is designed to provide a comprehensive collection of open-source Python projects that span different domains. These projects aim to serve as educational resources, examples, and starting points for your Python journey.
81/100 health