Title: ON THE VARIANCE OF THE ADAPTIVE LEARNING RATE AND BEYOND

Abstract: The learning rate warmup heuristic achieves remarkable success in stabilizing training, accelerating convergence and improving generalization for adaptive stochastic optimization algorithms like RMSprop and Adam. Pursuing the theory behind warmup, we identify a problem of the adaptive learning rate -its variance is problematically large in the early stage, and presume warmup works as a variance reduction technique. We provide both empirical and theoretical evidence to verify our hypothesis. We further propose Rectified Adam (RAdam), a novel variant of Adam, by introducing a term to rectify the variance of the adaptive learning rate. Experimental results on image classification, language modeling, and neural machine translation verify our intuition and demonstrate the efficacy and robustness of RAdam.

1. INTRODUCTION:



Adam-eps:

Adam-2k Adam-vanilla RAdam Adam-warmup Fast and stable optimization algorithms are what generations of researchers have been pursuing (Gauss, 1823; Cauchy, 1847) . Remarkably, stochastic gradient-based optimization, such as stochastic gradient descent (SGD), has witnessed tremendous success in many fields of science and engineering despite its simplicity. Recently, many efforts have been made to accelerate optimization by applying adaptive learning rate.

In particular, Adagrad (Duchi et al., 2010) and its variants, e.g., RMSprop (Hinton et al., 2012) , Adam (Kingma & Ba, 2014) , Adadelta (Zeiler, 2012) and Nadam (Dozat, 2016) , stand out due to their fast convergence, and have been considered as the optimizer of choice in many applications.

However, it has been observed that these optimization methods may converge to bad/suspicious local optima, and have to resort to a warmup heuristic -using a small learning rate in the first few epochs of training to mitigate such problem (Vaswani et al., 2017; Popel & Bojar, 2018) . For example, when training typical Transformers based neural machine translation models on the De-En IWSLT'14 dataset, removing the warmup stage increases the training loss from 3 to around 10, as shown in Figure 1 . Similar phenomena are observed in other scenarios like BERT (a bidirectional transformer language model) pre-training (Devlin et al., 2019) .

Duo to the lack of the theoretical underpinnings, there is neither guarantee that warmup would bring consistent improvements for various machine learning settings nor guidance on how we should conduct warmup. Thus, researchers typically use different settings in different applications and have to take a trial-and-error approach, which can be tedious and time-consuming.

In this paper, we conduct both empirical and theoretical analysis of the convergence issue to identify its origin. We show that its root cause is: the adaptive learning rate has undesirably large variance in the early stage of model training, due to the limited amount of training samples being used. Thus, to reduce such variance, it is better to use smaller learning rates in the first few epochs of training, which justifies the warmup heuristic.

Inspired by our analysis results, we propose a new variant of Adam, called Rectified Adam (RAdam), which explicitly rectifies the variance of the adaptive learning rate based on derivations. We conduct extensive experiments on language modeling, image classification, and neural machine translation. RAdam brings consistent improvement over the vanilla Adam, which verifies the variance issue generally exists on various tasks across different network architectures.

In summary, our main contributions are two-fold:

• We identify the variance issue of the adaptive learning rate and present a theoretical justification for the warmup heuristic. We show that the convergence issue is due to the undesirably large variance of the adaptive learning rate in the early stage of model training. • We propose a new variant of Adam (i.e., RAdam), which not only explicitly rectifies the variance and is theoretically sound, but also compares favorably with the heuristic warmup.

2. PRELIMINARIES AND MOTIVATIONS:

Generic adaptive methods. Algorithm 1 is a generic framework (all operations are element-wise).

It describes various popular stochastic gradient descent algorithms (Reddi et al., 2018) . Specifically, different optimization algorithms can be specified by different choices of φ(.) and ψ(.), where φ(.) specifies how the momentum at time step t is calculated, and ψ(.) how the adaptive learning rate at t is calculated. For example, in the Adam algorithm, we have:

EQUATION

For numerical stability, the function ψ(.) in Equation 1 is usually calculated as ψ(g

1 , • • • , g t ) = √ 1-β t 2 + √ (1-β2) t i=1 β t-i 2 g 2 i

, where is a relatively small / negligible value (e.g., 1 × 10 -8 ).

Algorithm 1: Generic adaptive optimization method setup. All operations are element-wise.

Input: {α t } T t=1 : step size, {φ t , ψ t } T t=1 : function to calculate momentum and adaptive rate, θ 0 : initial parameter, f (θ): stochastic objective function. Output: θ T : resulting parameters while t = 1 to T do

g t ← ∆ θ f t (θ t-1 ) (Calculate gradients w.r.t. stochastic objective at timestep t) m t ← φ t (g 1 , • • • , g t ) (Calculate momentum) l t ← ψ t (g 1 , • • • , g t ) (Calculate adaptive learning rate) θ t ← θ t-1 -α t m t l t (Update parameters) return θ T

Learning rate warmup. Instead of setting the learning rate α t as a constant or in a decreasing order, a learning rate warmup strategy sets α t as smaller values in the first few steps, thus not satisfying ∀t α t+1 ≤ α t . For example, linear warmup sets α t = t α 0 when t < T w . Warmup has been demonstrated to be beneficial in many deep learning applications. For example, in the NMT experiments in Figure 1 , the training loss convergences around 10 when warmup is not applied (Adam-vanilla), and it surprisingly decreases to below 3 after applying warmup (Adam-warmup).

To further analyze this phenomenon, we visualize the histogram of the absolute value of gradients on a log scale in Figure 2 . We observe that, without applying warmup, the gradient distribution is distorted to have a mass center in relatively small values within 10 updates. Such gradient distortion means that the vanilla Adam is trapped in bad/suspicious local optima after the first few updates. Warmup essentially reduces the impact of these problematic updates to avoid the convergence problem. In the following sections, we focus our analysis on learning rate warmup for the Adam algorithm, while it can be applied to other algorithms that use similar adaptive learning rate (ψ(.)) designs, e.g., RMSprop (Hinton et al., 2012) and Nadam (Dozat, 2016) .

Iteration < -./0 -.1' -.1/ -.2 < -./0 -.1' -.1/ -.2 < -./0 -.1' -.1/ -.2 < -./0 -.1' -.1/ -.2 -.3

3. VARIANCE OF THE ADAPTIVE LEARNING RATE:

In this section, we first introduce empirical evidence, then analyze the variance of the adaptive learning rate to support our hypothesis -Due to the lack of samples in the early stage, the adaptive learning rate has an undesirably large variance, which leads to suspicious/bad local optima.

To convey our intuition, we begin with a special case. When t = 1, we have ψ(g 1 ) = 1/g2 1 . We view {g 1 , • • • , g t } as i.i.d. Gaussian random variables following N (0, σ 2 ) 2 . Therefore, 1/g 2 1 is subject to the scaled inverse chi-squared distribution, Scale-inv-X 2 (1, 1/σ 2 ), and Var[ 1/g 2 1 ] is divergent. It means that the adaptive ratio can be undesirably large in the first stage of learning. Meanwhile, setting a small learning rate at the early stage can reduce the variance (Var[αx] = α 2 Var[x]), thus alleviating this problem. Therefore, we suggest it is the unbounded variance of the adaptive learning rate in the early stage that causes the problematic updates.

3.1. WARMUP AS VARIANCE REDUCTION:

In this section, we design a set of controlled experiments to verify our hypothesis. Particularly, we design two variants of Adam that reducing the variance of the adaptive learning rate: Adam-2k and Adam-eps. We compare them to vanilla Adam with and without warmup on the IWSLT'14 German to English translation dataset (Cettolo et al., 2014) .

In order to reduce the variance of the adaptive learning rate (ψ(.)), Adam-2k only updates ψ(.) in the first two thousand iterations, while the momentum (φ(.)) and parameters (θ) are fixed3 ; other than this, it follows the original Adam algorithm. To make comparison with other methods, its iterations are indexed from -1999 instead of 1. In Figure 1 , we observe that, after getting these additional two thousand samples for estimating the adaptive learning rate, Adam-2k avoids the convergence problem of the vanilla-Adam. Also, comparing Figure 2 and Figure 3 , getting large enough samples prevents the gradient distribution from being distorted. These observations verify our hypothesis that the lack of sufficient data samples in the early stage is the root cause of the convergence issue.

Another straightforward way to reduce the variance is to increase the value of in ψ

(g 1 , • • • , g t ) = √ 1-β t 2 + √ (1-β2) t i=1 β t-i 2 g 2 i .

Actually, if we assume ψ(.) is subject to the uniform distribution, its variance equals to 1 12 2 . Therefore, we design Adam-eps, which uses a non-negligibly large = 10 -4 , while = 10 -8 for vanilla Adam. Its performance is summarized in Figure 1 . We observe that it does not suffer from the serious convergence problem of vanilla-Adam. This further demonstrates that the convergence problem can be alleviated by reducing the variance of the adaptive learning rate, and also explains why tuning is important in practice (Liu et al., 2019) . Besides, similar to Adam-2k, it prevents the gradient distribution from being distorted (as shown in Figure 3 ). However, as in Figure 1 , it produces a much worse performance comparing to Adam-2k and Adam-warmup. We conjecture that this is because large induces a large bias into the adaptive learning rate and slows down the optimization process. Thus, we need a more principled and rigorous way to control the variance of the adaptive learning rate. In the next subsection, we will present a theoretical analysis of the variance of the adaptive learning rate.

3.2. ANALYSIS OF ADAPTIVE LEARNING RATE VARIANCE:

As mentioned before, Adam uses the exponential moving average to calculate the adaptive learning rate. For gradients {g 1 , • • • , g t }, their exponential moving average has a larger variance than their simple average. Also, in the early stage (t is small), the difference of the exponential weights of

{g 1 , • • • , g t } is relatively small (up to 1 -β t-1

2 ). Therefore, for ease of analysis, we approximate the distribution of the exponential moving average as the distribution of the simple average (Nau, 2014) , i.e., p(ψ(.)) = p(

1-β t 2 (1-β2) t i=1 β t-i 2 g 2 i ) ≈ p( t t i=1 g 2 i ). Since g i ∼ N (0, σ 2 ), we have t t i=1 g 2 i ∼ Scale-inv-X 2 (t, 1 σ 2 )

. Therefore, we assume

1-β t 2 (1-β2) t i=1 β t-i 2 g 2

i also subjects to a scaled inverse chi-square distribution with ρ degrees of freedom (further analysis on this approximation is conducted in Section 5.3). Based on this assumption, we can calculate Var[ψ 2 (.)] and the PDF of ψ 2 (.). Now, we proceed to the analysis of its square root variance, i.e., Var[ψ(.)], and show how the variance changes with ρ (which corresponds to number of used training samples). ) ] monotonically decreases as ρ increases.

Theorem 1. If ψ 2 (.) ∼ Scale-inv-X 2 (ρ, 1 σ 2 ), Var[ψ(.

Proof. For ∀ ρ > 4, we have:

EQUATION

where B(.) is the beta function. By analyzing the derivative of Var[ψ(.)], we know it monotonically decreases as ρ increases. The detailed derivation is elaborated in the Appendix A.

Theorem 1 gives a qualitative analysis of the variance of the adaptive learning rate. It shows that, due to the lack of used training samples in the early stage, Var[ψ(.)] is larger than the late stage (Figure 8 ). To rigorously constraint the variance, we perform a quantified analysis on Var[ψ(.)] by estimating the degree of freedoms ρ.

4. RECTIFIED ADAPTIVE LEARNING RATE:

In the previous section, Equation 2gives the analytic form of Var[ψ(.)], where ρ is the degree of freedoms. Here, we first give an estimation of ρ based on t to conduct a quantified analysis for

Var[ψ(g 1 , • • • , g t )]

, then we describe the design of the learning rate rectification, and compare it to the heuristic warmup strategies.

4.1. ESTIMATION OF ρ:

The exponential moving average (EMA) can be interpreted as an approximation to the simple moving average (SMA) in real application (Nau, 2014) , i.e.,

EQUATION

)

Algorithm 2: Rectified Adam. All operations are element-wise.

Input: {α t } T t=1 : step size, {β 1 , β 2 }: decay rate to calculate moving average and moving 2nd moment, θ 0 : initial parameter, f t (θ): stochastic objective function. Output: θ t : resulting parameters m 0 , v 0 ← 0, 0 (Initialize moving 1st and 2nd moment)

ρ ∞ ← 2/(1 -β 2 ) -1 (Compute the maximum length of the approximated SMA) while t = {1, • • • , T } do g t ← ∆ θ f t (θ t-1 ) (Calculate gradients w.r.t. stochastic objective at timestep t) v t ← 1/β 2 v t-1 + (1 -β 2 )g 2 t (Update exponential moving 2nd moment) m t ← β 1 m t-1 + (1 -β 1 )g t (Update exponential moving 1st moment) m t ← m t /(1 -β t 1 ) (Compute bias-corrected moving average) ρ t ← ρ ∞ -2tβ t 2 /(1 -β t 2 )(Compute the length of the approximated SMA)

if the variance is tractable, i.e., ρ t > 4 then where f (t, β 2 ) is the length of the SMA which allows the SMA to have the same "center of mass" with the EMA. In other words, f (t, β 2 ) satisfies:

l t ← (1 -β t 2 )/v t (

EQUATION

By solving Equation 4, we have:

f (t, β 2 ) = 2 1-β2 -1 - 2tβ t 2 1-β t 2 .

In the previous section, we assume:

1-β t 2 (1-β2) t i=1 β t-i 2 g 2 i ∼ Scale-inv-X 2 (ρ, 1 σ 2 ).

Here, since g i ∼ N (0, σ 2 ), we have

f (t,β 2 ) i=1 g 2 t+1-i f (t,β2) ∼ Scale-inv-X 2 (f (t, β 2 ), 1 σ 2

). Thus, Equation 3 views Scale-inv-X 2 (f (t, β 2 ), 1 σ 2 ) as an approximation to Scale-inv-X 2 (ρ, 1 σ 2 ). Therefore, we treat f (t, β 2 ) as an estimation of ρ. For ease of notation, we mark f (t, β 2 ) as ρ t . Also, we refer 2 1-β2 -1 as ρ ∞ (maximum length of the approximated SMA), due to the inequality f (t,

β 2 ) ≤ lim t→∞ f (t, β 2 ) = 2 1-β2 -1.

4.2. VARIANCE ESTIMATION AND RECTIFICATION:

Based on previous estimations, we have

Var[ψ(.)] = τ 2 ( ρt ρt-2 -ρt 2 2ρ t -5 π B( ρt-1 2 , ρt-1 2 ) 2

). The value of this function in the early stage is significantly larger than the late stage (as analyzed later, it decays roughly at the speed of O( 1 ρt )). For example, the variance at ρ t = 5 is over 100 times larger than the variance at ρ t = 500. Additionally, based on Theorem 1, we know min ρt Var[ψ(.)] = Var[ψ(.)]| ρt=ρ∞ and mark this minimal value as C var . In order to ensure that the adaptive learning rate (ψ(.)) has consistent variance, we rectify the variance at the t-th timestamp as below,

Var[r t ψ(g 1 , • • • , g t )] = C var where r t = C var /Var[ψ(g 1 , • • • , g t )]

. Although we have the analytic form of Var[ψ(.)] (i.e., Equation 2), it is not numerically stable. Therefore, we use the first-order approximation to calculate the rectification term. Specifically, by approximating ψ 2 (.) to the first order (Wolter, 2007) ,

ψ 2 (.) ≈ E[ψ 2 (.)] + 1 2 E[ψ 2 (.)] (ψ 2 (.) -E[ψ 2 (.)]) and Var[ψ(.)] ≈ Var[ψ 2 (.)] 4 E[ψ 2 (.)] .

Since ψ 2 (.) ∼ Scale-inv-X 2 (ρ t , 1 σ 2 ), we have:

Var[ψ(.)] ≈ ρ t /[2(ρ t -2)(ρ t -4)σ 2 ].

(5) In Section 5.3, we conduct simulation experiments to examine Equation 5 and find that it is a reliable approximation. Based on Equation 5, we know that Var[ ψ(.)] decreases approximately at the With this approximation, we can calculate the rectification term as:

r t = (ρ t -4)(ρ t -2)ρ ∞ (ρ ∞ -4)(ρ ∞ -2)ρ t .

Applying our rectification term to Adam, we come up with a new variant of Adam, Rectified Adam (RAdam), as summarized in Algorithm 2. Specifically, when the length of the approximated SMA is less or equal than 4, the variance of the adaptive learning rate is intractable and the adaptive learning rate is inactivated. Otherwise, we calculate the variance rectification term and update parameters with the adaptive learning rate. It is worth mentioning that, if β 2 ≤ 0.6, we have ρ ∞ ≤ 4 and RAdam is degenerated to SGD with momentum.

4.3. IN COMPARISON WITH WARMUP AND OTHER STABILIZATION TECHNIQUES:

Different from the analysis in this paper, warmup is originally proposed to handle training with very large batches for SGD (Goyal et al., 2017; Gotmare et al., 2019; Bernstein et al., 2018; Xiao et al., 2017) . We notice that r t has a similar form to the heuristic linear warmup, which can be viewed as setting the rectification term as min(t,Tw)

Tw:

. It verifies our intuition that warmup works as a variance reduction technique. RAdam deactivates the adaptive learning rate when its variance is divergent, thus avoiding undesired instability in the first few updates. Besides, our method does not require an additional hyperparameter (i.e., T w ) and can automatically adapt to different moving average rules.

Here, we identify and address an underlying issue of adaptive optimization methods independent of (neural) model architectures. Thus, the proposed rectification term is orthogonal to other training stabilization techniques such as gradient clipping (Bengio et al., 2013) , smoothing the adaptive learning rate (i.e., increasing , applying geometric mean filter (Chen & Gu, 2018) , or adding range constraints (Luo et al., 2019) ), initialization (Balduzzi et al., 2017; Zhang et al., 2019) and normalization (Ba et al., 2016; Ioffe & Szegedy, 2015) . Indeed, these techniques can be combined with the proposed variance rectification method.

5. EXPERIMENTS:

We evaluate RAdam on several benchmarks: One Billion Word for language modeling; Cifar10 and ImageNet for image classification; IWSLT'14 De-En/EN-DE and WMT'16 EN-De for neural machine translation. Following Loshchilov & Hutter (2018) , we decouple weight decays in the vanilla Adam, Adam with warmup and RAdam in our experiments. Details are in Appendix B.

5.1. COMPARING TO VANILLA ADAM:

As analyzed before, the adaptive learning rate has undesirably large variance in the early stage of training and leads to suspicious/bad local optima on NMT. One question we are interested in Different learning rates lead to similar performance.

Sensitive to the choice of the learning rate.

X-axis is the epoch #. is: whether such an issue widely exits in other similar tasks and applications. Thus, we conduct a set of experiments with two classical tasks of NLP and CV, i.e., language modeling and image classification. RAdam not only results in consistent improvements over the vanilla Adam, but also demonstrates its robustness to the change of learning rates. It verifies that the variance issue exists in various machine learning applications, and has a big impact on the model behavior.

Performance Comparison.:

The performances on language modeling (i.e., One Billion Word (Chelba et al., 2013) ) and image classification (i.e., CIFAR10 (Krizhevsky et al., 2009) and ImageNet (Deng et al., 2009) ) are presented in Figure 4 , 5. The results show that RAdam outperforms Adam in all three datasets. As shown in Figure 4 , although the rectification term makes RAdam slower than the vanilla Adam in the first few epochs, it allows RAdam to converge faster after that. In other words, by reducing the variance of the adaptive learning rate in the early stage, it gets both faster convergence and better performance, which verifies the impact of the variance issue. We also observe that RAdam obtains consistent improvements over Adam on image classification. It is worth noting that, on both ImageNet and CIFAR10, although RAdam fails to outperform SGD in terms of test accuracy, it results in a better training performance (e.g., the training accuracy of SGD, Adam, and RAdam on ImageNet are 69.57, 69.12 and 70.30 respectively).

Robustness to Learning Rate Change. Besides performance improvements, RAdam also improves the robustness of model training. We use different initial learning rates, conduct experiments with ResNet-20 on the CIFAR10 datasets, and summarize their performance in Figure 6 . For learning rates within a broad range (i.e., {0.1, 0.03, 0.01, 0.003}), RAdam achieves consistent model performances (their test accuracy curves highly overlap with each other), while Adam and SGD are shown to be more sensitive to the learning rate. The observation can be interpreted that by rectifying the variance of the adaptive learning rate, RAdam improves the robustness of model training and can adapt to different learning rates of a broader range.

5.2. COMPARING TO HEURISTIC WARMUP:

To examine the effectiveness of RAdam, we first conduct comparisons on neural machine translation, on which the state-of-the-art employs Adam with the linear warmup. Specifically, we conduct experiments on three datasets, i.e., IWSLT'14 De-En, IWSLT'14 En-De, and WMT'16 En-De. Due to the limited size of the IWSLT'14 dataset, we conduct experiments using 5 different random seeds and report their mean and standard derivation. As discussed before, the vanilla Adam algorithm leads to suspicious/bad local optima (i.e., converges to a training perplexity around 500), and needs a learning rate warmup stage to stabilize the training.

We summarize the performance obtained with the heuristic warmup and our proposed rectification term in Table 2 and visualize the training curve of IWSLT De-En in Figure 1 . With a consistent adaptive learning rate variance, our proposed method achieves similar performance to that of previous state-of-the-art warmup heuristics. It verifies our intuition that the problematic updates of Adam are indeed caused by the undesirably large variance in the early stage.

Moreover, we applied Adam with warmup on the CIFAR10 dataset. Its best accuracy on the test set is 91.29, which is similar to RAdam (91.38). However, we found that RAdam requires less hyperparameter tuning. Specifically, we visualize their learning curves in Figure 7 . For some warmup steps, Adam with warmup is relatively more sensitive to the choice of the learning rate. RAdam, at the same time, is not only more robust, but also can automatically control the warmup behavior (i.e., without requiring the length of warmup). For example, when setting the learning rate as 0.1, Adam with 100 steps of warmup fails to get satisfying performance and only results in an accuracy of 90.13; RAdam successfully gets an accuracy of 91.06, with the original setting of the moving average calculation (i.e., β 1 = 0.9, β 2 = 0.999). We conjecture the reason is due to the fact that RAdam, which is based on a rigorous variance analysis, explicitly avoids the extreme situation where the variance is divergent, and rectifies the variance to be consistent in other situations.

5.3. SIMULATED VERIFICATION:

In Sections 3 and 4, we approximate Var[ t/ t i=1 g 2 i ] to the first order, and assume ψ 2 (.) =

1-β t 2 (1-β2) t i=1 β t-i 2 g 2 i

subjects to a scaled inverse chi-square distribution (this assumption covers the approximation from EMA to SMA). Here, we examine these two approximations using simulations.

First Order Approximation of Var:

[ t/ t i=1 g 2 i ].

To compare Equations 5 and 2, we assume τ = 1 and plot their values and difference for ν = {5, • • • , 500} in Figure 8 . The curve of the analytic form and the first-order approximation highly overlap, and their difference is much smaller than their value. This result verifies that our first-order approximation is very accurate.

Scaled Inverse Chi-Square Distribution Assumption. In this paper, we assume g i accords to a Normal distribution with a zero mean. We also assume ψ 2 (.) accords to the scaled inverse chi-square distribution to derive the variance of Var[ψ(.)], based on the similarity between the exponential moving average and simple moving average. Here, we empirically verify this assumption. Specifically, since g i in the optimization problem may not be zero-mean, we assume its expectation is µ and sample g i from N (µ, 1). Then, based on these samples, we calculate the variance of the original adaptive learning rate and the proposed rectified adaptive learning rate, i.e., Var[ 1 vt ] and Var[ rt vt ] respectively. We set β 2 to 0.999, the number of sampled trajectories to 5000, the number of iterations to 6000, and summarize the simulation results in Figure 9 . Across all six settings with different µ, the adaptive learning rate has a larger variance in the first stage and the rectified adaptive learning rate has relative consistent variance. This verifies the reliability of our assumption.

6. CONCLUSION:

In this paper, we explore the underlying principle of the effectiveness of the warmup heuristic used for adaptive optimization algorithms. Specifically, we identify that, due to the limited amount of samples in the early stage of model training, the adaptive learning rate has an undesirably large variance and can cause the model to converge to suspicious/bad local optima. We provide both empirical and theoretical evidence to support our hypothesis, and further propose a new variant of Adam, whose adaptive learning rate is rectified so as to have a consistent variance. Empirical results demonstrate the effectiveness of our proposed method. In future work, we plan to replace the rectification strategy by sharing the second moment estimation across similar parameters.

A PROOF OF THEOREM 1:

For ease of notation, we refer ψ 2 (.) as x and 1 σ 2 as τ 2 . Thus, x ∼ Scale-inv-X 2 (ρ, τ 2 ) and:

p(x) = (τ 2 ρ/2) ρ/2 Γ(ρ/2) exp[ -ρτ 2 2x ] x 1+ρ/2 and E[x] = ρ (ρ -2)σ 2 (∀ ρ > 2) (6)

where Γ(.) is the gamma function. Therefore, we have:

EQUATION

Based on Equation 6 and 7, for ∀ ρ > 4, we have:

EQUATION

where B(.) is the beta function. To prove the monotonic property of Var[ψ(.)], we need to show:

Lemma 1. for t ≥ 4, ∂ ∂t ( t t-2 -t 2 2t-5 π B( t-1 2 , t-1 2 ) 2 ) < 0

Proof. The target inequality can be re-wrote as ∂ ∂t

( t t -2 - t 2 2t-5 π B( t -1 2 , t -1 2 ) 2 ) = -2 (t -2) 2 - 2 2t-5 π B( t -1 2 , t -1 2 ) 2 - t 2 2t-5 ln 4 π B( t -1 2 , t -1 2 ) 2 - 2t 2 2t-5 π B( t -1 2 , t -1 2 ) 2 (Ψ( t -1 2 ) -Ψ(t -1)), Ψ(x) = Γ (x) Γ(x) < 0 This inequality is equivalent to: 64π (t -2) 2 4 t B( t-1 2 , t-1 2 ) 2 + 1 + t ln 4 + 2tΨ( t -1 2 ) > 2tΨ(t -1) (i) = t[Ψ( t -1 2 ) + Ψ( t 2 ) + ln 4],

where (i) is derived from Legendre duplication formula. Simplify the above inequality, we get:

64π (t -2) 2 4 t B( t-1 2 , t-1 2 ) 2 + 1 + tΨ( t -1 2 ) -tΨ( t 2 ) > 0, We only need to show 64π (t -2) 2 4 t B( t-1 2 , t-1 2 ) 2 + 1 + tΨ( t -1 2 ) -tΨ( t 2 ) ≥ 64π (t -2) 2 4 t B( t-1 2 , t-1 2 ) 2 + 2 + t(ln(t/2) -1/(t/2 -0.5)) -t ln(t/2) = 64π (t -2) 2 4 t B( t-1 2 , t-1 2 ) 2 - 2 t -1 > 64π (t -2) 2 4 t B( t-1 2 , t-1 2 ) 2 - 2 t -2 ≥ 0,

where the first inequality is from ln(x) -1/(2x) > Ψ(x) > ln(x + 0.5) -1/x.

Therefore, we only need to show

32π ≥ (t -2)4 t B( t -1 2 , t -1 2 ) 2 ,

which is equivalent to

(t -2)4 t B( t -1 2 , t -1 2 ) 2 = (t -2)4 t Γ( t-1 2 ) 4 Γ(t -1) 2 (i) = (t -2)4 t Γ( t-1 2 ) 2 Γ(t/2) 2 4 2-t π = 16π(t -2) Γ( t-1 2 ) 2 Γ(t/2) 2 ≤ 32π,

where (i) is from Legendre duplication formula.

So we only need to show

(t -2) Γ( t-1 2 ) 2 Γ(t/2) 2 ≤ 2 (9)

Using Gautschi's inequality ( Γ(x+1) Γ(x+s) < (x + 1) 1-s ), we have

(t -2) Γ( t-1 2 ) 2 Γ(t/2) 2 ≤ (t -2)( t -1 2 ) -1 = 2(t -2) t -1 < 2 (10) B IMPLEMENTATION DETAILS B.1 LANGUAGE MODELING

Our implementation is based on the previous work (Liu et al., 2018) . Specifically, we use two-layer LSTMs with 2048 hidden states with adaptive softmax to conduct experiments on the one billion words dataset. Word embedding (random initialized) of 300 dimensions is used as the input and the adaptive softmax is incorporated with a default setting (cut-offs are set to [4000, 40000, 200000] ).

Additionally, as pre-processing, we replace all tokens occurring equal or less than 3 times with as UNK, which shrinks the dictionary from 7.9M to 6.4M. Dropout is applied to each layer with a ratio of 0.1, gradients are clipped at 5.0. We use the default hyper-parameters to update moving averages, i.e.β 1 = 0.9 and β 2 = 0.999. The learning rate is set to start from 0.001, and decayed at the start of 10th epochs. LSTMs are unrolled for 20 steps without resetting the LSTM states and the batch size is set to 128. All models are trained on one NVIDIA Tesla V100 GPU.

B.2 IMAGEINE CLASSIFICATION:

We use the default ResNet architectures (He et al., 2016) in a public pytorch re-implementation4 . Specifically, we use 20-layer ResNet (9 Basic Blocks) for CIFAR-10 and 18-layer ResNet (8 Basic Blocks) for ImageNet. Batch size is 128 for CIFAR-10 and 256 for ImageNet. The model is trained for 186 epoches and the learning rate decays at the 81-th and the 122-th epoches by 0.1 on CIFAR-10, while the model is trained for 90 epoches and the learning rate decays at the 31-th and the 61-th epoch by 0.1 on ImageNet. For Adam and RAdam, we set β 1 = 0.9, β 2 = 0.999. For SGD, we set the momentum factor as 0.9. The weight decay rate is 10 -4 . Random cropping and random horizontal flipping are applied to training data.

B.3 NEURAL MACHINE TRANSLATION:

Our experiments are based on the default Transformers (Vaswani et al., 2017) implementation from the fairseq package (Ott et al., 2019) . Specifically, we use word embedding with 512 dimensions and 6-layer encoder / decoder with 4 head and 1024 hidden dimensions on the IWSLT14' dataset; use word embedding with 512 dimension and 6-layer encoder / decoder with 8 heads and 2048 hidden dimensions. Label smoothed cross entropy is used as the objective function with an uncertainty = 0.1 (Szegedy et al., 2016) . We use linear learning rate decay starting from 3e -4 , and the checkpoints of the last 20 epoches are averaged before evaluation. As to the wamrup strategy, we use a linear warmup for Adam in the first 4000 updates, and set β 2 to satisfy ν = 4000 (β 2 = 0.9995). In the IWSLT'14 dataset, we conduct training on one NVIDIA Tesla V100 GPU, set maximum batch size as 4000, apply dropout with a ratio 0.3, using weight decay of 0.0001 and clip the gradient norm at 25. In the WMT'16 dataset, we conduct training on four NVIDIA Quadro R8000 GPUs and set maximum batch size as 8196.

C DOWNGRADING TO SGDM:

As a byproduct determined by math derivations, we degenerated RAdam to SGD with momentum in the first several updates. Although this stage only contains several gradient updates, these up-dates could be quite damaging (e.g., in our Figure 2 , the gradient distribution is distorted within 10 gradient updates). Intuitively, updates with divergent adaptive learning rate variance could be more damaging than the ones with converged variance, as divergent variance implies more instability. As a case study, we performed experiments on the CIFAR10 dataset. Five-run average results are summarized in Table 3 . The optimizer fails to get an equally reliably model when changing the first 4 updates to Adam, yet the influence of switching is less deleterious when we change 5-8 updates instead. This result verifies our intuition and is in agreement with our theory the first few updates could be more damaging than later updates. By saying that, we still want to emphasize that this part (downgrading to SGDM) is only a minor part of our algorithm design whereas our main focus is on the mechanism of warmup and the derivation of the rectification term. 

:

The mean zero normal assumption is valid at the beginning of the training, since weights are sampled from normal distributions with mean zero(Balduzzi et al., 2017), further analysis is conducted in Section 5.3.

Different fromGotmare et al. (2019), all parameters and first moments are frozen in the first 2000 iterations.

https://github.com/bearpaw/pytorch-classification

Figures and Tables:

Figure 1: Training loss v.s. # of iterations of Transformers on the De-En IWSLT'14 dataset.

Figure 2: The absolute gradient histogram of the Transformers on the De-En IWSLT' 14 dataset during the training (stacked along the y-axis). X-axis is absolute value in the log scale and the height is the frequency. Without warmup, the gradient distribution is distorted in the first 10 steps.

Figure 4: Language modeling (LSTMs) on the One Billion Word.

Figure 5: Training of ResNet-18 on the ImageNet and ResNet-20 on the CIFAR10 dataset. speed of O( 1 ρt ).With this approximation, we can calculate the rectification term as:

Figure 6: Performance of RAdam, Adam and SGD with different learning rates on CIFAR10.

Figure 8: The value of Equation2, Equation 5 and their difference (absolute difference). The x-axis is ρ and the y-axis is the variance (log scale).

Figure 9: The simulation of Var[ 1 vt ] and Var[ ct vt]. The x-axis is iteration # (from 5), the y-axis is the variance (log scale).

Compute adaptive learning rate)

Table content: <table><tr><td>r t ← θ</td><td>(ρt-4)(ρt-2)ρ∞ (ρ∞-4)(ρ∞-2)ρt (Compute the variance rectification term)</td></tr></table>

Image Classification

Table content: <table><tr><td/><td>Method Acc.</td></tr><tr><td>CIFAR10</td><td>SGD Adam RAdam 91.38 91.51 90.54</td></tr><tr><td>ImageNet</td><td>SGD Adam RAdam 67.62 69.86 66.54</td></tr></table>

BLEU score on Neural Machine Translation.

Table content: <table><tr><td>Method</td><td colspan="3">IWSLT'14 DE-EN IWSLT'14 EN-DE WMT'16 EN-DE</td></tr><tr><td>Adam with warmup RAdam</td><td>34.66 ± 0.014 34.76 ± 0.003</td><td>28.56 ± 0.067 28.48 ± 0.054</td><td>27.03 27.27</td></tr></table>

Performance on CIFAR10 (lr = 0.1).

Table content: <table><tr><td>1-4 steps</td><td>5-8 steps</td><td>8+ steps</td><td>test</td><td>train</td><td>train</td></tr><tr><td/><td/><td/><td>acc</td><td>loss</td><td>error</td></tr><tr><td>RAdam</td><td>RAdam</td><td>RAdam</td><td>91.08</td><td>0.021</td><td>0.74</td></tr><tr><td colspan="2">Adam (w. divergent var.) RAdam</td><td>RAdam</td><td>89.98</td><td>0.060</td><td>2.12</td></tr><tr><td>SGD</td><td colspan="2">Adam (w. convergent var.) RAdam</td><td>90.29</td><td>0.038</td><td>1.23</td></tr></table>

Peer review (iclr2020):
Authors propose a way to rectify the variance of the adaptive learning rate (RAdam) and apply the optimizer to applications in image classification, language modeling and neural machine translation. The experiments demonstrate not only a strong results over baseline Adam with warmup learning rate but the robustness of the optimizer. The authors additionally demonstrate the theoretical justification behind their optimizer, however I am not very qualified to make the judgement on the theory. Overall judging from the authors description of approach and experimental results, I recommend acceptance.