Skip to main content

Sparse Toolkit

Project description

:abacus: 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 with block_size=128:

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)

stk.ops.ssd: sparse = op(sparse) x op(dense) [Experimental]
stk.ops.sds: sparse = op(dense) x op(sparse) [Experimental]
stk.ops.dss: dense = op(sparse) x op(sparse) [Experimental]

[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.

:rocket: Performance

STK 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

:building_construction: Installation

pip install stanford-stk

:writing_hand: 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},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stanford-stk-0.0.3.tar.gz (472.5 kB view details)

Uploaded Source

File details

Details for the file stanford-stk-0.0.3.tar.gz.

File metadata

  • Download URL: stanford-stk-0.0.3.tar.gz
  • Upload date:
  • Size: 472.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for stanford-stk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8279142c6f8800b689a9a553ab05ca98eca46e7477484c4e492f4ae749ebd4ef
MD5 4baa141aba85744685953838c91701d6
BLAKE2b-256 84ced9d3de22ea5c8971e5615651a02794e4ea7a87264c363834e57ab8305bb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page