Abstract
We present ALX, an open-source library for distributed matrix factorization using Alternating Least Squares (ALS), written in JAX. Our design allows for efficient use of the TPU architecture and scales well to matrix factorization problems of O(B) rows/columns by scaling the number of available TPU cores. In order to spur future research on large scale matrix factorization methods and to illustrate the scalability properties of our own implementation, we also built a real world web link prediction dataset called WebGraph. This dataset can be easily modeled as a matrix factorization problem. We created several variants of this dataset based on locality and sparsity properties of sub-graphs. The largest variant of WebGraph has around 365M nodes and training a single epoch finishes in about 20 minutes with 256 TPU cores. We include speed and performance numbers of ALX on all variants of WebGraph. Both the framework code and the dataset is open-sourced.
Introduction
Matrix Factorization (MF) remains a foundational technique for recommendation systems and graph analysis, often outperforming deep learning models in real-world sparse data scenarios. However, scaling MF to "web-scale" (billions of entries) presents significant challenges. While Google’s Tensor Processing Units (TPUs) offer immense compute power and high-speed interconnects, they are optimized for the regular, dense computations of deep learning. Adapting them for the sparse, irregular nature of matrix factorization requires overcoming constraints related to static tensor shapes and distributed memory management.
ALX is a new open-source JAX library designed to bridge this gap, enabling massive-scale matrix factorization using Alternating Least Squares (ALS) on TPU pods. By treating the TPU pod as a single massive distributed memory system, ALX successfully factorized a web-scale graph with over 365 million nodes and 29 billion edges.
Distributed Architecture and Methods
ALX treats the TPU pod as a unified distributed memory system. Embedding tables are uniformly sharded across all available TPU cores, with each core holding a fraction of the user ($W$) and item ($H$) embeddings. This architecture relies on efficient "gather" and "scatter" operations to synchronize weights across the network of chips.
Overcoming TPU Constraints
To utilize TPUs effectively, ALX addresses two primary technical hurdles:
- Dense Batching: TPU compilers (XLA) require fixed-size tensors. However, real-world sparse data has wildly varying row lengths. ALX introduces "Dense Batching," which breaks long, sparse rows into multiple smaller, fixed-length "dense" rows. A mapping is maintained to reconstruct the original data, satisfying XLA's static shape requirements without the memory waste of excessive padding.
- Iterative Solvers: While standard ALS often uses exact solvers like Cholesky decomposition, ALX employs Conjugate Gradients (CG). CG is an iterative algorithm that relies heavily on matrix-vector products, which map perfectly to the TPU’s Matrix Multiply Unit (MXU). This synergy allows CG to scale significantly better than traditional solvers as the embedding dimension grows.
- Mixed Precision: To balance memory efficiency and numerical stability, ALX stores embeddings in
bfloat16but performs the critical "Solve" step infloat32. This prevents the "unrecoverable collapse" in model accuracy observed when using lower precision for the linear system solver.
The WebGraph Dataset
To benchmark ALX, the authors introduced WebGraph, derived from the Common Crawl web link dataset. It includes six variants ranging from locale-specific graphs to the massive WebGraph-sparse, which contains 365.4 million nodes and 29.9 billion edges. The primary task is link prediction, modeling which pages a given page is likely to link to.
Performance and Scaling
ALX demonstrates impressive efficiency at scale. On the largest WebGraph-sparse dataset, a single training epoch finishes in just 20 minutes using 256 TPU cores. A full training run of 16 epochs takes approximately 5.5 hours. The resulting model contains approximately 100 billion parameters, demonstrating that ALX can handle models orders of magnitude larger than those that fit on a single machine.
Scaling analysis shows that for dense variants, the system achieves near-perfect linear scaling until network communication overhead becomes the primary bottleneck. This "sweet spot" for scaling depends on the dataset size and the number of available TPU cores.
Conclusion and Future Work
ALX provides a scalable framework for web-scale matrix factorization, though some challenges remain. Model evaluation (finding "top-k" neighbors) is currently a bottleneck on TPUs due to sorting complexity; future implementations may utilize approximate Maximum Inner Product Search (MIPS). Additionally, the sharded nature of the embeddings means large datasets have a minimum hardware requirement (e.g., 32 TPU cores for WebGraph-sparse). By open-sourcing both the ALX library and the WebGraph dataset, the authors aim to spur further research into massive-scale sparse matrix problems and hardware-optimized iterative solvers.
Summary updated