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

Tensor Program Optimization with Probabilistic Programs

Junru Shao, Xiyou Zhou, Siyuan Feng, Bohan Hou, Ruihang Lai, Hongyi Jin, Wuwei Lin, Masahiro Masuda, Cody Hao Yu, Tianqi Chen

Deep learning models must execute efficiently across a dizzying array of hardware, from massive cloud GPUs to tiny edge devices. To extract maximum performance, the low-level code for operations like matrix multiplication—known as "tensor programs"—must be heavily optimized for specific hardware architectures using techniques like loop tiling, vectorization, and threading.

Historically, this optimization has been done either manually, which is slow and expensive, or via "auto-schedulers" like TVM's Ansor. However, existing auto-schedulers suffer from a major flaw: their search spaces are hard-coded. If a domain expert wants to add a new optimization trick for a specific chip, they often have to perform surgical modifications to the compiler's core logic. This lack of modularity makes it exceedingly difficult to keep up with rapidly evolving hardware primitives, such as NVIDIA's Tensor Cores.

To solve this, researchers have introduced MetaSchedule, a system that provides a probabilistic programming abstraction allowing developers to modularly define and grow the search space for tensor program optimizations. By decoupling search space construction from the search algorithm, MetaSchedule enables domain experts to easily incorporate hardware-specific knowledge, leading to significant performance gains.

High-level workflow of MetaSchedule, illustrating how an initial tensor program is expanded into a search space and optimized.

Methods: A Probabilistic Approach to Optimization

MetaSchedule shifts the paradigm by treating search space construction as a probabilistic program.

  1. Probabilistic Abstraction: Instead of relying on a static set of rules, the search space is defined by a program that makes stochastic choices. For example, a program might instruct the system to "sample a tile size from this distribution" or "decide randomly whether to fuse these two operators."
  2. Transformation Modules: These are reusable, modular blocks of optimization logic. An expert can write a "Multi-Level Tiling" module once and apply it to many different operators (e.g., Conv2D, Dense).
  3. Execution Tracing: When the probabilistic program runs, the system records a "trace" of all the random choices made. This trace represents one specific, concrete way to optimize the tensor program.
  4. Learning-Driven Search: MetaSchedule uses an evolutionary search algorithm (specifically, annealed Metropolis-Hastings) to explore the space of possible traces. This exploration is guided by a learned cost model—a tree-boosting model—that predicts how fast a specific program will run on actual hardware, saving the system from having to physically measure every single candidate.
An example of parameterized transformations, showing how an initial program is split, parallelized, and vectorized into an optimized equivalent.

Key Insights

  • Decoupling is King: By separating the definition of the search space (the probabilistic programming language) from the exploration of that space (the evolutionary search), the system becomes vastly more extensible.
  • Modular Expertise: The core breakthrough is that domain knowledge can now be encapsulated into small, 50-100 line Python modules. For instance, a graduate student was able to add support for specialized hardware primitives (Tensor Cores) in just two days—a task that previously required deep, complex compiler engineering.
  • Tracing over Control Flow: By tracing only the sampling and transformation instructions while ignoring the host language's (Python) control flow, MetaSchedule allows developers to use the full power and flexibility of Python to write complex meta-logic for their search spaces.

Evaluation and Results

The authors evaluated MetaSchedule on a wide range of operators (including various convolutions, GEMM, and normalization layers) and end-to-end models (BERT-Base, BERT-Large, ResNet-50, and MobileNet-v2). They compared it against PyTorch (representing vendor-optimized libraries like cuDNN/mkl) and TVM/Ansor (the previous state-of-the-art in automatic optimization).

  • Performance Parity and Beyond: MetaSchedule consistently matched or outperformed TVM (Ansor) across nearly all tested operators on both CPU and GPU.
  • Significant Speedups: On end-to-end workloads, MetaSchedule significantly outperformed PyTorch.
  • The Power of Customization: By adding a hardware-specific Use-Tensor-Core module consisting of only 82 lines of code, MetaSchedule achieved a 48% speedup on BERT-Large compared to the previous state-of-the-art.
  • Expressiveness: The system successfully demonstrated that it could cover the search spaces of previous frameworks modularly, rather than relying on hard-coded templates.

Limitations and Future Work

While MetaSchedule drastically simplifies the addition of domain knowledge, it still requires an expert who understands hardware-level optimizations to write the initial transformation modules. Furthermore, like all auto-tuning frameworks, finding the "optimal" program requires significant search time, though this remains comparable to previous methods.

Looking ahead, the authors suggest moving toward a more declarative API where users can simply describe hardware properties, allowing the system to automatically derive the necessary probabilistic transformation modules. They also plan to explore more advanced search algorithms, such as Bayesian Optimization or Reinforcement Learning, within this new probabilistic framework.

Summary updated

BibTeX
@inproceedings{shao2022tensor,
  author = {Junru Shao and Xiyou Zhou and Siyuan Feng and Bohan Hou and Ruihang Lai and Hongyi Jin and Wuwei Lin and Masahiro Masuda and Cody Hao Yu and Tianqi Chen},
  title = {{Tensor Program Optimization with Probabilistic Programs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
}
Figure