
Debugging a Transformer When You Can't Set a Breakpoint
Debugging a transformer incident when there is no breakpoint: which on-call instincts still catch model failures, and where the forward pass goes dark.
This theme is curated by our AI council — see how it works.
Transformer and attention internals are the mechanisms inside modern language models: how text becomes tokens, how attention weighs those tokens against each other, and how architectural choices — encoder-decoder or decoder-only, dense or mixture-of-experts, attention or state space — decide what a model can do and what it costs to run. The theme spans the full stack, from tokenization to the efficient designs now challenging attention itself. This page maps that stack: what to read first, what each design decides, and where the designs get mistaken for each other.
Every API you call, every model you fine-tune, and every inference bill you pay is downstream of a handful of architecture decisions made before you arrived. When a long prompt suddenly costs more than you budgeted, that is attention’s quadratic scaling; when the same text bills a different token count across providers, that is the tokenizer; when a model card says “only a fraction of parameters active per token”, that is expert routing, with failure modes of its own. This theme replaces “the model is a black box” with a parts list — and the parts, not the brand names, are what transfer from one model generation to the next.

Three concepts carry everything else in this theme, and they are worth reading in order, because each one feeds the next.
The first is the attention mechanism — the operation that lets a model weigh the relevance of every token against every other instead of processing them one at a time. How queries, keys, and values power modern AI is the single best first read in this theme; once the core idea lands, self-attention vs. cross-attention vs. causal masking sorts out the variants you will meet on every model card. If you learn by building, implementing attention from scratch with PyTorch and FlashAttention turns the concept into code.
Attention only becomes a language model inside the transformer architecture — the full assembly of multi-head attention, positional encoding, and stacked layers that displaced recurrent networks. Multi-head attention, positional encoding, and the encoder-decoder structure explained walks the whole blueprint, and prerequisites for understanding transformers explains why RNNs lost and where the quadratic scaling limit comes from — the constraint the entire advanced tier is built to escape. When you want your hands on a real model, the Hugging Face and PyTorch build-and-fine-tune guide is the practical entry.
The least glamorous foundation decides more than most people expect: tokenizer architecture, the subsystem that converts raw text into the numeric tokens everything else operates on. How BPE, WordPiece, and Unigram encode text for LLMs is the orientation read, and glitch tokens and fertility gaps covers the unsolved problems that surface in production as odd failures and uneven costs.
With these three, you can pick up any model’s architecture diagram and know what you are looking at. The next tier is about the layouts those parts get arranged into.
Same parts, three arrangements — and the arrangement decides which workloads a model serves.
Encoder-decoder architecture is the original transformer layout: one network compresses the input into a representation, a second generates output from it. How sequence-to-sequence models process language explains the pattern, which still owns translation, transcription, and structured transformation — when to choose encoder-decoder over decoder-only is the decision read, with T5, BART, and Whisper as the working examples.
Decoder-only architecture is the pattern behind GPT, LLaMA, and most modern LLMs: a single stack that generates text token by token, each conditioned on everything before it. How autoregressive LLMs generate text is the entry point, and why decoder-only beat encoder-decoder explains the current LLM landscape in one sitting — scaling laws and data efficiency, not elegance, picked the winner.
The third arrangement leaves text entirely. The vision transformer treats image patches as tokens and runs the same attention machinery over them — how image patches replaced convolutions covers the move, and from CNN intuition to data hunger is honest about the price: transformers see images without convolution’s built-in assumptions and pay for that freedom in training data.
Once these three layouts are clear, the advanced tier stops looking like exotica — every design in it is a targeted answer to a cost the core layouts run into.
This tier is where the field’s current architecture work happens, and its three topics answer one shared question: how do you buy more capability without paying attention’s full price?
Mixture of experts scales a model’s parameters without scaling its per-token compute: a gating network routes each input to a few specialized sub-networks instead of activating the whole model. How sparse gating routes inputs to specialized sub-networks is the orientation read, and routing collapse and load-balancing failures covers the engineering limits that make MoE a discipline rather than a free lunch — worth knowing now that MoE has become the default frontier architecture.
The state space model family — Mamba and its descendants — replaces attention altogether, processing sequences in linear time through a fixed-size recurrent state. How selective SSMs replace quadratic attention explains the substitution, and in-context learning gaps and hybrid complexity explains why the practical answer in 2026 is usually a hybrid stack rather than a wholesale replacement.
Multimodal architecture is where the pieces above converge: designs that fuse text, images, audio, and video into a unified representation, the way GPT-4o and Gemini do. How models fuse modalities into unified representations is the entry point, and from vision transformers to modality gaps makes the dependency explicit — multimodal systems inherit both the strengths and the limits of the vision and attention layers underneath them.
The distinctions that cost engineers the most are the ones that look interchangeable on a model card. The three sequence architectures first:
| Decoder-only | Encoder-decoder | State-space model | |
|---|---|---|---|
| Core design | One stack generates tokens autoregressively | Encoder compresses input, decoder generates from it | Fixed-size recurrent state instead of attention |
| Known from | GPT, LLaMA, most modern LLMs | T5, BART, Whisper | Mamba family, Jamba, Nemotron hybrids |
| Best when | Open-ended generation, general-purpose assistants | Input and output are distinct sequences (translation, transcription) | Very long sequences where attention’s quadratic cost dominates |
| Main limit | Cost grows quadratically with context length | Lost the scaling race — less data-efficient at LLM scale | In-context learning gaps; usually shipped as part of a hybrid |
Three finer confusions sit inside these and trip people just as often:
None of these choices is settled. As our trend read shows, 2026 is the year of the hybrid architecture shift — frontier models increasingly mix attention layers, state-space layers, and expert routing in a single stack, while linear attention, ring attention, and gated variants keep redrawing the efficiency frontier from inside attention itself.
Q: Where should I start learning transformer internals as a software developer? A: Start with the queries, keys, and values explainer — attention is the one mechanism every other topic in this theme assumes. If you want the narrative before the mechanism, read the developer bridge linked at the end of this page, then return to the foundations tier.
Q: What should I read before tackling mixture-of-experts or state-space models? A: The whole foundations tier — both designs answer attention’s quadratic cost, which you need to understand before the fixes make sense. Then from feedforward layers to expert pools for MoE and from HiPPO to selective scan for SSMs list the exact prerequisites.
Q: Is encoder-decoder still worth learning when nearly every new LLM is decoder-only? A: Yes — the pattern owns workloads where input and output are genuinely different sequences: translation, transcription, structured rewriting. When to choose encoder-decoder over decoder-only maps the use cases, and T5Gemma 2’s encoder-decoder revival shows the pattern is not history.
Q: Do state-space models make transformers obsolete? A: No — they trade attention’s quadratic cost for a fixed-size state and give up some in-context ability in the bargain. The production pattern in 2026 is a hybrid stack that mixes both layer types, as Mamba-3, Jamba 1.5, and Nemotron-H shows.
Q: Why does the same prompt cost a different number of tokens on different models? A: Different tokenizers split text differently — vocabulary size, training data, and algorithm all change how many tokens a sentence becomes, and the gap widens sharply for non-English text. The hidden bias in tokenizers traces who ends up paying for that.
Q: Why does my fine-tuned vision transformer underperform a CNN on a small dataset? A: It is starved, not broken: vision transformers lack convolution’s built-in spatial assumptions and need far more data — or a strong pretrained backbone — to compensate. From CNN intuition to data hunger explains the trade-off and the practical workarounds.
Coming from software engineering? Bridge articles map this theme onto what you already know — which of your instincts still apply, which quietly break, and where to dive deeper once you're oriented.
An attention mechanism is a neural network component that lets a model dynamically focus on the most relevant parts of …
Decoder-only architecture is a transformer design where a single decoder stack generates output tokens one at a time, …
Encoder-decoder architecture is a neural network design pattern where an encoder network compresses an input sequence …
Mixture of Experts is a neural network architecture that splits computation across multiple specialized sub-networks …
Multimodal architecture describes AI model designs that process and generate across multiple data types at once — text, …
A State Space Model is a neural network architecture that processes sequences by maintaining a compressed hidden state …
Tokenizer architecture is the subsystem that converts raw text into numeric tokens a language model can process. It …
The transformer architecture is a neural network design that uses self-attention to process all parts of an input …
A vision transformer is a deep learning architecture that applies the transformer model, originally designed for text, …
MONA's articles build your mental model — how things work, why they work that way, and what intuition to develop.
Updated Jul 8, 2026
Concepts covered

Debugging a transformer incident when there is no breakpoint: which on-call instincts still catch model failures, and where the forward pass goes dark.

Dense transformers, mixture-of-experts, and state-space models turn identical API calls into different cost, latency, and memory profiles.

Attention mechanisms let neural networks weigh input relevance dynamically. Learn how queries, keys, and values compute the focus behind every transformer output.

BPE tokenizers produce glitch tokens and penalize non-Latin scripts with fertility gaps. Learn where the math breaks — and what is emerging to fix it.

Multi-head attention, positional encoding, and encoder-decoder structure: the three mechanisms inside every transformer, explained from geometry to implementation.

Understand why RNNs failed, how transformer self-attention trades parallelism for quadratic cost, and what these trade-offs predict for long-context language models.

Self-attention, cross-attention, and causal masking solve different problems inside transformers. Learn the math, trade-offs, and the quadratic scaling wall.

Tokenizer architecture determines how LLMs read text. Learn how BPE, WordPiece, and Unigram split text into subword tokens before attention ever fires.

Transformers use weighted averaging, not human-like focus: scaled dot-product, self-attention vs cross-attention, and scaling factor significance.

Master the math behind attention mechanisms — dot products, softmax, QKV matrices, and multi-head projections — before tackling transformer architecture.

Master the math behind transformers: embeddings, matrix multiplication, positional encoding, and multi-head attention explained with the precision engineers actually need.

The transformer architecture powers every major LLM. Learn how self-attention computes token relationships, why multi-head attention matters, and where the math breaks down.

Standard attention scales quadratically with sequence length. Learn why O(n²) breaks at long contexts, what attention sinks waste, and where fixes stand.

Transformer self-attention scales quadratically with sequence length. Understand the O(n²) memory wall, KV cache costs, and what FlashAttention and SSMs actually fix.

Vision Transformers treat images as token sequences, not pixel grids. Learn how 16x16 patches, self-attention, and position embeddings replaced convolution.

Vision Transformers drop CNN priors for learned attention — a trade that changes everything. Learn the prerequisites, CNN mappings, and hard limits of ViT.

How Vision Transformers turn images into token sequences — inside patch embeddings, the CLS token, and the shift from 1D to modern 2D positional encoding.

The encoder-decoder bottleneck crushed long sequences into one vector. Learn how attention replaced compression with selective access to every encoder position.

Decoder-only architecture powers every major LLM today. Learn how causal masking, KV cache, and autoregressive generation produce text one token at a time.

Encoder-decoder models compress input sequences into vectors and generate outputs token by token. Learn how seq2seq works and why attention changed everything.

Decoder-only models won the scaling race by doing less. Learn how a simpler training objective, scaling laws, and MoE extensions beat encoder-decoder design.

Before multimodal AI works, vision transformers, modality gaps, and grounding decay define its limits. The mechanics of why 2026 models still hallucinate.

Multimodal models like GPT-5 and Gemini 3.1 Pro don't see images — they translate them into token space. Here's the encoder-connector-backbone trick.

State space models trade recall for speed. Learn why pure Mamba breaks on in-context tasks and how hybrid SSM-attention models pay the compression bill.

State space models trade quadratic attention for linear recurrence. See how Mamba's selection works and why long-context models run hybrid in 2026.

State space models rebuilt recurrence on new math. Trace the components — HiPPO, S4, selective scan, gating — and the prerequisites that make SSMs click.

MoE models promise scale at fractional compute cost. Understand routing collapse, memory tradeoffs, and communication overhead — the hard engineering limits.

Mixture of experts activates only selected sub-networks per token. Learn how sparse gating makes trillion-parameter models practical and efficient.

Mixture of experts replaces one feedforward layer with many expert networks and a router. Learn how MoE gating and routing enable trillion-parameter models.