Rice University's SparseEinSum Runs Sparse Attention 100x Faster Than Dense
A new notation called EinSum bridges relational databases and tensor math, automatically routing sparse data through SQL and dense chunks through fast GPU kernels
ProTakeaways
- New notation: EinSum is a tensor-relational version of Einstein summation that automatically splits sparse tensor computations between a relational database and dense GPU kernels.
- 100x speedup: SparseEinSum is more than 100x faster than dense attention and 30-100x faster than pure relational approaches on sparse attention benchmarks.
- Key insight: Relational databases handle sparsity natively via SQL joins; dense sub-blocks are dispatched to optimized BLAS/cuBLAS kernels -- the system decides the split automatically.
- Target workloads: Graph neural networks, sparse transformer attention, quantum circuit simulation, and knowledge graph embeddings all benefit from the approach.
- Automated rewriting: Users write standard einsum or PyTorch-style code; SparseEinSum uses dynamic programming to find the optimal decomposition without manual tuning.
- Paper and preprint: Available on arXiv and the NSF Public Access Repository; no public code release announced yet.
Most ML engineers think of sparse data as a GPU problem: throw a sparse matrix library at it and hope for the best. A new paper from Rice University argues that the right tool for sparsity has been sitting in data engineering departments all along: the relational database. The work introduces EinSum, a tensor-relational notation that automatically splits a tensor computation into two lanes -- a relational lane for handling sparsity, and a dense numerical kernel lane for the heavy math.
The problem with sparse tensors at scale
Einstein summation notation (einsum) is the lingua franca of tensor math. It provides a compact and expressive notation for describing tensor computations, where operations are expressed as products over indexed expressions. Reductions are implicitly defined over index variables that do not appear in the output expression -- for example, matrix multiplication is expressed as C[m,n] = A[m,k] * B[k,n], where the computation reduces over the index k. PyTorch, NumPy, and JAX all support it natively.
The trouble is that standard einsum assumes dense tensors. Real-world workloads -- graph neural networks, attention over long sequences, knowledge graph embeddings, quantum circuit simulation -- are dominated by sparsity. Sparse tensor systems can perform well for highly sparse inputs but struggle on mixed dense-sparse workloads. You either pay the cost of materializing zeros, or you write custom sparse kernels by hand.
Current ML systems typically push whole tensors through a series of compute kernels such as matrix multiplications or activation functions, where each kernel runs on an AI accelerator like a GPU. This implementation abstraction provides little built-in support for ML systems to scale past a single machine, or for handling large models with matrices or tensors that do not easily fit into the RAM of an ASIC. The research community has been searching for a cleaner abstraction for years.
A two-lane highway for tensor math
A tensor-relational computation is a relational computation where individual tuples carry vectors, matrices, or higher-dimensional arrays. The overall computation can be executed on top of a relational system, inheriting the system's ability to automatically handle very large inputs with high levels of sparsity, while high-performance kernels such as optimized matrix-matrix multiplication codes can be used to perform most of the underlying mathematical operations.
The key insight is that a relational database is already a sparse data structure. A table with a million rows only stores the rows that exist -- zeros are implicit. If one views a tensor as a relation -- tensors can be seen as relations mapping keys (lists of integers that index into the tensor) to values (some sort of scalar value) -- then Einstein summation notation is closely related to SQL, as it specifies a join followed by an aggregation over the input tensors.
The paper introduces EinSum, a tensor-relational version of classical Einstein Summation Notation, and studies how to automatically rewrite a computation in Einstein Notation into EinSum so that computationally intensive components are executed using efficient numerical kernels, while sparsity is managed relationally.
Think of it this way: the relational engine acts as a smart dispatcher. It only materializes the non-zero blocks of a tensor and passes those dense chunks down to a BLAS or cuBLAS kernel for the actual multiply-accumulate. The database handles the index bookkeeping; the GPU handles the math.
How the decomposition works
The paper introduces a system called SparseEinSum that automates the translation. At a high level, the process works in three steps:
- Parse the EinSum expression. The user writes a standard einsum string (or uses a PyTorch-like API). If it is unreasonable to require programmers to write EinSum expressions directly, they may instead specify computations using a PyTorch-like syntax, in which high-level operators such as
matmulact as thin wrappers around the underlying EinSum representation. - Search for the best decomposition. A greedy search is evaluated: along a path through the graph of EinSum expressions, greedily pick the decomposition that minimizes the cost. A dynamic programming approach is also available for more exhaustive optimization.
- Execute in two lanes. Sparse index structure is managed by the relational engine (SQL joins and aggregations). Dense sub-blocks are dispatched to optimized numerical kernels. The cost model decides where each boundary falls.
The notation itself uses a mixed upper/lower case convention to distinguish which indices are "relational" (managed by the database, sparse) versus "tensor" (managed by dense kernels). This is the core novelty -- a formal grammar that makes the boundary explicit and machine-readable, enabling automated optimization.

The numbers that matter
The benchmarks cover three workloads that are representative of real production pain points: sparse attention (as used in transformers over long or sparse sequences), graph neural network (GNN) inference, and quantum circuit simulation.
The headline result is striking. SparseEinSum can be more than 100x as fast when computing sparse attention rather than dense attention, and is 30x to 100x as fast as a pure relational approach with hyperparameter tuning in the sparse case.
The comparison baseline is revealing. The surprising finding is that even though relational computations are inherently sparse, the pure relational implementations are not much faster when using sparse attention compared to dense attention -- a pure relational approach is only up to 2x as fast in the sparse case compared to the dense case. The relational engine alone cannot exploit sparsity efficiently without the dense kernel layer underneath. SparseEinSum needs both halves to work.
Where this is and is not useful
The sweet spot for this approach is workloads that are simultaneously large, sparse, and mathematically intensive. Concrete use cases include:
- Graph neural networks on large real-world graphs, where adjacency matrices are extremely sparse but node feature multiplications are dense matrix operations.
- Sparse attention in transformers, where only a small fraction of token pairs actually attend to each other (e.g., local window attention, BigBird, Longformer patterns).
- Quantum circuit simulation, where the state vector is sparse for low-entanglement circuits but gate operations are dense unitary matrices.
- Knowledge graph embeddings, where entity-relation tensors are massively sparse but embedding lookups involve dense matrix multiplications.
The approach is less useful when data is dense throughout -- if your tensors are nearly full, the relational overhead adds cost without benefit. It also assumes the sparsity pattern is known ahead of time (or can be estimated), since the cost model needs to decide how to split the computation before execution begins.
The bigger picture
This work is part of a longer research arc. Tensor relational algebra proposes a relational layer on top of dense tensor algebra that provides a strong foundation for automatically optimizing distributed dense tensor computations. Prior work in this line -- including TRA (Tensor Relational Algebra) and EinDecomp -- focused on parallelism and distribution. This paper is the first in the series to tackle sparsity as a first-class concern, and to provide an automated rewriting system rather than requiring manual decomposition.
The tensor relational algebra has been suggested as the interface that could be exported by the back-end of a machine learning system, and through extensive experimentation it has been shown to be competitive with -- and often faster than -- other options, including HPC software such as ScaLAPACK and ML software such as TensorFlow and PyTorch. EinSum and SparseEinSum push this further by making the sparse case automatic.
No public code repository was announced alongside the paper. The work is available as a preprint on arXiv and a full-text version is accessible through the NSF Public Access Repository. For those building systems that need to handle large sparse tensor workloads without hand-tuning every kernel, this is a framework worth watching closely.