I tried two options, but I don’t know if they behave the same way.

out = out.contiguous (). View (1, batch, 1, wn1) -> self.bn1 = nn.BatchNorm2d (batch, affine = True)
out = out.contiguous (). View (1,1, batch, wn1) -> self.bn1 = nn.BatchNorm2d (batch, affine = True)
In the first case, BatchNorm2d takes batch and does the normalization for each example. In the second case, BatchNorm2d takes 1 and makes normalization for all examples. The second case allows me to change batch without problems. Training in the first case and in the second is the same.