A more efficient but slightly less generalised optimizer than SGD
Adam solvers are the hassle free standard for optimizers.
Empirically, Adam solvers converge faster and are more robust towards hyper-parameter settings than SGD. However, they generalize slightly worse. So, a good approach can be to start with Adam, and when you struggle to get good results, switch to the more costly SGD.
Hyper-parameter tuning usually yields 1-3% marginal gains in performance. Fixing your data is usually more effective.
The intuition behind Adam solvers is similar to the one behind SGD. The main difference is though, that Adam solvers are adaptive notifiers. Adam also adjusts the learning rate based on the gradients' magnitude using Root Mean Square Propagation (RMSProp). This follows a similar logic as using momentum + dampening for SGD. This makes it robust for the non-convex optimization landscape of neural network.
# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10
# Create random Tensors to hold inputs and outputs.
x = torch.randn(N, D_in)
y = torch.randn(N, D_out)
# Use the nn package to define our model and loss function.
model = torch.nn.Sequential(
loss_fn = torch.nn.MSELoss(reduction='sum')
# Use the optim package to define an Optimizer that will update the weights of
# the model for us. Here we will use Adam; the optim package contains many other
# optimization algorithms. The first argument to the Adam constructor tells the