Introduction
Optimizing the low-level implementation of deep learning models is a critical yet labor-intensive task. Researchers at Facebook AI Research (FAIR) introduced a novel approach at NeurIPS 2020 that treats code optimization as a reinforcement learning problem. By utilizing a learned value function, they demonstrate that "schedules"—the specific execution patterns on hardware—can be discovered in seconds rather than hours, while outperforming current industry standards.
The Scheduling Bottleneck
Deep learning frameworks typically rely on hand-optimized libraries like cuDNN. While effective, manual optimization is a bottleneck that requires rare expertise and often fails to optimize non-standard operators. Compilers like Halide and TVM attempt to automate this by separating the algorithm from the schedule (e.g., loop tiling, vectorization, and parallelization). However, the scheduling search space is combinatorially explosive, making exhaustive benchmarking on hardware prohibitively slow.
Methodology: Reinforcement Learning for Code Optimization
The researchers reframed scheduling as a Markov Decision Process (MDP). In this framework, a state represents a partial schedule, and an action is a specific scheduling choice for a layer.
The core of the system is a learned Value Function ($V(s)$), implemented via an LSTM-based model. This function predicts the best possible runtime achievable from a given partial schedule by analyzing both intrinsic mathematical features and acquired scheduling features. With a sufficiently accurate value function, the system can make "greedy" decisions at each step, effectively bypassing the need for exhaustive search or backtracking.
Performance and Efficiency
The system was evaluated across 12 diverse deep learning workloads, including image classification (ResNet, MobileNet) and sequence models (Transformer, WaveNet), on both Intel CPUs and NVIDIA GPUs.
Key Results
- Search Speed: The approach is 2 to 3 orders of magnitude faster than existing tools. While AutoTVM requires an average of 3 hours to optimize a network, this method completes the task in approximately 13 seconds.
- Execution Performance: The discovered schedules resulted in code that was 5.1x faster than default PyTorch implementations, 2.6x faster than Halide’s auto-scheduler, and 1.5x faster than TVM.
- Predictive Accuracy: The model achieved high predictive accuracy ($R^2 > 0.955$), allowing local greedy decisions to yield globally optimal results.
Conclusion
By leveraging a learned value function to navigate the optimization search space, this research significantly reduces the time required to generate high-performance kernels. While the model requires hardware-specific training, its ability to generalize across diverse models and provide near-instantaneous scheduling makes it a powerful tool for the future of deep learning compilers.
Summary updated