D ON ’ T U SE L ARGE M INI -B ATCHES , U SE L OCAL SGD
kumarkshitijpatel@gmail
A BSTRACT
Mini-batch stochastic gradient methods (SGD) are state of the art for distributed training of deep neural networks.
Drastic increases in the mini-batch sizes have lead to key efﬁciency and scalability gains in recent years.
However, progress faces a major roadblock, as models trained with large batches often do not generalize well, i.e. they do not show good accuracy on new data.
As a remedy, we propose a post-local SGD and show that it signiﬁcantly improves the generalization performance compared to large-batch training on standard benchmarks while enjoying the same efﬁciency (time-to-accuracy) and scalability.
We further provide an extensive study of the communication efﬁciency vs. performance trade-offs associated with a host of local SGD variants.
I NTRODUCTION
Fast and efﬁcient training of large scale deep-learning models relies on distributed hardware and on distributed optimization algorithms.
For efﬁcient use of system resources, these algorithms crucially must (i) enable parallelization while being communication efﬁcient, and (ii) exhibit good generalization behaviour, i.e. good performance on unseen data (test-set).
Most machine learning applications currently depend on stochastic gradient descent (SGD) (Robbins & Monro, 1985) and in particular its mini-batch variant (Bottou, 2010; Dekel et al., 2012).
However, this algorithm faces generalization difﬁculties in the regime of very large batch sizes as we will review now.
Mini-batch SGD.
For a sum-structured optimization problem of the form min w P R d 1 N (cid:176)
Ni (cid:16) 1 f i p w q where w P R d denotes the parameters of the model and f i : R d (cid:209) R the loss function of the i -th training example, the mini-batch SGD update for K ¥ 1 workers is given as
[Equation]
where γ p t q ¡ 0 denotes the learning rate and I k p t q (cid:132) r N s the subset (mini-batch) of training datapoints selected by worker k (typically selected uniformly at random from the locally available datapoints on worker k ).
For convenience, we will assume the same batch size B per worker.
Local SGD.
Motivated to better balance the available system resources (computation vs. communication), local SGD (a.k.a.
local-update SGD, parallel SGD, or federated averaging) has recently attracted increased research interest (Mcdonald et al., 2009; Zinkevich et al., 2010;
McDonald et al., 2010; Zhang et al., 2014; 2016; McMahan et al., 2017).
In local SGD, each worker k P r K s evolves a local model by performing H sequential SGD updates with mini-batch size B loc , before communication (synchronization by averaging) among the workers.
Formally,
[Equation]
where w k p t q(cid:0) h denotes the local model on machine k after t global synchronization rounds and subsequent h P r H s local steps ( I k p t q(cid:0) h is deﬁned analogously).
Mini-batch SGD is a special case [Figure] [Table] [Figure]
[Table]
[Figure] [Table] [Figure] [Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
if H (cid:16) 1 and B loc (cid:16) B .
Furthermore, the communication patterns of both algorithms are identical if B (cid:16) HB loc .
However, as the updates (eq. (2)) are different from the mini-batch updates (eq.
(1)) for any H ¡ 1 , the generalization behavior (test error) of both algorithms is expected to be different.
Large batch SGD.
Recent schemes for scaling training to a large number of workers rely on standard mini-batch SGD (1) with very large overall batch sizes (Shallue et al., 2018;
You et al., 2018; Goyal et al., 2017), i.e. increasing the global batch size linearly with the number of workers K .
However, the batch size interacts differently with the overall system efﬁciency on one hand, and with generalization performance on the other hand.
While a larger batch size in general increases throughput, it may negatively affect the ﬁnal accuracy on both the train- and test-set.
Two main scenarios of particular interest can be decoupled as follows:
Scenario 1.
The communication restricted setting , where the synchronization time is much higher than the gradient computation time.
In this case the batch size of best efﬁciency is typically large, and is achieved by using partial computation (gradient accumulation) while waiting for communication.
We in particular study the interesting case when the mini-batch sizes of both algorithms satisfy the relation B (cid:16) HB loc , as in this case both algorithms (local SGD and minibatch SGD) evaluate the same number of stochastic gradients between synchronization steps.
Scenario 2.
The regime of poor generalization of large-batch SGD , that is the use of very large overall batches (often a signiﬁcant fraction of the training set size), which is known to cause drastically decreased generalization performance (Chen & Huo, 2016; Keskar et al., 2017; Hoffer et al., 2017; Shallue et al., 2018;
Golmant et al., 2018).
If sticking to standard mini-batch SGD and maintaining the level of parallelisation, the batch size B would have to be reduced below the device (locally optimal) capacity in order to alleviate this generalization issue, which however impacts training time 1 .
Main Results.
Key aspects of the empirical performance of local SGD compared to mini-batch baselines are illustrated in Figure 1.
In scenario 1), comparing local SGD with H (cid:16) 4 (A4) with mini-batch SGD of same effective batch size B (cid:16) 4 B loc (A3) reveals a stark difference, both in terms of train and test error (local SGD achieves lower training loss and higher test accuracy).
This motivates the use of local SGD as an alternative to large-batch training —a hypothesis that we conﬁrm in our experiments.
Further, in scenario 2), mini-batch SGD with smaller batch size B (cid:16) B loc (A2) is observed to suffer from poor generalization, although the training curve matches the single- machine baseline (A1).
The generalization gap can thus not be explained as an optimization issue alone .
Our proposed post-local SGD (A5) (deﬁned by starting local SGD from the model obtained by large-batch SGD ( A2 ) at epoch 150 ) closes this generalization gap with the single-machine baseline (A1) and is also more communication efﬁcient than the mini-batch competitors.
In direct comparison, post-local SGD is more communication-efﬁcient than mini-batch SGD (while less than local SGD).
It achieves better generalization performance than both these algorithms.
Contributions.
Our main contributions can thus be summarized as follows:
• Trade-offs in Local SGD: We provide the ﬁrst comprehensive empirically study of the trade-offs in local SGD for deep learning—when varying the number of workers K , number of local steps H and mini-batch sizes—for both scenarios 1) on communication efﬁciency and 2) on generalization.
• Post-local SGD: We propose post-local SGD , a simple but very efﬁcient training scheme to address the current generalization issue of large-batch training.
It allows us to scale the training to much higher number of parallel devices.
Large batches trained by post-local SGD enjoy improved communication efﬁciency, while at the same time strongly outperforming most competing small and large batch baselines in terms of accuracy.
Our empirical experiments on standard benchmarks show that post-local SGD can reach ﬂatter minima than large-batch SGD on those problems.
R ELATED W ORK
The generalization gap in large-batch training.
State-of-the-art distributed deep learning frameworks (Abadi et al., 2016;
Paszke et al., 2017; Seide & Agarwal, 2016) resort to synchronized large-batch SGD training, allowing scaling by adding more computational units and performing data-parallel synchronous SGD with mini-batches divided between devices.
Training with large batch size (e.g. batch size > 10 3 on ImageNet) typically degrades the performance both in terms of training and test error (often denoted as generalization gap ) (Chen & Huo, 2016; Li, 2017; Li et al., 2014; Keskar et al., 2017; Shallue et al., 2018; McCandlish et al., 2018;
Golmant et al., 2018; Masters & Luschi, 2018).
Goyal et al.
(2017) argue that the test error degrades because of optimization issues and propose to use a “learning rate warm-up” phase with linear scaling of the step-size.
You et al.
(2017a)
propose Layer-wise Adaptive Rate Scaling (LARS) to scale to larger mini-batch size, but the generalization gap does not vanish.
Hoffer et al.
(2017) argue that the generalization gap can be closed when increasing the number of iterations along with the batch size.
However, this diminishes the efﬁciency gains of parallel training.
Keskar et al.
(2017) empirically show that larger batch sizes correlate with sharper minima (Hochreiter & Schmidhuber, 1997) found by SGD and that ﬂat minima are preferred for better generalization.
This interpretation—despite being debated in Dinh et al.
(2017)—was further developed in Hoffer et al.
; Yao et al.
Izmailov et al.
Neelakantan et al.
(2015) propose to add isotropic white noise to the gradients to avoid over-ﬁtting and better optimization.
Zhu et al.
Xing et al.
(2018) further analyze “structured” anisotropic noise and highlight the importance of anisotropic noise (over isotropic noise) for improving generalization.
The importance of the scale of the noise for non-convex optimization has also been studied in Smith & Le (2018);
Chaudhari & Soatto (2018).
Wen et al.
(2019) propose to inject noise (sampled from the expensive empirical
Fisher matrix) to large-batch SGD.
However, to our best knowledge, none of the prior work (except our post-local SGD) can provide a computation efﬁcient way to inject noise to achieve as good generalization performance as small-batch SGD, for both of CIFAR and ImageNet experiments.
Local SGD and convergence theory.
While mini-batch SGD is very well studied (Zinkevich et al., 2010; Dekel et al., 2012;
Takáˇc et al., 2013), the theoretical foundations of local SGD variants are still developing.
Jain et al.
(2018) study one-shot averaging on quadratic functions and Bijral et al.
(2016) study local SGD in the setting of a general graph of workers.
A main research question is whether local SGD provides a linear speedup with respect to the number of workers K , similar to mini-batch SGD.
Recent work partially conﬁrms this, under the assumption that H is not too large compared to the total iterations T .
Stich (2019) and Patel & Dieuleveut (2019) show convergence at rate O (cid:0) p KTHB
[Equation]
q (cid:1)(cid:8) on strongly convex and smooth objective functions when H (cid:16) O p T 1 { 2 q .
For smooth non-convex objective functions, Zhou & Cong (2018) show a rate of O (cid:0) p KTB loc q (cid:1) 1 {(cid:8) (for the decrement of the stochastic gradient), Yu et al.
(2019) give an improved result O (cid:0) p HKTB loc q (cid:1) 1 {(cid:8)
when H (cid:16)
O p T 1 { 4 q .
For a discussion of more recent theoretical results we refer to (Kairouz et al., 2019).
Alistarh et al.
(2018) study convergence under adversarial delays.
Zhang et al.
(2016) empirically study the effect of the averaging frequency on the quality of the solution for some problem cases and observe that more frequent averaging at the beginning of the optimization can help.
Similarly, Bijral et al.
(2016) argue to average more frequently at the beginning.
P OST -L OCAL SGD AND H IERARCHICAL L OCAL SGD
In this section we present two novel variants of local SGD.
First, we propose post-local SGD to reach high generalization accuracy (cf.
Section 4.2 below), and second, hierarchical SGD designed from a systems perspective aiming at optimal resource adaptivity (computation vs. communication trade-off).
Post-local SGD: Large-batch Training Alternative for Better Generalization.
We propose postlocal SGD, a variant where local SGD is only started in the second phase of training, after t 1 initial steps 2 with standard mini-batch SGD.
Formally, the update in (2) is performed with a iteration dependent H p t q given as
[Equation]
As the proposed scheme is identical to mini-batch SGD in the ﬁrst phase (with local batch size
B (cid:16) B loc ), we can leverage previously tuned learning rate warm-up strategies and schedules for large-batch training (Goyal et al., 2017) without additional tuning.
Note that we only use ‘small’ local mini-batches of size B (cid:16) B loc in the warm-up phase, and switch to the communication efﬁcient larger effective batches HB loc in the second phase, while also achieving better generalization in our experiments (cf.
also the discussion in Section 5).
We would like to point out that it is crucial to use local SGD in the second phase, as e.g. just resorting to large batch training does achieve worse performance (see e.g. 3rd row in Table 2 below).
Hierarchical Local SGD: Optimal Use of Systems Resources in Heterogeneous Systems.
Real world systems come with different communication bandwidths on several levels, e.g. with GPUs or other accelerators grouped hierarchically within a chip, machine, rack or even at the level of entire data-centers.
In this scenario, we propose to employ local SGD as an inner loop on each level of the hierarchy, adapted to the corresponding computation vs communication trade-off of that particular level.
The resulting scheme, hierarchical local SGD , can offer signiﬁcant beneﬁts in terms of system adaptivity and performance, as we show with experiments and a discussion in Appendix D.
E XPERIMENTAL R ESULTS
In this section we systematically evaluate the aforementioned variants of local SGD on deep learning tasks.
In summary, the main ﬁndings presented in Sections 4.1 and 4.2 below are:
Local SGD, on the one hand , can serve as a communication-efﬁcient alternative to mini-batch SGD for different practical purposes (communication restricted Scenario 1) .
For example in Figure 2(a) (with ﬁxed B loc and K ), in terms of 92 .
48% best test accuracy achieved by our mini-batch SGD implementation for K (cid:16) 16 , practitioners can either choose to achieve reasonable good training quality ( 91 . 2% , matching (He et al., 2016a)) with a 2 . 59 (cid:2)
speedup (time-to-accuracy) in training time ( H (cid:16) 8 ), or achieve slight better test performance ( 92 . 57% ) with slightly reduced communication efﬁciency ( 1 . 76 (cid:2) speedup for H (cid:16) 2 ).
Post-local SGD, on the other hand, in addition to overcoming communication restrictions does provide a state-of-the-art remedy for the generalization issue of large-batch training (Scenario 2).
Unlike local SGD with large H and K (e.g. H (cid:16) 16 , K (cid:16) 16 ) which can encounter optimization issues during initial training (which can impact later generalization performance), we found that post-local
SGD elegantly enables an ideal trade-off between optimization and generalization within a ﬁxed training budget (e.g. Table 3, Table 5, Figure 3 and many others in Appendix C.5), and can achieve the same or even better performance than small mini-batch baselines.
Setup.
We brieﬂy outline the general experimental setup, and refer to Appendix A for full details.
Datasets.
We evaluate all methods on the following two main (standard) tasks: (1) Image classiﬁcation for CIFAR-10/100 (Krizhevsky & Hinton, 2009), and (2) Image classiﬁcation for ImageNet (Russakovsky et al., 2015).
The detailed data augmentation scheme refers to Appendix A.
Models.
We use ResNet-20 (He et al., 2016a) with CIFAR-10 as a base conﬁguration to understand different properties of (post-)local SGD.
We then empirical evaluate the large-batch training performance of post-local SGD, for ResNet-20, DensetNet-40-12 (Huang et al., 2017b) and WideResNet28-10 (Zagoruyko & Komodakis, 2016) on CIFAR-10/100.
Finally, we train ResNet-50 (He et al., 2016a) on ImageNet to investigate the accuracy and scalability of (post-)local SGD training.
Implementation and platform.
Our algorithms are implemented 3 in PyTorch (Paszke et al., 2017), with a ﬂexible conﬁguration of the machine topology supported by Kubernetes.
The cluster consists of Intel Xeon E5-2680 v3 servers and each server has 2 NVIDIA TITAN
Xp GPUs.
We use the notion a (cid:2) b -GPU to denote the topology of the cluster, i.e., a nodes and each with b GPUs.
Speciﬁc learning schemes for large-batch SGD.
We rely on the recently proposed schemes for efﬁcient large batch training (Goyal et al., 2017), which are formalized by (i) linearly scaling the learning rate w.r.t.
the global mini-batch size; (ii) gradual warm-up of the learning rate from a small value.
See
Appendix A.3 for more details.
Distributed training procedure on CIFAR-10/100.
The experiments follow the common mini-batch
SGD training scheme for CIFAR (He et al., 2016a;b; Huang et al., 2017b) and all competing methods access the same total number of data samples (i.e. gradients)
regardless of the number of local steps.
Training ends when the distributed algorithms have accessed the same number of samples as the single-worker baseline.
The data is disjointly partitioned and reshufﬂed globally every epoch.
The learning rate scheme follows (He et al., 2016a; Huang et al., 2017b), where we drop the initial learning rate by a factor of 10 when the model has accessed 50% and 75% of the total number of training samples.
Unless mentioned speciﬁcally, the used learning rate is scaled by the global mini-batch size ( BK for mini-batch SGD and B loc K for local SGD) where the initial learning rate is ﬁne-tuned for each model and each task for the single worker.
See Appendix A.4 for more details.
4. S UPERIOR S CALABILITY OF L OCAL SGD OVER MINI - BATCH SGD
First, we empirically study local SGD training for the communication restricted case (i.e. Scenario 1).
As local SGD (with local batch size B loc ) needs H times fewer communication rounds than minibatch SGD (with the same batch size B (cid:16) B loc q we expect local SGD to signiﬁcantly outperform mini-batch SGD in terms of time-to-accuracy and scalability and verify this experimentally.
We further observe that local SGD shows better generalization performance than mini-batch SGD.
Signiﬁcantly better scalability when increasing the number of workers on CIFAR, in terms of time-to-accuracy.
Figure 1 demonstrates the speedup in time-to-accuracy for training ResNetfor CIFAR-10, with varying number of GPUs K and the number of local steps H , both from 1 to 16 .
[Figure]
[Table]
d u p w .
r .
t .
t i m e - t o - a cc u r a c y
[Table]
[Table]
[Table]
[Table] [Table] [Table] We demonstrate in Figure 1 that local SGD scales 2 (cid:2) better than its mini-batch SGD counterpart, in terms of time-to-accuracy as we increase the number of workers K on a commodity cluster.
The local update steps ( H ) result in a strong advantage over the standard large-batch training.
Mini-batch
SGD ﬁxes the batch size to B (cid:16) B loc , and while increasing the number of workers K gets impacted by the communication bottleneck (section 1), even as parallelism per device remains unchanged.
In this experiment, local SGD on 8 GPUs even achieves a 2 (cid:2) lower time-to-accuracy than mini-batch
SGD with 16 GPUs.
Moreover, the (near) linear scaling performance for H (cid:16) 8 in Figure 1, shows that the main hyper-parameter H of local SGD is robust and consistently different from its mini-batch counterpart, when scaling the number of workers.
Effectiveness and scalability of local SGD to even larger datasets (e.g., ImageNet) and larger clusters.
Local SGD presents a competitive alternative to the current large-batch ImageNet training methods.
Figure 8 in Appendix B.3.2 shows that we can efﬁciently train state-of-the-art ResNet- (at least 1 . 5 (cid:2) speedup to reach 75% top-1 accuracy) for ImageNet (Goyal et al., [-
 ;-]2017; You et al., 2017a) via local SGD on a 16 (cid:2) 2 -GPU cluster.
Local SGD signiﬁcantly outperforms mini-batch SGD at the same effective batch size and communication ratio.
Figure 2 compares local SGD with mini-batch SGD of the same effective batch size, that is the same number of gradient computations per communication round as described in Scenario 1 above (Section 1). [Figure] H H
[Figure]
[Figure]
[Figure]
[Figure]
4. (P OST )-L OCAL SGD CLOSES THE G ENERALIZATION G AP OF L ARGE - BATCH T RAINING
Even though local SGD has demonstrated effective communication efﬁciency with guaranteed test performance (Scenario 1), we observed in the previous section that it still encounters difﬁculties when scaling to very large mini-batches (Figure 2(a)), though it is much less affected than mini-batch SGD (Figure 2(b)).
Post-local SGD can address the generalization issue of large batch training (Scenario 2) as we show now.
First, we would like to highlight some key ﬁndings in Table
(generalization) for local SGD variants and mini-batch SGD (highlighting selected data from Figure 2, Table 3 and Figure 3).
Mini-batch SGD suffers from the generalization gap (and sometimes even from optimization issues due to insufﬁcient training) when scaling to larger H and K .
Same experimental setup as in Figure 2 (ﬁne-tuned mini-batch SGD baselines).
The ‘ (cid:209) ’ denotes the transition at the ﬁrst learning rate decay.
The reported results are averaged over three runs.
[Table]
We now focus on the generalization issues (Section 1) of large-batch SGD, isolating the potential negative impact from the optimization difﬁculty (e.g. the insufﬁcient training epochs (Shallue et al., 2018)) from the performance on the test set.
Our evaluation starts from a (standard) constant effective mini-batch size of 2048 or 4096 for mini-batch SGD 4 on CIFAR dataset, as in (Keskar et al., 2017;
Hoffer et al., 2017; Yao et al., 2018).
Post-local SGD generalizes better and faster than mini-batch SGD.
Table 3 summarizes the generalization performance of post-local SGD on large batch size ( K (cid:16) 16 , B loc (cid:16) 128 ) across different architectures on CIFAR tasks for H (cid:16) 16 and H (cid:16) 32 .
Under the same setup, Table 9 in the
Appendix C.3 evaluates the speedup of training, while Figure 1 demonstrates the learning curves of mini-batch SGD and post-local SGD, highlighting the generalization difﬁculty of large-batch SGD.
We can witness that post-local SGD achieves at least 1 . 3 (cid:2) speedup over the whole training procedure compared to the mini-batch SGD counterpart ( K (cid:16) 16 , B (cid:16) 128 ), while enjoying the signiﬁcantly improved generalization performance.
[Table]
We further demonstrate the generalization performance and the scalability of post-local SGD, for diverse tasks (e
[Table]
g., Language Modeling), and for even larger global batch sizes ( KB loc (cid:16)for CIFAR-100 and 4096 and 8192 respectively for ImageNet), in Appendix C.5 .
For example,
Table 11 presents the severe generalization issue ( 2% drop) of the ﬁne-tuned large-batch SGD training ( KB (cid:16) 4096 ) for above three CNNs on CIFAR-100, and cannot be addressed by increasing the training steps (Table 12).
Post-local SGD ( KB loc (cid:16) 4096 ) with default hyper-parameters can perfectly close this generalization gap or even better than the ﬁne-tuned small mini-batch baselines 5 .
For
ImageNet training in Figure 16, the post-local SGD outperforms mini-batch SGD baseline for both of KB (cid:16) 4096 ( 76 . 18 and 75 . 87 respectively) and KB (cid:16) 8192 ( 75 . 65 and 75 .
64 respectively)
with 1 . 35 (cid:2) speedup for the post-local SGD training phase.
The effectiveness of post-local SGD training for different H and K .
As seen in Figure 3(a), applying any number of local steps over the case of large-batch training (when KB loc (cid:16) 2048 ) improves the generalization performance compared to mini-batch SGD.
Figure 3(b) illustrates that post-local SGD is better than mini-batch SGD in general for different number of workers K (as well as different KB loc ).
Thus, post-local SGD presents consistently excellent generalization performance.
Post-local SGD can improve the training efﬁciency upon other compression techniques.
The results in Table 4 illustrate that post-local SGD can be combined with other communication-efﬁcient techniques (e.g. the sign-based compression schemes) for further improved communication efﬁciency and better test generalization performance.
Post-local SGD can improve upon other SOTA optimizers.
The beneﬁts of post-local SGD training on ImageNet are even more pronounced for larger batches (e.g. KB loc ¡ 8192 )
(Goyal et al., is less challenging (e.g. comparing the ﬁrst and third rows in the right column of Table 2) to train with mini-batch SGD for medium-size, constant effective mini-batch size.
In our evaluation, the training of the post-local SGD and mini-batch SGD will start from the same effective mini-batch size with the same number of workers K .
Even under this relaxed comparison, post-local SGD still signiﬁcantly outperform mini-batch SGD.
We omit the comparison with other noise injection methods as none of them (Neelakantan et al., 2015; Wen et al., 2019) can completely address the generalization issue even for CIFAR dataset. [Figure] T o p - 1 T e s t C l a ss i f i c a t i o n A cc u r a c y
[Figure]
[Figure]
[Figure]
[Figure]
[Figure]
[Figure]
[Figure]
[Table]
2017; Shallue et al., 2018;
Golmant et al., 2018).
Considering other optimizers, Table 5 below shows that post-local SGD can improve upon LARS 6 (You et al., 2017a) [Table]
[Table]
D ISCUSSION AND I NTERPRETATION
Generalization issues of large-batch SGD training are not yet very well understood from a theoretical perspective.
Hence, a profound theoretical study of the generalization local SGD is beyond the scope of this work
but we hope the favorable experimental results will trigger future research in this direction.
In this section we discuss some related work and we argue that local SGD can be seen as a way to inject and control stochastic noise to the whole training procedure.
Connecting Local Updates with Stochastic Noise Injection.
The update eq.
(1) can alternatively be written as
[Equation]
3) where ˆ g t : (cid:16) 1 B (cid:176) i ∇ f i p w t q , g t : (cid:16) E ˆ g t (cid:16) ∇ f p w t q and (cid:15) : (cid:16) g t (cid:1) ˆ g t .
For most data-sets the noise (cid:15) can be well approximated by a zero-mean Gaussian with variance Σ p w q .
The variance matrix Σ p w q , following Hoffer et al.
(2017) and Hu et al.
(2017), for uniform sampling of mini-batch indices can be approximated as
[Equation]
[Equation]
Recent works (Jastrz˛ebski et al., 2018; Li et al., 2017; Mandt et al., 2017; Zhu et al., 2019) interpret eq.
(3) as an Euler-Maruyama approximation to the continuous-time Stochastic Differential Equation (SDE): d w t (cid:16) (cid:1) g t dt (cid:0) b γ N (cid:1) B BN R p w q d θ p t q where R p w q R p w q J (cid:16) K p w q and θ p t q (cid:18) N p 0 , I q .
When B !
N (in eq.
(4)), the learning rate and the batch size only appear in the SDE through the ratio ρ : (cid:16) γB (cid:1) 1 .
Jastrz˛ebski et al.
(2018) argue that thus mainly the ratio ρ controls the stochastic noise and training dynamics, and that ρ positively correlates with wider minima and better generalization— matching with recent experimental successes of ImageNet training (Goyal et al., 2017).
This explanation fails in the large batch regime.
When the batch size grows too large, the relative magnitude of the stochastic noise decreases as γB (cid:1) 1 (cid:27) γ p N (cid:1) B q{ BN , i.e. ρ is not anymore uniquely describing the training dynamics for large batch size and small dataset size when B (cid:127)!
N (Jastrz˛ebski et al., 2018).
This could be a reason why the generalization difﬁculty of large-batch training remains, as clearly illustrated e.g. in Figure 1, Table 3, Figure 3(b), and as well as in (Shallue et al., 2018;
Golmant et al., 2018).
The local update step of local SGD is a natural and computation-free way to inject well-structured stochastic noise to the SGD training dynamics.
By using the same ratio γB as mini-batch SGD, the main difference of the local SGD training dynamics comes from the stochastic noise (cid:15) during the local update phase ( K times smaller local mini-batch with H local update steps).
The (cid:15) will be approximately sampled with the variance matrix K Σ p w q instead of Σ p w q in mini-batch SGD, causing the stochastic noise determined by K and H to increase.
This could be one of the reasons for post-local SGD to generalize as good as mini-batch SGD (small mini-batch size) and leading to ﬂatter minima than large-batch SGD in our experiments.
Similar positive effects of adding well-structured stochastic noise to SGD dynamics on non-convex problems have recently also been observed in (Smith & Le, 2018; Chaudhari & Soatto, 2018; Zhu et al., 2019; Xing et al., 2018; Wen et al., 2019).
5. P OST - LOCAL SGD CONVERGES TO FLATTER MINIMA
Figure 4(a) evaluates the spectrum of the Hessian for different local minima.
We observe that largebatch SGD tends to get stuck at locations with high Hessian spectrum while post-local SGD tends to prefer low curvature solutions with better generalization error.
Figure 4(b) linearly interpolates two minima obtained by mini-batch SGD and post-local SGD, and Figure 13 (in the Appendix) visualizes the sharpness of the model trained by different methods.
These results give evidence that post-local
SGD converges to ﬂatter minima than mini-batch SGD for training ResNet-20 on CIFAR-10.
[Figure]
Hessian
[Figure]
trained from different schemes
Mini-batch SGD or post-local SGD with small H (e.g., H (cid:16) 2 , 4 ) have noticeably larger dominant eigenvalue
[Figure]
[Figure]
[Figure]
C ONCLUSION
We leverage the idea of local SGD for training in distributed and heterogeneous environments.
Ours is the ﬁrst work to extensively study the trade-off between communication efﬁciency and generalization performance of local SGD.
Our local SGD variant, called post-local SGD, not only outperforms large-batch SGD’s generalization performance but also matches that of small-batch SGD.
In our experiments post-local SGD converged to ﬂatter minima compared to traditional large-batch
SGD, which partially explains its improved generalization performance.
We also provide extensive experiments with another variant hierarchical local SGD, showing its adaptivity to available system resources.
Overall, local SGD comes off as a simpler and more efﬁcient algorithm, replacing complex ad-hoc tricks used for current large-batch SGD training
A CKNOWLEDGEMENTS
The authors thank the anonymous reviewers and Thijs Vogels for their precious comments and feedback.
We acknowledge funding from SNSF grant 200021_175796, as well as a Google Focused
Research Award.
Supplementary Material
For easier navigation through the paper and the extensive appendix, we include a table of contents.
C ONTENTS 1 Introduction
2 Related Work 3 Post-Local SGD and Hierarchical Local SGD 4 Experimental Results 4.1 Superior Scalability of Local SGD over mini-batch SGD . . . . . . . . . . . . . . . . . . . .
4.2 (Post)-Local SGD closes the Generalization Gap of Large-batch Training . . . . . . . . . . .
5 Discussion and Interpretation 5.1 Post-local SGD converges to ﬂatter minima . . . .
Conclusion
A Details on Deep Learning Experimental Setup
A.1 Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A.
Models
and Model Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A.
Large Batch Learning Schemes
A.
4 Hyperparameter Choices and Training Procedure, over Different
Models
Datasets . . . . . . .
A.
CIFAR-
10/CIFAR
A.4.2 ImageNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A.
System Performance Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B Local SGD Training
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
C Post-local SGD Training
[Table]
Algorithm of Post-local SGD
[Table]
The Effectiveness of Turning on Post-local SGD after the First Learning Rate Decay
C
[Table]
3 The Speedup of Post-local SGD Training on CIFAR
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table]
D Hierarchical Local SGD
[Table]
[Table] [Table] [Table] [Table]
[Table] [Table] [Table]
E Communication Schemes
F Discussion and Future Work
A D ETAILS ON D EEP L EARNING E XPERIMENTAL S ETUP A. D ATASET
We use the following tasks.
• Image classiﬁcation for CIFAR-10/100 (Krizhevsky & Hinton, 2009).
Each consists of a training set of 50 K and a test set of 10 K color images of 32 (cid:2) 32 pixels, as well as 10 and 100 target classes respectively.
We adopt the standard data augmentation scheme and preprocessing scheme (He et al., 2016a; Huang et al., 2016).
For preprocessing, we normalize the data using the channel means and standard deviations.
• Image classiﬁcation for ImageNet (Russakovsky et al., 2015).
The ILSVRC 2012 classiﬁcation dataset consists of 1 . 28 million images for training, and 50 K for validation, with 1 K target classes.
We use ImageNet-1k (Deng et al., 2009) and adopt the same data preprocessing and augmentation scheme as in He et al.
(2016a;b); Simonyan & Zisserman (2015).
The network input image is a 224 (cid:2) 224 pixel random crop from augmented images, with per-pixel mean subtracted.
• Language Modeling for WikiText-2 (Merity et al., 2017).
WikiText-2 is sourced from curated Wikipedia articles.
It is frequently used for machine translation and language modelling, and features a vocabulary of over 30 , 000 words.
Compared to the preprocessed version of Penn Treebank (PTB), WikiText-2 is over 2 times larger.
A. M ODELS AND M ODEL I NITIALIZATION
We use ResNet-20 (He et al., 2016a) with CIFAR-10 as a base conﬁguration to understand different properties of (post-)local SGD.
We then empirically evaluate the large-batch training performance of post-local SGD, for ResNet-20, DensetNet-40-12 (Huang et al., 2017b) and WideResNet-2810 (Zagoruyko & Komodakis, 2016) on CIFAR-10/100, and for LSTM on WikiText-2 (Merity et al., 2017).
Finally, we train ResNet-50 (He et al., 2016a) on ImageNet to investigate the accuracy and scalability of (post-)local SGD training.
For the weight initialization we follow Goyal et al.
(2017), where we adopt the initialization introduced by He et al.
(2015) for convolutional layers and initialize fully-connected layers by a zero-mean
Gaussian distribution with the standard deviation of 0 . 01 .
Table 6 demonstrates the scaling ratio of our mainly used Neural Network architectures.
The scaling ratio (You et al., 2017b) identiﬁes the ratio between computation and communication, wherein
DNN models
, the computation is proportional to the number of ﬂoating point operations required for processing an input while the communication is proportional to model size (or the number of parameters).
Our local SGD training scheme will show more advantages over models with small “computation and communication scaling ratio”.
[Table] [Table]
A. L ARGE B ATCH L EARNING S CHEMES
The work of Goyal et al.
(2017) proposes common conﬁgurations to tackle large-batch training for the ImageNet dataset.
We speciﬁcally refer to their crucial techniques w.r.t.
learning rate as “large batch learning schemes” in our main text.
For a precise deﬁnition, this is formalized by the following two conﬁgurations:
• Scaling the learning rate : When the mini-batch size is multiplied by k , multiply the learning rate by k . • Learning rate gradual warm-up : We gradually ramp up the learning rate from a small to a large value.
In (our) experiments, with a large mini-batch of size kn , we start from a learning rate of η and increment it by a constant amount at each iteration such that it reaches ˆ η (cid:16) kη after 5 epochs.
More precisely, the incremental
step size for each iteration is calculated from ˆ η (cid:1) η 5 N {p kn q , where N is the number of total training samples, k is the number of computing units and n is the local mini-batch size.
A. H YPERPARAMETER C HOICES AND T RAINING P ROCEDURE , OVER D IFFERENT M ODELS /D ATASETS A.4. CIFAR-10/CIFAR-
The experiments follow the common mini-batch SGD training scheme for CIFAR (He et al., 2016a;b;
Huang et al., 2017b) and all competing methods access the same total amount of data samples regardless of the number of local steps.
The training procedure is terminated when the distributed algorithms have accessed the same number of samples as a standalone worker would access.
For example, ResNet-20, DensetNet-40-12 and WideResNet-28-10 would access 300 , 300 andepochs respectively.
The data is partitioned among the GPUs and reshufﬂed globally every epoch.
The local mini-batches are then sampled among the local data available on each GPU, and its size is ﬁxed to B loc (cid:16) 128 .
The learning rate scheme follows works (He et al., 2016a;
Huang et al., 2017b), where we drop the initial learning rate by 10 when the model has accessed 50% and 75% of the total number of training samples.
The initial learning rates of ResNet-20, DensetNet-40-12 and WideResNet-28are ﬁne-tuned on single GPU (which are 0 . 2 , 0 . 2 and 0 . 1 respectively), and can be scaled by the global mini-batch size when using large-batch learning schemes.
In addition to this, we use a Nesterov momentum of 0 .
9 without dampening, which is applied independently to each local model.
For all architectures, following He et al.
(2016a), we do not apply weight decay on the learnable Batch Normalization (BN) coefﬁcients.
The weight decay of ResNet-20, DensetNet-40-12 and WideResNet-28-10 are 1 e - 4 , 1 e - 4 and 5 e - 4 respectively.
For the BN for distributed training we again follow Goyal et al.
and compute the BN statistics independently for each worker.
Unless mentioned speciﬁcally, local SGD uses the exact same optimization scheme as mini-batch
SGD.
The procedure of ﬁne-tuning.
There is no optimal learning rate scaling rule for large-batch SGD across different mini-batch sizes, tasks and architectures, as revealed in the Figure 8 of Shallue et al.
Our tuning procedure is built on the insight of their Figure 8 , where we grid-search the optimal learning rate for each mini-batch size, starting from the linearly scaled learning rate.
For example, compared to mini-batch size 128 , mini-batch size 2048 with default large-batch learning schemes need to linearly scale the learning rate by the factor of 16 .
In order to ﬁnd out its optimal learning rate, we will evaluate a linear-spaced grid of ﬁve different factors (i.e., t 15 , 15 . 5 , 16 , 16 .
5 , 17 u ).
If the best performance was ever at one of the extremes of the grid, we would try new grid points so that the best performance was contained in the middle of the parameters.
Please note that this unbounded grid search—even though initialized at the linearly scaled learning rate—does also cover other suggested scaling heuristics, for instance square root scaling, and ﬁnds the best scaling for each scenario.
Note that in our experiments of large-batch SGD, either with the default large-batch learning schemes, or tuning/using the optimal learning rate, we always warm-up the learning rate for the ﬁrst 5 epochs.
A.4. I MAGE N ET
ResNet-50 training is limited to 90 passes over the data in total, and the data is disjointly partitioned and is re-shufﬂed globally every epoch.
All competing methods access the same total number of data samples (i.e. gradients)
regardless of the number of local steps.
We adopt the large-batch learning schemes as in Goyal et al.
(2017) below.
We linearly scale the learning rate based on (cid:0)
Number of GPUs (cid:2)
[Figure]
[Equation] [Figure] (cid:8) where 0 . 1 and 256 is the base learning rate and mini-batch size respectively for standard single GPU training.
The local mini-batch size is set to 128 .
For learning rate scaling, we perform gradual warmup for the ﬁrst 5 epochs, and decay the scaled learning rate by the factor of 10 when local models have access 30 , 60 , 80 epochs of training samples respectively.
A. S YSTEM P ERFORMANCE E VALUATION
Figure 5 investigates the increased latency of transmitting data among CPU cores.
[Figure]
Table 7 evaluates the time of running forward and backward with different mini-batch size, for training ResNet20 on CIFAR-10.
We can witness that a larger mini-batch size we use, the better parallelism can a GPU have.
[Table]
B L OCAL SGD T RAINING B. F ORMAL D EFINITION OF THE L OCAL SGD A LGORITHM
p t q(cid:0) h (cid:1) 1 . 6: compute the gradient g k p t q(cid:0) h (cid:1) 1 : (cid:16) 1 B loc (cid:176)
i P I k p t q(cid:0) h (cid:1) 1 ∇ f i (cid:0) w k p t q(cid:0) h (cid:1) 1 (cid:8) .
7: update the local model to w k p t q(cid:0) h : (cid:16) w p t q(cid:0) h (cid:1) 1 (cid:1) γ p t q g k p t q(cid:0) h (cid:1) 1 .
8: end for 9: all-reduce aggregation of the gradients ∆ k p t q : (cid:16) w k p t q (cid:1) w k p t q(cid:0) H .
10: get new global (synchronized) model w k p t (cid:0) 1 q for all K nodes: w k p t (cid:0) 1 q : (cid:16) w k p t q (cid:1) γ p t q 1 K (cid:176)
Ki (cid:16) 1 ∆ k p t q 11: end for 12: end for
B. N UMERICAL I LLUSTRATION OF L OCAL SGD ON A C ONVEX P ROBLEM
In addition to our deep learning experiments, we ﬁrst illustrate the convergence properties of local
SGD on a small scale convex problem.
For this, we consider logistic regression on the w8a dataset
( d (cid:16) 300 , n (cid:16) 49749 ).
We measure the number of iterations to reach the target accuracy (cid:15) (cid:16) 0 .
For each combination of H, B loc and K we determine the best learning rate by extensive grid search (cf.
paragraph below for the detailed experimental setup).
In order to mitigate extraneous effects on the measured results, we here measure time in discrete units, that is we count the number of stochastic gradient computations and communication rounds, and assume that communication of the weights is 25 (cid:2) more expensive than a gradient computation, for ease of illustration.
Figure 6(a) shows that different combinations of the parameters p B loc , H q can impact the convergence time for K (cid:16) 16 .
Here, local SGD with p 16 , 16 q converges more than 2 (cid:2) faster than for p 64 , 1 q and 3 (cid:2) faster than for p 256 , 1 q .
Figure 6(b) depicts the speedup when increasing the number of workers K .
Local SGD shows the best speedup for H (cid:16) 16 on a small number of workers, while the advantage gradually diminishes for very large K .
H=1H=2H= {+H=
+}
[-H=
-]H=
(a) Time (relative to best method) to solve a regu- larized logistic regression problem to target accuracy (cid:15) (cid:16) 0 . 005 for K (cid:16) 16 workers for H P 1 , 2 , 4 , 8 , 16 and local mini-batch size B loc . We simulate the network trafﬁc under the assumption that communication is 25 (cid:2) slower than a stochastic gradient computation.
[Figure]
workers K to solve a regularized logistic regression problem to target accuracy (cid:15) (cid:16) 0 .
005 , for B loc (cid:16) 16 and H P 1 , 2 , 4 , 8 , 16 .
We simulate the network trafﬁc under the assumption that communication is 25 (cid:2) slower than a stochastic gradient computation.
Experimental Setup for Convex Experiments For the illustrative experiments here we study the convergence of local SGD on the logistic regression problem, f p w q (cid:16) 1 n (cid:176) ni (cid:16) 1 log p 1 (cid:0) exp p(cid:1) b i a J i w qq(cid:0) λ 2 } w } 2 , where a i P R d and b i P t(cid:1) 1 , (cid:0) 1 u are the data samples, and regularization parameter λ (cid:16) 1 { n .
For each run, we initialize w 0 {+(cid:16) 
+} d and measure the number of stochastic gradient evaluations (and communication rounds) until be best of last iterate and weighted average of the iterates reaches the target accuracy f p w t q (cid:1) f (cid:14) ⁄
(cid:15) : (cid:16) 0 .
005 , with f (cid:14) : (cid:16) 0 .
For each conﬁguration p K, H, B loc q , we report the best result found with any of the following two stepsizes: γ t : (cid:16) min p 32 , cnt (cid:0) 1 q and γ t (cid:16) 32 c .
Here c is a parameter that can take the values c (cid:16) 2 i for i P Z .
For each stepsize we determine the best parameter c by a grid search, and consider parameter c optimal, if parameters t 2 (cid:1) 2 c, 2 (cid:1) 1 c, 2 c, 2 2 c u yield worse results (i.e. more iterations to reach the target accuracy). [Figure] [Figure]
R ESULTS ON L OCAL SGD T RAINING B.3. T RAINING CIFAR-10 VIA LOCAL SGD
Better communication efﬁciency, with guaranteed test accuracy.
Figure 7 shows that local SGD is signiﬁcantly more communication efﬁcient while guaranteeing the same accuracy and enjoys faster convergence speed.
In Figure 7, the local models use a ﬁxed local mini-batch size B loc (cid:16)for all updates.
All methods run for the same number of total gradient computations.
Mini-batch
[Figure]
T o
[Figure]
1 T r a i n i n g C l a ss i f i c a t i o n
A cc u r a c y
[Figure]
SGD—the baseline method for comparison—is a special case of local SGD with H (cid:16) 1 , with full global model synchronization for each local update.
We see that local SGD with H ¡ 1 , as illustrated in Figure 7(a), by design does H times less global model synchronizations, alleviating the communication bottleneck while accessing the same number of samples (see section 1).
The impact of local SGD training upon the total training time is more signiﬁcant for larger number of local steps
H (i.e., Figure 7(b)), resulting in an at least 3 (cid:2) speed-up when comparing mini-batch H (cid:16) 1 to local
SGD with H (cid:16) 16 .
The ﬁnal training accuracy remains stable across different H values, and there is no difference or negligible difference in test accuracy (Figure 7(c)).
B.3. T RAINING I MAGE N ET VIA L OCAL SGD
Figure 8 shows the effectiveness of scaling local SGD to the challenging ImageNet dataset.
We limit
ResNet- 50 training to 90 passes over the data in total, and use the standard training conﬁgurations as mentioned in Appendix A.4.2.
[Figure]
Moreover, in our ImageNet experiment, the initial phase of local SGD training follows the theoretical assumption mentioned in Subsection 2, and thus we gradually warm up the number of local steps from 1 to the desired value H during the ﬁrst few epochs of the training.
We found that exponentially increasing the number of local steps from 1 by the factor of 2 (until reaching the expected number of local steps) performs well.
For example, our ImageNet training uses H (cid:16) 8 , so the number of local steps for the ﬁrst three epochs is 1 , 2 , 4 respectively.
B.3. L OCAL SGD S CALES TO L ARGER B ATCH S IZES THAN M INI - BATCH SGD
The empirical studies (Shallue et al., 2018; Golmant et al., 2018) reveal the regime of maximal data parallelism across different tasks and models, where the large-batch training would reach the limit and additional parallelism provides no beneﬁt whatsoever.
[Figure]
On contrary to standard large-batch training, local SGD scales to larger batch size and provides additional parallelism upon the limitation of current large batch training.
Figure 9 shows the example of training ResNet-20 on CIFAR-10 with H (cid:16) 2 , which trains and generalizes better in terms of update steps while with reduced communication cost.
B. P RACTICAL I MPROVEMENT P OSSIBILITIES FOR S TANDARD L OCAL SGD T RAINING
We investigate different aspects of the training to address the quality when scaling local SGD to the extreme case, e.g., hybrid momentum scheme, warming up the local SGD or ﬁne-tuning the learning rate.
In this section, we brieﬂy present how these strategies are, and how they work in practice where we train ResNet-20 on CIFAR-10 on 16 GPUs.
B.4. L OCAL SGD WITH M OMENTUM
Momentum mini-batch SGD is widely used in place of vanilla SGD.
The distributed mini-batch SGD with vanilla momentum on K training nodes follows
[Equation]
where ∇ k p t q (cid:16) 1 | I k p t q | [Equation] q
[Equation]
After H updates of mini-batch SGD, we have the following updated w p t (cid:0) H q :
[Equation]
Coming back to the setting of local SGD, we can apply momentum acceleration on each local model, or on a global level (Chen & Huo, 2016).
In the remaining part of this section, we analyze the case of applying local momentum and global momentum.
For ease of understanding, we assume the learning rate γ is the same throughout the H update steps.
Local SGD with Local Momentum.
When applying local momentum on the local SGD, i.e., using independent identical momentum acceleration for each local model and only globally aggregating the gradients at the time p t q (cid:0) H , we have the following local update scheme
[Equation]
where ∇ k p t q (cid:16) 1 | I
[Equation]
q | (cid:176) i P I k
[Equation]
q ∇ f i p w p t q q .
Consequently, after H local steps,
[Equation]
Substituting the above equation into eq.
(2), we have the update
[Equation]
Comparing the mini-batch SGD with local momentum local SGD after H update steps ( H global update steps v.s. H local update steps and 1 global update step), we witness that the main difference of these two update schemes is the difference between (cid:176) Hτ (cid:16) [Equation] m
[Equation]
u p t (cid:1) 1 q and
[Equation]
where mini-batch SGD holds a global u p t (cid:1) 1 q while each local model of the local SGD has their own u k p t (cid:1) 1 q .
We will soon see the difference between the global momentum of mini-batch SGD and the local momentum of local SGD.
Local SGD with Global Momentum For global momentum local SGD, i.e., a more general variant of block momentum (Chen & Huo, 2016), we would like to apply the momentum factor only to the accumulated/synchronized gradients:
[Equation]
q (cid:16) w p t q (cid:1) γ u p t q (cid:16) w p t q (cid:1) γ
[Equation]
m
[Equation]
[Equation] (cid:8) where w k p t q(cid:0) H (cid:16) w k p t q (cid:1) η (cid:176) H (cid:1) 1 l (cid:16) 0 ∇ k p t q(cid:0) l (cid:16) w p t q (cid:1) η (cid:176)
H (cid:1) 1 l (cid:16) 0 ∇ k p t q(cid:0) l . Note that for local SGD, we consider summing up the gradients from each local update, i.e., the model difference before and after one global synchronization, and then apply the global momentum to the gradients over workers over previous local update steps.
Obviously, there exists a signiﬁcant difference between mini-batch momentum SGD and global momentum local SGD, at least the term
[Equation]
Local SGD with Hybrid Momentum.
The following equation tries to combine local momentum with global momentum, showing a naive implementation.
First of all, based on the local momentum scheme, after H local update steps,
[Equation]
Together with the result from local momentum with the global momentum, we have
[Equation]
where u p t (cid:1) 1 q is the global momentum memory and u p t (cid:1) 1 q is the local momentum memory for each node k .
[Table]
Local SGD with Momentum in Practice.
In practice, it is possible to combine the local momentum with global momentum to further improve the model performance.
For example, a toy example in
Table 8 investigates the impact of different momentum schemes on CIFAR-10 trained with ResNeton a 5 (cid:2) 2 -GPU cluster, where some factors of global momentum could further slightly improve the ﬁnal test accuracy.
However, the theoretical understanding of how local momentum and global momentum contribute to the optimization still remains unclear, which further increase the difﬁculty of tuning local SGD over
H , K .
An efﬁcient way of using local and global momentum remains a future work and in this work, we only consider the local momentum.
B.4. W ARM - UP OF THE N UMBER OF L OCAL SGD S TEPS
We use the term “local step warm-up strategy”, to refer to a speciﬁc variant of post-local SGD.
More precisely, instead of the two-phase regime which we presented here the used number of local steps H will be gradually increased from 1 to the expected number of local steps H .
The warm-up strategies investigated here are “linear”, “exponential” and “constant”.
Please note that the implemented post-local SGD over the whole text only refers to the training scheme that uses frequent communication (i.e., H (cid:16) 1 ) before the ﬁrst learning rate decay and then reduces the communication frequency (i.e., H ¡ 1 ) after the decay.
This section then investigates the trade-off between stochastic noise and the training stability.
Also note that the Figure 2(a) in the main text has already presented one aspect of the trade-off.
So the exploration below mainly focuses on the other aspects and tries to understand how will the scale of the added stochastic noise impact the training stability.
Infact, even the model has been stabilized to a region with good quality.
Figure 10 and Figure 11 investigate the potential improvement through using the local step warm-up strategy for the case of training ResNet-20 on CIFAR-10.
Figure 10 evaluates the warm-up strategies of “linear” and “constant” for different H , while the evaluation of “exponential” warm-up strategy is omitted due to its showing similar performance as “linear” warm-up.
However, none of the investigated strategies show convincing performance.
Figure 11 further studies how the period of warm-up impacts the training performance.
We can witness that even if we increase the warm-up phase to 50 epochs where the training curve of mini-batch SGD becomes stabilized, the large noise introduced by the local SGD will soon degrade the status of training and lead to potential quality loss, as in Figure 11(a)
[Figure] [Figure]
[Figure] [Figure]
Evaluate the impact of “linear” local step warm-up for different period of warm-up phase
[Figure] [Figure]
[Figure]
C P OST - LOCAL SGD T RAINING C. T HE A LGORITHM OF P OST - LOCAL SGD
[Table]
[Table] [Table] [Table] [Table]
[Table] [Table] [Table] [Table]
[Table] [Table] [Table] [Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table] [Table] [Table]
[Table]
w k p t q(cid:0) H .
15: get new global (synchronized) model w k p t (cid:0) 1 q for all K nodes:
w
[Equation]
16: end for 17: end for
C. T HE E FFECTIVENESS OF T URNING ON P OST - LOCAL SGD AFTER THE F IRST L EARNING R ATE D ECAY
In Figure we study the sufﬁciency as well as the necessity of “injecting” more stochastic noise (i e., using post-local SGD) into the optimization procedure after performing the ﬁrst learning rate decay.
Otherwise, the delayed noise injection (i e., starting the post-local SGD only from the second learning rate decay) not only introduces more communication cost but also meets the increased risk of converging to sharper minima.
[Figure]
C. T HE S PEEDUP OF P OST - LOCAL SGD T RAINING ON CIFAR
3 and
CIFARCIFAR-
[Table]
[Table]
C. U NDERSTANDING THE G ENERALIZATION OF P OST - LOCAL SGD
The Sharpness Visualization Figure 13 visualizes the sharpness of the minima for training ResNet20 on CIFAR-10.
10 different random direction vectors are used for the ﬁlter normalization (Li et al., 2018), to ensure the correctness and consistence of the sharp visualization
[Figure]
The spectrum of the Hessian for mini-batch SGD and post-local SGD Figure 14 evaluates the spectrum of the Hessian for the model trained from mini-batch SGD and post-local SGD with different H , which again demonstrates the fact that large-batch SGD tends to stop at points with high
Hessian spectrum while post-local SGD could easily generalize to a low curvature solution and with better generalization.
d linear interpolation between models The 1 -d linear interpolation was ﬁrst used by Goodfellow et al.
and then widely used to study the “sharpness” and “ﬂatness” of different minima in several works (Keskar et al., 2017;
Dinh et al., 2017; Li et al., 2018).
In Figure 15, the model trained by post-local SGD ( w post-local SGD q can generalize to ﬂatter minima than that of mini-batch
SGD ( w mini-batch SGD ), either w post-local SGD is trained from scratch, or resumed from the checkpoint of w mini-batch SGD (i.e., the checkpoint is one-epoch ahead of the ﬁrst learning rate decay so as to share the common weight structure with w mini-batch SGD ).
C. P OST - LOCAL SGD T RAINING ON D IVERSE T ASKS C.5. P OST - LOCAL SGD T RAINING ON CIFAR-100 FOR G LOBAL M INI - BATCH S IZE
[Table] Table 11 presents the severe quality loss (at around 2% ) of the ﬁne-tuned large-batch SGD for training three CNNs on CIFAR-100.
Our post-local SGD with default hyper-parameters (i.e., the hyper-parameters from small mini-batch size and via large-batch training schemes) can perfectly close the generalization gap or even better the ﬁne-tuned small mini-batch baselines.
We further justify the argument of works (Hoffer et al., 2017; Shallue et al., 2018) in Table 12, where we increase the number of training epochs and train it longer (from 300 to 400 and 500 ) for
ResNet-20 on CIFAR-100.
The results below illustrate that increasing the number of training epochs alleviates the optimization difﬁculty of large-batch training
[Figure] [Figure]
[Figure]
[Figure]
[Figure] [Figure]
[Table]
P OST - LOCAL SGD T RAINING ON L ANGUAGE M ODELING
We evaluate the effectiveness of post-local SGD for training the language modeling task on WikiText2 through LSTM.
We borrowed and adapted the general experimental setup of Merity et al.
(2018), where we use a three-layer LSTM with hidden dimension of size 650 .
The loss will be averaged over all examples and timesteps.
The BPTT length is set to 30 .
We ﬁne-tune the value of gradient clipping ( 0 . 4 ) and the dropout ( 0 . 4 ) is only applied on the output of LSTM.
The local mini-batch size B loc is
[Figure]
[Figure] [Figure] [Figure]
[Figure]
T o pC l a ss i f i c a t i o n A cc u r a c y [Table]
[Figure]
[Table] [Figure] [Table]
[Figure] [Table] [Figure] [Table]
[Figure]
[Table]
64 and we train the model for 120 epochs.
The learning rate is again decayed at the phase when the training algorithm has accessed 50% and 75% of the total training samples.
Table 13 below demonstrates the effectiveness of post-local SGD for large-batch training on language modeling task (without extra ﬁne-tuning except our baselines).
Note that most of the existing work focuses on improving the large-batch training issue for computer vision tasks; and it is non-trivial to scale the training of LSTM for language modeling task due to the presence of different hyperparameters.
Here we provide a proof of concept result in Table 13 to show that our post-local SGD is able to improve upon standard large-batch baseline.
The beneﬁts can be further pronounced if we scale to larger batches (as the case of image classiﬁcation e.g. in Table 11 and Table 12). [Table]
[Table]
C.5. P OST - LOCAL SGD T RAINING ON I MAGE N ET
We evaluate the performance of post-local SGD on the challenging ImageNet training.
Again we limit
ResNet- 50 training to 90 passes over the data in total, and use the standard training conﬁgurations as mentioned in Appendix A.4.2.
The post-local SGD begins when performing the ﬁrst learning rate decay
We can witness that post-local SGD outperforms mini-batch SGD baseline for both of mini-batch size 4096 ( 76 . 18 and 75 . 87 respectively) and 8192 ( 75 . 65 and 75 .
64 respectively)
[Figure] [Figure]
[Figure]
[Figure]
e s t C l a ss i f i c a t i o n
A cc u r a c y
[Figure] [Figure]
C.5. P OST - LOCAL SGD VS. O THER N OISE I NJECTION M ETHODS
The role of “noise” has been actively studied in SGD for non-convex deep learning, from optimization and generalization aspects.
Neelakantan et al.
(2015) propose to inject isotropic white noise for better optimization.
Zhu et al. ; Xing et al.
(2018) study the “structured” anisotropic noise and ﬁnd the importance of anisotropic noise in SGD for escaping from minima (over isotropic noise) in terms of generalization.
Wen et al.
(2019) on top of these work
and try to inject noise (sampled from the expensive empirical Fisher matrix) to large-batch SGD.
However, to our best knowledge, none of the prior work can provide a computation efﬁcient way to inject noise to achieve as good generalization performance as small-batch SGD.
Either it is practically unknown if injecting the isotropic noise (Neelakantan et al., 2015) can alleviate the issue of large-batch training, or it has been empirically justiﬁed (Wen et al., 2019) that injecting anisotropic noise from expensive (diagonal) empirical Fisher matrix fails to recover the same performance as the small mini-batch baselines.
In this section, we only evaluate the impact of injecting isotropic noise (Neelakantan et al., 2015) for large-batch training, and omit the comparison to Wen et al.
The idea of Neelakantan et al.
(2015) considers to add time-dependent Gaussian noise to the gradient at every training step t : ∇ f i (cid:0) w p t q (cid:8) — ∇ f i (cid:0) w p t q (cid:8) (cid:0) N p 0 , σ 2 t q , where σ 2 t follows σ 2 t : (cid:16)
η p 1 (cid:0) t q γ 1 .
We follow the general hyper-parameter search scheme (as mentioned in Section A.4) and ﬁne-tune the η and γ 1 in the range of t 1 e (cid:1) 6 , 5 e (cid:1) 6 , 1 e (cid:1) 5 , 5 e (cid:1) 5 u and t 0 .
5 , 1 , 1 . 5 , 2 , 2 . 5 , 3 . 0 u respectively.
Table 14 below compares the post-local SGD to Neelakantan et al.
(2015), where the noise injection scheme in Neelakantan et al.
(2015) cannot address the large-batch training issue and could even deteriorate the generalization performance.
Note that we also tried to search the hyper-parameters at around the values reported in Neelakantan et al.
(2015) for our state-of-the-art CNNs,
but it will directly result in the severe quality loss or even divergence.
[Table]
Compared to another local SGD variant.
Recently [Table] Wang & Joshi (2019) proposed to decrease the number of local update steps H during training.
However, their scheme is inherited from the convergence analysis for optimization (not the generalization for deep learning), and in principle opposite to our interpolation and proposed strategy (i.e. increasing the local update steps during the training).
Their evaluation (ResNet-50 on CIFAR-10 for K (cid:16) 4 with B loc (cid:16) 128 ) also does not cover the difﬁcult large batch training scenario (Scenario 2), e.g., H (cid:16) 16 , K (cid:16) 16 , B loc (cid:16) 128 .
For the same CIFARtask and K =4 as in Wang & Joshi (2019), our smaller ResNet-20 with local SGD can simply reach a better accuracy with less communication 9 (Figure 2).
C.5. P OST - LOCAL SGD WITH O THER C OMPRESSION S CHEMES
In this subsection, we demonstrate that (post-)local SGD can be integrated with other compression techniques for better training efﬁciency (further reduced communication cost) and improved generalization performance (w.r.t.
the gradient compression methods).
We use sign-based compression scheme (i.e. signSGD (Bernstein et al., 2018) and EFsignSGD (Karimireddy et al., 2019)) for the demonstration.
The pseudo code can be found in
Algorithm 3 and Algorithm 4.
Post-local SGD with signSGD.
We slightly adapt the original signSGD
(Bernstein et al., 2018) to ﬁt in the local SGD framework.
The local model will be ﬁrstly updated by the sign of the local update directions (e.g. gradients, or gradients with weight decay and momentum acceleration), and then be synchronized to reach the global consensus model for the next local updates.
Note that we can almost recover the signSGD in Bernstein et al.
(2018) from Algorithm
when
H 1 (cid:16) 1 , except that we will average over the sign instead of using the majority vote in Bernstein et al.
Table 15 illustrates the trivial generalization performance difference of these two schemes, where the post-local SGD in Algorithm 3 is able to signiﬁcantly improve the generalization performance (as in Table 4) with further improved communication efﬁciency.
[Table]
[Table]
[Table]
Post-local SGD with EF-signSGD.
We extend the single-worker EF-signSGD algorithm of Karimireddy et al.
(i.e. their Algorithm 1) to multiple-workers case by empirically investigating different algorithmic design choices.
Our presented Algorithm 4 of EF-signSGD for multiple-workers can reach a similar performance as the mini-batch SGD counterpart (both are after the proper hyper-parameters tuning and under the same experimental setup).
Training schemes, hyper-parameter tuning procedure for signSGD, signSGD variant in Algorithm 3, and EF-signSGD in Algorithm 4.
The training schemes of the signSGD
(Bernstein et al., 2018)
(i.e. the one using majority vote) and the signSGD variant in Algorithm 3 are slightly different from the the experimental setup mentioned in A.4, where we only ﬁne-tune the initial learning rate in signSGD and Algorithm 3 (when H (cid:16) 1 ).
The optimal learning rate is searched from the grid t 0 .
20 u with the general ﬁne-tuning principle mentioned in A.4.
No learning rate
[Table]
[Table]
[Table]
[Table]
[Table]
t q : (cid:16) w k p t q (cid:1) w k p t q(cid:0) H (cid:0) e p t q .
16: compress the model difference:
[Table]
p
[Table]
q (cid:16) sign
[Table] ∆ [Table] q q
and
[Table]
q (cid:16) (cid:13)(cid:13)(cid:13)
∆ k p t q (cid:13)(cid:13)(cid:13) 1 d .
17: update local memory: e k p t (cid:0) 1 q (cid:16) e k p t q (cid:1) s k p t q p k p t q .
18: get new global (synchronized) model w
[Table]
p t (cid:0)
[Table]
for all
[Table]
nodes:
[Table]
q :
[Table] p [Table] q . 19: end for 20: end for scaling up or warming up is required during the training, and the learning rate will be decayed bywhen accessing 50% and 75% of the total training samples.
The training schemes of the distributed EF-signSGD in Algorithm 4 in general follow the experimental setup mentioned in A.4.
We grid search the optimal initial learning rate for Algorithm 4 (for the case of H (cid:16) 1 ), and gradually warm up the learning rate from a relatively small value (0.1) to this found initial learning rate during the ﬁrst 5 epochs of the training.
Note that in our experiments, weight decay and Nesterov momentum are used for the local model updates, for both of Algorithm 3 and Algorithm 4.
We empirically found these two techniques can signiﬁcantly improve the training/test performance under a ﬁxed training epoch budget.
D H IERARCHICAL L OCAL SGD
The idea of local SGD can be leveraged to the more general setting of training on decentralized and heterogeneous systems, which is an increasingly important application area.
Such systems have become common in the industry, e.g. with GPUs or other accelerators grouped hierarchically within machines, racks or even at the level of several data-centers.
Hierarchical system architectures such as in Figure 17 motivate our hierarchical extension of local SGD.
Moreover, end-user devices such as mobile phones form huge heterogeneous networks, where the beneﬁts of efﬁcient distributed and data-local training of machine learning models promises strong beneﬁts in terms of data privacy
[Figure]
D. T HE I LLUSTRATION OF H IERARCHICAL L OCAL SGD
Real world systems come with different communication bandwidths on several levels.
In this scenario, we propose to employ local SGD on each level of the hierarchy, adapted to each corresponding computation vs communication trade-off.
The resulting scheme, hierarchical local SGD, can offer signiﬁcant beneﬁts in system adaptivity and performance.
D e v i c e w  w  w w D e v i c e w  w  w w
D e v i c e w  w  w w D e v i c e w  w  w w
H b H
H
H
H
D e v i c e w  w  w w D e v i c e w  w  w w
D e v i c e w  w  w w D e v i c e w  w  w w
H b H
H
H
H N o d e
N o d e
As the guiding example, we consider compute clusters which typically allocate a large number of
GPUs grouped over several machines, and refer to each group as a GPU-block.
Hierarchical local
SGD continuously updates the local models on each GPU for a number of H local update steps before a (fast) synchronization within a GPU-block.
On the outer level, after H b such block update steps , a
(slower) global synchronization over all GPU-blocks is performed.
Figure 18 and Algorithm 5 depict how the hierarchical local SGD works, and the complete procedure is formalized below:
[Equation]
where w k rp t q(cid:0) l s(cid:0) H indicates the model after l block update steps and H local update steps, and K i is the number of GPUs on the GPU-block i .
The deﬁnition of γ rp t qs and I k rp t q(cid:0) l s(cid:0) h (cid:1) 1 follows a similar scheme.
As the number of devices grows to the thousands (Goyal et al., 2017; You et al., 2017b), the difference between ‘within’ and ‘between’ block communication efﬁciency becomes more drastic.
Thus, the performance beneﬁts of our adaptive scheme compared to ﬂat & large mini-batch SGD will be even more pronounced.
D. T HE A LGORITHM OF H IERARCHICAL L OCAL SGD
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]
[Equation]
[Table]
[Table] [Table]
[Equation]
11: get new block (synchronized)
[Equation]
K
[Equation]
nodes
[Equation]
12: end for 13: outer all-reduce aggregation of the gradients
[Equation]
14: get new global (synchronized) model
[Equation]
for [Equation] nodes
[Equation]
15: end for 16: end for
D. H IERARCHICAL L OCAL SGD T RAINING
Now we move to our proposed training scheme for distributed heterogeneous systems.
In our experimental setup, we try to mimic the real world setting where several compute devices such as GPUs are grouped over different servers, and where network bandwidth (e.g. Ethernet) limits the communication of updates of large models.
The investigation of hierarchical local SGD again trains ResNet-20 on CIFAR-10 and follows the same training procedure as local SGD where we re-formulate below.
The experiments follow the common mini-batch SGD training scheme for CIFAR (He et al., 2016a;b) and all competing methods access the same total amount of data samples regardless of the number of local steps or block steps.
More precisely, the training procedure is terminated when the distributed algorithms have accessed the same number of samples as a standalone worker would access inepochs.
The data is partitioned among the GPUs and reshufﬂed globally every epoch.
The local mini-batches are then sampled among the local data available on each GPU.
The learning rate scheme is the same as in He et al.
(2016a), where the initial learning rate starts from 0 .
and is divided bywhen the model has accessed 50% and 75% of the total number of training samples.
In addition to this, the momentum parameter is set to 0 .
9 without dampening and applied independently to each local model.
D.3. T HE P ERFORMANCE OF H IERARCHICAL L OCAL SGD.
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
Training time vs. local number of steps.
Table 16 shows the performance of local SGD in terms of training time.
The communication trafﬁc comes from the global synchronization over 8 nodes, each having 2 GPUs.
We can witness that increasing the number of local steps over the “datacenter” scenario cannot inﬁnitely improve the communication performance, or would even reduce the communication beneﬁts brought by a large number of local steps.
Hierarchical local SGD with inner node synchronization reduces the difﬁculty of synchronizing over the complex heterogeneous environment, and hence enhances the overall system performance of the synchronization.
The beneﬁts are further pronounced when scaling up the cluster size.
[Figure]
T
[Figure]
1 T r
[Figure]
i n C l a ss i f i c a t i o n A cc u r a c y H =2, H b =1 H =
[Figure]
H b =2 H =
[Figure]
H b =
H =
[Figure]
H b =8 H =
[Figure]
= [Figure] [Figure] [Figure]
C
[Figure]
f i c a t i o n
[Figure]
c y
[Figure]
=
[Figure]
b =
[Figure]
=
[Figure]
b =
[Figure]
=
[Figure]
b =
[Figure]
[Figure]
Hierarchical local SGD shows high tolerance to network delays.
Even in our small-scale experiment of two servers and each with two GPUs, hierarchical local SGD shows its ability to signiﬁcantly reduce the communication cost by increasing the number of block step H b (for a ﬁxed H ), with trivial performance degradation.
Moreover, hierarchical local SGD with a sufﬁcient number of block steps offers strong robustness to network delays.
For example, for ﬁxed H (cid:16) 2 , by increasing the number of H b , i e. reducing the number of global synchronizations over all models, we obtain a signiﬁcant gain in training time as in Figure 19(a).
The impact of a network of slower communication is further studied in Figure 19(b), where the training is simulated in a realistic scenario and each global communication round comes with an additional delay of 1 second.
Surprisingly, even for the global synchronization with straggling workers and severe 50 seconds delay per global communication round, Figure 19(c) demonstrates that a large number of block steps (e g. H b (cid:16) 16 ) still manages to fully overcome the communication bottleneck with no/trivial performance damage.
[Table]
Hierarchical local SGD offers improved scaling and better test accuracy.
Table 17 compares the mini-batch SGD with hierarchical local SGD for ﬁxed product H (cid:4) H b (cid:16) 16 under different network topologies, with the same training procedure.
We can observe that for a heterogeneous system with a sufﬁcient block size, hierarchical local SGD with a sufﬁcient number of block update steps can further improve the generalization performance of local SGD training.
More precisely, when H (cid:4) H b is ﬁxed, hierarchical local SGD with more frequent inner-node synchronizations ( H b ¡ 1 ) outperforms local SGD ( H b (cid:16) 1 ), while still maintaining the beneﬁts of signiﬁcantly reduced communication by the inner synchronizations within each node.
In summary, as witnessed by Table 17, hierarchical local SGD outperforms both local SGD and mini-batch SGD in terms of training speed as well as model performance , especially for the training across nodes where inter-node connection is slow but intra-node communication is more efﬁcient.
E C OMMUNICATION S CHEMES
This section evaluates the communication cost in terms of the number of local steps and block steps, and formalizes the whole communication problem below.
Assume K computing devices uniformly distributed over K 1 servers, where each server has KKdevices.
The hierarchical local SGD training procedure will access N total samples with local mini-batch size B , with H local steps and H b block steps.
The MPI communication scheme (Gropp et al., 1999) is introduced for communication cost evaluation.
More precisely, we use general all-reduce, e.g., recursive halving and doubling algorithm (Thakur et al., 2005;
Rabenseifner, 2004), for gradient aggregation among K computation devices.
For each all-reduce communication, it introduces C (cid:4) log 2 K communication cost, where C is the message transmission time plus network latency.
The communication cost under our hierarchical local SGD setting is mainly determined by the number of local steps and block steps.
The KT models within each server synchronize the gradients for every
H local mini-batch, and it only performs global gradients aggregation of K local models after H b block updates.
Thus, the total number of synchronizations among compute devices is reduced to r
N KB (cid:4) HH b s , and we can formulate the overall communication cost ˜ C as:
[Equation]
where C 1 is the single message passing cost for compute devices within the same server, C 2 is the cost of that across servers, and obviously C 1 !
C 2 .
We can easily witness that the number of block steps H b is more deterministic in terms of communication reduction than local step H .
Empirical evaluations can be found in Section D.3.
Also, note that our hierarchical local SGD is orthogonal to the implementation of gradient aggregation (Goyal et al., 2017) optimized for the hardware, but focusing on overcoming the aggregation cost of more general distributed scenarios, and can easily be integrated with any optimized all-reduce implementation.
F D ISCUSSION AND F UTURE W ORK
Data distribution patterns.
In our experiments, the dataset is globally shufﬂed once per epoch and each local worker only accesses a disjoint part of the training data.
Removing shufﬂing altogether, and instead keeping the disjoint data parts completely local during training might be envisioned for extremely large datasets which can not be shared, or also in a federated scenario where data locality is a must for privacy reasons.
This scenario is not covered by the current theoretical understanding of local SGD, but will be interesting to investigate theoretically and practically.
Better learning rate scheduler for local SGD.
We have shown in our experiments that local SGD delivers consistent and signiﬁcant improvements over the state-of-the-art performance of mini-batch
SGD.
For ImageNet, we simply applied the same conﬁguration of “large-batch learning schemes” by Goyal et al.
However, this set of schemes was speciﬁcally developed and tuned for mini-batch SGD only, not for local SGD.
For example, scaling the learning rate w.r.t.
the global mini-batch size ignores the frequent local updates where each local model only accesses local minibatches for most of the time.
Therefore, it is expected that speciﬁcally deriving and tuning a learning rate scheduler for local SGD would lead to even more drastic improvements over mini-batch SGD, especially on larger tasks such as ImageNet.
Adaptive local SGD.
As local SGD achieves better generalization than current mini-batch SGD approaches, an interesting question is if the number of local steps H could be chosen adaptively, i.e. change during the training phase.
This could potentially eliminate or at least simplify complex learning rate schedules.
Furthermore, recent works (Loshchilov & Hutter, 2017; Huang et al., 2017a)
leverage cyclic learning rate schedules either improving the general performance of deep neural network training, or using an ensemble multiple neural networks at no additional training cost.
Adaptive local SGD could potentially achieve similar goals with reduced training cost.
Hierarchical local SGD design.
Hierarchical local SGD provides a simple but efﬁcient training solution for devices over the complex heterogeneous system.
However, its performance might be impacted by the cluster topology.
For example, the topology of 8 (cid:2) 2 -GPU in Table 17 fails to further improve the performance of local SGD by using more frequent inner node synchronizations.
On contrary, sufﬁciently large size of the GPU block could easily beneﬁt from the block update of hierarchical local SGD, for both communication efﬁciency and training quality.
The design space of hierarchical local SGD for different cluster topologies should be further investigated, e.g., to investigate the two levels of model averaging frequency (within and between blocks) in terms of convergence, and the interplay of different local minima in the case of very large number of local steps.
Another interesting line of work, explores heterogenous systems by allowing for different number of local steps on different clusters, thus making up for slower machines.