You don't need to understand LLM architecture to use LLMs. But understanding it explains a lot about why they cost what they cost, why they have context limits, why they're slow at generating long outputs, and why some prompts work better than others.
Virtually every major LLM today — GPT-4, Claude, Gemini, Llama, Mistral — is based on the transformer architecture, introduced in the 2017 paper "Attention Is All You Need." The key innovation was the attention mechanism, which lets the model look at all tokens in the context simultaneously rather than processing them sequentially.
Your prompt is split into tokens — roughly 3-4 characters each for English text. "Hello world" becomes ["Hello", " world"]. The model never sees raw text, only token IDs.
This is why you're billed per token, not per character or word. See our guide to where token waste hides for how this affects costs.
Each token ID is converted to a high-dimensional vector (typically 4,096-16,384 dimensions). These vectors encode semantic meaning — similar words have similar vectors.
The embedded tokens pass through N transformer layers (GPT-4 has ~96 layers). Each layer has two components:
The final layer outputs a probability distribution over all tokens in the vocabulary (~50,000-100,000 tokens). The model samples from this distribution to pick the next token.
The model generates one token at a time. Each new token is appended to the context, and the model runs another forward pass to generate the next one. This is why output tokens cost more than input tokens — they're generated sequentially, not in parallel.
Attention is the bottleneck. Every token must attend to every other token — making attention complexity O(n²) with context length. Doubling the context window quadruples the attention compute. This is why:
| Architecture | Examples | Key difference |
|---|---|---|
| Dense transformer | GPT-4, Claude, Llama 3 | All parameters active for every token |
| Mixture of Experts (MoE) | Mixtral, DeepSeek, GPT-4 (rumored) | Only a subset of parameters active per token — more efficient |
| State space models | Mamba, RWKV | Linear complexity vs quadratic attention — better for very long sequences |
| Hybrid | Jamba, Zamba | Combines transformer attention with SSM layers |
MoE models like DeepSeek get their cost efficiency from this architecture — they have many parameters but only activate a fraction per token, making inference cheaper than equally capable dense models. This is why DeepSeek can be 10-18x cheaper than GPT-4o while achieving similar benchmark scores.
The transformer's attention mechanism is both its greatest strength (it can relate any token to any other) and its greatest cost driver (attention scales quadratically with sequence length).
Tokoscope measures token usage, cost, and waste across every model and provider. Free to start.
Get started free →