NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Optimizing Memory Mapping Using Deep Reinforcement Learning

Pengming Wang, Mikita Sazanovich, Berkin Ilbeyi, Phitchaya Mangpo Phothilimthana, Manish Purohit, Han Yang Tay, Ngân Vu, Miaosen Wang, Cosmin Paduraru, Edouard Leurent, Anton Zhernov, Julian Schrittwieser, Thomas Hubert, Robert Tung, Paula Kurylowicz, Kieran Milan, Oriol Vinyals, Daniel J. MankowitzarXiv 2023 · DOI

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.

A visualization of the memory layout over time, which serves as the 2D input representation for the MMap-MuZero agent.

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).

Summary of the features used to characterize each buffer within the reinforcement learning environment.

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

BibTeX
@misc{wang2023optimizing,
  author = {Pengming Wang and Mikita Sazanovich and Berkin Ilbeyi and Phitchaya Mangpo Phothilimthana and Manish Purohit and Han Yang Tay and Ngân Vu and Miaosen Wang and Cosmin Paduraru and Edouard Leurent and Anton Zhernov and Julian Schrittwieser and Thomas Hubert and Robert Tung and Paula Kurylowicz and Kieran Milan and Oriol Vinyals and Daniel J. Mankowitz},
  title = {{Optimizing Memory Mapping Using Deep Reinforcement Learning}},
  year = {2023},
  eprint = {2305.07440},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.07440},
}
Figure