技术分享
LLM Scaling Laws Paper Excerpt - Scaling Laws for Neural Language Models
✋ Many people believe that the performance of large models is related to the model's structure, size, training compute, and dataset size. However, how exactly do these factors influence the final performance of a large model? Understanding this can help in better deciding where to invest resources to train the required models.
Background and Content
In 2020, OpenAI released the paper "Scaling Laws for Neural Language Models," exploring Scaling Laws. This paper discusses the relationship between the training loss of large models based on Transformers and the model parameter size (N), dataset size (D), and computational volume (C).
In April 2022, Google DeepMind revisited Scaling Laws in their article "Training Compute-Optimal Large Language Models." They pointed out that current large models are significantly under-trained. By using four times the data (compared to the 280B parameter Gopher) to train the 70B parameter Chinchilla, they achieved better results (SOTA average accuracy of 67.5% on the MMLU benchmark, a 7% increase).
However, in February 2023, a blog titled "Chinchilla’s Death" by Thaddée Tyl argued that with sufficient training time, small models can outperform large models.
Paper
Scaling Laws for Neural Language Models
Key Findings
- Model performance improves with the increase in model size (N), dataset size (D), and compute (C), and is weakly correlated with the model's shape (depth and width) and the number of self-attention heads.
- When other factors are not limited, there is a power-law relationship between model size (N), dataset size (D), compute (C), and performance.
- Expanding both model size (N) and dataset size (D) simultaneously can improve model performance. However, the study suggests that when the model size increases eightfold, the dataset size only needs to increase fivefold, and this will not incur a performance penalty.
- Because the training curve follows a power-law relationship, the loss is independent of model size, allowing us to roughly predict the loss for subsequent training.
- There is a penalty (greater error) when transferring to a dataset different from the training set, but this penalty is constant, meaning other improvements are consistent.
- Large models have higher sample efficiency compared to smaller models, requiring less training (Figure 2) and less data (Figure 4) to achieve the same level of performance.


- Convergence is inefficient. When the compute (C) is fixed, it is possible to stop training before the model fully converges to achieve optimal performance (Figure 3). The paper provides a reference relationship as follows:

- The ideal batch size for training should be proportional to the power of the training data size and can be further determined using the gradient noise scale.
Scaling Law Summary
Parameters:
non-embedding parameters
the dataset size
optimally allocated compute budget
When the other two factors are not limited, the test loss can be predicted using the following formula:
- N is limited
- D is limited(with early stopping)
- C is limited
Formula Meaning:
In the above formulas, indicate the power law exponents that describe the performance improvement when increasing .
For example, if we double the number of model parameters, the model loss will decrease by a factor of , meaning the loss will be 0.95 times the previous value. The exact numbers for are based on vocabulary size and tokenization, thus only representing an order of magnitude relationship rather than precise values.
Additionally, the paper discusses the relationship between batch size and loss.
Based on the previous formulas (1) and (2), when we increase the model size, we should correspondingly increase the dataset size. It can be calculated as:。
They also derived a combined formula from (1) and (2) to manage the dependencies of N and D and to control overfitting:
- The authors speculate that this function can also generate the maximum log-likelihood for other generative tasks.
The training curve can also be derived from the number of training steps, allowing us to determine the optimal number of training steps.
is the minimum possible number of optimization steps (parameter updates) estimated using Equation
In the case of fixed compute C, the following relationship formula is derived:
Here we have:
So we can get ,here drop out the ideas:
-
When the compute budget C is increased, it should primarily be used to create larger models rather than extending training time or increasing dataset size.
-
Additionally, as models become larger, they become more sample efficient.
Research Methodology
The study was conducted using the WebText2 dataset and its extension (2.29 × 10^10 tokens). The tokenization method employed was byte-pair encoding, with a vocabulary size of . The performance metric (Loss) was the cross-entropy loss over a context of 1024 tokens. The primary model used was a decoder-only Transformer, and LSTM along with other types of Transformers were also trained for comparison.
Unless otherwise specified, the model training utilized the Adam optimizer for steps with a batch size of 512 and a context of 512 tokens. Due to memory constraints, the largest models were trained using the Adafactor optimizer.
The learning rate schedule, unless otherwise noted, included a warm-up period of 3000 steps followed by cosine decay to zero.
Model Parameter Calculation Method
To calculate the model parameters and compute requirements, the model hyperparameters are defined as follows:
| 层数 number of layers | |
|---|---|
| 残差流的维度 dimension of the residual stream | |
| 前馈层(全连接)的维度 dimension of the intermediate feed-forward layer | |
| 注意力输出的维度 dimension of the attention output | |
| 每层注意力头数量 number of attention heads per layer | |
| 上下文词元数量,除另说明外为1024 input context |
to represent the size of the model parameters, excluding the embedding layers, the calculation for model parameters is as follows:
Here, the parameters for the embedding layers and are omitted.
The compute required for a forward pass, denoted as , is approximately:

Experimental Results
Experimental Variables:
- Model Size: Ranging from 768 non-embedding parameters to 1.5 billion parameters.
- Dataset Size: From 22 million to 23 billion tokens.
- Model Shape: Including variations in depth, width, attention heads, and feed-forward dimensions.
- Context Length: Typically 1024 tokens, but shorter contexts were also tested.
- Batch Size: Typically , but varied to measure the critical batch size.


Conclusion:
- When the non-embedding model size is fixed, the model shape has a minimal impact on performance, with large adjustments affecting performance by only a few percentage points.
- If the embedding parameters are included, model performance shows a significant correlation with the number of layers (left graph). However, if the embedding parameters are excluded, the performance of models with different numbers of layers follows the same trend, except for models with fewer than two layers (right graph).
- The same applies to LSTM models, although LSTM performance is slightly inferior to Transformers.
- The power law theorem formula holds:
参考
[1] https://arxiv.org/pdf/2001.08361.pdf
[2] https://arxiv.org/pdf/2203.15556.pdf
[3] https://espadrine.github.io/blog/posts/chinchilla-s-death.html
[4] https://arxiv.org/pdf/2109.10686.pdf
[5] https://self-supervised.cs.jhu.edu/sp2023/files/17.retrieval-augmentation.pdf