adasplash 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adasplash-0.1.0/LICENSE +21 -0
- adasplash-0.1.0/PKG-INFO +121 -0
- adasplash-0.1.0/README.md +89 -0
- adasplash-0.1.0/adasplash/__init__.py +3 -0
- adasplash-0.1.0/adasplash/adasplash_block_mask.py +1207 -0
- adasplash-0.1.0/adasplash/adasplash_no_block_mask.py +1075 -0
- adasplash-0.1.0/adasplash/triton_entmax.py +326 -0
- adasplash-0.1.0/adasplash.egg-info/PKG-INFO +121 -0
- adasplash-0.1.0/adasplash.egg-info/SOURCES.txt +16 -0
- adasplash-0.1.0/adasplash.egg-info/dependency_links.txt +1 -0
- adasplash-0.1.0/adasplash.egg-info/requires.txt +9 -0
- adasplash-0.1.0/adasplash.egg-info/top_level.txt +1 -0
- adasplash-0.1.0/pyproject.toml +6 -0
- adasplash-0.1.0/setup.cfg +4 -0
- adasplash-0.1.0/setup.py +32 -0
- adasplash-0.1.0/tests/test_adasplash.py +194 -0
- adasplash-0.1.0/tests/test_adasplash_no_block_mask.py +194 -0
- adasplash-0.1.0/tests/test_triton_entmax.py +141 -0
adasplash-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DeepSPIN
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
adasplash-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: adasplash
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AdaSplash: Efficient Adaptive Sparse Attention in Triton
|
|
5
|
+
Home-page: https://github.com/deep-spin/adasplash
|
|
6
|
+
Author: Nuno Gonçalves, Marcos Treviso
|
|
7
|
+
Author-email: marcosvtreviso@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: torch
|
|
15
|
+
Requires-Dist: triton
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Requires-Dist: black; extra == "dev"
|
|
19
|
+
Requires-Dist: isort; extra == "dev"
|
|
20
|
+
Requires-Dist: flake8; extra == "dev"
|
|
21
|
+
Requires-Dist: entmax; extra == "dev"
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description
|
|
26
|
+
Dynamic: description-content-type
|
|
27
|
+
Dynamic: home-page
|
|
28
|
+
Dynamic: provides-extra
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
Dynamic: summary
|
|
32
|
+
|
|
33
|
+
# AdaSplash: Adaptive Sparse Flash Attention
|
|
34
|
+
|
|
35
|
+
[](https://github.com/deep-spin/adasplash/actions)
|
|
36
|
+
[](https://badge.fury.io/py/adasplash)
|
|
37
|
+
|
|
38
|
+
AdaSplash, aka flash entmax attention, is an efficient adaptive sparse attention mechanism implemented in Triton.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
- **Optimized Entmax (triton_entmax):** A Triton-accelerated implementation of Entmax, using Halley's method with bisection instead of pure bisection.
|
|
43
|
+
- **AdaSplash with block masking (adasplash):** Uses adaptive sparsity to improve efficiency, requiring extra memory for storing a binary mask.
|
|
44
|
+
- **AdaSplash without block masking (adasplash_no_block_mask):** A more memory-efficient variant that maintains efficiency through tiling and fused operations.
|
|
45
|
+
- **Fully compatible with PyTorch** and optimized for GPU execution.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
You can install AdaSplash via pip:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install adasplash
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Alternatively, install the latest development version directly from GitHub:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install git+https://github.com/deep-spin/adasplash.git
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
AdaSplash provides three main functions, all available via `from adasplash import ...`:
|
|
64
|
+
|
|
65
|
+
### **Triton Entmax** (Optimized Entmax Activation)
|
|
66
|
+
```python
|
|
67
|
+
from adasplash import triton_entmax
|
|
68
|
+
import torch
|
|
69
|
+
|
|
70
|
+
x = torch.randn(128, 256).cuda()
|
|
71
|
+
y = triton_entmax(x, alpha=1.5)
|
|
72
|
+
```
|
|
73
|
+
- Uses **Halley's method + bisection** instead of pure bisection.
|
|
74
|
+
- Faster and more efficient than traditional Entmax implementations.
|
|
75
|
+
|
|
76
|
+
### **AdaSplash with Block Masking**
|
|
77
|
+
```python
|
|
78
|
+
from adasplash import adasplash
|
|
79
|
+
|
|
80
|
+
q = torch.randn(1, 8, 128, 64, device="cuda")
|
|
81
|
+
k = torch.randn(1, 8, 128, 64, device="cuda")
|
|
82
|
+
v = torch.randn(1, 8, 128, 64, device="cuda")
|
|
83
|
+
|
|
84
|
+
output = adasplash(q, k, v)
|
|
85
|
+
```
|
|
86
|
+
- Leverages **adaptive sparsity** for efficiency in both forward and backward passes.
|
|
87
|
+
- Requires **O(Tr × Tc) bits** of extra memory for storing a binary mask per block.
|
|
88
|
+
|
|
89
|
+
### **AdaSplash without Block Masking**
|
|
90
|
+
```python
|
|
91
|
+
from adasplash import adasplash_no_block_mask
|
|
92
|
+
|
|
93
|
+
output = adasplash_no_block_mask(q, k, v)
|
|
94
|
+
```
|
|
95
|
+
- Does **not** use block masking but still benefits from **tiling and fused ops** for efficiency.
|
|
96
|
+
- Requires **less memory** than the block-masked version.
|
|
97
|
+
|
|
98
|
+
## Testing
|
|
99
|
+
To ensure the library works as expected, install the development dependencies and run tests:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pip install -r requirements-dev.txt
|
|
103
|
+
pytest
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Citation
|
|
107
|
+
If you use AdaSplash in your research, please cite:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
@article{goncalves2025adasplash,
|
|
111
|
+
title={AdaSplash: Adaptive Sparse Flash Attention},
|
|
112
|
+
author={Nuno Gonçalves and Marcos Treviso and André F. T. Martins},
|
|
113
|
+
journal={arXiv preprint arXiv:2502.12082},
|
|
114
|
+
url={https://arxiv.org/abs/2502.12082},
|
|
115
|
+
year={2025}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
AdaSplash is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
121
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# AdaSplash: Adaptive Sparse Flash Attention
|
|
2
|
+
|
|
3
|
+
[](https://github.com/deep-spin/adasplash/actions)
|
|
4
|
+
[](https://badge.fury.io/py/adasplash)
|
|
5
|
+
|
|
6
|
+
AdaSplash, aka flash entmax attention, is an efficient adaptive sparse attention mechanism implemented in Triton.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
- **Optimized Entmax (triton_entmax):** A Triton-accelerated implementation of Entmax, using Halley's method with bisection instead of pure bisection.
|
|
11
|
+
- **AdaSplash with block masking (adasplash):** Uses adaptive sparsity to improve efficiency, requiring extra memory for storing a binary mask.
|
|
12
|
+
- **AdaSplash without block masking (adasplash_no_block_mask):** A more memory-efficient variant that maintains efficiency through tiling and fused operations.
|
|
13
|
+
- **Fully compatible with PyTorch** and optimized for GPU execution.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
You can install AdaSplash via pip:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install adasplash
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Alternatively, install the latest development version directly from GitHub:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install git+https://github.com/deep-spin/adasplash.git
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
AdaSplash provides three main functions, all available via `from adasplash import ...`:
|
|
32
|
+
|
|
33
|
+
### **Triton Entmax** (Optimized Entmax Activation)
|
|
34
|
+
```python
|
|
35
|
+
from adasplash import triton_entmax
|
|
36
|
+
import torch
|
|
37
|
+
|
|
38
|
+
x = torch.randn(128, 256).cuda()
|
|
39
|
+
y = triton_entmax(x, alpha=1.5)
|
|
40
|
+
```
|
|
41
|
+
- Uses **Halley's method + bisection** instead of pure bisection.
|
|
42
|
+
- Faster and more efficient than traditional Entmax implementations.
|
|
43
|
+
|
|
44
|
+
### **AdaSplash with Block Masking**
|
|
45
|
+
```python
|
|
46
|
+
from adasplash import adasplash
|
|
47
|
+
|
|
48
|
+
q = torch.randn(1, 8, 128, 64, device="cuda")
|
|
49
|
+
k = torch.randn(1, 8, 128, 64, device="cuda")
|
|
50
|
+
v = torch.randn(1, 8, 128, 64, device="cuda")
|
|
51
|
+
|
|
52
|
+
output = adasplash(q, k, v)
|
|
53
|
+
```
|
|
54
|
+
- Leverages **adaptive sparsity** for efficiency in both forward and backward passes.
|
|
55
|
+
- Requires **O(Tr × Tc) bits** of extra memory for storing a binary mask per block.
|
|
56
|
+
|
|
57
|
+
### **AdaSplash without Block Masking**
|
|
58
|
+
```python
|
|
59
|
+
from adasplash import adasplash_no_block_mask
|
|
60
|
+
|
|
61
|
+
output = adasplash_no_block_mask(q, k, v)
|
|
62
|
+
```
|
|
63
|
+
- Does **not** use block masking but still benefits from **tiling and fused ops** for efficiency.
|
|
64
|
+
- Requires **less memory** than the block-masked version.
|
|
65
|
+
|
|
66
|
+
## Testing
|
|
67
|
+
To ensure the library works as expected, install the development dependencies and run tests:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install -r requirements-dev.txt
|
|
71
|
+
pytest
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Citation
|
|
75
|
+
If you use AdaSplash in your research, please cite:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
@article{goncalves2025adasplash,
|
|
79
|
+
title={AdaSplash: Adaptive Sparse Flash Attention},
|
|
80
|
+
author={Nuno Gonçalves and Marcos Treviso and André F. T. Martins},
|
|
81
|
+
journal={arXiv preprint arXiv:2502.12082},
|
|
82
|
+
url={https://arxiv.org/abs/2502.12082},
|
|
83
|
+
year={2025}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
AdaSplash is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
89
|
+
|