Skip to content
induwara.lk
induwara.lkAI · Machine Learning

Transformer Parameter Count Calculator

Work out the exact parameter count of a GPT-style transformer from its architecture, vocab, hidden size, layers, feed-forward width, and head config, and see it split into embedding, attention, feed-forward, and norm shares. GPT-2's 124M and GPT-3's 175B both verified. No signup, formulas cited.

By Induwara AshinsanaUpdated Oct 2, 2026
Transformer parameter count
Decoder-only · dense
Presets

Number of distinct tokens in the tokenizer.

Model width. Heads must divide this.

Stacked transformer blocks.

Inner width of the feed-forward layer.

Must divide the hidden size evenly.

Equal to heads = standard MHA; fewer = grouped-query.

Only adds parameters with learned positions.

Bias in linear layers
Tied embeddings
Total parameters
124.4 M
124,439,808
Non-embedding
85.1 M
68.35% of total
Embedding params
39.4 M
31.65% of total
12·L·h² estimate
84.9 M
+0.14% vs exact
Embeddings 31.65%Attention 22.78%Feed-forward 45.54%Norms 0.03%

Parameter breakdown

ComponentParametersShare
Token embedding38,597,37631.02%
Positional embedding786,4320.63%
Output unembedding00%
Attention (all layers)28,348,41622.78%
Feed-forward (all layers)56,669,18445.54%
Norms (all layers + final)38,4000.03%
Total124,439,808100%

Per layer: attention 2,362,368, feed-forward 4,722,432, norms 3,072 = 7,087,872 parameters, repeated 12×.

Formulas follow . Dense decoder-only models; 2-matrix FFN.

Have a parameter count already? Feed it into the LLM VRAM Calculator to size a GPU, or the AI Training Compute Calculator to estimate training cost.

How it works

The calculator follows the closed-form parameter breakdown in EleutherAI's Transformer Math 101 and the original architecture papers. Write h for hidden size (d_model), L for the number of layers, V for vocabulary size, n_ctx for the maximum context length, and d_ff for the feed-forward inner size. Every parameter in a decoder-only transformer falls into one of three groups, embeddings, the repeated layer stack, and a single final norm, and the total is just their sum. Nothing is estimated: each term below is an exact integer.

Embeddings. The token embedding matrix holds V · h weights. Learned absolute positions add n_ctx · h; rotary (RoPE) and ALiBi positions are computed from head geometry rather than learned, so they add nothing, which is why modern long-context models can stretch their window without growing. (If you are extending a RoPE window, the RoPE context extension calculator covers the frequency-scaling side.) The output unembedding adds another V · h unless it is tied to the input embedding, in which case it costs nothing. Tying is the single biggest lever on small models: it is 31% of GPT-2 small.

Attention, per layer. Attention has four projections. With standard multi-head attention the query, key, value, and output matrices are each h×h, giving 4 · h² weights. Under grouped-query attention several query heads share one key/value head, so K and V shrink to h · (n_kv · head_dim), where head_dim = h / n_heads. Llama 3 8B pairs 32 query heads with 8 KV heads: its attention block is 41.9M parameters instead of the 67.1M that full MHA would cost, a 37% saving on the attention term and a 4× cut to KV cache memory at inference time. Head count must divide the hidden size evenly, and KV heads must divide the head count, the tool rejects configurations that do not.

Feed-forward, per layer. The classic block is two linear layers, so 2 · h · d_ff weights, with d_ff = 4 · h in the original paper and across the GPT-2 and GPT-3 family. That term alone is two thirds of a large GPT-style model. Gated MLPs, SwiGLU in Llama, Mistral, and Gemma, use three matrices (gate, up, down) of width d_ff, so they cost 1.5× the two-matrix figure. The tool models them by taking an effective d_ff of 1.5× the reported intermediate size: Llama 3's 14,336 becomes 21,504, which reproduces the published 8.03B exactly.

Norms and biases. Each layer carries two normalization layers. LayerNorm has a weight and a bias vector, so 4h per layer; RMSNorm drops the bias and the mean subtraction, so 2h. One final norm sits after the stack (2h or h). Bias vectors on the linear layers add 2h + 2·(n_kv · head_dim) for attention and d_ff + h for the feed-forward, per layer. These terms are linear in h while the matrices are quadratic, so they are negligible at scale, 49,152 of GPT-3's 1.81 billion per-layer parameters, about 0.003%, but they are exactly what makes a hand count miss the real number by a few thousand on a small model.

Totals and the scaling rule. The grand total is embeddings plus L times the per-layer count plus the final norm. For comparison, the calculator also prints the Kaplan et al. (2020) non-embedding approximation N ≈ 12 · L · h², which follows from assuming d_ff = 4h and multi-head attention: 4h² for attention plus 8h² for the feed-forward gives 12h² per layer. It holds to 0.14% on GPT-2 small and 0.01% on GPT-3. It reads 7.7% low on Llama 3 8B, and the reason is worth knowing: grouped-query attention makes that layer cheaper than 4h² (2.5h² here), but the SwiGLU MLP costs 10.5h² instead of 8h², so the two deviations do not cancel, the layer lands at 13h² and the rule undershoots. Change only the attention and it overshoots instead. The tool reports the signed deviation so you can see where your own configuration sits. Use the exact figure for memory planning and the approximation only for order-of-magnitude scaling arguments, such as the token budget in the Chinchilla compute-optimal calculator.

Where the parameters actually go: width, depth, and vocabulary

Three knobs decide almost everything, and they do not pull with equal force. Write r = d_ff / h for the feed-forward ratio and one layer's weights collapse to (4 + 2r) · h² under full multi-head attention, hidden size enters squared, layer count only linearly. Doubling h quadruples the stack; doubling L merely doubles it. GPT-2 Small to Medium is the clean demonstration: h rises 768 → 1,024 (1.33×) and L 12 → 24 (2×), and the layer stack grows from 85.1M to 302.3M, a factor of 3.55, which is 1.33² × 2 to three significant figures. Width is the expensive knob, which is why depth-vs-width tables in architecture papers look so lopsided.

Head count is free; KV head count is not. The head count has to divide h evenly, giving head_dim = h / n_heads, 64 in GPT-2 Small (768/12) and 128 across the Llama 3 family (4,096/32 and 8,192/64). Under full MHA that choice costs nothing: Q, K, V, and O stay h×h however many heads you slice them into, so re-splitting 32 heads into 64 leaves the parameter count untouched and only changes what each head attends to. The count moves the moment you cut KV heads. Llama 3 70B pairs 64 query heads with 8 KV heads, which takes attention from the 268.4M that 4h² would cost down to 151.0M per layer, a 43.8% cut on the attention term, compounded 80 times.

The vocabulary crossover. Embeddings are V · h, linear in width, so their share of the model collapses as the quadratic layer terms take over: 31.6% of GPT-2 Small, 14.8% of Medium, 8.5% of Large, 5.3% of XL, and 0.4% of GPT-3 175B. The trend is not monotonic across families, though, Llama 3 8B climbs back to 13.1%, because a 128,256-token vocabulary is 2.6× GPT-2's and the model unties its output head, so it carries two V · h matrices worth 1.05B parameters on a model only 8B in total. At that scale the tokenizer is an architecture decision, not a preprocessing detail; the tokenizer visualizer shows what a larger vocabulary buys you in tokens per word to set against that cost.

The feed-forward ratio, and why SwiGLU breaks the arithmetic. r = 4 runs from the 2017 paper through GPT-3, so the MLP is 8h² and two thirds of each layer. Gated models report a smaller intermediate size spread over three matrices: Llama 3 8B's 14,336 is 3.5h, but gate, up, and down together cost what a two-matrix block of 1.5 × 14,336 = 21,504 would, an effective r = 5.25, so the MLP is 10.5h², not 8h². Enter the reported number directly and you will undercount an 8B model by 1,879,048,192 parameters. That one substitution is the single most common reason a hand-rolled spreadsheet disagrees with a model card. Parameter-efficient fine-tuning changes the arithmetic again, since only a low-rank slice of these matrices is trainable, the LoRA calculator sizes that slice, and the training memory calculator turns either figure into optimizer and gradient footprint.

What the number excludes. A parameter count is weights only. It does not include optimizer state (Adam carries two moments, so training memory is several times the weights), gradients, activations, or the KV cache, and it is not the file size on disk until you multiply by bytes per parameter, 2 for FP16, 1 for INT8, about 0.5 for 4-bit quantization. The model size calculator does that conversion. Mixture-of-Experts models also break the single-number assumption, because total and active parameters differ by an order of magnitude; the MoE calculator handles that split. Everything on this page assumes a dense decoder-only stack.

Worked examples

Four configurations, each computed term by term. The first two are the canonical reference points, the third shows what grouped-query attention changes, and the fourth is the edge case where the familiar rule of thumb stops working.

GPT-2 Small, 124,439,808 parameters

V=50,257 · h=768 · L=12 · d_ff=3,072 · MHA · learned pos · tied

  1. Token embedding: 50,257 × 768 = 38,597,376
  2. Positional (learned): 1,024 × 768 = 786,432
  3. Output: 0 (tied to input embedding)
  4. Per layer, attention 4 × 768² + biases = 2,362,368
  5. Per layer, feed-forward 2 × 768 × 3,072 + biases = 4,722,432
  6. Per layer, 2 LayerNorms = 4 × 768 = 3,072 → layer total 7,087,872
  7. Stack: 7,087,872 × 12 = 85,054,464; final norm = 1,536
  8. Total: 38,597,376 + 786,432 + 85,054,464 + 1,536 = 124,439,808
  9. Split: embeddings 31.6% · attention 22.8% · feed-forward 45.5%

GPT-3 175B, 174.6B parameters

V=50,257 · h=12,288 · L=96 · d_ff=49,152 · MHA · learned pos · tied

  1. Embeddings: 50,257 × 12,288 + 2,048 × 12,288 = 642,723,840
  2. Per layer, attention 4 × 12,288² + biases = 604,028,928
  3. Per layer, feed-forward 2 × 12,288 × 49,152 + biases = 1,208,020,992
  4. Per layer, 2 LayerNorms = 49,152 → layer total 1,812,099,072
  5. Stack: 1,812,099,072 × 96 = 173,961,510,912; final norm = 24,576
  6. Total: 174,604,259,328 ≈ 174.6B (rounds to the reported 175B)
  7. 12·L·h² check: 12 × 96 × 12,288² = 173,946,175,488 → 0.01% under exact
  8. Embeddings are now just 0.4% of the model, the inverse of GPT-2 small

Llama 3 8B (GQA), 8,030,261,248 parameters

V=128,256 · h=4,096 · L=32 · 8 KV heads · RoPE · RMSNorm · no bias · untied

  1. head_dim = 4,096 / 32 = 128; KV width = 8 × 128 = 1,024
  2. Attention 2 × 4,096² + 2 × 4,096 × 1,024 = 41,943,040 (GQA shrinks K, V)
  3. Full MHA would have been 4 × 4,096² = 67,108,864, GQA saves 37% here
  4. Feed-forward (SwiGLU as 2-matrix, d_ff=21,504) = 2 × 4,096 × 21,504 = 176,160,768
  5. RMSNorms: 2 × 4,096 = 8,192 → layer total 218,112,000
  6. Stack: 218,112,000 × 32 = 6,979,584,000
  7. Embeddings (untied): 2 × 128,256 × 4,096 = 1,050,673,152; final norm 4,096
  8. Total: 8,030,261,248 ≈ 8.03B (matches the published count)
  9. 12·L·h² predicts 6,442,450,944 non-embedding vs 6,979,588,096 actual → 7.7% low

Edge case: small model where the rule of thumb breaks, 12,913,920 parameters

V=32,000 · h=256 · L=6 · d_ff=1,024 · MHA · RoPE · RMSNorm · no bias · tied

  1. Token embedding: 32,000 × 256 = 8,192,000
  2. Positional: 0 (RoPE is computed, not learned)
  3. Output: 0 (tied), untying would push the total to 21,105,920
  4. Per layer, attention 4 × 256² = 262,144
  5. Per layer, feed-forward 2 × 256 × 1,024 = 524,288
  6. Per layer, 2 RMSNorms = 2 × 256 = 512 → layer total 786,944
  7. Stack: 786,944 × 6 = 4,721,664; final norm = 256
  8. Total: 8,192,000 + 4,721,664 + 256 = 12,913,920
  9. 12·L·h² = 12 × 6 × 256² = 4,718,592, only 0.07% off the non-embedding count…
  10. …but 63.4% of this model IS the embedding table, so the rule misses 2.7× the real size

The fourth example is the one worth keeping in mind. The 12·L·h² rule is a non-embedding approximation, and quoting it as a model's size is safe only once the layer stack dwarfs the vocabulary table. Below roughly a hundred million parameters, small language models, distilled students, classroom builds, the embedding matrix is the model, and a large tokenizer vocabulary costs more than adding layers. Shrinking the vocabulary or tying the output head buys far more than trimming d_ff at that scale.

Parameter counts of well-known models

Ten published architectures, with the exact count this calculator returns for each beside the figure its model card or paper reports. Nothing in the table is typed in by hand, every total is computed from the configuration in the same row when the page renders, so the table and the calculator can never disagree. Load any of the presets to walk a row line by line, or use it as a sanity check on a config you are entering yourself.

ModelhLd_ffQ/KV headsVocabExact totalReportedEmb. share
GPT-2 Small768123,07212 / 1250,257124,439,808124M31.6%
GPT-2 Medium1,024244,09616 / 1650,257354,823,168355M14.8%
GPT-2 Large1,280365,12020 / 2050,257774,030,080774M8.5%
GPT-2 XL1,600486,40025 / 2550,2571,557,611,2001.5B5.3%
GPT-3 175B12,2889649,15296 / 9650,257174,604,259,328175B0.4%
Llama 2 7B4,0963216,51232 / 3232,0006,738,415,6166.74B3.9%
Llama 2 13B5,1204020,73640 / 4032,00013,015,864,32013.0B2.5%
Mistral 7B4,0963221,50432 / 832,0007,241,732,0967.24B3.6%
Llama 3 8B4,0963221,50432 / 8128,2568,030,261,2488.03B13.1%
Llama 3 70B8,1928043,00864 / 8128,25670,553,706,49670.6B3.0%

GPT-2 and GPT-3 rows use learned positions, LayerNorm, biases, and tied embeddings. Llama and Mistral rows use RoPE, RMSNorm, no biases, and untied embeddings, with d_ff set to 1.5× the model's reported intermediate size to stand in for the three-matrix SwiGLU MLP, 14,336 → 21,504 for Llama 3 8B, 28,672 → 43,008 for Llama 3 70B, 11,008 → 16,512 for Llama 2 7B. Totals round to the reported figure in every row.

Read down the last column and the scaling story is right there. Embeddings are 31.6% of GPT-2 Small and 0.4% of GPT-3 175B, because V · h grows linearly while the layer stack grows with h². Mistral 7B and Llama 3 8B share an identical layer stack, same hidden size, same depth, same 8 KV heads, same effective d_ff, so the same 6,979,588,096 non-embedding parameters, and differ by 788M purely because Llama 3 carries a 128,256-token vocabulary against Mistral's 32,000. Two models described as “7B” and “8B” are the same transformer with different tokenizers. If you need to turn any of these totals into a GPU shopping list, the GGUF quantization calculator covers what each quantization level costs in quality and bytes.

Frequently asked questions

Sources & references

Related tools

Comments & feedback

Spotted a bug or want an improvement? Tell us, our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] , most fixes ship within 24 hours.