Neural scaling law explained

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

In general, a neural model can be characterized by 4 parameters: size of the model, size of the training dataset, cost of training, error rate after training. Each of these four variables can be precisely defined into a real number, and they are empirically found to be related by simple statistical laws, called "scaling laws". These are usually written as

N,D,C,L

(number of parameters, dataset size, computing cost, loss).

Size of the model

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

Size of the training dataset

The size of the training dataset is usually quantified by the number of data points it contains. Larger training datasets are typically preferred as they provide a richer and more diverse source of information for the model to learn from. This in turn can lead to improved generalization performance when the model is applied to 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 in most large language models, there are two kinds of training dataset: the pretraining dataset and the finetuning dataset. Their sizes would 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 improve performance.

Cost of training

The cost of training 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 to train the model). It's 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 like GPUs or TPUs.

The cost of training a neural model is a function of several factors including the size of the model, the size of the training dataset, the complexity of the training algorithm, and the computational resources available. In particular, doubling the training dataset 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

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

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.

Examples

(Hestness, Narang, et al, 2017)

The 2017 paper 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

L\proptoD-\alpha

, with

\alpha\in\{0.5,1,2\}

, the paper found that

\alpha\in[0.07,0.35]

.

Of the factors they varied, only task can change the exponent

\alpha

. 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

L=1000D-0.3

while another might have

L=500D-0.3

. The 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

N\proptoD\beta

for another exponent

\beta

.

They studied machine translation with LSTM (

\alpha\sim0.13

), generative language modelling with LSTM (

\alpha\in[0.06,0.09],\beta0.7

), ImageNet classification with ResNet (

\alpha\in[0.3,0.5],\beta0.6

), and speech recognition (

\alpha0.3

).

(Henighan, Kaplan, et al, 2020)

A 2020 analysis [8] studied statistical relations between

C,N,D,L

over a wide range of values and found similar scaling laws, over the range of

N\in[103,109]

,

C\in[1012,1021]

, and over multiple modalities (text, video, image, text to image, etc.).

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

C,N

, and varying the other one (

D

is varied along using

D=C/6N

), the achievable test loss satisfiesL = L_0 + \left(\frac\right)^\alphawhere

x

is the varied variable, and

L0,x0,\alpha

are parameters to be found by statistical fitting. The parameter

\alpha

is the most important one.

N

is the varied variable,

\alpha

ranges from

0.037

to

0.24

depending on the model modality. This corresponds to the

\alpha=0.34

from the Chinchilla scaling paper.

C

is the varied variable,

\alpha

ranges from

0.048

to

0.19

depending on the model modality. This corresponds to the

\beta=0.28

from the Chinchilla scaling paper.

9.0 x 10-7

varies by a factor of up to 10 for different modalities. The exponent parameter

0.7

varies from

0.64

to

0.75

for different modalities. This exponent corresponds to the

0.5

from the Chinchilla scaling paper.

Dopt(C)\proptoNopt(C)0.4\proptoC0.28

. This exponent corresponds to the

0.5

from the Chinchilla scaling paper.

The scaling law of

L=L0+

0.048
(C
0/C)
was confirmed during the training of GPT-3 (Figure 3.1 [9]).

Chinchilla scaling (Hoffmann, et al, 2022)

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:[10] \beginC = C_0 ND\\L = \frac + \frac + L_0\endwhere the variables are

C

is the cost of training the model, in FLOPS.

N

is the number of parameters in the model.

D

is the number of tokens in the training set.

L

is the average negative log-likelihood loss per token (nats/token), achieved by the trained LLM on the test dataset.

L0

represents the loss of an ideal generative process on the test data
A
N\alpha
captures the fact that a Transformer language model with

N

parameters underperforms the ideal generative process
B
D\beta
captures the fact that the model trained on

D

tokens underperforms the ideal generative process

and the statistical parameters are

C0=6

, meaning that it costs 6 FLOPs per parameter to train on one token. This is estimated by Kaplan et al.[11] 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.

\alpha=0.34,\beta=0.28,A=406.4,B=410.7,L0=1.69

.Although Besiroglu et. al. claims that the statistical estimation is slightly off, and should be

\alpha=0.35,\beta=0.37,A=482.01,B=2085.43,L0=1.82

.

The statistical laws were fitted over experimental data with

N\in[7 x 107,1.6 x 1010],D\in[5 x 109,5 x 1011],C\in[1018,1024]

.

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

C

, we can uniquely solve for all 4 variables that minimizes

L

. This provides us with the optimal

Dopt(C),Nopt(C)

for any fixed

C

:N_(C)=G\left(\frac\right)^a, \quad D_(C)=G^\left(\frac\right)^b, \quad \text \quad G=\left(\frac\right)^, \quad a=\frac \text b=\frac \text Plugging in the numerical values, we obtain the "Chinchilla efficient" model size and training dataset size, as well as the test loss achievable:\beginN_(C) = 0.6 \; C^ \\D_(C) = 0.3 \; C^ \\L_(C) = 1070 \; C^ + 1.7\endSimilarly, 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

L=

A
N\alpha

+

B
D\beta

+L0

. One can also directly fit a statistical law for

Dopt(C),Nopt(C)

without going through the detour, for which one obtains:\beginN_(C) = 0.1 \; C^\\D_(C) = 1.7 \; C^\endor as tabulated:
!

Nopt(C)

!

C

/ FLOP!

C

/ FLOPs of training Gopher!

Dopt(C)

400 Million1.92e+191/299688.0 Billion
1 Billion1.21e+201/570620.2 Billion
10 Billion1.23e+221/2819205.1 Billion
67 Billion5.76e+2311.5 Trillion
175 Billion3.85e+246.73.7 Trillion
280 Billion9.90e+2417.25.9 Trillion
520 Billion3.43e+2559.511.0 Trillion
1 Trillion1.27e+26221.321.2 Trillion
10 Trillion1.30e+2822515.9216.2 Trillion
In simpler terms, the Chinchilla scaling law for training Transformer language models suggests that when given an increased budget (in FLOPs), to achieve compute-optimal, the number of model parameters (N) and the number of tokens for training the model (D) should scale in approximately equal proportions. This conclusion differs from the previous scaling law for neural language models, which states that N should be scaled faster than D. The discrepancy arises from setting different cycle lengths for cosine learning rate schedulers. In estimating the Chinchilla scaling, the authors set the cycle length to be the same as the training steps, as experimental results indicate that larger cycles overestimate the loss of the models.

Beyond Chinchilla scaling

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.

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. found that augmenting the dataset with a mix of "denoising objectives" constructed from the dataset improves performance. [12] 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.

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. 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.

Broken Neural Scaling Laws (BNSL)

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

y=a+

-c0
(bx

)

n
\prod
i=1

\left(1+\left(

x
di
1/fi
\right)
-ci*fi
\right)

in which

x

refers to the quantity being scaled (i.e.

C

,

N

,

D

, number of training steps, number of inference steps, or model input size) and

y

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

a,b,c0,c1...cn,d1...dn,f1...fn

are found by statistical fitting.

On a log–log plot, when

fi

is not too large and

a

is subtracted out from the y-axis, this functional form looks like a series of linear segments connected by arcs; the

n

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 ResNets, 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.

Other examples

Vision transformers

Vision transformers, similar to language transformers, exhibit scaling laws. A 2022 research trained vision transformers, with parameter counts

N\in[5 x 106,2 x 109]

, on image sets of sizes

D\in[3 x 107,3 x 109]

, for computing

C\in[0.2,104]

(in units of TPUv3-core-days).[14]

After training the model, it is finetuned on ImageNet training set. Let

L

be the error probability of the finetuned model classifying ImageNet test set. They found

minN,L=0.09+

0.26
(C+0.01)0.35
.

Neural machine translation

Ghorbani, Behrooz et al.[15] 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

C

or dataset size

D

). They varied

N\in[108,3.5 x 109]

They found three results:

L

is a scaling law function of

NE,ND

, where

NE,ND

are encoder and decoder parameter count. It is not simply a function of total parameter count

N=NE+ND

. The function has form

L\left(Ne,

N
d\right)=\alpha\left(\bar{N
e}{N
pe
\left(
e}\right)
\bar{N
d}{N
pd
d}\right)

+Linfty

, where

\alpha,pe,pd,Linfty,\barNe,\barNd

are fitted parameters. They found that

Nd/N0.55

minimizes loss if

N

is held fixed.

L

"saturates" (that is, it reaches

Linfty

) 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.[16] To construct the two kinds of datasets, the authors collected natural English and German sentences online, then used machine translation to generate their translations.

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.

[17] trained Transformers for machine translations with sizes

N\in[4 x 105,5.6 x 107]

on dataset sizes

D\in[6 x 105,6 x 109]

. They found the Kaplan et al (2020) scaling law applied to machine translation:

L(N,D)=\left[\left(

NC
N
\alphaN
\alphaD
\right)+
DC
D
\alphaD
\right]
. They also found the BLEU score scaling as

BLEUCe-kL

.

Transfer learning

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

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

N

, and after being finetuned on

DF

Python tokens, it achieves some loss

L

. We say that its "transferred token count" is

DT

, if another model with the same

N

achieves the same

L

after training on

DF+DT

Python tokens.

They found

DT=1.9e

.18
4\left(D
F\right)

(N).38

for pretraining on English text, and

DT=2.1e

.096
5\left(D
F\right)

(N).38

for pretraining on English and non-Python code.

See also

References

  1. Bahri . Yasaman . Dyer . Ethan . Kaplan . Jared . Lee . Jaehoon . Sharma . Utkarsh . 2024 . Explaining neural scaling laws . . 121 . 27 . 2102.06701 . 10.1073/pnas.2311878121 . free.
  2. 1712.00409 . cs.LG . Joel . Hestness . Sharan . Narang . Deep Learning Scaling is Predictable, Empirically . 2017-12-01 . Ardalani . Newsha . Diamos . Gregory . Jun . Heewoo . Kianinejad . Hassan . Patwary . Md Mostofa Ali . Yang . Yang . Zhou . Yanqi.
  3. Rajbhandari . Samyam . Li . Conglong . Yao . Zhewei . Zhang . Minjia . Aminabadi . Reza Yazdani . Awan . Ammar Ahmad . Rasley . Jeff . He . Yuxiong . 2022-06-28 . DeepSpeed-MoE: Advancing Mixture-of-Experts Inference and Training to Power Next-Generation AI Scale . Proceedings of the 39th International Conference on Machine Learning . en . PMLR . 18332–18346. 2201.05596 .
  4. Goodfellow, I., Bengio, Y., & Courville, A. (2016). Deep Learning. MIT Press.
  5. Zhou . Chunting . Liu . Pengfei . Xu . Puxin . Iyer . Srini . Sun . Jiao . Mao . Yuning . Ma . Xuezhe . Efrat . Avia . Yu . Ping . Yu . Lili . Zhang . Susan . Ghosh . Gargi . Lewis . Mike . Zettlemoyer . Luke . Levy . Omer . 2023-05-01 . LIMA: Less Is More for Alignment . cs.CL . 2305.11206 .
  6. 2104.03113 . Jones . Andy L. . Scaling Scaling Laws with Board Games . 2021 . cs.LG .
  7. https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard LMSYS Chatbot leaderboard
  8. Book: Sam, Henighan, Tom Kaplan, Jared Katz, Mor Chen, Mark Hesse, Christopher Jackson, Jacob Jun, Heewoo Brown, Tom B. Dhariwal, Prafulla Gray, Scott Hallacy, Chris Mann, Benjamin Radford, Alec Ramesh, Aditya Ryder, Nick Ziegler, Daniel M. Schulman, John Amodei, Dario McCandlish . Scaling Laws for Autoregressive Generative Modeling . 2020-10-27 . 1228442047.
  9. Brown . Tom B. . Mann . Benjamin . Ryder . Nick . Subbiah . Melanie . Kaplan . J. . Dhariwal . Prafulla . Neelakantan . Arvind . Shyam . Pranav . Sastry . Girish . Askell . Amanda . Agarwal . Sandhini . Herbert-Voss . Ariel . Krueger . Gretchen . Henighan . T. . Child . Rewon . 2020-05-28 . Language Models are Few-Shot Learners . cs.CL . 2005.14165 .
  10. Hoffmann . Jordan . Borgeaud . Sebastian . Mensch . Arthur . Buchatskaya . Elena . Cai . Trevor . Rutherford . Eliza . Casas . Diego de Las . Hendricks . Lisa Anne . Welbl . Johannes . Clark . Aidan . Hennigan . Tom . Noland . Eric . Millican . Katie . Driessche . George van den . Damoc . Bogdan . 2022-03-29 . Training Compute-Optimal Large Language Models . cs.CL . 2203.15556 .
  11. Kaplan . Jared . McCandlish . Sam . Henighan . Tom . Brown . Tom B. . Chess . Benjamin . Child . Rewon . Gray . Scott . Radford . Alec . Wu . Jeffrey . Amodei . Dario . Scaling Laws for Neural Language Models . CoRR . abs/2001.08361 . 2020 . 2001.08361.
  12. Muennighoff . Niklas . Rush . Alexander . Barak . Boaz . Le Scao . Teven . Tazi . Nouamane . Piktus . Aleksandra . Pyysalo . Sampo . Wolf . Thomas . Raffel . Colin A. . 2023-12-15 . Scaling Data-Constrained Language Models . Advances in Neural Information Processing Systems . en . 36 . 50358–50376. 2305.16264 .
  13. 2210.14891 . Caballero . Ethan . Gupta . Kshitij . Rish . Irina . Krueger . David . Broken Neural Scaling Laws . 2022 . cs.LG .
  14. Zhai . Xiaohua . Kolesnikov . Alexander . Houlsby . Neil . Beyer . Lucas . 2022 . Scaling Vision Transformers . CVPR . en . 12104–12113.
  15. Ghorbani . Behrooz . Firat . Orhan . Freitag . Markus . Bapna . Ankur . Krikun . Maxim . Garcia . Xavier . Chelba . Ciprian . Cherry . Colin . 2021-09-01 . Scaling Laws for Neural Machine Translation . cs.LG . 2109.07740.
  16. Chen . Mia Xu . Firat . Orhan . Bapna . Ankur . Johnson . Melvin . Macherey . Wolfgang . Foster . George . Jones . Llion . Schuster . Mike . Shazeer . Noam . Parmar . Niki . Vaswani . Ashish . Uszkoreit . Jakob . Kaiser . Lukasz . Chen . Zhifeng . Wu . Yonghui . July 2018 . The Best of Both Worlds: Combining Recent Advances in Neural Machine Translation . Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) . Melbourne, Australia . Association for Computational Linguistics . 76–86 . 10.18653/v1/P18-1008. 1804.09849 .
  17. Book: Gordon . Mitchell A . Duh . Kevin . Kaplan . Jared . Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing . Data and Parameter Scaling Laws for Neural Machine Translation . 2021 . 5915–5922 . Stroudsburg, PA, USA . Association for Computational Linguistics . 10.18653/v1/2021.emnlp-main.478. free .
  18. Hernandez . Danny . Kaplan . Jared . Henighan . Tom . McCandlish . Sam . 2021-02-01 . Scaling Laws for Transfer . cs.LG . 2102.01293.