Adam optimization method memory usage
"TLDR: Adam optimization method memory usage. Generally speaking, Adam uses more information, so it requires more memory. There was an experiment. When the Optimizer selects SGD, the Batch Size can be selected to be 20, but when it is replaced with Adam, the Batch Size can only be selected to be 2. The adaptive embodiment of Adam is exponential smoothing, which alleviates drastic changes in the gradient direction and makes the convergence path smoother."
#Adam optimization method memory usage
Generally speaking, Adam uses more information, so it requires more memory. There was an experiment. When the Optimizer selects SGD, the Batch Size can be selected to be 20, but when it is replaced with Adam, the Batch Size can only be selected to be 2.
Definition of moment
Moment comes from the definition of physics, it is the product of distance and physical quantity, and reflects the spatial distribution of objects;
In mathematics, a moment represents a measure of data: is called the moment of with respect to .
In particular, is called the -order origin moment, and is called the center distance.
More specifically, is called the order moment of about .
If , it is called order mixed origin moment
If , it is called order mixed center distance
Exponential moving average
The exponential moving average method is referred to as the exponential smoothing method. It uses the last actual value and predicted value (estimated value), performs different weighted distributions on them, and obtains an exponential smoothing value as a prediction method for the next period's predicted value. Its prediction formula is:
Usually, the first-order exponential smoothing method is not used directly for prediction, but the second-order exponential smoothing method is used to find the smoothing coefficient, establish a prediction model, and then make predictions. Cubic or more exponential smoothing methods are suitable for almost all time series predictions.
Adam principle (full name: adaptive moment estimation optimizer)
The most critical part is: use exponentially weighted moving average to estimate the momentum and second moment of the gradient, state variables:
It can be found that the upper term is actually the first-order moment of the gradient, and the lower term is the second-order moment of the gradient. Generally speaking, , that is to say, the variance estimate moves much slower than the momentum estimate movement.
Bias in corrected moment estimates
Update equation:
Adam is essentially RMSprop with a momentum term, which uses the first-order moment estimate and second-order moment estimate of the gradient to dynamically adjust
The here is regarded as normalization. The possible understanding is: only cares about the direction, the norm does not matter, anyway there is a learning rate
Understand
In fact, each training is done in batches, and a part of the overall sample is selected as the sample for this training. Then using the gradient of this small sample as the gradient of the overall sample is moment estimation (it has never been clear where the moment of adaptive moment estimation is reflected). Then, if you directly use the sample gradient as the overall gradient, you will find some problems, and that is the variance. Obviously, the batch sample extracted is only a part of the overall sample, so the gradient of the batch sample cannot be exactly the gradient of the overall sample. The gradient of the batch sample obeys a random distribution, and its expectation is the overall gradient, but this random distribution has variance. (balabalal, nonsense)
The embodiment of Adam's adaptability is exponential smoothing, which alleviates drastic changes in the gradient direction and makes the convergence path smoother.
Memory usage
Since more information is used, the memory usage will naturally be more, and it is obvious that the upper bound of Batch_Size for batch training will be smaller.
Adam uses parameters, gradients, momentum and second-order momentum, so its memory footprint is four times the data