Understand modern AI from the inside out.
- Intuition
- Mechanism
- System
- Security
- Research
- 1StorybookBuild intuitionYou learn: Fourteen short read-aloud chapters: next-word guessing, tokens, attention, training, agents, safety, history to 2026.Assumes: Nothing.Why it matters: A picture to hang every later mechanism on.
- 2MasteryUnderstand the real mechanismYou learn: 30 topics across six levels: the Qwen3-8B transformer, training and post-training, inference and serving, RAG, agents and MCP, interpretability.Assumes: Basic algebra and some Python; the Storybook helps.Why it matters: Lets you trace one token, one training step and one request without hand-waving.
- 3SecurityTrust boundaries, failure modes, defensesYou learn: 17 topics from assets and trust boundaries to prompt injection, poisoning, agent risks and red-team method, plus local synthetic labs.Assumes: Mastery levels 1, 4 and 5.Why it matters: Once a model reads untrusted text and can act, security is a design property of the whole system.
- 4ResearchInvestigate model internalsYou learn: Hidden states by layer, RMSNorm, linear probes, the Recall Microscope, and the human-vs-AI question.Assumes: Mastery levels 1 and 6.Why it matters: Moves from what the model outputs to where inside it a signal becomes accessible.
How does this piece of text become the next token?
Follow one sentence through a real language model, Qwen3-8B-Base, one step at a time. You predict, change something, and see what happens. No background is needed to start; the Mechanics and Research levels open the mathematics and the recorded measurements.
The researcher opened the notebook ?
Every number on these pages is labelled: Toy calculation Recorded Qwen measurement Experiment pending
Three things to try first
- Glass BoxOpen one real Qwen block and re-check its mathEvery tensor recorded from Qwen3-8B. Your browser re-derives ten operations and shows that only Qwen's real formulas fit: try LayerNorm, ReLU or the wrong rotation.Open →
- Mistake, or another version?9 of Qwen's 73 Gettysburg misses are another Lincoln manuscript's wordingLincoln wrote five copies of the Gettysburg Address. Several of Qwen's 'errors' match another copy word for word, which matters for any recall plateau.Open →
- You vs QwenGuess the next word against an 8B modelThe recall experiment as a game: the true text so far, your guess, and Qwen's recorded answer for the same position.Open →
The journey
Eight connected scenes. Each one asks a question, gives you one thing to change, and shows the consequence.
- 1outputText becomes tokensWhat does the model actually read?
- 2residual streamTokens become vectorsHow does a token turn into numbers?
- 3residual streamA block updates the representationWhat happens inside one block, and in what order?
- 4attentionAttention mixes informationWhich earlier words can this word look at?
- 5MLPThe MLP transforms each tokenWhat does the MLP do that attention does not?
- 6residual streamBlocks repeatIs block 30 the same as block 3?
- 7outputScores become the next tokenHow does a list of scores become one chosen word?
- 8normalizationLearning versus usingWhen do the model's weights change?
Labs
Focused experiments that go deeper than the journey.
Can Qwen's internal representations tell human-written from AI-generated text, and where? Plan, controls and status.
Teacher-forced next-token accuracy on a famous text and an unpublished control (Gettysburg Address 76.9%, bfloat16), traced through the layers.
A keyboard-controlled presentation with presenter notes and optional deeper sections.
Real Qwen: the exact block order
Recorded Qwen measurement· checked in the installed transformers sourceQwen/Qwen3-8B-Base @ 49e3418f: 36 blocks like this, then a final RMSNorm and an output projection to 151,936 scores (not tied to the embedding).
- 1input_layernormRMSNorm over 4,096 numbers (ε 0.000001)
- 2q_proj, k_proj, v_projQ: 32 heads × 128; K and V: 8 heads × 128; no bias
- 3q_norm, k_normRMSNorm over each 128-number Q and K head vector (V is not normalized)
- 4rotary embeddingRoPE on Q and K, θ = 1,000,000, rotate-half pairing
- 5causal attentiongrouped-query: 4 query heads per KV head; scale 1/√128
- 6o_proj4,096 → 4,096
- 7+ residualfirst residual addition
- 8post_attention_layernormRMSNorm, its own learned gain
- 9mlp (SwiGLU)down(SILU(gate(x)) × up(x)): 4,096 → 12,288 → 4,096
- 10+ residualsecond residual addition
Qwen3-8B-Base, verified: 36 blocks, 4,096-wide residual stream
Verified facts
Recorded Qwen measurement· verified from the checkpoint| Quantity | Value | Verified from |
|---|---|---|
| Model | Qwen/Qwen3-8B-Base @ 49e3418f | checkpoint |
| Transformer blocks | 36 | model object |
| Hidden size (residual stream width) | 4,096 | model object |
| MLP intermediate size | 12,288 | model object |
| Query heads / KV heads | 32 / 8 (4 query heads per KV head) | model object |
| Head dimension | 128 | model object |
| Vocabulary (embedding rows / tokenizer entries) | 151,936 / 151,669 | model object, tokenizer |
| Normalization | Qwen3RMSNorm (RMSNorm), eps 1e-6; plus Q/K RMSNorm over 128 dims | implementation source |
| Positions | RoPE on Q and K, theta 1,000,000, rotate-half pairing, 64 frequencies | config, implementation source |
| MLP activation | SILU inside SwiGLU (gate, up, down; no bias) | config, implementation source |
| Attention bias | none | config |
| Embedding and LM head tied? | no, stored separately | model object, safetensors |
| Context length (max position embeddings) | 32,768 | config, model card |
| Sliding window | not used | config |
| Parameters | 8,190,735,360 total; 6,946,075,648 excluding embedding and LM head | model object = stored tensors |
| Per block | 192,946,432 (attention 41,943,040, MLP 150,994,944, norms 8,448) | model object |
| Stored weights | bfloat16, 15.3 GiB | safetensors index |
Model card (Pretraining): 8.2B parameters, 6.95B non-embedding, 36 layers, 32 for Q and 8 for KV, context 32,768. Consistent with the counts above.
Order of operations, checked in the installed source (13/13)
transformers 5.18.0✓ Block is pre-norm: input_layernorm is applied before self_attn, and the residual is added after it
residual = hidden_states hidden_states = self.input_layernorm(hidden_states) hidden_states, _ = self.self_attn( hidden_states = residual + hidden_states residual = hidden_states hidden_states = self.post_attention_layernorm(hidden_states) hidden_states = self.mlp(hidden_states) hidden_states = residual + hidden_states
✓ Second sub-layer: post_attention_layernorm, then MLP, then the second residual addition
hidden_states = self.post_attention_layernorm(hidden_states) hidden_states = self.mlp(hidden_states)
✓ q_norm and k_norm are RMSNorms over head_dim (one head vector at a time), not over hidden_size
self.q_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # unlike olmo, only on the head dim! self.k_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # thus post q_norm does not need reshape
✓ q_norm / k_norm are applied after the projection and reshape to heads, and before RoPE
query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2) key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2) value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2) query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
✓ V is not normalized and not rotated
value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2) key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx)
✓ RoPE rotates Q and K only (applied inside attention, not added to the residual stream)
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
✓ RoPE uses the rotate-half pairing (dimension i with i + head_dim/2), not interleaved pairs
x1 = x[..., : x.shape[-1] // 2] x2 = x[..., x.shape[-1] // 2 :] return torch.cat((-x2, x1), dim=-1)
✓ Attention scores are scaled by head_dim ** -0.5
self.scaling = self.head_dim**-0.5
✓ Grouped-query attention: K/V heads are shared by num_attention_heads // num_key_value_heads query heads
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
✓ Attention is causal
self.is_causal = True
✓ MLP is SwiGLU: down_proj(act(gate_proj(x)) * up_proj(x))
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x)) return down_proj
✓ RMSNorm computes in float32: x * rsqrt(mean(x^2) + eps), then multiplies by a learned gain (no bias, no mean subtraction)
hidden_states = hidden_states.to(torch.float32) variance = hidden_states.pow(2).mean(-1, keepdim=True) hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon) return self.weight * hidden_states.to(input_dtype)
✓ A final RMSNorm (model.norm) follows the last decoder layer
hidden_states = self.norm(hidden_states)
- Textstring
- TokenizerT pieces
- Token IDs[B, T]
- Embeddings[B, T, 4096]
- 36 transformer blocks[B, T, 4096]
- Final RMSNorm[B, T, 4096]
- LM head[B, T, 151,936]
- Softmaxprobabilities
- Next token1 id
What does the model output?
A Regan-inspired statistical baseline, Maia-3 and Qwen3-8B compared on the same chess decisions, using their output probabilities.
Open Version 1What is happening inside the model that produces those outputs?
The same Qwen3-8B-Base checkpoint, opened up: residual stream, normalization, attention, MLP, and what a linear probe can read at each depth.
- 1Understand the architecture
- 2Instrument the architecture
- 3Measure the representations
- 4Test research hypotheses
Internal probe models and black-box generators
Internal probe model
Weights and hidden states are available, so we can read the residual stream, RMSNorm inputs and outputs, attention and MLP updates. Example: Qwen3-8B-Base (open weights). Only models of this kind appear in LatentLens's internal measurements.
Black-box generator
Only text comes back through an API. Examples include proprietary frontier systems. Their generated text can be studied as data (for example as the AI side of a human-vs-AI dataset), but their residual streams, normalization states, attention and MLP activations are not accessible and are never shown here.
Every tensor shape on this site refers to Qwen3-8B-Base only.