🧮 Sparse Toolkit
A light-weight PyTorch library for block-sparse matrices and block-sparse matrix multiplication.
STK is built around a core sparse matrix class (stk.Matrix), which uses a hybrid blocked-CSR-COO sparse matrix encoding to enable efficient matrix products with sparse inputs and outputs in transposed or non-transposed order. The library supports the following operations:
op: transpose or non-transpose
[Sparse Matrix Multiplication]
stk.ops.dsd: dense = op(sparse) x op(dense)
stk.ops.dds: dense = op(dense) x op(sparse)
stk.ops.sdd: sparse = op(dense) x op(dense)
[Sparse Matrix Conversion]
stk.ops.to_sparse: torch.Tensor => stk.Matrix
stk.ops.to_dense: stk.Matrix => torch.Tensor
[Sparse Matrix Generation]
stk.random.dense_mask: Create a random, block-sparse dense matrix.
stk.random.mask: Create a random, block-sparse sparse matrix.
STK is designed for applications where the sparse matrices change rapidly. This is complementary to libraries like triton-blocksparse, which assume that sparse matrix topologies do not change between invocations.
🚀 Performance
Block-sparse matrix multiplication with STK is able to match the performance of cuBLAS on a range of problems. On these benchmarks from MegaBlocks dMoE models, STK realizes 98.6% of cuBLAS throughput with 128x128 blocks on average.
Hardware: A100-SXM4-80GB
Software: CUDA 11.5, CUTLASS 2.5
🏗️ Installation
NOTE: This assumes that you have torch and numpy installed.
pip install stanford-stk
✍️ Citation
@article{megablocks-arxiv,
author = {Trevor Gale and Deepak Narayanan and Cliff Young and Matei Zaharia},
title = {MegaBlocks: Efficient Sparse Training with Mixture-of-Experts},
journal = {CoRR},
volume = {abs/2211.15841},
year = {2022},
}
Metadata
Release files for stanford-stk 0.7.1
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 | Actions |
|---|---|---|---|---|
| stanford_stk-0.7.1.tar.gz | 17.4 kB | Without provenance | Details for stanford_stk-0.7.1.tar.gz |
Release files / stanford_stk-0.7.1.tar.gz
| Download URL | stanford_stk-0.7.1.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc46140c2572ee9c008b2ac67ee6656f63f49c1074da8aea0923fa8290702871
|
|
BLAKE2b-256 checksum How to use checksums |
f6aeeeb2c3bd17fa94ed36530d53a8c06acf2f75a14f8f12aa701f6cf2504203
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for stanford-stk 0.7.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.