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

Optimizing Tensor Computation Graphs with Equality Saturation and Monte Carlo Tree Search

Jakob Hartmann, Guoliang He, Eiko Yoneki · DOI

Abstract

Optimizing the computation graphs of deep learning models is critical for efficient inference. Traditional rule-based rewrites suffer from the phase-ordering problem and memory constraints when using equality saturation. This paper presents a hybrid approach combining Equality Saturation with Monte Carlo Tree Search (MCTS) to intelligently explore the rewrite space. Additionally, a novel greedy cost function (OCF) is introduced to accurately extract optimal expressions from e-graphs containing shared subgraphs. Experimental results on 13 diverse models demonstrate up to an 11% inference speedup over state-of-the-art optimizers like TENSAT.

Introduction

The deployment of deep learning models relies on computation graph optimization to minimize latency. Compilers apply rewrite rules to fuse operations or replace them with more efficient alternatives. However, this process faces three primary challenges:

  1. The Phase-Ordering Problem: The sequence of rules matters; applying one rule may prevent a more beneficial one later.
  2. Memory Explosion: In "Equality Saturation," e-graphs represent many versions of a program simultaneously. For large networks, these structures grow exponentially, often hitting memory limits before finding the optimal version.
  3. Extraction Inaccuracies: Fast "greedy" extractors often fail because they "double-count" the cost of shared parts of the graph, such as skip connections in ResNets.
Figure 1: An e-graph representing the equivalence between multiplication and bit-shifting after applying a rewrite rule.

Methods

The proposed system addresses these hurdles through two main innovations:

  • MCTS-Guided Construction: Instead of exhaustive rule application, the system uses Monte Carlo Tree Search to strategically navigate the rewrite space. MCTS "plans" sequences of rewrites by simulating their impact on estimated latency, focusing memory resources on the most promising graph versions.
  • Optimized Cost Function (OCF): To improve the extraction phase, the researchers developed OCF. By tracking the history of operations, OCF prevents the overestimation of costs in graphs with shared components, allowing a fast greedy extractor to achieve results comparable to much slower exact mathematical solvers (ILP).
Figure 4: The system architecture integrates TASO for rules, MCTS for search guidance, and an e-graph for representing equivalent program versions.

The framework is built upon the TASO rewrite engine and the egg library for e-graph management, ensuring compatibility with industry-standard tools.

Evaluation and Results

The optimizer was tested on 13 architectures, including ResNet-50, BERT, and various Vision Transformers (ViT), using NVIDIA A100 and P100 GPUs. Key findings include:

  • Significant Speedups: The MCTS approach consistently outperformed TENSAT, yielding an 11% speedup for ResNeXt-50 and 8.5% for NasNet-A.
  • Efficient Extraction: The OCF cost function matched the accuracy of exact ILP solvers on 12 out of 13 models while being 3x to 6x faster.
  • Hardware Robustness: Improvements were consistent across different GPU generations, proving the structural optimizations are fundamentally sound.

Conclusion

By combining the exhaustive representational power of e-graphs with the strategic planning of MCTS, this work effectively mitigates the phase-ordering and memory explosion problems in tensor graph optimization. While the optimization process can be time-consuming, it is well-suited for "compile-once, run-forever" deployment scenarios. Future work will explore optimizing data layouts and modularizing the search for even larger models.

Summary updated

BibTeX
@inproceedings{hartmann2024optimizing,
  author = {Jakob Hartmann and Guoliang He and Eiko Yoneki},
  title = {{Optimizing Tensor Computation Graphs with Equality Saturation and Monte Carlo Tree Search}},
  booktitle = {PACT},
  year = {2024},
  url = {https://openreview.net/forum?id=KcyxUftXDC},
}
Figure