Thank you for your answer.  A follow-up question: how does BatchNorm1d calculate variance for 3D data? I noticed that the variance of normalized 3d data is nowhere near 1.  Here’s what I did:
X3 = torch.randn(150,20,100) * 2 + 4
X3 = Variable(X3)
B2 = nn.BatchNorm1d(20)
Y = B2(X3)
print(Y.var())

Every time I ran the above code, the output came out to be a number approximately in the range (0.20,0.40).
The variance of output for 2d and 4d inputs is close to 1 (as is expected).