Title: GAP-AWARE MITIGATION OF GRADIENT STALENESS

Abstract: Cloud computing is becoming increasingly popular as a platform for distributed training of deep neural networks. Synchronous stochastic gradient descent (SSGD) suffers from substantial slowdowns due to stragglers if the environment is nondedicated, as is common in cloud computing. Asynchronous SGD (ASGD) methods are immune to these slowdowns but are scarcely used due to gradient staleness, which encumbers the convergence process. Recent techniques have had limited success mitigating the gradient staleness when scaling up to many workers (computing nodes). In this paper we define the Gap as a measure of gradient staleness and propose Gap-Aware (GA), a novel asynchronous-distributed method that penalizes stale gradients linearly to the Gap and performs well even when scaling to large numbers of workers. Our evaluation on the CIFAR, ImageNet, and WikiText-103 datasets shows that GA outperforms the currently acceptable gradient penalization method, in final test accuracy. We also provide convergence rate proof for GA. Despite prior beliefs, we show that if GA is applied, momentum becomes beneficial in asynchronous environments, even when the number of workers scales up. * Equal contribution. 1 An environment of computation nodes who are not specifically optimized to work together

1. INTRODUCTION:

The steady growth of deep neural networks over the years has made it impractical to train them from scratch on a single worker (i.e., computational device). Distributing the computations over several workers can drastically reduce the training time. However, due to the sequential nature of the widely used stochastic gradient descent (SGD) method, distributing the process is not an easy task.

Synchronous SGD (SSGD) is the most common method used to distribute the learning process across multiple workers. Several recent works (Mikami et al., 2018; Ying et al., 2018; Yamazaki et al., 2019; Goyal et al., 2017) have shown that SSGD can achieve large speedups while maintaining high accuracy. The major drawback of SSGD is that its speed is confined to the slowest worker in every iteration. This shortcoming is magnified in non-dedicated 1 environments such as cloud computing. For this reason, all the above mentioned works were forced to use homogeneous workers in a dedicated network, which serves to reduce the variance in the workers' iteration times. Unlike cloud computing, dedicated networks are expensive and therefore not available to most users.

In asynchronous SGD (ASGD), each worker communicates independently of the others, thereby addressing the major drawback of SSGD. ASGD enjoys linear speedup in terms of the number of workers, even on non-dedicated networks. This makes ASGD a potentially better alternative to SSGD when using cloud computing. Unfortunately, ASGD also has a significant weakness known as gradient staleness; the gradients used to update the parameter server's (master) parameters are often based on older parameters and therefore are inaccurate. Prior works have shown that gradient staleness severely hinders the convergence process by reaching reduced final accuracy (Chen et al., 2016; Cui et al., 2016) . Mitliagkas et al. (2016) showed that gradient staleness also induces implicit momentum, thus the momentum coefficient γ must be decayed when scaling up the number of workers. Most research works measure the gradient staleness of a worker according to the delay: the number of master updates since the worker began calculating the stochastic gradient g, until g is used to update the master. To overcome gradient staleness, Zhang et al. (2015b) proposed Staleness-Aware (SA), which penalizes the step size of stale gradients linearly to their delay. This method was later embraced by other works (Jiang et al., 2017; Hardy et al., 2017; Giladi et al., 2019) and is currently the common method for penalizing stale gradients. Unfortunately, this method suffers from a degradation of the final accuracy, especially when scaling up the number of workers. In Section 4.1, we show that the main reason for this degradation is the over-penalization and under-penalization caused by SA.

SSGD and ASGD rely on hyperparameter tuning for every different number of workers (Shallue et al., 2018) . Tuning is extremely time-consuming, thus avoiding it is beneficial, whenever possible.

Our contribution: To mitigate gradient staleness while minimizing the degradation of final accuracy, we define a measure of gradient staleness we refer to as the Gap. The Gap is based on the difference between the parameters used to calculate the gradient and the parameters on which the gradient is applied. We propose a new method called Gap-Aware (GA) that penalizes the step size of stale gradients linearly to their Gap, while eliminating the over-penalization or under-penalization of SA. No new hyperparameters are introduced using the GA method.

• We show that GA out-performs SA, especially as the number of workers scales up.

• We prove that the convergence rate of the GA-ASGD algorithm with a non-convex loss function is consistent with SGD: O 1 √ BK where K is the total number of steps and B is the batch size.

• We show that penalizing the gradient itself rather than the step-size, eliminates under-penalization.

• Our results suggest that GA can be used without re-tuning the hyperparameters.

• As opposed to conclusions by Mitliagkas et al. (2016) , we show that applying momentum in an asynchronous environment is advantageous (using GA), even when multiple workers are used. • We combine GA with Adam (Kingma & Ba, 2015) (Adam-GA), and show that Adam-GA achieves almost two orders of magnitude better perplexity than Adam or Adam-SA (which combines Adam with SA) using several workers on the Transformers-XL model.

Our results establish GA as a superior gradient-penalizing option to SA and suggest that using GA is a preferable alternative to SSGD in non-dedicated networks such as cloud computing, even when scaling to large numbers of workers. To validate our claims, we performed experiments on the CIFAR10, CIFAR100 (Krizhevsky, 2012) , ImageNet (Russakovsky et al., 2015) , and WikiText-103 (Merity et al., 2016) datasets, using several state-of-the-art architectures. A version of GA has reached 72.18% final test accuracy on the ImageNet dataset using 128 simulated asynchronous workers. As far as we know, this is the largest number of asynchronous workers reported to converge on ImageNet.

2. RELATED WORK:

Eliminating gradient staleness is a challenging task and several papers suggested techniques to reduce its detrimental effects. Zheng et al. (2017) proposed DC-ASGD, which uses a Taylor expansion to mitigate the gradient staleness. EASGD (Zhang et al., 2015a) uses a center force to pull the workers' parameters toward the master's parameters. Both DC-ASGD and EASGD achieve high accuracy on small numbers of workers, but fall short when trained on large clusters. Chan & Lane (2014) proposed penalizing stale gradients by reducing their size and thus limiting their effect on the learning process. They suggest decaying the learning rate exponentially to the delay; this makes the step size arbitrarily small when the amount of workers grows, virtually ceasing the learning process. As part of their convergence analysis, Dutta et al. (2018) suggest a penalizing method that is linear to the norm between the master and worker's parameters. However, their method introduces another hyperparameter, which requires additional time to tune. As opposed to other methods, GA performs well even when the number of workers is large, without introducing new hyperparameters. Gupta et al. (2016) as well as Aji & Heafield (2019) suggest collecting several gradients before updating the master to reduce the effects of gradient staleness. Wen et al. (2017) propose minimizing the size of the gradients to reduce communication times. GA is orthogonal to both of these approaches.

3. BACKGROUND:

The goal of an optimization procedure is to minimize f (θ), where f is a smooth, but not necessarily convex, objective function (a.k.a. loss) and the vector θ ∈ R d is the model's parameters:

EQUATION

where ξ ∈ Ξ is a random variable from Ξ, the entire set of training samples Ξ = {1, 2, 

θ k+1 = θ k -η k ∇f (θ k ).

We denote X k as the variable X at the k th step, where X is any variable.

Momentum Momentum (Polyak, 1964 ) is a widely adopted optimization technique due to its accelerated convergence and oscillation reduction (Sutskever et al., 2013) . Instead of simply using the gradient, the momentum iterative update rule2 uses an exponentially-weighted moving average of gradients called the update vector:

v k+1 = γv k + ∇f (θ k ).

The update rule is:

θ k+1 = θ k -η k v k+1 .

Nesterov's Accelerated Gradient (NAG) (Nesterov, 1983 ) is a well-used variation of momentum that has been proven to achieve quadratic speedup in convergence rate compared to SGD.

4. ASYNCHRONOUS SGD (ASGD):

We consider the commonly used ASGD, which operates with a parameter-server (master), used to keep the model's most up-to-date parameters. Each worker maintains a replica of the model's parameters. The workers run in parallel and synchronize with the master independently from each other at the beginning of each batch iteration. We denote τ k as the delay at the k th step. The worker and master algorithms are given by Algorithm 1 and 2, respectively, where B is the batch-size and ξ k,b denotes the b th sample in the batch sampled at the k th iteration. Gradient staleness appears when a gradient g k is computed on parameters θ k-τ k but applied to different parameters θ k .

Algorithm 1 Momentum-ASGD: worker i

Always do: Receive parameters θ k-τ k from the master Get B training samples ξ k-τ k ,[1...B]

Compute gradient: Zhang et al. (2015b) proposed a gradient penalization method called Staleness-Aware (SA). SA aims to reduce the effects of gradient staleness by dividing the step size by its corresponding τ (Algorithm 3). The worker algorithm remains unchanged. The two ideas behind SA is that stale gradients should be penalized to reduce their impact and that gradient staleness scales up with τ . SA successfully mitigates the gradient staleness when N is small. Although commonly used, SA can potentially over-penalize as well as under-penalize stale gradients as we show below. 

g i k ← B b=1 ∇F (θ k-τ k ;ξ k-τ k ,b ) B Send g i k to

θ k+1 ← θ k -η k • v k+1 Send θ k+1 to worker i 4.1 STALENESS-AWARE

← k -iter[i] Update momentum v k+1 ← γv k + g i k Update master θ k+1 ← θ k -η k τ k v k+1 Send θ k+1 to worker i Save current iteration iter[i] ← k Algorithm 4 Gap-Aware: master For k = 1...K do: Receive gradient g i k from worker i Calculate Gap: G k = |θ k -θ k-τ k | C + 1 d Update momentum v k+1 ← γv k + 1 G k g i k Update master θ k+1 ← θ k -η k v k+1

Save and send current parameters θ k+1 to worker i

Over-Penalizing Let us assume that at some step k, after τ master updates we get θ k = θ k-τ just as the gradient calculated on θ k-τ is applied. This means there is no gradient staleness for the next gradient update since it was computed using the same parameters on which it is applied.

Unfortunately, the delay remains τ > 0, thereby causing over-penalization when SA is used.

Additionally, τ scales linearly with N , which dramatically reduces η when N is large. Consequently, on large numbers of workers, the convergence rate of SA is sluggish and its accuracy plummets.

Under-Penalizing The SA method doesn't take into account that when using momentum, the update step also contains past gradients. To emphasize the importance of this issue, let's examine a fictional example: assume that some gradient g k is very stale (τ k is large). Following the SA technique, the update rule is:

θ k+1 = θ k -η k τ k • v k+1 = θ k -η k τ k • (γv k + g k ).

This means the stale gradient g k is indeed penalized by being multiplied by η k τ k , which is small; thus g k doesn't change the parameters much. We further assume the next iteration is very fast (τ k+1 is small). The next update will be:

θ k+2 = θ k+1 -η k+1 τ k+1 • (γ 2 v k + γg k + g k+1 ).

The stale gradient g k is multiplied by γ η k+1 τ k+1 , which is large (assuming η k ≈ η k+1 ). Despite the fact that g k was stale, it still has a significant impact on the learning process. In other words, g k is under-penalized.

To eliminate this possibility we penalize the stale gradient itself rather than the learning rate. Using this method, the staleness of each gradient is accounted for within the update vector v.

5. GAP-AWARE (GA):

In this section we propose a new method called Gap-Aware to mitigate over and under-penalization.

5.1. THE GAP AS A MEASURE OF GRADIENT STALENESS:

An intuitive method to measure gradient staleness would be: ∇f (θ k )-∇f (θ k-τ k ) . This essentially measures the difference between the stale gradient and the accurate gradient that is computed on the up-to-date parameters. (Of course, ∇f (θ k ) is never calculated in ASGD algorithms.) Commonly used in deep learning is the Lipschitzian gradients assumption:

∇f (x) -∇f (y) ≤ L x -y , ∀x, ∀y, L ∈ R (2) Setting x = θ k , y = θ k-τ k into Equation 2 we get: ∇f (θ k ) -∇f (θ k-τ k ) ≤ L θ k -θ k-τ k .

This implies that θ k -θ k-τ k is a valid (and easily calculated) measure of the gradient staleness. This measure also addresses the delay's over-penalization; using the same simple example described in Section 4.1, the term θ k -θ k-τ k will now be zero, correctly measuring the gradient staleness.

The learning rate η, commonly decays as the training progresses. This decay can be viewed as a built-in penalization to reduce variance. Following this notion, we suggest reducing the staleness penalization as η decays. To accommodate all the attributes above, we define the Gap: Definition 1. G k , the Gap at the k th step, is defined as the minimal number of updates required to traverse the current distance between the master's and worker's parameters using the maximal learning rate and assuming all gradients have an average norm. G k ∈ R is defined as:

G k = θ k -θ k-τ k /C + 1 Where C = η max E k [ ∇f (θ k-τ k )

] is a constant representing the maximal distance the parameters can travel in a single update, given the gradient's norm is the average gradient norm.

Definition 1 means that dividing η by the Gap produces larger steps than those produced by SA This allows exploring more distant minimas while still mitigating the gradient staleness. Note that E[G k ] = τ k occurs only if all previous τ k updates were in the exact same direction, which rarely happens. Empirically, we found that

E[G k ] < τ k (See Appendix C.8).

To mitigate the gradient staleness, while eliminating the over-penalization and under-penalization, we divide the gradients themselves by their respective Gap. We refer to this method as Gap-Aware (GA).

5.2. CONVERGENCE ANALYSIS:

In this section we provide the outlines of the convergence analysis. The complete proofs are given in Appendix B. The GA-ASGD update rule (without momentum) is:

EQUATION

The convergence rate is the speed (or number of steps) at which a convergent sequence approaches its limit. We follow ideas similar to Lian et al. (2015) to show that the upper bound of the convergence rate of GA on a non-convex loss function is similar to that of SGD. Assumption 1. We assume the following, commonly-used assumptions, hold:

• Unbiased gradient: The stochastic gradient ∇F (θ; ξ) is unbiased:

EQUATION

• Bounded variance: The variance of the stochastic gradient is bounded:

EQUATION

• Lipschitzian gradients: See Equation 2.

• Independence: All the random variables {ξ k,b } k=1...K;b=1...B , are independent.

• Bounded age: All delay variables τ 1 , ...τ K are bounded:

max k τ k ≤ T (6)

Theorem 1. Assume that Assumption 1 holds and the learning rate sequence {η k } k=1•••K satisfies:

EQUATION

We have the following ergodic convergence rate for the iteration of GA-ASGD:

1 K k=1 η k G k K k=1 η k G k E( ∇f (θ k ) 2 ) ≤ 2(f (θ1)-f (θ * )) B + K k=1 η k G k + 2BL k-1 j=k-T η 2 j G 2 j η k Lσ 2 G k K k=1 η k G k (8) Where E[•] denotes taking expectation in terms of all random variables.

To simplify the upper bound in Theorem 1, we observed that setting the learning rate η k such that the expression η k G k is a constant value across all k obtains the following convergence rate: Corollary 1. Assume that Assumption 1 holds and that η k are set such that η k G k is constant for any k as follows:

EQUATION

If the maximal delay parameter T satisfies:

K ≥ 4BL(T + 1) 2 (f (θ 1 ) -f (θ * )) σ 2 (10)

then the output of GA satisfies the following ergodic convergence rate: Corollary 1 claims that if the total iterations K is greater than O(BT 2 ), the convergence rate achieves O(1/ √ BK), which is consistent with the convergence rate of ASGD presented in Lian et al. (2015) , and with the convergence rate of SGD.

EQUATION

5.3. GAP-AWARE VERSIONS:

We explore three ways to measure G k :

• Global: G k ∈ R as defined in Definition 1.

• Layer-wise: Every layer is penalized differently and independently. G k ∈ R P where P is the number of layers in the model. We denote 1 S as an S-dimensional vector of ones. We denote any vector X * ,p is the p th layer in the vector X * . Every element in G k is calculated per-layer:

EQUATION

• Parameter-wise: Every parameter (element in the parameter vector θ) is penalized differently and independently. G k ∈ R d where d is the number of parameters. We denote | • | on vector X, as the absolute value per element of X. Every element in G k is calculated and applied per-element:

EQUATION

Where C ∈ R d is also calculated element-wise. Specifically,

C = η max E k [|∇f (θ k-τ k )|].

We tested these variations on three different frameworks3 to determine which technique has the best performance. Figure 1 demonstrates that the parameter-wise method (equation 13) resulted in the best test and train error. Since this phenomenon repeats across all frameworks, we henceforth use the parameter-wise method in the Gap-Aware algorithm. We denote as an element-wise multiplication between vectors and describe the final GA algorithm of the master as Algorithm 4. The worker algorithm remains the same as in Algorithm 1.

6. EXPERIMENTS:

We simulated multiple distributed workers4 to measure the final test error, train error, and convergence speed of different cluster sizes. To validate that penalizing linearly to the Gap is the factor that leads to better performance, we used the same hyperparameters across all the tested algorithms (see Appendix C.4). These hyperparameters are the ones tuned for a single worker, suggested by the authors of the respective papers for each framework. We simulated the workers' execution time using a gamma-distributed model (Ali et al., 2000) (see Appendix C.3), where the execution time for each individual batch was drawn from a gamma distribution. The gamma distribution is a well-accepted model for task execution time, which naturally gives rise to stragglers. The importance of asynchronous over synchronous training is explained in Appendix D.

Combining GA with DANA One way to verify whether it is better to penalize using the Gap or the delay, is to change the Gap while fixing the delay, and examining the results using GA and SA. Momentum generally increases the norm of the update vector; this in turn, increases the effective step size thus increasing the Gap for a given delay. Hakimi et al. (2019) introduced DANA, which uses the momentum to estimate the master's parameters at the time of the gradient update, thus decreasing the Gap. The combination of decreasing the Gap using DANA and penalizing stale gradients using GA or SA is easily integrated since both methods are orthogonal. In our experiments, we also compared between DANA-Gap-Aware (DANA-GA) and DANA-Staleness-Aware (DANA-SA). We note that since DANA decreases the Gap, DANA-GA penalizes much less than DANA-SA (see Appendix C.8).

:RUNHUV 7HVW(UURU $6*' 1$*$6*' 6WDOHQHVV$ZDUH *DS$ZDUH '$1$ '$1$6$ '$1$*$ (a) CIFAR10 ResNet-20 :RUNHUV 7HVW(UURU $6*' 1$*$6*' 6WDOHQHVV$ZDUH *DS$ZDUH '$1$ '$1$6$ '$1$*$ (b) CIFAR10 WideResNet :RUNHUV 7HVW(UURU $6*' 1$*$6*' 6WDOHQHVV$ZDUH *DS$ZDUH '$1$ '$1$6$ '$1$*$ (c) CIFAR100 WideResNet

Algorithms Our evaluations consist of the following algorithms:

• Baseline: Single worker with the same tuned hyperparameters as in the respective framework's paper. See Appendix C.4. • ASGD: ASGD (Algorithm 2) without momentum (γ = 0).

• NAG-ASGD: ASGD with momentum (Algorithm 2) using a NAG optimizer.

• Staleness-Aware: SA as described in Algorithm 3, using a NAG optimizer.

• Gap-Aware: Parameter-wise GA (Algorithm 4) as described in Section 5, using a NAG optimizer. Our evaluation was extensive on image classification tasks such as CIFAR10, CIFAR100 (Krizhevsky, 2012) , and ImageNet (Russakovsky et al., 2015) . It also included a language modeling task using the WikiText-103 corpus (Merity et al., 2016) . All datasets and models are detailed in Appendix C.2.

6.1. EVALUATION ON CIFAR:

Gradient Staleness Effects In Figure 2 , NAG-ASGD shows how gradient staleness is exacerbated by momentum. NAG-ASGD yields high accuracy with few workers, but the test error climbs sharply when more than 16 workers are used. On the other hand, ASGD without momentum performs poorly using few workers. When using many workers, ASGD significantly surpasses NAG-ASGD because of the implicit momentum generated in asynchronous training (Mitliagkas et al., 2016) .

SA & GA Figure 2 also demonstrates that both staleness penalization methods (GA and SA) outperform the naive NAG-ASGD. GA results in better final test error than SA across all experiments. This empirically proves that GA is the better method for penalizing the gradients. We claim this occurs mainly because SA over-penalizes the gradients, thereby making it impossible to reach any distant, good minima when the number of steps is limited (for more details see Appendix C.8).

DANA Versions:

Figure 2 shows that DANA potentially diverges when N grows as opposed to DANA-GA and DANA-SA. This shows that DANA benefits from staleness penalization. Furthermore, DANA-GA out-performs all other methods and remains close to the baseline's error across all frameworks. The fact that DANA-GA out-performs DANA-SA validates that GA is superior to SA. Tuned ASGD To validate that the staleness penalization helps overcome the gradient staleness and improve the results, we tuned the momentum and learning rate of ASGD using 32 workers on the 3 frameworks shown in Figure 2 . For each framework, we performed a grid search of 70 perturbations (See Appendix C.12). Table 1 shows that GA and DANA-GA, using the same hyperparameters as the baseline, provide similar or better results than tuning both γ and η, which is highly time-consuming.

According to Mitliagkas et al. (2016) , if momentum is used, the asynchronous implicit momentum should impede the convergence as N increases. However, GA and DANA-GA, which use a large momentum, generally perform better than the tuned ASGD even when N is large. This phenomenon repeats across all frameworks, which suggests that GA, and especially DANA-GA, can mitigate the asynchronous implicit momentum problem. Tuning these methods should further improve the results.

The graphs of the train error also show the same concepts discussed here regarding the test error and are presented in Figure 6 , Appendix C.10. The convergence rate analysis appears in Appendix C.11.

6.2. IMAGENET EXPERIMENTS:

We conducted experiments on the ImageNet dataset using the ResNet-50 model (He et al., 2016) . Every asynchronous worker is a machine with 8 GPUs, so the 128 workers in our experiments simulate a total of 1024 GPUs. For reference, Goyal et al. (2017) used 256 GPUs synchronously. The hyperparameters we used are those of the tuned single worker (see Appendix C.4). Table 3 shows that GA out-performs SA due to the high number of workers, which exacerbates the over-penalizing of SA. Unlike SA, GA out-performs NAG-ASGD as N increases due to successful staleness mitigation. DANA-GA remains close to the baseline and better than any other method as N increases. DANA-GA reaches 72.18% final test accuracy when using 128 workers, which is the most asynchronous workers shown to converge on ImageNet as far as we know.

6.3. NLP EXPERIMENTS:

NLP tasks are usually trained using Adam (Kingma & Ba, 2015) . To test SA and GA we implemented a version of Adam-SA and Adam-GA given by Algorithm 10 and 11, respectively (Appendix C.1). Transformer-XL (Dai et al., 2019) is a state-of-the-art model for NLP tasks; however, its sensitivity to gradient staleness is catastrophic (Aji & Heafield, 2019) . Table 2 shows that GA successfully mitigates the gradient staleness and achieves near-baseline perplexity while SA results in a higher perplexity by almost two orders of magnitude. In this scenario, SA completely fails to mitigate the gradient staleness, proving the superiority of GA. (See hyperparameters in Appendix C.4).

7. CONCLUSIONS:

The goal of this work is to mitigate gradient staleness, one of the main challenges of ASGD. We argue that penalizing stale gradients linearly to the delay, as done in the widely used SA method, flounders due to over and under-penalization. We defined the Gap to measure gradient staleness and proposed GA, a novel asynchronous distributed technique that mitigates the gradient staleness by penalizing stale gradients linearly to the Gap. We showed that GA surpasses SA across all frameworks, especially in NLP problems or when the number of workers is large. This presents GA as a superior alternative for staleness penalizing. We further introduced DANA-GA and demonstrated that DANA-GA mitigates gradient staleness better than any of the other methods we compared. Despite prior belief, DANA-GA's superb performance enables the use of momentum in asynchronous environments with many workers; it presents a desirable alternative for parallel training with multiple workers, especially on non-dedicated environments such as cloud computing. In future work, we plan to examine what makes GA perform so well in NLP tasks.

ACKNOWLEDGEMENT:

This work was supported by The Hasso Plattner Institute.

A SOURCE CODE:

The source code of DANA-Gap-Aware is provided via: DOWNLOAD LINK

B PROOFS:

Proof for Theorem 1

Proof. From the Lipschitzisan gradient assumption equation 2, we have

EQUATION

Taking expectation with respect to ξ k, * on both sides of equation 14, we have

EQUATION

)

where we use the unbiased stochastic gradient assumption (equation 4).

From the fact that:

a, b = 1 2 a 2 + b 2 -a -b 2

we have

EQUATION

Next we estimate the upper bound of T 1 and T 2 . For T 2 we have

T 2 =E ξ k, *   B b=1 ∇F (θ k-τ k ; ξ k-τ k ,b ) 2   =E ξ k, *   B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) + B b=1 ∇f (θ k-τ k ) 2   =E ξ k, * B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) 2 + B b=1 ∇f (θ k-τ k ) 2 + 2 B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) , B b=1 ∇f (θ k-τ k ) =E ξ k, *   B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) 2 + B b=1 ∇f (θ k-τ k ) 2   =E ξ k, *   B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) 2 + B b=1 ∇f (θ k-τ k ) 2   =E ξ k, * B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) 2 + 2 1≤b<b ≤B ∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k ), ∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k ) + B b=1 ∇f (θ k-τ k ) 2 ≤E ξ k, * B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) 2 + B b=1 ∇f (θ k-τ k ) 2 ≤Bσ 2 + B b=1 ∇f (θ k-τ k ) 2 (17)

where the fifth equality is due to

E ξ k, * B b=1 (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) , B b=1 ∇f (θ k-τ k ) = B b=1 E ξ k, * (∇F (θ k-τ k ; ξ k-τ k ,b ) -∇f (θ k-τ k )) , B b=1 ∇f (θ k-τ k ) =0

and the last inequality is due to the bounded variance assumption equation 5 and due to:

EQUATION

)

We next turn to T 1 :

T 1 = ∇f (θ k ) - 1 B B b=1 ∇f (θ k-τ k ) 2 = ∇f (θ k ) -∇f (θ k-τ k ) 2 ≤L 2 θ k -θ k-τ k 2

where the last inequality is from the Lipschitzian gradient assumption (equation 2). It follows that

T 1 ≤L 2 θ k -θ k-τ k 2 =L 2 k-1 j=k-τ k (θ j+1 -θ j ) 2 =L 2 k-1 j=k-τ k η j 1 G j • B b=1 ∇F θ j-τj ; ξ j-τj ,b 2 =L 2 k-1 j=k-τ k η j 1 G j • B b=1 ∇F θ j-τj ; ξ j-τj ,b -∇f θ j-τj + k-1 j=k-τ k η j 1 G j • B b=1 ∇f θ j-τj 2 ≤2L 2        k-1 j=k-τ k η j 1 G j • B b=1 ∇F θ j-τj ; ξ j-τj ,b -∇f θ j-τj 2 T3 + k-1 j=k-τ k η j 1 G j • B b=1 ∇f θ j-τj 2 T4        (19)

where the last inequality uses the fact that a + b 2 ≤ 2 a 2 + 2 b 2 for any real vectors a and b.

Taking the expectation in terms of {ξ j-τj , * |j ∈ {k -τ k , ..., k -1}} for T 3 , we have

E ξj-τ j , * |j∈{k-τ k ,...,k-1} (T 3 ) =E ξj-τ j , * |j∈{k-τ k ,...,k-1}    k-1 j=k-τ k η j 1 G j • B b=1 ∇F (θ j-τj ; ξ j-τj ,b ) -∇f (θ j-τj ) 2    =E ξj-τ j , * |j∈{k-τ k ,...,k-1}   k-1 j=k-τ k η 2 j G 2 j B b=1 ∇F (θ j-τj ; ξ j-τj ,b ) -∇f (θ j-τj ) 2   + 2E ξj-τ j , * |j∈{k-τ k ,...,k-1} k-1≥j >j ≥k-τ k η j η j G j G j B b=1 ∇F (θ j -τ j ; ξ j -τ j ,b ) -∇f (θ j -τ j ) , B b=1 ∇F (θ j -τ j ; ξ j -τ j ,b ) -∇f (θ j -τ j ) =E ξj-τ j , * |j∈{k-τ k ,...,k-1}   k-1 j=k-τ k η 2 j G 2 j B b=1 ∇F (θ j-τj ; ξ j-τj ,b ) -∇f (θ j-τj ) 2   =E ξj-τ j , * |j∈{k-τ k ,...,k-1}   k-1 j=k-τ k η 2 j G 2 j B b=1 ∇F (θ j-τj ; ξ j-τj ,b ) -∇f (θ j-τj ) 2   ≤E ξj-τ j , * |j∈{k-τ k ,...,k-1}   k-1 j=k-τ k Bη 2 j G 2 j ∇F (θ j-τj ; ξ j-τj ,b ) -∇f (θ j-τj ) 2   ≤B k-1 j=k-τ k η 2 j G 2 j σ 2 (20)

where the second to last equality is due to the last lines in equation 17 and the third equality is due to

E ξj ,k-1≥j≥k-τ k k+τ k -1≥j >j ≥k η j η j G j G j B b=1 ∇F (θ j -τ j ; ξ j -τ j ,b ) -∇f (θ j -τ j ) , B b=1 ∇F (θ j -τ j ; ξ j -τ j ,b ) -∇f (θ j -τ j ) =E ξj ,k-1≥j≥k-τ k k-1≥j >j ≥k-τ k η j η j G j G j B b=1 E j , * ∇F (θ j -τ j ; ξ j -τ j ,b ) -∇f (θ j -τ j ) , B b=1 ∇F (θ j -τ j ; ξ j -τ j ,b ) -∇f (θ j -τ j ) =0.

Taking the expectation in terms of ξ j-τj , * for T 4 , we have

EQUATION

where the last inequality uses the fact that

N i=1 a i 2 ≤ N N i=1 a i 2

for any real vectors a i and the bounded age assumption equation 6.

We take full expectation on both sides of equation 19 and substitute E[T 3 ] and E[T 4 ] by their upper bounds, equation 20 and equation 21 respectively:

EQUATION

Substituting E[T 1 ] and E[T 2 ] with their upper bounds equation 22 and equation 17 respectively, and taking full expectation on both sides in equation 16, we obtain

EQUATION

Summarizing the inequality equation 23 from k = 1 to k = K, meaning until the K-th update of the master, we have

EQUATION

where the second to last inequality is due to equation 7 and the last inequality is due to equation 6.

Note that θ * is the global optimization point. By doing a few simple algebraic operations on equation 24 we have:

EQUATION

This completes the proof.

Proof for Corollary 1:

Proof. Combining equation 9 and equation 10, we get

EQUATION

If follows from equation 26 that

BηL + 2B 2 L 2 T 2 η 2 ≤ 1 2T + 2 + T 2 2(T + 1) 2 ≤ 1 2 + 1 2 = 1

The last inequality holds since naturally T ≥ 0. This implies that condition equation 7 in Theorem 1 is satisfied globally. Then we can safely apply equation 8 in Theorem 1:

1 K K i=1 E( ∇f (θ i ) 2 ) ≤ 2(f (θ 1 ) -f (θ * )) + K Bη 2 L + 2B 2 L 2 T η 3 σ 2 BKη = 2(f (θ 1 ) -f (θ * )) BKη + Lσ 2 η (1 + 2BLT η) ≤ 2(f (θ 1 ) -f (θ * )) BKη + 2Lσ 2 η =2 (f (θ 1 ) -f (θ * ))Lσ 2 BK + 2 (f (θ 1 ) -f (θ * ))Lσ 2 BK =4 (f (θ 1 ) -f (θ * ))Lσ 2 BK

where the third inequality is due to equation 26 and the second to last equality uses equation 9. This completes the proof.

Proof for equation in Section 4.1

Proof.

EQUATION

C EXPERIMENTAL SETUP C.1 ALGORITHMS Algorithms 5 to 11 only change the master's algorithm; the complementary worker algorithm is the same as ASGD (Algorithm 1). The master's scheme is a simple FIFO. We consider parameter server optimizations beyond the scope of this paper.

The calculation of the C coefficient is described in Appendix C.6.

We note that in Algorithms 8 and 11 the term θ i is identical to θ k-τ k from the definition of τ k in Section 4. Receive gradient g i k from worker i Calculate worker i's current delay

← θ k -η k v i Send estimate θ = θ k+1 -η k γ

τ k ← k -iter[i] Update worker's momentum v i ← γv i + g i k τ k Update master's weights θ k+1 ← θ k -η k v i Send estimate θ = θ k+1 -η k γ N j=1 v j to worker i Save current iteration iter[i] ← k

Algorithm 8 DANA-Gap-Aware: master Initialize the given weights for each worker: θ i = θ 0 For k = 1...K do:

Receive gradient g i k from worker i Calculate Gap:

G k = |θ k -θ i | C + 1 d Update worker's momentum v i ← γv i + 1 G k g i k

Update master's weights θ k+1 ← θ k -ηv i Save and send estimate θ i ← θ k+1 -ηγ N j=1 v j to worker i

The Adam-based algorithm requires a slightly more intelligent integration to the gradient staleness penalizing methods (such as GA and SA). Penalizing the gradient before calculating the first and second moments doesn't affect the update vector since the first and second moments cancel each other out. Therefore, we suggest applying the penalty only on the first moment, thus decreasing the update step's size by the desired amount. Since DANA's integration into the Adam algorithm is convoluted and not straight forward, we chose not to implement the combination in this paper.

Algorithm 9 Adam: master Require: η 1 . . . η K : step lengths Require: β 1 , β 2 ∈ [0, 1): exponential decay rates for the moment estimates Initialize: m 0 ← 0, v 0 ← 0 For k = 1...K do:

Receive gradient g i k from worker i Update biased first moment estimate

m k ← β 1 m k-1 + (1 -β 1 )g i k Update biased second moment estimate v k ← β 2 v k-1 + (1 -β 2 )(g i k ) 2 Compute bias-corrected first order moment estimate mk ← m k 1-β k 1 Compute bias-corrected second order moment estimate vk ← v k 1-β k 2 Update master's weights θ k+1 ← θ k -η k • mk √ vk +

Send θ k+1 to worker i Algorithm 10 Adam-Staleness-Aware: master

Require: η 1 . . . η K : step lengths Require: β 1 , β 2 ∈ [0, 1): exponential decay rates for the moment estimates Initialize: m 0 ← 0, v 0 ← 0 Initialize: iter = [0] * N : an iteration array for the workers For k = 1...K do: Receive gradient g i k from worker i Calculate worker i's current delay

τ k ← k -iter[i] Update biased first moment estimate m k ← β 1 m k-1 + (1 -β 1 ) g i k τ k Update biased second moment estimate v k ← β 2 v k-1 + (1 -β 2 )(g i k ) 2 Compute bias-corrected first order moment estimate mk ← m k 1-β k 1 Compute bias-corrected second order moment estimate vk ← v k 1-β k 2 Update master's weights θ k+1 ← θ k -η k • mk √ vk + Send θ k+1 to worker i Save current iteration iter[i] ← k

Algorithm 11 Adam-Gap-Aware: master

Require: η 1 . . . η K : step lengths Require: β 1 , β 2 ∈ [0, 1): exponential decay rates for the moment estimates Initialize: m 0 ← 0, v 0 ← 0 Initialize: θ i = θ 0 : parameters for every worker For k = 1...K do: Receive gradient g i k from worker i

Calculate Gap:

G k = |θ k -θ i | C + 1 d Update biased first moment estimate m k ← β 1 m k-1 + 1-β1 G k g i k Update biased second moment estimate v k ← β 2 v k-1 + (1 -β 2 )(g i k ) 2 Compute bias-corrected first order moment estimate mk ← m k 1-β k 1 Compute bias-corrected second order moment estimate vk ← v k 1-β k 2 Update master's weights θ k+1 ← θ k -η k • mk √ vk +

Send θ k+1 to worker i Save worker i's given parameters θ i ← θ k+1

C.2 DATASETS & MODELS:

CIFAR The CIFAR-10 (Krizhevsky, 2012) dataset comprises 60K RGB images partitioned into 50K training images and 10K test images. Each image contains 32x32 RGB pixels and belongs to 1 of 10 equal-sized classes. CIFAR-100 is similar but has 100 classes. Link.

ImageNet The ImageNet dataset (Russakovsky et al., 2015) , known as ILSVRC2012, consists of RGB images, each labeled as one of 1000 classes. The images are partitioned into 1.28 million training images and 50K validation images; each image is randomly cropped and re-sized to 224x224

(1-crop validation). Link.

WikiText-103:

The WikiText language modeling dataset is a collection of over 100 million tokens extracted from the set of verified Good and Featured articles on Wikipedia. Compared to the preprocessed version of Penn Treebank (PTB), WikiText-103 is over 110 times larger. The WikiText dataset also features a far larger vocabulary and retains the original case, punctuation, and numbers (Merity et al., 2016) . Link.

Transformer-XL The WikiText-103 dataset is trained on the Transformer-XL model (Dai et al., 2019) . The hyperparameters are the ones suggested in the original paper (also see Appendix C.4) and the implementation is taken from their repository. Link.

C.3 GAMMA DISTRIBUTION Ali et al. (2000) suggest a method called CVB to simulate the run-time of a distributive network of computers. The method is based on several definitions: Definition 2. Task execution time variables:

• µ task -mean time of tasks • V task -variance of tasks • µ mach -mean computation power of machines • V mach -variance of computation power of machines

• α task = 1 V 2 task • α mach = 1 V 2 mach G(α, β

) is a random number generated using a gamma distribution, where α is the shape and β is the scale.

For our case, all tasks are similar and run on a batch size of B. Therefore, the algorithm for deciding the execution-time of every task on a certain machine is reduced to one of the following:

Algorithm 12 Task execution time -homogeneous machines

β task = µ task α task q = G(α task , β task ) β mach = q α mach for i from 0 to K -1: time = G(α mach , β mach )

Algorithm 13 Task execution time -heterogeneous machines

β mach = µ mach α mach for j from 0 to M : p[j] = G(α mach , β mach ) β task [j] = p[j] α task for i from 0 to K -1: time = G(α task , β task [curr])

where K is the total amount of tasks of all the machines combined (the total number of batch iterations), M is the total number of machines (workers), and curr is the machine currently about to run.

We note that Algorithms 12 and 13 naturally give rise to stragglers. In the homogeneous algorithm, all workers have the same mean execution time but some tasks can still be very slow; this generally means that in every epoch a different machine will be the slowest. In the heterogeneous algorithm, every machine has a different mean execution time throughout the training. We further note that p[j] is the mean execution time of machine j on the average task.

In our experiments, we simulated execution times using the following parameters as suggested by Ali et al. (2000) :

µ task = µ mach = B • V 2 mach ,

where B is the batch size, yielding a mean execution time of µ simulated time units, which is proportionate to B. In the homogeneous setting V mach = 0.1, whereas in the heterogeneous setting V mach = 0.6. For both settings, V task = 0.1. [4, 8, 16, 24, 32] . All sub-figures are equally scaled to easily compare between them. GA penalizes the stale gradient much less than SA. DANA-GA penalizes the stale gradients even less than GA thanks to its approximation. DANA uses an approximation of the master's parameters at the time of the future update, thus mitigating the staleness of the incoming gradients. This mitigation also reduces the Gap, as shown in Figure 4 (a), which reduces the needed penalization when using DANA-GA.

C.9 GAP VERSIONS We tested three different Gap variations (See Section 5.3) to determine which technique has the best performance. The variations were tested on three different frameworks:

• CIFAR10 using ResNet-20 gradient staleness noise that a framework can "tolerate" and still perform well. Following this intuition, it is reasonable that some gradient staleness should be allowed to go "un-penalized" to avoid limiting the step-size needlessly. This idea explains why SA and GA demonstrated relatively poor results in ImageNet, especially when the number of workers was relatively small. Though we consider this analysis beyond the scope of this work, it is relevant for this paper to note that we think that the tolerable gradient staleness noise depends on the size of the model and dataset, which suggests that GA can be further improved by correctly analysing the tolerable gradient staleness noise and starting the penalization accordingly. We plan to continue our research in this path as well.

•

D ASYNCHRONOUS SPEEDUP:

Cloud computing is becoming increasingly popular as a platform to perform distributed training of deep neural networks. Although synchronous SGD is currently the primary method (Mikami et al., 2018; Ying et al., 2018; Yamazaki et al., 2019; Goyal et al., 2017) used to distribute the learning process, it suffers from substantial slowdowns when run in non-dedicated environments such as the cloud. This shortcoming is magnified in heterogeneous environments and non-dedicated networks. ASGD addresses the SSGD drawback and enjoys linear speedup in terms of the number of workers in both heterogeneous and homogeneous environments even in non-dedicated networks. This makes ASGD a potentially better alternative for cloud computing.

Figure 12 (a) shows the theoretically achievable speedup, based on the detailed gamma-distributed model, for asynchronous (GA and other ASGD variants) and synchronous algorithms using homogeneous and heterogeneous workers. The asynchronous algorithms can achieve linear speedup while the synchronous algorithm (SSGD) falls short as we increase the number of workers. This occurs because SSGD must wait in each iteration until all workers complete their batch. Figure 12 (b) shows that ASGD-based algorithms (including GA, SA and DANA versions) are up to 21% faster than SSGD in homogeneous environments. In heterogeneous environments, ASGD methods can be 6x faster than SSGD. We note that this speedup is an underestimate, since our simulation includes only batch execution times. It does not model the execution time of barriers, all-gather operations, and other overheads which usually increase communication time, especially in SSGD.

:

We consider the version of momentum without dampening

A framework is a unique combination of dataset and model. See full experiment in Appendix C.9.

A worker is a machine with one or more accelerators (i.e., GPU). ASGD methods treat each machine with multiple accelerators, all working synchronously locally, as a single worker.

Figures and Tables:

Figure 1: Final test and train error for different numbers of asynchronous workers N . The figure shows the average (bold line) and standard deviation (band) of 5 runs on the CIFAR10 dataset using the WideResNet model. The black dashed line is the SGD error using a single worker.

Figure 2: Final test error for different numbers of asynchronous workers N . Each line in the figure represents the average (bold line) and standard deviation (band) of 5 runs on a specific framework. The black dashed line represents the average result of SGD using a single worker.

• DANA: DANA (Algorithm 6) as described in Appendix C.1. • DANA-SA: DANA-Staleness-Aware (Algorithm 7) as described in Appendix C.1. • DANA-GA: DANA-Gap-Aware (Algorithm 8) as described in Appendix C.1. • Adam: Adam (Algorithm 9) as described in Appendix C.1. • Adam-SA: Adam-Staleness-Aware (Algorithm 10) as described in Appendix C.1. • Adam-GA: Adam-Gap-Aware (Algorithm 11) as described in Appendix C.1.

j=1 v j to worker i Algorithm 7 DANA-Staleness-Aware: master Initialize an iteration array for the workers: iter = [0] * N For k = 1...K do:

Figure3illustrates the differences between the homogeneous and heterogeneous gamma-distribution. Both environments have the same mean (128) but the probability of having an iteration that is at

Figure4shows the average Gap and Delay (τ ) for every epoch throughout the training process. The Gap (Figure4(b)) is constantly lower than the Delay (Figure4(c)), especially towards the end of the training where the learning rate is small (which decreases the distance between the master's and worker's parameters). This figure illustrates how penalizing according to the Delay, as in Staleness-Aware, can easily over-penalize when the number of workers is large.

Figure 11: Test Accuracy of ASGD using 32 asynchronous workers on CIFAR10 WideResNet 16-4 using different learning rate and momentum coefficients. The best accuracy achieved is 71.07% (η = 0.3, γ = -0.5). The tuning includes negative values of momentum

• • • , M }. F (θ; ξ) is the stochastic loss function with respect to the training sample indexed by ξ. SGD is commonly the workhorse behind the optimization of deep neural networks. Denoting η as the learning rate and k as the step number, SGD's iterative update rule is:

Table content: <table/>

Test accuracy on different frameworks a . N=32.

Table content: <table><tr><td colspan="2">Framework Tuned ASGD</td><td>GA</td><td>DANA-GA</td></tr><tr><td>C10 R</td><td>88%</td><td>87.9%</td><td>91.1%</td></tr><tr><td>C10 WR</td><td>91.6%</td><td>92.3%</td><td>94.3%</td></tr><tr><td>C100 WR</td><td>71.1%</td><td>70.6%</td><td>74.3%</td></tr><tr><td colspan="4">a C10/C100=CIFAR10/100, R=ResNet, WR=WideResNet.</td></tr></table>

Final test perplexity using Transformer-XL on WikiText-103. (Baseline 24.25. Lower is better).

Table content: <table><tr><td>N</td><td>Adam</td><td colspan="2">Adam-SA Adam-GA</td></tr><tr><td colspan="2">4 1644.76</td><td>1210.8</td><td>26.48</td></tr><tr><td colspan="2">8 1603.01</td><td>1129.9</td><td>28.7</td></tr></table>

ResNet-50 ImageNet final test accuracy (Baseline 75.64%)

Table content: <table><tr><td>N</td><td colspan="2">ASGD NAG-ASGD</td><td>SA</td><td>GA</td><td colspan="3">DANA DANA-SA DANA-GA</td></tr><tr><td colspan="2">32 70.53%</td><td>70.64%</td><td colspan="3">61.73% 70.27% 74.89%</td><td>65.66%</td><td>75.06%</td></tr><tr><td colspan="2">48 69.05%</td><td>66.78%</td><td colspan="3">56.22% 67.75% 73.75%</td><td>61.16%</td><td>74.23%</td></tr><tr><td>64</td><td>67.1%</td><td>59.81%</td><td colspan="3">50.79% 64.78% 69.88%</td><td>56.98%</td><td>74.11%</td></tr><tr><td>128</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>NaN</td><td>72.18%</td></tr></table>

Calculate workeri's current delay τ k ← k -iter[i] Update momentum v k+1 ← γv k + Update master's weights θ k+1 ← θ k -η k • v k+1 Send θ k+1 to worker i Save current iteration iter[i] ← k Update worker's momentum v i ← γv i + g i

Table content: <table><tr><td>Algorithm 6 DANA: master</td></tr><tr><td>For k = 1...K do:</td></tr><tr><td>Receive gradient g i k from worker i</td></tr><tr><td>k</td></tr><tr><td>Update master's weights θ k+1</td></tr><tr><td>Algorithm 5 Staleness-Aware-Gradient: master</td></tr><tr><td>Initialize an iteration array: iter = [0]  *  N</td></tr><tr><td>For k = 1...K do:</td></tr><tr><td>Receive gradient g i k from worker i</td></tr><tr><td>g i k</td></tr><tr><td>τ k</td></tr></table>

WideResNet 16-4 CIFAR100 Final Test Accuracy (Baseline 76.72%)

Table content: <table><tr><td>N</td><td>SA</td><td>DANA-SA NAG-ASGD</td><td>GA</td><td>ASGD</td><td>DANA</td><td>DANA-GA</td></tr></table>

Peer review (iclr2020):
This paper proposes a simple idea to mitigate gradient staleness in asynchronized distributed systems. Instead of scaling the staleness as in SA method, the authors propose to scale with the GAP, which is defined as the distance between current parameter and the staled parameter. The paper is fairly well written, and the overall idea is interesting and simple in implementation. The authors also derive convergence bounds for the proposed algorithm and provide reasonable experimental results. I have the following comments: 1. I think the theory, at the current stage, is not sufficient. The authors only provide a convergence bound for the proposed method, which does not tell anything about the advantages over other methods such as the ASGD and SA methods. I think a detailed comparison should be conducted. From the current presentation, it seems there is no theoretical advantages of the proposed method over existing methods, which seems to suggest that the empirical advantage might not come from the algorithm itself. I also notice that comparisons of convergence are illustrated in the appendix. However, it shows all SA and GA have similar convergence rates. This seems to indicate that SA and GA should performed similarly, which is not the case in the experiments. 2. For experimental results, in Figure 2 (and others), how do you get the errors for different workers? I mean, how long do you need to run for each case? You should make sure that all the settings should use the same computational resources for fair comparisons, but this is not described in the text, making the results doubtable.