Introduction
In the field of machine learning compilation, memory mapping is a critical yet computationally expensive challenge. Researchers at Google DeepMind have recently introduced MMap-MuZero, a specialized reinforcement learning (RL) agent that treats memory mapping as a single-player game. By moving beyond traditional human-designed heuristics, this approach has achieved an average execution speedup of 4.05% on real-world workloads, with performance gains reaching as high as 87% for specific models.
The Memory Mapping Problem
Modern machine learning accelerators, such as Google’s TPUs, utilize a tiered memory hierarchy consisting of a small, high-speed "scratchpad" memory (CMEM) and a larger, slower main memory (HBM). The compiler's task is to determine which tensors should reside in the fast memory and when they should be moved to maximize performance.
This memory mapping problem is NP-hard. Every decision, such as prefetching a tensor too early, can inadvertently block space for more critical operations later in the execution timeline. Traditional compilers like XLA (Accelerated Linear Algebra) rely on expert-designed heuristics. However, given the massive search space of modern models—estimated at $10^{4000}$ possible trajectories—these heuristics often fail to find the most efficient schedules.
Methodology: MMap-MuZero
The authors adapted the MuZero algorithm, originally famous for mastering games like Chess and Go, to create MMap-MuZero. The optimization process is framed as the MMapGame, where the agent processes program instructions sequentially and chooses one of three actions for each buffer: Copy (move to fast memory), NoCopy (reuse existing allocation), or Drop (remain in slow memory).
Representation and Features
To perceive the state of memory, the agent utilizes a combination of ResNets and ConvNets to process a 2D binary grid representing the memory layout over time. This allows the agent to "see" fragmentation and availability within the scratchpad memory.
The agent's decisions are informed by a set of specific features for each buffer, including its size, its role as an output or operand, and its estimated "benefit" (the speedup gained if placed in CMEM).
Robust Learning Mechanisms
To handle the risk of reaching "infeasible states" (where no legal moves remain), the researchers implemented a Drop-backup mechanism. This allows the agent to roll back to a safe state and apply a "Drop" action rather than failing the entire episode, facilitating more effective credit assignment during training. Additionally, a hybrid production agent, MMap-MuZero-prod, runs the RL agent alongside existing XLA heuristics and selects the best result, ensuring performance never regresses below the baseline.
Experimental Evaluation
The approach was evaluated on a benchmark of 60 machine learning workloads, including 52 models from the standard XLA TPU suite and 8 high-impact internal production workloads. The agent was also tested on AlphaTensor, a state-of-the-art matrix multiplication model, to determine if further optimization was possible.
Key Results and Insights
- Performance Gains: MMap-MuZero improved execution time for 33 out of 60 programs, achieving a maximum speedup of 87% on one workload and an average speedup of 4.05% across the entire fleet. It even improved AlphaTensor’s execution time by 5.78%.
- Strategic Discovery: Qualitative analysis revealed that the agent discovered strategies often overlooked by humans, such as aggressively "evicting" tensors from fast memory when not needed for long periods to free up space, rather than keeping them in CMEM for their entire lifetime.
- The Importance of Proxy Rewards: The agent's success was found to be highly dependent on the correlation between the "proxy reward" (estimated speedup) and actual hardware latency. Strengthening this correlation is a key factor in achieving real-world gains.
Conclusion and Future Work
While MMap-MuZero demonstrates the power of gamifying systems optimization, challenges remain. Currently, the agent is trained from scratch for each new model, a process that can take up to 24 hours. Future research will focus on transfer learning to allow agents to generalize across different workloads and improving the accuracy of proxy reward models to better reflect hardware realities. Despite these hurdles, the 4% fleet-wide improvement represents a significant step forward in reducing energy and hardware costs for hyperscale computing.
Summary updated