SparseTIR: Composable Abstractions for Sparse Compilation in Deep Learning

Zihao Ye, Ruihang Lai, Junru Shao, Tianqi Chen, Luis Ceze

TL;DR

SparseTIR is a novel sparse tensor compiler that introduces composable formats and composable transformations to optimize deep learning workloads. By breaking away from the "single-shot" compilation of traditional sparse compilers, it enables the use of specialized hardware like Tensor Cores for sparse data, delivering up to 40x speedups over state-of-the-art vendor libraries.

What Problem Does This Paper Address?

Sparsity is a cornerstone of modern deep learning, appearing in Graph Neural Networks (GNNs), sparse transformers, and pruned models. However, high-performance sparse kernels are notoriously difficult to write. Developers typically rely on vendor libraries like cuSPARSE, which often lag behind the latest research and support only a limited set of operators and formats.

Existing sparse compilers, such as TACO, simplify development by decoupling computation from format. Yet, they face two major hurdles in a deep learning context:

  1. Format Rigidity: They usually assume a single sparse format (like CSR) for an entire matrix, even though different parts of a matrix might benefit from different storage patterns.
  2. The "Single-Shot" Problem: They often lower high-level expressions directly to code in one go. This makes it nearly impossible to apply low-level hardware optimizations, such as tensorization (using specialized units like NVIDIA’s Tensor Cores), which are essential for modern performance.

Methods

SparseTIR addresses these challenges by re-imagining the compilation flow as a series of composable stages.

Composable Formats

Instead of forcing a matrix into one format, SparseTIR allows for format decomposition. A sparse matrix can be split into multiple parts, each stored in the format that best fits its local pattern. For example, dense sub-blocks can be stored in Block Compressed Sparse Row (BSR) to utilize Tensor Cores, while the remaining scattered elements use a more flexible format like ELLPACK.

Format composability enables us to leverage multiple formats for different parts in sparse pattern we face in deep learning, and maximize the use of underlying hardware resources.

Multi-Stage IR and Composable Transformations

SparseTIR moves away from single-shot compilation by using a three-stage Intermediate Representation (IR):

  • Stage I (Coordinate Space): Computation is described using high-level coordinates. This is where format decomposition and high-level reordering happen.
  • Stage II (Position Space): The IR reflects the actual indices of non-zero elements in compressed storage. This stage allows for loop manipulations and mapping to GPU threads.
  • Stage III (Loop-based IR): SparseTIR lowers to a loop-level IR compatible with dense tensor compilers (specifically TVM’s TensorIR). This allows SparseTIR to "inherit" advanced optimizations like tensorization and vectorization.
Single-shot sparse compilers vs SparseTIR. The composable formats and composable transformations enable us to create optimizations that fit into broader range of deep learning workloads and leverage more advances in hardware backends.

Datasets

The authors evaluated SparseTIR across a wide range of real-world workloads:

  • GNNs: Standard benchmarks including Cora, Citeseer, Pubmed, PPI, and large-scale graphs from the Open Graph Benchmark (ogbn-arxiv, ogbn-proteins, Reddit).
  • Heterogeneous Graphs (RGCN): AIFB, MUTAG, BGS, ogbl-biokg, and AM.
  • Sparse Transformers: Models like Longformer and Pixelated Butterfly.
  • Pruned Models: PruneBERT (both structured and unstructured pruning).
  • Sparse Convolution: The SemanticKITTI dataset for 3D point cloud processing.

Key Insights and Ideas

  • Bridging the Sparse-Dense Gap: The most significant "aha moment" is the realization that sparse compilation can be lowered into a dense loop-based IR. This allows sparse kernels to benefit from the years of optimization work poured into dense compilers like TVM.
  • Compile-Time Load Balancing: By using a hybrid format (bucketing rows by their non-zero counts), SparseTIR achieves better load balancing across GPU threads at compile-time, avoiding the runtime overhead of dynamic load balancing.
  • Kernel Fusion for RGCN: For Relational GNNs, SparseTIR fuses the "Gather-Matmul-Scatter" operations into a single kernel. By keeping intermediate results in fast on-chip SRAM rather than writing them back to global memory, it achieves massive speedups.

Key Results

SparseTIR consistently outperforms both vendor libraries and existing compilers:

  • Single Operators: Achieved 1.20–2.34x speedup for GNN operators and 1.05–2.98x for sparse attention compared to cuSPARSE and Triton.
  • End-to-End GNNs: Accelerated GraphSAGE training by 1.08–1.52x.
  • RGCN Inference: Delivered a staggering 4.20–40.18x speedup over Graphiler and DGL by fusing kernels and utilizing Tensor Cores.
  • Sparse Convolution: Outperformed the state-of-the-art TorchSparse library by up to 7.45x for certain channel sizes.

Limitations and Future Work

While SparseTIR is powerful, it currently requires users to manually specify schedule templates and format decomposition rules. The authors identify automatic scheduling (similar to TVM's Ansor) and automatic format selection as key areas for future research. Additionally, the current system is optimized for static sparsity (where the sparse pattern doesn't change every iteration); extending these abstractions to handle dynamic sparsity remains an open challenge.

Summary updated

BibTeX
@inproceedings{ye2023sparsetir,
  author = {Zihao Ye and Ruihang Lai and Junru Shao and Tianqi Chen and Luis Ceze},
  title = {{SparseTIR: Composable Abstractions for Sparse Compilation in Deep Learning}},
  booktitle = {ASPLOS},
  year = {2023},
  doi = {10.1145/3582016.3582047},
}
Figure