Small Language Model Design › The Parameter Budget

Michael BrenndoerferDecember 1, 20267 min read
Language AI HandbookAll chapters
Part 43 of 67Small and On-Device Language Models
Chapter 327Small Language Model Design › The Parameter Budget
Reading section 3 of 11 · The Parameter Budget · 7 minSection 3 of 11 · 7 min

Section 3 of 11 · 7 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The following accountant models a bias-free decoder with a SwiGLU feed-forward network and two RMS scale vectors in each block. It omits the final normalization and assumes there are no separate learned position embeddings. Under those assumptions, the token matrices grow with vocabulary size and hidden width, while the block weights grow with layer count. An embedding table at fixed vocabulary and width takes an increasing fraction of the total as you remove layers.

Counting Parameters per Component

For the full-attention case, suppose all query, key, and value heads have the same width, with their concatenated width equal to the model's hidden width. The model then spends its counted parameters as follows:

  • Token embedding table. The VV token rows each have width dd, for VdVd weights.
  • Attention. Query, key, value, and output each use a d×dd \times d projection, for 4d24d^2 weights per layer.
  • Gated FFN. The two input projections and one output projection use 3ddff3d d_{\mathrm{ff}} weights per layer. The code sets dff=⌊8d/3⌋d_{\mathrm{ff}}=\lfloor 8d/3\rfloor unless you supply a different size.
  • Output head. An untied output projection adds dVdV weights. A tied head uses the token embedding table transposed for projection to logits.
  • Block normalization. Two vectors of length dd add 2d2d parameters per layer.

With tied embeddings, the following approximation makes the layer and vocabulary terms easy to compare. It drops the small normalization term and ignores rounding the FFN width to an integer:

P=Vd+L(4d2+3ddff+2d)≈Vd+12Ld2.\begin{aligned} P &= Vd + L\left(4d^2 + 3d d_{\mathrm{ff}} + 2d\right) \\ &\approx Vd + 12 Ld^2. \end{aligned}

where:

  • PP is the counted parameter total.
  • VV is the vocabulary size, and dd is the hidden width.
  • LL is the number of blocks.
  • dffd_{\mathrm{ff}} is the intermediate width in each SwiGLU block.

The approximate block term grows quadratically with width at fixed LL, linearly with layer count at fixed dd, and cubically with width if you fix d/Ld/L while scaling both. The embedding term grows linearly with width at fixed VV. Check the actual block design before applying the formula: untied embeddings, grouped-query attention, or a different FFN multiplier change the total.

Why the Embedding Table Matters More at Small Scale

Take a 128,000-token vocabulary. With width 8,192, the table has 1,048,576,000 parameters, about 1.5% of a hypothetical 70B total. With width 2,048, the table has 262,144,000 parameters, about 26% of a hypothetical 1B total. The smaller table is cheaper in absolute terms and takes a larger share of the model.

Reducing a tied vocabulary from 128K to 32K at width 2,048 saves 196.608M weights. Each extra full-attention layer at that width costs about 50.33M under this accountant, so the saved weights could buy three whole layers. Which change helps depends on what strings the tokenizer sees and what functions the model needs to learn. A smaller vocabulary may require more tokens for some inputs, consuming more of the context and cache.

Here is the parameter accountant. The first fixtures use tied embeddings and full attention. Specify head counts when you get to the GQA example.

PythonIn [3]
CollapseExpand
def count_parameters(
    vocab_size,
    d_model,
    n_layers,
    d_ff=None,
    tie_embeddings=True,
    n_heads=1,
    n_kv_heads=None,
):
    """Count the specified projections and two RMS scale vectors per layer."""
    if d_ff is None:
        d_ff = 8 * d_model // 3
    if n_kv_heads is None:
        n_kv_heads = n_heads
    if d_model % n_heads or n_heads % n_kv_heads:
        raise ValueError("Head widths and query groups must be integral")
    d_head = d_model // n_heads
    embeddings = vocab_size * d_model
    output_head = 0 if tie_embeddings else embeddings
    attention = n_layers * (2 * d_model**2 + 2 * d_model * n_kv_heads * d_head)
    ffn = n_layers * 3 * d_model * d_ff
    norms = n_layers * 2 * d_model
    return {
        "embeddings": embeddings,
        "head (extra)": output_head,
        "attention": attention,
        "ffn": ffn,
        "norms": norms,
        "total": embeddings + output_head + attention + ffn + norms,
    }


configs = {
    "32K / 1024 / 24": dict(vocab_size=32_000, d_model=1024, n_layers=24),
    "32K / 2048 / 16": dict(vocab_size=32_000, d_model=2048, n_layers=16),
    "128K / 2048 / 14": dict(vocab_size=128_000, d_model=2048, n_layers=14),
    "128K / 3072 / 26": dict(vocab_size=128_000, d_model=3072, n_layers=26),
    "128K / 4096 / 32": dict(vocab_size=128_000, d_model=4096, n_layers=32),
}
breakdown = {
    name: count_parameters(**config) for name, config in configs.items()
}
ConsoleOut [4]
CollapseExpand
vocab / width / layers     total  embed %   ffn %  attn %
32K / 1024 / 24            0.33B     9.8%   60.1%   30.1%
32K / 2048 / 16            0.87B     7.5%   61.6%   30.8%
128K / 2048 / 14           0.97B    27.1%   48.6%   24.3%
128K / 3072 / 26           3.34B    11.8%   58.8%   29.4%
128K / 4096 / 32           6.97B     7.5%   61.6%   30.8%

The rows at width 2,048 have different depths and parameter totals. The 16-layer, 32K-vocabulary fixture uses about 871M weights, with 7.5% in embeddings. The 14-layer, 128K-vocabulary fixture uses about 967M, with 27.1% in embeddings. The comparison shows how vocabulary and depth affect allocation under this accounting scheme.

VisualizationOut [6]
CollapseExpand
Stacked shares highlight the wide vocabulary at width 2,048.
Illustrative shares of counted parameters for the five tied, full-attention configurations. At width 2,048 the 128K-vocabulary configuration spends a larger share of its budget on embeddings than the 32K-vocabulary configuration. The normalization segment is very small at this scale.

You can use the parameter plot in two passes. The formula VdVd tells you that the embedding count at fixed vocabulary and width is independent of depth. The two rows at width 2,048 change the vocabulary and depth together. At that width the 128K table has exactly four times as many parameters as the 32K table. Their embedding shares differ by about 3.6 times because each share divides its table size by a different total, which includes both the token table and the blocks. Second, compare the 128K rows across widths. Their token tables grow with width, while the attention and FFN projections also grow within each layer. This is why the widest 128K row assigns a smaller fraction to embeddings than the narrowest 128K row, despite using a larger absolute token table.

When you use the accountant on another architecture, work from the shapes of the saved tensors. For example, if you see a combined input projection of a SwiGLU block, count its two intermediate-width slices along with the contraction back to model width. If token embeddings and output weights appear under different names, check whether the implementation shares storage and training parameters before counting a second copy. The same parameter graph can be serialized in different ways, so these checks distinguish trainable weights from the bytes in a particular exported file.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy