TL;DR
This paper introduces Topoformer, a novel attention-based Graph Neural Network (GNN) for finding optimal topological orders in computation graphs, specifically to minimize peak memory usage in compilers. Their end-to-end approach significantly outperforms existing methods in speed and often in memory optimization, even on large, real-world graphs.
What Problem Does This Paper Address?
Compilers for hardware like edge devices often need to optimize the execution order of operations within a computation graph to minimize memory usage. This is a combinatorial optimization problem formulated as finding an optimal topological sort of a Directed Acyclic Graph (DAG). While traditional heuristic methods exist, they can be slow or suboptimal. Machine learning approaches have shown promise, but existing methods struggle with scalability, generalization to unseen problems, and effectively leveraging the specific structure of DAGs. This paper aims to bridge this gap by developing a fast, scalable, and effective end-to-end ML solution for this critical compiler task.
Methods
The core of the proposed solution is an encoder-decoder framework.
- Encoder: Topoformer. This is a novel GNN architecture designed to capture the topological structure of DAGs. It uses a Multi-Head Attention (MHA) mechanism, but crucially, it employs multiple sets of attention heads, each attending to different "topological transforms" of the DAG. These transforms include the transitive reduction, the graph with TR edges removed, the transitive closure with original edges removed, and their backward versions, plus an undirected graph of incomparable pairs. This allows for both global and topologically-aware message passing, injecting a strong inductive bias into the node embeddings.
- Decoder: Non-Auto-Regressive (NAR). To achieve fast inference, the decoder doesn't generate the topological order one node at a time in a sequential manner (auto-regressively). Instead, it assigns "priorities" to each node based on its embedding from the encoder. These priorities are then used to construct the topological order using methods like greedy selection, sampling, or beam search. This NAR approach decouples the number of neural network calls from the graph size, leading to significant speedups.
Datasets
- Synthetic Layered Graphs: The authors introduce a new synthetic dataset generator for creating "layered graphs." These graphs mimic the structure of feed-forward neural networks, with nodes organized into layers and connections between layers, including skip connections. This dataset allows for generating graphs of varying sizes (up to 2k nodes) and complexity, facilitating large-scale training and evaluation.
- Real-World Computation Graphs: The paper also evaluates their model on a dataset of 115 representative computation graphs from commercial AI hardware development, covering diverse architectures and sizes (up to 1k nodes).
Key Insights and Ideas
- Topoformer's Topological Inductive Bias: By using attention heads that specifically attend to different structural properties of the DAG (like transitive reduction and closure), Topoformer effectively injects knowledge about the graph's topology into the node embeddings. This is crucial for problems where the graph structure itself dictates valid solutions.
- Non-Auto-Regressive Decoding for Speed: Moving away from auto-regressive decoding, which is common in sequence generation, allows for a dramatic speedup. Assigning priorities and then constructing the sequence is a clever way to achieve fast inference without sacrificing too much performance.
- Generalization to Real-World Problems: The success on both synthetic and real-world computation graphs demonstrates that the learned embeddings and ordering strategy are not just specific to the synthetic data but generalize well to complex, practical scenarios.
- Beyond TSP for MLCO Benchmarking: The authors implicitly argue that while TSP is a popular benchmark for MLCO, it might not fully represent the challenges of DAG-based optimization problems, which have different structural properties and constraints.
Key Results
- Synthetic Graphs: On layered graphs up to 2000 nodes, Topoformer (especially with beam search decoding) achieves performance comparable to or better than approximate dynamic programming (the best baseline) in terms of peak memory usage, while being orders of magnitude faster (e.g., 4000x faster on 2000-node graphs).
- Real-World Graphs: On real-world computation graphs, Topoformer achieves sequences that are, on average, 50% better than approximate DP in terms of memory usage and is nearly 1000x faster.
- Encoder Ablation: The Topoformer architecture significantly outperforms simpler GNNs (like vanilla GAT) and standard Transformers, highlighting the benefit of its specialized message-passing mechanism.
Limitations and Future Work
- Limitations: While the NAR decoder is fast, it might not always reach the absolute optimal solution compared to more computationally intensive methods like approximate DP. The paper focuses on peak local memory minimization, and extending it to other compiler optimization objectives (like execution time) or to end-to-end pipeline optimization is a natural next step.
- Future Work: The authors suggest extending their method to address other compiler optimization tasks, such as device assignment, and to tackle the more challenging problem of optimizing an entire pipeline end-to-end.
Summary updated