Question: I am about to train a big LSTM network with 2-3 million articles and am struggling with Memory Errors (I use AWS EC2 g2x2large).

I found out that one solution is to reduce the `batch_size`. However, I am not sure if this parameter is only related to memory efficiency issues or if it will effect my results. As a matter of fact, I also noticed that `batch_size` used in examples is usually as a power of two, which I don't understand either.

I don't mind if my network takes longer to train, but I would like to know if reducing the `batch_size` will decrease the quality of my predictions.

Thanks.

Answer: 
After one and a half years, I come back to my answer because my previous answer was wrong. 

Batch size impacts learning significantly. What happens when you put a batch through your network is that you average the gradients. The concept is that if your batch size is big enough, this will provide a stable enough estimate of what the gradient of the full dataset would be. By taking samples from your dataset, you estimate the gradient while reducing computational cost significantly. The lower you go, the less accurate your esttimate will be, however in some cases these noisy gradients can actually help escape local minima. When it is too low, your network weights can just jump around if your data is noisy and it might be unable to learn or it converges very slowly, thus negatively impacting total computation time.

Another advantage of batching is for GPU computation, GPUs are very good at parallelizing the calculations that happen in neural networks if part of the computation is the same (for example, repeated matrix multiplication over the same weight matrix of your network). This means that a batch size of 16 will take less than twice the amount of a batch size of 8.

In the case that you do need bigger batch sizes but it will not fit on your GPU, you can feed a small batch, save the gradient estimates and feed one or more batches, and then do a weight update. This way you get a more stable gradient because you increased your virtual batch size.
A couple of papers have been published showing – and conventional wisdom in 2020 seems to still be persuaded— that, as [Yann LeCun](https://twitter.com/ylecun/status/989610208497360896) put, large batches are bad for your health.

Two relevant papers are

* [Revisiting Small Batch Training For Deep Neural Networks, Dominic Masters and Carlo Luschi](https://arxiv.org/abs/1804.07612) which implies that anything over 32 may degrade training in SGD.

and

* [On Large-batch Training For Deep Learning: Generalization Gap And Sharp Minima](https://arxiv.org/abs/1609.04836)

which offers possible reasons. To paraphrase badly, big batches are likely to get stuck in local (“sharp”) minima, small batches not. There is some interplay with choice of learning rate.