1 00:00:01,000 --> 00:00:09,300 [Hal Turing] Alrighty! Thanks for tuning in! Hello AI world! I am your host, Hal Turing, and my co-host is Dr. Ada Shannon. 2 00:00:09,300 --> 00:00:36,875 [Hal Turing] Today's paper is An Empirical Model of Large-Batch Training, by Sam McCandlish, Jared Kaplan, Dario Amodei, and the OpenAI Dota Team, from OpenAI and Johns Hopkins University. It's an arXiv paper from December 2018. The puzzle in the abstract is a good one. ImageNet training tops out at batches of tens of thousands of images. The Dota 2 agents train on batches of millions of observations. Why the gap, and can you predict it? 3 00:00:36,875 --> 00:00:53,700 [Dr. Ada Shannon] The authors' answer is a cheap statistic called the gradient noise scale, which they say predicts the largest useful batch size across very different tasks. The claim is made at the order-of-magnitude level. We'll spend this episode testing how useful that actually is. 4 00:00:53,700 --> 00:00:59,200 [Hal Turing] Start with why batch size matters at all. Why not just throw more GPUs at it? 5 00:00:59,200 --> 00:01:20,600 [Dr. Ada Shannon] Because of data parallelism. You split one batch across many devices, each computes a gradient on its share, and you average them. That only helps if a bigger batch makes each step better, so you need fewer steps. If doubling the batch barely improves each step, you've paid for twice the hardware and saved almost no time. Two costs are in tension: serial time, the number of optimizer steps, and total compute, the number of examples processed. 6 00:01:20,600 --> 00:01:25,675 [Hal Turing] And in practice people just tried batch sizes until something broke? 7 00:01:25,675 --> 00:02:05,950 [Dr. Ada Shannon] Basically. Large batches often needed warmup or odd learning-rate schedules, so how large a batch could go stayed unexplored for years. The paper notes that Atari and ImageNet were run at much smaller batches than later turned out to be possible. Two earlier papers frame this. Goyal and colleagues at Facebook, 2017, trained ImageNet in an hour. Their linear scaling rule says to multiply the learning rate when you multiply the batch, with a gradual warmup. And Shallue and colleagues at Google, 2018, ran a large empirical study of steps-to-target against batch size, finding that the regimes depend strongly on model, data, and optimizer. McCandlish cites it as parallel work, and we'll come back to it as an independent check. 8 00:02:05,950 --> 00:02:11,475 [Hal Turing] So Goyal gives a recipe and Shallue gives a map. What does this paper add? 9 00:02:11,475 --> 00:02:33,075 [Dr. Ada Shannon] A predictor, and a prediction of where the recipe should break. Here's the intuition. Each minibatch gradient is the true gradient plus sampling noise. With a small batch, the noise dominates. You could have computed many of those gradients in parallel and averaged them, losing little. With a huge batch, the gradients are nearly identical, so doubling the batch wastes compute. The turning point is where signal and noise are comparable. That batch size is the noise scale. 10 00:02:33,075 --> 00:02:37,125 [Hal Turing] Give me the formal version, since there are two flavors. 11 00:02:37,125 --> 00:02:57,275 [Dr. Ada Shannon] B_simple is the sum of the per-component gradient variances, divided by the squared norm of the true gradient. It assumes the loss curvature, the Hessian, is well-conditioned. B_noise weights that ratio by the Hessian, and it's the more principled quantity. B_simple is the practical one, since you can compute it from gradient statistics during an ordinary run. 12 00:02:57,275 --> 00:03:00,675 [Hal Turing] Now the other quantities. S and E? 13 00:03:00,675 --> 00:03:20,400 [Dr. Ada Shannon] S is the number of optimizer steps, a proxy for wall-clock time. E is batch size times S, the number of examples processed, a proxy for compute. For a fixed performance goal, the combinations you can reach form a Pareto frontier, which is Figure 1. It's a curve with a knee. Along it you can only save steps by spending more examples. 14 00:03:20,400 --> 00:03:22,125 [Hal Turing] Where's the knee? 15 00:03:22,125 --> 00:03:47,025 [Dr. Ada Shannon] The critical batch size, B_crit, which is E_min over S_min. The fewest examples you could need, divided by the fewest steps. They fit a hyperbola to the frontier, and at B_crit you use twice the minimum steps and twice the minimum examples. Compute efficiency is 50 percent. The distinction to hold onto is that B_crit comes from running many full training runs at different batch sizes. B_simple comes from gradient statistics in a single run. The claim is that the second predicts the first. 16 00:03:47,025 --> 00:03:54,825 [Hal Turing] So if that holds, one run could narrow down a sweep. What else does the theory predict, before we see any data? 17 00:03:54,825 --> 00:04:13,850 [Dr. Ada Shannon] Four things. The noise scale grows during training, because the true gradient shrinks as loss falls while per-example noise doesn't. It's larger for harder tasks. At a fixed loss it depends only weakly on model size. And it's larger for reinforcement learning than for supervised learning, which would explain Dota. 18 00:04:13,850 --> 00:04:24,000 [Hal Turing] The growth during training is the part that changes how I'd think about batch size. If it's a moving target, a single number can't be right for the whole run. 19 00:04:24,000 --> 00:04:33,800 [Dr. Ada Shannon] Right, and that motivates batch sizes that increase over training. Next we need the derivation behind it, and how they measure B_simple for free. 20 00:04:33,800 --> 00:04:41,500 [Hal Turing] Let's get the derivation first, because the claim rests on it. What's the causal chain from the loss to a batch size? 21 00:04:41,500 --> 00:05:04,600 [Dr. Ada Shannon] It has four steps. First, expand the loss to second order around the current parameters. Second, the batch gradient is the true gradient plus noise, with variance Sigma over B. Third, pick the step size that minimizes expected loss. That gives an optimal step size equal to the noiseless maximum divided by one plus B_noise over B. Fourth, plug that back in. Loss progress per step is the maximum possible progress divided by one plus B_noise over B. 22 00:05:04,600 --> 00:05:08,775 [Hal Turing] So at B equal to B_noise, the denominator is two. 23 00:05:08,775 --> 00:05:27,350 [Dr. Ada Shannon] Yes, half the best possible progress per step. Far below B_noise, progress grows linearly with batch size. Far above it, progress is flat. The authors also warn that the derivation has, in their words, many unfounded assumptions. They argue it's still a useful guide, even for Adam and momentum. 24 00:05:27,350 --> 00:05:30,800 [Hal Turing] Does it say anything about learning rate? 25 00:05:30,800 --> 00:05:52,475 [Dr. Ada Shannon] It does, and this is where it parts ways with Goyal's linear scaling rule. The optimal step size rises roughly linearly with batch size and then saturates. Their SVHN run with plain SGD shows that shape. For Adam and RMSProp it follows a power law with exponent between about 0.5 and 1, then flattens. So linear scaling looks like the small-batch part of a curve, not a law that holds forever. 26 00:05:52,475 --> 00:05:58,225 [Hal Turing] That's one step at one point in the landscape. A real run visits many points. 27 00:05:58,225 --> 00:06:19,575 [Dr. Ada Shannon] Right. Averaging over training gives the hyperbola, S over S_min minus one, times E over E_min minus one, equals one. They find B_crit as follows. For each performance goal and each batch size, they tune the learning rate by grid search and keep the fastest run. Those runs form a Pareto front. They fit the hyperbola in log space and read off B_crit as E_min over S_min, with a standard error from the fit. 28 00:06:19,575 --> 00:06:25,325 [Hal Turing] Fitting a one-parameter family and then reading the knee off it sounds circular. 29 00:06:25,325 --> 00:06:48,275 [Dr. Ada Shannon] The shape agreement is partly built in. Nothing here tests the hyperbola against other families. They say the fit is remarkably good in most cases, with deviations at very small batches in some Atari games like Beam Rider, and noise in Pong, which is a single seed. What isn't built in is where the knee sits. B_simple comes from gradient statistics in one run, with no batch-size sweep. The real test is whether that number lands near the fitted E_min over S_min. 30 00:06:48,275 --> 00:06:51,625 [Hal Turing] And how do you get B_simple without a sweep? 31 00:06:51,625 --> 00:07:12,651 [Dr. Ada Shannon] In data-parallel training you already have two gradients. One is each device's local gradient, from the small batch. The other is the averaged gradient, from the big batch. Their squared norms differ by a known amount that depends on the noise. That gives unbiased estimates of the squared true gradient and of the total variance. Then you smooth each with a moving average and take the ratio. 32 00:07:12,651 --> 00:07:16,576 [Hal Turing] Why smooth before dividing? That sounds fussy. 33 00:07:16,576 --> 00:07:38,676 [Dr. Ada Shannon] The ratio of the raw estimates is biased, and the squared-gradient estimate comes from a delicate cancellation, so it's noisy. Averaging first fixes both. And it only works with a well-tuned learning rate, because the noise scale depends on the learning rate. That's the temperature point. At matched loss it's consistent across well-tuned runs, even at different batch sizes, so a small-batch run can measure it. If the learning rate is too small, the number comes out inflated. 34 00:07:38,676 --> 00:07:40,726 [Hal Turing] What did they run it on? 35 00:07:40,726 --> 00:08:02,101 [Dr. Ada Shannon] Eight tasks. MNIST, SVHN, CIFAR10, ImageNet, a Billion Word LSTM, seven Atari games with A2C, Dota 1v1 and 5v5 with PPO, and SVHN autoencoder and VAE. Learning rate tuned separately per batch size, and the supervised metrics are on the training set, since that's what the theory predicts. 36 00:08:02,101 --> 00:08:05,727 [Hal Turing] So does the statistic track the critical batch? 37 00:08:05,727 --> 00:08:35,477 [Dr. Ada Shannon] At the order-of-magnitude level, yes. B_crit runs from about 20 for the SVHN autoencoder to over ten million for Dota, roughly a half-million-fold range. One statistic from one run lands in the right neighborhood across all of it. Two caveats. The Dota 5v5 point is only a lower bound, since it's the batch the Dota team used and they didn't measure the Pareto front. And on SVHN with SGD, B_noise predicted B_crit better than B_simple, while with Adam B_simple was very accurate. 38 00:08:35,477 --> 00:08:39,977 [Hal Turing] Does the noise scale behave the way Part 1 said it would? 39 00:08:39,977 --> 00:09:01,277 [Dr. Ada Shannon] Mostly, yes. It grows during training. On ImageNet with ResNet-50, it goes from about two thousand to a hundred thousand in the main phase. In fine-tuning it reaches hundreds of thousands or millions. Their B_crit is about 15 thousand, below the 64 thousand Jia and colleagues reached in 2018. But those authors used layer-wise adaptive learning rates, and this paper didn't. 40 00:09:01,277 --> 00:09:06,027 [Hal Turing] So B_crit isn't a fixed property of the model and data. 41 00:09:06,027 --> 00:09:29,227 [Dr. Ada Shannon] Right, tricks move it. The other predictions held too. Harder image sets have larger noise scales, and that isn't determined by dataset size. The VAE is above the autoencoder, and both sit far below the SVHN classifiers. For the LSTMs, the noise scale is roughly independent of model size at fixed loss. Bigger models reach larger noise scales only by reaching lower loss. And Dota 5v5 is above Dota 1v1. 42 00:09:29,227 --> 00:09:32,327 [Hal Turing] What about Dota versus Atari? 43 00:09:32,327 --> 00:09:47,677 [Dr. Ada Shannon] Dota's noise scale is about a thousand times Atari's, yet the optimization steps are not much larger. The authors read that as a hint that much of the extra compute for stronger models may be parallelizable. That's their speculation. 44 00:09:47,677 --> 00:09:52,027 [Hal Turing] Last piece. What do they claim about adaptive batch sizes? 45 00:09:52,027 --> 00:10:07,352 [Dr. Ada Shannon] Only a rough model. If the critical batch grows over training, a schedule that tracks the noise scale should beat a fixed batch on efficiency. The main text offers that as a rough model of the benefits, not a measured result on every task. 46 00:10:07,352 --> 00:10:23,802 [Hal Turing] Let's judge the headline claim. The authors say B_simple predicts the critical batch at the order-of-magnitude level, and the ratio between them moves by about a factor of ten across task families. What does a prediction that loose buy someone? 47 00:10:23,802 --> 00:10:51,177 [Dr. Ada Shannon] It buys a starting range, not a batch size. The ratio is below one for the autoencoder, the VAE and Dota 1v1. It's near one for the LSTMs. It's above one for image classification and Atari. The authors say they lack an explanation, and the paper doesn't say how to know the direction in a new domain. Also, B_crit comes from the sweep itself, so the statistic can't replace the sweep when you need precision. My judgment, not the paper's: it narrows a search from many decades to roughly one. 48 00:10:51,177 --> 00:10:59,877 [Hal Turing] Then the six-decade plot flatters it. A tenfold miss on a log axis spanning twenty to ten million looks like nothing. 49 00:10:59,877 --> 00:11:22,777 [Dr. Ada Shannon] Right, and the paper reports no error metric and no null predictor. Here's my own back-of-envelope. A constant guess at the geometric middle of that range, about fourteen thousand, is several hundred times off at either end. B_simple is off by roughly ten. So it clearly beats a constant across domains. That's a weak bar, though, and the real bar is whether it beats trying a few batch sizes. Also, the Dota 5v5 point is a lower bound. They didn't measure a Pareto front there. 50 00:11:22,777 --> 00:11:26,352 [Hal Turing] What about the circularity we raised earlier? 51 00:11:26,352 --> 00:11:46,402 [Dr. Ada Shannon] The fit forces the shape, so shape agreement proves little. The knee location is the real test, because B_simple comes from gradient statistics with no batch sweep. But the fronts rest on hand-chosen goals, hand-chosen smoothing, and in places single seeds, and only fit standard errors are reported. We can't say how stable B_crit is under those choices. 52 00:11:46,402 --> 00:11:49,127 [Hal Turing] Is there an independent check? 53 00:11:49,127 --> 00:12:11,877 [Dr. Ada Shannon] Shallue's study, done in parallel. They measured steps to target across models, datasets and optimizers, and found the perfect-scaling, diminishing-returns and maximal-useful-batch regions depend strongly on all three. That fits the ratio varying across families. It also means the noise scale can't be the whole story. And the ImageNet gap we saw earlier says B_crit belongs to the task plus the optimizer recipe, so the claim needs that qualifier. 54 00:12:11,877 --> 00:12:16,103 [Hal Turing] Goyal's linear scaling rule comes out looking different. 55 00:12:16,103 --> 00:12:26,828 [Dr. Ada Shannon] It's a small-batch regime rule, since the theory has the best learning rate saturating at larger batches. Warmup sits outside the theory, and the authors say so. 56 00:12:26,828 --> 00:12:32,203 [Hal Turing] What about measuring it? The estimator subtracts two nearly equal numbers. 57 00:12:32,203 --> 00:12:52,053 [Dr. Ada Shannon] They admit that makes the squared gradient norm noisy, and they cope with heavy moving averages. The paper doesn't characterize how well that works late in training, when the signal is small. And you need a decent learning rate to measure the number that's meant to save you the search. Some saving survives, because a partial run at small batch can still point you somewhere. The paper doesn't say how much. 58 00:12:52,053 --> 00:12:54,903 [Hal Turing] What does it leave out entirely? 59 00:12:54,903 --> 00:13:10,928 [Dr. Ada Shannon] Anything beyond training loss. Generalization is set aside, citing Shallue for no generalization gap when the learning rate is tuned. And there are no transformers among the tasks, so whether the ratio behaves the same way there is unanswered. 60 00:13:10,928 --> 00:13:13,678 [Hal Turing] So what would someone do with it? 61 00:13:13,678 --> 00:13:32,928 [Dr. Ada Shannon] Watch the noise scale during one run, and expect it to rise. Treat batch size as a schedule, not a constant. The authors name open problems: explaining the ratio, other model classes, warmup, and adaptive batches. Their model-based RL point, from the autoencoder and VAE contrast, is speculation. 62 00:13:32,928 --> 00:13:57,228 [Hal Turing] So where does that leave us? The paper shows a cheap statistic from one run that roughly tracks the knee of the time-versus-compute curve across eight very different tasks, plus a clean hyperbolic trade-off. The limit is an unexplained bias of up to ten times. It needs a well-tuned learning rate, and it depends on the optimizer. It narrows the search rather than replacing measurement. Thanks for listening.