~/fba-lab/lab/qwen-c/04-forward

FBALab

Code · architecture · study mode

AboutRoadmapSpeedrun
FBALab

Study mode — no GPU required.

Interactive LLM training & inference lab.

Qwen CAboutContactTermsPrivacyCookiesCommunity

© 2026 FBA Lab

Contact · contact@bubblspace.com · +91 75061 55016

INFERENCE SIMULATION

Qwen3 Pure C — 4 · Forward pass

running
◷run_viz.c▸rmsnorm()◎learner⌁04-forward$no GPU
weights
Load the model
The 4 GB weight file is mapped into memory in milliseconds. No copying — the OS pages in only what inference needs.
run_viz.c · stage 01–02
load
active
runtime
Run inference
Your prompt flows through 28 layers of attention and computation, one token at a time.
stage 03–04
forward
output
Generate text
The model scores all 151,936 possible next words and picks one. Then repeats.
stage 05–06
1/8
Blocks
Quick summary

Without normalization, numbers grow out of control as they pass through 28 layers of matrix multiplication — RMSNorm resets the scale after each layer so the math stays stable.

Full explanation below the code →

fba-lab — run_viz.c · rmsnorm()executing
$ rmsnorm(x, weight)ss = sum(x²); scale by 1/rms(x)activations normalized ✓
Explanation

Imagine multiplying a vector by a matrix 28 times in a row. Even if each multiplication changes the values by a small amount, those changes compound. Numbers drift toward very large or very small values — eventually becoming infinity or zero, making the entire output meaningless. Normalization prevents this by resetting the scale of the activations at key points.

RMSNorm does this in three steps: 1. Compute the root-mean-square of the current values: ss = sum(x[i]²) / dim, then rms = sqrt(ss + eps) — a measure of the overall magnitude 2. Divide every value by that RMS — rescaling everything to roughly unit magnitude 3. Multiply by a learned per-channel weight vector — letting the model control the scale it actually wants for each dimension

The result: activations enter the next matmul at a predictable scale, regardless of what happened before.

Qwen3 uses RMSNorm instead of the older LayerNorm (which also subtracts the mean). Skipping the mean subtraction makes it faster and slightly simpler — and it turns out mean subtraction isn't necessary for stability.

Why it matters

Without normalization, deep stacks amplify activation magnitude — matmuls explode or vanish.

Think about

Why does a 28-layer model need normalization between layers if each individual matmul seems fine?

// architecture

Live diagram

100%
Dataflow overviewtokenembedLayer×Nlogitsresidual stream →RMSNormQKV matmulRoPEattn scoresWoFFN normw1 / w3SwiGLUw2KV cacheloff + pos
← 3 · Buffers5 · Tokenizer →
Step 4 of 10Skill: The Forward Pass
01Blueprint02Load weights03Buffers04Forward pass05Tokenizer06Generate loop07GEMV, not GEMM08Every op a kernel09Attention & memory10Prefill vs decode