AlgoViz

From a local checkpoint to a serving endpoint

medium 6 min

A local process proves one prompt can run.

Video lesson · Chapter 1 of 4

A tutor leaves the laptop

0:00 / 3:30

Theory

Read or listen first. About 2 min.

What it is

A local process proves one prompt can run. A shared service must load the same immutable artifacts on each replica, bound concurrency, report readiness after the model is usable, and cancel abandoned work. The client contract includes streaming behavior, supported fields and error handling. Compatible HTTP shapes can conceal different tokenizers, defaults and feature support.

Why it exists

Separate the artifact store, serving process and application gateway. Keep model loading off the user request path when a warm service is required. A production runtime such as vLLM can batch active requests on supported hardware; llama.cpp offers a portable local server. Evaluate a representative distribution of input and output lengths. A healthy endpoint can still have unacceptable queueing or incoherent output.

Promote a local tutor to a small shared service

Release manifest → Warm replica (pinned release). Warm replica → Request scheduler (ready capacity). Client gateway → Request scheduler (bounded request). Request scheduler → Client gateway (stream and outcome)
Release manifest → Warm replica (pinned release). Warm replica → Request scheduler (ready capacity). Client gateway → Request scheduler (bounded request). Request scheduler → Client gateway (stream and outcome)

Inside this chapter

Chapter sources
Artifact registry and warmup
Pin revision, tensor precision, tokenizer, chat template, engine build and relevant hardware settings together. Load weights and run a representative warmup before marking a replica ready. A process listening on a port may still be initializing.

A replica is a pinned bundle: weights digest, precision, tokenizer, chat template, engine version and device settings. Reproduce any one differently and you may get different output. Loading a multi-gigabyte model takes time, and the first requests often trigger one-off work such as kernel compilation or memory allocation, so readiness should mean a real prompt has succeeded, not that a port is open.

Example. A deployment that starts receiving traffic while loading a multi-gigabyte artifact can violate every first-token deadline during scale-out.

Another example. During a traffic spike, an autoscaler adds two replicas that report healthy as soon as the HTTP server starts. Requests routed to them wait while weights load, and first-token latency jumps for everyone on those replicas.

A replica's lifecycle

Traffic is routed only in Ready. Listening on a port happens much earlier.
Concurrency and capacity
Weight memory is largely shared across requests, while cached sequence state and some workspace grow with active tokens. Budget aggregate concurrent context, cap output and test short and long requests together.

Weights are loaded once per replica and shared by every request. The KV cache is per sequence and grows by one entry per layer for every token processed, so capacity is really a budget of active tokens. One long document can consume as much as many short chats. Set output caps, limit total reserved tokens, and test with a realistic mix of short and long requests together.

Example. Four active chats at 2,000 cached positions each consume roughly four times the KV state of one such chat with the same model and cache dtype.

Shared weights, per-request cache

Active chatsCached positions eachTotal cached positionsKV stateWeight memory
12,0002,0001xsame
42,0008,000about 4xsame
45002,000about 1xsame
Same model and cache precision. Capacity is set by total active tokens, not by request count.
Runtime selection and production boundaries
Use an engine that implements the architecture and quantization with kernels for the chosen device. Put authentication, quotas and access logs at the service boundary, isolate model workers and avoid shipping the checkpoint inside an ordinary web application bundle.

Splitting gateway from workers keeps concerns apart. The gateway handles identity, rate limits and logging, and can be scaled and patched like any web service. Workers need GPUs and a specific engine and are restarted carefully. The engine must support the model's architecture and quantisation format on the target device; a laptop GGUF does not automatically run on a GPU serving engine.

Example. A CPU laptop accepts the local GGUF. For a GPU service, verify the engine supports the intended checkpoint format rather than changing only the base URL.

Another example. A team moves its tutor from a laptop to a GPU server and only changes the base URL. The new engine cannot load the GGUF file, so they convert to a format it supports and re-run the quality fixture.

Where each responsibility lives

Weights live in the artifact store and workers, never inside the web app bundle.
Cancellation and abandoned work
When a user closes a tab or a client times out, the server should stop generating for that request and free its cache. Otherwise abandoned generations keep consuming capacity that live users are waiting for.

Cancellation has to cross every hop: the client disconnects, the gateway notices, and the engine actually aborts the sequence and releases its memory. Test it by starting long generations, disconnecting, and checking that active-token metrics fall promptly.

Example. A user pastes a long contract, waits five seconds and leaves. Without cancellation the worker keeps decoding a 1,000-token summary nobody will read.

Propagating a disconnect

The gateway must notice the disconnect and pass it on; the worker must act on it.
Compatible API, different behaviour
Many engines offer an OpenAI-compatible HTTP interface, but matching request shapes does not mean matching behaviour. Default sampling settings, supported fields, chat templates, tokenizers and error formats can all differ.

Treat a switch between compatible endpoints as a model change: rerun the frozen fixture, compare finish reasons and token usage, and check that every optional field you rely on is honoured rather than ignored.

Example. Pointing a client at a new engine with the same base path works, but an unsupported response_format field is silently ignored and JSON output breaks.

Same on the surface

  • Endpoint paths and JSON shapes
  • Message roles
  • Streaming format

Can differ underneath

  • Default temperature and token caps
  • Which optional fields are honoured
  • Tokenizer, template and usage counting

How it works

Step through the idea, or press Play.

Step 1 of 4

Release manifest. Pin weights and serialization

Understand it

Worked example

Promote a local tutor to a small shared service

  1. 1

    Pin weights and serialization

    The serving release records the checkpoint digest, engine and template needed to reproduce the local test.

  2. 2

    Load and test a known prompt

    The replica becomes ready only when it can generate a bounded completion with the expected shape.

  3. 3

    Admit work within capacity

    Queue requests when token or memory reservations are exhausted. Cancel abandoned generations and release their allocations.

  4. 4

    Evaluate task-level outcomes

    Measure time to first token, completion latency, cost and accuracy by workload before routing more users.

Follow the handoffs

Separate the artifact store, serving process and application gateway. Keep model loading off the user request path when a warm service is required. A production runtime such as vLLM can batch active requests on supported hardware; llama.cpp offers a portable local server. Evaluate a representative distribution of input and output lengths. A healthy endpoint can still have unacceptable queueing or incoherent output.

Admission at the request scheduler

Queue delay belongs in the latency you report, not hidden behind a healthy check.

What to measure per workload before adding servers

WorkloadTime to first tokenQueue delayCompletion latencyAccuracy
Short chatstrack p50 and p95tracktracktask fixture
Long documentstrack p50 and p95tracktracktask fixture
Both mixedshort chats behind long prefill?tracktracktask fixture
Health checks pass in every row; these numbers show whether users are being served well.

Summary

The whole topic in one minute.

A connection count does not reveal how much prefill, decode time or KV state each request consumes.

Separate the artifact store, serving process and application gateway. Keep model loading off the user request path when a warm service is required. A production runtime such as vLLM can batch active requests on supported hardware; llama.cpp offers a portable local server. Evaluate a representative distribution of input and output lengths. A healthy endpoint can still have unacceptable queueing or incoherent output.

Sources