Computational Biology2022advanced13 min read
Discovering Faster Matrix Multiplication Algorithms with Reinforcement Learning
اكتشاف خوارزميات أسرع لضرب المصفوفات بالتعلّم المعزَّز
Fawzi, A. · Balog, M. · Huang, A. · Hubert, T. · Romera-Paredes, B. · Barekatain, M. · Novikov, A. · Ruiz, F. J. R. · Schrittwieser, J. · Swirszcz, G. · Silver, D. · Hassabis, D. · Kohli, P. — Nature
The problem
multiplication is one of the most fundamental operations in computing — it powers neural networks, computer graphics, scientific simulations, and data compression. The naive for multiplying two n×n matrices requires n³ scalar multiplications. In 1969, Strassen shocked the mathematical community by showing that 2×2 matrices can be multiplied with 7 multiplications instead of 8, yielding an asymptotically faster algorithm. But for 50 years after Strassen, finding better algorithms for larger matrices remained an open problem. The search space is astronomically large — for a 4×4 multiplication, there are more possible algorithms than atoms in the universe — and human intuition alone had reached its limits.
The contribution
AlphaTensor reformulates the search for matrix multiplication algorithms as a single-player game called TensorGame, where the state is a 3D and each move selects a -1 outer product to subtract from it. The goal is to zero out the tensor in the fewest moves — each move corresponds to one multiplication in the final algorithm. Built on AlphaZero with a custom architecture and , AlphaTensor rediscovers Strassen's algorithm from scratch, then surpasses it: for 4×4 matrices over a finite field, it finds an algorithm using 47 multiplications, beating Strassen's two-level 49 for the first time in 50 years. It also discovers thousands of non-equivalent algorithms and optimizes for specific hardware, achieving 10–20% speedups on GPU and TPU.
The impact
AlphaTensor demonstrated that can surpass decades of human expertise in algorithm discovery for a foundational mathematical problem. It established a new paradigm: turning open mathematical conjectures into games that AI agents can learn to play. The work inspired AlphaEvolve and other AI-for-math systems, and showed that the AlphaZero framework generalizes far beyond board games into scientific discovery. Practically, the hardware-optimized algorithms discovered by AlphaTensor can accelerate any system that relies on matrix multiplication — from training neural networks to rendering graphics.
Imagine you need to ship a cargo container across the ocean. The "standard" route makes 100 stops. A clever logistics genius named Strassen found a route with only 49 stops — but for 50 years, nobody could find anything shorter.
Now imagine giving a virtual explorer a blank map and telling it: "Find any route that delivers the cargo correctly. The fewer stops, the bigger your ." The explorer knows nothing about shipping or geography — it just starts trying random routes, learning from each attempt.
After millions of tries, this explorer — AlphaTensor — discovers routes with only 47 stops. Not one route, but thousands of valid shortcuts that no human cartographer ever found. And when you tell it to optimize for a specific type of ship (a GPU or TPU), it finds routes that are 10–20% faster on that particular vessel.
Why matrix multiplication is the heartbeat of computing
Every time you ask a voice assistant a question, apply a filter to a photo, or run a neural network, the computer is multiplying matrices. Matrix multiplication is to computing what addition is to arithmetic — a primitive operation that everything else builds upon. Speeding it up by even a small fraction compounds across billions of daily computations worldwide.
The schoolbook algorithm for multiplying two n×n matrices performs n³ multiplications: for two 2×2 matrices, that means 2³ = 8 multiplications. Each scalar multiplication is the expensive step — additions are comparatively cheap. So the fundamental question becomes: can we multiply matrices using fewer multiplications?
Strassen's breakthrough — and 50 years of silence
In 1969, Volker Strassen proved that 2×2 matrix multiplication can be done with 7 multiplications instead of 8. The trick: instead of computing each entry of the result independently, combine rows and columns of the input matrices in clever sums, multiply those sums, then recombine the products to get the final answer. You trade one multiplication for several extra additions — a good deal because multiplications dominate the cost.
Strassen's insight has a profound consequence: by applying the 2×2 trick recursively to larger matrices (divide each n×n matrix into four n/2 × n/2 blocks), the asymptotic complexity drops from O(n³) to roughly O(n^2.807). For large matrices, this is a massive speedup. But for larger base cases — 3×3, 4×4, 5×5 — nobody knew the optimal number of multiplications. The search space grows so rapidly that brute-force enumeration is impossible.
The key insight: matrix multiplication is tensor decomposition
Here is the elegant mathematical connection that makes AlphaTensor possible. Any algorithm for multiplying an m×k matrix by a k×n matrix can be encoded as a decomposition of a 3D tensor of size (mk) × (kn) × (mn). Think of this tensor as a cube of numbers that encodes which entries of the input matrices need to be combined to produce each entry of the output.
Each "step" of the algorithm — one scalar multiplication — corresponds to one rank-1 term in the decomposition: three vectors u, v, w whose outer product u ⊗ v ⊗ w contributes one layer of the tensor. The total number of rank-1 terms is the rank of the decomposition, and it equals the number of scalar multiplications the algorithm uses.
The standard algorithm for 2×2 matrices has rank 8. Strassen's has rank 7. Finding a faster algorithm means finding a lower-rank decomposition of the same tensor — a classic problem in algebraic complexity theory that has resisted human efforts for decades.
TensorGame: turning math into a game an AI can play
The crucial design decision of this paper is reframing tensor decomposition as a single-player game. The game works as follows:
State: a 3D tensor S_t, initialized to the matrix multiplication tensor 𝒯. Action: at each step t, the player chooses three vectors u, v, w and subtracts their outer product from the current state to get the next state: S minus u ⊗ v ⊗ w. Goal: reduce S_t to the all-zeros tensor. Reward: a negative reward at each step (encouraging fewer steps), plus a large negative penalty if the tensor is not zeroed by a maximum number of steps.
The number of steps to reach zero equals the rank R — the number of multiplications. Playing the game optimally means finding the lowest-rank decomposition, which is the most efficient algorithm.
How AlphaTensor thinks: architecture and training
AlphaTensor builds on AlphaZero but introduces critical innovations to handle the unique challenges of TensorGame. Unlike Go where the board is a 2D grid with 361 possible moves, TensorGame involves a 3D tensor with an exceeding 10³³ — thirty orders of magnitude larger than Go.
The neural network is an encoder-decoder Transformer. The encoder takes three inputs: the current tensor state (projected along all three axes to capture its 3D structure), the last several actions taken (for temporal context), and a scalar time embedding. It processes the tensor through attention layers that treat all three cyclic transpositions of the axes equally — a key inductive bias that respects the mathematical symmetry of tensor decomposition.
The decoder outputs two things: a — a distribution over candidate actions (which u, v, w to choose next) — and a value — an estimate of how many more steps are needed from the current state. Since enumerating all possible actions is infeasible, AlphaTensor uses the Sampled AlphaZero approach: the network proposes a small set of promising candidate actions, and Monte Carlo Tree Search explores among them.
Training combines two data sources. First, synthetic demonstrations: randomly generated tensor decompositions that provide a warm-start curriculum. These are not optimal solutions — just valid ones that teach the network the basic structure of the problem. Second, self-play games: the agent plays TensorGame using MCTS, and the resulting trajectories are added to a replay buffer. The network is trained to predict both the policy (which move was selected by MCTS) and the value (how many steps remained) from each state.
A crucial technique is change-of-basis augmentation: the same tensor can be expressed in many equivalent coordinate systems. By randomly transforming the tensor before each game, AlphaTensor sees diverse views of the same problem, injecting symmetry awareness without hardcoding it. The agent plays all views in parallel and only needs to solve one — if any basis yields a decomposition, it's mathematically valid in all bases.
Results: surpassing 50 years of human discovery
AlphaTensor was trained on a range of matrix sizes from 2×2 up to 5×5, and its discoveries were remarkable.
Starting from zero knowledge, the agent first rediscovers the standard algorithms, then Strassen's 7-multiplication solution for 2×2 matrices, and then pushes beyond. For 4×4 matrices over the finite field Z/2Z (modular arithmetic mod 2), AlphaTensor discovered an algorithm using 47 multiplications — beating Strassen's two-level recursion of 49 for the first time since 1969.
For the practically important case of multiplying a 4×5 by a 5×5 matrix, where the standard algorithm uses 100 multiplications and prior human-designed algorithms had reached 80, AlphaTensor found algorithms using only 76. Across more than 70 matrix sizes tested, AlphaTensor improved upon the best known algorithm in many cases and matched it in the rest.
Perhaps even more surprising: AlphaTensor discovered over 14,000 non-equivalent algorithms for a single problem (4×4 matrix multiplication). This diversity revealed that the space of efficient algorithms is far richer than mathematicians had suspected.
Beyond theory: optimizing for real hardware
Minimizing the number of multiplications is not the only objective that matters. Different algorithms with the same number of multiplications can have very different runtimes on real hardware because of factors like memory access patterns, parallelism, and cache utilization.
AlphaTensor exploits the diversity of its discovered algorithms by adding a second optimization stage. After finding many mathematically equivalent algorithms (same rank), it benchmarks each one on a target hardware platform — such as an NVIDIA V100 GPU or a Google TPU v2 — and feeds the runtime back as an additional reward signal.
The result: hardware-tailored algorithms that run 10–20% faster than commonly used implementations on the same hardware. This demonstrates a key advantage of AI-driven algorithm discovery: the ability to optimize for arbitrary, non-mathematical objectives that matter in practice.
Simplified to show the idea — not the real implementation.
# AlphaTensor training loop (simplified)
# 1. Initialize: load matrix multiplication tensor T
T = build_matmul_tensor(m, k, n)
# 2. Generate synthetic demonstrations
demos = generate_random_decompositions(T, num_demos=10000)
# 3. Training loop
for episode in range(num_episodes):
# Change-of-basis augmentation
T_aug = random_change_of_basis(T)
# Play TensorGame with MCTS
trajectory = mcts_play(network, T_aug, max_steps=R_max)
# Reward: negative step count (fewer = better)
reward = -len(trajectory)
# Add to replay buffer
buffer.add(trajectory, reward)
# Train network on buffer + demos
network.train(buffer, demos)
# Track best decomposition found
if len(trajectory) < best_rank:
best_rank = len(trajectory)
best_algorithm = trajectoryThe bigger picture: from games to scientific discovery
AlphaTensor is part of a broader trajectory at DeepMind: extending the AlphaZero framework from board games to real-world problems. AlphaZero mastered chess, Go, and shogi. MuZero learned to plan without even knowing the rules. AlphaTensor shows the next step — applying the same principles to an open problem in pure mathematics.
The approach is generalizable. Any problem that can be expressed as "take a sequence of actions to reach a verifiable goal state" is a candidate for this framework. Potential applications include discovering faster algorithms for other computational primitives (sorting, FFT, convolution), optimizing circuit layouts, finding new chemical synthesis pathways, and more.
The paper also connects to AlphaFold 2 — another instance of DeepMind applying AI to solve a fundamental scientific problem that had resisted decades of human effort. Together, these works suggest a new paradigm where AI is not just a tool for automating known tasks, but a partner in scientific discovery itself.
Timeline: the road to AlphaTensor and beyond
1969
Strassen's algorithm
Volker Strassen proves 2×2 matrix multiplication can be done in 7 multiplications instead of 8, breaking the n³ barrier for the first time.
2016
AlphaGo defeats Lee Sedol
DeepMind's AlphaGo beats the world Go champion, demonstrating that deep RL with MCTS can master complex strategic games.
2017
AlphaZero — one algorithm for all games
AlphaZero masters chess, Go, and shogi from self-play alone, with no human data. Proves that tabula rasa learning can surpass human expertise.
2019
MuZero — planning without rules
MuZero learns to plan in environments where the rules are unknown, building an internal model of the dynamics. Extends AlphaZero to Atari games.
2022
AlphaTensor — from games to mathematics
First extension of AlphaZero to an open mathematical problem. Discovers faster matrix multiplication algorithms, beating Strassen's 50-year record.
2025
AlphaEvolve — evolving algorithms with Gemini
DeepMind's AlphaEvolve uses large language models to design advanced algorithms for math and computing, extending the AI-for-algorithms paradigm further.
AlphaTensor's deepest contribution is not any single algorithm it discovered, but the proof of concept: open mathematical problems, long considered the exclusive domain of human genius, can be attacked by AI agents that learn from scratch. The search space may be astronomically large, but a well-designed game formulation combined with powerful neural networks and tree search can find needles in haystacks that humans could not even begin to sift through.
CitationFawzi, Balog, Huang, Hubert, Romera-Paredes, Barekatain, Novikov, Ruiz, Schrittwieser, Swirszcz, Silver, Hassabis, Kohli. Discovering faster matrix multiplication algorithms with reinforcement learning. Nature, 2022.
Terms in this paper
- Tensorالموتّر
- Tensor Contractionانقباض المُوتِّر
- Matrixالمصفوفة
- Matrix Factorizationتحليل المصفوفات
- Rankالرتبة
- Low-Rank Decompositionالتفكيك مُنخَفِض الرُّتبة
- Outer Product Meanمتوسط الجداء الخارجي
- Reinforcement Learningالتعلم المعزز
- Deep Reinforcement Learningالتعلم العميق بالتعزيز
- Monte Carlo Tree Searchخوارزمية بحث شجرة مونت كارلو
- Self-Playاللعب الذاتي
- Action Spaceفضاء الأفعال
- Explorationالاستكشاف (تجربة أفعال جديدة)
- Combinatorial Optimizationالأمثَلة التوافقية
- Policyالسياسة