TL;DR
This paper introduces SparseEinSum, an automated framework that bridges the gap between relational databases and deep learning systems for massive-scale sparse tensor algebra. By decomposing Einstein Summation (EinSum) expressions into a hybrid "tensor-relational" format, the system leverages the scalability of databases to handle sparsity while using high-performance kernels for dense sub-computations, enabling the processing of graphs with over a billion edges that crash traditional frameworks.
What Problem Does This Paper Address?
Modern machine learning often involves massive, sparse tensors—think of a graph neural network (GNN) processing a social network with hundreds of millions of users.
Current tools fall into two camps, both with flaws:
- Deep Learning Frameworks (e.g., PyTorch, DGL): These excel at dense linear algebra on GPUs. However, they struggle with extreme sparsity. Storing a massive sparse matrix often leads to "Out-Of-Memory" errors, and sparse-dense kernels often utilize less than 0.1% of a GPU's theoretical compute power.
- Relational Databases (RDBMS): These are built to handle massive, sparse data via joins and aggregations. However, treating every single numerical value as a row in a table (the "triple" format) is incredibly inefficient for the actual math, leading to an explosion of intermediate tuples.
The authors seek a "middle way": tensor-relational computation, where database tuples carry small dense vectors or matrices instead of single scalars. The challenge is automation: how do you decide which parts of a complex tensor expression should be handled by the database and which should be tucked into a high-performance math kernel?
Methods
The authors introduce a new notation called upper-case-lower-case EinSum.
- Upper-case indices are "promoted" to the relational level (handled by SQL joins/groups).
- Lower-case indices are "demoted" to the tensor level (handled by dense kernels like BLAS or TACO).
To automate the translation from standard EinSum to this hybrid format, they developed the SparseEinSum algorithm:
- Cost Model: A sparsity-aware estimator that predicts the size of intermediate results. It treats "distinct values" in a database sense as "non-zero sub-tensors," allowing it to estimate how many tuples will exist after a join or aggregation.
- Dynamic Programming (DP): The algorithm searches the space of possible index promotions/demotions to find the plan with the lowest estimated cost.
- Compilation: The chosen plan is compiled into optimized SQL that executes on a distributed relational engine (PlinyCompute), calling specialized C++ kernels for the dense math.
Datasets
The system was evaluated on a wide range of benchmarks:
- Graph Datasets: Standard small sets (Cora, CiteSeer, Amazon) and massive-scale graphs including ogbn-papers100M (111M nodes, 1.6B edges) and Friendster (65M nodes, 1.8B edges).
- Quantum Benchmarks: Circuits from QASMbench (
seca_n11andmultiplier_n13), which involve complex tensor contractions.
Key Insights and Ideas
- The "Sweet Spot" of Granularity: The most important insight is that performance isn't binary. By grouping scalars into vectors (e.g., a vertex embedding of size 8192), you reduce the number of tuples the database has to manage by orders of magnitude while keeping the data small enough to fit in CPU/GPU caches for dense processing.
- Relational Engines as Orchestrators: Instead of building a new sparse tensor engine from scratch, the authors show that a relational engine is the perfect "sharding" and "sparsity" manager. It handles the messy work of data movement and parallelization, leaving the math to optimized kernels.
- Automatic Repartitioning: In complex chains of operations (like GNN layers), the optimal way to store a tensor might change (e.g., from row-vectors to column-vectors). SparseEinSum automatically detects these mismatches and generates "repartitioning" SQL to reshuffle the data.
Key Results
- Beating the Giants: On the largest graphs (1B+ edges), SparseEinSum successfully ran GNN training where DGL (PyTorch) and AliGraph failed due to memory exhaustion.
- Massive Speedups: For sparse attention mechanisms, SparseEinSum was 30x to 100x faster than pure relational implementations (like Hyper or Postgres) because it avoided the "tuple explosion" of scalar-based processing.
- Scalability: The system showed strong scaling, with a roughly 5x to 6.8x speedup when moving from 1 to 8 machines on massive graph workloads.
- Cost Model Accuracy: The DP-optimized plans ("Opt") consistently outperformed the second and third-best plans, validating the accuracy of their sparsity-aware cost model.
Limitations and Future Work
- Contraction Ordering: The current system focuses on how to decompose a binary EinSum. For "high-degree" expressions (multiplying many tensors at once), it relies on existing libraries to pick the order of operations. Integrating contraction order into the DP search is a future goal.
- Global vs. Local Optimization: The DP approach optimizes "trees" of expressions. In workloads where data is reused many times (like backpropagation), the current heuristic-based approach might miss some global optimizations.
- Hardware Heterogeneity: While the framework can call GPU kernels, the primary evaluation was on distributed CPUs. Deeply integrating GPU memory management into the relational buffer pool is a promising next step.
Summary updated