Deep learning with Elastic Averaging SGD
Sixin Zhang, Anna Choromanska, Yann LeCun
Introduction
One of the most challenging problems in large-scale machine learning is how to parallelize the training of large models that use a form of stochastic gradient descent (SGD) . There have been attempts to parallelize SGD-based training for large-scale deep learning models on large number of CPUs, including the Google’s Distbelief system . But practical image recognition systems consist of large-scale convolutional neural networks trained on few GPU cards sitting in a single computer . The main challenge is to devise parallel SGD algorithms to train large-scale deep learning models that yield a significant speedup when run on multiple GPU cards.
In this paper we introduce the Elastic Averaging SGD method (EASGD) and its variants. EASGD is motivated by quadratic penalty method , but is re-interpreted as a parallelized extension of the averaging SGD algorithm . The basic idea is to let each worker maintain its own local parameter, and the communication and coordination of work among the local workers is based on an elastic force which links the parameters they compute with a center variable stored by the master. The center variable is updated as a moving average where the average is taken in time and also in space over the parameters computed by local workers. The main contribution of this paper is a new algorithm that provides fast convergent minimization while outperforming DOWNPOUR method and other baseline approaches in practice. Simultaneously it reduces the communication overhead between the master and the local workers while at the same time it maintains high-quality performance measured by the test error. The new algorithm applies to deep learning settings such as parallelized training of convolutional neural networks.
The article is organized as follows. Section 2 explains the problem setting, Section 3 presents the synchronous EASGD algorithm and its asynchronous and momentum-based variants, Section 4 provides stability analysis of EASGD and ADMM in the round-robin scheme, Section 5 shows experimental results and Section 6 concludes. The Supplement contains additional material including additional theoretical analysis.
Problem setting
EASGD update rule
The communication period controls the frequency of the communication between every local worker and the master, and thus the trade-off between exploration and exploitation.
2 Momentum EASGD
The momentum EASGD (EAMSGD) is a variant of our Algorithm 1 and is captured in Algorithm 2. It is based on the Nesterov’s momentum scheme , where the update of the local worker of the form captured in Equation 3 is replaced by the following update
where is the momentum term. Note that when we recover the original EASGD algorithm.
As we are interested in reducing the communication overhead in the parallel computing environment where the parameter vector is very large, we will be exploring in the experimental section the asynchronous EASGD algorithm and its momentum-based variant in the relatively large regime (less frequent communication).
Stability analysis of EASGD and ADMM in the round-robin scheme
In this section we study the stability of the asynchronous EASGD and ADMM methods in the round-robin scheme . We first state the updates of both algorithms in this setting, and then we study their stability. We will show that in the one-dimensional quadratic case, ADMM algorithm can exhibit chaotic behavior, leading to exponential divergence. The analytic condition for the ADMM algorithm to be stable is still unknown, while for the EASGD algorithm it is very simpleThis condition resembles the stability condition for the synchronous EASGD algorithm (Condition 23 for ) in the analysis in the Supplement..
The analysis of the synchronous EASGD algorithm, including its convergence rate, and its averaging property, in the quadratic and strongly convex case, is deferred to the Supplement.
In our setting, the ADMM method involves solving the following minimax problemThe convergence analysis in is based on the assumption that “At any master iteration, updates from the workers have the same probability of arriving at the master.”, which is not satisfied in the round-robin scheme.,
where ’s are the Lagrangian multipliers. The resulting updates of the ADMM algorithm in the round-robin scheme are given next. Let be a global clock. At each , we linearize the function with as in . The updates become
The EASGD algorithm in the round-robin scheme is defined similarly and is given below
At time , only the -th local worker (whose index equals modulo ) is activated, and performs the update in Equations 18 which is followed by the master update given in Equation 19.
For each of the linear maps, it’s possible to find a simple condition such that each map, where the map has the form , is stable (the absolute value of the eigenvalues of the map are smaller or equal to one). However, when these non-symmetric maps are composed one after another as follows , the resulting map can become unstable! (more precisely, some eigenvalues of the map can sit outside the unit circle in the complex plane).
We now present the numerical conditions for which the ADMM algorithm becomes unstable in the round-robin scheme for and , by computing the largest absolute eigenvalue of the map . Figure 1 summarizes the obtained result.
For the composite map to be stable, the condition that needs to be satisfied is actually the same for each , and is furthermore independent of (since each linear map is symmetric). It essentially involves the stability of the matrix \left(\begin{array}[]{cc}1-\eta-\alpha&\alpha\\ \alpha&1-\alpha\end{array}\right), whose two (real) eigenvalues satisfy . The resulting stability condition () is simple and given as .
Experiments
In this section we compare the performance of EASGD and EAMSGD with the parallel method DOWNPOUR and the sequential method SGD, as well as their averaging and momentum variants.
All the parallel comparator methods are listed belowWe have compared asynchronous ADMM with EASGD in our setting as well, the performance is nearly the same. However, ADMM’s momentum variant is not as stable for large communication periods.:
DOWNPOUR , the pseudo-code of the implementation of DOWNPOUR used in this paper is enclosed in the Supplement.
Momentum DOWNPOUR (MDOWNPOUR), where the Nesterov’s momentum scheme is applied to the master’s update (note it is unclear how to apply it to the local workers or for the case when ). The pseudo-code is in the Supplement.
All the sequential comparator methods () are listed below:
Momentum SGD (MSGD) with constant momentum .
ASGD with moving rate .
MVASGD with moving rate set to a constant.
We perform experiments in a deep learning setting on two benchmark datasets: CIFAR-10 (we refer to it as CIFAR) Downloaded from http://www.cs.toronto.edu/~kriz/cifar.html. and ImageNet ILSVRC 2013 (we refer to it as ImageNet) Downloaded from http://image-net.org/challenges/LSVRC/2013.. We focus on the image classification task with deep convolutional neural networks. We next explain the experimental setup. The details of the data preprocessing and prefetching are deferred to the Supplement.
For all our experiments we use a GPU-cluster interconnected with InfiniBand. Each node has Titan GPU processors where each local worker corresponds to one GPU processor. The center variable of the master is stored and updated on the centralized parameter server Our implementation is available at https://github.com/sixin-zh/mpiT..
To describe the architecture of the convolutional neural network, we will first introduce a notation. Let denotes the size of the input image to each layer, where is the number of color channels and is both the horizontal and the vertical dimension of the input. Let denotes the fully-connected convolutional operator and let denotes the max pooling operator, denotes the linear operator with dropout rate equal to and denotes the linear operator with softmax output non-linearity. We use the cross-entropy loss and all inner layers use rectified linear units. For the ImageNet experiment we use the similar approach to with the following -layer convolutional neural network (3,221)C(96,108)P(96,36)C(256,32)P(256,16)C(384,14) C(384,13)C(256,12)P(256,6)D(4096,1)D(4096,1)S(1000,1). For the CIFAR experiment we use the similar approach to with the following -layer convolutional neural network (3,28)C(64,24)P(64,12)C(128,8)P(128,4)C(64,2)D(256,1)S(10,1).
In our experiments all the methods we run use the same initial parameter chosen randomly, except that we set all the biases to zero for CIFAR case and to 0.1 for ImageNet case. This parameter is used to initialize the master and all the local workersOn the contrary, initializing the local workers and the master with different random seeds ’traps’ the algorithm in the symmetry breaking phase.. We add -regularization to the loss function . For ImageNet we use and for CIFAR we use . We also compute the stochastic gradient using mini-batches of sample size .
2 Experimental results
For all experiments in this section we use EASGD with Intuitively the ’effective ’ is (thus ) in the asynchronous setting. , for all momentum-based methods we set the momentum term and finally for MVADOWNPOUR we set the moving rate to . We start with the experiment on CIFAR dataset with local workers running on a single computing node. For all the methods, we examined the communication periods from the following set . For comparison we also report the performance of MSGD which outperformed SGD, ASGD and MVASGD as shown in Figure 6 in the Supplement. For each method we examined a wide range of learning rates (the learning rates explored in all experiments are summarized in Table 1, 2, 3 in the Supplement). The CIFAR experiment was run times independently from the same initialization and for each method we report its best performance measured by the smallest achievable test error.
From the results in Figure 2, we conclude that all DOWNPOUR-based methods achieve their best performance (test error) for small (), and become highly unstable for . While EAMSGD significantly outperforms comparator methods for all values of by having faster convergence. It also finds better-quality solution measured by the test error and this advantage becomes more significant for . Note that the tendency to achieve better test performance with larger is also characteristic for the EASGD algorithm.
We next explore different number of local workers from the set for the CIFAR experiment, and for the ImageNet experimentFor the ImageNet experiment, the training loss is measured on a subset of the training data of size 50,000.. For the ImageNet experiment we report the results of one run with the best setting we have found. EASGD and EAMSGD were run with whereas DOWNPOUR and MDOWNPOUR were run with . The results are in Figure 3 and 4. For the CIFAR experiment, it’s noticeable that the lowest achievable test error by either EASGD or EAMSGD decreases with larger . This can potentially be explained by the fact that larger allows for more exploration of the parameter space. In the Supplement, we discuss further the trade-off between exploration and exploitation as a function of the learning rate (section 9.5) and the communication period (section 9.6). Finally, the results obtained for the ImageNet experiment also shows the advantage of EAMSGD over the competitor methods.
Conclusion
In this paper we describe a new algorithm called EASGD and its variants for training deep neural networks in the stochastic setting when the computations are parallelized over multiple GPUs. Experiments demonstrate that this new algorithm quickly achieves improvement in test error compared to more common baseline approaches such as DOWNPOUR and its variants. We show that our approach is very stable and plausible under communication constraints. We provide the stability analysis of the asynchronous EASGD in the round-robin scheme, and show the theoretical advantage of the method over ADMM. The different behavior of the EASGD algorithm from its momentum-based variant EAMSGD is intriguing and will be studied in future works.
The authors thank R. Power, J. Li for implementation guidance, J. Bruna, O. Henaff, C. Farabet, A. Szlam, Y. Bakhtin for helpful discussion, P. L. Combettes, S. Bengio and the referees for valuable feedback.
References
Additional theoretical results and proofs
We provide here the convergence analysis of the synchronous EASGD algorithm with constant learning rate. The analysis is focused on the convergence of the center variable to the local optimum. We discuss one-dimensional quadratic case first, then the generalization to multi-dimensional setting (Lemma 7.3) and finally to the strongly convex case (Theorem 7.1).
It follows from Lemma 7.1 that for the center variable to be stable the following has to hold
It can be verified that and are the two zero-roots of the polynomial in : . Recall that and are the functions of and . Thus (see proof in Section 7.1.2)
iff (i.e. and ).
iff and .
iff (i.e. ).
The proof the above Lemma is based on the diagonalization of the linear gradient map (this map is symmetric due to the relation ). The stability analysis of the asynchronous EASGD algorithm in the round-robin scheme is similar due to this elastic symmetry.
Substituting the gradient from Equation 20 into the update rule used by each local worker in the synchronous EASGD algorithm (Equation 5 and 6) we obtain
where is the learning rate, and is the moving rate. Recall that and .
and the (diffusion) vector .
By combining Equation 25 and 26 as follows
where the last step results from the following relations: and . Thus we obtained
Substituting , each given through Equation 28, into Equation 29 we obtain
To be more specific, the Equation 30 is obtained by integrating by parts,
Since the random variables are i.i.d, we may sum the variance term by term as follows
1.2 Condition in Equation 23
iff (i.e. and ).
iff and .
iff (i.e. ).
Recall that , , , , and . We have
.
.
.
The next corollary is a consequence of Lemma 7.1. As the number of workers grows, the averaging property of the EASGD can be characterized as follows
Let the Elastic Averaging relation and the condition 23 hold, then
Note that when is fixed, and . Then and . Also note that using Lemma 7.1 we obtain
Corollary 7.1 is obtained by plugining in the limiting values of and . ∎
The crucial point of Corollary 7.1 is that the MSE in the limit is in the order of which implies that as the number of processors grows, the MSE will decrease for the EASGD algorithm. Also note that the smaller the is (recall that ), the more exploration is allowed (small ) and simultaneously the smaller the MSE is.
2 Generalization to multidimensional case
The next lemma (Lemma 7.2) shows that EASGD algorithm achieves the highest possible rate of convergence when we consider the double averaging sequence (similarly to ) defined as below
If the condition in Equation 23 holds, then the normalized double averaging sequence defined in Equation 32 converges weakly to the normal distribution with zero mean and variance ,
Also recall that ’s are i.i.d. random variables (noise) with zero mean and the same covariance . We are interested in the asymptotic behavior of the double averaging sequence defined as
Recall the Equation 30 from the proof of Lemma 7.1 (for the convenience it is provided below):
where . Therefore
Therefore the expression in Equation 35 is asymptotically normal with zero mean and variance . ∎
The asymptotic variance in the Lemma 7.2 is optimal with any fixed and for which Equation 23 holds. The next lemma (Lemma 7.3) extends the result in Lemma 7.2 to the multi-dimensional setting.
Let denotes the largest eigenvalue of . If , , and , then the normalized double averaging sequence converges weakly to the normal distribution with zero mean and the covariance matrix ,
Let the spatial average of the local parameters at time be denoted as where , and let the average noise be denoted as , where . Equations 24 and 25 can then be reduced to the following
From Equations 37 and 38 it follows that . Note that this linear system has a degenerate noise which prevents us from directly applying results of . Expanding this recursive relation and summing by parts, we have
Note that the only non-vanishing term (in weak convergence) of is thus we have
The eigenvalue of and the (non-zero) eigenvector of satisfy
Since is assumed to be non-zero, we can write . Then the Equation 50 can be reduced to
Thus is the eigenvector of . Let be the eigenvalue of matrix such that . Thus based on Equation 51 it follows that
where , . It follows from the condition in Equation 23 that iff , , and . Let denote the maximum eigenvalue of and note that . This implies that the condition of our lemma is sufficient. ∎
As in Lemma 7.2, the asymptotic covariance in the Lemma 7.3 is optimal, i.e. meets the Fisher information lower-bound. The fact that this asymptotic covariance matrix does not contain any term involving is quite remarkable, since the penalty term does have an impact on the condition number of the Hessian in Equation 2.
3 Strongly convex case
We have thus the update for the spatial average,
From Equation 54 the following relation holds,
By the cosine rule (), we have
By the Cauchy-Schwarz inequality, we have
Combining the above estimates in Equations 57, 58, 59, 60, we obtain
Now we apply similar idea to estimate . From Equation 56 the following relation holds,
By , we have
Denote , we can rewrite Equation 65 as
By combining the above Equations 66, 67 with 68, we obtain
Thus it follows from Equation 57 and 70 that
Recall , we have the following bias-variance relation,
By the Cauchy-Schwarz inequality, we have
Combining the above estimates in Equations 71, 72, 73, we obtain
Since , we need also bound the non-linear term . Recall the bias-variance relation . The key observation is that if remains bounded, then larger variance implies smaller bias . Thus this non-linear term can be compensated.
Again choose small enough such that and take expectation in Equation 75,
As for the center variable in Equation 55, we apply simply the convexity of the norm to obtain
as long as , and , i.e. ∎
Additional pseudo-codes of the algorithms
Algorithm 3 captures the pseudo-code of the implementation of the DOWNPOUR used in this paper.
2 MDOWNPOUR pseudo-code
Algorithms 4 and 5 capture the pseudo-codes of the implementation of momentum DOWNPOUR (MDOWNPOUR) used in this paper. Algorithm 4 shows the behavior of each local worker and Algorithm 5 shows the behavior of the master.
Experiments - additional material
For the ImageNet experiment, we re-size each RGB image so that the smallest dimension is pixels. We also re-scale each pixel value to the interval $3\times 221\times 221128$.
For the CIFAR experiment, we use the original RGB image of size . As before, we re-scale each pixel value to the interval $3\times 28\times 28128$.
The training and test loss and the test error are only computed from the center patch () for the CIFAR experiment and the center patch () for the ImageNet experiment.
2 Data prefetching (Sampling the dataset by the local workers)
We will now explain precisely how the dataset is sampled by each local worker as uniformly and efficiently as possible. The general parallel data loading scheme on a single machine is as follows: we use CPUs, where , to load the data in parallel. Each data loader reads from the memory-mapped (mmap) file a chunk of raw images (preprocessing was described in the previous subsection) and their labels (for CIFAR and for ImageNet ). For the CIFAR, the mmap file of each data loader contains the entire dataset whereas for ImageNet, each mmap file of each data loader contains different fractions of the entire dataset. A chunk of data is always sent by one of the data loaders to the first worker who requests the data. The next worker requesting the data from the same data loader will get the next chunk. Each worker requests in total data chunks from different data loaders and then process them before asking for new data chunks. Notice that each data loader cycles through the data in the mmap file, sending consecutive chunks to the workers in order in which it receives requests from them. When the data loader reaches the end of the mmap file, it selects the address in memory uniformly at random from the interval , where , and uses this address to start cycling again through the data in the mmap file. After the local worker receives the data chunks from the data loaders, it shuffles them and divides it into mini-batches of size .
3 Learning rates
In Table 1 we summarize the learning rates (we used constant learning rates) explored for each method shown in Figure 2. For all values of the same set of learning rates was explored for each method.
In Table 2 we summarize the learning rates (we used constant learning rates) explored for each method shown in Figure 3. For all values of the same set of learning rates was explored for each method.
In Table 3 we summarize the initial learning rates we use for each method shown in Figure 4. For all values of the same set of learning rates was explored for each method. We also used the rule of the thumb to decrease the initial learning rate twice, first time we divided it by and the second time by , when we observed that the decrease of the online predictive (training) loss saturates.
4 Comparison of SGD, ASGD, MVASGD and MSGD
Figure 6 shows the convergence of the training and test loss (negative log-likelihood) and the test error computed for the center variable as a function of wallclock time for SGD, ASGD, MVASGD and MSGD () on the CIFAR experiment. For all CIFAR experiments we always start the averaging for the and methods from the very beginning of each experiment. For all ImageNet experiments we start the averaging for the at the same time when we first reduce the initial learning rate.
Figure 7 shows the convergence of the training and test loss (negative log-likelihood) and the test error computed for the center variable as a function of wallclock time for SGD, ASGD, MVASGD and MSGD () on the ImageNet experiment.
5 Dependence of the learning rate
This section discusses the dependence of the trade-off between exploration and exploitation on the learning rate. We compare the performance of respectively EAMSGD and EASGD for different learning rates when and on the CIFAR experiment. We observe in Figure 8 that higher learning rates lead to better test performance for the EAMSGD algorithm which potentially can be justified by the fact that they sustain higher fluctuations of the local workers. We conjecture that higher fluctuations lead to more exploration and simultaneously they also impose higher regularization. This picture however seems to be opposite for the EASGD algorithm for which larger learning rates hurt the performance of the method and lead to overfitting. Interestingly in this experiment for both EASGD and EAMSGD algorithm, the learning rate for which the best training performance was achieved simultaneously led to the worst test performance.
6 Dependence of the communication period
This section discusses the dependence of the trade-off between exploration and exploitation on the communication period. We have observed from the CIFAR experiment that EASGD algorithm exhibits very similar convergence behavior when up to even , whereas EAMSGD can get trapped at worse energy (loss) level for . This behavior of EAMSGD is most likely due to the non-convexity of the objective function. Luckily, it can be avoided by gradually decreasing the learning rate, i.e. increasing the penalty term (recall ), as shown in Figure 9. In contrast, the EASGD algorithm does not seem to get trapped at all along its trajectory. The performance of EASGD is less sensitive to increasing the communication period compared to EAMSGD, whereas for the EAMSGD the careful choice of the learning rate for large communication periods seems crucial.
Compared to all earlier results, the experiment in this section is re-run three times with a new randomTo clarify, the random initialization we use is by default in Torch’s implementation. seed and with faster cuDNNhttps://developer.nvidia.com/cuDNN packagehttps://github.com/soumith/cudnn.torch. All our methods are implemented in Torchhttp://torch.ch. The Message Passing Interface implementation MVAPICH2http://mvapich.cse.ohio-state.edu is used for the GPU-CPU communication.
7 Breakdown of the wallclock time
In addition, we report in Table 4 the breakdown of the total running time for EASGD when (the time breakdown for EAMSGD is almost identical) and DOWNPOUR when into computation time, data loading time and parameter communication time. For the CIFAR experiment the reported time corresponds to processing data samples whereas for the ImageNet experiment it corresponds to processing data samples. For and we observe that the communication time accounts for significant portion of the total running time whereas for the communication time becomes negligible compared to the total running time (recall that based on previous results EASGD and EAMSGD achieve best performance with larger which is ideal in the setting when communication is time-consuming).
8 Time speed-up
In Figure 10 and 11, we summarize the wall clock time needed to achieve the same level of the test error for all the methods in the CIFAR and ImageNet experiment as a function of the number of local workers . For the CIFAR (Figure 10) we examined the following levels: and for the ImageNet (Figure 11) we examined: . If some method does not appear on the figure for a given test error level, it indicates that this method never achieved this level. For the CIFAR experiment we observe that from among EASGD, DOWNPOUR and MDOWNPOUR methods, the EASGD method needs less time to achieve a particular level of test error. We observe that with higher each of these methods does not necessarily need less time to achieve the same level of test error. This seems counter intuitive though recall that the learning rate for the methods is selected based on the smallest achievable test error. For larger smaller learning rates were selected than for smaller which explains our results. Meanwhile, the EAMSGD method achieves significant speed-up over other methods for all the test error levels. For the ImageNet experiment we observe that all methods outperform MSGD and furthermore with or each of these methods requires less time to achieve the same level of test error. The EAMSGD consistently needs less time than any other method, in particular DOWNPOUR, to achieve any of the test error levels.