Skip to main content

How a number’s partner changed its output in a model

Put zero next to −1. Zero is above the pair’s average. Put it next to 2, and now it’s below average. If you want to describe where zero stands among its neighbors, you need to know who its neighbors are.

We tried this with a single calculation used inside AI models. We sent the same four numbers through it in different pairs. In one setting zero came out close to +1 beside −1 and close to −1 beside 2. In the other setting it came out close to −0.5 with either partner.

The calculation, called batch normalization, compares each number with an average and scales the difference according to how spread out the numbers are. A group of numbers processed together is a batch. We used PyTorch’s BatchNorm1d layer, the piece of software that does the calculation. Both runs used evaluation mode, the setting normally chosen when testing a trained model. One layer took the average and spread from the pair at hand. The other used values we had fixed in advance. Recorded outputs and controls

Follow zero through the two pairs

We used 0, -1, 2 and 3 once per run. The first row pairs zero with −1 and leaves 2 with 3. The second pairs zero with 2 and leaves −1 with 3. The ‘target’ is the input zero. The middle column (‘tracking off’) gives its output when the layer uses each pair’s own average and spread. The right column (‘fixed running buffers’) gives zero’s output when the layer uses the same saved values every time.

Zero’s output with a different partner, using the pair’s statistics or fixed values
Ordered batchesTarget output, tracking offTarget output, fixed running buffers
[0, -1] and [2, 3]+0.9999800005999799-0.49999937500117186
[0, 2] and [-1, 3]-0.9999950000374997-0.49999937500117186

To check whether the order mattered, we swapped the two numbers in the pair containing zero, then used each input’s ID to find its output again. Reversing the pair kept every output the same within our tolerance. With the saved values, all four outputs also held steady when we changed partners. The stored mean, variance and batch counter stayed at 1, 4 and 0.

For anyone repeating the calculation, we used two 2 × 1 CPU float64 arrays per run, separate BatchNorm1d(1, eps=1e-5, affine=False) layers in .eval() mode and torch.inference_mode(). The setting affine=False turns off a further learned scaling and shift. With Python 3.13.17 and PyTorch 2.9.1+cpu, every output was finite and matched the predicted value within 1e-12 absolute tolerance and zero relative tolerance. Replay script

The pair’s average explains the sign

With track_running_stats=False, the layer had no saved mean or variance. Even in evaluation mode it used the current pair. For zero and −1, the mean was -0.5. Subtracting that mean from zero gave a positive number. For zero and 2, the mean was 1. Subtracting it gave a negative number. The layer divided this difference by the square root of the pair’s variance plus a small allowance, eps=1e-5. That kept the sign and put the outputs close to +1 and −1.

For the layer with track_running_stats=True, we supplied a fixed mean of 1 and variance of 4. Variance measures how spread out the values are. Zero was below the same mean by the same amount both times, so its output stayed close to −0.5. We measured these outputs for one layer with four invented inputs. PyTorch 2.9.1 BatchNorm source

How to check whether the other inputs matter

  1. Give each input a stable ID so you can match it across runs. Save the order of the IDs in each batch and the output for each ID. Record the layer’s evaluation mode, the track_running_stats setting and the saved mean and variance, or their absence.
  2. Keep the inputs, batch size and model state fixed. Change which inputs share a batch with the one you’re following. State how much numerical difference you will allow, then compare the outputs. Separately try reversing the original order without changing partners.
  3. If the partners make a difference, save the original groups. In a larger model, check that the same number reached this layer in both runs. Compare the layer’s outputs using the recorded settings, including eps and any learned scale or shift. That tells you whether the difference shows up here before you try to explain a change in the model’s final answer.