Inside Qwen3-4B's inference pipeline: 36 decoder blocks from tokens to logits

Abhishekcur · x · 2026-11-27

Abhishekcur walks through the full inference pipeline of Qwen3-4B (4.02B parameters), layer by layer, and plans to follow up with deeper dives into each component.

Preprocessing: the prompt goes through a chat template and BPE tokenizer to produce token embeddings.

The core is 36 Transformer decoder blocks, each performing: RMSNorm → Q/K/V projections → QK-Norm → RoPE applied to Q and K → KV cache update → Causal Grouped Query Attention → output projection + residual addition → RMSNorm → SwiGLU MLP → residual addition.

The output path is a final RMSNorm followed by the LM head producing logits. The breakdown is a handy map of the standard component stack (QK-Norm, RoPE, GQA, SwiGLU) in modern small open-source models.

Related event: Inside Qwen3-4B's Full Inference Pipeline(2 posts)→

Original post →

More from Models

Models channel →