← Back to blog

Transformers dashboard

May 4, 2024

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.

In order to count model parameters, we need break the model down into building blocks:

PMHA=h(2dmodeldk+2dk+dmodeldv+dv)+hdvdmodel+dmodel=4(dmodel2+dmodel)\begin{aligned} P_{\textrm{MHA}} &= h (2d_{\textrm{model}}d_k + 2d_k + d_{\textrm{model}}d_v + d_v) + hd_vd_{\textrm{model}} + d_{\textrm{model}} \\\\ &= 4 (d_{\textrm{model}}^2 + d_{\textrm{model}}) \end{aligned} PFFN=2(dffdmodel+dmodel)P_{\textrm{FFN}} = 2 (d_{\textrm{ff}} d_{\textrm{model}} + d_{\textrm{model}}) PLN=2dmodelP_{\textrm{LN}} = 2 d_{\textrm{model}} Pencoder=N(PMHA+PFFN+2PLN)P_{\textrm{encoder}} = N (P_{\textrm{MHA}} + P_{\textrm{FFN}} + 2P_{\textrm{LN}} ) Pdecoder=N(2PMHA+PFFN+3PLN)P_{\textrm{decoder}} = N (2P_{\textrm{MHA}} + P_{\textrm{FFN}} + 3 P_{\textrm{LN}}) Plinear=dmodelV+VP_{\textrm{linear}} = d_{\textrm{model}} V + V

Finally the total number of parameters is

P=Pencoder+Pdecoder+PlinearP = P_{\textrm{encoder}} + P_{\textrm{decoder}} + P_{\textrm{linear}}

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:

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#

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

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

  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

  4. Radford, A., & Narasimhan, K. (2018). Improving Language Understanding by Generative Pre-Training.