Abstract
We present a deep reinforcement learning approach to minimizing the execution cost of neural network computation graphs in an optimizing compiler. Unlike earlier learning-based works that require training the optimizer on the same graph to be optimized, we propose a learning approach that trains an optimizer offline and then generalizes to previously unseen graphs without further training. This allows our approach to produce high-quality execution decisions on real-world TensorFlow graphs in seconds instead of hours. We consider two optimization tasks for computation graphs: minimizing running time and peak memory usage. In comparison to an extensive set of baselines, our approach achieves significant improvements over classical and other learning-based methods on these two tasks.
Introduction
When a compiler prepares a neural network for execution, it must make two critical decisions: placement (which processor runs which operation?) and scheduling (in what order should operations run on each processor?). These decisions directly impact execution speed and peak memory usage. This is a classic NP-hard problem. Traditionally, compilers use hand-tuned heuristics that are fast but often sub-optimal. Recent research applied Reinforcement Learning (RL) to find better solutions, but these "first-generation" RL optimizers had to be trained from scratch for every new neural network graph, often requiring 12–27 hours for the optimizer to retrain. REGAL (Reinforced Genetic Algorithm Learning) aims to provide an "offline" trained optimizer that generalizes to completely unseen graphs instantly.
Methods
REGAL utilizes a hybrid approach that combines the structural awareness of Graph Neural Networks (GNNs) with the robust search capabilities of Genetic Algorithms.
- The Search Engine (BRKGA): The system uses the Biased Random-Key Genetic Algorithm. It represents solutions as vectors of "random keys" in the range [0, 1], which are then decoded into specific placement and scheduling decisions.
- The Neural Policy (GNN): Instead of using a uniform distribution to generate new candidates, REGAL uses a GNN to predict node-specific Beta distributions.
- Guidance, Not Direct Prediction: The GNN doesn't predict the final schedule directly. Instead, it predicts the parameters of the distributions that the genetic algorithm uses to sample new "mutant" solutions. This allows the GNN to learn high-level strategies while the genetic algorithm handles the fine-grained search.
- Training: The model is trained using the REINFORCE algorithm, where the reward is the improvement in execution time or memory usage compared to a standard, non-learned version of the genetic algorithm.
Datasets
The researchers evaluated REGAL on three distinct datasets:
- TF Real-world Dataset: 372 unique, topologically diverse TensorFlow graphs mined from Google’s internal clusters, augmented to create over 20,000 training instances.
- Synthetic Dataset: 10,000 graphs generated using classical random graph models (like Erdos-Renyi) to test structural generalization.
- XLA Benchmarks: Production compiler graphs used to test "out-of-distribution" generalization on graphs much larger than those in the training set.
Key Results
REGAL demonstrated superior performance across multiple metrics and datasets, significantly outperforming both classical heuristics and other learning-based methods.
- Superior Performance: REGAL outperformed all baselines, including XLA’s default heuristics. As shown in the results table, it achieved a 7.09% improvement over the BRKGA 5K baseline on the TF Runtime test set.
- Massive Speedup: While previous RL methods took hours per graph, REGAL produces high-quality decisions in about 1 second.
- Memory Efficiency: On the task of minimizing peak memory, REGAL reduced the "gap to the best known solution" to just 4.44%, a significant improvement over standard BRKGA.
- Zero-Shot Generalization: Even when tested on XLA benchmark graphs with 10x more nodes than the training data, REGAL provided measurable improvements without any additional training.
Conclusion
The most significant insight from REGAL is that a GNN can learn structural features of computation graphs that transfer across different architectures. By using the RL model to bias a search algorithm, the system gains the intuition of deep learning alongside the mathematical guarantees of search. While the current system relies on a static cost model, future work could integrate this directly into production compilers like LLVM or XLA to handle even larger industrial-scale graphs.
Summary updated