How do you estimate the number of parameters in a single Transformer layer given hidden size d and an FFN dimension of 4d?

Last updated 22 November 2026

  • Attention has four d×d projections (4d², independent of head count) and the FFN has two d×4d matrices (8d²), giving about 12d² per layer. Biases and norms add only O(d).

  • Example: d = 4096 gives about 201M per layer, so 32 layers is about 6.4B plus V·d embeddings.

  • Variants: SwiGLU uses hidden size about 8d/3 to keep the FFN near 8d², and GQA shrinks W_K/W_V below 4d² total for attention.

  • https://d2l.smola.org/slides/jax/chapter_transformers/scaling-laws.html
  • https://computervisiononline.com/explains/transformer/
  • https://www.glennklockwood.com/garden/hidden-dimension
All Transformers interview questions