On 1: in training mode, BatchNorm DOES NOT use running_mean and running_std to compute the output. It only updates running_mean and running_std values internally. Hence, what you see is exactly what’s expected.
On 2: At test time, the output is not the same as the last training output. The output uses the previously updated running_mean and running_std to compute the output. The default momentum value for BatchNorm is 0.9, so after 10 iterations through, it should be roughly in the neighborhood, but not exactly the same. If you run the first for loop for 100 iterations, it’ll probably be very close.
There’s also the other problem that im, which is your input has a mean of 1 and a standard deviation of 0. That’s not great to compute and running-update batch statistics.