Decoder-only architecture is a Transformer variant that discards the encoder stack entirely, relying exclusively on decoder blocks with causal self-attention to generate sequences autoregressively. Unlike encoder-decoder models that first encode a source sequence, this architecture predicts the next token based solely on the preceding context, making it the foundation for models like the GPT family, PaLM, and Llama.
Glossary
Decoder-Only Architecture

What is Decoder-Only Architecture?
A Transformer configuration consisting solely of decoder blocks with causal self-attention, used by modern autoregressive language models like GPT to generate text token by token.
The defining characteristic is the causal attention mask, which prevents each token from attending to future positions, ensuring the model's predictions depend only on known information. During inference, a Key-Value (KV) cache stores previously computed attention states to avoid redundant computation, while modern variants like Grouped-Query Attention (GQA) reduce memory bandwidth demands, enabling efficient long-form text generation.
Core Characteristics of Decoder-Only Architectures
The defining structural and operational principles that distinguish decoder-only Transformers from encoder-decoder models, enabling their dominant role in modern autoregressive language generation.
Causal Self-Attention
The fundamental mechanism enforcing the autoregressive property. A causal mask—typically an upper triangular matrix set to negative infinity—is applied to the attention score matrix before softmax. This prevents token i from attending to any token j where j > i, ensuring the prediction for position i depends only on known outputs at positions less than i. This is what allows the model to be trained efficiently on all positions of a sequence in parallel using teacher forcing, while still behaving sequentially during inference.
Autoregressive Generation Loop
The inference process is inherently sequential. The model takes an initial prompt and generates one token. This new token is appended to the input sequence, and the entire sequence is fed back into the model to generate the next token. This loop continues until a special end-of-sequence (EOS) token is produced or a maximum length is reached. This contrasts with encoder-decoder models, which can generate the full output in a single, parallel forward pass after encoding the input.
Absence of Cross-Attention
A pure decoder-only architecture contains no cross-attention sub-layer. In an encoder-decoder Transformer, the decoder uses cross-attention to condition its generation on the encoder's representation of the input sequence. In a decoder-only model, there is no separate encoder; the source context and the generated sequence are simply concatenated into a single input stream. The model relies entirely on self-attention to draw relationships between the prompt and the generated text.
Unified Input-Output Representation
The model processes both the input prompt and its own previously generated output as a single, undifferentiated sequence of tokens. There is no architectural distinction between the source and target. This elegant simplicity allows the model to seamlessly handle tasks like few-shot prompting, where task instructions and examples are provided as part of the same input stream that the model will continue, blurring the line between instruction and generation.
KV Cache Optimization
A critical inference optimization unique to autoregressive generation. Without a cache, each generation step would recompute the Key and Value vectors for all previous tokens, leading to quadratic complexity. The KV Cache stores these vectors in GPU memory. On each new step, only the Query vector for the newest token is computed; its Keys and Values are calculated and appended to the cache, avoiding redundant computation and transforming the per-step complexity from quadratic to linear.
Pre-Normalization Architecture
Modern decoder-only models (like GPT-3 and Llama) predominantly use a pre-layer normalization scheme. The LayerNorm operation is applied to the input of each sub-layer (attention and FFN) before the sub-layer's computation, rather than after. This contrasts with the original Transformer's post-normalization. Pre-normalization has been empirically shown to stabilize training, reduce the need for learning rate warmup, and improve gradient flow in very deep networks.
How Decoder-Only Generation Works
A decoder-only architecture generates text by sequentially predicting one token at a time, conditioning each prediction on the previously generated tokens using causal self-attention.
A decoder-only architecture is a Transformer variant that generates sequences autoregressively. It applies causal self-attention, using a mask to ensure the prediction for token t depends only on tokens 0 through t-1. The model receives an input sequence and iteratively predicts the next most probable token, which is appended to the sequence for the subsequent step.
During inference, the Key-Value (KV) Cache stores previously computed Key and Value vectors to avoid redundant computation. The process repeats until a special end-of-sequence token is generated. Architectures like GPT and Meta Llama use this design, scaling effectively with techniques like Grouped-Query Attention (GQA) to manage memory bandwidth.
Frequently Asked Questions
Clear, technical answers to the most common questions about the autoregressive Transformer configuration powering modern generative language models.
A decoder-only architecture is a Transformer configuration consisting solely of decoder blocks that uses causal self-attention to generate text autoregressively, predicting one token at a time based on all previously generated tokens. Unlike the original encoder-decoder Transformer, it omits the separate encoder stack and cross-attention sub-layers entirely. The architecture stacks multiple Transformer blocks, each containing a masked multi-head self-attention sub-layer and a position-wise feed-forward network (FFN), wrapped with residual connections and layer normalization. During training, a causal mask ensures each token can only attend to itself and preceding tokens, preserving the left-to-right autoregressive property. At inference, the model leverages a Key-Value (KV) cache to store previously computed Key and Value vectors, avoiding redundant recomputation and enabling efficient token-by-token generation. This design, popularized by the GPT series, excels at next-token prediction tasks and emergent in-context learning.
Decoder-Only vs. Encoder-Decoder Architecture
A technical comparison of the two dominant Transformer configurations, contrasting their information flow, attention mechanisms, and primary use cases.
| Feature | Decoder-Only | Encoder-Decoder | Encoder-Only |
|---|---|---|---|
Information Flow | Unidirectional (left-to-right) | Bidirectional encoding, unidirectional decoding | Bidirectional |
Attention Mechanism | Causal Self-Attention | Self-Attention + Cross-Attention | Bi-directional Self-Attention |
Contextualization | Autoregressive | Conditioned on full input | Full context |
Training Objective | Next Token Prediction | Span Corruption / Denoising | Masked Language Modeling |
Generation Style | Token-by-token | Token-by-token | |
Input Processing | Prefix only | Full sequence | Full sequence |
Representative Models | GPT-4, Llama 3, Claude 3 | T5, BART, Flan-T5 | BERT, RoBERTa, DeBERTa |
Primary Use Case | Open-ended text generation | Sequence-to-sequence tasks | NLU classification & extraction |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Understanding the core components and mechanisms that enable autoregressive text generation in models like GPT.
Causal Attention
The defining mechanism of decoder-only models. A masking pattern prevents tokens from attending to future positions in the sequence, ensuring the autoregressive property. During training, this mask is applied to the attention score matrix, setting future token scores to negative infinity before the softmax. This enforces that the prediction for position i depends only on positions less than i.
Key-Value (KV) Cache
A critical inference optimization for autoregressive generation. Instead of recomputing Key and Value vectors for all previous tokens at each new step, the model stores them in memory. This avoids quadratic recomputation, reducing the per-step generation cost to linear time. The KV cache is the primary determinant of memory usage during long text generation.
Grouped-Query Attention (GQA)
An interpolation between Multi-Head Attention and Multi-Query Attention. GQA partitions Query heads into groups, with each group sharing a single set of Key and Value heads. This dramatically reduces the size of the KV cache while preserving model quality. Used in Llama 2 and Llama 3 to balance inference speed and accuracy.
Rotary Position Embedding (RoPE)
The dominant positional encoding scheme in modern decoder-only models. RoPE encodes position by rotating the Query and Key vectors in multi-head attention by an angle proportional to their position. This naturally incorporates relative position dependencies and shows superior length extrapolation properties. Adopted by Llama, PaLM, and GPT-NeoX.
Pre-Norm vs. Post-Norm
Refers to the placement of Layer Normalization within the Transformer block. Original Transformers used post-norm (normalization after residual addition), but modern decoder-only architectures like GPT-2 and Llama use pre-norm (normalization before attention and FFN sub-layers). Pre-norm stabilizes training, enabling larger models without warmup stages.
FlashAttention
An IO-aware exact attention algorithm that minimizes reads/writes between GPU HBM and SRAM. By fusing operations in a tiled, kernel-fused manner, FlashAttention avoids materializing the full N x N attention matrix in slow memory. This delivers 2-4x speedups and enables training with longer context windows. FlashAttention-2 and -3 further optimize for newer GPU architectures.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us