Module 25 — Modern LLM Architecture
Modern Large Language Models (LLMs) improve the original Transformer architecture by introducing more efficient normalization, activation functions, attention mechanisms, and inference optimizations.
These techniques significantly improve training stability, memory efficiency, long-context handling, and inference speed.
They are widely used in models such as LLaMA, Gemma, Qwen, DeepSeek, Mistral, Phi, Falcon, Mixtral, Claude, and Gemini.
Topics
- RMSNorm
- SwiGLU
- KV Cache
- Grouped Query Attention (GQA)
- Rotary Position Embedding (RoPE)
1. RMSNorm
RMSNorm (Root Mean Square Normalization) normalizes activations using only the root mean square value instead of subtracting the mean like LayerNorm.
Formula
RMSNorm
Expanded,
where
- = Learnable Scale Parameter
- = Numerical Stability Constant
Advantages
- Faster than LayerNorm
- Lower computation
- Better scalability for LLMs
Used in
- LLaMA
- Gemma
- Mistral
- Qwen
- DeepSeek
2. SwiGLU
SwiGLU is an improved Feed Forward activation that combines the Swish activation with a gating mechanism.
Swish
where
SwiGLU
where
- = Element-wise Multiplication
Expanded,
Advantages
- Higher model quality
- Better gradient flow
- Replaces ReLU/GELU FFNs
Used in
- PaLM
- LLaMA
- Gemma
- Mistral
- Qwen
3. KV Cache
During autoregressive inference, previously computed Key and Value matrices are stored to avoid recomputation.
Key Cache
Value Cache
Attention Using KV Cache
Advantages
- Faster decoding
- Reduced computation
- Lower inference latency
4. Grouped Query Attention (GQA)
Grouped Query Attention allows multiple Query heads to share one Key-Value group.
Query
Shared Key
Shared Value
Attention
Advantages
- Smaller KV Cache
- Lower memory usage
- Faster inference
Used in
- LLaMA 2
- LLaMA 3
- Gemma
- Mistral
- Qwen
5. Rotary Position Embedding (RoPE)
RoPE encodes positional information by rotating Query and Key vectors.
Rotation Matrix
Rotated Query
Rotated Key
RoPE Attention
Advantages
- Long-context capability
- Better positional generalization
- No learned position embeddings
Used in
- GPT-NeoX
- LLaMA
- Gemma
- DeepSeek
- Qwen
- Phi
6. Modern LLM Decoder Block
A modern decoder layer can be represented as
7. Complete Modern LLM Pipeline
The complete architecture is
8. Applications
These architectural improvements are used in
- LLaMA 2
- LLaMA 3
- Gemma
- Gemma 2
- Mistral
- Mixtral
- Qwen
- DeepSeek
- Phi
- Falcon
- Claude
- Gemini
- GPT-NeoX
- Modern Large Language Models (LLMs)
Summary
| Concept | Formula |
|---|---|
| RMS |