Tune Strategies Guide
Tune strategies determine how AITune selects and configures backends during the tuning process. They provide flexibility in balancing performance, reliability, and tuning time.
Overview
AITune provides three built-in strategies:
- OneBackendStrategy: Uses a single specified backend
- FirstWinsStrategy: Tries backends in order, uses the first that succeeds
- MaxThroughputStrategy: Profiles all backends, selects the fastest
Why Backends Can Fail
Not every backend can successfully tune every model. Each backend relies on a different compilation or export technology, and each has its own limitations:
- TensorRT requires exporting the model to ONNX. Models with unsupported operators, complex dynamic control flow, or symbolic shape constraints may fail during ONNX export or TensorRT engine building. Memory constraints can also prevent the engine from being built.
- Torch Inductor uses
torch.compile, which may encounter graph breaks on unsupported Python constructs or operations, causing partial or failed compilation. - TorchAO applies quantization transformations that may not support all layer types or model architectures.
- Torch-TensorRT combines PyTorch’s compiler with TensorRT, inheriting potential limitations from both.
Because of these differences, a backend that fails on one model may succeed on another, and vice versa. This is the core motivation behind strategies like FirstWinsStrategy: by trying multiple backends in priority order, you get automatic fallback when your preferred backend cannot handle a particular model.
Performance Validation
Strategies validate both correctness and performance before accepting a tuned backend. When performance validation is enabled, AITune profiles a TorchEagerBackend baseline at the resolved batch size, then profiles each correctness-passing backend against that baseline.
For OneBackendStrategy and FirstWinsStrategy, baseline validation is enabled by default. A backend is rejected when its throughput is below 1 + min_speedup_ratio relative to Torch eager; the default threshold is 1%, so a backend must be at least 1.01x faster to pass. FirstWinsStrategy then tries the next backend. OneBackendStrategy falls back to the profiled TorchEagerBackend when its single backend is correct but not faster. Disable this only when you deliberately want to keep a backend that is correct but not faster:
MaxThroughputStrategy also profiles Torch eager as a baseline. With performance validation enabled, it falls back to Torch eager if no user-provided backend beats the baseline. When disabled with enable_performance_validation(False), the Torch eager baseline is skipped and the fastest successful user backend wins.
Choosing a Strategy
Use the table below as a quick decision guide. If you already know a backend is compatible and stable in production, start with OneBackendStrategy. If you want a safer default with minimal tuning time, FirstWinsStrategy balances reliability and speed. When absolute throughput matters and you can afford longer tuning, choose MaxThroughputStrategy.
OneBackendStrategy
Uses exactly one backend, failing immediately with the original error if it cannot build or validate correctness. If the backend is correct but does not pass the eager performance gate, the strategy falls back to TorchEagerBackend. Use this when you have already validated that a backend works and want deterministic, reproducible behavior in production.
OneBackendStrategy may look equivalent to FirstWinsStrategy with a single backend, but the key difference is error handling: OneBackendStrategy raises the backend’s original build and correctness exceptions, while FirstWinsStrategy catches errors and tries the next candidate.
Usage
When to Use
✅ Good for:
- Production environments with validated backends
- Reproducible results
- Fast tuning cycles
- Specific backend requirements
❌ Not ideal for:
- Experimentation (no fallback)
- Unknown models (might fail)
- Maximum performance discovery
FirstWinsStrategy
Tries backends in priority order and returns the first one that successfully builds, passes correctness checks, and meets the performance threshold. If a backend fails or is slower than the Torch eager baseline, the strategy moves on to the next candidate instead of aborting. If all backends fail, the error is caught and the original model is used as-is. List backends from fastest to most compatible — for example, TensorRT first, then Torch Inductor.
Usage
How It Works
- Tries first backend (e.g., TensorRT)
- If successful → uses it, done
- If fails or is slower than the Torch eager baseline → tries next backend
- Repeats until a backend succeeds or all fail
When to Use
✅ Good for:
- Experimentation with unknown or diverse models
- CI/CD pipelines where different models may need different backends
- Maximum reliability (if all backends fail, the original model is used as-is)
- Quick validation that something works before investing in backend-specific tuning
❌ Not ideal for:
- Maximum performance (stops at first success, not the fastest)
- When you already know which backend works (use
OneBackendStrategyinstead) - Detailed performance comparison (use
MaxThroughputStrategyinstead)
Best Practices
- Order by Performance: Put fastest backends first
- Automatic Fallback: If all backends fail, the original model is used as-is
- Similar Configurations: Use compatible configs (e.g., all FP16)
MaxThroughputStrategy
Tries all backends, profiles their performance, and selects the fastest backend that beats the Torch eager baseline.
Usage
How It Works
- Tries to build with each backend
- For successful backends:
- Runs warmup iterations
- Measures throughput over N iterations
- Records performance metrics
- Compares throughput with the Torch eager baseline
- Selects the fastest user backend when it beats the baseline, otherwise falls back to Torch eager
When to Use
✅ Good for:
- Production deployment planning
- Maximum performance requirements
- Comparing backend options
- When tuning time is not critical
❌ Not ideal for:
- Quick experiments (slow)
- Development iteration (overkill)
- Memory-constrained systems (keeps multiple builds)
Best Practices
- Development: Use
FirstWinsStrategywith fallback - Production: Use
OneBackendStrategywith validated backend - Benchmarking: Use
MaxThroughputStrategyto find the best option - Always Validate: Test tuned models before deployment
- Cache Results: Save tuned models to avoid re-tuning
Next Steps
- Learn about specific backends: TensorRT, ONNXRuntime, Torch-TensorRT, TorchAO, Inductor
- Explore Deployment Guide
- Review AOT Tuning for strategy usage