Module 19 · Part IV · The Modern Architecture
Reading a Model Card
GPT-2, LLaMA, Gemma and Qwen Compared, a Config File Field by Field, and Estimating Parameters, Cache and Compute
By the end you can read a real model config and say what each field implies for memory, speed and quality.
Check yourself ▸
Before you start, can you already…
- ☐turn the 2017 block into a 2024 block and justify each change. (Module 15)
If any is shaky, the linked module teaches it.
An open model's card and configuration file answer most of what this course has taught you to ask: how wide, how deep, which attention, which position encoding, how big a vocabulary. This module compares the families you have met, then reads a configuration field by field and turns it into parameters, KV cache and compute per token.
19.1 Comparing the Architectures
The table collects the choices of Modules 15 to 17 for four families.
| Feature | GPT-2 (2019) | LLaMA-3 (2024) | Gemma 2 (2024) | Qwen2 / Qwen2.5 (2024) |
|---|---|---|---|---|
| Normalization | LayerNorm, before each sub-layer (Pre-LN) | RMSNorm, before each sub-layer | RMSNorm before and after each sub-layer | RMSNorm, before each sub-layer |
| Position encoding | Learned absolute positions | RoPE () | RoPE (); Gemma 3: 10k local, 1M global | RoPE (), YaRN (section 15.2) for long context |
| Activation | GELU | SwiGLU | GeGLU (gated GELU) | SwiGLU |
| Attention | Multi-head (MHA) | Grouped-query (GQA, 8 KV heads) | GQA, local and global layers alternating 1:1; Gemma 3: 5 local to 1 global | GQA |
| Logit soft-capping | None | None | Yes: in attention, on output logits (Gemma 3 uses QK-norm instead) | None |
| Vocabulary size | 50,257 tokens | 128,256 tokens | 256,000 tokens | 152,064 embedding rows |
| Feed-forward | Dense, 2 matrices | Dense SwiGLU, 3 matrices | Dense GeGLU, 3 matrices | Dense SwiGLU; MoE variant: 64 routed + 8 shared experts |
| Model width | 768 (Small) | 4,096 (8B) | 3,584 (9B) | 3,584 (Qwen2.5-7B) |
Every row is from the cited papers and model cards, not measured; none of these architectures is in the reference repository.
How transformer designs differ
Compare the design choices of well-known models, from the original 2017 Transformer to GPT-2, LLaMA 3, Gemma 2 and Qwen2.5, a vision-language model, and two specialized models (PP-OCRv6 for reading text in images, Qwen3-TTS for speech). Pick a model on the left to see its details.
Gemma 2
Google DeepMind • Released 2024 • Frontier-LLM
- Local layers let each token see only the previous 4,096 tokens; global layers see everything
- Soft-capping, C·tanh(x / C), keeps values below C: C = 50 on attention scores, 30 on output logits
- Token embeddings are multiplied by √d_model
- Gemma 3 (2025) changed this: 5 local layers per global one, W = 1,024, and QK-norm in place of soft-capping
Before opening it, guess which single feature changed the most between GPT-2 and the 2024 families: normalization, position encoding, feed-forward, or attention.
In words. The explorer lists architectures from the original Transformer and GPT-2 to LLaMA 3, Gemma 2, Qwen, a vision-language model, PP-OCR and Qwen3-TTS, and shows the chosen one's normalization, position encoding, activation, attention, vocabulary and loss beside the others.
19.2 A Config File, Field by FieldRun this section
Models on Hugging Face ship a config.json. Here is one for an 8-billion-parameter LLaMA-3-style model:
{
"vocab_size": 128256,
"hidden_size": 4096,
"num_hidden_layers": 32,
"num_attention_heads": 32,
"num_key_value_heads": 8,
"intermediate_size": 14336,
"hidden_act": "silu",
"max_position_embeddings": 8192,
"rope_theta": 500000.0,
"rms_norm_eps": 1e-05,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16"
}| field | meaning | section |
|---|---|---|
vocab_size | , rows of the embedding table | 9.4 |
hidden_size | , the width of the residual stream | 1.5, 7.6 |
num_hidden_layers | the number of blocks | 7.6 |
num_attention_heads | query heads ; the head width is hidden_size / num_attention_heads = 128 | 6.6 |
num_key_value_heads | ; fewer than means grouped-query attention, here 4 query heads per KV head | 15.5 |
intermediate_size | , the inner width of the feed-forward network | 7.4, 15.4 |
hidden_act: silu | Swish with ; with three matrices this is SwiGLU | 15.4 |
max_position_embeddings | the context length it was trained for | 15.2 |
rope_theta | the RoPE base (10,000 in the original; raised for long context) | 15.1, 15.2 |
rms_norm_eps | the inside RMSNorm | 15.3 |
tie_word_embeddings | whether the output layer reuses the embedding table | 7.5 |
torch_dtype | the format the weights are stored in, 2 bytes per number for bfloat16 | 1.7, 24.1 |
Other fields signal Modules 16 to 18: sliding_window or per-layer attention types for local and global layers, num_experts and num_experts_per_tok for mixture of experts, rope_scaling for context extension, and final_logit_softcapping for Gemma's soft cap.
19.3 Estimating Parameters, Cache, and ComputeRun this section
With hidden_size, num_hidden_layers, and intermediate_size:
- Parameters per block. Attention has and of size , and and of size , so . A SwiGLU feed-forward network has three matrices, . Norms add a few times .
- Total parameters. blocks plus the embedding table , plus the same again for the output layer if it is not tied.
- KV cache per sequence (sections 15.5 and 23.1): .
- Compute per token, from section 10.5: about (parameters) FLOPs in the forward pass, plus the attention scores, about more, which matters only for long contexts.
Worked example. For the configuration above: attention is million per block, SwiGLU is million, so a block is about 218 million and 32 blocks about 6.98 billion. The untied embedding and output layer add billion, for a total of about 8.03 billion: the "8B" in the name. At 8,192 tokens in bf16 the KV cache is bytes GiB per sequence.
Edit the configuration or load a preset. The readout applies the formulas of this section.
Load the 8B configuration, then change num_key_value_heads from 8 to 32. Before you look, predict which of the three outputs change: parameters, KV cache, or compute per token.
In words. An editable model configuration, with presets, and a readout of head width, parameters per block and in total, KV cache at a chosen context, and forward compute per token.
Exercises
Which configuration field tells you whether a model uses grouped-query attention?
A configuration has hidden_size 2048, num_attention_heads 16, num_key_value_heads 4. What is the head width, and how many query heads share each key-value head?
Estimate the KV cache in GiB for one 32,768-token sequence of a model with 28 layers, 4 key-value heads, head width 128, in bf16.
How many parameters does one SwiGLU feed-forward network have at hidden_size 4096 and intermediate_size 14336, in millions?
A configuration has num_experts 128 and num_experts_per_tok 8. How do you expect its total parameter count and its compute per token to compare with a dense model of the same width and depth whose feed-forward network is the size of one expert?
Core Academic References
- Radford et al., OpenAI (2019): Language Models are Unsupervised Multitask Learners (GPT-2). Technical Report.
- Grattafiori et al. (2024): The Llama 3 Herd of Models. arXiv:2407.21783
- Gemma Team, Google DeepMind (2024): Gemma 2: Improving Open Language Models at a Practical Size. arXiv:2408.00118
- Qwen Team, Alibaba (2024): Qwen2.5 Technical Report. arXiv:2412.15115
- Mitchell et al. (2019): Model Cards for Model Reporting. FAT* 2019. arXiv:1810.03993
Measured labs
These labs test what this module says by running real code. Each card states the idea, what the experiment found, and what it does not prove. The numbers come from experiments/results.json, the output of running experiments/run_all.sh on the tiny-transformers reference code at version 137f7ef. The project checks fail if a measured number in the module text stops matching that file.
Lab 5 — what this repository does and does not implement
What the module says
Modules 16 to 19 compare the Gemma and Qwen model families: alternating local and global attention, RMSNorm before and after each sub-layer, soft-capping of scores, mixture-of-experts routing with shared experts, and capacity limits per expert.
What the experiment found
None of these designs is in the reference repository. What this lab can show is the gap in scale: the reference model has 112,323 parameters and 2 layers, while the models in Module 17 have up to 64 routed experts and vocabularies of 152,064 to 256,000 tokens. The comparison table in 5.4 comes from the published papers, not from measurements.
- reference model parameters
- 112,323
- reference model layers
- 2
- reference model attention heads
- 2
- reference vocabulary size
- 67
single characters; section 19.1 lists 152,064–256,000 for the large models
What this does not prove
The architecture comparisons of Modules 16 to 19 are description. None of their numbers was measured here, and this panel says so rather than suggest otherwise. Treat them as taken from the cited papers and model cards, not from running code.
Run it yourself
cd tiny-transformers && .venv/bin/python experiments/parameter_count.pyThe code being tested