GPU inference

On this page 7

GPU inference is the execution of a trained machine learning model on graphics processing units to produce predictions, embeddings, images or generated text for real requests. In AI infrastructure, it is the production side of the model lifecycle: training happens once or occasionally, while inference runs continuously for every user request and usually accounts for most of a deployed model’s long-term compute cost.

GPUs dominate inference for large models because neural network workloads consist mainly of matrix multiplications, which GPUs execute across thousands of parallel cores, and because they provide high-bandwidth memory to hold model weights close to the compute units. The engineering challenge is to keep these expensive processors busy while meeting latency targets.

How inference runs on a GPU

During inference, model weights are loaded into GPU memory (VRAM), inputs are batched and sent to the device, and optimized compute kernels perform the layer operations. For large language models, generation has two distinct phases with very different performance profiles.

PhaseWhat happensMain bottleneck
PrefillThe whole prompt is processed in parallel and the KV cache is builtCompute throughput
DecodeTokens are generated one at a time, each reading all weightsMemory bandwidth
The two phases of language model inference

In the decode phase, every new token requires reading the full set of model weights from memory. A model with 70 billion parameters stored in 16-bit precision occupies about 140 GB, so per-token speed for a single request is limited by how fast memory can be read, not by arithmetic. Batching many requests lets the GPU reuse each weight read for many tokens, which is the key to efficient throughput.

The KV cache stores attention keys and values for previous tokens so they are not recomputed. It grows with context length and the number of concurrent requests and often consumes as much memory as the weights themselves in long-context workloads.

Performance metrics and their trade-offs

GPU inference is tuned against several metrics that pull in different directions. The central tension is between latency for each user and throughput for the whole system.

MetricDefinitionInteractive target range
Time to first token (TTFT)Delay before the first output token appearsTypically under 0.5-2 seconds
Inter-token latencyTime between consecutive output tokensOften 10-50 ms, faster than reading speed
ThroughputTokens or requests processed per second per GPUMaximized within latency limits
GPU utilizationShare of compute capacity in useHigher means lower cost per token
Cost per million tokensHardware cost divided by tokens servedDepends on all the above
Key GPU inference metrics

Larger batches raise throughput and lower cost per token but increase latency for each request. Production systems set a latency budget, often expressed as a service level objective, and then fit the largest batch that respects it.

Optimization techniques

Most of the efficiency in GPU inference comes from software optimization rather than faster hardware. Inference servers combine several techniques, each addressing a different bottleneck.

TechniqueWhat it doesMain benefit
Continuous batchingAdds and removes requests from a running batch at each stepMuch higher utilization
Paged KV cacheStores the cache in fixed-size blocks like virtual memoryLess fragmentation, more concurrent users
QuantizationStores weights in 8-bit or 4-bit formatsLess memory, faster decoding
Fused attention kernelsComputes attention without materializing large matricesFaster prefill, less memory
Speculative decodingA small draft model proposes tokens the large model verifiesLower latency per output
Prompt cachingReuses the KV cache for repeated prompt prefixesFaster and cheaper repeated prompts
Common GPU inference optimizations

When a model does not fit on one GPU, it is split. Tensor parallelism divides each layer across GPUs connected by fast links, while pipeline parallelism places different layers on different GPUs. Tensor parallelism lowers latency but needs high-bandwidth interconnects between devices.

Choosing hardware and deployment

Hardware selection starts with memory capacity: the GPU or group of GPUs must hold the weights, the KV cache for the expected concurrency and runtime overhead. Compute speed and memory bandwidth then determine latency and throughput.

WorkloadTypical choiceReason
Small models and embeddingsSingle mid-range data center or workstation GPULow memory needs, high request volume
Mid-size LLM, quantizedOne GPU with 24-80 GB of memoryWeights and cache fit on one device
Large LLM at full precisionMultiple high-memory GPUs with fast interconnectWeights exceed one device
Image and video generationHigh-compute GPUsDiffusion steps are compute-bound
Spiky, low-volume trafficServerless or shared GPU capacityAvoids paying for idle hardware
Matching workloads to GPU options

GPU inference is usually deployed behind an inference server that handles batching, scheduling and the model API, as part of a broader model serving platform. Model routing can send simple requests to smaller, cheaper models and reserve large GPUs for difficult ones.

Common pitfalls

Many inference deployments are more expensive than necessary because of avoidable configuration mistakes.

  • Sizing memory for weights only and running out when the KV cache grows with long contexts.
  • Benchmarking with a single request, which hides how latency behaves under real concurrency.
  • Leaving GPUs idle between requests because static batching waits for full batches.
  • Quantizing without evaluation, which can quietly degrade accuracy on specific tasks.
  • Ignoring cold starts: loading tens of gigabytes of weights can take minutes when scaling out.

The reliable approach is to load test with realistic prompt and output lengths, measure latency percentiles such as p95 and p99 rather than averages, and validate output quality after every optimization.

Explained without jargon

GPU inference is the moment an AI model actually does its job for someone. Training teaches the model; inference is when it answers a question, writes a reply or creates a picture.

Graphics chips are used because they can do thousands of small calculations at the same time, which is exactly what AI models need. The hard part is serving many people at once. Nobody should wait too long. It is a bit like a busy kitchen that cooks many orders together, so each meal still arrives hot and on time.

A typical use case

An online retailer runs a customer-service chatbot on an open 8-billion-parameter language model. The first deployment uses a basic server with static batching on two GPUs, and during evening peaks users wait several seconds for the first token.

The infrastructure team moves the model to an inference server with continuous batching and a paged KV cache, quantizes the weights to 8 bits after confirming answer quality on 500 test conversations and enables prompt caching for the long system prompt shared by every session.

Under the same peak load, time to first token falls to well under one second, and one GPU now handles the traffic that previously needed two. The team uses the freed capacity to serve a second model for order-status lookups, routed automatically by request type.