TL;DR
This paper introduces a novel machine learning approach to automatically learn performance models for Tensor Processing Units (TPUs). Their method significantly outperforms existing analytical models on key optimization tasks like tile-size selection and operator fusion, enabling faster program discovery with limited hardware access.
What Problem Does This Paper Address?
Developing accurate performance models for modern hardware, especially specialized accelerators like TPUs, is a significant engineering challenge. These models are crucial for compilers to make optimal code generation decisions, for superoptimizers to find efficient configurations, and for autotuners to explore vast search spaces. Traditional analytical models are time-consuming to develop, difficult to maintain, and often struggle to capture the complex interactions between hardware features and compiler optimizations. The rapid proliferation of new accelerators further exacerbates this problem, demanding faster and more adaptable modeling solutions.
Methods
The authors propose a learned performance model that represents tensor programs as directed acyclic graphs (DAGs). Their approach uses a Graph Neural Network (GNN), specifically GraphSAGE, to capture local structural information within these graphs. This GNN processes node features (operation type, tensor shapes, etc.) and adjacency matrices to generate node embeddings. These embeddings are then aggregated to form a kernel embedding, which is used to predict the kernel's execution time.
Key aspects of their method include:
- Graph-based Representation: Tensor computation kernels are treated as graphs, allowing the model to learn from structural relationships.
- GNN for Local Information: GraphSAGE is employed to learn representations of nodes by aggregating information from their neighbors, capturing local context crucial for performance.
- Flexible Kernel Embedding: Various reduction methods (e.g., LSTM, Transformer) are explored to combine node embeddings into a single kernel embedding, allowing for global information capture.
- Task-Specific Training Objectives: For tile-size selection, a pairwise rank loss is used to learn relative performance rankings. For operator fusion, a mean squared error loss on log-transformed runtimes is employed to predict absolute execution times.
- Minimal Feature Engineering: The model relies on features directly extractable from the XLA graph representation, minimizing the need for manual, domain-specific feature creation.
Datasets
The authors created two primary datasets for training and evaluation:
- Tile-Size Dataset: Generated by compiling XLA programs with default fusion heuristics and then querying the compiler for valid tile sizes for each kernel. Runtimes were measured for as many tile sizes as possible within a time limit, resulting in approximately 25 million samples.
- Fusion Dataset: Generated by running an XLA fusion autotuner with a random search strategy. For each computation graph, 50,000 fusion configurations were explored (or until a timeout), yielding around 208 million samples after decomposition into kernels.
These datasets were split into training, validation, and test sets using both a random split and a manual split (designed to maximize dissimilarity between sets) to evaluate generalization capabilities. The experiments were conducted on TPUs v2 and v3.
Key Insights and Ideas
- GNNs are Crucial for Generalization: The study strongly suggests that using GNNs is essential for achieving good performance and generalization across different tensor programs, outperforming sequence-based models like LSTMs or Transformers alone.
- Global Information Enhances Accuracy: Combining GNNs with sequence models (LSTM) or attention models (Transformer) for global information aggregation further improves accuracy, especially for the fusion task.
- Rank Loss is Effective for Relative Prediction: For tasks like tile-size selection, where relative performance is key, training with a rank loss is more effective than using a direct MSE loss.
- Static Features Provide a Boost: While the model aims for minimal feature engineering, incorporating static performance features (like FLOPs, data transfer sizes) significantly improves accuracy, particularly for the fusion task.
- Edge Direction Matters for Fusion: The direction of data flow in the computation graph is an important feature for predicting fusion performance but less so for tile-size selection.
Key Results
- Outperforms Analytical Models: The learned performance model achieved a mean error of 3.7% and a mean Kendall's $\tau$ correlation of 0.80 for tile-size selection, slightly outperforming the analytical model (6.1% error, 0.74 correlation). For fusion, the learned model achieved a mean absolute percentage error (MAPE) of 4.5 and a mean Kendall's $\tau$ of 0.92, significantly outperforming the analytical model (31.1 MAPE, 0.8 correlation).
- Faster Autotuning: Integrating the learned model into an XLA autotuner allowed it to discover faster programs with significantly less hardware evaluation time. For tile-size selection, it matched the analytical model's performance while reducing search time. For fusion, it enabled discovering configurations that were on average 1.5% faster than hardware-only approaches and only 1.5% slower than exhaustive searches that took hours.
- Generalization: The model demonstrated generalization to unseen programs, particularly with the random split dataset. Even on the harder manual split, it showed competitive performance.
- Retargetability: The approach is designed to be retargetable to different optimization tasks with minimal effort.
Limitations and Future Work
- Data Imbalances: The datasets exhibit imbalances in model types (e.g., many ResNet variants, few AlexNet) and kernel complexity, which the authors addressed by drawing examples evenly from model types during training. However, significant imbalances might still affect performance.
- Hardware Access Limitations: The authors acknowledge that the model's effectiveness is particularly pronounced when access to target hardware is limited or expensive, as it reduces the need for extensive hardware evaluations.
- Future Work: The authors suggest that the learned model can be improved by retraining or fine-tuning with more data, highlighting its adaptability. They also note that the model's performance is comparable to the analytical model on the manual split, indicating room for further improvement on more challenging, dissimilar test cases. The paper also hints at exploring more sophisticated GNN architectures and reduction methods.
Summary updated