Introduction
Deep learning models rely heavily on efficient operators like convolutions and matrix multiplications. Traditionally, achieving peak performance required significant manual effort from "ninja" programmers to write hardware-specific templates or rely on vendor libraries. Ansor, presented at OSDI '20, introduces a framework that automates this process. By moving away from rigid templates toward a hierarchical, automated search strategy, Ansor generates high-performance code that often surpasses state-of-the-art libraries across various hardware backends.
The Challenge: The "Ninja Gap"
The development of high-performance tensor programs faces several hurdles:
- Manual Effort: Vendor libraries (e.g., cuDNN) require extensive engineering for every new hardware architecture.
- Template Rigidity: Existing search-based compilers often use pre-defined templates. If an optimal optimization strategy is not included in the template, the compiler cannot discover it.
- Ineffective Search Spaces: Many tools attempt to build programs incrementally, but they often discard promising paths early because they cannot accurately predict the performance of incomplete programs.
Methodology
Ansor addresses these challenges by decoupling the high-level program structure from low-level implementation details.
Program Sampler and Hierarchical Search
Instead of a monolithic search space, Ansor employs a two-level hierarchical approach. It first generates sketches—high-level structures representing tiling and fusion—using a set of derivation rules. Subsequently, it applies annotations for low-level choices such as unrolling, parallelization, and specific tile sizes. This allows Ansor to explore a vast search space without the constraints of manual templates.
Performance Tuner and Learned Cost Model
To navigate billions of potential programs, Ansor uses an evolutionary search guided by a learned cost model. Specifically, it utilizes a Gradient Boosting Decision Tree (GBDT) to predict program execution speed. Unlike previous approaches that struggled with incomplete programs, Ansor only evaluates complete programs, significantly improving prediction accuracy.
Task Scheduler
For end-to-end model optimization, Ansor uses a gradient-descent-based task scheduler. This scheduler prioritizes subgraphs that are most likely to improve the overall performance of the entire neural network, rather than spending equal time on every layer.
Evaluation and Results
Ansor was evaluated on a diverse set of operators (e.g., 1D/2D/3D convolutions, GMM) and full-scale models (ResNet-50, BERT, MobileNet-V2) across Intel CPUs, NVIDIA GPUs, and ARM processors.
- Performance: Ansor outperformed existing frameworks like AutoTVM and Halide, as well as vendor libraries (MKL-DNN, cuDNN), by up to 3.8x on Intel CPUs and 1.7x on NVIDIA GPUs.
- Efficiency: It achieved comparable performance to AutoTVM while requiring 10x fewer measurement trials.
- Flexibility: Ansor successfully optimized uncommon operators, such as those in DCGAN, where manual tuning is often lacking.
Conclusion and Future Work
Ansor demonstrates that automated, template-free search can bridge the "ninja gap" in deep learning performance. While highly effective for static shapes and dense operators, future work includes extending support to dynamic shapes, sparse operators (e.g., for Graph Neural Networks), and deeper integration with back-end compilers to exploit specialized hardware instructions like Tensor Cores.
Summary updated