r/MachineLearning • u/XTXinverseXTY ML Engineer • 18d ago
Discussion Did we ever really get to the bottom of why BatchNorm works? [D]
It's been a long time since I studied this. Just checking in on an old friend.
I also realize it's fallen out of favor for being extremely inconvenient, but why did it ever work?
74
Upvotes
73
u/orangehumanoid 18d ago
This paper found that "internal covariate shift" wasn't right and it's more about making the loss surface nicer for optimization.
30
u/jebuarary 18d ago
All I remember in terms of the explanation is the internal covariant shift memes about batchnorm. I’ve admittedly always used it pretty blindly. BN and Adam optimizer both fell under the category of so much more stable than not using that I didn’t even question it.
But this is a good explanation: https://www.reddit.com/r/MachineLearning/comments/1o7pgbl/d_what_is_internal_covariate_shift/
9
u/NaivelyBayesic 17d ago
I don’t really think it really "stopped" working, I think it just became a pain to deal with.
Most of the issues folks seem to run into were from the batch dependence. Your forward pass for one sample depends on whatever else happens to be in the batch. Fine for imagenet at 256... not so fine for small batches, variable length sequences, or anything multi-gpu where you have to sync stats. And then inference uses running averages so train and test never quite line up.
LayerNorm doesn’t have any of that since it’s just within the sample. So I think for transformers people just went with it and it stuck. 🤷♂️
6
u/js49997 17d ago edited 17d ago
Basically keeps things well conditioned and prevents blow up or decay of activation and gradient magnitudes
2
u/sadnesspie42069 17d ago
Conceptually it would be like applying a series of convolutions on the loss landscape which makes the loss landscape look more like a normal distribution. You are literally sampling a distribution and taking a mean such as in this:
Https://www.statscalculators.com/resources/simulations/central-limit-theorem
Https://www.lesswrong.com/posts/YM6Qgiz9RT7EmeFpp/how-long-does-it-take-to-become-gaussian
14
u/TheRealStepBot 18d ago edited 17d ago
It lives in a weird place. You might need normalization. But normalization leaks and needs you to load the whole dataset.
So you pick batch norm for being easier than a full norm to handle all the numerical issues.
But in many very useful datasets like images video and tokenized text not only do you not need norming as they are already in a fixed range but also datasets are massive.
You may still need to reach for norming of some kind when training smaller models on smaller datasets that are not well scaled.
That’s my casual understanding
1
u/ProfMasterBait 17d ago
no
0
u/o-h_2792562 15d ago
Batch-statistic noise can also regularize training; that's a separate benefit from the optimization story.
-1
u/lqstuart 17d ago
It doesn’t do anything, it’s just ten years of idiots cargo culting shit
-7
u/altmly 18d ago
I don't think it's a huge mystery. Batch norm is the same idea as instance norm, but the problem with instance norm is that you're whitening the samples, whereas batch norm has a proxy for overall feature distribution rather than per sample feature distribution.