Zubnet AIApprendreWiki › Adam Optimizer
Training

Adam Optimizer

Adam, AdamW
L'algorithme d'optimisation le plus largement utilisé pour entraîner les réseaux de neurones. Adam (Adaptive Moment Estimation) combine le momentum (utilisant une moyenne glissante des gradients passés) avec des learning rates adaptatifs (scalant les updates par l'inverse des magnitudes de gradients passés). AdamW ajoute un weight decay découplé pour une meilleure régularisation. Presque chaque LLM moderne est entraîné avec AdamW.

Pourquoi c'est important

Adam marche bien à travers une large gamme de tâches et d'hyperparamètres, en faisant l'optimiseur par défaut. Le comprendre explique pourquoi l'entraînement « marche juste » la plupart du temps (Adam s'adapte par paramètre) et pourquoi parfois non (les exigences mémoire d'Adam sont 2x les paramètres du modèle, ce qui compte pour les gros modèles). C'est aussi la réponse à « quel optimiseur je devrais utiliser ? » dans 90 % des cas.

Deep Dive

Adam maintains two moving averages per parameter: the first moment (mean of gradients — momentum) and the second moment (mean of squared gradients — adaptive scaling). The update rule: parameter -= lr × m̂ / (√v̂ + ε), where m̂ and v̂ are bias-corrected moments. Parameters with consistently large gradients get smaller updates (they're already well-calibrated). Parameters with small, noisy gradients get larger updates (they need more aggressive movement).

AdamW: The Fix

The original Adam applied weight decay by adding it to the gradient before computing moments, which caused the decay to be scaled by the adaptive learning rate — not what you want. AdamW (Loshchilov & Hutter, 2017) decouples weight decay from the gradient update, applying it directly to the parameters. This seems like a minor fix but significantly improves generalization. All modern LLM training uses AdamW.

Memory Cost

Adam stores two additional values per parameter (first and second moments), tripling the memory needed for optimizer state: a 70B model needs ~140 GB for weights (FP16) plus ~280 GB for Adam states (FP32), totaling ~420 GB. This is why optimizer state sharding (DeepSpeed ZeRO, FSDP) is essential for large model training. Some newer optimizers (Adafactor, CAME, Lion) reduce this memory overhead at some cost to stability.

Concepts liés

← Tous les termes
ESC