3.2.5 · HinglishTraining Deep Networks

Adam and AdamW optimizers

1,867 words8 min readRead in English

3.2.5 · AI-ML › Training Deep Networks


Hume Adam ki zaroorat kyun hai?

Plain SGD har parameter ke liye same learning rate use karta hai:

Problem 1 — alag-alag scales. Deep nets mein, kuch parameters ko bahut bade gradients milte hain, doosron ko bahut chhote. Ek global kuch ke liye bahut bada hai, kuch ke liye bahut chhota.

Problem 2 — noisy stochastic gradients. Har minibatch ek noisy deta hai. Hum chahte hain ki noise average out ho jaye (momentum) aur saath hi normalize ho iske hisaab se ki har gradient kitna bada/variable hai.

Adam dono ka jawab deta hai, har parameter ke liye do exponential moving averages (EMAs) track karke.


Adam ko first principles se derive karna

Step 1 — First moment (momentum): direction ko smooth karo

Hum gradient ka EMA lete hain: Kyun? , — yaani average gradient — ko estimate karta hai. Yeh noise cancel karta hai aur consistent directions ko aage move karta rehta hai.

Step 2 — Second moment: magnitude ko smooth karo

Hum squared gradient (elementwise) ka EMA lete hain: Kyun? , — har coordinate mein gradient ki size/variance — ko estimate karta hai. Bada ⇒ woh direction steep/noisy hai ⇒ wahan chhote steps lo.

Step 3 — Bias correction (yeh hai clever wala hissa)

Kyunki hai, early EMAs zero ki taraf biased hote hain. Chaliye correction ko prove karte hain. Maano roughly stationary hai, mean ke saath. Unrolling karke: Expectations lete hain ke saath: Toh factor se bahut chhota hai. Ise divide out karo: Ab unbiased. Jab , aur correction khatam ho jaata hai.

Step 4 — Update


AdamW — decoupled weight decay

Adam-with-L2 (naive): decay ko gradient mein fold karo

AdamW: decay ko adaptive machinery ke bahar rakho

Figure — Adam and AdamW optimizers

Worked examples


Common mistakes (Steel-manned)


Recall

Recall Active recall — answers cover karo
  • Adam har parameter ke liye kaunse do statistics track karta hai? ⇒ Gradient ka EMA () aur squared gradient ka EMA ().
  • se divide kyun karte hain? ⇒ Har coordinate ko uski gradient magnitude se normalize karne ke liye → adaptive per-parameter learning rate.
  • Bias-correct kyun karte hain? ⇒ EMAs 0 par initialize hote hain, factor se biased low hain; ussse divide karne par yeh remove ho jaata hai.
  • Constant gradient par steady-state Adam step kya hai? ⇒ .
  • AdamW exactly kya change karta hai? ⇒ weight decay ko normalization ke bahar (decoupled) apply karta hai.
Recall Feynman: 12-saal ke bachche ko explain karo

Socho tum fog mein pahadi utaar rhe ho. Momentum () matlab hai yaad rakhna ki tum kis taraf chal rahe ho taaki zig-zag na ho. Magnitude tracker () notice karta hai kaunsi directions steep aur slippery hain, toh wahan tiny careful steps lo aur gentle slopes par bade confident steps lo. Bias correction isliye hai kyunki bilkul shuru mein tumhare paas koi memory nahi hoti, toh tum apne pehle guesses ko multiply up karte ho taaki woh fair lagein. AdamW ek rule add karta hai: "har step mein, apni saari cheezein thodi si zero ki taraf shrink karo, equally" — taaki kuch bhi bahut bada aur messy na ho jaye. Adam = smart footwork; AdamW = smart footwork plus tidy-up.


Flashcards

Adam first moment update formula
Adam second moment update formula
Adam bias-corrected estimates
,
Adam parameter update
Bias correction kyun zaroori hai
EMAs 0 par initialize hote hain, factor se zero ki taraf biased hain; ussse divide karne par estimate unbiased ho jaata hai.
Default Adam hyperparameters
ka interpretation
yeh ek signal-to-noise ratio hai; consistent gradients → step ≈ η, noisy gradients → chhota step.
Constant gradient g par steady-state Adam step
— magnitude se independent.
AdamW, Adam+L2 se kya change karta hai
weight decay ko normalization se bahar (decoupled) apply karta hai.
Adam+L2 decay galat kyun hai
term se divide ho jaata hai, toh decay uniform ki jagah gradient-dependent ban jaati hai.
AdamW update equation
ka role /0 avoid karne ke alawa
max effective learning rate () cap karta hai jab tiny ho.

Connections

  • Stochastic Gradient Descent — woh baseline jise Adam generalize karta hai.
  • Momentum and Nesterov Acceleration — first-moment term ka source.
  • RMSProp — second-moment normalization ka source.
  • Exponential Moving Average — core smoothing tool aur iska bias.
  • Weight Decay and L2 Regularization — jo AdamW decouple karta hai.
  • Learning Rate Schedules — warmup naturally Adam ki early instability ke saath pair hota hai.
  • Bias-Variance in Gradient Estimation — kyun hum gradients smooth karte hain.

Concept Map

too rigid for

motivates

used to build

used to build

smooths direction

smooths magnitude

biased toward zero

biased toward zero

gives

feeds

defines

decouple weight decay

Plain SGD one global lr

Scale + noise problems

Adam optimizer

Exponential moving average

First moment m_t

Second moment v_t

Momentum

RMSProp scaling

Bias correction

Unbiased m-hat v-hat

Update theta = -eta m-hat / sqrt v-hat

AdamW fixes regularization