Abstract
We present a method for randomizing formulas for bilinear computation of matrix products which does not increase the leading order complexity of the computation. We consider the implications of such randomization when there are two sources of error: approximate computation formulas and floating-point arithmetic errors. Our theoretical results and numerical experiments indicate that our method can improve performance when these errors are present individually or simultaneously, particularly in low-precision hardware environments.
Introduction
Matrix multiplication is the fundamental computational engine driving fields ranging from climate modeling to the training of large-scale neural networks. While the standard algorithm requires $O(n^3)$ operations, "fast" algorithms, such as Strassen’s algorithm, reduce this complexity to $O(n^{2.81})$ or lower. Despite their theoretical appeal, two primary hurdles prevent the widespread adoption of new fast algorithms: the difficulty of discovering exact formulas and the inherent numerical instability of these algorithms in finite-precision arithmetic.
Researchers often employ numerical search techniques to find new algorithms. These searches frequently result in "Approximate Bilinear Computations" (ABCs)—formulas that are computationally efficient but mathematically slightly inaccurate. Furthermore, fast algorithms are notoriously sensitive to rounding errors, especially on low-precision hardware like GPUs (using 16-bit or 8-bit floats), where the clever cancellations required for speed can lead to significant divergence from the true result.
The RandABC Method
To address these challenges, we introduce RandABC (Randomized Approximate Bilinear Computation). This method wraps an existing, potentially approximate, matrix multiplication formula $f$ within a framework of random transformations. Given two matrices $A$ and $B$, the randomized estimate $\hat{f}(A, B)$ is computed as:
$$\hat{f}(A, B) = (1 - \kappa)^{-1} M_1^{-1} f(M_1 A M_2, M_2^{-1} B M_3) M_3^{-1}$$
In this construction, $M_1, M_2,$ and $M_3$ are random matrices formed by the product of a permutation matrix (which shuffles rows or columns) and a diagonal matrix of random signs ($\pm 1$). The constant $\kappa$ is a small rescaling factor that ensures the resulting estimator is unbiased.
Crucially, these transformations are "orthogonal" and computationally inexpensive. Permutations and sign flips do not alter the magnitude of the data and can be performed in $O(n^2)$ time. Consequently, the randomization does not increase the overall asymptotic complexity of the underlying fast algorithm (e.g., $O(n^{2.81})$).
Theoretical Insights: Unbiasedness and Stability
The most significant theoretical contribution of RandABC is the proof that even if the underlying algorithm $f$ is mathematically incorrect (an ABC), the randomized version $\hat{f}$ is an unbiased estimator. In expectation, the algorithm yields the exact product of the matrices: $E[\hat{f}(A, B)] = AB$.
Beyond unbiasedness, the randomization serves to "smear" numerical errors. Numerical instability in deterministic fast algorithms often arises when the specific structure of the input data aligns with the "blind spots" of the algorithm's algebraic structure. By randomly permuting and flipping signs, RandABC breaks this alignment, ensuring that no specific input structure can consistently trigger worst-case numerical behavior. This makes the method particularly robust against "adversarial" inputs.
Experimental Evaluation
The method was evaluated using several synthetic matrix distributions designed to stress-test numerical stability, including Gaussian, Uniform, and specifically constructed "Adversarial" matrices (Types 1, 2, and 3). We also tested the method on Hilbert matrices, which are notoriously ill-conditioned and often cause standard numerical solvers to fail.
Key Findings
- Superior Stability: In tests involving Hilbert and Type 3 adversarial matrices, RandABC significantly outperformed existing state-of-the-art rescaling techniques. While traditional diagonal rescaling failed to maintain accuracy in these difficult cases, RandABC consistently produced low-error results.
- Strassen Optimization: When applied to 5 levels of recursion with Strassen’s algorithm in single-precision floating-point arithmetic, the randomized version showed lower median errors and significantly fewer extreme outliers compared to the standard deterministic implementation.
- Efficiency: The computational overhead introduced by the random transformations was found to be negligible compared to the cost of the core matrix multiplication, confirming the practical viability of the approach.
Limitations and Future Directions
While RandABC provides an unbiased result, any single execution of the randomized algorithm will still contain some error (variance). For applications requiring extreme precision in a single pass, this variance must be managed, though experiments suggest it remains well-behaved in most contexts.
Future research may explore the integration of the Fast Hadamard Transform to further enhance the randomization process. Additionally, the inherent error tolerance of Neural Networks makes them an ideal candidate for randomized approximate multiplication, potentially allowing for extreme speedups in deep learning inference and training without sacrificing model performance.
Conclusion
RandABC offers a powerful framework for leveraging approximate matrix multiplication algorithms and improving the stability of existing fast algorithms. By utilizing computationally cheap random transformations, we can turn "almost correct" formulas into reliable, unbiased tools that are resilient to the numerical pitfalls of low-precision hardware.
Summary updated