Batch and Online Inference

Batch and online inference are different operational modes for using a trained model. They often use the same model weights but optimize for different constraints.

Batch inference processes a dataset:

Online inference processes requests as they arrive:

Mode Contract

FieldBatch inferenceOnline inference
unitdataset row, file, molecule, document, shardrequest
objectivethroughput, reproducibility, costlatency, availability, UX
failure handlingretry item or shardtimeout, fallback, clear error
orderingoften reorderablerequest order may matter
loggingartifact manifest and run idrequest log with privacy boundary
versioningmodel + data + output versionmodel + endpoint + client contract

The same model can be correct in batch mode and unsuitable online if preprocessing, latency, memory, or error handling differs.

Batch Inference

Batch mode is optimized for throughput, cost, and reproducibility. It is common for dataset scoring, embedding generation, virtual screening, offline evaluation, and paper-processing pipelines.

Key questions:

  • Can examples be reordered?
  • Can failed items be retried independently?
  • Is output versioning tied to model and data version?
  • Is the bottleneck GPU compute, CPU preprocessing, storage IO, or network transfer?

Online Inference

Online mode is optimized for latency, reliability, and request contract. It is common for APIs, interactive tools, agent loops, dashboards, and user-facing applications.

Key questions:

  • What are latency and timeout targets?
  • Can requests be batched without changing behavior?
  • How are invalid inputs rejected?
  • What is logged, redacted, or never stored?

Tradeoff

Throughput is roughly:

Latency is per request:

Optimizing one can hurt the other.

Dynamic Batching

Online systems often batch requests briefly to improve GPU utilization:

This improves throughput when model execution benefits from batching, but increases waiting time by up to the batching window .

ChoiceEffect
larger batchbetter hardware utilization, higher latency
shorter timeoutbetter latency, more partial batches
queue priorityprotects interactive users or small requests
max sequence lengthcontrols memory and tail latency

Reproducibility Boundary

Batch inference can usually produce a manifest:

Online inference is harder to reproduce because requests arrive from a live distribution and logs may be redacted. Public notes should distinguish same model from same operational behavior.

Checks

  • Can failed batch items be retried without duplicating successful outputs?
  • Is online timeout behavior documented?
  • Does batching change numerical results or output ordering?
  • Are batch outputs tied to input/model/preprocessing versions?
  • Are request logs privacy-safe and sufficient for debugging?