Simple Algorithm
Deep Learning · Emergence · 28 min

Gradient Noise, Batch Size & Scaling Rules

The SDE view of SGD, the gradient noise scale and the critical batch size.

Change the batch size and you must change the learning rate, but by how much, and how far does a bigger batch keep paying? This lesson treats SGD's noise quantitatively three ways: as a diffusion whose temperature is η/B\eta/B, with an exact stationary spread and fluctuation–dissipation identities; as a per-step trade-off that defines the gradient noise scale and the critical batch size; and as an implicit regularizer that every finite step adds to the loss.

What you’ll learn

  • State the weak-approximation theorem for stochastic modified equations, derive the linear scaling rule as an invariance of the SDE, state the square-root rule for Adam, and say where both fail.
  • Derive the Ornstein–Uhlenbeck stationary variance ησ2/(2Bh)\eta\sigma^2/(2Bh), compare it with the exact discrete result, and prove the fluctuation–dissipation relation E[θ⋅∇L]=η2E∥g∥2\E[\boldsymbol\theta\cdot\nabla\loss]=\frac\eta2\E\norm{\mathbf g}^2.
  • Derive the optimal step and progress per step as functions of BB, the gradient noise scale and the steps–examples trade-off, and estimate the noise scale from two batch sizes.
  • Derive the implicit regularizer η4∥∇L∥2\frac\eta4\norm{\nabla\loss}^2 of gradient descent by backward error analysis, and state its stochastic counterpart.

SGD as a diffusion

The Machine Learning course's Batch Size, Learning Rate & Noise introduces this diffusion picture and the critical batch size; here both are made precise and taken further. One SGD step is θk+1=θk−η∇L(θk)−ηξk\boldsymbol\theta_{k+1}=\boldsymbol\theta_k-\eta\nabla\loss(\boldsymbol\theta_k)-\eta\boldsymbol\xi_k, with noise Eξk=0\E\boldsymbol\xi_k=\mathbf 0 and Cov⁡ξk=Σ(θk)/B\Cov\boldsymbol\xi_k=\Sigma(\boldsymbol\theta_k)/B. Measure time in units of the learning rate, t=kηt=k\eta. In one step the drift moves θ\boldsymbol\theta as far as the gradient flow θ˙=−∇L\dot{\boldsymbol\theta}=-\nabla\loss does in time η\eta, and the noise adds covariance η2Σ/B\eta^2\Sigma/B, which is what a Brownian motion with diffusion matrix ηΣ/B\eta\Sigma/B accumulates in time η\eta. Matching these two moments gives a stochastic differential equation:

dΘt=−∇L(Θt) dt+ηB  Σ(Θt)1/2 dWtd\boldsymbol\Theta_t=-\nabla\loss(\boldsymbol\Theta_t)\,dt+\sqrt{\frac{\eta}{B}}\;\Sigma(\boldsymbol\Theta_t)^{1/2}\,d\mathbf W_t
Wt\mathbf W_t is a standard Brownian motion. The learning rate and batch size enter only through the noise scale η/B\eta/B (Mandt, Hoffman & Blei, 2017; Jastrzębski et al., 2017; Smith & Le, 2018, whose loss is a sum over the NN training examples rather than a mean, so they write it as ϵN/B\epsilon N/B).
DerivationScaling rules as invariances of the SDE
  1. κηκB=ηB\frac{\kappa\eta}{\kappa B}=\frac{\eta}{B}

    Multiply the batch size by κ\kappa and the learning rate by κ\kappa. The diffusion coefficient η/B\sqrt{\eta/B} does not change, and neither does the drift: it is literally the same equation.

  2. S=Tκη,E=κB⋅Tκη=BTηS=\frac{T}{\kappa\eta},\qquad E=\kappa B\cdot\frac{T}{\kappa\eta}=\frac{BT}{\eta}

    Time advances by η\eta per step, so reaching time TT takes κ\kappa times fewer steps, each with κ\kappa times more examples. While the SDE approximates both runs, the larger batch reaches the same distribution of outcomes in κ\kappa times fewer steps and the same number of examples: perfect scaling, which is the linear scaling rule.

  3. B→κB:η→κ η,1−βi→κ (1−βi),ϵ→ϵ/κB\to\kappa B:\qquad\eta\to\sqrt\kappa\,\eta,\qquad1-\beta_i\to\kappa\,(1-\beta_i),\qquad\epsilon\to\epsilon/\sqrt\kappa

    Adaptive methods divide the step by a running root-mean-square of the gradient, which itself grows with the noise, so the matching changes. For RMSprop and Adam, Malladi, Lyu, Panigrahi & Arora (2022) derive SDEs whose invariance gives the square-root scaling rule, which also rescales the averaging horizons and ϵ\epsilon:

Where the picture breaks. Both rules are small-learning-rate statements: the theorem holds as η→0\eta\to0 over a fixed horizon, while practical runs use nearly the largest stable rates for many epochs. Li, Malladi & Arora (2021) built an efficient way to simulate the SDE (stochastic variance amplified gradient, SVAG) and proved a testable necessary condition for the approximation, whose best-known consequence is the linear scaling rule itself. Read backwards: where linear scaling fails, as it does beyond about 8,000 images per batch for ResNet-50 on ImageNet (Goyal et al., 2017), the SDE has stopped describing SGD. The SDE also keeps only the first two moments of the noise. Simsekli, Sagun & Gürbüzbalaban (2019) measured heavy-tailed gradient noise and argued for Lévy-driven dynamics instead; how Gaussian the noise is at practical batch sizes is still debated.

The stationary spread in a basin

Near a minimum, treat the loss as quadratic and the noise as constant. In one dimension, take L(θ)=h2θ2\loss(\theta)=\frac h2\theta^2 with the minimum at 00, and let the per-example gradients have variance σ2\sigma^2. The SDE becomes an Ornstein–Uhlenbeck process, and the actual algorithm can be solved too.

DerivationOrnstein–Uhlenbeck versus discrete SGD
  1. dΘt=−hΘt dt+ησ2B dWt⟹dvdt=−2hv+ησ2Bd\Theta_t=-h\Theta_t\,dt+\sqrt{\frac{\eta\sigma^2}{B}}\,dW_t\quad\Longrightarrow\quad\frac{dv}{dt}=-2hv+\frac{\eta\sigma^2}{B}

    The SDE is linear. Itô's formula applied to Θ2\Theta^2 gives an ordinary differential equation for the second moment v(t)=EΘt2v(t)=\E\Theta_t^2:

  2. v∞=ησ22Bh,EL−L⋆=h2v∞=ησ24Bv_\infty=\frac{\eta\sigma^2}{2Bh},\qquad\E\loss-\loss^\star=\frac h2v_\infty=\frac{\eta\sigma^2}{4B}

    Its fixed point is the stationary variance. The excess loss h2v\frac h2v then does not depend on the curvature at all:

  3. v∞SGD=η2σ2/B1−(1−ηh)2=ησ2Bh (2−ηh)=22−ηh  v∞v_\infty^{\text{SGD}}=\frac{\eta^2\sigma^2/B}{1-(1-\eta h)^2}=\frac{\eta\sigma^2}{Bh\,(2-\eta h)}=\frac{2}{2-\eta h}\;v_\infty

    Now the real algorithm: θk+1=(1−ηh)θk−ηξk\theta_{k+1}=(1-\eta h)\theta_k-\eta\xi_k with Var⁡ξk=σ2/B\Var\xi_k=\sigma^2/B, so vk+1=(1−ηh)2vk+η2σ2/Bv_{k+1}=(1-\eta h)^2v_k+\eta^2\sigma^2/B, whose fixed point is

  4. HS+SH=ηB C⟹EL−L⋆=12Tr⁡(HS)=η4BTr⁡CHS+SH=\frac{\eta}{B}\,C\quad\Longrightarrow\quad\E\loss-\loss^\star=\tfrac12\Tr(HS)=\frac{\eta}{4B}\Tr C

    The SDE is right to leading order in ηh\eta h and wrong near the stability threshold: as ηh→2\eta h\to2 the true variance blows up while the SDE's stays finite, and beyond it the SDE still predicts a stationary state where SGD diverges. In dd dimensions, with Hessian H≻0H\succ0 and noise covariance C/BC/B, the stationary covariance SS of the SDE solves a Lyapunov equation, and taking its trace gives the excess loss without solving for SS:

To leading order, a constant-step run hovers at an excess loss of η4BTr⁡C\frac{\eta}{4B}\Tr C: set by the total gradient noise at the minimum, not by the curvature. Curvature decides only where the spread goes; when CC and HH commute, S=η2BCH−1S=\frac{\eta}{2B}CH^{-1}, so sharp directions fluctuate less. Halve η\eta or double BB and the floor halves. Mandt, Hoffman & Blei (2017) used this picture to tune constant-step SGD so that its stationary distribution approximates a Bayesian posterior.

Both sides of the relation are cheap to measure during training, so it doubles as an equilibrium detector. Yaida proposed tracking running averages of θ⋅∇LB\boldsymbol\theta\cdot\nabla\loss_{\mathcal B} and η2∥g∥2\frac\eta2\norm{\mathbf g}^2 and cutting η\eta by 10% whenever they agree to within 1%: a schedule that decays exactly when the run has reached its noise floor. The relation extends to momentum with a modified right-hand side.

Predict before you look

A constant-rate run has settled on its noise floor. You double the batch size and keep η\eta. By what factor does the excess loss at stationarity change?

Show the answer

0.5

The excess loss is η4BTr⁡C\frac{\eta}{4B}\Tr C to leading order, so it halves. In the noisy quadratic model the exact floor, η2B∑ihi2−ηhi\frac{\eta}{2B}\sum_i\frac{h_i}{2-\eta h_i}, is proportional to 1/B1/B as well. Doubling η\eta instead would roughly double it, and slightly more, since the factor 22−ηh\frac{2}{2-\eta h} grows with η\eta.

How much does a bigger batch buy?

The SDE says what stays the same when η\eta and BB scale together, not how far the scaling can go. McCandlish, Kaplan, Amodei and the OpenAI Dota Team (2018) asked a sharper question: how much can one step achieve with batch BB if its size is chosen optimally? Expand the loss to second order around the current point, with gradient GG, Hessian HH and per-example covariance Σ\Sigma.

DerivationThe optimal step and the gradient noise scale
  1. E[L(θ)−L(θ−ϵgB)]≈ϵ∥G∥2−ϵ22(G⊤HG+Tr⁡(HΣ)B)\E\big[\loss(\boldsymbol\theta)-\loss(\boldsymbol\theta-\epsilon\mathbf g_B)\big]\approx\epsilon\norm G^2-\frac{\epsilon^2}{2}\Big(G^\top HG+\frac{\Tr(H\Sigma)}{B}\Big)

    Average over the batch, using EgB=G\E\mathbf g_B=G and E[gB⊤HgB]=G⊤HG+Tr⁡(HΣ)/B\E[\mathbf g_B^\top H\mathbf g_B]=G^\top HG+\Tr(H\Sigma)/B. A step −ϵgB-\epsilon\mathbf g_B lowers the expected loss by

  2. ϵopt(B)=ϵmax⁡1+Bnoise/B,ΔLopt(B)=ΔLmax⁡1+Bnoise/B,Bnoise=Tr⁡(HΣ)G⊤HG\epsilon_{\text{opt}}(B)=\frac{\epsilon_{\max}}{1+B_{\text{noise}}/B},\qquad\Delta\loss_{\text{opt}}(B)=\frac{\Delta\loss_{\max}}{1+B_{\text{noise}}/B},\qquad B_{\text{noise}}=\frac{\Tr(H\Sigma)}{G^\top HG}

    This is a concave quadratic in ϵ\epsilon. Its maximizer and maximum are the infinite-batch values ϵmax⁡=∥G∥2/G⊤HG\epsilon_{\max}=\norm G^2/G^\top HG and ΔLmax⁡=12∥G∥4/G⊤HG\Delta\loss_{\max}=\frac12\norm G^4/G^\top HG, both discounted by the same factor:

  3. Bsimple=Tr⁡Σ∥G∥2B_{\text{simple}}=\frac{\Tr\Sigma}{\norm G^2}

    For B≪BnoiseB\ll B_{\text{noise}} the best step grows linearly with BB, the linear scaling rule again but now with a known slope, and so does the progress per step. For B≫BnoiseB\gg B_{\text{noise}} both saturate and extra examples are wasted. If HH is close to a multiple of the identity, the noise scale becomes a ratio that can be measured:

  4. (SSmin⁡−1)(EEmin⁡−1)=BnoiseB⋅BBnoise=1,Bcrit=Emin⁡Smin⁡\Big(\frac{S}{S_{\min}}-1\Big)\Big(\frac{E}{E_{\min}}-1\Big)=\frac{B_{\text{noise}}}{B}\cdot\frac{B}{B_{\text{noise}}}=1,\qquad B_{\text{crit}}=\frac{E_{\min}}{S_{\min}}

    For a fixed amount of progress the number of steps scales like 1/ΔLopt1/\Delta\loss_{\text{opt}}, so S=Smin⁡(1+Bnoise/B)S=S_{\min}(1+B_{\text{noise}}/B) and the number of examples is E=BS=Emin⁡(1+B/Bnoise)E=BS=E_{\min}(1+B/B_{\text{noise}}), with Emin⁡=Smin⁡BnoiseE_{\min}=S_{\min}B_{\text{noise}}. Eliminating BB leaves a hyperbola:

Predict before you look

A training run is allowed only 1.5 times the minimum number of examples, E=1.5Emin⁡E=1.5E_{\min}. How many times the minimum number of steps Smin⁡S_{\min} does it take?

Show the answer

3

(S/Smin⁡−1)(1.5−1)=1(S/S_{\min}-1)(1.5-1)=1 gives S=3Smin⁡S=3S_{\min}. At E=2Emin⁡E=2E_{\min} the run would sit at the critical batch size, the knee where time and computation are both twice their minimum. Toward small example budgets the curve steepens fast: 1.25Emin⁡1.25E_{\min} examples need 5Smin⁡5S_{\min} steps, and as EE approaches Emin⁡E_{\min} the number of steps grows without bound.

In a real run the noise scale changes, so McCandlish et al. fit Smin⁡S_{\min} and Emin⁡E_{\min} to whole training runs; their model predicts Bcrit≈BnoiseB_{\text{crit}}\approx B_{\text{noise}} "appropriately averaged over training". The critical batch size varies enormously across tasks, from about 20 for an SVHN autoencoder to millions for the Dota game-playing agents, and within a run it grows severalfold to more than a hundredfold, because ∥G∥2\norm G^2 shrinks as the loss falls while Tr⁡Σ\Tr\Sigma does not:

TaskBcritB_{\text{crit}} early in trainingBcritB_{\text{crit}} averaged over training
MNIST20200
CIFAR-10300900
ImageNet1,00015,000
Dota 1v1 (reinforcement learning)50,0003,000,000
Measured critical batch sizes in examples, from McCandlish et al. (2018), Table 1. The simple noise scale BsimpleB_{\text{simple}} tracked the critical batch size across tasks, typically within about an order of magnitude.

Measuring it. Data-parallel training gives two batch sizes for free: each device's local batch BsmallB_{\text{small}} and the averaged global batch BbigB_{\text{big}}. Since E∥gB∥2=∥G∥2+Tr⁡Σ/B\E\norm{\mathbf g_B}^2=\norm G^2+\Tr\Sigma/B, two measurements yield unbiased estimates of both pieces. Their ratio is biased, so McCandlish et al. smooth each piece with a moving average before dividing.

∥G∥2^=Bbig∥gBbig∥2−Bsmall∥gBsmall∥2Bbig−Bsmall,Tr⁡Σ^=∥gBsmall∥2−∥gBbig∥21/Bsmall−1/Bbig\widehat{\norm G^2}=\frac{B_{\text{big}}\norm{\mathbf g_{B_{\text{big}}}}^2-B_{\text{small}}\norm{\mathbf g_{B_{\text{small}}}}^2}{B_{\text{big}}-B_{\text{small}}},\qquad\widehat{\Tr\Sigma}=\frac{\norm{\mathbf g_{B_{\text{small}}}}^2-\norm{\mathbf g_{B_{\text{big}}}}^2}{1/B_{\text{small}}-1/B_{\text{big}}}
Both follow by solving the two equations E∥gB∥2=∥G∥2+Tr⁡Σ/B\E\norm{\mathbf g_B}^2=\norm G^2+\Tr\Sigma/B for the two unknowns.
Check your understanding

On each device, batches of 16 give an average squared gradient norm of 5.05.0; the averaged batch of 256 gives 1.251.25. What is the estimate of BsimpleB_{\text{simple}}?

  1. 44
  2. 1616
  3. 6464
  4. 256256
Show the answer

C. 6464

Tr⁡Σ^=(5−1.25)/(116−1256)=3.75⋅25615=64\widehat{\Tr\Sigma}=(5-1.25)/(\tfrac1{16}-\tfrac1{256})=3.75\cdot\tfrac{256}{15}=64 and ∥G∥2^=(256⋅1.25−16⋅5)/240=1\widehat{\norm G^2}=(256\cdot1.25-16\cdot5)/240=1, so Bsimple=64B_{\text{simple}}=64. Check: 1+64/16=51+64/16=5 and 1+64/256=1.251+64/256=1.25. Batches well below 64 are noise-dominated, so growing them still buys nearly linear speed-ups.

Language models and optimizers. Kaplan et al. (2020) found that for language models the critical batch size depends on the loss alone and not on model size, Bcrit(L)≈B∗/L1/αBB_{\text{crit}}(L)\approx B_*/L^{1/\alpha_B} with B∗≈2×108B_*\approx2\times10^8 tokens, αB≈0.21\alpha_B\approx0.21 and LL the loss in nats. Later work separated the effects of data and model size. Training language models of 85 million to 1.2 billion parameters, Zhang et al. (2025) found that the critical batch size grows mainly with the amount of training data rather than with model size. Measuring it directly with a small amount of extra training, Merrill, Arora, Groeneveld & Hajishirzi (2025) found that it starts near zero, rises quickly and then plateaus; growing the batch size to match trained a 1-billion-parameter OLMo model with 43% fewer gradient steps at slightly better loss. The optimizer matters as well: in the noisy quadratic model, momentum leaves small-batch training unchanged but extends perfect scaling to larger batches, and preconditioners such as Adam and K-FAC raise the critical batch size further, in line with experiments on real networks (Zhang et al., 2019; Shallue et al., 2019).

The regularizer hidden in a finite step

Even without noise, a finite step does not follow the gradient flow. Backward error analysis, a tool from numerical integration, asks which modified flow the discrete iterates follow exactly, up to higher-order terms.

DerivationImplicit gradient regularization (Barrett & Dherin, 2021)
  1. θ(η)=θ−η∇L+η2 f1+η22 H∇L+O(η3)\boldsymbol\theta(\eta)=\boldsymbol\theta-\eta\nabla\loss+\eta^2\,\mathbf f_1+\frac{\eta^2}{2}\,H\nabla\loss+\order{\eta^3}

    Look for a flow θ˙=−∇L+η f1(θ)\dot{\boldsymbol\theta}=-\nabla\loss+\eta\,\mathbf f_1(\boldsymbol\theta) whose solution after time η\eta matches one gradient step up to O(η3)\order{\eta^3}. Since θ¨=−Hθ˙=H∇L+O(η)\ddot{\boldsymbol\theta}=-H\dot{\boldsymbol\theta}=H\nabla\loss+\order\eta, a Taylor expansion of the flow gives

  2. f1=−12H∇L=−14∇∥∇L∥2\mathbf f_1=-\tfrac12H\nabla\loss=-\tfrac14\nabla\norm{\nabla\loss}^2

    Gradient descent lands exactly at θ−η∇L\boldsymbol\theta-\eta\nabla\loss, so the η2\eta^2 terms must cancel. The correction turns out to be a gradient itself:

  3. L~GD=L+η4∥∇L∥2\tilde\loss_{\text{GD}}=\loss+\frac\eta4\norm{\nabla\loss}^2

    So gradient descent with step η\eta follows, to this order, the gradient flow of a modified loss that penalizes steep regions. It is the same correction that turns the first-order stochastic modified equation into the second-order one.

For SGD with random reshuffling, Smith, Dherin, Barrett & De (2021) showed that over one epoch the mean iterate, averaged over batch orders, follows a modified loss built from the m=n/Bm=n/B batch losses L^k\hat\loss_k:

L~SGD=L+η4m∑k=1m∥∇L^k∥2=L+η4∥∇L∥2+η4m∑k=1m∥∇L^k−∇L∥2\tilde\loss_{\text{SGD}}=\loss+\frac{\eta}{4m}\sum_{k=1}^{m}\norm{\nabla\hat\loss_k}^2=\loss+\frac\eta4\norm{\nabla\loss}^2+\frac{\eta}{4m}\sum_{k=1}^{m}\norm{\nabla\hat\loss_k-\nabla\loss}^2
The two forms agree because the batch-gradient deviations sum to zero. Averaged over shuffles, the last term equals n−Bn−1⋅η4BTr⁡Σ\frac{n-B}{n-1}\cdot\frac{\eta}{4B}\Tr\Sigma: a penalty on gradient disagreement whose strength is the noise scale η/B\eta/B. Keeping η/B\eta/B fixed keeps this implicit regularizer fixed, another route to the linear scaling rule.

Both results assume small but finite steps and describe average behavior. They also suggest experiments, which have been run. Smith et al. found that adding the regularizer to the loss explicitly improves test accuracy when the learning rate is small, and Geiping, Goldblum, Pope, Moeller & Goldstein (2022) matched SGD's accuracy on CIFAR-10 with non-stochastic, full-batch training by adding an explicit gradient-norm penalty, together with more steps and aggressive gradient clipping. Over longer times, noise also acts along the valley of minimizers. Once SGD reaches a manifold of zero-loss solutions, its noise drives a slow drift along the manifold on a timescale of η−2\eta^{-2} steps; for SGD with label noise, that drift lowers the trace of the Hessian, a measure of sharpness (Blanc et al., 2020; Li, Wang & Arora, 2022).

Key takeaways

  • To first order in η\eta, SGD is weakly approximated over a fixed horizon by dΘ=−∇L dt+η/B Σ1/2dWd\boldsymbol\Theta=-\nabla\loss\,dt+\sqrt{\eta/B}\,\Sigma^{1/2}d\mathbf W. Learning rate and batch size act through η/B\eta/B, so linear scaling keeps the SDE fixed; Adam's analogue is η∝B\eta\propto\sqrt B with 1−βi∝B1-\beta_i\propto B. Both rules fail as η\eta nears the stability threshold.
  • In a quadratic basin the stationary excess loss is η4BTr⁡C\frac{\eta}{4B}\Tr C, independent of curvature; the exact discrete variance is larger by 22−ηh\frac{2}{2-\eta h}. The fluctuation–dissipation relation E[θ⋅∇L]=η2E∥g∥2\E[\boldsymbol\theta\cdot\nabla\loss]=\frac\eta2\E\norm{\mathbf g}^2 holds exactly at stationarity and can trigger learning-rate decay.
  • One step with batch BB makes progress ΔLmax⁡/(1+Bnoise/B)\Delta\loss_{\max}/(1+B_{\text{noise}}/B) with Bnoise=Tr⁡(HΣ)/G⊤HG≈Tr⁡Σ/∥G∥2B_{\text{noise}}=\Tr(H\Sigma)/G^\top HG\approx\Tr\Sigma/\norm G^2. Steps and examples trade off as (S/Smin⁡−1)(E/Emin⁡−1)=1(S/S_{\min}-1)(E/E_{\min}-1)=1; the critical batch size grows severalfold or more during training and is larger for preconditioned optimizers.
  • A finite step adds the implicit regularizer η4∥∇L∥2\frac\eta4\norm{\nabla\loss}^2; SGD adds a penalty on batch-gradient disagreement with strength proportional to η/B\eta/B.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A run uses SGD with batch size 256 and learning rate 0.10.1. According to the SDE approximation, which run follows the same dynamics in time t=kηt=k\eta?

  1. Batch size 1,024 and learning rate 0.20.2
  2. Batch size 1,024 and learning rate 0.10.1
  3. Batch size 64 and learning rate 0.40.4
  4. Batch size 1,024 and learning rate 0.40.4
Show the answer

D. Batch size 1,024 and learning rate 0.40.4

The SDE depends on η\eta and BB only through η/B\eta/B; 0.4/1024=0.1/2560.4/1024=0.1/256. The new run needs four times fewer steps to reach the same time, with the same number of examples, as long as η\eta stays small enough for the approximation to hold.

Question 2

In the Ornstein–Uhlenbeck approximation of constant-step SGD on L=h2θ2\loss=\frac h2\theta^2 with per-example gradient variance σ2\sigma^2, how does the stationary excess loss depend on the curvature hh?

  1. It does not: it is ησ2/(4B)\eta\sigma^2/(4B) for every hh
  2. It grows in proportion to hh: sharper minima are noisier
  3. It is inversely proportional to hh, like the variance
  4. It grows like h2h^2
Show the answer

A. It does not: it is ησ2/(4B)\eta\sigma^2/(4B) for every hh

The variance ησ2/(2Bh)\eta\sigma^2/(2Bh) falls like 1/h1/h and the loss multiplies it by h/2h/2, so the curvature cancels. The exact discrete result multiplies this by 2/(2−ηh)2/(2-\eta h), which does depend on hh and blows up at the stability threshold.

Question 3

By backward error analysis, gradient descent with step η\eta follows, up to higher-order terms, the gradient flow of which modified loss?

  1. L−η4∥∇L∥2\loss-\frac\eta4\norm{\nabla\loss}^2
  2. L+η4∥∇L∥2\loss+\frac\eta4\norm{\nabla\loss}^2
  3. L+η2Tr⁡∇2L\loss+\frac\eta2\Tr\nabla^2\loss
  4. L\loss itself: gradient descent is an exact discretization
Show the answer

B. L+η4∥∇L∥2\loss+\frac\eta4\norm{\nabla\loss}^2

Matching one step with the flow over time η\eta forces the correction −12H∇L=−14∇∥∇L∥2-\frac12H\nabla\loss=-\frac14\nabla\norm{\nabla\loss}^2 into the drift. The extra term penalizes regions where the gradient is large; the same correction appears in the second-order stochastic modified equation.

Question 4

Early in training you use a batch size far below the gradient noise scale, B≪BnoiseB\ll B_{\text{noise}}. What does doubling BB, with the step size re-optimized, do?

  1. It halves the number of examples needed and leaves the steps unchanged
  2. Nothing: below the noise scale the batch size does not matter
  3. It nearly halves the number of steps needed, at nearly the same number of examples
  4. It doubles the progress per example
Show the answer

C. It nearly halves the number of steps needed, at nearly the same number of examples

With S=Smin⁡(1+Bnoise/B)≈Smin⁡Bnoise/BS=S_{\min}(1+B_{\text{noise}}/B)\approx S_{\min}B_{\text{noise}}/B for small BB, steps fall like 1/B1/B, while E=Emin⁡(1+B/Bnoise)≈Emin⁡E=E_{\min}(1+B/B_{\text{noise}})\approx E_{\min} hardly moves. That is perfect scaling; it ends around BcritB_{\text{crit}}.

Further reading

  • Q. Li, C. Tai & W. E, "Stochastic modified equations and dynamics of stochastic gradient algorithms I: Mathematical foundations," Journal of Machine Learning Research 20 (2019).
  • S. McCandlish, J. Kaplan, D. Amodei & the OpenAI Dota Team, "An empirical model of large-batch training," arXiv:1812.06162 (2018).
  • S. Malladi, K. Lyu, A. Panigrahi & S. Arora, "On the SDEs and scaling rules for adaptive gradient algorithms," NeurIPS (2022).
  • S. Yaida, "Fluctuation-dissipation relations for stochastic gradient descent," ICLR (2019).
  • S. L. Smith, B. Dherin, D. G. T. Barrett & S. De, "On the origin of implicit regularization in stochastic gradient descent," ICLR (2021).