Hi,
This happens because you use a batchnorm on an input with no spacial size: An input of size (1, 40) has 40 channels only.
And batchnorm compute normalization for each channel. In this case, since there is a single element, then the renormalization by the standard deviation will divide by 0 and would produce nan. This is why we raise an error in this case.
Layers like batchnorm only work when you have a batchsize > 1 or you have to use it in evaluation mode to make it use the saved statistics.