AI performance engineering, as we use the term, is making a production model meet explicit latency, throughput and memory targets. Performance engineering in general covers the techniques used during development to make sure performance requirements such as throughput, latency and memory usage are met. For AI serving, TechnoLynx audits the production stack for latency and cost improvements before recommending a model replacement. Inference performance depends on how frameworks, system libraries and hardware interact. Production cost and latency can often be improved without replacing the model: the main levers (batching, caching, routing, quantisation, kernel work, serving configuration, runtime choice) sit below the model layer, and a model swap is the most expensive of them.
How is performance engineering different from performance testing?
Performance testing measures whether a system is fast enough. Performance engineering explains why it is or is not, then changes the layer responsible. A load-testing tool can show that p99 latency rose as traffic increased. It measures latency end to end, so it cannot show whether the time went into GPU kernels, Python-side scheduling, a host-to-device copy or a full KV cache.
The XSP across-stack profiling paper makes a similar argument from the research side. Each existing profiling tool gives only a partial view of model execution, and a complete picture means correlating model-level, layer-level and GPU kernel-level profiles. Its ResNet comparison is an example. MXNet and TensorFlow ResNets had roughly the same total GPU kernel latency, but MXNet ResNet_v1_50 spent 4.44 ms (55.1% of online latency) outside the GPU, against 2.18 ms (35.3%) for TensorFlow. Only the layered profile shows that the GPU was not the reason, so a faster GPU or a smaller model would have missed the problem.
How does AI performance engineering work in practice, step by step?
The order of work matters more than any single technique, because each step decides what the next one is allowed to change. The sequence:
- Write the budget first. Set p50, p95 and p99 latency (or TTFT and time-between-tokens for LLMs), sustained throughput before queueing starts, and cost per inference at the target latency. Without a budget there is no way to tell whether a change helped.
- Reproduce under realistic load. Run a warm-up phase before timing. The DEEP-GAP benchmark study (2026) uses 20 warm-up iterations to remove cold-start effects such as kernel initialisation and memory allocation, then times 100 iterations for steady-state figures.
- Profile the end-to-end timeline. Split host time, GPU time and transfer time before looking at any single kernel; a map of the serving path helps decide where to place the trace ranges.
- Go to kernel level only on the hot kernels. Use roofline and stall analysis to see whether each one is memory-bound or compute-bound.
- Change one layer at a time. Consider the model last.
- Re-run the same load test against the budget. A result measured at a different clock state or batch size is not comparable.
What does a performance engineer actually do when the workload runs on GPUs?
On GPUs, most of the job is working out whether the accelerator is short of arithmetic or short of data, because the fixes for those two problems point in opposite directions. The tools are distinct enough to list:
- PyTorch profiler records CPU operators and on-device CUDA kernels, with optional input shapes and per-operator tensor memory.
- NVIDIA Nsight Systems puts CPU threads, CUDA API calls and GPU activity on one timeline, and NVTX ranges project application regions onto the GPU rows.
- NVIDIA Nsight Compute reports per-kernel “speed of light” throughput for compute and memory as a percentage of the theoretical maximum.
- TensorRT’s trtexec reports throughput, latency and a per-layer runtime breakdown, which can be exported to JSON.
The single most common misread in production inference is treating every latency problem as a compute problem: the team buys a GPU with more FLOPS and the benchmark barely moves because, as our post on memory-bound inference describes, on a large fraction of workloads the accelerator sits idle, waiting. The XSP study found that 20 of 37 image classification models were memory-bound on a Tesla V100 at their optimal batch sizes, and none reached more than 52% of theoretical peak throughput, which the authors read as room for optimisation. For LLMs, the Sarathi-Serve paper (OSDI 2024) describes prefill as compute-bound and decode as memory-bound, since decode processes one token per request at a time. PyTorch’s GPT-fast write-up goes further: at batch size 1, KV caching turns every transformer matrix multiplication into a matrix-vector product, so decoding is entirely memory-bandwidth bound. We cover memory-bound versus compute-bound inference in more depth separately.
This is also why TechnoLynx profiles before applying any performance tuning advice. Rules like “avoid branches” or “use the vendor API” only make sense in a context, and the context comes from a profile of this workload, not from a blog post.
How do you profile a GPU workload to find where time actually goes?
Work from coarse to fine. First compare host wall time with GPU compute time, then read the timeline, then look at kernel metrics and the roofline, and question each measurement for profiler side effects.
Host wall time versus GPU compute time
TensorRT’s benchmarking documentation offers a quick first diagnosis. If the total GPU compute time is much shorter than the total host wall time, host-side overhead or data transfers are probably leaving the GPU underused. Very small workloads (small GEMMs, small convolutions, mostly element-wise operations) tend to be enqueue-bound, and the documentation recommends comparing reported enqueue time with GPU compute time on the deployment system rather than relying on a fixed launch-cost estimate. CUDA Graphs can cut host-side launch overhead in that regime, but in NVIDIA’s own example they helped FP16 latency slightly and did nothing for FP8.
The timeline: kernels, gaps and transfers
Nsight Systems’ GPU metrics show PCIe and NVLink throughput, GPU memory bandwidth, SM activity, Tensor Core activity and warp occupancy over time. These answer questions such as “is my GPU idle?” and “am I blocked on IO?” To decide whether PCIe is the limit, TensorRT’s guidance is to check in the Nsight Systems profile whether the host-to-device or device-to-host copies of a query take longer than the GPU execution itself. When profiling a TensorRT application, start the profile after the engine is built, because the build phase times every candidate tactic and shows kernels that inference will never use.
Kernel metrics and the roofline
On the roofline chart, the ridge point divides kernels into a memory-bound region and a compute-bound region, and the distance to the boundary shows how much improvement is available. XSP defines a kernel as memory-bound when its arithmetic intensity (flops per byte of DRAM traffic) falls below the GPU’s peak FLOPS divided by its memory bandwidth. The stall reasons need careful reading. Nsight Compute’s guide says a kernel dominated by L1TEX scoreboard stalls is memory-latency-bound, which is not necessarily memory-bandwidth-bound. The real target is issue-slot utilisation rather than driving every stall counter to zero.
Profiler side effects
Profiling always adds overhead to what it measures. XSP reports that collecting GPU memory metrics can slow execution by more than 100×. Nsight Compute replays a kernel across several passes when more metrics are requested, which increases overhead. It also locks SM clocks by default where Nsight Systems does not, and it flushes GPU caches between replay passes, so NVIDIA recommends locking clocks externally with nvidia-smi before comparing results from the two tools. TensorRT’s documentation warns that two runs of the same engine on the same GPU can differ by tens of percent if the clock floats in one run and is locked in the other.
How do I set realistic latency and throughput budgets for a production AI feature?
Set a budget on the tail percentile the user actually experiences, at a load the service has to sustain. Then express throughput as the highest load that still meets that latency target, not as peak tokens per second. The Sarathi-Serve paper defines this as capacity: the maximum queries per second a system can sustain while meeting its latency targets.
Average latency is the wrong number for the budget because tails compound. Dean and Barroso’s “The Tail at Scale” (CACM, 2013) gives an example where a single request’s 99th-percentile latency is 10 ms but the 99th-percentile latency for all requests in a fan-out to finish is 140 ms. Waiting for the slowest 5% of requests accounts for half of that total. For LLM serving, every decode token produces a time-between-tokens value, so the Sarathi-Serve authors report median TTFT (measured once per request) but P99 for time between tokens. We would follow the same split: the per-token tail decides whether streaming output feels smooth, and one TTFT figure per request decides whether the response feels responsive.
Three further checks keep a budget honest. The budget should state the prompt and output length mix, since prefill and decode stress the GPU differently. It should state a cost-per-inference ceiling at the target latency, because a budget met by over-provisioning has only moved the problem onto the bill; the inference cost audit covers that side of the trade. And it should state which metric is primary. Choosing throughput or latency as the wrong optimisation target is a separate failure from missing either one. Turning a budget into fleet size is a steady-state capacity planning question.
How do you tell whether an inference latency problem lives in the model, the kernels, or the serving engine?
Each of the three layers leaves a different trace in the profile. A model problem shows up as more GPU work per token. A kernel problem shows up as hot kernels well below their roofline. A serving-engine problem shows up as generation stalls, preemption or dispatch gaps rather than more GPU work. In Llama2 the decoder layer takes most of the compute time, and its GEMM-based MLP and QKV projections are the most expensive parts, according to a 2023 study of LLM runtime performance. That cost comes from the model’s own GEMM work. The same study found that FlashAttention, by fusing the attention operations into one kernel that favours on-chip SRAM over DRAM, sped up the attention module by 34.9% and 24.7% in its tests. That gain came from a kernel-level change, with the model unchanged.
Batching and KV-cache settings trade throughput against latency
Batching helps decode a great deal and prefill hardly at all. Mixing the two in one batch creates a direct trade-off between throughput and latency. Prefill-prioritising schedulers cause what the Sarathi-Serve authors call generation stalls, and they show a stall in vLLM lasting several seconds. Naive hybrid batching increased time between tokens by up to 28.3× compared with a decode-only batch. Chunked prefill splits a long prompt into pieces and fits them into batches alongside ongoing decodes. With a token budget of 512, Sarathi-Serve reached 3.5× the capacity of vLLM under a strict 100 ms SLO on Mistral-7B, and a budget of 2048 gave 1.65× under a relaxed one-second SLO on Yi-34B. The authors set the budget by profiling batches of different sizes once and choosing the largest that does not break the time-between-tokens SLO.
vLLM makes the same trade-off tunable through max_num_batched_tokens. According to its documentation, smaller values such as 2048 give better inter-token latency, larger values give better TTFT, and values above 8192 are recommended for throughput, especially for smaller models on large GPUs. When KV-cache space runs out, vLLM preempts requests and recomputes them later. It logs a warning when this happens, and end-to-end performance suffers. The documented responses each cost something: raise gpu_memory_utilization, lower max_num_seqs or max_num_batched_tokens, or shard with tensor or pipeline parallelism at the price of synchronisation overhead or latency.
How the KV cache is managed limits batch size. The PagedAttention paper reported 2-4× higher throughput at the same latency as FasterTransformer and Orca, with near-zero waste in KV-cache memory. Compressing the cache is a different matter. A 2026 comparison of KV-cache strategies found that H2O cut GPU memory by up to 70% with competitive throughput, but at a 0.1 cache budget its HellaSwag score dropped by 23 percentage points. The authors conclude that KV-cache management is a three-way trade between memory, throughput and accuracy, and that no single framework wins on all three. Separating prefill and decode onto different GPUs goes further: DistServe (2024) reports serving 7.4× more requests, or meeting a 12.6× tighter SLO, while keeping more than 90% of requests within latency constraints.
Tail latency often comes from outside the GPU
The host CPU sits on the critical path of every mainstream LLM serving stack. It handles request admission, continuous batching, KV block management and kernel dispatch after each decode step. The Blink paper (2026) measured three production serving systems (SGLang, vLLM and TensorRT-LLM) keeping only 28-54% of their isolated throughput when co-located with CPU-intensive workloads. Under interference, gaps between kernel dispatches widened from about 1 µs to 40 µs, and that delay adds up over hundreds of output tokens. vLLM’s documentation sets a floor of 2 + N physical cores for N GPUs. It also notes that lower-than-expected GPU utilisation can point to CPU contention.
The interconnect matters as well. On shared A100 clusters, MIG isolates compute and HBM but not the PCIe path, so PCIe-heavy tenants can still slow each other down. A study combined dynamic MIG, PCIe-aware placement and lightweight guardrails, and improved p99 latency by about 15% at no more than 5% throughput cost, compared with static MIG and naive placement. For vLLM serving, the same controller cut TTFT p99 by roughly 12-15%. At fleet scale, Dean and Barroso describe hedged requests: send a second request only once the first has been outstanding longer than the 95th-percentile expected latency. This limits the extra load to about 5% while substantially shortening the tail.
When quantisation and mixed precision are the right latency fix
Quantisation fits a workload whose bottleneck is moving weights or activations. A smaller model fits only when the task really needs less capacity. A study of LLM quantisation (“Give Me BF16 or Give Me Death”) explains the mechanism. Weight-only quantisation mainly speeds up memory-bound decode, while quantising both weights and activations speeds up compute-bound prefill, so the right format depends on the ratio of prefill to decode tokens. Across the Llama-3.1 family, the same study found FP8 (W8A8-FP) effectively lossless, well-tuned INT8 (W8A8-INT) within 1-3% accuracy degradation, and INT4 weight-only (W4A16-INT) close to 8-bit. W8A8 gave the highest throughput under asynchronous continuous batching. SmoothQuant (2022) reports up to 1.56× speedup and 2× memory reduction for W8A8 LLMs with negligible accuracy loss.
For convolutional models, DEEP-GAP measured INT8 TensorRT engines at up to 14× (T4) and 18× (L4) faster than FP32 on ResNets. INT8 also had the lowest P99 latency and FP32 the highest. NVIDIA’s TensorRT documentation shows an FP8 ViT improving median latency from 54.18 ms to 31.11 ms, and adds that the engine used random calibration data and was not checked for accuracy. That caveat is the real risk with quantisation, so any precision change needs a task-specific evaluation before it ships.
Mixed precision gains are capped by Amdahl’s law. NVIDIA’s mixed-precision guide gives the example of a model spending half its time in Tensor Core operations that become 5× faster, which yields only 1.67× overall. Very small linear and convolution layers gain little. Per-layer profiles help find quantisation opportunities, which is one more reason the profile comes first.
When to restructure the algorithm instead of tuning kernels
Nsight Compute’s guidance ties speedups from stall reductions to kernels whose low issue activity makes them latency-limited. If the roofline shows a kernel near the memory bandwidth limit with low arithmetic intensity, further kernel tuning has little left to gain. The useful change then alters how much data moves. FlashAttention is an example: it fuses attention into one kernel and reduces accesses to GPU DRAM. Speculative decoding restructures the algorithm in a different way. It breaks the serial dependency of autoregressive generation without changing output quality, provided drafting plus verification takes less time than generating the tokens would. Chunked prefill restructures the schedule rather than the kernel.
Tracing a regression to the model or the serving stack: symptoms and first checks
Compare per-request GPU work before and after the regression. If it rose, start with the model or kernels. If it held steady while latency rose, the cause is in the serving stack or the load. This diagnostic table maps common symptoms to the layer we would check first:
| Symptom | Likely layer | First check |
|---|---|---|
| GPU compute time per request rose with the new model version | Model or kernels | Per-layer profile (trtexec --dumpProfile, PyTorch profiler) against the previous version |
| Host wall time well above total GPU compute time | Host-side overhead or transfers | Enqueue time versus GPU compute time; H2D/D2H copies in Nsight Systems |
| Generation stalls in time-between-tokens when long prompts arrive | Prefill interference in the scheduler | Chunked prefill and max_num_batched_tokens |
| Preemption warnings in logs, end-to-end performance falls | KV-cache capacity | gpu_memory_utilization, max_num_seqs, parallelism settings |
| GPU utilisation lower than expected | Host CPU contention | Physical cores against the 2 + N floor |
| p99 worse only on shared nodes, high PCIe traffic | Noisy neighbour on PCIe | Placement and MIG configuration |
| Accuracy dropped after a “performance” change | Precision or KV compression | Task-level evaluation at the new setting |
For the other rows, the likely layer sits below the model. A smaller model can lower the average and make the dashboard look healthier while the scheduler stall, the CPU starvation or the PCIe contention remains, ready to return at the next traffic peak. Even a real model-side regression is often recoverable below the model through precision, kernel fusion or batching changes, so replacement belongs at the end of the list.
What does load testing look like for an inference endpoint under burst traffic?
A useful load test steps through rising offered load with realistic request traces. It holds each level long enough to reach steady state and records tail percentiles and SLO misses at every level, rather than reporting one average figure. The Blink evaluation follows this pattern. It swept 13 offered load levels from 1 to 32 requests per second, measured each for 60 seconds using ShareGPT conversation traces, and reported results across the pre-saturation range, the loads before throughput stops growing and levels off. The shared-cluster study reported SLO miss-rate as its primary metric, with p95, p99 and p999 latency and, for LLM serving, TTFT percentiles.
For burst traffic specifically, we would add three things. First, step changes from steady load to a burst and back, to see where queueing starts and how fast the tail recovers. Second, a run with realistic co-located work on the host, since existing serving systems degraded by up to two orders of magnitude under CPU interference in the Blink measurements. Third, a check of the engine logs for preemption during the burst, because vLLM preempts requests when KV-cache space runs short. Latency and throughput also behave differently across batch sizes. DEEP-GAP found that throughput levels off beyond moderate batch sizes while latency keeps rising roughly linearly, so a burst that pushes batches larger buys little throughput at a real latency cost. Our latency testing methodology goes further into test design, and a separate post covers peak versus steady-state performance.
A model swap belongs at the end of the list
TechnoLynx audits the production serving stack to find latency and cost improvements before recommending a new model. That means profiling the path, setting the budget, and tuning batching, caching, precision, kernels and serving configuration first. GPU performance engineering work starts from that profile. For sports workloads, see AI engineering for sports analytics.
One question stays open after any tuning pass: whether the gains hold as traffic, prompts and co-located workloads change. Performance budgets and load-test evidence supply the latency and throughput part of release readiness. Evaluations, drift detection and rollout ownership are the rest, which a production AI reliability audit tests alongside them. A p99 budget that was met last quarter is a hypothesis this quarter until the load test is run again.
FAQ
What is inference time?
Inference latency is the time from presenting an input to the network until an output is available, for a single inference. Throughput is how many inferences complete per unit of time.