Full text
Exploring Alternatives to Policy Search Author: Carlos G¨uemes Palau Thesis Supervisor: Albert Cabellos Aparicio - UPC Tutor: Cecilio Angulo Bah´on - UPC MASTER IN ARTIFICIAL INTELLIGENCE January 2022 FACULTAT DE MATEM` ATIQUES I INFORM` ATICA UNIVERSITAT DE BARCELONA (UB) FACULTAT D’INFORMATICA DE BARCELONA (FIB) UNIVERSITAT POLITECNICA DE CATALUNYA (UPC) – BarcelonaTech ESCOLA T` ECNICA SUPERIOR D’ENGINYERIA (ETSE) UNIVERSITAT ROVIRA I VIRGILI (URV)
Exploring Alternatives to Policy Search Contents List of Figures 4 List of Tables 4 1 Introduction 7 2 Background and State of the Art 9 2.1 Deep Reinforcement Learning (DRL) . . . . . . . . . . . . . . . . . . . . . 9 2.2 EvolutionStrategies .............................. 11 2.3 Graph Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3 Thesis Objectives and Goals 15 4 Proposed solution 17 4.1 Evolution Strategies and RL . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2 Modifications to the parallelized solution . . . . . . . . . . . . . . . . . . . 21 4.2.1 Reward regularization and fitness shaping . . . . . . . . . . . . . . 21 4.2.2 Mirrorsampling............................. 21 4.2.3 Adding noise to the action probabilities . . . . . . . . . . . . . . . . 22 4.2.4 Precomputed noise . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.2.5 Distribution of perturbations among workers . . . . . . . . . . . . . 22 4.3 Design of our proposed solution . . . . . . . . . . . . . . . . . . . . . . . . 23 5 Use case: Computer Network Resource Allocation 26 6 Evaluation 28 6.1 Evaluationsettings ............................... 28 6.2 Analysis of ES hyperparameters . . . . . . . . . . . . . . . . . . . . . . . . 29 6.3 Performance of ES versus PPO . . . . . . . . . . . . . . . . . . . . . . . . 33 6.4 Analyzing ES scalability over the number of workers . . . . . . . . . . . . . 38 6.5 Summaryofresults............................... 39 7 Conclusions 42 References 44 3
Exploring Alternatives to Policy Search List of Algorithms 1 Natural Evolution Strategies [17] . . . . . . . . . . . . . . . . . . . . . . . 17 2 Parallelized Natural Evolution Strategies [17] . . . . . . . . . . . . . . . . . 18 3 Improved Parallelized Natural Evolution Strategies . . . . . . . . . . . . . 23 List of Figures 1 Interactions between the agent and the environment in RL . . . . . . . . . 9 2 Effect on choosing an adequate noise level for generating perturbations. . . 19 3 Diagram detailing the interactions between the agent and the environment in the network routing problem [22] . . . . . . . . . . . . . . . . . . . . . . 27 4 Representation of the graph used in the MPNN [22] . . . . . . . . . . . . . 27 5 Effect on the number of perturbations . . . . . . . . . . . . . . . . . . . . . 30 6 Effect of the standard deviation for the mutations . . . . . . . . . . . . . . 31 7 Effect of the standard deviation for the noise to be added to the obtained actionprobabilities ............................... 32 8 Effect of using ES with varying number of workers over the NSFNET topology 34 9 Effect of using ES with varying number of workers over the G´ EANT2 topology 35 10 Effect of using ES with varying number of workers over both topologies simultaneously ................................. 37 11 Effect on the number of workers over the time spent per epoch performing episodes ..................................... 38 12 Effect on the number of workers over the relative time spent per epoch performingepisodes............................... 39 13 Training speed-up achieved when switching from PPO to ES across different number of workers and topologies . . . . . . . . . . . . . . . . . . . . . . . 40 List of Tables 1 Summary of the configurations for the evaluation . . . . . . . . . . . . . . 29 4
Exploring Alternatives to Policy Search Abstract The field of Reinforcement Learning (RL) has been receiving much attention during the last few years as a new paradigm to solve complex problems. However, one of the main issues with the current state of the art is their computational cost. Compared with other paradigms such as Supervised learning, RL requires constant interaction with the environment, which is both expensive and hard to parallelize. In this work we explore a more scalable alternative to conventional RL through the use of Evolution Strategies (ES). This consists in iteratively modifying the current solution by adding Gaussian noise to it, evaluating these modifications, and use their score to guide the improvement of the solution. The advantage of ES lies on that creating and evaluating these modifications can be parallelized. After introducing the network routing scenario, we used it to compare how ES performed against PPO, a RL policy gradient method. Ultimately ES took advantage of increasing its number of workers to eventually overtake PPO, training faster while also generating better results overall. However, it was also clear that for this to occur ES must have access to a considerable amount of hardware resources, hence being viable only within high perfomance computing environments. 5
Exploring Alternatives to Policy Search Acknowledgements I wish to thank my supervisor Alberto Cabellos and my tutor Cecilio Angulo. I also wish to thank Paul Almasan, author to the original proposal of applying DRL for network routing and which I expand upon on this thesis. I also wish to thank my research group colleagues at the Barcelona Neural Networking Center including, but not limited to, Albert Lopez, Jordi Pailliss´e, Guillermo Bern´ardez and Spyros Garyfallos. 6
Exploring Alternatives to Policy Search 1 Introduction Reinforcement learning is a paradigm within Machine Learning that has seen increased attention over the last decades. Originally its techniques like Q-learning were limited to toy problems, due to their inability to generalize knowledge across similar states or relying in memory taxing lookup tables [3]. While progress was done to amend this by encoding states and replacing lookup tables by linear functions, eventually a big resurgence came with the first applications of neural networks with reinforcement learning [4, 5]. The main advantage between RL algorithms over the other forms of learning like Supervised and Unsupervised learning, was the ability to learn from actively interacting with environment. This allowed RL to be more appropriate for tasks related to control, that is, where the model takes actions to control the environment’s state. In research this usually consists in playing games, from toy examples like pole balancing, to more complex games like playing soccer or even videogames like StarCraft II [11, 10]. However, in real world applications this usually means control over machinery or even entire installations. For example, in 2016 Google used a DQN model to oversee energy consumption, which lead to “15% reduction in overall energy overhead” [12]. A more recent application is the idea of using a RL model to control traffic demands within a computer network to increase throughput and reduce the saturation of links [22]. However, while powerful, RL’s biggest strength is also is biggest drawback: unlike in the other types of learning where samples are already available, with RL the agent needs to constantly interact with the environment to continue learning, which in turn takes time. Overall, this is the biggest factor affecting the speed of RL training. For example, the solution discussed earlier about network routing found itself limited by the training time, making it impractical to train for larger network topologies [22]. Another issue is that the actions of updating the parameters and further interacting with the environment are interweaved and must be done concurrently. This means that while it is interesting to perform several interactions with the environment in parallel there are some issues to resolve, like how is the learned experienced re-unified or how to avoid overlap of learned knowledge between different copies. That does not mean that it has not been tried, as approaches like A3C saw success until being overshadowed by better, single-threaded algorithms [8]. Evolutionary Strategies comes into play as a black-box optimization algorithm, part of the field of evolutionary computing [13, 14]. Evolutionary methods are based on Darwinian theory of natural selection. In a nutshell, these algorithms consist in iteratively improving the current solution by randomly generating small modifications to it and keeping those that improve the score given by a given fitness function to optimize. ES specifically uses these modifications, called perturbations, to make a sampling of alternative solutions, called mutations, which are then evaluated and used as a basis for applying changes to the current solution. 7
Exploring Alternatives to Policy Search After looking at the issue of scalability and parallelization within RL, and the potential of ES, OpenAI released a paper which proposes training RL agents using ES instead of traditional RL algorithms [17]. The main benefit of this approach is that, unlike RL, here the interactions with the environment can be safely parallelized with marginal overhead. As a result, we wished to adapt and test this solution in uses cases like the network routing it was introduced earlier, and see if this way of training agents would allow for larger network topologies to be trained by taking advantage of high performance computing environments. In section 2, Background and State of the Art, we will provide the theoretical background behind RL, ES and Graphical Neural Networks, the network model used in our use case, necessary to understand the rest of the paper. Next, in section 3, Thesis Objectives and Goals, we will go more into detail about the limitations behind scaling RL, as well as formalizing the goals of the report. In section 4, Proposed solution, we will explain the solution proposed by the OpenAI paper, as well as their optional modifications and some of our own. Ultimately, we will conclude with the final version of the algorithm to be evaluated, as well as justifying our reasoning behind including or dropping some of features discussed earlier. Afterwards, in section 5, Use case: Computer Network Resource Allocation, we will introduce the use case of network routing, and how it is represented as a Reinforcement learning problem, as well as understanding how the GNN is designed and applied within this context. In Section 6, Evaluation, we start by presenting how the algorithm is going to evaluated, followed by detailing the obtained results. The report ends with section 7, Conclusions, in which we discuss the results obtained and if they satisfy, or not, the objectives of the thesis. In it we will also propose ways in which our work can be further expanded. 8
Exploring Alternatives to Policy Search 2 Background and State of the Art 2.1 Deep Reinforcement Learning (DRL) The field of Machine Learning can be split broadly into three paradigms: Supervised, Unsupervised and Reinforcement learning. Supervised learning may be thought as the more intuitive of the three: problems consist on a set of samples, each with an assigned output (also referred as labels), and the task is to build a system that is able to learn from this set of samples to then be able to predict the labels of new unseen ones. Hence, supervised models are mostly used for solving problems of classification or regression. Unsupervised learning differs slightly as the samples no longer have assigned outputs. Instead, unsupervised models try to find patterns within the data, in an attempt to summarize and better understand it (for example, through clustering). State si Reward ri Enviroment Action ai Agent Figure 1: Interactions between the agent and the environment in RL In Reinforcement learning, on the other hand, instead of having a problem represented through a set of samples, the problem is framed as the interactions between the environment and agent, as shown in Figure 1. The environment starts with an initial state s0, which the agent will observe. From the current environment, the agent will take an action a0within the environment. As a result, the environment will give feedback to the agent, also known as the reward r0, and the state of the environment will be modified from s0to s1. This will continue endlessly or until the environment reaches an end-state. We refer as an episode to the sequence of state, actions and rewards from the initial state until an end-state is reached. We refer as ‘the policy’ the way the agent chooses its actions from the observed state from the environment. Formally, we can define it as a mathematical function that maps states to actions. Hence, Reinforcement learning algorithms try to find the policy that maximizes the reward obtained. One of the first known RL algorithms is Q-learning [2]. The algorithm consists in learning the Q-values Q(a, s) for each state, action pair, which indicates the expected long-term reward from performing action aon state s. During training, the expected long-term reward is updated by allowing the agent to interact with the environment, record which states it visited and which actions it took in response. Then, the Q-values are updated through Bellman’s equation, which takes into account the immediate reward obtained by taking action aon state s, as well as the expected-long term reward from other states s′ currently available from the current one. Once trained, the optimal policy is trivial: given the current state choose the action which maximizes the current Q-value. 9
Exploring Alternatives to Policy Search As a result, we aim to find a new method for training agents, specifically those represented by neural networks, that can compete with the state of the art algorithms, such as PPO, while also being scalable and suitable in high performance computing environments. We measure scalabity in three of ways: by measuring how performance is increased through increased hardware resources, how is decreased through increased number of worker processes, and how is decreased through increased problem size. First, for the method to be scalable across hardware it should utilize all of the available resources at hand. To do so the method must be parallelizable and hence be run on multiple threads and/or processes, in different computers if it has to. The memory usage should also remain low enough so it does not become the limiting factor in the number of workers that can be launched at once in the same machine, and instead being the number of available cores in the CPU. Also, while not a requisite, it would be best if the algorithm also took advantage of any additional accelerator available, such as GPUs. The second aspect of scalability refers to the amount of computational overhead generated by the number of workers launched. To accomplish a scalable method in this sense, the algorithm should aim to minimize the communication costs between workers, and even the amount of messages sent all together. The last aspect of scalability refers on how the computational cost of the algorithm increases depending on the problem size. In other words, the method should be invariant (or as close as it can be) to the the scale of the problem, which in this case would be measured through the network’s size. Ultimately, the objectives of this thesis are the following: •Explore an appropriate parallelizable alternative to RL, and design an efficient implementation adequate for our use case. •Evaluate the speed-up obtained by the algorithm when increasing the number of workers. •Determine how the overhead increases as the number of workers increase, how many workers the algorithm can support at once, and which are the limiting factors. •Ascertain how does the size of the network impacts the training time of the algorithm. •Benchmark the performance of our implementation against a classical DRL algorithm. 16
Exploring Alternatives to Policy Search 4 Proposed solution 4.1 Evolution Strategies and RL Recently OpenAI released a paper titled “Evolution Strategies as a Scalable Alternative to Reinforcement Learning” that dealt in how to apply ES to train RL agents [17]. In it, they specified how they adapted Natural Evolution Strategies, a variant of ES, and how it could be parallelized. Unlike ES, NES updates the solution by using natural gradient ascent, rather than directly using the average of the perturbations [15]. This consists in obtaining an approximate of the gradient by computing the average of the product between the perturbations and their corresponding fitness function returns. Note that perturbations and mutations do not refer to the same concept: we refer as perturbations the normalized Gaussian noise before being multiplied by the standard deviation and added to the original sample to generate the mutation. Once the gradient is obtained, then the current solution is updated as if it were normal gradient descent. The pseudocode detailing the algorithm can be seen in Algorithm 1. Algorithm 1 Natural Evolution Strategies [17] Require: Learning rate α, noise standard deviation σ, initial policy parameters θ0, number of mutations n, fitness function F 1: for t= 0,1,2, ... do 2: Sample perturbations ϵ1, ϵ2, ..., ϵn∼ N (0, I) 3: Compute returns Fi=F(θt+σϵi) for i= 1, ..., n 4: Update policy parameters θt+1 ←θt+α1 nσ Pn i=1 Fiϵi For it to be applied in the context of RL, the main change to be done is how to define the fitness function to evaluate each mutation. Here, both the solutions and mutations represent a model as a one dimensional vector. In the context of neural networks, including GNNs, each solution will represent all the parameters of the network being flattened into a single vector. Then, the fitness score is extracted by obtaining the accumulated reward by the mutation across en entire episode within the environment. Consequently, the algorithm must perform gradient ascent, as we wish benefit those perturbations which maximize the obtained reward. The main advantage of using ES is how it can be trivially parallelized. What the paper proposes is to initialize a number of workers n, each with an environment instance of its own. When working together, each worker can evaluate only a part of the perturbations, and then send its results to each other so everyone can update the parameters independently. As long as each worker share the same perturbations and fitness results across execution, all workers will converge to the same solution. The algorithm’s pseudocode can be seen in Algorithm 2. 17
Exploring Alternatives to Policy Search Algorithm 2 Parallelized Natural Evolution Strategies [17] Require: Learning rate α, noise standard deviation σ, initial policy parameters θ0, fitness function F Ensure: nworkers with known random seeds and initial parameters θ0 1: for t= 0,1,2, ... do 2: for each worker i= 1, ..., n do 3: Sample perturbation ϵi∼ N (0, I) 4: Compute returns Fi=F(θt+σϵi) 5: Send all scalar returns Fifrom each worker to every other workers 6: for each worker i= 1, ..., n do 7: Reconstruct all perturbations ϵjfor j= 1, ..., n using known random seeds 8: Update policy parameters θt+1 ←θt+α1 nσ Pn j=1 Fjϵj Not only the resulting version splits its workload across multiple threads and/or processes, but also does so at a minimal overhead. Through clever use of predetermined seeds for the noise generators, the communication cost can be kept to a minimum by generating each other’s perturbations without needing to send anything. Hence, the only communication costs come from sending the fitness function returns to other workers, meaning the asymptotic cost of communication will be of O(nki), where nis the number of workers, kthe total number of perturbations and ithe number of iterations, and the expected number of messages sent being i·(n−1)2. Overall, this algorithm takes advantage of NES’s properties to offer a more scalable alternative in form of a fully distributed solution compared to traditional RL algorithms. Additionally, it does so while requiring fewer hyperparameters. While algorithms like PPO requires making decisions about the replay buffer’s characteristics (size, sampling rate), discount factor and exploration policy among others, NES only requires the user to decide the values of two hyperparameters: •The number of perturbations n: The higher the number of perturbations, the more information the algorithm will have at each epoch to approximate the gradient correctly, making learning more stable. However, more perturbations to evaluate results in more time is spent interacting with the environment. •Standard deviation σfor generating mutations: it controls how different the mutations will be compared with the current solution. The effect of this hyperparameter is similar to the learning rate in gradient descent, where the value will depend on how irregular is the “solution space”. That is, it will depend on how much the quality of the solution will change over small changes in its value. This impact is illustrated in Figure 2 representing a simplified example where the solutions have only one parameter: –Point A shows the current solution θ. 18
Exploring Alternatives to Policy Search Solution Space Average Reward AB C D Figure 2: Effect on choosing an adequate noise level for generating perturbations. –Point B shows a mutation being being generated from a sub-optimally small value of σ. By being too close to the solution it captures small irregularities that could lead to the solution to be more easily stuck in a local minimum. –Point D shows a mutation being generated from an sub-optimally large value of σ. By being too far away from the current solution it no longer represents the neighborhood near it, and hence it will worsen the gradient approximation. –Point C shows a perturbation generated from an ideal value of σ. It captures correctly the solution space near the current solution without capturing the irregularities that do not have a significant impact over the solution. However, unlike the learning rate, the value of σwill not translate into larger gradient steps. This is because in the end the gradient is updated using the raw perturbations, which are drawn from the normalized Gaussian distribution, and standard deviation is only applied to then create the mutations. ES also offers the advantage of not being affected by certain limitations of traditional RL algorithms [17]. The first one is that ES does not have to consider future discounting, a measure of how much future rewards are worth relative to immediate rewards. Since learning occurs at the level of individual interactions, a balance must be struck between maximizing the reward obtained with the next action and the expected long term reward that you can obtain afterwards. If this balance is not achieved agents may end up being myopic, choosing actions that maximize their short term rewards but at the cost of rewards later on. However, not applying any discount will avoid agents from converging, as those environments with potentially infinite episodes could have theoretically infinite expected rewards. On the other hand, in ES each perturbation is evaluated by the accumulated reward across the entire episode. Since the evaluation is done at the episode level, the notion of taking into account expected long term reward from taking actions in individual states is no longer relevant for training the agent. 19
Exploring Alternatives to Policy Search Another advantage of training agents through ES over traditional RL is also not being affected by environments with sparse rewards. In traditional RL, both Q-learning and policy approximation, learning is only triggered once the agent reaches states that award some reward. Otherwise, due to the definition of the loss functions used to train the agents, the obtained loss would be equal to 0 and so the network will not learn anything. This issue is not relevant in ES due to the same reason as before: since ES evaluate perturbations by evaluating entire episodes as a whole, it does not care how spread out the reward is within the episode itself. Furthermore, due to the benefits of ES being a black-box optimization algorithm, it does not make any assumptions of the environment itself either, including if it can be defined as a Markovian Decision Process or not, assumption held by many traditional RL algorithms. Therefore, using ES may prove even more beneficial in these kinds of environments. Before we move on, we must also clarify the disadvantages that ES has over traditional RL algorithms. The first one is that, as we clarified at our introduction to ES, evolutionary algorithms tend to perform slower than gradient based methods, and in this case we do not expect things to be different. Unlike DRL algorithms, ES tries to optimize all parameters at once and without using backpropagation, a major speed up in updating a network’s parameters. This is exacerbated by the fact the current implementation of ES is not accelerated by being run in an accelerator such as a GPU. Additionally, ES is a substantially more ‘bruteforce’ way of optimizing the gradient. In ES we depend on randomly generated perturbations for finding a better solution, while traditional RL algorithms like PPO have made massive improvements in how to sample interactions more effectively (e.g. through prioritized experience replay [9]). While using entire episodes to evaluate perturbations has significant benefits as we just discussed, it also means that ES takes many more interactions with the environment before it can adapt its current solution compared to traditional RL algorithms. Overall, we expect that the single-threaded performance for ES to be significantly slower than traditional RL algorithms like PPO. Another important limitation to consider is that ES theoretically cannot run in environments with infinite episodes. Since ES uses entire completed episodes to evaluate the perturbations, it will always enforce a finite horizon on its episodes. In practice limiting the episodes length may not be a deal-breaker, but it will mean the obtained solution will not longer be reliable after the cut off mark in the episode. Also, allowing episodes to run for too long will affect the time taken to train the agent, as running the episodes is the current bottleneck in the agent’s training. 20
Exploring Alternatives to Policy Search 4.2 Modifications to the parallelized solution While the algorithm shown in Algorithm 2 is the proposed solution by the OpenAI paper, in the same paper they also discuss other modifications that could be done to improve algorithm, by either improving the training time or increasing the stability of learning. 4.2.1 Reward regularization and fitness shaping Fitness shaping is a technique described in the paper introducing NES, although the idea is common place in evolutionary computing [15]. The idea is to evaluate the perturbations using a ranking according to their fitness return, rather than using the value directly. Once the ranking replaces their fitness values, then it is scaled so scores are assigned in the range of [−0.5,0.5]. Using the rank instead of the values allows learning to be more stable. On one hand, it makes sure that the magnitude of change of the solution between iterations is more bounded by limiting the values of the returns, especially useful in environments where the obtained reward can drastically change [17]. This effect is more pronounced at the beginning of training, where the differences in reward between different mutations is more pronounced. This effect also helps avoiding learning to stall when reaching convergence, as it will amplify the differences in obtained reward between mutations if it becomes too small. 4.2.2 Mirror sampling Mirrored sampling is a technique introduced to increase stability of ES algorithms by improving how perturbations are generated [19]. The idea is simple: for every perturbation ϵiwe generate, we will also consider its inverse −ϵi. This change improves stability by ensuring we are correctly exploring the solution space near our current solution, as for every perturbations we evaluate we will also take into account exploring the complete opposite direction. Applying this change is also computationally inexpensive, barely increasing the cost of obtaining the gradient. First, it reduces the cost of generating the perturbations to half, as the other will be the mirrored version. Additionally, by taking advantage of how the gradient is obtained, we can reshuffle the operators to further minimize the computational cost of doing so. This is done as such: let us have ngenerated perturbations, and for each perturbation ϵiwe have its mirrored version −ϵi. We have also obtained the fitness returns for ϵiand −ϵias Fiand F′ irespectively. Hence, the gradient would be obtained as: 1 2nσn X j=1 Fjϵj+ n X j=1 F′ j(−ϵj)=1 2nσn X j=1 Fjϵj−F′ jϵj=1 2nσn X j=1 Fj−F′ j)ϵj As such, by subtracting the obtained mirrored rewards from the original perturbations’s returns, we can reduce by half the amount of dot products operations later on to obtain the gradient, making this change inexpensive computationally. 21
Exploring Alternatives to Policy Search 4.2.3 Adding noise to the action probabilities Unlike traditional RL algorithms, exploration strategies are no longer necessary when running episodes to train the network. That is because the exploration is already done when generating the perturbations, as with them we are exploring the solution space. Instead, episodes are run to evaluate the perturbations, thus they must be run as if it were evaluation episodes in traditional RL methods, always choosing the action preferred by the model. The paper exploring the use of ES in RL explores this argument from a more formal angle [17]. Specifically, they state that trying to apply gradient descent directly over the solution space is risky since it is not known how smooth the solution space really is. Therefore, as to add smoothness to the gradients Gaussian noise is added. In DRL this is done when exploration policies are considered and/or Gaussian noise is added to the action probability distributions drawn by the models. In ES, the noise added are the perturbations in the solution space. Ultimately, they argue that in those scenarios where stronger smoothing is required for gradient descent to occur successfully, noise can be added to both the solution and actions. That is, whenever episodes are run in ES to evaluate a perturbation, noise should also be added to action distributions drawn by the model before committing to a specific action. 4.2.4 Precomputed noise Another of OpenAI’s proposals is to, rather than generating new noise vectors every epoch, to have a certain amount of pre-computed noise from a normalized Gaussian distribution and sample from it instead [17]. The argument is that sampling from the matrix is quicker than generating the noise, trading memory for a computational speed up. The main issue with this is that the drawn perturbations must be i.i.d, while sampling from the same precomputed set of noise vectors is not. As a result, bias is introduced into the search and hurting its performance, unless a significant amount of noise is pre-generated. 4.2.5 Distribution of perturbations among workers One aspect that the original pseudocode glosses over is how is perturbations are divided among the workers . As it is written in Algorithm 2 it implies that there are many workers as perturbations, which in reality this is impractical as each worker requires its own overhead. In reality, workers are expected to sample several perturbations. The most simple solution would mean to split the perturbations evenly across workers. However, since episodes could have varying length this does not guarantee that the workload is evenly divided. As a result, the proposal recommends a system in which all workers will train for a fixed number of interactions, and will send the results of the episodes it is able to complete in the process. This minimizes even further downtime from waiting threads [17]. 22
Exploring Alternatives to Policy Search 4.3 Design of our proposed solution Given the original parallelized algorithm we will explore the version of the algorithm we will use in this report after introducing some of the modifications introduced in the same paper, as well as some of our own. By combining all of these changes together, the final version of the algorithm to be used can be seen in Algorithm 3. Algorithm 3 Improved Parallelized Natural Evolution Strategies Require: Learning rate α, noise standard deviation for mutations σ, noise standard deviation for actions φ, initial policy parameters θ0, fitness function F, number of mutations k Ensure: nworkers with known random seeds and initial parameters θ0, one of them being designed as the coordinator 1: for each worker i= 1, ..., n do 2: Obtain assigned number of mutations ki←AssignMutations(k) 3: if worker iis coordinator then ▷Coordinator thread 4: for t= 0,1,2, ... do 5: Sample global perturbations E←[ϵ1, ϵ2, ..., ϵk], ϵj∼ N (0, I) 6: Retrieve local perturbations Ei←E[ki, ki+1 −1] 7: Compute returns Foriginal i←F(θt+σϵi;φ) 8: Compute mirrored returns Fmirrored i←F(θt−σϵi;φ) 9: Receive returns other workers: Foriginal 10: Receive mirrored returns from other workers: Fmirrored 11: Combine returns and mirrored returns Fcombined ←Foriginal −Fmirrored 12: Obtained ranked returns Franked ←ObtainRanking(Fcombined) 13: ▷Other forms of gradient descent can be used, regularization can be added 14: Obtain solution update ∆θ←α1 nσ Pn j=1 Franked jϵj 15: Send ∆θto all worker threads 16: Update solution θt+1 ←θt+ ∆θ 17: else ▷Worker thread 18: for t= 0,1,2, ... do 19: Sample local perturbations E←[ϵ1, ϵ2, ..., ϵki], ϵj∼ N (0, I) 20: Compute returns Foriginal i←F(θt+σϵi;φ) 21: Compute mirrored returns Fmirrored i←F(θt−σϵi;φ) 22: Send Foriginal iand Fmirrored ito coordinator thread 23: Receive ∆θfrom coordinator thread 24: Update solution θt+1 ←θt+ ∆θ Out of the five improvements above, we have decided to include fitness shaping, mirror sampling and adding noise to the action probabilities. Including fitness shaping and mirror sampling was an easy decision, due to their many benefits and no downsides. Having to add noise to the action probabilities will be more exceptional, but its code complexity is not high and it can be added without affecting the behaviour whenever no noise is added. 23
Exploring Alternatives to Policy Search Contrary to the original paper, we decided to not pre-compute noise as the benefit it brought was not worth its cost in memory. On one hand, later executions of our code saw that the cost of generating Gaussian noise was insignificant in respect to the cost of executing the environments themselves. On the other hand, the amount of pre-genereted noise that was needed to avoid introducing too much bias in the generation of perturbations, combined by the fact that this noise had to be replicated in all execution threads, increased memory costs to a point it was limiting in the amount of workers a machine could run. The other difference we have respect the original paper is how perturbations are distributed. Ultimately, we did not observe the predicted situation where some episodes would be significantly longer than others, as the authors worried. Even if some episodes were marginally longer than others, ultimately all workers had to evaluate several episodes, which further evens out their workload. Additionally, this method also requires the perturbations themselves to be sent, which significantly increases the communication costs, and therefore the overhead, of the algorithm. Instead, we opted with a fixed assigned number of perturbations per worker. Another aspect we decided to modify is the decentralized nature of the algorithm. While decentralization may be attractive in some applications, we do not believe it was the case here. Distributed solutions that benefit from decentralization are those that want to avoid a single point of failure. However, due to the synchronous behaviour of our algorithm, it would fail if anything interrupted any of the workers involved. Additionally, decentralization increased significantly the memory cost of the algorithm. For the environment to be purely decentralized every worker must be able to update their solutions independently and in order to do so it must store the perturbations of the others. As a result, each perturbation will be replicated in each worker, resulting in the memory needed for storing every copy increasing up to a total of n·k·p32-bit floating point numbers, where nis the number of workers, kis the number of perturbations, and pthe size of the perturbations, the same as the size of the solution θ. A counter proposal would be instead to develop a centralized version of the algorithm, where one coordinator is the only one responsible for performing gradient descent. As a result, the workers only have to worry about their own perturbations, and only the coordinator will have a copy of other’s. By limiting to storing each perturbation twice (the worker’s original and the coordinator’s copy), rather than having ncopies, it reduces the cost of storing them down to 2 ·n·k32-bit floating point numbers, independently of the number of workers. The biggest issue with centralization is the increased downtime by the threads/processes, as the coordinator must wait for the workers to finish before continuing and vice-versa. 24
Exploring Alternatives to Policy Search Centralization also has an impact in communication overhead. On one hand, since the rewards for perturbations have to be sent to a single coordinator rather to several workers, the amount of messages sent is reduced. On the other hand, the updated parameters now must be sent from the coordinator to the workers every time they are updated (once per iteration). Consequently, the resulting asymptotic cost of communication therefore changes to O(ip), where ithe number of iterations and pthe size of the perturbations, compared to the previous O(ikn) where kthe total number of perturbations and nis the number of workers. Usually the size of the solution θis larger than the number of perturbations, but is hard to say if it is always larger than k·n. What is known to decrease is the number of messages, from i·(n−1)2to i·2(n−1) messages sent. Overall, the benefits outweigh the drawbacks. While not commented in the paper, this is the approach chosen in the official code implementation of the algorithm [18]. However, unlike the official implementation, we made our coordinator to also assume the role of a worker. This both virtually eliminates the downtime of the coordinator, and also slightly reduces the communication costs, as the coordinator does not have to send information to itself. One final note to discuss is how gradient ascent is applied. This is not covered by the paper’s pseudocode, but it reflected later on both in its evaluation section and in the published code [18]. Since gradient ascent is applied, even if not through backpropagation, that means that we can use other forms of gradient descent such as gradient descent with momentum, or even the Adam optimizer. It is also possible to add regularization to the gradient approximation. For example the authors in their implementation opted for Ridge regression [18]. 25
Exploring Alternatives to Policy Search 0 200 400 600 800 1000 1200 1400 1600 Time (s) 12.5 15.0 17.5 20.0 22.5 25.0 27.5 Mean Reward No noise 0.05 Standard Deviation noise 0.5 Standard Deviation noise Figure 7: Effect of the standard deviation for the noise to be added to the obtained action probabilities Figure 7 shows the impact of different values for the noise to be added to the obtained action probabilities. This is also referred as φback in Algorithm 3. On one hand we observe that the effect of this parameter is very subtle. When moving from adding no noise to a minimal amount of noise, with φ= 0.05, we see that it did not have an impact over the results, with both curves moving in an identical trajectory. However, by increasing the amount of noise to φ= 0.5 the mean reward is negatively affected, reducing the point where it converges from a mean reward of 26 to roughly 20. Ultimately, the addition of noise to the action distribution is not always necessary and it is more reasonable to consider it on a case by case basis. Small amounts of noise should be included in a grid search for finding the correct hyperparameter values of the algorithm, but only with the understanding that most likely no noise should be added. Another observation to point out from the graph is how adding more noise increased the training speed of the algorithm. As a reminder, all three configurations tested had the same number of epochs, however the configuration with φ= 0.5 finished after 1100 seconds, while the other two curves took longer than 1500. However, we believe this occurs because when the algorithm performs worse its episodes are shorter: since it performs poorly, the graph is saturated in fewer allocations of demand, hence episodes end sooner. A similar situation can be found in Figure 6 with the curves from configurations with values of σ= 0.5 and σ= 1, whose mean reward did not increase over training and they also ended significantly sooner. 32
Exploring Alternatives to Policy Search 6.3 Performance of ES versus PPO In the following section we will focus in analyzing the performance of ES against PPO as our reference RL algorithm. In order to make this comparison we will run our implementation of ES across the three configurations with a varying number of workers: one, two, four, eight, 16 and 32 in the local server, and 16, 32 and 64 in the remote AWS server. We will also run PPO, using the implementation offered by the authors of DRL solution for network routing, in both the local and remote server, to act as a baseline [22]. The first set of figures will show the raw results of our experiments. The plots will be similar to those from our previous section: each curve represents one configuration run with either PPO or ES with a specific number of workers. Each point in the line plot represents one epoch, the x-axis represents the amount of training time taken to reach that point, and the y-axis represents the mean accumulated reward per episode obtained across 60 episodes (in the case where we use both topologies we will obtain 60 episodes from each). We will begin with Figure 8, which shows the results of the experiments run with the NSFNET topology and configuration (revise Table 1 for details). Figures 8a and 8b show the results of the experiments run on the local server, where the latter represents a zoomed-in version of the former. Figure 8c shows the results of of the experiments run on the remote AWS server. The first clear observation that, overall, the more workers we assign, the greater is the speed up the training receives. As all ES experiments use the same number of iterations, we can compare how long they took by simply seeing where the curve ends. Looking back at Figure 8a running ES with one and two workers only are clearly the slowest options, with a great margin from the third slowest being four workers. If we continue by looking into in Figure 8b we see this trend of increasing number of workers resulting in decreasing training times continues. Only when we reach 32 workers this speed up is halted, but it also coincides with the point where all 16 cores of the CPU are occupied, hence this is not due to the limitation of algorithm but of the machine. When moving to the remote server in Figure 8c we can confirm that the trend continues even further. If we compare our results with PPO we can notice two interesting trends. The first one is that by looking at the shape of the curve PPO tends to converge faster than ES with any number of workers, even with 32 and 64 of them in Figures 8c: the fastest ES run, the one with 64 workers, converges at roughly 800 seconds, while PPO roughly at 500. However, across all ES executions we seen that it obtains significantly better solutions than PPO, converging at a mean reward of over 26 instead of PPO’s 16. This is unexpected, as we were not anticipating any method to obtain inherently better policies. However, the properties of evolutionary algorithms being more resistant to local minima may give the edge to ES when obtaining a better policy of this specific scenario. What we were expecting, however, is that the number of workers do not affect the mean reward at which ES converges. Looking at graphs eventually all ES executions reach a mean reward of 26, confirming that its performance does not degrade when parallelized. 33
Exploring Alternatives to Policy Search 0 20000 40000 60000 80000 100000 Time (s) 10 15 20 25 30 Mean Reward PPO (baseline) 1 Worker 2 Workers 4 Workers 8 Workers 16 Workers 32 Workers (a) Results of running 1 to 32 workers in the local server 0 500 1000 1500 2000 2500 Time (s) 10 15 20 25 30 Mean Reward PPO (baseline) 1 Worker 2 Workers 4 Workers 8 Workers 16 Workers 32 Workers (b) Results of running 1 to 32 workers in the local server (zoomed in) 0 1000 2000 3000 4000 5000 Time (s) 10 15 20 25 30 Mean Reward PPO (baseline) 16 Workers 32 Workers 64 Workers (c) Results of running 16 to 64 workers in the remote server Figure 8: Effect of using ES with varying number of workers over the NSFNET topology 34
Exploring Alternatives to Policy Search 0 50000 100000 150000 200000 250000 300000 350000 Time (s) 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 Mean Reward PPO (baseline) 1 Worker 2 Workers 4 Workers 8 Workers 16 Workers 32 Workers (a) Results of running 1 to 32 workers in the local server 0 500 1000 1500 2000 2500 Time (s) 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 Mean Reward PPO (baseline) 1 Worker 2 Workers 4 Workers 8 Workers 16 Workers 32 Workers (b) Results of running 1 to 32 workers in the local server (zoomed in) 0 5000 10000 15000 20000 25000 30000 Time (s) 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 Mean Reward PPO (baseline) 16 Workers 32 Workers 64 Workers (c) Results of running 16 to 64 workers in the remote server Figure 9: Effect of using ES with varying number of workers over the G´ EANT2 topology 35
Exploring Alternatives to Policy Search Figure 9 shows the results when run with the G´ EANT2 topology and its respective configuration. Just as before, Figures 8a and 8b show the results of the local server, while Figure 8c of the remote server. From it results we can draw similar conclusions to the ones drawn by the results over NSFNET. First, increasing the number of workers speed ups training time without affecting the value at which the algorithm converges, with the exception of increasing from 16 to 32 workers in the local server (Figure 9b), just as before. ES also converges to a higher value than PPO: the former converges at a mean reward of around 26 while the latter at around 22, as seen clearly in Figure 9c. However, unlike before we see that this time around the shape of the training curve of PPO and ES ends up being much closer to each other. In Figure 9c we can see that the slope of the curve of ES when using 16, 32 and 64 workers is more pronounced than PPO’s curve during the first 5000 seconds. This confirms that ES was increasing its mean reward faster than PPO during this period, thus meaning it was learning faster. This contrast to the results in NSFNET, where the main advantage came from ES outperforming PPO’s score by a significant margin. Besides this, the only remaining difference between the results in both topologies is that overall the G´ EANT2 topology took longer longer to train both in ES and PPO, but that was due to the larger environment and MPNN model. The final set of graphs, shown in Figure 10, show the results when running the model to optimize both topologies simultaneously. The idea with this configuration was not only to test the scalability of ES but also how it performed when training from more that one environment. To do is important to enrich the model by learning from more than one topology at once. This aspect is crucial when we consider the fact that the underlying model is a MPNN, which is invariant to graph isomorphism, meaning that any degradation in performance is more likely to come from the optimization algorithm that the model itself. However, by looking at the results in Figure 10 it is clear that ES works appropriately when trained with both graph topologies simultaneously, as its results mirror those from previous results, specifically those when trained with the G´ EANT2 topology alone. The only notable difference is by comparing the performance of ES with 16 workers against PPO in the remote server. By comparing Figures 9c and 10c we can see than when training only in the G´ EANT2 topology and using ES with 16 workers converges slightly faster than PPO. However, when training in both topologies PPO seems to be slightly quicker instead. This may suggest that ES performs slightly worse with multiple topologies relative to PPO, however this result is marginal. A alternative explanation could be the innate instabilities of both methods (as they use randomness in some way or another) caused PPO to be more “lucky” when training in both topologies. Nevertheless the main conclusions related to ES converging at a higher score and being accelerated through additional workers still hold. 36
Exploring Alternatives to Policy Search 0 50000 100000 150000 200000 250000 300000 350000 Time (s) 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 Mean Reward PPO (baseline) 1 Worker 2 Workers 4 Workers 8 Workers 16 Workers 32 Workers (a) Results of running 1 to 32 workers in the local server 0 500 1000 1500 2000 2500 Time (s) 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 Mean Reward PPO (baseline) 1 Worker 2 Workers 4 Workers 8 Workers 16 Workers 32 Workers (b) Results of running 1 to 32 workers in the local server (zoomed in) 0 5000 10000 15000 20000 25000 30000 Time (s) 10 15 20 25 Mean Reward PPO (baseline) 16 Workers 32 Workers 64 Workers (c) Results of running 16 to 64 workers in the remote server Figure 10: Effect of using ES with varying number of workers over both topologies simultaneously 37
Exploring Alternatives to Policy Search 6.4 Analyzing ES scalability over the number of workers With the figures showing the raw data out of the way, let us now examine more in detail the scalability of ES in respect to the number of workers. Figure 11 shows the effect of the number of workers in the time spent interacting with the environment. Each curve represents one of the configurations, the x-axis denotes the number of workers and the y-axis the time dedicated in each iteration to interact with the environment. 1 2 4 8 16 32 64 Number of workers 8 32 128 512 Time spent perfoming episodes per epoch (s) Local Server AWS NSFNET GÉANT2 NSFNET + GEÁNT2 (estimate) Figure 11: Effect on the number of workers over the time spent per epoch performing episodes By looking at the downward slope it is clear that increasing the number of workers decreases the time spent by ES interacting with environment across all three configurations. Note that this does not mean that the number of mutations is reduced, but that more mutations are done simultaneously, as the workload is further spread out. We can also see that this relationship is linear as expected: doubling the number of workers will cut in half the time spent (for example, in G´ EANT2 from 118 to 62 seconds when increasing from four to eight workers, in NSFNET being from 18 to nine seconds). In the remote server this effect continues, as the difference between 32 and 64 threads the time is reduced from 41 to 21 seconds for the G´ EANT2 topology and from seven to four seconds for the NSFNET topology. Unsurprisingly, overall NSFNET spends the least time interacting with the environment and G´ EANT2 the most. In the first place the latter works with a larger network topology, which can take more demands before saturating and thus its episodes last longer. The G´ EANT2 configuration also works with a larger model, so it will also take longer for it to compute its action probabilities distribution. Finally, referring back at Table 1, the G´ EANT2 configuration generates six times as many perturbations as those in NSFNET, which means it performs six times the number of episodes per iteration. 38
Exploring Alternatives to Policy Search 1 2 4 8 16 32 64 Number of workers 98.4% 98.6% 98.8% 99% 99.2% 99.4% 99.6% 99.8% 100% Percentage (%) training time spent interacting with the Environment Local Server AWS NSFNET GÉANT2 NSFNET + GEÁNT2 (estimate) Figure 12: Effect on the number of workers over the relative time spent per epoch performing episodes To these results we have to add those of Figure 12, which shows the percentage of training time dedicated to performing episodes according to the number of workers. This figure is the same as before, but the y-axis shows the time invested in interacting with the environment as a percentage of total training time. While increasing the number of workers reduces this value, as the raw amount time taken is reduced and the overhead due to communication costs is increased, across all configurations it is clear that interacting with the environment is the most time-consuming part of the training. Even with the configuration with the fastest episodes, NSFNET, and with the highest number of workers tested, it still spends over 98.2% of training interacting with the environment. This comes to show that we still have plenty of margin to increase the number of workers and further decrease the time taken to interact with the environment, solidifying the scalability of ES over the number of workers. 6.5 Summary of results The final aspect to consider is evaluating how each configuration performs relative to PPO depending on the number of workers available. While we know from the previous figures that the algorithm does scale, the question now is if that is enough to justify its use over PPO. To do so, from the experiments run and presented in Figures 8, 9 and 10 the following steps were completed: 1. We recorded the score at which PPO converged, and established it as the “benchmark”. 2. From the results, we extracted the time taken for both PPO and ES (with varying number of workers) to reach that benchmark. 3. We extracted the ratio between ES’s time and PPO’s time. This is repeated across the three configurations and the different number of workers for ES used. 39
Exploring Alternatives to Policy Search The resulting graph is the one shown in Figure 13. The y-axis shows how fast ES training time was as a multiple of PPO’s training time. For example, a value of “×2” meant that ES was twice as fast to reach the benchmark, or that it took half the time. A value of “×1/2” conversely means that ES took twice as long as PPO to reach the benchmark, or that it was twice as slow. Overall, the higher the y-value, the faster was ES relative to PPO. The horizontal dotted line at “×1” represents the break-even point where both techniques train just as fast. The first thing it can be seen is the confirmation of what it was already shown by Figures 11 and 12: an increase in workers resulted in a linear decrease in training time. However, the degree of the speed-up depended heavily on the configuration used. 1 2 4 8 16 32 64 Number of workers ×1/16 ×1/4 ×1 ×4 ×16 ×64 ×256 Training speed-up with ES (relative to PPO) Local Server AWS Break-even point ES slower than PPO ES faster than PPO NSFNET GÉANT2 NSFNET + GEÁNT2 Figure 13: Training speed-up achieved when switching from PPO to ES across different number of workers and topologies On one hand, NSFNET benefited massively by switching to ES. The only scenario where PPO is faster than ES is when it only has one worker, where it goes twice as fast. However, by increasing to two workers by we see the time taken to reach the benchmark fall by one quarter, from taking twice the time than PPO to slightly over half of the time. Further duplicating the number of workers continues this trend: with four workers the training time is one eighth of PPO’s time, and with eight workers ES reaches the benchmark 32 times as fast as PPO. This streak is broken by running 16 workers, where the speed-up stalls. When changing to the remote server the results fall within our original expectations: doubling from 32 to 64 workers halved the time taken to reach the benchmark. The question then is how duplicating the number of threads results in a four-fold decrease in the training time, as well as how did the speed up stalled when jumping from eight to 16 workers. The answer lies in the method’s inherent instability due to its reliance in Gaussian noise. Thus, during those four first experiments not only each iteration was becoming shorter, but also the amount of epochs required to reach the benchmark score was also decreasing due to having better “luck” with the perturbations it sampled. Similarly, that randomness might explain why with 16 workers the speed up stalled, as poorer sampling resulted in taking more iterations that its predecessors to reach the benchmark. 40
Exploring Alternatives to Policy Search On the other hand, both the G´ EANT2 topology and running both topologies offered more moderate results. Compared to the NSFNET results, both curves had a more stable trajectory along our expected outcome of double the workers, half the time. At first the results appear to be abnormally bad, with both one and two workers taking 16 times longer than PPO respectively. However, by looking the trend between four and 16 workers we can observe the desired behaviour: with four workers the training time was roughly twice as slow as PPO, with eight was approximately just as fast, and with 16 around twice as fast. When switching to the remote server the trend continued. The only notable fact here is how in the local server the G´ EANT2 topology by itself was taking slightly longer to reach the benchmark relative to using both topologies at once, while in the remote server it was the other way around. While we discussed this when presenting the results from Figure 10, we believe that this is due to a slight increase in PPO’s performance when training in both topologies due to the method’s inherent instability. Another important observation is the clear the gap that exists between the curves using NSFNET and the other two configurations. The main reason why the gap exists is due to the difference in the number of mutations. Looking back at Table 1 we can see that the NSFNET topology used 128 perturbations per iteration (doubled if counting the mirrored perturbations), while the other two episodes used 640, five times as many. As a remainder, the number of perturbations used per each iteration also equals the number of episodes in it. The increased number of perturbations is needed however, as the G´ EANT2 and the combined NSFNET and G´ EANT2 configurations use a larger MPNN, meaning its solution space is larger and more perturbations are needed to properly cover it when computing its gradient. Still, even if the number of episodes increases five-fold, from the graph we can observe that roughly NSFNET takes an eight of the time to reach the benchmark compared to the other two configurations. On one hand this can be explained by the fact that NSFNET’s initial scores are closer to the benchmark than G´ EANT2, and therefore it requires less iterations to reach it. Looking back at Figure 8b we see when applying ES to NSFNET the initial solutions start with a mean reward of around 15 while PPO converges at around 17. On the other hand, looking at Figure 9b shows that when applying ES to G´ EANT2 the initial solutions also start with a mean reward of 15 but PPO converges at around 23.5. The difference between the starting points may explain this massive difference, but also hints that NSFNET speedups are too optimistic for new untested scenarios, and instead it is more realistic to expect results similar to the ones obtained with G´ EANT2. Other factors also include longer computation times from G´ EANT2’s larger MPNN, or longer episodes due to its larger topology. In the end, it is clear that problem’s size will eventually affect the number of parameters of the network, which in itself will have a direct and indirect (through the effect on the number of perturbations) impact in the training time of ES. 41