Batch Renormalization is a method that applies corrections r and d, which cancel the gap between the mini-batch statistics and the moving averages, to the output of batch normalization, so that training produces the same values as inference. Ioffe (one of the authors of batch normalization) proposed it in 2017.
Batch normalization normalizes with the mini-batch mean and variance during training and with moving averages collected during training at inference. When mini-batches are large and their samples are independent of each other, the two are nearly the same. But they diverge significantly in the following cases.
When mini-batches are small: a mean and variance computed from a few values fluctuate widely, and the errors accumulate in deeper layers.
When mini-batch contents are biased: in metric learning (Triplet Loss and the like), for example, mini-batches sometimes always contain two images of the same label. The model overfits to these "paired" mini-batches and fails to work well when inferring one image at a time.
The paper attributes both problems to "upper layers being trained on values different from those they see at inference". Batch Renormalization matches the training-time normalization results to the inference-time values so that upper layers learn from the values actually used at inference.
In the paper's experiments (Inception v3, ImageNet), when training with biased mini-batches, batch normalization reached 67.0% accuracy while Batch Renormalization reached 78.5%, recovering almost the same accuracy as training with unbiased mini-batches.
Computation Steps
The two normalizations are related by a linear equation
For the values x of one channel (a unit in a fully connected layer), the value normalized with the mini-batch mean μB and standard deviation σB and the value normalized with the moving averages μ and σ are related as follows (Section 3 of the paper).
σxi−μ=σBxi−μB⋅r+d,r=σσB,d=σμB−μ
In other words, multiplying the mini-batch-normalized value by r and adding d gives the same value as at inference. Batch normalization is the special case r=1, d=0. If the moving averages are the correct averages (μ=E[μB], σ=E[σB]), the expected value of r is 1 and that of d is 0, so on average the correction changes nothing.
Training procedure
For the m values x1,…,xm in the mini-batch, compute the following in order (Algorithm 1 in the paper). μ and σ are the current moving averages, and α is the update rate of the moving averages.
Compute the mini-batch mean and standard deviation. Up to this point it is the same as batch normalization.
μB=m1∑i=1mxi,σB=ϵ+m1∑i=1m(xi−μB)2
Compute the correction factors r and d and clip their range.clip[a,b] restricts a value to between a and b.
r=sg(clip[1/rmax,rmax](σσB)),d=sg(clip[−dmax,dmax](σμB−μ))sg (stop gradient) means that r and d are treated as constants and no gradient flows through them.
Normalize with the mini-batch statistics and correct with r and d.x^i=σBxi−μB⋅r+d
Apply the learned scale and shift.yi=γx^i+β
Update the moving averages. Unlike in batch normalization, the moving averages are used not only for inference but also for the correction in the next step.
μ←μ+α(μB−μ),σ←σ+α(σB−σ)
At inference, as in batch normalization, normalization uses the moving averages.
y=γ⋅σx−μ+β
As long as r and d stay within the clipping range, the training-time x^i equals the inference-time σxi−μ. The figure at the top of the article places these training and inference flows side by side.
Apply the correction gradually
The paper trains as plain batch normalization (rmax=1, dmax=0) at first and then gradually relaxes the limits. In the Inception v3 experiments, the first 5,000 steps were identical to batch normalization; after that, rmax was widened to 3 over 40,000 steps and dmax to 5 over 25,000 steps. The update rate of the moving averages was set relatively fast at α=0.01 so that the statistics do not lag behind changes in the model.
Why the Correction Works
Training upper layers on inference-time values
With batch normalization, upper layers receive "values normalized with the mini-batch" during training and "values normalized with the moving averages" at inference. When mini-batches are small or biased, the two differ greatly, and upper layers learn to fit values they never see at inference. With Batch Renormalization, the training-time output matches the inference-time output, so the training-time output also depends only on the sample itself, not on the other samples.
Simply normalizing with the moving averages does not work
One might then think: why not normalize with the moving averages μ and σ from the start of training? According to the paper, however, this is known to make the model blow up. Because the moving averages are not part of the gradient computation, the optimizer keeps making changes that normalization should cancel, such as "increasing the bias" or "enlarging the weights", so the parameters grow without bound while the loss does not decrease.
Batch Renormalization performs the normalization itself with the mini-batch μB and σB and lets gradients flow through that computation. It then treats r and d as constants and only aligns the output values with the moving-average reference. The paper shows that this backward pass is equivalent to "the backward pass of normalizing with the moving averages, plus a projection that removes the components in the directions of shifting all samples by the same amount and scaling them by the same factor". Thanks to this projection, the parameters do not keep moving in directions that normalization cancels.
As an analogy, batch normalization is like "computing standard scores using only that day's test takers", while Batch Renormalization is like "computing standard scores with that day's test takers and then converting them to the scale of all past test takers". Even on days with few test takers or a skewed group, the converted scores can be compared on the usual scale.
r and d are clipped because the moving averages are not yet reliable early in training. In the paper, widening rmax abruptly early on, when the learning rate is large, occasionally produced large gradients and suddenly worsened the loss.
Experimental Results
The paper replaced the batch normalization in Inception v3 with Batch Renormalization and compared them on ImageNet image classification. Training was synchronized across 50 machines, with a mini-batch of 32 per machine and the RMSprop optimizer. γ was fixed at 1. Evaluation used top-1 accuracy on the validation data.
Experimental condition
Batch normalization
Batch Renormalization
Ordinary mini-batches (normalized over 32 examples)
78.3%
78.5%
Small mini-batches (normalized over 4 examples each)
74.2% (210k steps)
76.5% (130k steps)
Biased mini-batches (16 labels × 2 images)
67.0%
78.5% (120k steps)
(From Sections 4.1–4.3 and Figures 1–3 of the paper. For Batch Renormalization with biased mini-batches, the text gives 78.5% and the legend of Figure 3 gives 78.6%)
With ordinary mini-batches, accuracy did not drop. The learning curve closely followed that of batch normalization and ended slightly higher.
With small mini-batches, it reached higher accuracy faster. However, it did not reach the accuracy of normalizing over 32 examples (78.3–78.5%), so the advantage of large mini-batches does not disappear.
With biased mini-batches, the accuracy loss almost disappeared. With batch normalization, even training accuracy stalled at 72.8% and dropped partway through. The paper attributes this to overfitting to guessing the labels of the paired images. Keeping batch normalization but splitting each mini-batch in half for normalization, so that the two images of the same label land in different halves, improved accuracy to 77.4%, while Batch Renormalization reached 78.5% without any such workaround.
The Group Normalization paper also compared them on ResNet-50 (ImageNet, 4 images per GPU). rmax=1.5 and dmax=0.5 worked best, with an error rate of 26.3%. That was better than batch normalization's 27.3% but fell short of Group Normalization's 24.2%.
Practical Considerations
Accuracy still drops as mini-batches get smaller. Because the mean and variance are computed from the mini-batch, the dependence on the mini-batch does not go away. In the paper, too, normalizing over 4 examples fell short of normalizing over 32. When only 1–2 images fit on a GPU, as in object detection, also compare methods that do not use the mini-batch, such as Group Normalization.
It adds three hyperparameters: the update rate α of the moving averages and the schedules for relaxing rmax and dmax. The best values vary by model: Inception v3 in the paper ended with rmax=3 and dmax=5, while ResNet-50 in the Group Normalization paper used rmax=1.5 and dmax=0.5. The paper also leaves a detailed study of their effects to future work.
Also keep the following points in mind.
PyTorch has no built-in layer. As in the code example below, write a layer that holds its own moving averages. Following the paper, the moving averages hold the standard deviation σ, unlike batch normalization (nn.BatchNorm2d holds the variance).
The computation differs between model.train() and model.eval(). Training uses the mini-batch statistics with r and d; inference uses the moving averages. If r and d stay within their limits, the two outputs match, but as with batch normalization, model.eval() must be called before inference.
Do not apply the correction abruptly at the start of training. Train with rmax=1 and dmax=0 (the same as batch normalization) until the moving averages settle, then relax them gradually.
With data parallelism, normalization is done on each GPU's mini-batch. In the paper's experiments as well, the gradients from 50 machines were aggregated, but normalization was done over 32 (or 4) examples on each machine.
Does the training-time output depend on other samples?
No (if the correction is within range)
Yes
No
No
Training vs. inference
Computation differs, but outputs match
Both computation and output differ
Same computation
Same computation
Small batches (ResNet-50, 4 images, error rate)
26.3%
27.3%
24.2%
—
Extra hyperparameters
α, schedules for rmax and dmax
None (moving-average coefficient)
Number of groups G
None
Rough guidelines for choosing:
CNNs that can use sufficiently large mini-batches: batch normalization. Switching to Batch Renormalization barely changes accuracy.
You want to keep a batch-normalized model as is, but mini-batches are somewhat small, or their contents are biased as in metric learning: Batch Renormalization. Just swapping the layers is enough.
Very small mini-batches (1–2 images per GPU): Group Normalization, or Filter Response Normalization, which does not use the mini-batch.
Transformers and RNNs: Layer Normalization or RMSNorm.
PyTorch example
▶Show code
python
import torch
import torch.nn as nn
class BatchRenorm2d(nn.Module):
"""Batch Renormalization following Algorithm 1 of the paper (for conv layers; not built into PyTorch)"""
def __init__(self, num_features, eps=1e-5, alpha=0.01):
super().__init__()
self.eps, self.alpha = eps, alpha # alpha: update rate of the moving averages (0.01 in the paper)
self.gamma = nn.Parameter(torch.ones(num_features))
self.beta = nn.Parameter(torch.zeros(num_features))
# The moving averages hold the mean μ and the *standard deviation* σ (unlike nn.BatchNorm2d, which holds the variance)
self.register_buffer("running_mean", torch.zeros(num_features))
self.register_buffer("running_std", torch.ones(num_features))
self.r_max, self.d_max = 1.0, 0.0 # start out identical to batch normalization
def forward(self, x): # x: [N, C, H, W]
g = self.gamma.view(1, -1, 1, 1); b = self.beta.view(1, -1, 1, 1)
mu = self.running_mean.view(1, -1, 1, 1); sigma = self.running_std.view(1, -1, 1, 1)
if not self.training: # inference: normalize with the moving averages
return g * (x - mu) / sigma + b
mu_b = x.mean(dim=(0, 2, 3), keepdim=True) # 1. mini-batch mean and standard deviation
sigma_b = torch.sqrt(x.var(dim=(0, 2, 3), unbiased=False, keepdim=True) + self.eps)
r = (sigma_b / sigma).clamp(1 / self.r_max, self.r_max).detach() # 2. no gradient flows
d = ((mu_b - mu) / sigma).clamp(-self.d_max, self.d_max).detach()
x_hat = (x - mu_b) / sigma_b * r + d # 3. normalize and correct
with torch.no_grad(): # 5. update the moving averages
self.running_mean += self.alpha * (mu_b.flatten() - self.running_mean)
self.running_std += self.alpha * (sigma_b.flatten() - self.running_std)
return g * x_hat + b # 4. scale and shift
def relax(step, start=5000, r_end=(40000, 3.0), d_end=(25000, 5.0)):
"""Schedule for relaxing r_max and d_max (values from the paper's Inception v3).
The paper only says "gradually relax", so here they are widened linearly"""
def ramp(end_step, end_value, v0):
t = min(max((step - start) / (end_step - start), 0.0), 1.0)
return v0 + t * (end_value - v0)
return ramp(*r_end, 1.0), ramp(*d_end, 0.0)
layer = BatchRenorm2d(64)
x = torch.randn(4, 64, 16, 16) # small mini-batch
for step in [0, 10000, 50000]:
layer.r_max, layer.d_max = relax(step)
layer.train(); y_train = layer(x) # training: mini-batch statistics + r, d correction
layer.eval()
with torch.no_grad():
y_eval = layer(x[:1]) # inference: normalize with the moving averages only (a single example is fine)
FAQ
Q. Can a model that uses batch normalization switch to Batch Renormalization just by replacing the layers?
A.
Yes. The paper's experiments also simply replaced the batch normalization layers of Inception v3. However, a schedule for relaxing the upper limits of the correction factors and a new update rate for the moving averages must be chosen. The paper's approach is to start with the same settings as batch normalization and apply the correction gradually.
Q. Is there any point in using it when mini-batches are large enough?
A.
In terms of accuracy, there is almost no difference. In the paper's experiments, with normalization over 32 examples, accuracy was 78.3% for batch normalization and 78.5% for Batch Renormalization. When training with biased mini-batches (such as metric learning that pairs images of the same label), it helps even with large mini-batches.
Q. Should Group Normalization or Batch Renormalization be chosen?
A.
If mini-batches are so small that only 1–2 images fit on a GPU, Group Normalization, which does not use the mini-batch, is the better fit. In the comparison in the Group Normalization paper (ResNet-50, 4 images), Group Normalization also had the lower error rate. When you want to ease the effects of small or biased mini-batches while changing an existing batch-normalized model and its settings as little as possible, Batch Renormalization is the easy option.