Batching, decoding and serving caches 00:00:01 A short request overtakes a long one One order at the café needs three decoding steps. The next needs one. Instead of making the small order occupy a seat for three steps, Nia can retire it as soon as its token sequence is complete. Serving combines admission control, prefill, autoregressive decoding and memory management. Continuous batching lets active requests share compute as their lengths diverge. Prefix reuse and speculative decoding can save different kinds of work under different conditions. On the first shared decode tick both requests advance. On the next tick the short request has released its slot while the long one continues. The requests keep separate histories even when their kernels run together. 00:00:45 Follow the scheduler for three steps The scheduler can admit and retire requests at different times. Prefill builds a prefix cache while decode extends each active sequence. B completes after one step. Continuous batching can reuse the freed capacity for a waiting request rather than waiting for A. Paged allocation reduces some fragmentation. A future request benefits from prefix caching only when its prefix is eligible and compatible. 00:01:14 Measure a person's wait Speculative decoding has a smaller draft model propose several tokens and a target model verify them. With the proper acceptance and correction rule, sampling preserves the target distribution. Speed depends on acceptance rate, verification cost and workload. When drafts diverge, extra model calls can outweigh saved serial steps. A draft model proposes four tokens and the verifier accepts the first two. The remaining draft suffix cannot simply be emitted unchanged. Ollama packages local model serving behind a convenient interface. Check the exact model tag, quantization and available memory. Local data handling can simplify some workflows, but the machine still needs authorization, resource limits and a policy for logs if multiple people use the service. Load a pinned model tag locally. Run two concurrent long prompts and record peak memory as well as the single-request latency. Prefix caching reuses computation for an identical eligible prefix. Put stable instructions before request-specific fields when the provider supports it. A changed token early in the prefix can reduce reuse. Keep cache identity isolated across incompatible model versions, tenants and sensitive contexts. Two requests share 900 leading tokens and differ afterward. Prefix reuse may save work on the compatible prefix while their distinct suffixes still run. Record the distribution of input lengths, output lengths and arrival bursts. A benchmark of a single short prompt may hide queueing, expensive prefills and memory contention that dominate a real service. 00:02:58 What does a larger batch buy? Would increasing batch size guarantee lower latency for every user? High throughput can coexist with long waits or slower individual decode steps. Measure latency separately from aggregate capacity. Tokens per second measures the café's output. Queue time, first-token latency and inter-token delay describe a customer's experience. Nia times each one before changing the batch policy.