batch inference
Batch inference processes multiple input samples together in a single forward pass through a model, exploiting GPU parallel processing capabilities to achieve significantly higher throughput than processing inputs individually. While real-time interactive applications require single-input inference with low latency, many production workloads — document processing, overnight analysis, recommendation generation, embedding computation, content moderation at scale — can collect inputs and process them in batches for dramatically better efficiency. The performance advantage of batching comes from GPU architecture: GPUs contain thousands of parallel processing cores designed for simultaneous computation on large tensors. Single-input inference underutilizes these cores — the GPU spends most of its time on memory access and kernel launch overhead rather than computation. Batching amortizes this overhead across multiple inputs, increasing arithmetic intensity (the ratio of computation to memory operations) and achieving much higher GPU utilization. Batch size affects performance in a non-linear way: increasing from batch_size=1 to batch_size=8 might provide 6× throughput improvement (nearly linear), but increasing from 32 to 64 might only provide 1.3× improvement as the GPU approaches full utilization. Optimal batch size depends on: model size (larger models fill GPU memory with fewer batch elements), sequence length (longer sequences consume more memory per element), GPU memory capacity (batch must fit in VRAM alongside model weights and KV-cache), and latency requirements (larger batches increase per-request latency despite higher throughput). Advanced batching strategies include: dynamic batching (accumulating requests over a time window and processing together — used by Triton Inference Server and other serving frameworks), continuous batching (for autoregressive models — inserting new requests into running batches as existing requests complete — maximizing GPU utilization), bucketed batching (grouping inputs of similar length to minimize padding waste), and priority batching (processing high-priority requests with smaller batches for lower latency while processing bulk workloads with larger batches).