Skip to content

Smart Inference Server (v0.30.0)

soup serve graduated from a basic OpenAI-compatible wrapper into a production-grade serving stack. Speculative decoding, prefix caching, structured output, dynamic LoRA hot-swap, a /metrics endpoint, and OpenTelemetry tracing all ship in v0.30.0. (The --dashboard flag that came with /metrics draws nothing at v0.78.0; see below.)

Speculative decoding

Use a smaller draft model to propose tokens the target verifies in one pass. Whether it is faster depends entirely on the pair: soup draft measure (v0.71.33) is how you find out before you enable it.

bash
# Transformers backend — uses HF assisted generation
soup serve --model ./output --speculative-decoding small-draft-model --num-speculative-tokens 5

# vLLM backend — uses vLLM native speculative decoding
soup serve --model ./output --backend vllm --speculative-decoding small-draft-model

# Auto-pair: Soup picks the draft from the base model recorded in the adapter
soup serve --model ./output --backend vllm --auto-spec

With the default --hub hf, soup serve --model takes a local directory, not a Hub id; a path that does not exist exits 1 with "Model path not found". With --hub modelscope or --hub modelers, a --base repo id that is not a local path is fetched first, and otherwise a --model repo id is. --auto-spec looks the draft up from the base model recorded in the adapter's adapter_config.json (or from --base), so the base has to be one of the large families in its pairing table: Llama 3.1 / 3.3 / 4, Qwen 2.5 / 3, Mistral Large, Mixtral, DeepSeek V3 / R1, and Gemma 2 / 3 at their large sizes. Anything without a known draft pairing prints a yellow "no draft" note and falls back to standard decoding. A draft you trained yourself with soup draft distill is picked up before this built-in table, when the names match exactly (see the local draft registry: an absolute path, or on Windows a --model path with a directory in it, never matches).

Before you enable any of this, measure it. soup draft measure (v0.71.33) reports the draft's real acceptance rate and plain-vs-assisted throughput on your own pair. On the pair we validated, assisted decoding came out at 0.55 to 0.64x, a net slowdown, and upstream's documentation cites a larger pair (a Llama-3.1-8B target, a Llama-3.2-1B draft, one H100) where 81.3% acceptance still ran at 0.48x of plain decoding. Treat a speedup as something to verify rather than assume.

Prefix caching (vLLM)

For RAG and agent workloads with a shared system prompt:

bash
soup serve --model ./output --backend vllm --prefix-cache

The first request with a given prefix warms the cache; subsequent requests skip the shared prefix compute entirely.

Structured output

Constrain output to a JSON schema or regex pattern.

bash
# JSON schema (file must live under cwd)
soup serve --model ./output --structured-output json --json-schema product.json

# Regex (length-capped at 2048 chars, null bytes rejected)
soup serve --model ./output --structured-output regex --regex-pattern '\d{3}-\d{4}'

Schemas serialised over 64 KB are rejected. JSON schemas must declare a top-level type field. Constraints are validated at startup, not per-request. This applies on the transformers backend only. With --backend vllm or sglang the mode is still checked at startup (an unknown mode, or json without --json-schema or regex without --regex-pattern, exits 1) and then not applied; with --backend mii the flags are accepted and nothing reads them. On all three, replies are not constrained.

On the transformers backend the constraint applies to streamed (stream: true) requests since v0.76.0 (#1607); through v0.75.2 a streamed request ignored it. Since v0.78.0 a streamed reply from that backend is sent while the model generates, except with a draft model (--speculative-decoding) or n-gram lookup, with --reasoning-parser or MoLE routing, or on a model whose generation config sets beam search or several return sequences, which are generated in full and then sent. The constraint is applied token by token, because it is a logits processor, so it shapes a streamed reply as it is produced. (Since closed in v0.78.0: through v0.77.2 a streamed reply was generated in full and then sent word by word, so the constraint shaped the whole reply before the first chunk left.) See Inference Server.

Dynamic LoRA hot-swap

Switch the active adapter at runtime without restarting the server.

bash
soup serve --model ./base-model --adapters chat=./chat-adapter --adapters code=./code-adapter
bash
curl -X POST http://localhost:8000/v1/adapters/activate/chat
# → {"active": "chat", "status": "ok"}

curl -X POST http://localhost:8000/v1/adapters/deactivate
# → {"active": null, "status": "ok"}

curl http://localhost:8000/v1/adapters
# → {"adapters": [{"name": "chat", "active": true}, ...], "active": "chat"}

Names match ^[a-zA-Z0-9][a-zA-Z0-9-]*$. Activate/deactivate is thread-safe behind a lock, and since v0.75.1 both also check the Host and Origin headers, answering 421 or 403 rather than acting. Until then a cross-site request from any page the operator merely visited could switch the adapter every subsequent completion ran against (0.30.0 to 0.75.0). The same release put the tool token in front of GET /v1/adapters, activate and deactivate, with the check running before the 404 branches so an unauthenticated probe cannot learn which adapter names are loaded from an "unknown adapter" reply. See which routes get which check. Since v0.78.0 a server started with --adapter-dir can also load an adapter from that directory while it runs, with POST /v1/adapters/load, which needs the token on every bind (see Loading adapters at runtime).

A single request can also name its own adapter with an adapter field in the JSON body, which uses that adapter for that call without changing the active one. The model field is ignored for this, so "model": "chat" does not select anything. See Multi-Adapter Serving.

/metrics (and the --dashboard flag)

bash
soup serve --model ./output --dashboard
bash
curl http://localhost:8000/metrics
# {
#   "requests_total": 1234,
#   "tokens_generated_total": 456789,
#   "active_requests": 3,
#   "latency_p50_ms": 185.2,
#   "latency_p95_ms": 720.0,
#   "latency_samples": 1000
# }

Latency percentiles are computed from the last 1000 requests; counters include failure paths so the figures reflect true reliability. The transformers and vLLM backends serve /metrics whether or not --dashboard is passed. The flag only records intent: nothing is drawn in the terminal, whatever its --help text says; the SGLang and DeepSpeed-MII backends do not serve it at all, and --dashboard there prints a warning instead of collecting anything.

OpenTelemetry tracing

Emit per-request spans to your OTLP collector.

bash
pip install opentelemetry-sdk opentelemetry-exporter-otlp

soup serve --model ./output \
  --trace --trace-endpoint http://localhost:4317

OTLP endpoint hardening: scheme allowlist, plain HTTP only for loopback, and a private, link-local, shared-space (100.64.0.0/10), deprecated site-local (fec0::/10) or 0.0.0.0 IP address rejected on either scheme, which is stricter than HF_ENDPOINT, where the address is checked only over plain HTTP. A host written only as numbers that is not a valid IPv4 address (for example 4294967296) is rejected as well, since it is neither an address nor a hostname. Hostnames are not resolved. Missing SDK is a no-op with a warning. Tracing is set up on the transformers backend only: with --backend vllm or sglang, a --trace-endpoint given with --trace is still checked at startup and no span is emitted; with --backend mii, --trace is accepted and nothing reads it.

A local trace file, with no collector

If you do not want to stand up a collector to answer "what did it actually reply, and how slowly":

bash
soup serve --model ./output --trace-log ./traces.jsonl --trace-log-cap-mb 100

One version-1 conversation record is appended per logged answer, on /v1/chat/completions and /v1/messages (an answer to a request whose message roles the schema cannot describe, an empty messages list or an empty model name is not logged, and neither is the loop's own check request): schema_version, id (the answer's response_id), conversation_id, ts (an ISO 8601 UTC string), model, adapter, canary_bucket, messages (the conversation without the answer), response, prompt (the last user message), finish_reason, latency_ms, tokens (an object with prompt and completion), version (always null from soup serve) and source; the schema's optional options is not written by soup serve. The field table is under what --trace-log writes now. The path must stay under the working directory, and it is a file path: a directory starts the server and records nothing. It rotates at the cap (1 to 10000 MB, default 100) keeping one backup, and refuses to write through a symlink on the backup path. Transformers backend only: since v0.78.0 --trace-log with --backend vllm, sglang or mii exits 2 naming the flag (once the [serve] extra is installed; on a core install the missing-extra message comes first, with exit 1). (Since closed in v0.78.0: through v0.77.2 the flag was accepted on those backends and no trace line was written, and the line was ts as epoch seconds, prompt, response, latency_ms and tokens as one integer. A script of your own that reads either has to read both shapes.)

To turn these traces into preference data, soup data from-traces --format soup-serve reads a directory of *.jsonl files, so point --logs at the directory that holds the trace file (for example --trace-log ./traces/serve.jsonl, then --logs ./traces). Since v0.76.0 a single file there is refused with exit 1 (#1557); through v0.75.2 it wrote an empty output and exited 0 with Wrote 0 preference pair(s). The records --trace-log writes carry no preference signal, so a harvest of this directory on its own reports that no trace carried one (run at v0.78.0 on a directory of two version-1 lines: Read 2 trace(s) but built no pairs for --signal thumbs_up. No trace carried a signal., then Wrote 0 preference pair(s), exit 0); soup ingest writes the signal that from-traces reads. What people said about an answer goes to the feedback log (--feedback-log, POST /v1/feedback), joined to the answer by its id by soup loop's harvest, not by from-traces.

Secrets are redacted before the line is written, not after: Hugging Face tokens, sk- keys and Bearer values are stripped, because a trace file is the most likely thing in a serving directory to get pasted into an issue. A write failure never takes down the request handler.

Capturing thumbs from the served model

bash
soup serve --model ./output --record-thumbs ./feedback.db

Turns on POST /v1/thumbs and writes into the same local SQLite that soup local-rl harvests, so a served model feeds the preference flywheel without anyone recording feedback by hand. Path contained under cwd, transformers backend only (since v0.78.0 --record-thumbs with --backend vllm, sglang or mii exits 2 naming the flag; before, it was ignored). Since v0.77.0 the pre-wired harvest of soup loop can read that database too: soup loop init ... --pre-wired --thumbs-db ./feedback.db (or SOUP_LOOP_THUMBS_DB) turns its thumbs into preference pairs; the file must stay under the working directory and must already be a thumbs database, so start the server first (see soup loop).

DeepSpeed-MII backend

bash
soup serve --model ./output --backend mii

Loopback-only CORS, max_tokens capped at 16384, streaming disabled (no SSE for MII v0.x). Pipeline crashes return generic 500 with no stack-trace leak. Since v0.77.2 (#2329) /v1/chat/completions on this backend answers a request whose Origin names another site with 403, as the transformers server does; requests without an Origin are served as before, and the check is covered by tests, not exercised by hand before the release (see Inference Server).

--auto-quant is refused (v0.76.0)

bash
soup serve --model ./output --auto-quant   # exits 2 with the [serve] extra installed

soup serve --auto-quant exits 2 with an explanation (with the [serve] extra installed; without it the command stops earlier with exit 1 and the install hint, because the FastAPI and uvicorn import check runs before the refusal). Soup cannot compare GGUF, AWQ, GPTQ, FP8 and an unquantized baseline before a serving engine has loaded them. Through v0.75.2 the flag timed three calls to a stub that returned a constant and presented the fastest few hundred nanoseconds as a quality-gated evaluation; on vLLM that result could force AWQ, GPTQ or FP8 on a checkpoint that did not declare it. vLLM now follows the checkpoint's own quantization metadata, so if you served with --auto-quant on vLLM before, check which quantization the engine actually loaded. To serve a quantized model, quantize the checkpoint explicitly (see Model Export), then serve it without the flag.

Soup is free and Apache-2.0. If it saved you a training run, starring the repo costs nothing and helps most. You can also fund the GPU time behind the work a 4 GB laptop cannot reach.