Skip to content

Commit 949e716

Browse files
committed
the usual
1 parent 152c365 commit 949e716

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,35 @@
44

55
Implementation of the sparse attention pattern proposed by the Deepseek team in their [Native Sparse Attention](https://arxiv.org/abs/2502.11089) paper
66

7+
## Install
8+
9+
```bash
10+
$ pip install native-sparse-attention-pytorch
11+
```
12+
13+
## Usage
14+
15+
```python
16+
import torch
17+
from native_sparse_attention_pytorch import SparseAttention
18+
19+
attn = SparseAttention(
20+
dim = 512,
21+
dim_head = 64,
22+
heads = 8,
23+
sliding_window_size = 2,
24+
compress_block_size = 4,
25+
selection_block_size = 4,
26+
num_selected_blocks = 2
27+
)
28+
29+
tokens = torch.randn(2, 31, 512)
30+
31+
attended = attn(tokens)
32+
33+
assert tokens.shape == attended.shape
34+
```
35+
736
## Citations
837

938
```bibtex

0 commit comments

Comments
 (0)