Ask a long-running AI agent to hold a 100,000-token conversation, and something quietly shifts under the hood: the attention mechanism, not the rest of the model, starts eating most of the compute budget. NVIDIA’s technical blog lays out why long-context inference gets slower in a very specific, measurable way as context grows, and argues that fixing it requires rethinking how attention is designed, not just how it is coded.
The team points to a concrete example: for DeepSeek-R1, the share of prefill time spent on attention rises from 18% at a 4K context window to 85% at 128K tokens. That is not a rounding error. It means that as agentic applications extend their working memory, attention stops being a minor cost and becomes the dominant one. NVIDIA frames this as a case for AI model co-design, where architecture decisions are made with GPU execution patterns in mind from the start, rather than bolted on afterward.
Two Different Problems Wearing One Name
The post’s central technical move is separating attention into two phases that behave nothing alike: prefill and decode. Prefill processes an entire prompt at once, producing large matrix multiplications that are compute-bound. Decode generates one token at a time, producing small matrix multiplications that are memory-bound, limited by how fast the GPU can pull the key-value (KV) cache from high-bandwidth memory rather than by raw compute power.
NVIDIA uses the roofline model, a standard way of describing whether a workload is limited by compute throughput or memory bandwidth, to show why this split matters. Arithmetic intensity, the ratio of total floating-point operations to bytes moved, determines which ceiling an operation hits. Prefill sits well above the “ridge point” where compute becomes the bottleneck. Decode sits below it, where memory bandwidth is the limiting factor. Speculative decoding, which generates multiple candidate tokens before verifying them, can push decode’s arithmetic intensity higher and shift it closer to compute-bound territory, but in the common case, decode stays memory-hungry.
There’s a practical wrinkle worth noting for agentic and multiturn applications: prefix caching. When a new conversational turn has a short new input but attends to a large cached prefix from earlier turns, that prefill step starts behaving like decode instead. NVIDIA’s analysis treats this as a real deployment pattern, not an edge case, since agent frameworks that maintain long-running context routinely hit it.
The FlashAttention Kernel and Why Shapes Matter
Underlying this analysis is FlashAttention, the kernel approach that computes attention without ever materializing the full attention matrix in memory. It streams tiles of queries, keys, and values from HBM into on-chip SRAM and fuses three steps: scoring queries against keys, running an online softmax normalization, and weighting the resulting values. The matrix multiplications run on Tensor Cores while the softmax math runs on separate function units.
NVIDIA’s engineers trace performance back to the shapes of these matrix multiplications. In decode, the “M” dimension of the matmul equals the group size, typically 8 to 16, which sits far below a GPU’s efficient tile size of 64 or 128. That mismatch means decode leaves compute capacity idle unless the group size is large enough to fill the tile more completely.
Group Size: The Lever That Only Helps in One Phase
Group size refers to how many query heads share a single KV head, a ratio set by the attention architecture itself. Multi-head attention (MHA) uses a group size of 1. Grouped-query attention (GQA) commonly uses 4, 8, or 16. Multi-query attention (MQA) pushes the group size up to the full number of query heads.
NVIDIA’s arithmetic shows these two phases respond to group size in opposite ways:
- In prefill, arithmetic intensity approaches roughly twice the input sequence length as group size grows, and the effect saturates quickly. Raising group size from 8 to 16 at a 32K sequence length improves arithmetic intensity by under 6%. Measured results confirm this: varying group size across the full MHA-to-MQA range changes prefill runtime by less than 1%.
- In decode, arithmetic intensity scales directly with group size. Doubling group size roughly doubles arithmetic intensity, and increasing it from 1 to 8 delivers an 8x gain by cutting memory traffic and improving GPU utilization per KV load.
The practical takeaway NVIDIA draws is that group size is a decode lever, largely inert for prefill. Models such as NVIDIA Nemotron 3 use GQA with just two KV heads specifically to make decode more efficient, illustrating that this is an active design choice already showing up in shipping architectures rather than a theoretical suggestion.
Head Dimension and the Case for Minimizing KV State
Beyond group size, NVIDIA’s guidance touches on head dimension and overall KV cache size. Head dimensions of 128 or 256 are recommended because they align with GPU tile and memory access patterns, extracting more throughput from the same hardware. Separately, minimizing the effective size of the KV cache, whether through cache compression, sparse or sliding-window attention, or hybrid architectures, reduces the memory traffic that dominates decode’s cost. NVIDIA cites Nemotron 3 again as an example of a hybrid architecture built with this goal in mind.
These recommendations form a co-design checklist that NVIDIA frames as actionable for model developers working directly with attention architecture, rather than general advice for application teams. The four guidelines: prioritize a high group size for decode efficiency, choose head dimensions of 128 or 256, actively shrink the KV state through compression or sparsity, and align parallelism strategy with KV head count.
Parallelism Has Its Own Rules
That last point deserves unpacking. NVIDIA’s post argues that how attention is split across multiple GPUs must be dictated by the number of KV heads a model has, not decided independently. Tensor parallelism, a common technique for spreading a model’s computation across GPUs, must not exceed the KV head count. Push tensor parallelism past that ceiling and KV data gets duplicated across GPUs, wasting memory and bandwidth rather than saving it.
For architectures with few KV heads, such as those using GQA or MQA aggressively, NVIDIA points to alternative strategies implemented in TensorRT-LLM: Attention Data Parallelism, KV Parallelism, and hybrid approaches like Wide Expert Parallelism and Helix Parallelism. The common thread is that reducing KV heads for decode efficiency creates a downstream constraint on how a model can be distributed across hardware, and teams need a parallelism strategy that accounts for that constraint rather than treating attention design and deployment topology as separate decisions.
Where This Fits Among Attention Optimization Approaches
This co-design framing sits alongside other well-known strategies for taming attention costs, such as quantizing the KV cache to lower precision, using sliding-window attention to cap how far back a model looks, or applying speculative decoding to shift decode toward compute-bound territory. What distinguishes NVIDIA’s argument is the emphasis on treating group size, head dimension, and parallelism as a single, interdependent system tied to specific GPU hardware characteristics, rather than optimizing each lever in isolation. The post explicitly separates this from sparse attention, which NVIDIA says it plans to cover in a followup, suggesting the dense-attention analysis here is meant as a foundation rather than a complete picture of every optimization technique in use.
A Concrete Workflow: Tuning an Agent’s Serving Stack
Consider a team serving a coding agent that maintains long working sessions with heavy prefix caching across turns. Applying NVIDIA’s framework, they would first profile whether their workload is prefill-heavy or decode-heavy at typical context lengths, since a 128K-context session behaves very differently from a 4K one. If decode dominates, as it will for most steady-state agent turns after the initial prompt, they would check their model’s group size and consider whether a GQA configuration with a higher group size is available or worth retraining toward. They would confirm head dimensions align with 128 or 256 rather than an odd value that leaves GPU tiles underutilized. Finally, before scaling out across multiple GPUs, they would check their KV head count against their planned tensor parallelism degree to avoid silent KV duplication, and evaluate whether TensorRT-LLM’s Attention Data Parallelism or KV Parallelism modes fit their KV head configuration better than default tensor parallelism.
Some caveats apply to this workflow in practice. NVIDIA’s arithmetic-intensity analysis assumes FP8 precision for both attention compute and the KV cache, so teams running different precision formats should verify whether the same ratios hold. The guidance also targets NVIDIA GPU architecture specifically, so its tile-size and memory-alignment recommendations may not transfer directly to other accelerator hardware. And because this post focuses solely on dense attention, where every query attends to every key and value, teams already using sparse or windowed attention will need the promised followup post before applying equivalent guidance to their architecture.
What the Followup Post Will Need to Resolve
NVIDIA’s dense-attention analysis leaves an open question that the company itself flags: how do these same group-size, head-dimension, and parallelism tradeoffs change once sparse attention, sliding windows, or other KV-reduction techniques enter the picture? Since NVIDIA already recommends sparse and hybrid approaches as ways to shrink KV state, the promised followup on sparse attention will determine whether the four-point checklist here holds up unchanged or needs its own separate set of rules for that increasingly common architecture family.