Profiling makes long-running code obvious so that it can be optimised. On an AI inference service, the useful kind of profiling splits each request into its stages: network handling, time in the scheduling queue, copying input to the GPU, model execution and copying output back. The main question the numbers answer is whether the time is spent inside the model or around it. That answer decides whether a model swap is even warranted, which makes per-stage profiling the measurement step of an inference cost audit.
Read the stages as percentiles, not averages. An average can sit far from any real request, and it says nothing about the slow requests your users remember.
How Profiling Works on an Inference Serving Path
This article covers two ways a profiler gets its data. A sampling profiler probes the call stack at regular intervals. That gives a statistical approximation, but the program runs at close to full speed. Instrumentation puts timers or named ranges around the code you care about. lm-Meter, for example, puts monotonic steady_clock timers before and after each phase of an LLM runtime, and NVIDIA’s NVTX API marks CPU ranges that Nsight Systems projects onto the GPU timeline.
Serving systems such as Triton add request-level tracing on top. Triton Inference Server can trace individual requests, including execution timestamps, and its default trace sampling rate is every 1,000th request. Distributed tracing models each timed piece of work as a span with start and end timestamps and a parent reference, then joins the spans into one timeline. XSP uses that structure to join profiles from several stack levels into one timeline trace.
Two reading rules help. In PyTorch Profiler, self time leaves out time spent in child operator calls, while total time includes it. Phase-level numbers also beat a single end-to-end figure, because they show which stage dominates and stop one aggregate from hiding very different behaviour across stages.
The Profiler Changes What It Measures
Profiling always comes with overhead. In the XSP study, turning on layer-level profiling for a ResNet-50 run added 157 ms to a 275.1 ms model-level baseline. The same paper reports that collecting GPU memory metrics can slow execution by more than 100×. On mobile and edge devices, a heavy profiler distorts latency and memory signals and leads to wrong conclusions about real-world performance. vLLM’s own documentation says end users should never turn profiling on, because it significantly slows inference, and vLLM-Omni says profiling is for development and debugging only.
Warm-up distorts results as well. PyTorch Profiler’s schedule has a warm-up phase whose samples are thrown away because they are skewed by extra overhead. DLProf warns that warm-up and tear-down iterations can badly distort aggregated results, and suggests picking a stable iteration range. In one GNN inference study, GPU warm-up took about 6.8 s, which was 86× the time to process one mini-batch in TGAT. A profile that includes GPU warm-up also captures model initialisation and memory allocation.
Profiling the Model Versus Profiling the Full Serving Path
XSP describes three levels inside model evaluation: the model level (pre-processing, prediction, post-processing), the layer level (convolution, softmax and other operators) and the GPU kernel level. A production request also passes through ingestion, transfer to an accelerator, waiting and post-processing, all of which affect latency. At the data-centre level, networking, storage and coordination software all become part of the AI application.
In the studies below, much of the time goes outside the model:
- In a study of computer vision serving, non-inference work (preprocessing, queueing, data transfer, post-processing) dominated requests for most models under 5 GFLOPs. Even above 10 GFLOPs, 16–49% of latency went to non-DNN functions.
- In the “AI Tax” face recognition pipeline, AI computation made up 55.2% of end-to-end cycles. The rest went to resizing, networking, tensor preparation and message-broker processing. Within the detection stage, only 42% of the time ran in TensorFlow, which caps the stage’s speedup at 1.74× however much faster the model gets.
- Snowflake profiled embedding inference in vLLM with a flame graph. The GPU
embed()call took 10% of compute time, and the other 90% went to CPU tokenisation and data serialisation. - UCSD’s WukLab measured vLLM v0.5.4 scheduling overhead at more than half of total inference time in some settings, mostly from building input tensors and detokenising output.
One GNN study measured GPU utilisation below 1% for two models during inference, and we cover why that reading misleads in the illusion of idle GPUs. If you want the basics of inference itself first, start with what inference in AI is and what it costs in production.
Which Profiling Tools See Which Stage
Each tool sees a different slice of the path:
- PyTorch Profiler: operator-level CPU and CUDA time and tensor memory, with a skip, wait, warm-up and active schedule for long jobs.
- NVIDIA Nsight Systems: a CPU and GPU timeline that can be limited to performance-critical regions with
cudaProfilerStart()andcudaProfilerStop()or NVTX ranges. - DLProf: a wrapper around Nsight Systems that maps kernel timings to model operations and reports GPU idle time.
- Triton perf_analyzer and Triton trace: client-side versus server-side latency, with server time split into queue and compute, per request.
- vLLM profiler backends: vLLM recommends Nsight Systems for low-overhead profiling and PyTorch Profiler for medium-overhead profiling with stack traces, memory and shapes.
Choosing between them, and reading each one’s output, has its own page: GPU profiling tools compared. Our page on APM tools for AI inference covers what they show and what they miss.
A Profiling Example: Where Triton’s Request Time Actually Went
Triton’s perf_analyzer reports per-stage breakdowns that make a good worked example. The table below reproduces three runs. The figures are server-side average request latency in microseconds, and the percentages are our arithmetic from them.
| Run | Total | Queue | Compute infer | Other stages | Where the time is |
|---|---|---|---|---|---|
| A: perf_analyzer default example | 12,005 µs | 42 µs | 11,748 µs (98%) | 215 µs | Inside the model |
| B: no dynamic batching, batch-2 requests | 17,937 µs | 15,854 µs (88%) | 2,040 µs (11%) | 41 µs | Waiting in the queue |
| C: same model, dynamic batching on | 6,231 µs | 3,758 µs (60%) | 2,396 µs (38%) | 77 µs | Still mostly queue, much less of it |
Run A is a model-bound request. Almost everything is compute infer, so changes to the serving path have little room to help. In run B, model execution takes about 2 ms and the request spends nearly 16 ms waiting for a model instance. With dynamic batching on, compute infer per request rises slightly while queue time falls by about three quarters. NVIDIA attributes the latency gain mainly to reduced queue wait.
Reading a Per-Stage Breakdown in Order
- Confirm the measurement window holds steady. perf_analyzer repeats its windows until values settle and can stabilise on a percentile instead of the mean.
- Separate client time from server time. perf_analyzer reports both, and splits client time into send/receive or (un)marshalling and response wait.
- Find the largest server stage. Is it queue, input copy, infer or output copy?
- Change the load and see which stage grows. In the vision serving study, queueing took 34–91% of latency across the optimal concurrency range.
- Only then profile down to layer or GPU kernel level, and only inside the stage that dominates.
Why the Averaged Latency Dashboard Looked Fine
Latency distributions are right-skewed. In ClickHouse’s worked example, 12 slow requests out of 1,000 lift the mean to 80 ms while the median stays at 52 ms and p99 reaches 2,400 ms. A mean in that position matches no real request, and it hides how slow the slow ones were.
Percentiles also cannot be averaged. In the same source, averaging two hosts’ p99s gives 550 ms when the true fleet p99 is 1,000 ms. The fix is to store mergeable histograms (HdrHistogram, t-digest, or Prometheus and OpenTelemetry buckets) and compute percentiles from them. Per-stage percentiles do not add up either. If three stages each meet their budget 95% of the time and their tails are independent, only about 86% of requests (0.95 × 0.95 × 0.95) meet the end-to-end budget.
Fan-out makes the tail worse. Dean and Barroso (CACM, 2013) work through a hypothetical: if each server is slow on 1% of requests and one user request touches 100 servers in parallel, 63% of user requests are slow. A comparison of vLLM and Hugging Face TGI found TGI had better p50 time-to-first-token but worse p99 total latency.
The Load Generator Can Hide the Tail Too
Many load generators send a new request only after the previous response arrives. When the server stalls, they effectively stop measuring, which is the coordinated omission effect Gil Tene describes. In his wrk2 example, a single 1.4 s pause produced a corrected 99th percentile 200× higher than the uncorrected tool reported. wrk2 avoids this by sending at a constant rate and timing each response from when the request should have been sent. If the p99 in a load test looks surprisingly calm, check how the load generator timed its requests before trusting the profile.
How Batching and Padding Waste Show up in a Profile
In runs B and C above, under-batching showed up as queue time. In a simulated LLM server described by Brenndoerfer, batch size 1 could not keep up with the offered load, requests piled up and p99 became extreme. DLProf has an expert-system detector for batch sizes too small to use the available GPU memory.
Padding shows up as hardware utilisation spent on wasted computation. With static batching, each sequence is padded to the longest one in the batch, so every request waits for the slowest one and the GPU computes on filler data. Measured figures depend on the workload:
- On the E-PUR RNN accelerator, padding caused 28.5% latency overhead on average and 30.2% of energy use.
- At 1,000 requests per second, about 26% of hardware utilisation went to wasted computation with sequence padding, against 5.2% with bucketing.
- Brenndoerfer estimates that padding can cut effective GPU utilisation by 30–70%, depending on the request-length distribution.
The sources here report padding’s latency and energy overhead, not its share of p95. PyTorch Profiler can record the shapes of operator inputs.
Attributing Cost per Request to Serving Stages
Splitting a request’s cost across stages means multiplying it by each stage’s share of the time the hardware was held, with a GPU that sits idle while the CPU tokenises still counted as paid for. Snowflake’s tokenisation bubbles are an example. OpenCost’s specification takes the same position for clusters: workload cost is the greater of requested and used resources, and idle cost is tracked separately.
This stage-level split is an estimate built from time shares, not a billing record. Snowflake reports a 16× lower cost per token on short sequences after fixing serialisation, tokenisation and GPU utilisation. The full method is in measuring inference cost per request before any optimisation, and the model-versus-serving split of spend is covered in where inference spend actually lands.
Does the Profile Say Tune the Runtime or Replace the Model?
Profile before you try to improve GPU performance: a rule like “always batch”, “move to a vendor runtime” or “use a smaller model” only makes sense in the context the profile gives you. Vendor-specific APIs are not faster in themselves. Code runs about the same either way, and the gain from a vendor’s lower-level features comes only with real engineering effort, which is not always worth it. XSP shows the same kind of case at framework level: TensorFlow and MXNet ResNets had about the same total GPU kernel latency, but MXNet’s non-GPU latency was 4.44 ms (55.1% of online latency) against 2.18 ms for TensorFlow. The difference was in non-GPU latency, outside the kernels.
| What the profile shows | What it points to | First lever to weigh |
|---|---|---|
| Queue time dominates and grows with load | Scheduling or batching configuration | Batching policy |
| CPU preprocessing, tokenisation or serialisation dominates | Work outside the model | GPU preprocessing, tokenisation and serialisation fixes |
| Large non-GPU time between kernels | Framework or scheduler overhead | Runtime choice, vectorised input preparation |
| Waiting between pipeline stages drives p99 | Broker or inter-stage congestion | Broker count and storage bandwidth |
| Compute infer dominates at the target load | The model’s own execution | Quantisation and kernel work before a model change |
In the studies above, much of the time went outside the model, where batching, quantisation, kernel work, serving configuration and runtime choice apply. When the last row of the table describes your system, the model really is the cost. The profile, not habit, makes that call. Once you have a finding, performance tuning for inference covers what each lever involves in practice.
Who Can Profile Our Inference Serving Path and Tell Us What to Fix?
TechnoLynx profiles your deployed serving path through the AI Inference Cost Audit in the Inference Cost-Cut Pack, showing where latency and cost go before anyone commits to a model replacement. The audit’s findings make up a bottleneck map: per-stage p50 and p95 latency, GPU utilisation and idle gaps, memory bandwidth saturation, and cost per request by serving stage. The audit starts by profiling the deployed serving path before any optimisation work.
The engagement suits teams that already have a model in production and a cost or latency problem they cannot yet locate.
FAQ
What Is the Difference Between Profiling and Benchmarking?
Benchmarking measures the throughput and latency a deployment produces under load, for sizing and cost estimates. Profiling identifies the bottlenecks behind that time by making long-running code obvious.
What Is the Difference Between Profiling and Tracing?
Tracing records timed spans for individual operations or requests and joins them into one timeline. Profiling identifies bottlenecks by making long-running code obvious, and tools like XSP turn several profilers’ output into spans on one timeline.