{'fraction_non_alphanumeric': 0.024475963348813856, 'fraction_numerical': 0.006872097401782352, 'mean_word_length': 4.759804807518525, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 1, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Accelerate Model Parallel Training by Using Efficient Graph Traversal Order in Device Placement

Modern neural networks require long training to reach decent performance on massive datasets. One common approach to speed up training is model parallelization, where large neural networks are split across multiple devices. However, different device placements of the same neural network lead to different training times. Most of the existing device placement solutions treat the problem as sequential decision-making by traversing neural network graphs and assigning their neurons to different devices. This work studies the impact of graph traversal order on device placement. In particular, we empirically study how different graph traversal order leads to different device placement, which in turn affects the training execution time. Our experiment results show that the best graph traversal order depends on the type of neural networks and their computation graphs features. In this work, we also provide recommendations on choosing graph traversal order in device placement for various neural network families to improve the training time in model parallelization.


I. INTRODUCTION
Recent years have seen the prevalence of Deep Learning (DL) with larger and deeper models with billions of neurons [1], [2]. Together with the performance boost of DL models comes the increasing computation demand for model training. Most solutions seek to parallelize the training on GPU clusters to meet the requirement of computation power. Data parallelism [3] and model parallelism [1] of DL models are the most common parallelization strategies. In data parallelism, data are distributed among several servers (a.k.a. workers or devices) in a GPU cluster. In contrast, in model parallelism, the DL model is split into multiple parts and distributed among workers. Assigning different parts of a DL model to different workers is known as device placement.
Finding the optimal device placement of DL models in model parallelization is challenging. It is mainly due to the large search spaces of potential parallelization strategies, understanding model architectures, and device characteristics [4]. Despite lots of efforts to improve device placements, the training time of device placement methods is still very long [4]- [8]. The first effort in automating device placement combines global partitioning and local scheduling by using heuristic strategies to first partition the DL model into smaller parts and then determine the execution schedule of neurons within each part [9]. The state-of-the-art device placement methods use a combination of Graph Neural Network (GNN) and Reinforcement Learning (RL) to find the placement of DL models [4], [6]. In these solutions, the computation graph of a DL model is represented as a Directed Acyclic Graph (DAG), in which each node of the DAG represents a single operation or a group of operations. In a typical setting, a GNN takes a DAG of a DL model and its nodes' features as input and generates nodes embeddings, which summarize the attributes and neighborhood topology of each node [4], [6]. An RL agent then processes the node embeddings and uses a policy to predict device placements for all nodes in the DAG on the given device cluster. To this end, the RL agent needs to traverse all the nodes in the DAG and learn to propose placements to reduce the training time of the DL.
Identifying a good graph traversal order can decrease the RL agent training time and can also potentially help the RL agent to find better placements to reduce the DL execution time. In this work, we empirically study the relationship between graph traversal order in device placement and the learning efficiency of the RL agent for device placement during the training process. We look into six different graph traversal order and show how they affect the training process of Placeto [6], a state-of-the-art device placement method on three different families of neural networks. Each family of neural networks contains structurally similar DL models [10]. Our initial results suggest that different traversal order are better suited for different types of neural networks. The best graph traversal order to use also depends on the attributes of the DL model that we want to find suitable placements on.
We also explain how our methods on some models could be used in Remote Sensing (RS) and Earth Observation (EO). RS and EO are domains where there is a need to provide near real-time services and products for global monitoring of planet earth. EO satellites developed over the years have provided an unprecedented amount of data that need to be processed [11], [12]. Model parallelization methods can contribute to these domains by distributing the computation and memory requirement for training large models on large datasets.
Our contribution is summarized as follows:

II. PRELIMINARIES
In this section, we discuss problem formulation of device placement problem, graph embedding, RL approach for device placement, and graph traversal order.

A. Device Placement
Let G(V, E) be a DAG that represents the computation graph of a neural network. Each node v ∈ V describes a single computation operation (e.g., convolution) or a predefined small group of operations (e.g., groups of convolutions nearby) that we are interested in predicting its device placement. Each edge e ∈ E models the data dependencies between the vertices. Let D denotes a given device cluster (e.g., GPU clusters) where d ∈ D characterizes a single device in D. A placement p : V → D is a mapping that assigns each node in G to a device in D. Our goal in device placement is to find a placement p to minimize the training time of G (i.e., the DL model) on the given device cluster D while satisfying the memory constraints of every device in the cluster.
When given a fixed number of devices, we can treat the device placement task as a classification problem by considering each device identifier as a label. The classification model takes the DAG of a computation graph G as input and classifies every neuron or group of neurons of G into devices in D.
To this end, Placeto [6] models a device placement task as "finding a sequence of iterative placement improvements." In each training round, Placeto takes the current placement for the DAG and the representation of one of its nodes as input and predicts that node's placement in that DAG. Each round of training last until the placements of all the nodes have been updated once. In the rest of this work, we will use the device placement method as proposed in Placeto.

B. Placeto
Placeto, in general, consists of two parts, (i) using GNN [13] for making DAG's embedding, and (ii) using RL for assigning nodes to devices. Below, we elaborate these two parts in more details.
1) Graph Embedding: What matters in embedding of a computation graph is not only the nodes features but also their relationship. Thus, if two connected nodes are placed on two different devices, there will be data transfer between two devices in both forward and backward path of model training, which is expensive. Things become even more complicated when there are more complex graph and sub-graph structures. Convolution blocks [14] contain parallel computation threads that depend on the same node for input data and send the result to another node for intermediate result concatenation. The attention mechanism [15] uses a weighted sum of the results from previous layers, which can incur a lot of data communication if the nodes in the previous layers are located on different devices. Temporal dependency [16] during the training of recurrent neural networks can also incur a lot of data communication if the nodes that construct the recurrent unit are located on different devices.
GNN [13] can generate d-dimensional graph embeddings for each node in a given graph that can generalize to unseen graphs. Placeto [6] uses a graph embedding architecture that computes node attributes (e.g., the execution time of operation, total size of output tensor), summarizes the topology of a local neighborhood through message passing, and uses pooling operations for creating a global summary of the entire graph. Mitropolitsky et al. [17] study the impact of different graph embedding techniques on the execution time of the placement and the computation time of graph embedding techniques. By explicitly modeling the relationships between nodes in a computation graph, better placement can be found by auto device placement methods.
2) Reinforcement Learning: After generating graph embedding of the input DAG, Placeto uses a two-layer feed-forward neural network that takes the DAG graph embeddings as input to iteratively predict the device placement of the DAG's nodes. The output of the neural network is the probability distribution of the current node over candidate hardware devices. The state-of-the-art methods usually evaluate placements of DL models by the execution time of the DL models. However, the execution time is not differentiable concerning the parameters in the neural network. Thus, Placeto leverages RL for training.
During the training process, the RL agent interacts with the training environment and uses execution time as a reward function to guide the training process. Placeto has a simulator that can predict the execution time of a placement, which helps to speed up the training process of RL agent by avoiding taking execution time measurement of placements on real hardware. In each episode of training, Placeto updates the placement of each node one time. The RL agent of Placeto is trained with REINFORCE [18] policy-gradient method.

C. Graph Traversal Order
Since the device placement problem is treated as a sequential decision-making task [5], we need to convert the computation graph into a sequence of nodes. Placeto formulated the device placement problem as Markov Decision Process (MDP), where the RL agent selects to update the placement for a node in the computation graph in each state. Thus, we need to form a sequence by traversing the computation graph, which is represented as a DAG. Below, we review some of the graph traversal order on DAG that one can consider using.
1) Topological: Topological ordering [19] on the DAG of a computation graph defines a graph traversal order such that for every directed edge u → v from node u to node v, u must appear before v in the traversal order. Topological ordering can be used to represent dependencies in a computation graph where we only visit a node once all its dependencies have been met.
2) Reversed Topological: A reversed topological ordering of a DAG of a computation graph is simply the reversed order of its topological ordering.
3) Depth-first Search: Depth-First Search (DFS) is a graph traversal method that starts at source nodes (input nodes of the computation graph) and explores the graph as far as possible by continuously visiting the children nodes of the current node first before visiting the sibling nodes. A DFS ordering is an enumeration of the nodes that is a possible output of applying DFS on the graph. A DFS preorder is a list of nodes that are in the order of when they are first visited by DFS. A DFS postorder is a list of nodes that are in the order of when they are last visited by DFS.

4) Breadth-first Search:
Breadth-First Search (BFS) is a graph traversal method that starts at source nodes (input nodes of the computation graph) and explores the graph by first visiting all the sibling nodes of the current nodes before moving to children nodes. A BFS order of a graph is an enumeration of its nodes that is one possible output of applying BFS on the graph.

5) Lexicographical:
Lexicographical order is an order where the strings are placed in order based on the position of each character in the string and their position in the alphabet. For example, given the name strings of two nodes in a computation graph a = a 1 a 2 · · · a k and b = b 1 b 2 · · · b k , the order of the name of the two nodes depends on the alphabetical order of the characters in the first place i that a and b differs. If a i < b i then a < b, otherwise a > b. For more concrete examples, see Appendix A.

III. GRAPH TRAVERSAL ORDER IN DEVICE PLACEMENT
In this section, we discuss challenges in device placement and impact of graph traversal order.

A. Challenges in Device Placement
Finding a good placement for model parallelization is challenging. Most of the state-of-the-art methods use RL to find placements; however, RL agents still require a long training time before they can find suitable placements. Mirhoseini et al. [20] find that it takes 12 to 27 hours for their RL method to find the best placement. Although lots of efforts have been made in reducing the complexity of the problem [5], making the training method more efficient [7], [8], and generalizing them better on unseen computation graph [4], [6], [21], the training time of the RL agent still remains long.
One of the challenges in device placement is defining order for nodes in the computation graph G. Unlike text and image data, the nodes in graphs reside in a multi-dimensional space that are linked by edges to represent connectivity [22]. One has to transform graph data from the multi-dimensional space into a sequence of nodes before the majority of the DL methods can consume the graph data. In Placeto [6], the structural information can be (partially) reflected in the sequential order that the auto device placement method iterates through the nodes of the computation graph. Recent work in graph representation learning [22] has shown that successfully learning structural information of the graph helps better represent the graph. Better representations, in turn, lead to performance improvement of downstream tasks that utilize graph representations.
Another challenge in device placement concern the expressiveness of GNN that are used to generate node embeddings. The GNN that are used by state-of-the-art device placement methods mostly follow the message-passing paradigm, which is known to have inherent limitations. For example, the expressiveness of such GNN is bounded by the Weisfeiler-Lehman isomorphism hierarchy [23]. Also, GNNs are known to suffer from over-squashing [24], where there is a distortion of information propagation between distant nodes. Due to these limitations, the node embeddings created by GNN have limited expressiveness. In such cases, different graph traversal order in device placement can lead to placement with different performances.

B. Impact of Graph Traversal Order
Graph traversal order determines the order, which an RL agent learns the placement of each node in the computation graph. We believe that the learning process of RL agents for device placement can be improved if proper graph traversal order can be identified and used in the RL training. Better placements could be found if an ordering of nodes can make the RL agent prioritize the placement learning of important nodes that have a more significant impact on the placement execution time. For example, it might be easier for the RL agent to first learn how to place the nodes that have heavy communications. On the other hand, misplacement of such nodes can lead to slower placement execution time due to extra data communication between different devices.
Order of placement in a local neighborhood could also play an important role. For example, modern DL models are usually constructed using several computation blocks [14]- [16]. The input of the computation block might be copied and sent to a few parallel threads that perform computation independently. All the intermediate results from these parallel threads are later concatenated that will serve as the input of the next computation block. Suppose an RL agent can not anticipate the concatenation of results from parallel computation threads. In that case, it might misplace the threads so that data communication becomes a bottleneck for the concatenation node. However, suppose the RL agent first learns and decides on the placement of the concatenation node. In that case, it can better decide on the placement for the earlier node in the computation block to a better balance between computation and communication. We empirically study different graph traversal order mentioned in Section II-C.

IV. EVALUATION
This section presents the details of the empirical evaluation setup, results, experiment analysis and discussion, and guidelines for choosing graph traversal order for a given DL model.

A. Datasets
We conduct our experiments on three different datasets cifar10, nmt, and ptb as in previous work [6], [17]. cifar10 and ptb are generated using an RL-based method ENAS [10] that finds the optimal subgraph within a larger graph search space. The cifar10 dataset consists of 32 computation graphs of convolutional neural networks for image classification tasks. The ptb dataset consists of 32 computation graphs for language modeling tasks. The nmt dataset contains 32 variations of Neural Machine Translation (NMT) [25] with different number of unrolled steps. The computation graphs in nmt are a family of encoder-decoder networks with attention structures. The nodes of computation graphs are pre-grouped together in all three datasets to reduce graph sizes in the same way as in [20]. The computation graphs in cifar10, ptb, and nmt have on average 300, 500, and 190 nodes. Table I summarizes the three datasets.

B. Experiment Setup
We implement all the graph traversal order in section II-C using NetworkX [26] and refer to them as topo, reversed-topo, dfs-preorder, dfs-postorder, bfs, and lexico hereafter. For the implementation of Placeto, we use the implementation provided in [17], which is based on the original implementation [6]. We use the same simulator in the original implementation to simulate the physical execution environment with different numbers of devices that a neural network can be placed on. We only change the graph traversal order of the RL agent in each episode of training, and this order is fixed across different episodes that happened in one experiment.
We conduct experiments on the graphs from each of the three datasets with three, five, and eight devices, in line with previous work [17]. We run independent experiments with the same setting (dataset and number of devices) to account for the stochastic and randomness that might lead to differences in experiment results. We compare three different settings for the number of repeated runs on a subset of the whole datasets and found that 10 repeated runs offer a good balance between computation load and the reproducibility of the result.
The experiments are run a standalone benchmark machine with AMD Ryzen Threadripper 2920X 12-Core Processor and 128 GB of RAM. Since we have 3 × 32 × 4 × 6 × 10 = 17280 experiments to run, we use parallel docker containers that each have one experiment to speed up the experiment. We empirically found that the metrics we measure in the experiment are not sensitive to the number of parallel docker containers running simultaneously. We use TensorFlow and NetworkX libraries for the experiment, and we refer the readers to this repository 1 for experiment code and the specific version of the libraries and other software settings.

C. Results and Analysis
Through the training process of device placement, an RL agent aims to find device placement with lower execution times. Device placement training processes using different graph traversal order might have different learning speeds. Given the same amount of training time, an efficient graph traversal order finds a placement with lower execution times for the given input DL model compared to the placements found by less efficient graph traversal order. We compare different graph traversal order based on the best placement execution time at episode 9, 19, and 49.
We empirically observe that the training process of the RL agent can be roughly divided into three phases. In the first phase (episode 1 to 9), the RL agent learns efficiently and can find a better placement across different training episodes. This can be explained by the fact that the learning process just started, and finding a good enough placement that is better than a random strategy is not very hard. In the second phase (episode 10 to 19), the learning process slows down, and the RL agent cannot always find drastically better placements than the first phase. This reflects that the learning process plateaus, and we see diminishing returns. In the third phase (episode 20 to 49), the RL agent overcomes the plateau and finds better placement thanks to the more extended training budget and the knowledge learning through the process.
We report the number of times each graph traversal order finds placement with the lowest execution time for the input DL models in the given dataset. Each execution time is based on an average of 10 repeated experiments to minimize 1 https://github.com/bwhub/Graph Traversal Order in Device Placement the effect of randomness and stochastic effects during the training process. Table II shows the result of experiments on cifar10 dataset. Although graph traversal order like topo and dfs-preorder are the ones that find the placement with the lowest execution time, most of the time reversed-topo and dfs-postorder are the best traversal order to use. This can be explained by the fact that there are structures of parallel convolutions in the computation graph of cifar10 dataset where the intermediate results for parallel convolutions are concatenated for later use. In such cases, it is better to start the learning process from the nodes in the output layer of the model. Once the placement of concatenation nodes is settled, it will be easier for the RL agent to optimize the placement for the parallel convolutions. Also, we observe that with more training episodes, topo and dfs-preorder start to show fewer advantages as the number of times they find the best placement with the lowest execution time decreases.
We also find that the diameter of the computation graph for the DL model also affects which graph traversal order is performing the best in the cifar10 dataset. With a shorter diameter (e.g., diameter smaller than 100), the DFS family (dfs-preorder and dfs-postorder) performs the best. With a longer diameter (e.g., diameter larger than 100), the topo family (topo, reversed-topo) tends to find better placements. This could be explained by the fact that the DFS family forms longer sequences of consecutive nodes on the diameter with a larger diameter. This can be hard for the RL agent to learn the placement of sibling nodes in the computation graph as they are far away from each other in the sequence. This might require the RL agent to learn placement collocation of sibling nodes far away from each other. Table III shows the result of experiments on nmt dataset. reversed-topo order dominates and gives the best result. The can be explained by the fact that reversed-topo order considers how intermediate results are concatenated in the computation graph. The RL agent can decide the placement of the concatenation operation first. Then it is easier for the RL agent to colocate the input operations nodes to the concatenation node to minimize expensive data transfer and synchronization between devices during training. In such cases, starting from the nodes in the output layers of the computation graph also helps. dfs-postorder order does not work well on nmt dataset as it has a larger average node degree of 2.65 compared to the average node degree of 1.47 of cifar10. This increases the effort for the RL agent to collocate the sibling nodes that are far away in the placement sequence generated using dfs-postorder order. Better collocation of sibling nodes can also potentially explain why bfs order is the graph traversal order that finds the placement with the lowest execution time. Table IV shows the result of experiments on ptb dataset. bfs order is the graph traversal order that achieves the best learning efficiency. This can be explained by the fact that computation graphs in ptb dataset have more nodes and edges than cifar10 and nmt datasets. There are potentially more sibling nodes that the RL agent needs to consider  when performing the placement. Since sibling nodes in a local neighborhood will be put close together in the traversal sequence generated by bfs, it is easier for the RL agent to learn to collocate these nodes together to avoid unnecessary data transfer between devices. In this way, the RL agent does not need to worry too much about long-range dependencies in large computation graphs.

D. Discussion and Guidelines
In the previous subsection, we show that graph traversal order affects the training efficiency of the RL agent, i.e., the execution time of the best placement found given the same amount of training budget. The optimal graph traversal order for the RL agent depends on the characteristic of the neural network, e.g., number of nodes, average degree, that we want to find optimal placement on. Our findings are in line with previous research findings [5], [6] that graph traversal order does not affect the quality of the final placement found if ample training budget is given for finding that placement.
We have observed that given enough training budget, the difference of execution time between the placement found is less and less obvious since the RL agent has managed   Identifying the proper graph traversal order for computation graph of DL models can improve the training efficiency that leads to better placement with lower execution time on distributed hardware. However, finding the optimal graph traversal order for a given DL model is not an easy task as many factors are involved in the process, e.g., the topology of the computation graph of the DL model, the ratio of computation and communication during training. Although one cannot always quickly find the best graph traversal order for the computation of a given DL model, we can still provide some guidelines based on our experience.
In general, it is good to start with graph traversal order that traverses the nodes in the computation graph in a backward fashion, i.e., start from the nodes in the final layer of the graph, gradually go through the nodes in the previous layers, and finish with the nodes in the first layer of the model. For example, when using reversed-topo order, the RL agent in the device placement method can first learn the placement of the nodes in the last layers and then on the nodes that are input to nodes that the RL agent already find placement for. By starting from backward, the RL agent can learn to better collocate parent and children nodes. If the DL model computation graph has a large diameter and a large number of nodes or groups of nodes, then graph traversal order that can put sibling nodes near each other in the one-dimensional sequence are better candidates for the optimal graph traversal order. For example, when facing a large DL model with more than 200 nodes, bfs order can put sibling nodes close to each other in the one-dimensional sequence. Thus, the RL agent can learn to better place the sibling nodes consecutively, instead of having to remember the placement of sibling nodes that are far away from each other in a long sequence.
In the context of ExtremeEarth project [11], [27], [28], different types of models are used to provide EO products. While hyperparameter tuning [29] and ablation studies [30] can help to improve model performance, identifying proper graph traversal order can improve the model parallel training performance. For example, for Synthetic Aperture Radar (SAR) image classification [31], [32], reversed-topo and dfs-postorder would be good traversal order to start the experiment, as the models are similar to that in cifar10 model dataset. For sequence classification tasks [33], bfs would be a good traversal order to start with, as they are sequence to sequence models, which are similar to those in ptb model datasets. bfs order can help the RL agent to collocate better the placement of sibling operations in the DL model.

V. RELATED WORK
In this section, we discuss related work on graph traversal order.
The previous work study relationship between graph traversal order and the execution time of the final placement found by an auto device placement method given enough training budget. HDP [5] randomized the order of groups on NMT (4-layer) baseline to feed into the Placer that predicts the placement for each group of nodes. The authors find that the difference between the fastest and slowest placements was less than 7% in 10 experiments. Placeto [6] uses GNN to eliminate the need to assign indices when embedding graph features. Experiment results showed that the predicted placement of Placeto is more robust to graph traversal order than the RNNbased approaches.
REGAL [34] uses topological ordering to convert a graph into a sequence. Mitropolitsky et al. [17] study how different graph embedding techniques affect the execution time of the final placement and show that position-aware graph embedding improves the execution time of the placement found compared to Placeto-GNN [6] and GraphSAGE [35]. GPD [4] removes the positional embedding in the transformer model to prevent overfitting.
Some work in other domains also studies graph traversal order. In chip placement, Mirhoseini et al. [36] find that topological ordering can help the RL agent to place connected nodes close to each other. In the domain of generating graphs with DL models, GraphRNN [37] uses BFS order for graph generation to reduce the complexity of learning over all possible node sequences. The only possible edges for a new node are those connecting to nodes in the "frontier" of the BFS order.
To the best of our knowledge, our work is the first to study how graph traversal order affects device placement training efficiency in device placement.

VI. CONCLUSION
In this work, we study the impact of graph traversal order in device placement. We empirically show that different graph traversal order affect the learning efficiency of the auto device placement training process. An RL agent can learn more efficiently during the training process by finding placement strategies with lower execution time faster when given a proper graph traversal order. Specifically, we find that traversing the computation graph from the nodes in the output layer to the nodes in the input layer helps the RL agent find good placement efficiently in many cases. We also find that when an RL agent finds placement for larger computation graphs, traversing order that can better collocate sibling nodes, e.g., BFS, in the traversal sequence is more efficient than its depthfirst counterparts.
We provide practical guidelines on choosing the traversal order for device placement. We believe that our study can help researchers and practitioners better understand the relationship between types of network and graph traversal order. And the knowledge learned about traversal order can further generalize to learning settings for parallelization beyond device placement (model parallelization).
There are several potential extensions and improvements, such as jointly learning graph traversal order, graph embedding, and the policy network in the RL agent. Another possible direction is to study graph traversal order based on the graph structures and features of individual nodes (e.g., input and output size, and computation intensity of the given node). Also, it would be interesting to see how the knowledge we learn on graph traversal order can be applied when using transformer for graphs for device placement.