Repository navigation
Transformer Concepts RoPE
RoPE (Rotary Positional Embedding) is the modern standard for injecting positional information into transformers. Instead of adding a vector at the beginning, RoPE mathematically rotates the Query and Key vectors inside the Attention mechanism based on their position in the sequence.
RoPE provides better extrapolation for long contexts compared to absolute positional embeddings. It allows the model to care about the relative distance between two words rather than their absolute position in the document.
RoPE is heavily featured in TokenPrint when exploring Llama or Qwen models.
-
Geometric Representation: In the 3D
TransformerStack, the RoPE operation is visualized as a helical/rotary twist applied to the Query and Key branches right before they enter the Attention blades. -
HUD Formulas: The Right Panel updates to show the complex rotary multiplication formulas:
$$q_m = f_q(x_m, m) = (W_q x_m) e^{im\theta}$$ -
Scientific Accuracy: The formulas dynamically read the real
rope_thetavalue from the model metadata (e.g.,1000000.0for Qwen 2.5) and display it in the HUD.
flowchart TD
Q[Query Vector] --> Rotate[Apply Rotation Matrix R_m]
K[Key Vector] --> RotateK[Apply Rotation Matrix R_n]
Rotate --> Dot[Dot Product (Attention Score)]
RotateK --> Dot
subgraph RoPE Property
Dot -.->|Depends only on relative distance| M_N[m - n]
end
| Previous | Home | Next |
|---|---|---|
| Positional Encoding | Home | Multi-Head Attention |
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