YOLO Inference on GPU: How It Works and What Batching Really Changes

How YOLO inference uses the GPU and what batch size changes: throughput rises until saturation, latency grows, and real-time and offline jobs batch…

YOLO Inference on GPU: How It Works and What Batching Really Changes
Written by TechnoLynx Published on 11 Jul 2026

Batching changes how much of the GPU each YOLO inference call uses. Until the GPU saturates, a bigger batch raises throughput and cuts the time spent per image. After that point throughput levels off, while the latency of each call keeps rising roughly in step with batch size. Where saturation happens depends on the hardware. In the DEEP-GAP benchmark (2026) of ResNet models, an NVIDIA L4 reached peak throughput at batch 16 to 32, but a T4 needed batch 256 or more. For offline and bulk YOLO inference, larger batches shorten total inference time. A real-time pipeline should stay at small batches, or batch only up to a fixed latency ceiling.

The rest of this article covers how one inference call actually runs, why small batches waste so little and so much at the same time, why detections can shift when the batch size changes, and how to pick a batch size for each kind of workload.

What one YOLO inference call does on the GPU

Every Ultralytics YOLO model, from YOLOv3 to YOLO26, has three stages. A backbone extracts features at strides 8, 16 and 32. A neck fuses those features across scales with FPN and PAN. A head predicts bounding boxes and class scores. Each inference fans out into a sequence of CUDA kernels. Each kernel has to be launched by the CPU. If you want the module-level detail, our walkthrough of how object detection with a YOLO model works covers the architecture. This article stays on execution.

The forward pass is only part of the cost of a detection. The images have to be decoded, letterboxed and normalised before the pass. After it comes post-processing such as non-maximum suppression (NMS). YOLO26 removes the NMS step by handling duplicate suppression inside the network. On an A100, YOLO26 had the lowest post-processing time but the highest end-to-end latency, because its residual overhead (preprocessing, data loading, tensor allocation, GPU-to-CPU copies) was the highest.

How batch size changes YOLO inference latency and throughput

DEEP-GAP’s sweep of ResNet-18, -50 and -101 on T4 and L4 GPUs found that throughput “increases rapidly as batch size grows from 1 to 32” and then plateaus as compute, memory bandwidth or kernel efficiency saturates. Across the same sweep, latency rose approximately linearly with batch size. A queueing study of GPU inference servers (2019) measured batch processing times with the MLPerf MultiStream scenario and found the same linear growth with batch size.

Here is the trade in plain terms. Batching cuts the time spent per image, but every image also waits for the whole batch to finish. Throughput is a property of the batch, and latency is felt by every image inside it.

What the YOLO-specific numbers show

YOLOv6 v3.0 (2023) reports throughput for YOLO-family detectors at batch 1 and batch 32 on a Tesla T4 with TensorRT 8.2 in FP16. Because the hardware and software are the same for every model, the table shows how much batching helps each model size:

Model (T4, FP16, TensorRT 8.2) FPS at batch 1 FPS at batch 32 Gain from batching
YOLOX-Tiny 766 1393 about 1.8×
YOLOv6-N 785 1215 about 1.55×
YOLOv5-N 702 843 about 1.2×
YOLOv5-L 126 137 about 1.09×
YOLOv7 128 135 about 1.05×

The FPS figures come from YOLOv6 v3.0, Table 9. The gain column is simple division (for example, 1215 / 785 ≈ 1.55).

Small models gain the most and large models barely gain at all.

A case study of a video analytics pipeline on a T4 shows per-frame inference time falling as the batch grows up to 16. Beyond batch 16, inference time went up again because of memory pressure and diminishing returns. The same study found that at batch 8, inference fell below 5 ms per frame, but pre- and post-processing together still took more than 15 ms per frame. The model-side win was real, but pre- and post-processing still took longer than inference.

Why small batches leave the GPU idle

At small batch sizes, latency is set by CPU-side framework overhead, not the arithmetic. PyTorch’s CUDA Graphs write-up explains that CPU cores process metadata such as tensor shapes to prepare each kernel launch. That cost is fixed, while GPU work grows with batch size, so at small batches the CPU overhead can exceed GPU run time and the GPU sits idle between kernels. The “Framework Tax” study (2023) describes this regime as framework-bound. In that regime latency stays constant regardless of batch size, until the compute kernels saturate and outweigh the CPU launch costs. The same study found minimal latency difference across models, runtimes and frameworks once batch sizes go above 16.

This explains why small batches seem nearly free. NVIDIA’s TensorRT documentation gives the matching diagnosis. When enqueue time exceeds GPU compute time, the workload is enqueue-bound, and increasing the batch size gives each kernel more work. CUDA Graphs attack the same launch overhead from the other side. They capture the kernel sequence once and replay it with a single CPU operation, which removes Python, C++ and driver dispatch costs. This only works when tensor shapes are static. One consequence follows: faster GPUs stay framework-bound up to larger batch sizes, because the fixed CPU overhead stays the same while the kernels get shorter.

Why do YOLO detections change slightly when the batch size changes?

Detections can shift slightly when only the batch size changes, because the GPU may compute the same image with different algorithms or a different reduction order. We cover three mechanisms below.

First, algorithm selection. PyTorch’s reproducibility notes explain that when a cuDNN convolution is called with a new set of size parameters, an optional benchmarking feature tries several convolution algorithms and keeps the fastest one for that set of sizes. Batch size is one of those size parameters, so batch 1 and batch 16 can end up on different algorithms, and different algorithms do not round identically. TensorRT does something similar when it builds an engine. It times candidate tactics and picks the fastest, and it can choose differently across builds when tactics have similar latencies. NVIDIA also notes that floating clocks or throttling during tuning make tactic selection less deterministic.

Second, reduction order. Thinking Machines Lab’s analysis of LLM inference shows that a kernel may split a reduction across cores at small batches to keep the GPU busy, and that this loses batch invariance because elements are no longer reduced in the same order. Their requirement for batch-invariant results is a reduction order per element that is fixed regardless of batch size. That work studies LLM inference kernels, not convolutional detectors. We think the mechanism carries over to any kernel whose parallelisation strategy depends on batch size, but we have no published YOLO measurement of how large the box differences are.

Third, input shape. Ultralytics’ rectangular letterbox mode (auto=True) produces variable-size inputs such as 384×640, while batched serving paths need homogeneous shapes. If one image is letterboxed to a variable shape in one run and to a fixed batch shape in another, the network sees different inputs.

If you need identical outputs across batch sizes (regression tests, audited inspection, golden-file comparisons), there are several things to do. Fix the input shape, as fixed-size pipelines do. Disable cuDNN benchmarking with torch.backends.cudnn.benchmark = False. Set torch.use_deterministic_algorithms(True) or torch.backends.cudnn.deterministic = True, because the algorithm cuDNN selects can itself be nondeterministic without those flags. Even with all of this, PyTorch does not guarantee reproducibility across releases, platforms, or CPU versus GPU execution. A sensible acceptance test therefore compares detections within a tolerance, not bit for bit.

When should a real-time video pipeline avoid batching frames?

For minimum latency, a live pipeline should not batch frames from a single camera. Each frame added to the batch adds one frame interval of waiting on top of inference. At 30 FPS, which an aquaculture benchmark (2026) cites as the widely referenced minimum for real-time video, frames arrive every 33.3 ms. A batch of 8 frames from one camera makes the first frame wait for seven more before inference starts: 7 × 33.3 ms ≈ 233 ms of extra delay before any GPU work happens. Triton’s optimisation guide states the minimum-latency setting directly: request concurrency 1, dynamic batcher disabled, one model instance.

Batching across cameras is different, because the batch fills from several streams instead of future frames. NVIDIA DeepStream’s Gst-nvstreammux forms a batch from multiple sources and pushes it downstream either when the batch is full or when batched-push-timeout expires. The timer starts with the first buffer collected, and the documentation’s example sets 40000 µs (40 ms). That timeout caps how long the first frame waits for the batch to fill. If it is set longer than your end-to-end deadline allows, the batch fills nicely and misses the deadline. For a request-based setup, Triton’s documentation reports an example in which the dynamic batcher raised throughput from about 73 to 272 inferences per second at eight concurrent requests, with no increase in latency compared with running without it. Designing the camera side for this is a topic in itself, which our piece on observable CV pipelines for CCTV covers from the architecture angle.

The Ultralytics multi-stream course gives 5 to 20 ms on the CPU to decode a 1080p frame, about 1 ms to preprocess it, and a few milliseconds for GPU inference. Running these stages one after another in a single thread leaves the accelerator idle while frames decode. Separating the stages is the fix. Ultralytics’ DALI guide adds that CPU preprocessing (resize, pad, normalise) can take 2 to 10 ms per image, which can exceed a TensorRT forward pass of a few milliseconds.

Overload behaviour also matters. In Ultralytics predict mode, stream_buffer=False drops old frames so a slow model keeps up with live input, and stream_buffer=True queues every frame at the cost of growing latency. For live cameras the course recommends the first setting, plus a bounded queue with a drop counter, because an unbounded queue makes latency grow every minute until memory runs out. To estimate capacity, divide sustained throughput at your batch size by the FPS each stream needs, measured on the real hardware with the optimised export, and keep 20 to 30% headroom for peaks. If the detector feeds a tracker, see our article on multiple object tracking in production.

If small-batch latency is too high, cut the framework overhead instead of batching harder. Use a compiled runtime such as TensorRT or ONNX Runtime, plus CUDA Graphs where shapes are static. The Framework Tax study recommends static or ahead-of-time runtimes when batch sizes are small. For batch 1 it measured average FP16 speedups over eager PyTorch of 34.16% for TorchScript and 71.38% for ONNX Runtime.

Choosing a batch size for large-scale offline YOLO inference

For an offline job over millions of images, per-image latency does not matter directly. The goal is the shortest total time per dataset, which TensorRT’s documentation describes as what throughput determines for bulk workloads. Choose the batch size from sustained end-to-end images per second measured on the target GPU, because the best size can only be found by measuring. A latency and throughput study of CNNs (2018) found on Android and Jetson devices that adding one image to a batch sometimes improved throughput at almost no latency cost and sometimes made both worse, and that the optimal size “is difficult to estimate without actual measurements”. TensorRT’s documentation adds that on Ada Lovelace and later GPUs, a smaller batch can raise throughput if it lets inputs and outputs fit in L2 cache, so several sizes should be tried.

A batch-size sweep you can trust

  1. Export with headroom. An Ultralytics TensorRT export sets a maximum batch size. With dynamic=True, smaller batches are accepted but larger ones are not, so export at the largest size you intend to test.
  2. Check memory headroom. Ultralytics’ autobatch profiles candidate batch sizes, fits a line to memory use and targets 60% of available CUDA memory by default. It is designed for training batch sizes, not inference.
  3. Sweep a wide range of batch sizes. DEEP-GAP swept 1 to 512 and reported median latency, P99 latency, throughput and GPU memory for each point.
  4. Warm up, then time steady state. DEEP-GAP ran 20 warm-up iterations and then 100 timed iterations, repeating each configuration three times. The first call after a shape or profile change in TensorRT is slower than later calls, so warm-up should happen at each batch size.
  5. Time end to end and model-only separately. If observed throughput is well below the reciprocal of GPU compute time, the GPU can be underutilised because of host-side overhead or data transfers.
  6. Run long enough to throttle. Power throttling happens by design on lower-power GPUs such as the T4 and A2, and a GPU that is fully loaded with no gaps runs at a lower clock than a short benchmark suggests. The 2019 queueing study saw T4 latency drift away from its model under heavy load for exactly this reason: the 70 W power cap pulls the clock down.
  7. Pick the knee, not the peak. Throughput gains shrink past saturation while memory pressure grows. In the video analytics case study, per-frame time got worse beyond batch 16. We would choose the smallest batch within a few per cent of peak throughput, because it leaves memory for preprocessing on the GPU and is less sensitive to throttling.

Batch size adds less memory than model size and precision do. DEEP-GAP found that GPU memory was dominated by model weights and runtime allocations, with activation memory growing only incrementally as batch size increased. It also found that INT8 reduced the footprint by about 2 to 3× compared with FP32.

Where offline gains stall

Batching alone does not fix a pipeline whose GPU waits on input. Ultralytics’ predict mode only applies the batch argument when the source is a directory, a video file or a .txt list. If you pass preprocessed torch.Tensor batches in BCHW format, the preprocessing step drops to about 0.004 ms, compared with about 1 to 10 ms on the CPU. Adding parallel workers helps up to a point and then stops. In the video analytics case study, going from one to four processes raised GPU utilisation from about 20% to over 50% and cut detection time by 47%, with little gain beyond four. Combining batching with multiprocessing caused memory contention: batched inference took a stage from 36 to 23 seconds, and adding multiprocessing made it 25. The authors’ conclusion is that higher throughput takes scheduling, memory sharing and data transfer work, not just more workers or bigger batches.

Batch or not: a decision table for YOLO workloads

Workload Batch? What limits the choice First thing to check
Single live camera, tight deadline No, for minimum latency Batching increases latency Enqueue time vs GPU compute time; consider CUDA Graphs
Several live cameras on one GPU Yes, across streams, with a timeout Batch-fill timeout must fit the latency budget batched-push-timeout and dropped-frame count
Request-based detection service Dynamic batching Throughput under a fixed latency ceiling Throughput at your maximum acceptable latency
Offline dataset, millions of images Yes, at the measured best size Throughput saturation, preprocessing End-to-end vs model-only throughput
High-resolution images sliced into tiles Usually yes Tiles of one image are a ready-made batch Tile count per image vs exported max batch

The last row is relevant to SAHI-style slicing inference for small objects.

The batch size belongs to the deployment

The YOLOv6 numbers show batching has little value for a large model and a lot for a nano model on the same T4. DEEP-GAP’s ResNet numbers show the saturation point moving from batch 16–32 on an L4 to batch 256 or more on a T4. A batch size tuned on one GPU therefore has to be re-measured on the production GPU. The same aquaculture benchmark found that inference speed rankings measured on an A100 did not carry over to a Raspberry Pi 5. Triton’s documentation reaches the same conclusion for serving: the benefits of dynamic batching and multiple instances are model-specific and should be found with perf_analyzer, not assumed.

That changes which question you should be asking. Do not start with “what batch size should YOLO use?” Start with “what deadline does each image have, and what does the GPU in this deployment do at the batch sizes that fit inside it?” Our article on YOLO inference for industrial CV inspection works through the inspection-line setting, and building the right pipeline around a YOLO-family detector covers the stages around the model.

Back See Blogs
arrow icon