Transformer Internals & Attention Flow Visualizer
Inspect every layer of a modern autoregressive Transformer forward pass: BPE subword tokenization and Rotary Position Embeddings (RoPE), scaled dot-product Q/K/V attention matrices, Pre-RMSNorm + SwiGLU residual streams, Grouped-Query Attention KV compression, and Temperature / Top-K / Top-P nucleus decoding.
Relative Offset Invariance in RoPE
Open Stage 01 (Tokenization & RoPE) and shift query position m and key position n while keeping the offset delta fixed. Observe how 2D complex-plane rotation makes inner products depend strictly on relative distance.
Why 1 / √d_k Scaling Prevents Saturation
In Stage 02 (Q/K/V Attention Matrix), toggle scaled dot-product normalization off and watch softmax weights spike toward one-hot saturation, collapsing gradient flow on long vectors.
Nucleus Sampling & GQA Bandwidth Savings
Compare Stage 04 (GQA KV Heads) against Stage 05 (Top-P Sampler) to see how reducing KV heads slashes decode memory traffic while nucleus thresholds keep generation coherent.
How Transformer Internals & Attention Flow Visualizer Works
The Transformer Internals Visualizer decomposes an autoregressive LLM forward pass into five inspectable stages: subword tokenization with RoPE complex-plane rotation, causal scaled dot-product attention with GQA KV-head sharing, RMSNorm + SwiGLU FFN residual streams, encoder-decoder cross-attention evolution, and temperature/Top-K/Top-P autoregressive sampling.
Frequently Asked Engineering Questions
- Why do modern LLMs use Rotary Position Embeddings (RoPE) instead of absolute sinusoids?
- RoPE rotates query and key sub-vectors by position-dependent angles in 2D subspaces so their inner product depends strictly on relative token offset (m - n), preserving sequence length extrapolation.
- How does Grouped-Query Attention (GQA) shrink inference memory?
- GQA shares fewer key and value projection heads across multiple query heads, reducing the per-token KV cache footprint proportionally while retaining multi-head expressivity.
- How do temperature, Top-K, and Top-P work together during decoding?
- Temperature rescales raw logits before softmax, Top-K restricts candidates to the K highest-probability tokens, and Top-P (nucleus sampling) dynamically truncates the smallest set whose cumulative mass reaches threshold p.
FS-102LLM Systems Foundations
Build a connected mental model from tokens through retrieval evaluation security and operations.
Get the weekly systems teardown
One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.