Transformer Parameter Count Calculator
Inputs
| Layers | 32 |
|---|---|
| Hidden size | 4,096 |
| Feed-forward expansion | 4 |
| Vocabulary size | 32,000 |
Transformer Parameter Count Calculator
Estimate the total parameter count of a decoder-only transformer from the number of layers, hidden size, feed-forward expansion, and vocabulary size, with a first-order architecture formula.
Inputs
Architecture
Results
Enter a value to see results.
Details
Transformer Parameter Count
The size of a large language model is usually quoted as a single headline number — seven billion, seventy billion — but that figure is determined entirely by a handful of architectural choices. Given the number of layers, the hidden size, the feed-forward expansion, and the vocabulary, the total parameter count follows from a short formula. This calculator applies that formula to give a first-order estimate, the same back-of-the-envelope reasoning used to size a model before any weights exist.
Where the parameters live
Almost every weight in a decoder-only transformer sits in one of three places. The attention sublayer of each block holds four square weight matrices — the query, key, value, and output projections — each of size hidden by hidden. The feed-forward sublayer holds two matrices that expand the hidden stream to a wider inner dimension and project it back. And separate from the stack of layers, the token embedding table stores one hidden-size vector for every entry in the vocabulary.
Counting these gives the architecture estimate. The attention block contributes about values per layer, where is the hidden size. The feed-forward block, expanding to an inner width of , contributes about . The embedding table contributes the vocabulary size times .
The formula
With layers, hidden size , feed-forward multiplier , and vocabulary size , the total parameter count is
N=L⋅d2⋅(4+2m)+V⋅dThe first term collects the per-layer attention and feed-forward weights across all layers; the second is the embedding table. Because the per-layer term scales with the square of the hidden size, the width of the model matters far more than the depth: doubling the hidden size roughly quadruples the count, while doubling the layers only doubles it.
Worked example
Take a model with 32 layers, a hidden size of 4096, a feed-forward expansion of four, and a vocabulary of 32,000 tokens. The per-layer factor is , so
N=32×40962×12+32000×4096=6,442,450,944+131,072,000≈6.57 billionThe layer stack accounts for almost all of it; the embedding table adds only about 131 million, a little over two percent. With the common expansion of four, roughly two thirds of each layer sits in the feed-forward weights and one third in attention.
What the estimate leaves out
This is a first-order count. It captures the matrices that dominate the total but omits the small terms: biases, the scale and shift values of layer normalization, and any learned position embeddings. Together these are typically well under one percent of a large model, so they do not move the headline figure. The estimate also assumes the input embedding and the output projection share one matrix — tied embeddings — so the table is counted once; a model with untied embeddings carries that table twice.
Once the count is known, it drives the practical questions of deployment. The memory needed to hold the weights depends on the count and the numeric precision, explored in the Model Size from Quantization Calculator. The memory required to train the same model, which adds optimizer state and activations on top of the weights, is covered in the LLM Training VRAM Calculator.
Frequently Asked Questions (FAQ)
What counts as a parameter?
A parameter is a single learned weight or bias value stored in the model. The dominant contributions are the weight matrices of the attention projections and the feed-forward layers, plus the token embedding table.
This estimate counts those matrices and the embedding table. It omits the small terms — biases, layer-normalization scale and shift values, and any learned position embeddings — which together usually amount to well under one percent of a large model.
How much does the embedding table contribute?
The token embedding table stores one hidden-size vector for every vocabulary entry, so it holds the vocabulary size times the hidden size values. For a small model with a large vocabulary this can be a sizeable share of the total, but for a large model the per-layer attention and feed-forward weights dominate and the embedding becomes a minor fraction.
When the input embedding and the output projection share the same matrix — tied embeddings — the table is counted once rather than twice.
Do attention or feed-forward layers hold more weights?
Per layer the attention block holds about four hidden-size-squared values from the query, key, value, and output projections, while the feed-forward block holds about two times the expansion multiplier times hidden-size-squared. With the common expansion of four, the feed-forward block holds roughly eight hidden-size-squared values against the attention block four, so about two thirds of each layer sits in the feed-forward weights.
Disclaimer
This is a first-order estimate. It captures the attention projections, the feed-forward weights, and the embedding table, but omits biases, layer-normalization parameters, and position embeddings, and assumes tied input and output embeddings. Published counts for a specific model may differ by a small margin.