The TVM Auto-Scheduler (Ansor) is a machine learning-based compiler system that automatically generates high-performance tensor programs for deep learning workloads by exploring a vast search space of possible loop transformations, parallelization strategies, and memory layouts. It replaces the need for manual, expert-written schedule templates by using a cost model trained on the target hardware to guide a hierarchical search, discovering novel optimizations tailored to specific NPU or GPU architectures. This process is a core technique in hardware-aware model optimization.
Glossary
TVM Auto-Scheduler (Ansor)

What is TVM Auto-Scheduler (Ansor)?
A machine learning-based compiler system for automatically generating high-performance tensor programs.
The system operates by first generating a diverse set of initial program sketches that outline high-level structures like loop tiling and fusion. It then uses evolutionary search and a learned performance cost model to iteratively refine these sketches by populating detailed parameters like unrolling factors and thread bindings. This automated graph compilation strategy directly optimizes for hardware-specific metrics like latency, making it a foundational tool for deployment and runtime optimization on diverse accelerators without requiring deep hardware expertise from the model developer.
Key Features of TVM Auto-Scheduler
The TVM Auto-Scheduler (Ansor) is a machine learning-based compiler system that automatically generates high-performance tensor programs by exploring a vast search space of possible loop transformations and schedules.
Cost Model-Guided Search
The core of Ansor is a learned cost model that predicts the execution latency of a candidate program without running it on hardware. This model is trained on measured performance data from sampled programs. The search algorithm uses this model to prioritize exploration of the most promising regions of the schedule space, which is astronomically large. This approach is far more efficient than exhaustive search or template-based autotuning.
- The cost model is typically a gradient-boosted tree (e.g., XGBoost) or a neural network.
- It evaluates features extracted from the program's loop structure, memory access patterns, and hardware characteristics.
- This guidance allows Ansor to discover novel, high-performance schedules that human experts might overlook.
Hierarchical Task Scheduler
Ansor decomposes the optimization problem using a hierarchical representation of the computational graph. It does not schedule low-level loops directly from the entire model. Instead, it:
- Sketches High-Level Structures: Generates possible high-level loop structures (sketches) for each computational task (operator), such as whether to tile, vectorize, or unroll loops.
- Explores Low-Level Parameters: For each sketch, it searches for optimal low-level parameters like tile sizes, unroll factors, and parallelization strategies.
This hierarchy makes the search tractable by first deciding on major optimization decisions before fine-tuning the numerical parameters.
Automated Program Sampling
To train its cost model, Ansor must generate a diverse set of training programs. It uses automated program sampling to create this dataset.
- Random Annotation: It starts by randomly applying a set of schedule primitives (like
split,reorder,tile) to the initial computational graph. - Evolutionary Search: It then uses an evolutionary algorithm to mutate and recombine high-performing sampled programs to generate new, potentially better candidates.
- This process continuously generates new programs, measures their actual hardware performance, and uses the results to refine the cost model in an iterative feedback loop.
Hardware-Aware Optimization
Ansor's search is fundamentally guided by the target hardware's constraints and capabilities. It automatically discovers schedules optimized for specific memory hierarchies, cache sizes, vector units, and parallel compute units.
- It learns hardware-specific patterns, such as optimal tile sizes for different levels of cache (L1, L2, shared memory).
- It automatically applies hardware-specific optimizations like vectorization for SIMD units and thread binding for multi-core CPUs or GPU streaming multiprocessors.
- This eliminates the need for manual, platform-specific tuning, enabling a single model description to achieve near-peak performance across diverse backends (e.g., ARM CPU, NVIDIA GPU, x86).
Integration with TVM Stack
Ansor is not a standalone tool; it is deeply integrated into the TVM compiler stack. It operates on TVM's intermediate representation (IR), specifically the Tensor Expression (TE) language.
- Input: Takes a computational graph defined via TVM's Relay frontend or directly as TE expressions.
- Output: Produces an optimized schedule object, which is then lowered by TVM to generate hardware-specific code (LLVM, CUDA, OpenCL, etc.).
- This integration allows Ansor to be used as a drop-in replacement for manual scheduling within existing TVM-based deployment pipelines, providing automatic performance gains.
Comparison to AutoTVM
Ansor was developed to address limitations in TVM's earlier autotuning system, AutoTVM. Key differentiators are:
- Template-Free: AutoTVM required manual definition of schedule templates for each operator, which limited the search space. Ansor requires no templates; it explores the space of all valid schedules.
- End-to-End Graph Optimization: AutoTVM tuned operators in isolation. Ansor performs cross-operator optimizations, like fusion, across the entire computational graph during its search.
- Superior Search Efficiency: The learned cost model and hierarchical search in Ansor typically find better-performing schedules faster than AutoTVM's template-guided search and simpler cost models.
TVM Auto-Scheduler vs. Manual Optimization
A comparison of the automated Ansor scheduler against traditional, expert-led manual schedule optimization for tensor program compilation.
| Optimization Dimension | TVM Auto-Scheduler (Ansor) | Manual Schedule Optimization |
|---|---|---|
Primary Objective | Automatically find a high-performance schedule by exploring a vast search space of possible loop transformations. | Leverage expert knowledge to hand-craft a schedule optimized for a specific model and hardware target. |
Required Expertise | Minimal. Requires defining a search space and cost model; the system handles exploration. | Extensive. Requires deep knowledge of target hardware architecture, memory hierarchy, and parallel programming. |
Development Time | Hours to days for the search process to converge, largely unattended. | Days to weeks of iterative coding, profiling, and debugging by an expert. |
Portability Across Hardware | High. The same search process can target different backends (CPU, GPU, NPU) by adjusting the cost model. | Low. A schedule is typically hand-tuned for a specific hardware generation and microarchitecture. |
Performance Ceiling (Theoretical) | Can discover novel, non-intuitive optimizations beyond human design patterns. | Bounded by the optimizer's creativity, experience, and available time. |
Performance Consistency | May produce variable results between search runs; final performance depends on search time/budget. | Deterministic and reproducible once the optimal manual schedule is finalized. |
Maintenance Overhead | Low. Re-running the search adapts to new model variants or compiler/hardware updates. | High. Manual schedules often require significant rework for new model ops, shapes, or hardware. |
Key Enabling Technology | Machine learning-guided search (cost models, reinforcement learning, evolutionary algorithms). | Expert analysis, roofline modeling, and empirical profiling (e.g., using nsight, vtune). |
Optimal Use Case | Rapid prototyping, supporting diverse model/hardware combinations, or when compiler expertise is scarce. | Pushing the absolute performance limits for a critical, fixed model on stable, production hardware. |
Where TVM Auto-Scheduler is Used
The TVM Auto-Scheduler (Ansor) is deployed to automate the most challenging performance optimization tasks across diverse hardware targets. Its primary value lies in generating high-performance tensor programs without requiring manual, expert-written schedules.
Research & Novel Hardware Prototyping
Researchers use Ansor as a performance evaluation tool for new AI accelerators and exotic architectures. Its ability to automatically explore the schedule space eliminates the need for a mature manual kernel library, allowing for:
- Rapid architectural exploration by measuring the performance potential of new tensor instructions or memory hierarchies.
- Benchmarking novel operators (e.g., from cutting-edge research papers) without months of manual optimization effort.
- Serving as the default optimization backend in ML compilers for academic hardware simulators and FPGA prototypes.
Optimizing Emerging Model Architectures
Ansor excels where no pre-optimized kernels exist, making it indispensable for newly published model architectures. Examples include:
- Vision Transformers (ViTs) and their variants with custom attention mechanisms.
- Diffusion models with unique sampling schedules and operator compositions.
- Graph Neural Networks (GNNs) with sparse, irregular computation patterns that are poorly served by standard GEMM libraries.
- Custom, domain-specific layers developed in-house by AI research teams.
Integrating with Higher-Level AutoML
Ansor acts as the low-level optimization engine within larger Neural Architecture Search (NAS) or hyperparameter tuning frameworks. In this role:
- A Hardware-Aware NAS algorithm proposes a candidate model architecture.
- Ansor is invoked to rapidly estimate the latency of that model on the target hardware by generating and benchmarking a schedule.
- This feedback loop allows NAS to directly optimize for inference speed or energy consumption, not just accuracy. Systems like Once-For-All (OFA) can use Ansor to profile the performance of different sub-networks.
Frequently Asked Questions
The TVM Auto-Scheduler, also known as Ansor, is a machine learning-based compiler system that automatically generates high-performance tensor programs for deep learning workloads. This FAQ addresses its core mechanisms, relationship to other optimization techniques, and practical applications.
The TVM Auto-Scheduler (Ansor) is a machine learning-based compiler optimization system that automatically generates high-performance tensor programs (schedules) for deep learning workloads on diverse hardware backends. It works by defining a vast, hierarchical search space of possible program transformations—including loop tiling, reordering, parallelization, and unrolling—and then using a cost model guided by reinforcement learning and evolutionary search to iteratively sample, measure, and refine candidate schedules on the actual target hardware. Unlike manual tuning or template-based approaches, Ansor explores novel, hardware-optimal schedules without requiring prior human expertise for each new operator or accelerator.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
These terms represent core compiler techniques and hardware optimization strategies that complement or are utilized by the TVM Auto-Scheduler (Ansor) to achieve peak performance on specialized accelerators.
Neural Architecture Search (NAS)
Neural Architecture Search (NAS) is an automated process for designing optimal neural network architectures for a specific task and hardware constraint. It uses search algorithms (e.g., reinforcement learning, evolutionary algorithms) to explore a vast space of possible model configurations (layer types, connections, channel widths). While Ansor searches for optimal schedules (how to execute a fixed graph), NAS searches for the optimal graph structure itself. Hardware-Aware NAS directly incorporates metrics like latency or power consumption into the search objective.
Graph Compilation
Graph Compilation is the overarching process of transforming a high-level neural network computational graph (e.g., from PyTorch or TensorFlow) into an optimized, hardware-specific sequence of low-level operations. This involves several stages where Ansor operates:
- Operator Lowering: Decomposing framework-specific layers into primitive tensor operations (e.g., conv2d -> im2col + GEMM).
- Graph-Level Optimizations: Applying transformations like operator fusion, constant folding, and dead code elimination.
- Schedule Generation & Auto-Tuning: This is Ansor's primary domain—finding the optimal loop nest structure, parallelization, and memory layout for each operator.
Kernel Auto-Tuning
Kernel Auto-Tuning is the automated, empirical search for the optimal configuration parameters of a single computational kernel. This is a critical sub-problem that Ansor solves at scale. For each candidate schedule, Ansor must generate code and find the best:
- Thread block size and grid dimensions for GPU targets.
- Loop tiling factors for CPU and NPU cache hierarchies.
- Vectorization and unrolling parameters. Ansor automates this by generating many code variants for each schedule and using a cost model to predict performance, followed by actual measurement on hardware to refine the model.
Operator Fusion
Operator Fusion is a fundamental compiler optimization that combines multiple sequential neural network operations into a single, fused kernel. This is a key transformation applied during graph compilation, often before Ansor's scheduling phase. Examples include:
- Fusing a convolution, bias addition, and ReLU activation.
- Fusing a matrix multiplication with a subsequent non-linearity. Benefits:
- Minimizes intermediate memory writes/reads between kernels, reducing bandwidth pressure.
- Reduces kernel launch overhead by executing fused logic in a single launch.
- Increases operational intensity, making the kernel more compute-bound.
Just-In-Time (JIT) & Ahead-Of-Time (AOT) Compilation
These are two deployment strategies for compiled models, both supported by TVM and Ansor.
Just-In-Time (JIT) Compilation: Code is compiled at runtime, immediately before execution. This allows for optimizations specific to dynamic input shapes or target hardware discovered at deployment. Ansor can run its search during JIT compilation.
Ahead-Of-Time (AOT) Compilation: Code is fully compiled into a standalone, minimal-footprint executable binary before runtime. This is critical for edge deployment on resource-constrained devices. Ansor's search is performed during the AOT compilation phase, and the optimal schedule is baked into the final binary.
Roofline Model & Operational Intensity
The Roofline Model is an analytical performance model used to guide and evaluate optimizations like those Ansor produces. It plots attainable performance (FLOPS/sec) against Operational Intensity (Ops/Byte).
Operational Intensity measures the arithmetic work done per byte of data transferred from main memory. Ansor's goal is to transform schedules to maximize this metric, pushing kernels toward the hardware's compute-bound roof. Techniques include:
- Loop tiling to increase data reuse from cache.
- Operator fusion to avoid writing intermediate results to memory.
- Selecting schedules that maximize cache locality.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us