High-Performance Large-Scale Image Recognition Without Normalization
- Publication
- ICML 2021Conference
- First submitted to arXiv
- arXiv:2102.06171
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{classiccnnsnfnet2021,
title = {{High-Performance Large-Scale Image Recognition Without Normalization}},
author = {Andrew Brock and Soham De and Samuel L. Smith and Karen Simonyan},
year = {2021},
eprint = {2102.06171},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2102.06171}
}
After 2015, nearly every image classification network had BatchNorm in it. It makes deep networks easy to train, allows large learning rates, and throws in a bit of regularization on the side. It was so handy that people rarely stopped to think about its drawbacks.
It has quite a few drawbacks, actually. It has to compute batch statistics, which costs memory and time. It uses batch statistics during training and moving averages at inference, so it behaves differently in the two. It also makes the samples in a batch affect one another, and that's the most troublesome part. It works worse when batches are too small, it's error-prone in distributed training, and in contrastive learning it needs special handling so the model can't peek at the answer through the batch statistics.
Andrew Brock, Soham De, Samuel L. Smith, and Karen Simonyan at DeepMind wanted to remove BatchNorm entirely. In their previous paper they had already built NF-ResNets without normalization layers, whose accuracy caught up with BN-ResNets of the same size; this paper tackles the two problems that remained.
Defining the Problem
What BatchNorm Actually Does for Us
To remove BatchNorm, you first have to know what it does, then find a replacement for each job one by one. The authors list four:
- It shrinks the residual branch's output. When BN sits on the residual branch, the branch output is fairly small at initialization, so the signal mainly travels through the shortcut and gradients are more stable early in training.
- It eliminates mean shift. Activation functions like ReLU and GELU have outputs whose mean isn't 0, and as layers stack up, the features of different samples grow more and more alike. BN pulls the mean back to 0 at every layer.
- It has a regularizing effect. Batch statistics are noisy, which is a bit like adding noise during training.
- It makes large-batch training practical. BN smooths the loss landscape and allows larger learning rates, which is what makes large-batch training worthwhile.
The earlier NF-ResNet handled the first two with initialization and weight standardization, and covered the third with Dropout and Stochastic Depth. Two problems remained. Training is unstable at batch sizes of 4096 and above, and the best results still couldn't catch up with EfficientNet.
What Mean Shift Looks Like
The second job is more abstract, so first look at what happens without normalization. Pass 64 unrelated random samples through ReLU and a He-initialized layer, 20 times over, and the mean cosine similarity between samples rises to about 0.96, so that nearly all the samples look the same. A second group using the NF-ResNet approach (explained shortly) keeps the similarity at 0, with the variance falling only from 1 to 0.88. The He-initialized group behaves this way because ReLU outputs are all greater than or equal to 0, so every layer adds the same positive mean to every sample. Research cited by the paper shows that this shift can make a deep network predict the same class for every sample at initialization.
Solving the Problem
First, Finishing NF-ResNet
The group on the right uses two tricks from the earlier NF-ResNet paper.
The first is Scaled Weight Standardization. For each output unit of a convolutional layer, the weights first have their own mean subtracted, then are divided by their standard deviation and :
where is the fan-in. After the mean is subtracted, each output unit's weights sum to 0, which cancels out the shared positive value the activation function brings in. That's why the similarity above stays at 0.
The second is a gain multiplied after the activation function. For ReLU, , about 1.71, which exactly makes up for the variance lost when ReLU cuts off the negative values. Together, the two keep each layer's output variance at roughly 1. The 0.88 after 20 layers comes from small deviations piling up layer by layer, a far smaller problem than the other group's samples nearly all turning into the same one.
With a branch that “roughly preserves variance at every layer,” NF-ResNet's residual block is written as
is the precomputed standard deviation of the input, so the signal entering the branch is always scaled back to variance 1; is a small constant (usually 0.2) that controls how much each block increases the variance. The variance along the main path can therefore be computed directly, growing by with each block, to 1.48 after 12 blocks. This replaces BatchNorm's first job. Because is small, the signal mainly travels through the shortcut, and at first the branch only makes small corrections. In blocks that shrink the feature map, the shortcut also takes the scaled input, and the variance count restarts from . On top of that, each residual branch ends with a learnable scalar initialized to 0 (SkipInit), so the whole branch is switched off at the start of training.
At this point, NF-ResNet can already match BN-ResNet at batch size 1024, but it becomes unstable once the batch gets large.
Adaptive Gradient Clipping
Large-batch training calls for large learning rates, and once the gradients get big, a single step can push the parameters too far. The usual fix is gradient clipping:
The authors found that this does hold up at somewhat larger batches, but the threshold is very hard to tune. Whenever the model depth, batch size, or learning rate changes, it has to be searched for all over again.
The trouble is that a fixed threshold ignores how large the parameters themselves are. The same gradient of 0.01 is only a 1% change on a weight of size 1, but on a weight of size 0.01 it flips the whole thing. So the authors look at a ratio instead:
which roughly tells you by what fraction one update step will change the weights. In practice it isn't computed once for the whole layer but unit-wise, that is, for each row of the weight matrix (for a convolution, each output channel together with its spatial extent):
Here with , which keeps zero-initialized parameters from always having their gradients clipped to 0. This is Adaptive Gradient Clipping (AGC).
Let's see how it clips with a small example of three units:
import torch
W = torch.tensor([[1.0, 0.0, 0.0],
[0.0, 0.1, 0.0],
[0.0, 0.0, 2.0]]) # three output units with weights of different sizes
G = torch.tensor([[0.005, 0.0, 0.0],
[0.0, 0.05, 0.0],
[0.0, 0.0, 0.01]]) # three rows of gradients
lam, eps = 0.01, 1e-3
w_norm = W.norm(dim=1, keepdim=True).clamp(min=eps)
g_norm = G.norm(dim=1, keepdim=True)
ratio = g_norm / w_norm
clipped = torch.where(ratio > lam, G * (lam * w_norm / g_norm), G)
for i in range(3):
print(f"Unit {i}: ‖W‖={w_norm[i].item():.2f}, ‖G‖={g_norm[i].item():.3f}, ratio {ratio[i].item():.3f}"
f" → clipped ‖G‖={clipped[i].norm().item():.4f}")
print("Overall gradient norm:", round(G.norm().item(), 4))
Unit 0: ‖W‖=1.00, ‖G‖=0.005, ratio 0.005 → clipped ‖G‖=0.0050
Unit 1: ‖W‖=0.10, ‖G‖=0.050, ratio 0.500 → clipped ‖G‖=0.0010
Unit 2: ‖W‖=2.00, ‖G‖=0.010, ratio 0.005 → clipped ‖G‖=0.0100
Overall gradient norm: 0.0512
Only unit 1 got clipped. Its weight is only 0.1 while its gradient is 0.05, enough to change half of it in one step, so it gets pushed down to . The other two units have ratios below the threshold and are left untouched. With ordinary global clipping, all three units would be scaled down by the same factor, and the one that really needs reining in might not get reined in enough.
The code above gives the same result as timm's timm.utils.agc.adaptive_clip_grad, with the three units coming out at 0.005, 0.001, and 0.01 after clipping.

In the left plot, the orange lines are NF-ResNet without AGC, which collapse beyond batch size 2048; the green lines, with AGC, hold up all the way to 4096, with accuracy about the same as BatchNorm's blue lines or even better. The right plot is about the threshold. The larger the batch, the smaller the threshold needs to be, and at batch size 4096 only 0.01 and 0.02 hold up.
The authors also tested which layers need clipping. It's better not to clip the final fully connected layer; the first convolutional layer can often go unclipped, but at batch size 4096 the weights of all four stages have to be clipped. All later experiments apply AGC to every parameter except the last layer.
The NFNet Architecture
With AGC in hand, the authors went on to design a new network. This time the target wasn't FLOPs or parameter count, but actual training speed on TPUs and GPUs. The authors point out that EfficientNet has very low FLOPs but doesn't train any faster for it. EfficientNet-B0 has only a tenth of ResNet-50's FLOPs, yet trains about as slowly on a GPU or TPU.
![Diagram of the NFNet bottleneck block. The input is first multiplied by 1/β, passes through a 1x1 convolution, two 3x3 convolutions, and another 1x1 convolution, is multiplied by α, and is added to the shortcut. On the right are the stage widths and depths: ResNet widths [256, 512, 1024, 2048] and NFNet widths [256, 512, 1536, 1536]; ResNet depths [3, 4, 6, 3], [3, 4, 23, 3]…, and NFNet depths [1, 2, 6, 3] times N](/content/papers/assets/6dc27a9ccca4de619c057562ea6384aab3c095ddc08b22f475601ab03fcf03bb.png)
The starting point is SE-ResNeXt-D with its activation function switched to GELU, followed by four changes:
- Group width fixed at 128. Finer groups mean fewer FLOPs, but compute density drops along with them, so on accelerators there's no real speedup.
- Depth pattern [1, 2, 6, 3]. Larger models simply multiply it by N; F1, for example, is [2, 4, 12, 6]. ResNets traditionally deepen only the middle two stages, which the authors consider suboptimal.
- Width pattern [256, 512, 1536, 1536]. Capacity is concentrated in the third stage and the fourth stage is slightly reduced, keeping training speed roughly the same.
- One more grouped convolution in the block. These are the two consecutive 3x3s in the figure. The authors say it adds only a few FLOPs and, on their accelerators, has almost no effect on training time.
When scaling the model up, only depth and resolution increase, not width; the authors found that widening doesn't work well for ResNet-style backbones. Each step up roughly doubles the training time, and Dropout goes up along with it, from 0.2 for F0 to 0.5 for F6. Without BatchNorm's implicit regularization, the model overfits badly unless explicit regularization like Dropout steps in.
Discussion
What Each Change Contributes
| Setting | F0 | F1 | F2 | F3 |
|---|---|---|---|---|
| Baseline | 80.4% | 81.7% | 82.0% | 82.3% |
| + Modified width | 80.9% | 81.8% | 82.0% | 82.3% |
| + Second | 81.3% | 82.2% | 82.4% | 82.7% |
| + MixUp | 82.2% | 82.9% | 83.1% | 83.5% |
| + RandAugment | 83.2% | 84.6% | 84.8% | 85.0% |
| + CutMix | 83.6% | 84.7% | 85.1% | 85.7% |
| Original width + the augmentations above | 83.1% | 84.5% | 85.0% | 85.5% |
Together, the two architectural changes add 0.4 to 0.9 percentage points. What really opens up the gap is data augmentation, with RandAugment alone worth 1 to 1.7 percentage points. These strong augmentations are exactly what the original NF-ResNet couldn't handle, and AGC makes them usable. The last row switches back to ResNet's original width pattern, and all four sizes do worse, which shows the width change really does help.
The authors also applied the same augmentations to EfficientNet. RandAugment helps, but going beyond 2 layers, or adding MixUp and CutMix, brings no further improvement. On this basis they argue that NFNet's gains don't come from augmentation alone.
Is Removing BN Really Faster?
When the same architectures are trained with BatchNorm instead, the accuracy and per-step training time are:
| Model | NF version | BN version |
|---|---|---|
| F0 | 83.6%, 73.3 ms | 83.4%, 111.7 ms |
| F1 | 84.7%, 158.5 ms | 84.4%, 258.0 ms |
| F2 | 85.1%, 295.8 ms | 85.1%, 396.3 ms |
Accuracy is about the same, with the NF version slightly better or tied, while per-step training time drops by 25% to 40%. The authors also mention that the larger F4 and F5 didn't train stably with BatchNorm, with or without AGC. Their guess is that the bfloat16 used to fit the models into memory doesn't get along with the computation of batch statistics.
Against Other Models

The whole red line lies above and to the left of the other models, meaning higher accuracy for the same training time. The most often quoted pair of numbers is NFNet-F1 versus EfficientNet-B7. Both reach 84.7%, but F1 needs only 158.5 ms per step while B7 needs 1397.0 ms, which makes F1 nearly 9 times faster. The largest, NFNet-F5, reaches 86.0%; with the SAM optimizer, F5 gets to 86.3% and F6 to 86.5%, the best results at the time without extra data.
This red line, though, is plotted against training time. Measured by parameter count, NFNet is anything but frugal. F0 has 71.5M parameters and 12.38 GFLOPs, while EfficientNet-B0 has only 5.3M and 0.39 GFLOPs; F1 also has twice as many parameters as B7. The authors are explicit about this in the paper. What they optimize is training time, and FLOPs and parameter count were never the target.
Fine-Tuning After Pretraining
In the last set of experiments, the authors pretrain on 300 million labeled images and then fine-tune on ImageNet. With this much data, BatchNorm's regularizing effect may actually get in the way, and the authors suspect networks without BN suit this setting better:
| Model | 224px | 320px | 384px |
|---|---|---|---|
| BN-ResNet-50 | 78.1% | 79.6% | 79.9% |
| NF-ResNet-50 | 79.5% | 80.9% | 81.1% |
| BN-ResNet-200 | 81.8% | 83.1% | 83.5% |
| NF-ResNet-200 | 82.9% | 84.1% | 84.3% |
The NF version wins in every group, by about 1 percentage point. The authors then pretrain a slightly wider NFNet-F4+ for 20 epochs, which reaches 89.2% after fine-tuning, the highest result achieved with transfer learning at the time.
Conclusion
With BatchNorm gone, training actually got faster. But everything BatchNorm used to handle on the side has to be put back by hand, one piece at a time. Mean shift goes to Scaled Weight Standardization and the gain, the residual branch's scale to , , and SkipInit, regularization to Dropout and strong data augmentation, and large-batch training is held together by AGC.
If you want to use it directly, timm has dm_nfnet_f0 through dm_nfnet_f6, plus the eca_nfnet_l0 series that timm trained itself and slimmed down for GPUs; AGC can also be applied on its own to your own model with adaptive_clip_grad.
Oh, right, if you're going to train any NFNet variant, remember to turn on gradient clipping. Don't tempt fate!