Two AI services can run the same model on the same GPU yet give very different user experiences. One replies quickly to single requests; the other serves many requests per second but makes individuals wait longer. To design reliable AI services, distinguish compute capacity, memory capacity, latency, and throughput.
1. Why GPUs help AI workloads
Many neural-network operations involve large numbers of parallel multiply-and-accumulate operations. GPUs are built to execute many numerical operations concurrently, making them suitable for matrix multiplication and tensor operations.
A GPU is not automatically faster for every task. Small workloads, unsupported operations, memory copies, and scheduling overhead can outweigh parallel-compute benefits. CPUs remain important for preprocessing, orchestration, data transfer, and small models.
2. GPU memory is not the same as compute speed
Model weights occupy device memory, but inference also needs activations, temporary buffers, framework overhead, and sometimes a key-value (KV) cache for generated sequences.
As a first approximation, raw weight storage is:
A 1-billion-parameter model using 2 bytes per parameter requires roughly 2 GB of raw weight storage (decimal units), before runtime buffers and caches. This approximation does not give the total memory needed to serve the model.
3. Latency and throughput are different
Latency is the time one request takes to complete, often measured in milliseconds or seconds. Throughput is the amount of completed work per unit time, such as requests per second or generated tokens per second.
A system can increase throughput by processing requests in batches, but users may wait for batching and queues. For interactive applications, track percentile latency, not only average latency.
Worked numerical example
If a service completes 240 requests over 60 seconds, its measured throughput is:
That alone does not reveal whether individual requests took 0.2 seconds or 8 seconds. Those latencies depend on concurrent requests, processing, and queueing.
4. Prompt processing versus token generation
Autoregressive language-model inference often has a prefill phase that processes the prompt and a decode phase that generates new tokens sequentially. Their compute and memory behavior differs. Systems may therefore track time to first token separately from time per output token.
Long contexts can increase KV-cache memory consumption. Running several users simultaneously introduces scheduling decisions: batching helps GPU utilization, while large batches or long sequences can raise memory demands.
5. Bottlenecks to recognize
| Bottleneck | Symptoms | Potential action |
|---|---|---|
| Compute-bound kernels | High arithmetic utilization | Optimize kernels or hardware choice |
| Memory bandwidth | Data transfer limits execution | Improve access patterns or reduce precision |
| Device memory | Out-of-memory errors | Reduce batch/context, quantize, shard where supported |
| CPU preprocessing | GPU sits idle waiting | Profile and parallelize preprocessing |
| Network or storage | Delayed data/model loading | Cache and improve transfer paths |
| Queueing | p95 latency grows with traffic | Add capacity, enforce concurrency limits |
Do not optimize based on intuition alone. Instrument each stage to identify where time and memory go.
6. A simple benchmark skeleton
from time import perf_counter
# Replace with a real model function and warm up first.
def model_call(x):
return sum(v * v for v in x)
inputs = [list(range(1000)) for _ in range(100)]
start = perf_counter()
for sample in inputs:
model_call(sample)
elapsed = perf_counter() - start
print('requests per second:', len(inputs) / elapsed)
This is a CPU timing demonstration, not a GPU benchmark. For GPU measurements, synchronize asynchronous device operations when appropriate and use framework-specific profilers.
7. Capacity planning and service quality
Choose expected input/output lengths, concurrent users, target p95 latency, and maximum cost. Run load tests with realistic traffic, then add safety margins for bursts and service failures. Recheck performance after model, runtime, and hardware changes.
Related concepts
- Model Serving and Deployment
- Inference Optimization and Quantization
- LLM Inference, Decoding, and Sampling
- Building Reliable AI Backends
References
Related articles in
- 2D vs 1D Memory: Why DLD and Assembly See Memory Differently — Why memory is a 2D grid in DLD but a 1D byte array in assembly, and how memory controllers connect the two views.
- How Computers Translate 1s and 0s into Screen Images — How binary memory states are mapped into RGB subpixel voltages and flashed onto physical monitor grids.
- Two's Complement: How Computers Represent Negative Integers — Two's complement is how CPUs store signed integers: count backward past zero, negate by inverting and adding 1, and let one adder handle signed math.