blksprs 1.8.2__tar.gz → 1.8.3__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.
- {blksprs-1.8.2 → blksprs-1.8.3}/PKG-INFO +21 -13
- {blksprs-1.8.2 → blksprs-1.8.3}/README.md +20 -12
- blksprs-1.8.3/blksprs/__init__.py +40 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/ops/softmax.py +2 -2
- blksprs-1.8.3/blksprs/utils/processing.py +41 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/utils/tools.py +1 -6
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/utils/validation.py +4 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs.egg-info/PKG-INFO +21 -13
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs.egg-info/SOURCES.txt +6 -5
- {blksprs-1.8.2 → blksprs-1.8.3}/pyproject.toml +1 -1
- blksprs-1.8.2/blksprs/__init__.py +0 -27
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/layouting/distribution_layout.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/layouting/sparsity_layout.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/ops/conversion.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/ops/distribution.py +0 -0
- {blksprs-1.8.2/blksprs → blksprs-1.8.3/blksprs/ops}/experimental/distribution_mdi.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/ops/matmul.py +0 -0
- {blksprs-1.8.2/blksprs → blksprs-1.8.3/blksprs/ops}/misc/broadcast_ops.py +0 -0
- {blksprs-1.8.2/blksprs → blksprs-1.8.3/blksprs/ops}/misc/exp.py +0 -0
- {blksprs-1.8.2/blksprs → blksprs-1.8.3/blksprs/ops}/misc/row_wise.py +0 -0
- {blksprs-1.8.2/blksprs/misc → blksprs-1.8.3/blksprs/ops}/partitioning.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/ops/repeat.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/ops/transpose.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/utils/benchmarking.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs/utils/blksprs_tensor.py +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs.egg-info/dependency_links.txt +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs.egg-info/requires.txt +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/blksprs.egg-info/top_level.txt +0 -0
- {blksprs-1.8.2 → blksprs-1.8.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: blksprs
|
|
3
|
-
Version: 1.8.
|
|
3
|
+
Version: 1.8.3
|
|
4
4
|
Summary: A lightweight library for operations on blocksparse matrices in PyTorch.
|
|
5
5
|
Author-email: Felix Schön <schoen@kr.tuwien.ac.at>
|
|
6
6
|
Project-URL: Homepage, https://github.com/FelixSchoen/blksprs
|
|
@@ -22,6 +22,14 @@ Requires-Dist: build; extra == "build"
|
|
|
22
22
|
[](https://github.com/FelixSchoen/blksprs/releases)
|
|
23
23
|
[](https://www.python.org/downloads/release/python-3119/)
|
|
24
24
|
|
|
25
|
+
## Important Notice
|
|
26
|
+
|
|
27
|
+
🚨 **Non-Final API** 🚨
|
|
28
|
+
|
|
29
|
+
Although it already supports a wide variety of functions, this library is still under active development and the API is
|
|
30
|
+
subject to change. For feature requests or bug reports, please open an [issue](https://github.com/FelixSchoen/blksprs/issues).
|
|
31
|
+
We also encourage [pull requests](https://github.com/FelixSchoen/blksprs/pulls).
|
|
32
|
+
|
|
25
33
|
## Overview
|
|
26
34
|
|
|
27
35
|
A lightweight and efficient library for operations on block-sparse matrices in PyTorch using Triton.
|
|
@@ -51,14 +59,14 @@ These include, e.g.,
|
|
|
51
59
|
Note that in order to correctly apply element-wise operations between two sparse tensors their sparsity layouts have to
|
|
52
60
|
match.
|
|
53
61
|
|
|
54
|
-
Further helpful operations (included in the ``bs.misc`` module) that do **not** support gradient calculation include:
|
|
62
|
+
Further helpful operations (included in the ``bs.ops.misc`` module) that do **not** support gradient calculation include:
|
|
55
63
|
|
|
56
64
|
- Row-wise sum, max, addition, and subtraction
|
|
57
65
|
- Broadcast addition and subtraction between slices
|
|
58
66
|
|
|
59
67
|
Furthermore, the library provides a set of utility functions for the creation of sparsity layouts based on existing
|
|
60
|
-
dense tensors and for the scatter operation (module ``bs.
|
|
61
|
-
dimensionality (module ``bs.
|
|
68
|
+
dense tensors and for the scatter operation (module ``bs.layouting``), as well as utility functions to apply linear layers,
|
|
69
|
+
ensure correct input dimensionality, and validate input (module ``bs.utils``).
|
|
62
70
|
|
|
63
71
|
## Installation
|
|
64
72
|
|
|
@@ -111,14 +119,14 @@ def test_readme():
|
|
|
111
119
|
y = torch.randn(size=(b, h, n, k), device="cuda").transpose(-1, -2).contiguous()
|
|
112
120
|
|
|
113
121
|
# Convert tensors to three-dimensional (dense) tensors since Triton can only handle tensors of exactly three dimensions
|
|
114
|
-
x_dense, x_shape_original = bs.
|
|
115
|
-
y_dense, y_shape_original = bs.
|
|
122
|
+
x_dense, x_shape_original = bs.utils.do_shape_blocksparse(x)
|
|
123
|
+
y_dense, y_shape_original = bs.utils.do_shape_blocksparse(y)
|
|
116
124
|
|
|
117
125
|
# Create sparsity layouts from existing tensors
|
|
118
|
-
sparsity_layout_x = bs.
|
|
119
|
-
|
|
120
|
-
sparsity_layout_y = bs.
|
|
121
|
-
|
|
126
|
+
sparsity_layout_x = bs.layouting.build_sparsity_layout(x_dense, sparsity_block_size,
|
|
127
|
+
triton_block_size=triton_block_size)
|
|
128
|
+
sparsity_layout_y = bs.layouting.build_sparsity_layout(y_dense, sparsity_block_size,
|
|
129
|
+
triton_block_size=triton_block_size)
|
|
122
130
|
|
|
123
131
|
# Create random sparsity layout for output tensor
|
|
124
132
|
sparsity_layout_o = _get_random_sparsity_layout(b * h, m, n, sparsity_block_size, sparsity_percentage)
|
|
@@ -150,12 +158,12 @@ def test_readme():
|
|
|
150
158
|
assert torch.allclose(o_dense, o_torch_round_trip, atol=2e-2) # Note that small numerical differences are expected
|
|
151
159
|
|
|
152
160
|
# Assert that the output has the correct sparsity layout
|
|
153
|
-
actual_sparsity_layout_o = bs.
|
|
154
|
-
|
|
161
|
+
actual_sparsity_layout_o = bs.layouting.build_sparsity_layout(o_dense, sparsity_block_size,
|
|
162
|
+
triton_block_size=triton_block_size)
|
|
155
163
|
assert torch.allclose(actual_sparsity_layout_o.to(torch.int), sparsity_layout_o)
|
|
156
164
|
|
|
157
165
|
# Convert output tensor back to original shape
|
|
158
|
-
o = bs.
|
|
166
|
+
o = bs.utils.undo_shape_blocksparse(o_dense, x_shape_original)
|
|
159
167
|
|
|
160
168
|
# Other available functions
|
|
161
169
|
bs.transpose(o_sparse, sparsity_layout_o, sparsity_block_size, triton_block_size=triton_block_size)
|
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
[](https://github.com/FelixSchoen/blksprs/releases)
|
|
4
4
|
[](https://www.python.org/downloads/release/python-3119/)
|
|
5
5
|
|
|
6
|
+
## Important Notice
|
|
7
|
+
|
|
8
|
+
🚨 **Non-Final API** 🚨
|
|
9
|
+
|
|
10
|
+
Although it already supports a wide variety of functions, this library is still under active development and the API is
|
|
11
|
+
subject to change. For feature requests or bug reports, please open an [issue](https://github.com/FelixSchoen/blksprs/issues).
|
|
12
|
+
We also encourage [pull requests](https://github.com/FelixSchoen/blksprs/pulls).
|
|
13
|
+
|
|
6
14
|
## Overview
|
|
7
15
|
|
|
8
16
|
A lightweight and efficient library for operations on block-sparse matrices in PyTorch using Triton.
|
|
@@ -32,14 +40,14 @@ These include, e.g.,
|
|
|
32
40
|
Note that in order to correctly apply element-wise operations between two sparse tensors their sparsity layouts have to
|
|
33
41
|
match.
|
|
34
42
|
|
|
35
|
-
Further helpful operations (included in the ``bs.misc`` module) that do **not** support gradient calculation include:
|
|
43
|
+
Further helpful operations (included in the ``bs.ops.misc`` module) that do **not** support gradient calculation include:
|
|
36
44
|
|
|
37
45
|
- Row-wise sum, max, addition, and subtraction
|
|
38
46
|
- Broadcast addition and subtraction between slices
|
|
39
47
|
|
|
40
48
|
Furthermore, the library provides a set of utility functions for the creation of sparsity layouts based on existing
|
|
41
|
-
dense tensors and for the scatter operation (module ``bs.
|
|
42
|
-
dimensionality (module ``bs.
|
|
49
|
+
dense tensors and for the scatter operation (module ``bs.layouting``), as well as utility functions to apply linear layers,
|
|
50
|
+
ensure correct input dimensionality, and validate input (module ``bs.utils``).
|
|
43
51
|
|
|
44
52
|
## Installation
|
|
45
53
|
|
|
@@ -92,14 +100,14 @@ def test_readme():
|
|
|
92
100
|
y = torch.randn(size=(b, h, n, k), device="cuda").transpose(-1, -2).contiguous()
|
|
93
101
|
|
|
94
102
|
# Convert tensors to three-dimensional (dense) tensors since Triton can only handle tensors of exactly three dimensions
|
|
95
|
-
x_dense, x_shape_original = bs.
|
|
96
|
-
y_dense, y_shape_original = bs.
|
|
103
|
+
x_dense, x_shape_original = bs.utils.do_shape_blocksparse(x)
|
|
104
|
+
y_dense, y_shape_original = bs.utils.do_shape_blocksparse(y)
|
|
97
105
|
|
|
98
106
|
# Create sparsity layouts from existing tensors
|
|
99
|
-
sparsity_layout_x = bs.
|
|
100
|
-
|
|
101
|
-
sparsity_layout_y = bs.
|
|
102
|
-
|
|
107
|
+
sparsity_layout_x = bs.layouting.build_sparsity_layout(x_dense, sparsity_block_size,
|
|
108
|
+
triton_block_size=triton_block_size)
|
|
109
|
+
sparsity_layout_y = bs.layouting.build_sparsity_layout(y_dense, sparsity_block_size,
|
|
110
|
+
triton_block_size=triton_block_size)
|
|
103
111
|
|
|
104
112
|
# Create random sparsity layout for output tensor
|
|
105
113
|
sparsity_layout_o = _get_random_sparsity_layout(b * h, m, n, sparsity_block_size, sparsity_percentage)
|
|
@@ -131,12 +139,12 @@ def test_readme():
|
|
|
131
139
|
assert torch.allclose(o_dense, o_torch_round_trip, atol=2e-2) # Note that small numerical differences are expected
|
|
132
140
|
|
|
133
141
|
# Assert that the output has the correct sparsity layout
|
|
134
|
-
actual_sparsity_layout_o = bs.
|
|
135
|
-
|
|
142
|
+
actual_sparsity_layout_o = bs.layouting.build_sparsity_layout(o_dense, sparsity_block_size,
|
|
143
|
+
triton_block_size=triton_block_size)
|
|
136
144
|
assert torch.allclose(actual_sparsity_layout_o.to(torch.int), sparsity_layout_o)
|
|
137
145
|
|
|
138
146
|
# Convert output tensor back to original shape
|
|
139
|
-
o = bs.
|
|
147
|
+
o = bs.utils.undo_shape_blocksparse(o_dense, x_shape_original)
|
|
140
148
|
|
|
141
149
|
# Other available functions
|
|
142
150
|
bs.transpose(o_sparse, sparsity_layout_o, sparsity_block_size, triton_block_size=triton_block_size)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from blksprs.utils.blksprs_tensor import BlksprsTensor
|
|
2
|
+
|
|
3
|
+
class ops:
|
|
4
|
+
from blksprs.ops.conversion import to_dense, to_sparse, from_blksprs, to_blksprs, adapt_layout
|
|
5
|
+
from blksprs.ops.distribution import gather, scatter, scatter_reduce
|
|
6
|
+
from blksprs.ops.matmul import matmul
|
|
7
|
+
from blksprs.ops.softmax import softmax
|
|
8
|
+
from blksprs.ops.transpose import transpose
|
|
9
|
+
from blksprs.ops.repeat import repeat, repeat_interleave
|
|
10
|
+
from blksprs.ops.partitioning import split, merge
|
|
11
|
+
|
|
12
|
+
class misc:
|
|
13
|
+
from blksprs.ops.misc.row_wise import row_wise_sum, row_wise_max, row_wise_add, row_wise_sub
|
|
14
|
+
from blksprs.ops.misc.broadcast_ops import broadcast_add, broadcast_sub
|
|
15
|
+
from blksprs.ops.misc.exp import exp
|
|
16
|
+
|
|
17
|
+
class experimental:
|
|
18
|
+
from blksprs.ops.experimental.distribution_mdi import gather_mdi, scatter_reduce_mdi
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class layouting:
|
|
22
|
+
from blksprs.layouting.distribution_layout import build_distribution_layout
|
|
23
|
+
from blksprs.layouting.sparsity_layout import build_sparsity_layout, build_sparsity_layout_adaption, \
|
|
24
|
+
build_sparsity_layout_matmul, build_sparsity_layout_matmul_fast
|
|
25
|
+
|
|
26
|
+
class experimental:
|
|
27
|
+
from blksprs.ops.experimental.distribution_mdi import build_distribution_layout_mdi
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class utils:
|
|
31
|
+
from blksprs.utils.processing import apply_torch_linear
|
|
32
|
+
from blksprs.utils.tools import do_shape_blocksparse, undo_shape_blocksparse
|
|
33
|
+
from blksprs.utils.validation import disable_validation
|
|
34
|
+
|
|
35
|
+
class validation:
|
|
36
|
+
from blksprs.utils.validation import disable_validation
|
|
37
|
+
from blksprs.utils.validation import validate_dimensions, validate_contiguous, validate_dtype_float, \
|
|
38
|
+
validate_dtype_int, validate_device, validate_sparsity, validate_sparsity_dense, \
|
|
39
|
+
validate_sparsity_block_size, \
|
|
40
|
+
validate_triton_block_size
|
|
@@ -3,8 +3,8 @@ import triton
|
|
|
3
3
|
from torch import Tensor
|
|
4
4
|
from triton import language as tl
|
|
5
5
|
|
|
6
|
-
from blksprs.misc.exp import exp
|
|
7
|
-
from blksprs.misc.row_wise import row_wise_sum, row_wise_max, row_wise_sub
|
|
6
|
+
from blksprs.ops.misc.exp import exp
|
|
7
|
+
from blksprs.ops.misc.row_wise import row_wise_sum, row_wise_max, row_wise_sub
|
|
8
8
|
from blksprs.utils.blksprs_tensor import BlksprsTensor
|
|
9
9
|
from blksprs.utils.tools import get_triton_block_size, stride
|
|
10
10
|
from blksprs.utils.validation import validate_contiguous, validate_dimensions, validate_device, \
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from torch import Tensor, nn
|
|
3
|
+
from triton.language import dtype
|
|
4
|
+
|
|
5
|
+
from blksprs.layouting.sparsity_layout import build_sparsity_layout_matmul_fast
|
|
6
|
+
from blksprs.ops.conversion import to_sparse
|
|
7
|
+
from blksprs.ops.matmul import matmul
|
|
8
|
+
from blksprs.ops.repeat import repeat
|
|
9
|
+
from blksprs.utils.blksprs_tensor import BlksprsTensor
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def apply_torch_linear(x: BlksprsTensor, sparsity_layout: Tensor, sparsity_block_size: int,
|
|
13
|
+
linear: nn.Linear) -> (BlksprsTensor, Tensor):
|
|
14
|
+
# Extract weight and bias
|
|
15
|
+
w = linear.weight
|
|
16
|
+
b = linear.bias
|
|
17
|
+
|
|
18
|
+
# Convert w to block-sparse representation
|
|
19
|
+
sparsity_layout_w_t = torch.ones(size=(sparsity_layout.size(0), w.size(1) // sparsity_block_size,
|
|
20
|
+
w.size(0) // sparsity_block_size), dtype=torch.bool, device=x.device)
|
|
21
|
+
w_t_bs = to_sparse(w.transpose(-1, -2).unsqueeze(0).repeat(sparsity_layout.size(0), 1, 1),
|
|
22
|
+
sparsity_layout_w_t, sparsity_block_size)
|
|
23
|
+
|
|
24
|
+
# Apply weights
|
|
25
|
+
sparsity_layout_xw = build_sparsity_layout_matmul_fast(sparsity_layout, sparsity_layout_w_t)
|
|
26
|
+
xw = matmul(x, sparsity_layout, w_t_bs, sparsity_layout_w_t, sparsity_layout_xw, sparsity_block_size)
|
|
27
|
+
interim = xw
|
|
28
|
+
|
|
29
|
+
# Apply bias
|
|
30
|
+
if b is not None:
|
|
31
|
+
b_slice = b.unsqueeze(0).unsqueeze(0).repeat(1, sparsity_block_size, 1)
|
|
32
|
+
sparsity_layout_b_slice = torch.ones(size=(1, b_slice.size(1) // sparsity_block_size,
|
|
33
|
+
b_slice.size(2) // sparsity_block_size), dtype=torch.bool,
|
|
34
|
+
device=x.device)
|
|
35
|
+
b_slice_bs = to_sparse(b_slice, sparsity_layout_b_slice, sparsity_block_size)
|
|
36
|
+
b_bs, sparsity_layout_b = repeat(b_slice_bs, sparsity_layout_b_slice,
|
|
37
|
+
(sparsity_layout.size(0), sparsity_layout_xw.size(1), 1), sparsity_block_size,
|
|
38
|
+
sparsity_layout_output=sparsity_layout_xw)
|
|
39
|
+
interim = interim + b_bs
|
|
40
|
+
|
|
41
|
+
return interim, sparsity_layout_xw
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
from torch import Tensor, Size
|
|
2
2
|
|
|
3
|
-
from blksprs.utils.validation import _set_skip_validation
|
|
4
|
-
|
|
5
3
|
|
|
6
4
|
def do_shape_blocksparse(x: Tensor):
|
|
7
5
|
if x.dim() == 3:
|
|
@@ -21,8 +19,5 @@ def get_triton_block_size(sparsity_block_size: int, limit: int = 128):
|
|
|
21
19
|
return min(sparsity_block_size, limit)
|
|
22
20
|
|
|
23
21
|
|
|
24
|
-
def disable_validation():
|
|
25
|
-
_set_skip_validation(True)
|
|
26
|
-
|
|
27
22
|
def stride(x: Tensor):
|
|
28
|
-
return x.view(x.shape).stride()
|
|
23
|
+
return x.view(x.shape).stride()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: blksprs
|
|
3
|
-
Version: 1.8.
|
|
3
|
+
Version: 1.8.3
|
|
4
4
|
Summary: A lightweight library for operations on blocksparse matrices in PyTorch.
|
|
5
5
|
Author-email: Felix Schön <schoen@kr.tuwien.ac.at>
|
|
6
6
|
Project-URL: Homepage, https://github.com/FelixSchoen/blksprs
|
|
@@ -22,6 +22,14 @@ Requires-Dist: build; extra == "build"
|
|
|
22
22
|
[](https://github.com/FelixSchoen/blksprs/releases)
|
|
23
23
|
[](https://www.python.org/downloads/release/python-3119/)
|
|
24
24
|
|
|
25
|
+
## Important Notice
|
|
26
|
+
|
|
27
|
+
🚨 **Non-Final API** 🚨
|
|
28
|
+
|
|
29
|
+
Although it already supports a wide variety of functions, this library is still under active development and the API is
|
|
30
|
+
subject to change. For feature requests or bug reports, please open an [issue](https://github.com/FelixSchoen/blksprs/issues).
|
|
31
|
+
We also encourage [pull requests](https://github.com/FelixSchoen/blksprs/pulls).
|
|
32
|
+
|
|
25
33
|
## Overview
|
|
26
34
|
|
|
27
35
|
A lightweight and efficient library for operations on block-sparse matrices in PyTorch using Triton.
|
|
@@ -51,14 +59,14 @@ These include, e.g.,
|
|
|
51
59
|
Note that in order to correctly apply element-wise operations between two sparse tensors their sparsity layouts have to
|
|
52
60
|
match.
|
|
53
61
|
|
|
54
|
-
Further helpful operations (included in the ``bs.misc`` module) that do **not** support gradient calculation include:
|
|
62
|
+
Further helpful operations (included in the ``bs.ops.misc`` module) that do **not** support gradient calculation include:
|
|
55
63
|
|
|
56
64
|
- Row-wise sum, max, addition, and subtraction
|
|
57
65
|
- Broadcast addition and subtraction between slices
|
|
58
66
|
|
|
59
67
|
Furthermore, the library provides a set of utility functions for the creation of sparsity layouts based on existing
|
|
60
|
-
dense tensors and for the scatter operation (module ``bs.
|
|
61
|
-
dimensionality (module ``bs.
|
|
68
|
+
dense tensors and for the scatter operation (module ``bs.layouting``), as well as utility functions to apply linear layers,
|
|
69
|
+
ensure correct input dimensionality, and validate input (module ``bs.utils``).
|
|
62
70
|
|
|
63
71
|
## Installation
|
|
64
72
|
|
|
@@ -111,14 +119,14 @@ def test_readme():
|
|
|
111
119
|
y = torch.randn(size=(b, h, n, k), device="cuda").transpose(-1, -2).contiguous()
|
|
112
120
|
|
|
113
121
|
# Convert tensors to three-dimensional (dense) tensors since Triton can only handle tensors of exactly three dimensions
|
|
114
|
-
x_dense, x_shape_original = bs.
|
|
115
|
-
y_dense, y_shape_original = bs.
|
|
122
|
+
x_dense, x_shape_original = bs.utils.do_shape_blocksparse(x)
|
|
123
|
+
y_dense, y_shape_original = bs.utils.do_shape_blocksparse(y)
|
|
116
124
|
|
|
117
125
|
# Create sparsity layouts from existing tensors
|
|
118
|
-
sparsity_layout_x = bs.
|
|
119
|
-
|
|
120
|
-
sparsity_layout_y = bs.
|
|
121
|
-
|
|
126
|
+
sparsity_layout_x = bs.layouting.build_sparsity_layout(x_dense, sparsity_block_size,
|
|
127
|
+
triton_block_size=triton_block_size)
|
|
128
|
+
sparsity_layout_y = bs.layouting.build_sparsity_layout(y_dense, sparsity_block_size,
|
|
129
|
+
triton_block_size=triton_block_size)
|
|
122
130
|
|
|
123
131
|
# Create random sparsity layout for output tensor
|
|
124
132
|
sparsity_layout_o = _get_random_sparsity_layout(b * h, m, n, sparsity_block_size, sparsity_percentage)
|
|
@@ -150,12 +158,12 @@ def test_readme():
|
|
|
150
158
|
assert torch.allclose(o_dense, o_torch_round_trip, atol=2e-2) # Note that small numerical differences are expected
|
|
151
159
|
|
|
152
160
|
# Assert that the output has the correct sparsity layout
|
|
153
|
-
actual_sparsity_layout_o = bs.
|
|
154
|
-
|
|
161
|
+
actual_sparsity_layout_o = bs.layouting.build_sparsity_layout(o_dense, sparsity_block_size,
|
|
162
|
+
triton_block_size=triton_block_size)
|
|
155
163
|
assert torch.allclose(actual_sparsity_layout_o.to(torch.int), sparsity_layout_o)
|
|
156
164
|
|
|
157
165
|
# Convert output tensor back to original shape
|
|
158
|
-
o = bs.
|
|
166
|
+
o = bs.utils.undo_shape_blocksparse(o_dense, x_shape_original)
|
|
159
167
|
|
|
160
168
|
# Other available functions
|
|
161
169
|
bs.transpose(o_sparse, sparsity_layout_o, sparsity_block_size, triton_block_size=triton_block_size)
|
|
@@ -6,20 +6,21 @@ blksprs.egg-info/SOURCES.txt
|
|
|
6
6
|
blksprs.egg-info/dependency_links.txt
|
|
7
7
|
blksprs.egg-info/requires.txt
|
|
8
8
|
blksprs.egg-info/top_level.txt
|
|
9
|
-
blksprs/experimental/distribution_mdi.py
|
|
10
9
|
blksprs/layouting/distribution_layout.py
|
|
11
10
|
blksprs/layouting/sparsity_layout.py
|
|
12
|
-
blksprs/misc/broadcast_ops.py
|
|
13
|
-
blksprs/misc/exp.py
|
|
14
|
-
blksprs/misc/partitioning.py
|
|
15
|
-
blksprs/misc/row_wise.py
|
|
16
11
|
blksprs/ops/conversion.py
|
|
17
12
|
blksprs/ops/distribution.py
|
|
18
13
|
blksprs/ops/matmul.py
|
|
14
|
+
blksprs/ops/partitioning.py
|
|
19
15
|
blksprs/ops/repeat.py
|
|
20
16
|
blksprs/ops/softmax.py
|
|
21
17
|
blksprs/ops/transpose.py
|
|
18
|
+
blksprs/ops/experimental/distribution_mdi.py
|
|
19
|
+
blksprs/ops/misc/broadcast_ops.py
|
|
20
|
+
blksprs/ops/misc/exp.py
|
|
21
|
+
blksprs/ops/misc/row_wise.py
|
|
22
22
|
blksprs/utils/benchmarking.py
|
|
23
23
|
blksprs/utils/blksprs_tensor.py
|
|
24
|
+
blksprs/utils/processing.py
|
|
24
25
|
blksprs/utils/tools.py
|
|
25
26
|
blksprs/utils/validation.py
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from blksprs.ops.conversion import to_dense, to_sparse, from_blksprs, to_blksprs
|
|
2
|
-
from blksprs.ops.distribution import gather, scatter, scatter_reduce
|
|
3
|
-
from blksprs.ops.matmul import matmul
|
|
4
|
-
from blksprs.ops.softmax import softmax
|
|
5
|
-
from blksprs.ops.transpose import transpose
|
|
6
|
-
from blksprs.ops.repeat import repeat, repeat_interleave
|
|
7
|
-
from blksprs.misc.partitioning import split, merge
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class layout:
|
|
11
|
-
from blksprs.layouting.distribution_layout import build_distribution_layout
|
|
12
|
-
from blksprs.layouting.sparsity_layout import build_sparsity_layout, build_sparsity_layout_adaption, \
|
|
13
|
-
build_sparsity_layout_matmul, build_sparsity_layout_matmul_fast
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class misc:
|
|
17
|
-
from blksprs.misc.broadcast_ops import broadcast_add, broadcast_sub
|
|
18
|
-
from blksprs.misc.exp import exp
|
|
19
|
-
from blksprs.misc.row_wise import row_wise_sum, row_wise_max, row_wise_add, row_wise_sub
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class util:
|
|
23
|
-
from blksprs.utils.tools import do_shape_blocksparse, undo_shape_blocksparse, disable_validation
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class experimental:
|
|
27
|
-
from blksprs.experimental.distribution_mdi import gather_mdi, scatter_reduce_mdi
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|