LLaMA Architecture › Worked Example: Counting Parameters in LLaMA 7B
Language AI HandbookAll chapters LLaMA Architecture › Worked Example: Counting Parameters in LLaMA 7BOne section · Sections in this chapter4 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To solidify your understanding of the architecture, let's trace through where the 7 billion parameters in LLaMA 7B live. This exercise connects the abstract configuration numbers to concrete matrix shapes and gives you an intuition for which components dominate model size.
The LLaMA 7B configuration has , , , , and .
Embedding layer: The token embedding matrix has shape , contributing parameters, roughly 131 million. In LLaMA, the output projection (the matrix that maps the final hidden state back to vocabulary logits) shares weights with the embedding matrix, so this counts only once.
Per-layer parameters: Each of the 32 transformer blocks contains:
- Attention: four projection matrices of shape , covering QKV plus the output projection. Total per layer: million.
- FFN (SwiGLU): three matrices. The gate and up projections have shape and the down projection has shape . Total per layer: million.
- RMSNorm: two small parameter vectors of length each, one before attention and one before FFN. These add about 8K parameters per layer, negligible at this scale.
Total per layer: approximately million. Across 32 layers: million.
Final normalization: One RMSNorm of size , negligible.
Total: roughly million. The gap from 7B to this estimate arises partly from rounding and partly from the fact that "7B" is an approximate label. The actual parameter count for LLaMA 7B is closer to 6.7 billion, consistent with our calculation.
The key observation from this exercise: the feed-forward network contains approximately twice as many parameters as the attention mechanism per layer. The three SwiGLU matrices collectively dwarf the four attention projection matrices. This matters for inference optimization: techniques that quantize or prune the FFN layers have outsized impact on total model size.