Skip to main content

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 with StructuredOBS
  • 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


Download files

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

Source Distribution

sparsekit-0.1.2.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sparsekit-0.1.2-py3-none-any.whl (53.4 kB view details)

Uploaded Python 3

File details

Details for the file sparsekit-0.1.2.tar.gz.

File metadata

  • Download URL: sparsekit-0.1.2.tar.gz
  • Upload date:
  • Size: 47.2 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

Hashes for sparsekit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 88cb873aaf98a734c1f2e561232fa167d785ce4fd47d6495ada05f6552bbdb29
MD5 94b57b8339c18f6969131f3c0624835f
BLAKE2b-256 01b6729fbe2e9696eed21c5e089f7f5cb70d9845c837d0991b0ccc530b7bdb6f

See more details on using hashes here.

File details

Details for the file sparsekit-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sparsekit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 53.4 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

Hashes for sparsekit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d15c0cd42e52582eadc2c5ee50a506918b41387e59d8c6fe370c8c8351b63f4
MD5 3bdd9db33dd51fd316932150a2308b3b
BLAKE2b-256 2be410db9810baba2ea3c1586b6cb63b5be768ce8e33c5a794330b028e5b31a4

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