Decoder Architecture › Layer Stacking and Information Flow
Language AI HandbookAll chapters Decoder Architecture › Layer Stacking and Information FlowOne section · Sections in this chapter7 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Decoder blocks are stacked sequentially. The output of block becomes the input to block . Each layer refines the representations, building increasingly abstract features.
def trace_layer_outputs(model, token_ids):
"""
Trace how representations evolve through decoder layers.
Returns the hidden states after each layer.
"""
seq_len = len(token_ids)
# Initial embeddings
tok_emb = model.token_embedding[token_ids]
pos_emb = model.position_embedding[:seq_len]
x = tok_emb + pos_emb
layer_outputs = [x.copy()]
# Through each block
for block in model.blocks:
x = block(x)
layer_outputs.append(x.copy())
# After final norm
x = rms_norm(x, model.final_norm_gamma)
layer_outputs.append(x.copy())
return layer_outputs
# Trace through our model
test_tokens = np.array([42, 100, 256, 789, 1000, 500, 333, 42])
layer_outputs = trace_layer_outputs(model, test_tokens)Tracing 8 tokens through 6 layers Layer output statistics (L2 norm of representations): -------------------------------------------------- Embedding : mean norm = 0.463, std = 0.028 Block 1 : mean norm = 24.058, std = 3.668 Block 2 : mean norm = 36.957, std = 4.267 Block 3 : mean norm = 44.214, std = 5.426 Block 4 : mean norm = 53.139, std = 4.717 Block 5 : mean norm = 60.062, std = 3.791 Block 6 : mean norm = 64.284, std = 2.553 Final Norm : mean norm = 16.000, std = 0.000
The representation norms reveal how the network transforms token embeddings. Starting from the embedding layer with relatively small norms (around 0.3), the representations grow as they pass through successive blocks. This growth reflects the accumulation of information via residual connections: each block adds its contribution to the running representation. The final layer norm rescales the output. This ensures consistent magnitudes before the language model head computes logits.

As we go deeper, representation norms tend to grow or stabilize depending on initialization and normalization. The final layer norm ensures consistent scale before the language model head.

The similarity matrix reveals how representations evolve. Adjacent layers tend to be more similar (the residual connections preserve information), while distant layers may diverge significantly as the model builds higher-level abstractions.