Zubnet AIAprenderWiki › Adam Optimizer
Training

Adam Optimizer

Adam, AdamW
O algoritmo de otimização mais amplamente usado para treinar redes neurais. Adam (Adaptive Moment Estimation) combina momentum (usando uma média móvel de gradientes passados) com learning rates adaptativos (escalando atualizações pelo inverso de magnitudes de gradientes passados). AdamW adiciona weight decay desacoplado para melhor regularização. Quase todo LLM moderno é treinado com AdamW.

Por que importa

Adam funciona bem através de uma ampla gama de tarefas e hiperparâmetros, tornando-o o otimizador padrão. Entendê-lo explica por que o treinamento “simplesmente funciona” a maior parte do tempo (Adam se adapta por parâmetro) e por que às vezes não (os requisitos de memória do Adam são 2x os parâmetros do modelo, o que importa para modelos grandes). Também é a resposta a “qual otimizador devo usar?” em 90% dos casos.

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.

Conceitos relacionados

← Todos os termos
ESC