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

Ansor : Generating High-Performance Tensor Programs for Deep Learning

Lianmin Zheng, Chengfan Jia, Minmin Sun, Zhao Wu, Cody Hao Yu, Ameer Haj-Ali, Yida Wang, Jun Yang, Danyang Zhuo, Koushik Sen, Joseph E. Gonzalez, Ion Stoica

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:

  1. Manual Effort: Vendor libraries (e.g., cuDNN) require extensive engineering for every new hardware architecture.
  2. 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.
  3. 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.

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.

Figure 1: Mathematical definition and high-level code representation for matrix multiplication in Ansor.

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.

Figure 2: Pairwise accuracy of the learned cost model as a function of the fraction of programs considered.

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

BibTeX
@inproceedings{zheng2020ansor,
  author = {Lianmin Zheng and Chengfan Jia and Minmin Sun and Zhao Wu and Cody Hao Yu and Ameer Haj-Ali and Yida Wang and Jun Yang and Danyang Zhuo and Koushik Sen and Joseph E. Gonzalez and Ion Stoica},
  title = {{Ansor : Generating High-Performance Tensor Programs for Deep Learning}},
  booktitle = {OSDI},
  year = {2020},
  url = {https://openreview.net/forum?id=WzFNX7zbI0l},
}
Figure