Using Graph Neural Networks to model the performance of Deep Neural Networks

Shikhar Singh, Benoit Steiner, James Hegarty, Hugh LeatherarXiv 2021

Introduction

Optimizing deep learning models for specific hardware targets is a complex "combinatorial nightmare." Modern compilers like Halide and TVM address this by separating the algorithm (the mathematical operations) from the schedule (the implementation details like tiling, vectorization, and parallelization). To identify the most efficient schedule among millions of possibilities, compilers rely on performance models—mathematical proxies that predict execution time without the need for slow, physical benchmarking.

However, traditional performance models often fall short. By treating computational stages in isolation or as simple sequences, they fail to account for the intricate data-flow relationships inherent in neural network graphs. This paper introduces a novel performance model based on Graph Neural Networks (GNNs) that treats computational stages as nodes in a graph, capturing complex inter-stage interactions and achieving a 7.75x to 12x reduction in prediction error compared to state-of-the-art models.

GNN-Based Performance Modeling

The core innovation of this approach is mirroring the natural structure of neural networks within the performance model itself. The authors represent each stage of a Halide pipeline as a node in a Directed Acyclic Graph (DAG).

The GNN architecture processes graph embeddings through linear and matrix multiplication layers to capture structural dependencies.

The model utilizes two graph convolutional layers where each node "talks" to its neighbors. This allows the network to learn how optimizations in one stage affect subsequent operations. Feature engineering is split into two categories:

  • Schedule-Invariant Features: These include operation counts (math, memory access patterns) that remain constant regardless of the implementation.
  • Schedule-Dependent Features: These capture specific optimization choices such as loop unrolling factors and tiling strategies.

To train this architecture effectively, the authors developed a custom loss function that balances absolute accuracy with pairwise ranking (prioritizing accuracy on fast schedules) and noise robustness (weighting measurements based on their variance during benchmarking).

Data Generation and Benchmarking

To train and validate the GNN model, the researchers constructed a massive dataset using a structured pipeline.

The data generation pipeline transforms ONNX models into benchmarked runtimes and extracted features.

The pipeline began with 10,000 randomly generated ONNX models, which were converted into Halide pipelines. A schedule explorer then generated over 1.6 million unique schedules. Each schedule was benchmarked on 18-core Intel Xeon CPUs to provide ground-truth runtimes. This high-quality dataset allowed the model to learn from a vast array of computational patterns, which were further tested against real-world architectures like ResNet-50 and AlexNet.

Key Results and Insights

The GNN model significantly outperformed industry standards, demonstrating that graph topology is a primary driver of performance.

  • Superior Accuracy: The model achieved an average error of only 8.2%, a stark contrast to the 64% error seen in the standard Halide model and 104% in the TVM model.
  • High Correlation: An $R^2$ score of 0.92 indicates a very high correlation between predicted and actual runtimes.
  • Effective Ranking: In pairwise comparisons—crucial for compiler optimization—the model correctly identified the faster schedule approximately 75% of the time across various real-world networks.

A key takeaway is that relative ranking is often more valuable than absolute accuracy in compiler contexts; the model's focus on finding the best implementation rather than the exact timing of slow ones proved highly effective.

Limitations and Future Directions

While the GNN approach represents a significant leap forward, several areas for improvement remain. The model currently relies on manual feature engineering; future work could involve automated feature learning directly from Abstract Syntax Trees (ASTs). Additionally, while this study focused on CPUs, extending the model to GPUs and TPUs would require extensive new benchmarking. Finally, the authors suggest using active learning to reduce the "data hunger" of the training process, potentially identifying the most informative schedules to benchmark and reducing the weeks of compute time currently required for dataset generation.

Summary updated

BibTeX
@misc{singh2021using,
  author = {Shikhar Singh and Benoit Steiner and James Hegarty and Hugh Leather},
  title = {{Using Graph Neural Networks to model the performance of Deep Neural Networks}},
  year = {2021},
  eprint = {2108.12489},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2108.12489},
}
Figure