Study the paper
Scaling Laws for Neural Language Models
Lessons, visuals, quizzes, flashcards, and resources—organized in teaching order.
Transformer Parameter and Compute Scaling
Transformer Parameter Count Approximation
Transformer Parameter Count Approximation
Source equation
This equation estimates the total number of non-embedding parameters in a standard Transformer model. It assumes standard scaling relationships between the model dimension, attention dimension, and feed-forward dimension.
Sources
equation
=12nlayerdmodel2 with the standard dattn=dff/4=dmodelformulae-sequenceabsent12subscript𝑛layersuperscriptsubscript𝑑model2 with the standard subscript𝑑attnsubscript𝑑ff4subscript𝑑model\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}} (2.1)
\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}}Sources
equation
=12nlayerdmodel2 with the standard dattn=dff/4=dmodelformulae-sequenceabsent12subscript𝑛layersuperscriptsubscript𝑑model2 with the standard subscript𝑑attnsubscript𝑑ff4subscript𝑑model\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}} (2.1)
\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}}Deep dive
For each Transformer layer, the parameters are divided into two main blocks:
- Self-Attention Block: Contains projection matrices for Query, Key, Value, and Output. Each has shape , contributing parameters.
- Feed-Forward Network (FFN): Consists of two linear layers. The first projects from to , and the second projects back to . This contributes parameters.
Summing these gives parameters per layer. Multiplying by the number of layers yields the total non-embedding parameter count.
Sources
equation
=12nlayerdmodel2 with the standard dattn=dff/4=dmodelformulae-sequenceabsent12subscript𝑛layersuperscriptsubscript𝑑model2 with the standard subscript𝑑attnsubscript𝑑ff4subscript𝑑model\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}} (2.1)
\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}}Implementation detail
Illustrative Calculation
Let's calculate the parameter count for a model with:
Using the formula:
Sources
equation
=12nlayerdmodel2 with the standard dattn=dff/4=dmodelformulae-sequenceabsent12subscript𝑛layersuperscriptsubscript𝑑model2 with the standard subscript𝑑attnsubscript𝑑ff4subscript𝑑model\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}} (2.1)
\displaystyle=12n_{\rm layer}d_{{\rm model}}^{2}\quad\text{ with the standard }\quad d_{\rm attn}=d_{\rm ff}/4=d_{{\rm model}}- Number of layers in the Transformer model · scalar
- Hidden dimension size of the model · scalar
- Attention dimension size · scalar
- Feed-forward network intermediate dimension size · scalar
- Total non-embedding parameter count · scalar