Inference Serving

Inference serving turns a trained model into a low-latency, high-throughput service. For LLMs the dominant costs are KV-cache memory and the prefill/decode split; batching and quantization are the main levers.

Serving should start from a capacity plan:

Serving Object

A served model is not only a checkpoint. It is the checkpoint plus the input contract, preprocessing, batching policy, runtime, and failure behavior.

If any element changes, latency, quality, and validity can change even when the model name stays the same.

Request Shape

Capacity planning starts with the request distribution, not the average prompt.

FieldWhy
input lengthcontrols prefill and memory
output lengthcontrols decode time and KV cache growth
concurrencycontrols queueing and memory pressure
payload sizecontrols network and preprocessing
valid input rangecontrols rejection and fallback behavior
response modesynchronous, async, streaming, or batch

For decoder-style generation:

Throughput claims should state whether they count requests/sec, samples/sec, tokens/sec, or jobs/day.

Memory Budget

For autoregressive serving, request concurrency is often constrained by weights plus request-specific cache:

where may include KV cache, activations, buffers, tokenizer state, and framework overhead.

The KV-cache term grows with layer count, heads, context length, and dtype:

This is why context length and concurrency must be part of the serving contract.

Batching Modes

ModeUse ForRisk
no batchinglowest complexity, debugging, low trafficpoor GPU utilization
static batchingoffline or fixed-shape workloadsidle time and padding waste
dynamic batchingonline serving with variable arrivaltail latency and queue tuning
continuous batchingautoregressive servingscheduler complexity and memory pressure
offline batchlarge backfills or evaluationnot representative of online latency

Quality Boundary

Serving optimizations can change the model’s behavior. Treat them as system changes, not only performance changes.

OptimizationCheck
quantizationcalibration, task metric, failure examples
truncationlost context and unsupported input handling
cachingstale data, privacy boundary, cache invalidation
batchingorder dependence, timeout, tail latency
fallback modeloutput compatibility and evaluation boundary

Practical Checks

  • Distinguish latency-bound (single request) from throughput-bound (batched) goals.
  • Use continuous/dynamic batching to keep the GPU busy without hurting tail latency.
  • Size the KV cache against context length and concurrency.
  • Apply quantization (int8/fp8) only after measuring accuracy impact.
  • Measure p50/p95/p99 latency, not just averages.
  • Use Inference capacity planning before choosing hardware or batching policy.

Public Serving Note Checklist

ItemInclude
model identitypublic model name or generic model class
input contractschema, limits, invalid input handling
output contractschema, confidence, error format
workload shapecontext length, batch/concurrency, request rate
capacity targetlatency, throughput, memory, cost
quality gatemetric or manual evaluation affected by serving changes
observabilitypublic-safe aggregate metrics, not raw private input

Boundary

Keep this note about serving behavior and capacity. Put GPU memory diagnosis in GPU, endpoint rollout in Deployment strategy, and public user-facing validity in Inference contract or Model card.