Sparsity Kit for Structured Sparsity Specification
Project description
SparseKit
SparseKit is the reference implementation of S³ (Structured Sparsity Specification), a unified framework for expressing and pruning structured sparse neural networks.
Browsing the Documentation
Full HTML documentation is bundled in docs/_build/html/.
Serve it locally with the included helper script:
python serve_docs.py
Then open http://localhost:8000 in your browser.
The documentation covers:
- Quickstart — install, construct a
BlockSpec, prune withStructuredOBS - Concepts — View, Block, Group, Coupling explained with examples
- API Reference — full docstrings for every public class and function
- Results — single-layer and end-to-end benchmark tables
Library Overview
sparsekit/
├── view.py # View — zero-copy strided parameter wrapper (torch.as_strided)
├── group.py # BlockSpec / BlockCoupling — atomic pruning unit
├── partition.py # ScopeSpec / ScopeCoupling — decision scope
├── linalg.py # Utility solvers (LSQR, proximal, thresholds)
├── utils.py # kth_largest, layout helpers
├── kernels.py # Triton kernels (auto-dispatched for large K/k)
├── builder.py # SparsityBuilder fluent API
├── viz.py # draw_layout() — visualize sparsity patterns
└── pruners/
├── obs.py # StructuredOBS — S-OBS with per-row Schur updates
├── quant.py # quantize_obs, mxfp4_quantize
└── nvquant.py # nvfp4_quantize, quantize_nvfp4_obs
Quick Example
import torch
from torch.nn import Parameter
from sparsekit import View, BlockSpec, ScopeSpec, StructuredOBS
M, K = 2560, 9728
W = Parameter(torch.randn(M, K, device="cuda"))
X = torch.randn(1024, K, device="cuda") # calibration inputs
# Express 2:4 sparsity
v = View.from_existing(W)
group = BlockSpec(v, shape=(1, 1))
part = ScopeSpec(group, shape=(1, 4))
# Prune with Structured OBS
hessian = (X.T @ X) / X.shape[0]
obs = StructuredOBS(part, hessian)
obs.prune_true_obs(num_nz=2) # keep 2 of 4, in-place
Any of the four experimental patterns replaces the three View/BlockSpec/ScopeSpec
lines above; the StructuredOBS call is identical.
Requirements
- Python ≥ 3.10
- PyTorch ≥ 2.8
- Triton 3.4.0
- CUDA (for Triton kernels; CPU fallback available)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sparsekit-0.1.3.tar.gz.
File metadata
- Download URL: sparsekit-0.1.3.tar.gz
- Upload date:
- Size: 46.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.13.11 Linux/6.12.74-gentoo-x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5add6aad30df3688b97dd82f0f79e36aa9884dcfeabd4c1f091a7c5b37674c5
|
|
| MD5 |
c72eac5f08779d098aeb646bed05ef62
|
|
| BLAKE2b-256 |
e06aad44bfa7f411e263ba07bf90ed0d672fe6bbf5f598990d8a10fb8ffa9f6a
|
File details
Details for the file sparsekit-0.1.3-py3-none-any.whl.
File metadata
- Download URL: sparsekit-0.1.3-py3-none-any.whl
- Upload date:
- Size: 52.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.13.11 Linux/6.12.74-gentoo-x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c80be54765b53812f809bc93a212f85e02cea90ef38b661df5ebbc3cc36105e0
|
|
| MD5 |
129d27b94dd32678246f5f6a3ec78470
|
|
| BLAKE2b-256 |
fceb27a634365ff2c92b6ad212cff76cd311ed99170fee8845377c9a3b630236
|