Neural scaling law

From AviationSafetyX Wiki
Jump to navigation Jump to search
Performance of AI models on various benchmarks from 1998 to 2024.

In machine learning, a neural scaling law is an empirical scaling law that describes how neural network performance changes as key factors are scaled up or down. These factors typically include the number of parameters, training dataset size,[1][2] and training cost.

Introduction[edit | edit source]

In general, a deep learning model can be characterized by four parameters: model size, training dataset size, training cost, and the post-training error rate (e.g., the test set error rate). Each of these variables can be defined as a real number, usually written as <math>N, D, C, L</math> (respectively: parameter count, dataset size, computing cost, and loss).

A neural scaling law is a theoretical or empirical statistical law between these parameters. There are also other parameters with other scaling laws.

Size of the model[edit | edit source]

In most cases, the model's size is simply the number of parameters. However, one complication arises with the use of sparse models, such as mixture-of-expert models.[3] With sparse models, during inference, only a fraction of their parameters are used. In comparison, most other kinds of neural networks, such as transformer models, always use all their parameters during inference.

Size of the training dataset[edit | edit source]

The size of the training dataset is usually quantified by the number of data points within it. Larger training datasets are typically preferred, as they provide a richer and more diverse source of information from which the model can learn. This can lead to improved generalization performance when the model is applied to new, unseen data.[4] However, increasing the size of the training dataset also increases the computational resources and time required for model training.

With the "pretrain, then finetune" method used for most large language models, there are two kinds of training dataset: the pretraining dataset and the finetuning dataset. Their sizes have different effects on model performance. Generally, the finetuning dataset is less than 1% the size of pretraining dataset.[5]

In some cases, a small amount of high quality data suffices for finetuning, and more data does not necessarily improve performance.[5]

Cost of training[edit | edit source]

Amortized hardware and energy cost to train frontier AI models over time.

Training cost is typically measured in terms of time (how long it takes to train the model) and computational resources (how much processing power and memory are required). It is important to note that the cost of training can be significantly reduced with efficient training algorithms, optimized software libraries, and parallel computing on specialized hardware such as GPUs or TPUs.

The cost of training a neural network model is a function of several factors, including model size, training dataset size, the training algorithm complexity, and the computational resources available.[4] In particular, doubling the training dataset size does not necessarily double the cost of training, because one may train the model for several times over the same dataset (each being an "epoch").

Performance[edit | edit source]

MMLU performance vs AI scale as a sigmoid
BIG-Bench (hard)[6] performance vs AI scale as a sigmoid.
Performance on several benchmarks vs negative log-likelihood loss <math>L</math> (with <math>L_0</math> removed), fitted as sigmoid functions.[7]Template:Pg

The performance of a neural network model is evaluated based on its ability to accurately predict the output given some input data. Common metrics for evaluating model performance include:[4]

Performance can be improved by using more data, larger models, different training algorithms, regularizing the model to prevent overfitting, and early stopping using a validation set.

When the performance is a number bounded within the range of <math>[0, 1]</math>, such as accuracy, precision, etc., it often scales as a sigmoid function of cost, as seen in the figures.

Examples[edit | edit source]

(Hestness, Narang, et al, 2017)[edit | edit source]

The 2017 paper[2] is a common reference point for neural scaling laws fitted by statistical analysis on experimental data. Previous works before the 2000s, as cited in the paper, were either theoretical or orders of magnitude smaller in scale. Whereas previous works generally found the scaling exponent to scale like <math>L \propto D^{-\alpha} </math>, with <math>\alpha \in \{0.5, 1, 2\} </math>, the paper found that <math>\alpha \in [0.07, 0.35]</math>.

Of the factors they varied, only task can change the exponent <math>\alpha</math>. Changing the architecture optimizers, regularizers, and loss functions, would only change the proportionality factor, not the exponent. For example, for the same task, one architecture might have <math>L = 1000 D^{-0.3} </math> while another might have <math>L = 500 D^{-0.3}</math>. They also found that for a given architecture, the number of parameters necessary to reach lowest levels of loss, given a fixed dataset size, grows like <math>N \propto D^{\beta}</math> for another exponent <math>\beta</math>.

They studied machine translation with LSTM (<math>\alpha \sim 0.13 </math>), generative language modelling with LSTM (<math>\alpha \in [0.06, 0.09], \beta \approx 0.7</math>), ImageNet classification with ResNet (<math>\alpha \in [0.3, 0.5], \beta \approx 0.6</math>), and speech recognition with two hybrid (LSTMs complemented by either CNNs or an attention decoder) architectures (<math>\alpha \approx 0.3</math>).

(Henighan, Kaplan, et al, 2020)[edit | edit source]

A 2020 analysis [10] studied statistical relations between <math>C, N, D, L</math> over a wide range of values and found similar scaling laws, over the range of <math>N \in [10^3, 10^9]</math>, <math>C\in [10^{12}, 10^{21}]</math>, and over multiple modalities (text, video, image, text to image, etc.).[10]

In particular, the scaling laws it found are (Table 1 of [10]):

  • For each modality, they fixed one of the two <math>C, N</math>, and varying the other one (<math>D</math> is varied along using <math>D = C/6N</math>), the achievable test loss satisfies<math display="block">L = L_0 + \left( \frac{x_0}{x}\right)^\alpha</math>where <math>x</math> is the varied variable, and <math>L_0, x_0, \alpha</math> are parameters to be found by statistical fitting. The parameter <math>\alpha</math> is the most important one.
    • When <math>N</math> is the varied variable, <math>\alpha</math> ranges from <math>0.037 </math> to <math>0.24</math> depending on the model modality. This corresponds to the <math>\alpha = 0.34 </math> from the Chinchilla scaling paper.
    • When <math>C</math> is the varied variable, <math>\alpha</math> ranges from <math>0.048 </math> to <math>0.19</math> depending on the model modality. This corresponds to the <math>\beta = 0.28 </math> from the Chinchilla scaling paper.
  • Given fixed computing budget, optimal model parameter count is consistently around<math display="block">N_{opt}(C) =\left(\frac{C}{5\times 10^{-12}\text{petaFLOP-day}}\right)^{0.7} = 9.0\times 10^{-7} C^{0.7}</math>The parameter <math>9.0 \times 10^{-7}</math> varies by a factor of up to 10 for different modalities. The exponent parameter <math>0.7</math> varies from <math>0.64</math> to <math>0.75</math> for different modalities. This exponent corresponds to the <math>\approx 0.5</math> from the Chinchilla scaling paper.
  • It's "strongly suggested" (but not statistically checked) that <math>D_{opt}(C) \propto N_{opt}(C)^{0.4} \propto C^{0.28}</math>. This exponent corresponds to the <math>\approx 0.5</math> from the Chinchilla scaling paper.

The scaling law of <math>L = L_0 + (C_0/C)^{0.048}</math> was confirmed during the training of GPT-3 (Figure 3.1 [11]).

Chinchilla scaling (Hoffmann, et al, 2022)[edit | edit source]

Optimal ratio of training tokens to model parameters for Chinchilla scaling law. It shows that in general, "Chinchilla optimal" scaling is <math>D = 20 N</math>, and is significantly different from (Hoffmann et al., 2022). Data analysis by Epoch AI.[12]

One particular scaling law ("Chinchilla scaling") states that, for a large language model (LLM) autoregressively trained for one epoch, with a cosine learning rate schedule, we have:[13]<math display="block">\begin{cases} C = C_0 ND\\ L = \frac{A}{N^\alpha} + \frac{B}{D^{\beta}} + L_0 \end{cases}</math>where the variables are

  • <math>C</math> is the cost of training the model, in FLOPS.
  • <math>N</math> is the number of parameters in the model.
  • <math>D</math> is the number of tokens in the training set.
  • <math>L</math> is the average negative log-likelihood loss per token (nats/token), achieved by the trained LLM on the test dataset.
    • <math>L_0</math> represents the loss of an ideal generative process on the test data
    • <math>\frac{A}{N^\alpha}</math> captures the fact that a Transformer language model with <math>N</math> parameters underperforms the ideal generative process
    • <math>\frac{B}{D^\beta}</math> captures the fact that the model trained on <math>D</math> tokens underperforms the ideal generative process

and the statistical parameters are

  • <math> C_0 = 6</math>, meaning that it costs 6 FLOPs per parameter to train on one token. This is estimated by Kaplan et al.[14] Note that training cost is much higher than inference cost, as training entails both forward and backward passes, whereas inference costs 1 to 2 FLOPs per parameter to infer on one token.
  • <math>\alpha = 0.34, \beta = 0.28, A = 406.4, B = 410.7, L_0 = 1.69</math>.

Although Besiroglu et al.[15] claims that the statistical estimation is slightly off, and should be <math>\alpha = 0.35, \beta = 0.37, A = 482.01, B = 2085.43, L_0 = 1.82</math>.

The statistical laws were fitted over experimental data with <math>N\in [7\times 10^7, 1.6 \times 10^{10}], D \in [5\times 10^9, 5\times 10^{11}], C \in [10^{18}, 10^{24}]</math>.

Since there are 4 variables related by 2 equations, imposing 1 additional constraint and 1 additional optimization objective allows us to solve for all four variables. In particular, for any fixed <math>C</math>, we can uniquely solve for all 4 variables that minimizes <math>L</math>. This provides us with the optimal <math>D_{opt}(C), N_{opt}(C)</math> for any fixed <math>C</math>:<math display="block">N_{o p t}(C)=G\left(\frac{C}{6}\right)^a, \quad D_{o p t}(C)=G^{-1}\left(\frac{C}{6}\right)^b, \quad \text { where } \quad G=\left(\frac{\alpha A}{\beta B}\right)^{\frac{1}{\alpha+\beta}}, \quad a=\frac{\beta}{\alpha+\beta} \text {, and } b=\frac{\alpha}{\alpha+\beta} \text {. }</math>Plugging in the numerical values, we obtain the "Chinchilla efficient" model size and training dataset size, as well as the test loss achievable:<math display="block">\begin{cases} N_{opt}(C) = 0.6 \; C^{0.45} \\ D_{opt}(C) = 0.3 \; C^{0.55} \\ L_{opt}(C) = 1070 \; C^{-0.154} + 1.7 \end{cases}</math>Similarly, we may find the optimal training dataset size and training compute budget for any fixed model parameter size, and so on.

There are other estimates for "Chinchilla efficient" model size and training dataset size. The above is based on a statistical model of <math>L = \frac{A}{N^\alpha} + \frac{B}{D^{\beta}} + L_0</math>. One can also directly fit a statistical law for <math>D_{opt}(C), N_{opt}(C)</math> without going through the detour, for which one obtains:<math display="block">\begin{cases} N_{opt}(C) = 0.1 \; C^{0.5}\\ D_{opt}(C) = 1.7 \; C^{0.5} \end{cases}</math>or as tabulated:

<math>N_{opt}(C)</math> <math>C</math> / FLOP <math>C</math> / FLOPs of training Gopher <math>D_{opt}(C)</math>
400 million 1.92e+19 1/29968 8.0 billion
1 billion 1.21e+20 1/5706 20.2 billion
10 billion 1.23e+22 1/2819 205.1 billion
67 billion 5.76e+23 1 1.5 trillion
175 billion 3.85e+24 6.7 3.7 trillion
280 billion 9.90e+24 17.2 5.9 trillion
520 billion 3.43e+25 59.5 11.0 trillion
1 trillion 1.27e+26 221.3 21.2 trillion
10 trillion 1.30e+28 22515.9 216.2 trillion

Discrepancy[edit | edit source]

The Chinchilla scaling law analysis for training transformer language models suggests that for a given training compute budget (<math>C</math>), to achieve the minimal pretraining loss for that budget, the number of model parameters (<math>N</math>) and the number of training tokens (<math>D</math>) should be scaled in equal proportions, <math>N_{opt}(C) \propto C^{0.5}, D_{opt}(C) \propto C^{0.5}</math>. This conclusion differs from analysis conducted by Kaplan et al.,[14] which found that <math>N</math> should be increased more quickly than <math>D</math>, <math>N_{opt}(C) \propto C^{0.73}, D_{opt}(C) \propto C^{0.27}</math>.

This discrepancy can primarily be attributed to the two studies using different methods for measuring model size. Kaplan et al.:[16]

  • did not count the parameters in the token embedding layer, which when analyzed at smaller model sizes leads to biased coefficients;
  • studied smaller models than the Chinchilla group, magnifying the effect;
  • assumed that <math>L_\infty = 0</math>.

Secondary effects also arise due to differences in hyperparameter tuning and learning rate schedules. Kaplan et al.:[17]

  • used a warmup schedule that was too long for smaller models, making them appear less efficient;
  • did not fully tuning optimization hyperparameters.

Beyond Chinchilla scaling[edit | edit source]

As Chinchilla scaling has been the reference point for many large-scaling training runs, there had been a concurrent effort to go "beyond Chinchilla scaling", meaning to modify some of the training pipeline in order to obtain the same loss with less effort, or deliberately train for longer than what is "Chinchilla optimal".

Usually, the goal is to make the scaling law exponent larger, which means the same loss can be trained for much less compute. For instance, filtering data can make the scaling law exponent larger.[18]

Another strand of research studies how to deal with limited data, as according to Chinchilla scaling laws, the training dataset size for the largest language models already approaches what is available on the internet.[19] found that augmenting the dataset with a mix of "denoising objectives" constructed from the dataset improves performance.[20] studies optimal scaling when all available data is already exhausted (such as in rare languages), so one must train multiple epoches over the same dataset (whereas Chinchilla scaling requires only one epoch). The Phi series of small language models were trained on textbook-like data generated by large language models, for which data is only limited by amount of compute available.[21]

Chinchilla optimality was defined as "optimal for training compute", whereas in actual production-quality models, there will be a lot of inference after training is complete. "Overtraining" during training means better performance during inference.[22] LLaMA models were overtrained for this reason. Subsequent studies discovered scaling laws in the overtraining regime, for dataset sizes up to 32x more than Chinchilla-optimal.[23]

Broken neural scaling laws (BNSL)[edit | edit source]

A 2022 analysis[24] found that many scaling behaviors of artificial neural networks follow a smoothly broken power law functional form:

<math>y = a + \bigg(bx^{-c_0}\bigg) \prod_{i=1}^n \left(1 + \left(\frac{x}{d_i}\right)^{1/f_i}\right)^{-c_i * f_i}</math>

in which <math>x</math> refers to the quantity being scaled (i.e. <math>C</math>, <math>N</math>, <math>D</math>, number of training steps, number of inference steps, or model input size) and <math>y</math> refers to the downstream (or upstream) performance evaluation metric of interest (e.g. prediction error, cross entropy, calibration error, AUROC, BLEU score percentage, F1 score, reward, Elo rating, solve rate, or FID score) in zero-shot, prompted, or fine-tuned settings. The parameters <math>a, b, c_0, c_1 ... c_n, d_1 ... d_n, f_1 ... f_n</math> are found by statistical fitting.

On a log–log plot, when <math>f_i</math> is not too large and <math>a</math> is subtracted out from the y-axis, this functional form looks like a series of linear segments connected by arcs; the <math>n</math> transitions between the segments are called "breaks", hence the name broken neural scaling laws (BNSL).

The scenarios in which the scaling behaviors of artificial neural networks were found to follow this functional form include large-scale vision, language, audio, video, diffusion, generative modeling, multimodal learning, contrastive learning, AI alignment, AI capabilities, robotics, out-of-distribution (OOD) generalization, continual learning, transfer learning, uncertainty estimation / calibration, out-of-distribution detection, adversarial robustness, distillation, sparsity, retrieval, quantization, pruning, fairness, molecules, computer programming/coding, math word problems, arithmetic, emergent abilities, double descent, supervised learning, unsupervised/self-supervised learning, and reinforcement learning (single agent and multi-agent).

The architectures for which the scaling behaviors of artificial neural networks were found to follow this functional form include residual neural networks, transformers, MLPs, MLP-mixers, recurrent neural networks, convolutional neural networks, graph neural networks, U-nets, encoder-decoder (and encoder-only) (and decoder-only) models, ensembles (and non-ensembles), MoE (mixture of experts) (and non-MoE) models, and sparse pruned (and non-sparse unpruned) models.

Inference scaling[edit | edit source]

The Elo rating of various AlphaZero agents trained to play the board game of Hex at varying train-time and test-time compute.

<templatestyles src="Module:Hatnote/styles.css"></templatestyles>

Other than scaling up training compute, one can also scale up inference compute (or "test-time compute"[25]). As an example, the Elo rating of AlphaGo improves steadily as it is allowed to spend more time on its Monte Carlo Tree Search per play.[26]Template:Pg For AlphaGo Zero, increasing Elo by 120 requires either 2x model size and training, or 2x test-time search.[27] Similarly, a language model for solving competition-level coding challenges, AlphaCode, consistently improved (log-linearly) in performance with more search time.[28]

For Hex, 10x training-time compute trades for 15x test-time compute.[8] For Libratus for heads up no-limit Texas hold 'em, and Cicero for Diplomacy, and many other abstract games of partial information, inference-time searching improves performance at a similar tradeoff ratio, for up to 100,000x effective increase in training-time compute.[27]

In 2024, the OpenAI o1 report documented that o1's performance consistently improved with both increased train-time compute and test-time compute, and gave numerous examples of test-time compute scaling in mathematics, scientific reasoning, and coding tasks.[29][30]

One method for scaling up test-time compute is process-based supervision, where a model generates a step-by-step reasoning chain to answer a question, and another model (either human or AI) provides a reward score on some of the intermediate steps, not just the final answer. Process-based supervision can be scaled arbitrarily by using synthetic reward score without another model, for example, by running Monte Carlo rollouts and scoring each step in the reasoning according to how likely it leads to the right answer. Another method is by revision models, which are models trained to solve a problem multiple times, each time revising the previous attempt.[31]

Other examples[edit | edit source]

Vision transformers[edit | edit source]

Vision transformers, similar to language transformers, exhibit scaling laws. A 2022 research trained vision transformers, with parameter counts <math>N\in [5\times 10^6, 2\times 10^9]</math>, on image sets of sizes <math>D \in [3\times 10^{7}, 3\times 10^{9}]</math>, for computing <math>C\in [0.2, 10^4] </math> (in units of TPUv3-core-days).[32]

After training the model, it is finetuned on ImageNet training set. Let <math>L</math> be the error probability of the finetuned model classifying ImageNet test set. They found <math>\min_{N, D} L = 0.09 + \frac {0.26}{(C + 0.01)^{0.35}}</math>.

Neural machine translation[edit | edit source]

Ghorbani, Behrooz et al.[33] studied scaling laws for neural machine translation (specifically, English as source, and German as target) in encoder-decoder Transformer models, trained until convergence on the same datasets (thus they did not fit scaling laws for computing cost <math>C</math> or dataset size <math>D</math>). They varied <math>N \in [10^8, 3.5 \times 10^9]</math> They found three results:

  • <math>L</math> is a scaling law function of <math>N_E, N_D</math>, where <math>N_E, N_D</math> are encoder and decoder parameter count. It is not simply a function of total parameter count <math>N = N_E + N_D</math>. The function has form <math>L\left(N_e, N_d\right)=\alpha\left(\frac{\bar{N}_e}{N_e}\right)^{p_e}\left(\frac{\bar{N}_d}{N_d}\right)^{p_d}+L_{\infty}</math>, where <math>\alpha, p_e, p_d, L_{\infty}, \bar N_e, \bar N_d</math> are fitted parameters. They found that <math>N_d/N \approx 0.55</math> minimizes loss if <math>N</math> is held fixed.
  • <math>L</math> "saturates" (that is, it reaches <math>L_\infty</math>) for smaller models when the training and testing datasets are "source-natural" than "target-natural". A "source-natural" data point means a pair of English-German sentences, and the model is asked to translate the English sentence into German, and the English sentence is written by a natural English writer, while the German sentence is translated from the English sentence by a machine translator.[34] To construct the two kinds of datasets, the authors collected natural English and German sentences online, then used machine translation to generate their translations.
  • As models grow larger, models trained on source-original datasets can achieve low loss but bad BLEU score. In contrast, models trained on target-original datasets achieve low loss and good BLEU score in tandem (Figure 10, 11 [33]).

The authors hypothesize that source-natural datasets have uniform and dull target sentences, and so a model that is trained to predict the target sentences would quickly overfit.

[35] trained Transformers for machine translations with sizes <math>N \in [4 \times 10^5 , 5.6 \times 10^7]</math> on dataset sizes <math>D \in [6\times 10^5, 6 \times 10^9]</math>. They found the Kaplan et al. (2020)[14] scaling law applied to machine translation: <math>L(N, D)=\left[\left(\frac{N_C}{N}\right)^{\frac{\alpha_N}{\alpha_D}}+\frac{D_C}{D}\right]^{\alpha_D}</math>. They also found the BLEU score scaling as <math>BLEU \approx C e^{-kL}</math>.

Transfer learning[edit | edit source]

Hernandez, Danny et al.[36] studied scaling laws for transfer learning in language models. They trained a family of Transformers in three ways:

  • pretraining on English, finetuning on Python
  • pretraining on an equal mix of English and Python, finetuning on Python
  • training on Python

The idea is that pretraining on English should help the model achieve low loss on a test set of Python text. Suppose the model has parameter count <math>N</math>, and after being finetuned on <math>D_F</math> Python tokens, it achieves some loss <math>L</math>. We say that its "transferred token count" is <math>D_T</math>, if another model with the same <math>N</math> achieves the same <math>L</math> after training on <math>D_F + D_T</math> Python tokens.

They found <math>D_T=1.9 e 4\left(D_F\right)^{.18}(N)^{.38}</math> for pretraining on English text, and <math>D_T=2.1 e 5\left(D_F\right)^{.096}(N)^{.38}</math> for pretraining on English and non-Python code.

Precision[edit | edit source]

Kumar et al.[37] study scaling laws for numerical precision in the training of language models. They train a family of language models with weights, activations, and KV cache in varying numerical precision in both integer and floating-point type to measure the effects on loss as a function of precision. For training, their scaling law accounts for lower precision by wrapping the effects of precision into an overall "effective parameter count" that governs loss scaling, using the parameterization <math>N \mapsto N_\text{eff}(P) = N(1-e^{-P/\gamma})</math>. This illustrates how training in lower precision degrades performance by reducing the true capacity of the model in a manner that varies exponentially with bits.

For inference, they find that extreme overtraining of language models past Chinchilla-optimality can lead to models being more sensitive to quantization, a standard technique for efficient deep learning. This is demonstrated by observing that the degradation in loss due to weight quantization increases as an approximate power law in the token/parameter ratio <math>D/N</math> seen during pretraining, so that models pretrained on extreme token budgets can perform worse in terms of validation loss than those trained on more modest token budgets if post-training quantization is applied. Other work examining the effects of overtraining include Sardana et al.[38] and Gadre et al.[39]

Densing laws[edit | edit source]

Xiao et al.[7] considered the parameter efficiency ("density") of models over time. The idea is that over time, researchers would discover models that use their parameters more efficiently, in that models with the same performance can have fewer parameters.

A model can have an actual parameter count <math>N</math>, defined as the actual number of parameters in the model, and an "effective" parameter count <math>\hat N</math>, defined as how many parameters it would have taken a previous well-known model to reach he same performance on some benchmarks, such as MMLU. <math>\hat N</math> is not measured directly, but rather by measuring the actual model performance <math>S</math>, then plugging it back to a previously fitted scaling law, such as the Chinchilla scaling law, to obtain what <math>\hat N</math> would be required to reach that performance <math>S</math>, according to that previously fitted scaling laws.

A densing law states that <math>\ln \left(\frac{\hat N}{N}\right)_{max} = At + B</math>, where <math>t</math> is real-world time, measured in days.

See also[edit | edit source]

<templatestyles src="Div col/styles.css"/>

References[edit | edit source]

  1. 2.0 2.1
  2. 4.0 4.1 4.2 Goodfellow, I., Bengio, Y., & Courville, A. (2016). Deep Learning. MIT Press.
  3. 5.0 5.1
  4. google/BIG-bench.  (2024-09-24)  Google.  Retrieved 2024-09-25 from link
  5. 7.0 7.1
  6. 8.0 8.1
  7. LMSYS Chatbot leaderboard
  8. 10.0 10.1 10.2
  9. Chinchilla Scaling: A Replication Attempt.  Tamay Besiroglu.  (2024-04-17)  Retrieved 2024-09-24 from Epoch AI
  10. 14.0 14.1 14.2
  11. 27.0 27.1 Template:Cite AV media Lecture at Paul G. Allen School on Thursday, May 23, 2024, 3:30 pm
  12. Trading Off Compute in Training and Inference.  Pablo Villalobos.  (2023-07-28)  Retrieved 2024-09-24 from Epoch AI
  13. Learning to Reason with LLMs.  OpenAI.  Retrieved 2024-09-16 from link
  14. 33.0 33.1