
Since the publication of the now famous 2017 paper Attention is All You Need1, many large language models based on the transformer architecture have emerged. Fortunately, some studies 2 3 have compiled extensive data on many published models, including the dimensions of their transformers.
Much like my experience learning about CNNs and their increasing complexity, I wanted to analyze LLM transformers. Which models are the largest? What is the optimal size for the feed-forward layer? Is it better to add more embeddings or more attention heads? Can we easily derive the total number of parameters from the network dimensions?
Transformer model parameters#
I will use the notations from the original Attention is All You Need 1 paper.
- : the number of layers
- : the number of attention heads
- : the size of the embeddings
- : the size of the hidden FFN layer
- : the vocabulary size, that is the number of tokens used

In order to count model parameters, we need break the model down into building blocks:
- Multi-head attention block : trainable parameters are contained in weight matrices , for , as well as and their associated biaises. We then multiply the added number of parameters by , the number of heads. Using the relationship 1 we get
- Feed-forward block : in both the encoder and the decoder, the output of size is passed throught a feed-forward block 1 : . This leads to the following number of parameters
- Layer normalization block : gain and bias with dimension
- Encoder : the encoder has one MHA and one FFN. Each one has a norm layer.
- Decoder : the decoder has two MHA and one FFN. Each one has a norm layer.
- Linear block : the linear block outputs as many logits as the vocabulary size, hence the dimension of its matrix and bias is
Finally the total number of parameters is
Gathering data#
Although the aforementioned studies 2 3 are invaluable and packed with useful information, they've become quickly outdated given the pace of model releases these days. I decided to collect my own data from original research papers, announcement posts, as well as some Hugging Face configuration files. I focused on models published by large research teams and/or that had significant impact.
Here are my findings:
- GPT 4 used a causal decoder-only transformer, which many models have adopted. This means the encoder block is not present in most models
- GPT used
- According to 2, sometimes biases are omitted in the model
- Sometimes, some parameters are omitted in the paper and implied from previous version of the model
- Closed-source models rarely disclose detailed architecture information
- Hugging Face configuration files generally display one version (size) from a family of models, potentially leading to misleading interpretations
Publishing a dashboard#
Once the data started to look interesting, I put together a small Next.js app using shadcn/ui data tables. A dashboard is available at https://transformers-dashboard.vercel.app.
Footnotes#
-
Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I. (2017). Attention is all you need. Advances in neural information processing systems, 30. ↩ ↩2 ↩3 ↩4
-
Naveed, H., Khan, A. U., Qiu, S., Saqib, M., Anwar, S., Usman, M., ... & Mian, A. (2023). A comprehensive overview of large language models. arXiv preprint arXiv:2307.06435. ↩ ↩2 ↩3
-
Zhao, W. X., Zhou, K., Li, J., Tang, T., Wang, X., Hou, Y., ... & Wen, J. R. (2023). A survey of large language models. arXiv preprint arXiv:2303.18223. ↩ ↩2
-
Radford, A., & Narasimhan, K. (2018). Improving Language Understanding by Generative Pre-Training. ↩