[Paper review] Scaling Laws for Neural Language Models

Jumyung Song·4일 전

Paper review

목록 보기
6/6
post-thumbnail

Summary

  • The test loss of a language model follows a power law with respect to each of model size NN, dataset size DD, and training compute CC, when the other two are not the bottleneck. In contrast, architecture shape such as depth, width, and the number of heads has almost no effect on loss as long as the non-embedding parameter count NN is the same.
  • When NN and DD are scaled together, the degree of overfitting is determined by a single ratio, N0.74/DN^{0.74}/D. In other words, if the model is made 8 times larger, the data only needs to be increased by about 5 times.
  • Under a fixed compute budget, the optimal strategy is to make the model much larger (N∝C0.73N \propto C^{0.73}) and stop training well before convergence.

1. Introduction

The performance of language modeling depends on the model architecture, the number of parameters, the amount of compute, the amount of available data, and so on. This paper targets Transformer language modeling and experimentally measures which of these factors are the main ones that actually determine performance. According to the results of several experiments conducted under varying conditions, performance scales as a power law with respect to training time, context length, dataset size, model size, and compute budget.

Since the paper compares results across many conditions, it defines and uses several notations.

LL: Cross-entropy loss
NN: Number of model parameters
DD: Dataset size
CC: Total non-embedding training compute
CminC_{min}: Estimate of minimum amount of non-embedding compute to reach a given loss

2. Background & Methods

2.1. Parameter and Compute Scaling of Transformers

The hyperparameters of the Transformer architecture are set as follows.

  • nlayern_{layer}: number of layers
  • dmodeld_{model}: dimension of the residual stream
  • dffd_{ff}: intermediate dimension of the feed-forward layer
  • dattnd_{attn}: dimension of the attention output
  • nheadn_{head}: number of attention heads per layer

① Model size NN

A single layer consists of the following parameters.

  • Q, K, V projections and output projection of attention: 4×dmodel×dattn4 \times d_{model} \times d_{attn}
  • Two linear layers of the FFN: 2×dmodel×dff2 \times d_{model} \times d_{ff}

Therefore, the total number of parameters excluding embeddings and biases is

N≈2 dmodel nlayer(2dattn+dff)=12 nlayer dmodel2(dattn=dmodel=dff/4)N \approx 2\, d_{model}\, n_{layer} \left(2 d_{attn} + d_{ff}\right) = 12\, n_{layer}\, d_{model}^2 \qquad (d_{attn} = d_{model} = d_{ff}/4)

② Compute

The amount of computation (FLOPs) for the forward pass of a single token is

Cforward≈2N+2 nlayer nctx dattnC_{forward} \approx 2N + 2\, n_{layer}\, n_{ctx}\, d_{attn}

Here, the second term is a context-length-dependent term arising from the attention score computation, and when dmodel≫nctx/12d_{model} \gg n_{ctx}/12 it becomes much smaller than NN, so it can be ignored. In addition, since the compute of the backward pass is about twice that of the forward pass, the total training compute per token can be approximated as follows.

C≈6NC \approx 6N

3. Empirical Results and Basic Power Laws

3.1. Transformer Shape and Hyperparameter Independence

To check the effect of the Transformer's shape on performance, the loss was measured while fixing the non-embedding parameter count NN and changing one of nlayern_{layer}, nheadn_{head}, and dffd_{ff} at a time. The resulting loss is as follows.

  • Even when the feed-forward ratio, aspect ratio (dmodel/nlayerd_{model}/n_{layer}), and head dimension are varied over a wide range, the change in loss stays within a few percent, and even architectures whose aspect ratios differ by a factor of 40 achieve similar performance.
  • In other words, once NN is fixed, the performance of the Transformer does not depend much on its shape.

3.2. Performance with Non-Embedding Parameter Count NN

The value used to represent the size of a model is the number of parameters in the model. Here, parameters can be viewed from two main perspectives, depending on whether only the parameters trained for the actual objective function are counted, or whether embedding parameters are also included. Therefore, to express the relationship between parameter count and model performance more accurately, it must be decided which of the two values to use as the parameter count, and the following experiment was conducted as the verification process.

  • Left: When embedding parameters are included in the count, the loss appears to depend not only on the number of parameters but also on nlayern_{layer}.
  • Right: When embedding parameters are excluded from the count, models with different depths converge onto a single line (power law). Only models with just one layer or with extreme depth/width ratios were exceptions.

The reason it looks like the left plot is that the smaller the model, the larger the share of embedding in the total parameters. The parameter count looks large, but the part actually used for computation is small, so the loss comes out poor. For this reason, the paper uses the non-embedding parameter count as NN in all subsequent analyses.

With this definition, the loss can be written as a function of NN.

L(N)≈(NcN)αN,αN≈0.076,Nc≈8.8×1013L(N) \approx \left(\frac{N_c}{N}\right)^{\alpha_N}, \qquad \alpha_N \approx 0.076,\quad N_c \approx 8.8 \times 10^{13}

3.3. Performance with Dataset Size and Compute

Dataset size DD
To make the amount of data the bottleneck of the model, a large model (nlayer=36n_{layer}=36, dmodel=1280d_{model}=1280) is trained on subsets of WebText2, and the lowest loss reachable with a given amount of data is measured. To compare the lowest losses, training is stopped once the test loss no longer decreases. The resulting relationship between loss and dataset size is as follows.

L(D)≈(DcD)αD,αD≈0.095,Dc≈5.4×1013L(D) \approx \left(\frac{D_c}{D}\right)^{\alpha_D}, \qquad \alpha_D \approx 0.095,\quad D_c \approx 5.4 \times 10^{13}

Compute CC

The training compute is C=6NBSC = 6NBS. With CC fixed, NN is varied to find the model that achieves the lowest loss within that compute. Connecting these optimal points gives the following relationship.

L(C)≈(CcC)αCL(C) \approx \left(\frac{C_c}{C}\right)^{\alpha_C}

The values written as XcX_c in each equation are obtained through fitting to express the relationship on a log-log graph. The relationships of loss with respect to parameters, dataset, and compute are summarized as follows.

All three graphs are linear on log-log axes. The light blue curves in the left graph are the learning curves of models of different sizes, and their lower envelope (black line) forms the power law with respect to compute, L=(Cmin⁡/2.3⋅108)−0.050L = (C_{\min}/2.3 \cdot 10^8)^{-0.050}. However, this power law holds only when the other two factors are not the bottleneck.

4. Charting the Infinite Data Limit and Overfitting

Up to this point, only one variable was made the bottleneck at a time in order to check the independent effect of each variable. This section deals with how the loss behaves when the two values NN and DD are changed simultaneously, and in particular with the overfitting that occurs when data is insufficient.

4.1. Proposed L(N,D)L(N, D) Equation

L(N,D)=[(NcN)αNαD+DcD]αDL(N, D) = \left[\left(\frac{N_c}{N}\right)^{\frac{\alpha_N}{\alpha_D}} + \frac{D_c}{D}\right]^{\alpha_D}

This loss as a function of NN and DD was chosen to satisfy the following principles.

  1. Rescaling: If the vocabulary size or tokenization changes, the overall loss is expected to change by a constant factor, so the equation should naturally allow for such rescaling.

  2. A limit imposed by the other variable even when one variable grows infinitely: If DD is fixed and N→∞N \to \infty, the loss should converge to L(D)L(D), and if NN is fixed and D→∞D \to \infty, it should converge to L(N)L(N).

  3. L(N,D)L(N, D) is analytic at D=∞D = \infty: It should be expandable as a series in integer powers of 1/D1/D.

4.2. Results

Training was performed while varying NN and DD, stopped once the test loss no longer decreased, and then the parameters of the above equation were fitted.

ParameterαN\alpha_NαD\alpha_DNcN_cDcD_c
Value0.0760.1036.4×10136.4 \times 10^{13}1.8×10131.8 \times 10^{13}

Overfitting
How much is lost compared to the loss with infinite data, L(N,∞)L(N, \infty), is defined as δL\delta L.

δL≡L(N,D)L(N,∞)−1≈(1+(NNc)αNαDDcD)αD−1\delta L \equiv \frac{L(N, D)}{L(N, \infty)} - 1 \approx \left(1 + \left(\frac{N}{N_c}\right)^{\frac{\alpha_N}{\alpha_D}} \frac{D_c}{D}\right)^{\alpha_D} - 1
  • The larger δL\delta L is, the more severe the overfitting.
  • From the equation, δL\delta L depends only on NαN/αD/D≈N0.74/DN^{\alpha_N/\alpha_D}/D \approx N^{0.74}/D.
  • Since the variation in loss due to the random seed is about 0.02, there is considered to be no overfitting when δL<0.02\delta L < 0.02. The condition that satisfies this is
D≳(5×103) N0.74D \gtrsim (5 \times 10^3)\, N^{0.74}

In other words, when increasing model size, overfitting can be avoided by increasing data only sub-linearly. In this way, not only can the loss equation be fitted with data DD and parameters NN, but the relationship between NN and DD needed to prevent overfitting can also be identified.

5. Scaling Laws with Model Size and Training Time

Now, the number of training steps SS is also taken into account, and the loss as a function of NN and training time is combined into a single equation. Before that, the critical batch size is introduced to correct for the step count and compute that vary with batch size.

5.1 Critical Batch Size Bcrit(L)B_{crit}(L)

Training time (number of steps) and compute vary with batch size BB.

  • B≪BcritB \ll B_{crit}: Increasing the batch reduces the number of steps almost proportionally. Compute efficiency is good.
  • B≫BcritB \gg B_{crit}: Increasing the batch further barely reduces the number of steps. The number of steps is close to the minimum, but compute is wasted.

The number of steps SS needed to reach a target loss and the amount of data processed E=BSE = BS have the following relationship. Here, EE is the number of tokens actually processed, which differs from the dataset size DD.

(SSmin⁡−1)(EEmin⁡−1)=1\left(\frac{S}{S_{\min}} - 1\right)\left(\frac{E}{E_{\min}} - 1\right) = 1
  • Smin⁡S_{\min}: minimum number of steps needed to reach the target loss (when B→∞B \to \infty)
  • Emin⁡E_{\min}: minimum amount of data needed to reach the target loss (when B→0B \to 0)

The critical batch size is defined as the ratio of the two.

Bcrit(L)≡Emin⁡Smin⁡B_{crit}(L) \equiv \frac{E_{\min}}{S_{\min}}
  • Since Emin⁡E_{\min} and Smin⁡S_{\min} are determined by the target loss, BcritB_{crit} is also a function of the loss.
  • Training with B=BcritB = B_{crit} gives S=2Smin⁡S = 2S_{\min} and E=2Emin⁡E = 2E_{\min}, which is the balance point between time and compute.

Empirically, BcritB_{crit} depends only on the loss, independent of model size, and follows the power law below.

Bcrit(L)≈B∗L1/αB,B∗≈2×108 tokens,αB≈0.21B_{crit}(L) \approx \frac{B_*}{L^{1/\alpha_B}}, \qquad B_* \approx 2 \times 10^8 \text{ tokens},\quad \alpha_B \approx 0.21

The critical batch size measured as a function of loss is shown below.

Every time the loss decreases by 13%, BcritB_{crit} roughly doubles. Using this, the results (SS, CC) of training with an arbitrary batch size BB can be converted into the minimum number of steps when B≫BcritB \gg B_{crit} and the minimum compute when B≪BcritB \ll B_{crit}.

Smin⁡(S)=S1+Bcrit(L)/B,Cmin⁡(C)=C1+B/Bcrit(L)S_{\min}(S) = \frac{S}{1 + B_{crit}(L)/B}, \qquad C_{\min}(C) = \frac{C}{1 + B/B_{crit}(L)}

5.2. Performance with Model size and Compute

Using Smin⁡S_{\min}, the loss can be written as a function of NN and training steps.

L(N,Smin⁡)=(NcN)αN+(ScSmin⁡)αS,αS≈0.76,Sc≈2.1×103L(N, S_{\min}) = \left(\frac{N_c}{N}\right)^{\alpha_N} + \left(\frac{S_c}{S_{\min}}\right)^{\alpha_S}, \qquad \alpha_S \approx 0.76,\quad S_c \approx 2.1 \times 10^3

The first term is the limit set by model size when trained infinitely, and the second term is the loss caused by insufficient training.

  • Left: When compute is fixed, there exists an optimal model size that minimizes the loss. A model that is too small lacks capacity, and a model that is too large cannot be trained sufficiently with the same compute.
  • Right: When the number of steps is fixed, the larger the model, the lower the loss.
  • The dotted lines are the L(N,S)L(N, S) equation, which fits the experimental values well except early in training (small SS).

5.3. Lower bound on Early Stopping Step

The learning curves for finite and infinite data are nearly identical up to around Smin⁡≈SstopS_{\min} \approx S_{stop}. Therefore, the lower bound on the number of steps at which training must be stopped due to overfitting can be estimated as follows.

Sstop(N,D)≳Sc[L(N,D)−L(N,∞)]1/αSS_{stop}(N, D) \gtrsim \frac{S_c}{\left[L(N, D) - L(N, \infty)\right]^{1/\alpha_S}}

The smaller the loss gap caused by insufficient data, L(N,D)−L(N,∞)L(N,D) - L(N,\infty), the longer training can continue before overfitting begins.


6. Optimal Allocation of the Compute Budget

6.1. Optimal Performance and Allocations

Using Cmin⁡C_{\min} corrected with BcritB_{crit}, the loss can be rewritten as a function of Cmin⁡C_{\min}, L(Cmin⁡)L(C_{\min}). Then, finding the optimal model size N(Cmin⁡)N(C_{\min}) that minimizes the loss for a given compute gives

N(Cmin⁡)∝Cmin⁡0.73N(C_{\min}) \propto C_{\min}^{0.73}

Since Cmin⁡=6NBcritSC_{\min} = 6NB_{crit}S and Bcrit∝Cmin⁡0.24B_{crit} \propto C_{\min}^{0.24}, the remaining number of steps is

Smin⁡∝Cmin⁡0.03S_{\min} \propto C_{\min}^{0.03}

In other words, the conclusion is as follows.

When scaling up a language model with an optimal allocation of compute, one should mainly increase the model size NN, increase the batch size along with BcritB_{crit}, and barely increase the number of steps.

6.2 Predictions from L(N,Smin⁡)L(N, S_{\min})

By combining the L(N,Smin⁡)L(N, S_{\min}) equation from Section 5.2 with the Bcrit(L)B_{crit}(L) equation, the exponent of L(Cmin⁡)L(C_{\min}) can be predicted theoretically.

L(Cmin⁡)=(Ccmin⁡Cmin⁡)αCmin⁡,αCmin⁡=11/αS+1/αB+1/αN≈0.054L(C_{\min}) = \left(\frac{C_c^{\min}}{C_{\min}}\right)^{\alpha_C^{\min}}, \qquad \alpha_C^{\min} = \frac{1}{1/\alpha_S + 1/\alpha_B + 1/\alpha_N} \approx 0.054

This agrees well with the directly measured value of 0.050. This is evidence that the three independent power laws are consistent with one another.

6.3 Contradictions and a Conjecture

Continuing to apply these scaling laws leads to a contradiction.

  • To avoid overfitting, data must grow as D∝N0.74∝Cmin⁡0.54D \propto N^{0.74} \propto C_{\min}^{0.54}.
  • However, the data actually seen when training compute-efficiently is
D(Cmin⁡)=2Cmin⁡6N(Cmin⁡)∝Cmin⁡0.26D(C_{\min}) = \frac{2C_{\min}}{6N(C_{\min})} \propto C_{\min}^{0.26}

which grows much more slowly than the required rate. Therefore, even without reusing data, training will eventually enter the overfitting regime.

  • L(Cmin⁡)L(C_{\min}) (orange dotted line) decreases quickly as compute increases. To the left of the intersection, compute is the bottleneck, so increasing compute reduces the loss.
  • L(D(C))L(D(C)) (red line) is the lower bound on the loss achievable with the amount of data seen at that compute. This line decreases more slowly.
  • To the right of the intersection, L(Cmin⁡)L(C_{\min}) falls below L(D(C))L(D(C)), which would mean the loss drops below the limit possible with that data even though data is insufficient, which is impossible. Therefore, the scaling laws must break down before the intersection.

The intersection is at roughly C∗∼104C^* \sim 10^4 PF-days, N∗∼1012N^* \sim 10^{12} parameters, D∗∼1012D^* \sim 10^{12} tokens, and L∗∼1.7L^* \sim 1.7 nats/token. The paper conjectures that the loss at this point, L∗L^*, may be an estimate of the per-token entropy of natural language. However, since the location of the intersection is highly sensitive to the power-law exponents, it cannot be taken as an exact value.

7. Discussion

  • The loss of a language model follows consistent power laws in NN (model size), DD (data), and Cmin⁡C_{\min} (compute), and depends very little on architecture or hyperparameters.
  • Large models are far more sample-efficient than previously thought. They need fewer steps and less data to reach the same loss. Therefore, given a fixed compute budget, it is more efficient to train a large model and stop before convergence than to train a small model until convergence.

8. My Take

1. What the loss at the intersection means
The loss L∗L^* at the intersection where the two power laws meet in the compute-data tradeoff corresponds, if the paper's conjecture is right, to the per-token entropy of natural language. If so, no matter how much model size or compute is increased, the loss cannot be pushed below this value. However, as the paper itself notes, this is a conjecture, and the location of the intersection is highly sensitive to the exponent values.

2. What if DD were defined as information content rather than token count?
Following this interpretation, I think what ultimately matters is the amount of information each token carries when the data is encoded. This paper simply defines dataset size DD as the number of tokens and expresses LL as a function of DD. If information content were defined as something like the total dimension of the encoded data and used in place of DD, I wonder whether a more accurate relationship could be obtained than when using the token count.

3. Which to scale: the model or the data
The LLaMA paper (based on the results of Chinchilla (Hoffmann et al., 2022)) holds that, for the same cost, training on more new data yields better performance than only increasing model size. In contrast, comparing the exponents in this paper, as compute increases, the optimal model size grows as N∝C0.73N \propto C^{0.73} while data grows only as D∝C0.26D \propto C^{0.26}, so the model grows much more than the data. It is interesting that the two papers reach nearly opposite conclusions on the same question.

References

  • Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R., Gray, S., Radford, A., Wu, J., & Amodei, D. (2020). Scaling Laws for Neural Language Models. arXiv:2001.08361
  • McCandlish, S., Kaplan, J., Amodei, D., & OpenAI Dota Team (2018). An Empirical Model of Large-Batch Training. arXiv:1812.06162
  • Hoffmann, J. et al. (2022). Training Compute-Optimal Large Language Models. arXiv:2203.15556
  • Touvron, H. et al. (2023). LLaMA: Open and Efficient Foundation Language Models. arXiv:2302.13971

This post was translated from the original Korean version with the help of AI, so some errors may remain.

0개의 댓글