Inside a GPU_ The token journey

Daily Visual Engineering — Edition 001

Network Insight · Daily Visual EngineeringEdition 001 / Architecture series
Inside the GPU · Visual engineering

What Happens Inside a GPU When an AI Model Generates a Token?

Follow the journey from GPU memory to parallel computation, cached attention and the next generated token.

Read the engineering note ↓
2–4 min quick journeyOptional advanced labsBy Matthew Conran5 December 2026
GPU LOGIC DIEHBMHBMMEMORY ↔ PARALLEL COMPUTE
Conceptual accelerator package · not a physical die floorplan
01 · See itExplore memory and compute architecture.
02 · Interact with itFollow a token through prefill and decode.
03 · Understand itIdentify why memory and arithmetic both matter.
Interactive engineering experience / GPU architecture

Trace the next token

Run the illustrated sequence or advance one stage at a time. Change the context, batch and cache precision to investigate the memory footprint.

Guided visual journey · four stops0 / 4 explored

Choose a stop; the diagram, cache state and token stream will synchronize. Or play the full journey below.

0 / 12
01
Prompt
02
Prefill
03
Read
04
Compute
05
Sample
GPU / PACKAGE DATA PATHCONCEPTUAL VIEW
Conceptual single-GPU inference data pathCPU tokenization feeds GPU model execution. HBM holds weights and KV cache, L2 is a cache between external memory and streaming multiprocessors. Streaming multiprocessors use registers, shared or L1 memory and parallel arithmetic units including tensor cores where supported. The model produces logits, a token is selected and the cycle repeats. GPU PACKAGE / CONCEPTUAL, NOT TO SCALE Host · tokenize inputPrompt → token IDs HBMModel weights KV cacheIn GPU memory0 tokens L2Cache Streaming multiprocessorsTensor cores*Matrix operationsCUDA coresOther arithmeticRegistersThread-local dataL1 / sharedLocal data reuseAttention · MLP · logits Select next token · repeat *Where supported by GPUand selected kernel.
Execution activityComponent under inspection
READY / STEP 01

Prompt awaiting processing

Press Run or Next stage to start the conceptual token journey.

Illustrative output token fragments (not generated by an AI model):

—

Prefill produces the first token's logits. Each subsequent decode iteration processes the previously selected token.

Explore the hardware

GPU memory and compute

Select a component to inspect its role independently of the animated execution path.

128 KiBRaw KV per token, per sequence
2 GiBProjected current-model raw KV payload
0Cached positions per sequence in this trace
0 / 4Example generated tokens
Current traced KV allocation (raw payload)0 GiB
Projected KV budget headroom14 GiB

Hypothetical decoder-only transformer: 32 layers × 8 KV heads × 128 head dimension × 2 tensors (K and V). Batch assumes equally long independent sequences. This is raw unpartitioned payload, excluding weights, allocator padding, metadata and workspaces. Precision options illustrate storage size only, not actual support or quality. Controls reset the trace; the budget indicator is not an actual out-of-memory predictor.

Explore inside the GPU · 4 interactive microarchitecture labs
Microscopic engineering explorer

Memory hierarchy · trace eight illustrative reads

A cache hit can avoid an external HBM read. Set an assumed L2 hit share, then replay eight line requests. This simplified trace is not a GPU cache emulator; registers and shared memory are distinct forms of on-chip working storage, not compulsory next levels of a cache chain.

HBML2 cacheSMRegisters / sharedDevice memoryOn-chip cacheLoad + computeKernel working dataILLUSTRATIVE READ PATH · NOT TO SCALE
Ready · run or step through requests
0 / 8Reads issued
0L2 hits
0HBM read requests

Open a lab to investigate the computation in more detail.

Explore performance · GPU inference command centre
Engineering intelligence / illustrative model

Prefill vs. decode

Change the workload, accelerator limits and model weight storage to discover which resource constrains inference. Compare arithmetic and HBM transfer time—not measured GPU utilisation.

COMPUTE + MEMORYCONCEPTUAL PACKAGE
Phase 01 · prompt

Prefill

–Idealised whole-prompt phase time
Compute–
HBM–
––
Phase 02 · autoregressive

Decode iteration

–Idealised time per batched output step
Compute–
HBM–
––

Each phase uses its own bar scale (the larger time in that phase). Blue = compute time; gold = estimated HBM time. The maximum is the optimistic roofline-style estimate; latency is not the sum of these bars.

–Estimated batch prompt tokens/s
–Estimated aggregate output tokens/s
–Raw resident weights
–Raw KV after next input
–Decode HBM traffic per step
–Compute / bandwidth crossover FLOP/byte
–

Live bottleneck diagnosis

Set the workload to investigate the limiting resource.

Capture a baseline, then change one engineering parameter to compare the modelled phase times.

Engineering investigation · improve a memory-limited request

Load the case. Improve the estimated decode step to 10 ms or less while preserving batch, context, KV precision, weight precision, compute and capacity. Only HBM bandwidth may change.

Load the investigation to begin.
Model assumptions, calculations and limitations

Hypothetical single-device dense 7-billion-parameter decoder, 32 layers, 32 query heads, 8 KV heads, head dimension 128. B=batch, S=prompt positions, P=7×10⁹ parameters. Each parameter is assumed to contribute approximately one multiply-add per token (2 FLOPs). Weight storage uses decimal bytes. KV bytes per position per sequence = 2×32×8×128×stored bytes per element.

Prefill FLOPs = 2PBS + 2×32×32×128×B×S(S+1) (causal attention pair work); decode FLOPs = 2PB + 4×32×32×128×B×(S+1). Illustrative HBM bytes = weights read once per phase/step plus prefill KV write or decode KV read and current-position write. This assumes ideal weight reuse across the batch and ignores activation traffic and additional attention reads during prefill. Real implementations may reuse KV in cache, read weights multiple times, or perform extra work.

Each phase time = max(FLOPs/effective compute ceiling, HBM bytes/effective bandwidth). Effective ceilings are selected assumptions, not vendor specs. Resident footprint = weights + raw KV at S+1 + arbitrary 4 GiB reserve. The main trace KV-only budget is independent of this full-device model. Capacity warnings do not predict actual OOM. No queuing, kernel launches, tokenization, networking, quantization overhead, dynamic batching, distributed transfer or quality impact is modelled. The prompt phase includes neither first-token sampling nor end-to-end TTFT. Rates and times are mathematical examples, not benchmark results and not deployment sizing advice.

Engineering challenge · fit the cache

Try the Memory pressure preset. Without lowering concurrency or changing the budget, change one setting to bring projected raw KV payload at or below the selected budget. Then check your answer.

Choose the preset first to start.
Inside the engineering / 2-minute explainer

Why memory matters as much as compute

A language model does not produce an entire answer in one operation. The inference runtime first tokenizes the prompt and processes it through the model. During this prefill phase, the transformer establishes key and value (KV) state for the context and produces logits for the first output token.

The next generation step feeds the previously selected token into the model. Across successive transformer layers, the accelerator performs operations using model weights and the existing KV state. GPU streaming multiprocessors execute parallel work; supported matrix operations can use tensor cores, while other operations use other execution units. Registers, local caches and shared memory can help reuse data. HBM holds large model and cache allocations on suitable accelerators.

Attention uses the cached representations of earlier context. The current token's key and value representations are stored as the cache grows. The model produces new vocabulary logits, and a decoding policy chooses another token. The sequence repeats until a stopping condition is reached.

Unlike prefill, which often has considerable parallel work across the input sequence, single-request decode steps can spend much of their time moving data. Batching, quantization, cache reuse, architecture and implementation all change the balance between memory traffic and arithmetic. This is why a GPU with impressive theoretical compute power does not necessarily deliver the best response time for every inference workload.

Engineering takeaway

The next token is a memory journey as well as a compute operation. Increase context or concurrency in the simulator to see why KV-cache capacity and memory bandwidth become important design constraints.

Understand it / knowledge check

Three questions to take away

Choose an answer for each. You can revise your selections and get immediate explanations.

1. When is the KV cache first populated?
2. What happens to raw KV payload when context doubles, with all else fixed?
3. Which change most directly reduces a bandwidth-limited HBM transfer time, assuming the same byte count?
0 / 3 correct · 0 answered
Technical references and model assumptions

Simplified teaching model; no real GPU, inference engine, telemetry or performance measurement. Original AI-assisted editorial prepared for Matthew Conran's review. Legal & Editorial Centre.

Network Insight · See It. Interact With It. Understand It.
☕
Support Network Insight
Help support the development of interactive networking labs, BGP simulations, and educational content.
Support the Project
Matt Conran
Tags: No tags

Comments are closed.