Repository navigation
Transformer Concepts LayerNorm
Normalization keeps the numbers flowing through the transformer stable. Without it, the massive matrix multiplications would cause the values to either explode toward infinity or vanish toward zero.
If the values inside the model become too large, the gradients used during training become unstable. During inference, extreme values can break the Softmax function, leading to garbage text generation. LayerNorm ensures the activations always have a reasonable mean and variance.
TokenPrint supports both standard LayerNorm and the more modern RMSNorm.
-
Geometry: In the
TransformerStack, normalization is represented as a waist or collar on the Residual Stream. Because normalization scales the magnitude of the vectors but doesn't change their dimensionality, the physical width of the 3D block stays the same (e.g., 896$\rightarrow$ 896), but the block pinches inward. -
Architecture Detection:
- If
gpt2is loaded, TokenPrint shows LayerNorm (which centers the mean and scales the variance). - If
llamaorqwen2is loaded, TokenPrint shows RMSNorm (Root Mean Square Normalization), which skips the mean-centering step for faster computation.
- If
-
HUD Formulas: The Right Panel updates to display the exact mathematical formulation, including the
$\epsilon$ (epsilon) constant used to prevent division by zero.
flowchart LR
Input[Unnormalized Vector X] --> Mean[Calculate Mean]
Input --> Var[Calculate Variance]
Mean --> Norm[Normalize: X - Mean / sqrt(Var + eps)]
Var --> Norm
Norm --> Scale[Scale by Gamma]
Scale --> Shift[Shift by Beta]
Shift --> Output[Normalized Vector]
subgraph RMSNorm Shortcut
Input -.-> |Skip Mean| RMS[Calculate RMS]
RMS -.-> |Scale by Gamma only| Output
end
| Previous | Home | Next |
|---|---|---|
| KV Cache | Home | Feed Forward Network |
TokenPrint Wiki | Home | Getting Started | User Guide | Concepts | Architecture | API | GitHub
TokenPrint is an interactive 3D visualization platform for exploring transformer architectures, tensors, and real-time LLM inference.
- User Guide
- Architecture Explorer
- Live Inference
- Tensor Inspector
- Camera Controls
- HUD
- Timeline
- Scene Navigation
- Transformer Concepts
- Tokenization
- Embeddings
- Positional Encoding
- RoPE
- Multi-Head Attention
- KV Cache
- LayerNorm
- Feed Forward Network
- Residual Connections
- Logits
- Softmax
- Sampling
- Autoregressive Generation
- Visualization System
- Scene Graph
- Geometry
- Materials
- Animation System
- Color Mapping
- Camera System
- Interaction Model
- Architecture
- Overall Architecture
- Frontend
- Backend
- WebSocket Protocol
- Data Pipeline
- Renderer
- Event System