The reasoning methods never required reading the transformer. This module is the map of the particular network they call: Qwen3 at 0.6B parameters, in the implementation shipped with the course code. It is a decoder-only transformer. The pieces that differ from a 2019 GPT-2 block are the ones worth naming, because they show up in the shapes of the cache and in the tokenizer behavior from Module 2.
The 0.6B configuration
| Vocabulary | |
| Layers | |
| Embedding width | |
| Query heads | |
| Key-value groups | |
| Head dimension | |
| Feed-forward width | |
| RoPE base | |
| Context length | |
| Dtype | bfloat16 |
| QK norm | on |
The context field is the maximum position the cache and the rotary table will accept. The model was trained with a shorter context,
The forward pass is: token embedding,
One block
Figure 9.1 is pre-norm. If
and the feed-forward is the same pattern with a second RMSNorm. The shortcut is what makes a stack of
RMSNorm
Definition 9.1 (RMSNorm).For a vector
and a learned scale , with
. There is no mean subtraction and no bias.
Definition 9.1 replaces LayerNorm in this model. Dropping the mean is the whole change. The same operation is also applied to queries and keys inside attention (QK norm), with the scale learned per head dimension, before the rotary rotation. QK norm keeps the dot products that become attention scores from drifting in magnitude. It is on for this configuration.
The code computes the square mean in float32 even when the activations are bfloat16, then casts back. That is a numerical detail, not a different definition.
The feed-forward
The inner map is a gated linear unit, not a two-layer MLP.
Definition 9.2 (SwiGLU feed-forward).With
and , where
.
Definition 9.2 has three matrices.
A third matrix looks like “more parameters than GPT-2’s two-layer MLP.” Compare at equal parameter count, not at equal
Grouped-query attention
Sixteen query heads and eight key-value groups means each key head is shared by two query heads. The head dimension is
Definition 9.3 (Grouped-query attention).Split the queries into
groups of heads. Each group attends to its own key and value heads. Scores inside a head are where
is on allowed positions and on future positions.
Definition 9.3 is why the KV cache from Definition 2.2 stores eight key heads and eight value heads per layer, not sixteen. Sharing keys is the memory saving. The attention math per query head is otherwise ordinary scaled dot-product attention.
The mask
Rotary positions
Positions are not added as a learned vector. They rotate queries and keys. This repository uses the split-halves layout: the head vector is cut into a first half and a second half, and those halves are mixed by
The angles depend on the token index
What you can ignore while reading the earlier modules
Nothing in modules 1–8 changes RMSNorm, the gating, or the rotary frequencies. Those modules treat the network as a map from ids to logits, plus a cache. Come back here when a shape error in the cache, a tokenizer id above
Code
The readable implementation is qwen3.py. The notebook that walks the same file is chC_main.ipynb. RoPE was introduced by Su et al., 2021.