radiance 1.7.0

- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-16 18:25:18 +02:00
1 parent b068190326
commit 1e968f6e1d
739 files changed
+128447 -84632

No files matched your search

+119 -110
View File
@@ -1,19 +1,16 @@
/* core/server/server.h -- the OpenAI-compatible server (spec §14).
*
* Threading, in the spec's terms (§1): HTTP threads feed a request queue, one scheduler thread
* produces one step. This object owns the HTTP thread pool and the admission queue; it does not
* own the step loop and never calls into it. Output comes back per request through a Sink the
* scheduler pushes into (sink.h), which `Request::sink` points at.
* Threading (spec §1): HTTP threads feed a request queue and one scheduler thread runs the steps.
* This object owns the HTTP thread pool and the admission queue, never the step loop. Output
* returns per request through a Sink (sink.h) that `Request::sink` points at.
*
* Backpressure is admission control, not buffering. A full queue is a 429 with Retry-After. The
* alternative -- accepting everything and letting the waiting list grow -- turns a load spike
* into an out-of-memory kill twenty minutes later, at which point every in-flight request dies
* rather than the marginal ones being refused up front.
* Backpressure is admission control, not buffering: a full queue answers 429 with Retry-After.
* Accepting everything would turn a load spike into a later out-of-memory kill of every in-flight
* request instead of refusing the marginal ones.
*
* Cancellation is not an edge case. An agent client that abandons a long generation is the normal
* case, so a dropped connection is detected on the streaming path (a failed write, or a closed
* socket seen while waiting) and turned into IScheduler::cancel, which frees the request's KV
* blocks immediately rather than at completion.
* Cancellation is the normal case for agent clients. A dropped connection, seen on the streaming
* path as a failed write or a closed socket, becomes IScheduler::cancel, which frees the request's
* KV blocks immediately.
*/
#pragma once
#include <functional>
@@ -27,6 +24,7 @@
#include <atomic>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <vector>
@@ -41,41 +39,36 @@ struct Deps {
IEmbedder* embed = nullptr; /* absent -> /v1/embeddings is 501 */
IMultimodal* mm = nullptr; /* absent -> image and audio parts are 501 */
IImageGen* images = nullptr; /* absent -> the images endpoints are 501 */
const SpeechFormat* speech = nullptr; /* absent -> /v1/audio/transcriptions is 501 */
/* WHAT ONLY THE ENGINE CAN SEE: per-card VRAM, the expert plane. The server holds interfaces
* and no device handle, so this dependency is a function rather than an object -- there is
* nothing to name it after. Absent, the dashboard shows the scheduler's half and omits the
* cards rather than drawing zeroes.
*
* The SAME function the live view is built with (liveview.h), so the terminal view and the
* web page cannot drift into disagreeing about what the engine is doing. */
/* Engine-side state the server cannot see (per-card VRAM, the expert plane), as a snapshot
* function since the server holds no device handle. The same function feeds the live view
* (liveview.h), so the terminal and the web page agree. Absent, the dashboard shows only the
* scheduler's metrics and omits the cards. */
LiveView::Source live;
};
struct ServerOptions {
std::string model_id = "radiance";
/* AN EMBEDDING MODEL (rad_declare_pooled) GENERATES NOTHING: /v1/chat/completions and
* /v1/completions answer 501 naming /v1/embeddings, rather than queueing a request the engine
* would finish after one step with no text. */
/* An embedding model (rad_declare_pooled) generates nothing: /v1/chat/completions and
* /v1/completions answer 501 naming /v1/embeddings. */
bool embedding_model = false;
/* AN IMAGE GENERATOR (rad_declare_generator) GENERATES NO TEXT either: the text endpoints
* answer 501 naming /v1/images/generations and /v1/images/edits. */
/* An image generator (rad_declare_generator) generates no text: the text endpoints answer
* 501 naming /v1/images/generations and /v1/images/edits. */
bool image_model = false;
/* WHICH DECISION PROTOCOL THE MODEL WAS TRAINED ON, from the container's `decision.type`:
* "d1" serves /v1/systemone (systemone.h); empty answers it 501. Never inferred from a name. */
/* The decision protocol from the container's `decision.type`: "d1" serves /v1/systemone
* (systemone.h); empty answers it 501. Never inferred from a name. */
std::string decision_type;
/* What --model named, reported as the model entry's `root` the way vLLM reports the path it
* loaded: a served name chosen for clients says nothing about which file is behind it. Empty
* leaves the field out. */
/* What --model named, reported as the model entry's `root` as vLLM reports its loaded path
* (the served name says nothing about the file behind it). Empty omits the field. */
std::string model_path;
std::string host = "0.0.0.0";
int port = 8000;
int n_threads = 0;
/* How many requests may be admitted and unfinished at once. Beyond this the answer is 429.
* Defaults to 8x max_seqs: enough that the scheduler always has a full batch to choose from
* and a queue to prefill out of, and small enough that the memory held by waiting requests is
* bounded by a number the operator picked. */
/* Requests that may be admitted and unfinished at once; beyond it, 429. Defaults to 8 x
* max_seqs: enough for a full batch plus a prefill queue, while bounding the memory waiting
* requests hold. */
int64_t queue_depth = 0;
int64_t max_seqs = 256;
int retry_after_s = 1;
@@ -88,14 +81,14 @@ struct ServerOptions {
int64_t max_stop_bytes = 4096;
bool supports_logprobs = false;
/* The deployment default for `reasoning_effort`, empty for the template's own. See
* OaiLimits::default_reasoning_effort for why a server-side default is needed at all. */
/* Deployment default for `reasoning_effort`; empty for the template's own. See
* OaiLimits::default_reasoning_effort. */
std::string default_reasoning_effort;
/* The deployment default for `thinking_token_budget`, -1 for none. See
/* Deployment default for `thinking_token_budget`, -1 for none. See
* OaiLimits::default_thinking_budget. */
int64_t default_thinking_budget = -1;
/* What a request that sends no sampler fields is served with. See
* OaiLimits::default_sampling; only the sampler knobs are read from it. */
/* Sampling for a request that sends no sampler fields; only the sampler knobs are read. See
* OaiLimits::default_sampling. */
SamplingParams default_sampling;
bool default_dry_breakers_set = false;
/* The deployment's chat template variables and reply format. See OaiLimits. */
@@ -107,33 +100,24 @@ struct ServerOptions {
bool allow_video = false;
bool allow_audio = false;
/* WHAT /server_info AND /version REPORT ABOUT THE ENGINE BEHIND THIS SERVER.
*
* `engine_info` is a JSON OBJECT as text, spliced in verbatim under "engine". The server
* cannot derive any of it -- it deliberately knows nothing about the device layer, the
* container or the placement plan -- and a struct with a field per fact would be a struct
* this component has to grow every time the engine learns something new about itself. */
/* What /server_info and /version report about the engine. `engine_info` is a JSON object as
* text, spliced in verbatim under "engine": the server knows nothing of the device layer,
* container or placement plan, and an opaque blob need not grow with every new engine fact. */
std::string version = RAD_VERSION;
std::string engine_info;
/* The declared compute graph, as JSON, for the Model view. A PROVIDER, called per request,
* rather than a string rendered once after declare.
/* The declared compute graph as JSON, for the Model view. A provider called per request, not
* a string rendered once: the dump includes `OpInfo::issued`, which a pre-first-step snapshot
* would report as false for every op, hiding dead declarations.
*
* The declaration itself does not change while the server runs, but the dump also carries what
* the run phase has DONE with it -- `OpInfo::issued` -- and a snapshot taken before the first
* step reports every op in the model as never issued, permanently, which makes /graph useless
* for finding a dead declaration.
*
* Regenerating reads the Program from the HTTP thread while the step path writes that one
* field. It is a monotonic false -> true bool, so the worst case is a graph fetched mid-step
* showing an op as unissued one step before it flips. Registry::select is asked with
* record = false and mutates nothing else. */
* Regenerating reads the Program on the HTTP thread while the step path writes that field. It
* is a monotonic false -> true bool, so at worst a mid-step fetch shows an op unissued one step
* early. Registry::select is called with record = false and mutates nothing else. */
std::function<std::string()> graph_json;
/* THE STARTUP REPORT READ AGAIN, as JSON (core/diag/diag.h): the options in force, the machine
* as it is now (the provider may reuse a reading for a second), and what on it costs speed.
* Without a key it is answered to loopback clients only (Server::handle_diagnostics). A
* provider like the graph's, because a card's link speed and clock only say anything under
* load -- a request made during a long prefill is how a link parked below its maximum is told
* from one at rest. */
/* The startup report as JSON (core/diag/diag.h): options in force, the machine as it is now
* (the provider may reuse a reading for a second), and what on it costs speed. Without an API
* key, loopback clients only (Server::handle_diagnostics). A provider because link speed and
* clock only mean something under load: queried during a long prefill, it tells a link parked
* below its maximum from one at rest. */
std::function<std::string()> diagnostics_json;
std::string api_key;
@@ -149,37 +133,34 @@ struct ServerOptions {
class Server {
public:
Server(const Deps& d, const ServerOptions& o);
/* Lifetime rule, and it is load-bearing: stop the scheduler before destroying the Server.
* `Request::sink` is a raw pointer into storage this object owns, and a request the scheduler
* has not finished is a request still writing into it. The destructor waits a bounded time
* for anything it cancelled and then deliberately leaks the rest rather than free memory a
/* Stop the scheduler before destroying the Server: `Request::sink` is a raw pointer into
* storage this object owns, and an unfinished request still writes into it. The destructor
* waits a bounded time for cancelled requests, then leaks the rest rather than free memory a
* running step may touch. */
~Server();
/* Every endpoint, registered. Tests drive this directly -- same handlers, no socket. */
/* Every endpoint. Tests drive this directly: same handlers, no socket. */
const Router& router() const { return router_; }
int run(); /* binds, serves, blocks. RAD_OK or negative. */
/* THE DEPLOYMENT'S TEMPLATE DEFAULTS, RENDERED ONCE BEFORE A CALLER DEPENDS ON THEM. A value
* the chat template refuses is a 400 on every request that leaves it to the default, so a
* one-message chat is parsed exactly as a request would be: first with no template defaults,
* then with the --chat-template-kwargs ones, then with the --reasoning-effort one as well.
* A render that fails at the first step says nothing about the defaults and is not reported.
* `kwargs_why` / `effort_why` are left empty, or hold the template's refusal at that step. */
/* Renders the deployment's template defaults once at startup, since a default the template
* refuses would 400 every request relying on it. A one-message chat is parsed as a request
* would be: with no defaults, then with --chat-template-kwargs, then also --reasoning-effort.
* A failure at the first stage is not about the defaults and is not reported. `kwargs_why` /
* `effort_why` stay empty or hold the template's refusal at that stage. */
void check_template_defaults(std::string* kwargs_why, std::string* effort_why) const;
/* THE DEPLOYMENT'S thinking_token_budget, asked for by a one-message chat the way a request
* would ask for it. Empty when this model's reasoning block can hold one; otherwise the 400 a
* request naming the budget would get, which says why. */
/* Checks the deployment's thinking_token_budget with a one-message chat, as a request would
* send it. Empty when the model's reasoning block can take one; otherwise the 400 message a
* request naming the budget would get. */
std::string check_thinking_budget() const;
/* THE EFFORTS THE CHAT TEMPLATE TAKES, found by parsing a one-message chat with each word this
* server knows of (low, medium, high, xhigh, max) the way a request would send it, with no
* deployment defaults. A template that takes a word nobody uses takes any word, and the answer
* is empty. Kept for the refusal of a word outside the set and for /server_info; called once,
* before run(). */
/* The reasoning efforts the chat template takes, found by parsing a one-message chat with each
* known word (low, medium, high, xhigh, max), with no deployment defaults. If the template
* also takes a nonsense word it takes any word, and the result is empty. Used to refuse words
* outside the set and for /server_info; called once, before run(). */
std::vector<std::string> probe_reasoning_efforts();
/* --reasoning-effort-map's targets, each rendered as a request's effort would be. Empty when
* the template takes every one; otherwise the first refusal, naming the target. */
/* Renders each --reasoning-effort-map target as a request's effort. Empty when the template
* takes all of them; otherwise the first refusal, naming the target. */
std::string check_reasoning_effort_map() const;
void stop();
int port() const { return transport_.port(); } /* 0 until run() is accepting */
@@ -190,6 +171,8 @@ public:
private:
struct Generation;
struct TranscriptionJob; /* speech.cpp */
struct RealtimeSession; /* realtime.cpp */
struct StreamState;
static UsageOut usage_of(const OaiRequest& r, const std::vector<Generation>& gens);
@@ -198,62 +181,77 @@ private:
void register_routes();
/* ------------------------------------------------------------------ server.cpp */
HttpResponse handle_chat(const HttpRequest& req);
HttpResponse handle_completion(const HttpRequest& req);
HttpResponse handle_messages(const HttpRequest& req);
HttpResponse handle_responses(const HttpRequest& req);
HttpResponse handle_native_completion(const HttpRequest& req);
HttpResponse handle_infill(const HttpRequest& req);
HttpResponse handle_embeddings(const HttpRequest& req);
/* ------------------------------------------------------------------ images.cpp */
HttpResponse handle_images(const HttpRequest& req, bool edit);
HttpResponse handle_systemone(const HttpRequest& req);
HttpResponse handle_apply_template(const HttpRequest& req);
using ToChat = int (*)(const std::string& body, const OaiLimits& lim, std::string* chat,
std::string* extra, ApiError* err);
HttpResponse count_tokens(const HttpRequest& req, ToChat to_chat, ApiShape shape,
const char* object);
/* OpenAI's /v1/audio/transcriptions, from the model's own RadAudioFormat (speech.cpp). */
HttpResponse handle_transcription(const HttpRequest& req);
/* OpenAI's realtime transcription session over a WebSocket at /v1/realtime: audio streamed
* in, the transcript streamed out while it is spoken (realtime.cpp). */
void handle_realtime(const HttpRequest& req, WsConn& ws);
/* The session's thread: realtime_loop, an exception turned into an error event and a close,
* and the pass in flight cancelled however the loop ends. The loop returns true when the
* server ended the session, false when the peer left. */
void realtime_run(RealtimeSession& s, WsConn& ws);
bool realtime_loop(RealtimeSession& s, WsConn& ws);
HttpResponse handle_models(const HttpRequest& req);
HttpResponse handle_metrics(const HttpRequest& req);
std::optional<HttpResponse> refuse_text(const std::string& peer,
ApiShape shape = ApiShape::OpenAI);
/* A parsed generation request, in any API's shape: admitted, run, answered in `r.shape`. */
HttpResponse serve(const HttpRequest& req, OaiRequest& r);
json native_result(const OaiRequest& r, const Generation& g, const std::string& content);
/* ------------------------------------------------------------------ images.cpp */
HttpResponse handle_images(const HttpRequest& req, bool edit);
/* ------------------------------------------------------------------ admin.cpp
* vLLM's non-generation surface. Separate because none of it touches the scheduler's step
* path, the admission queue or a Sink: these are questions about the server, answered on the
* HTTP thread and finished before they return. */
* vLLM's non-generation surface, answered on the HTTP thread without the step path, the
* admission queue or a Sink. */
HttpResponse handle_health(const HttpRequest& req);
HttpResponse handle_ping(const HttpRequest& req);
HttpResponse handle_version(const HttpRequest& req);
HttpResponse handle_props(const HttpRequest& req);
HttpResponse handle_apply_template(const HttpRequest& req);
HttpResponse handle_input_tokens(const HttpRequest& req);
HttpResponse handle_messages(const HttpRequest& req);
HttpResponse handle_count_tokens(const HttpRequest& req);
HttpResponse handle_responses(const HttpRequest& req);
HttpResponse handle_responses_tokens(const HttpRequest& req);
/* A request another API's shape was translated into: admitted and served like a chat one,
* answered in `r.shape`. */
HttpResponse serve_translated(const HttpRequest& req, OaiRequest& r);
HttpResponse handle_native_completion(const HttpRequest& req);
HttpResponse handle_infill(const HttpRequest& req);
json native_result(const OaiRequest& r, const Generation& g, const std::string& content);
HttpResponse handle_load(const HttpRequest& req);
HttpResponse handle_tokenize(const HttpRequest& req);
HttpResponse handle_detokenize(const HttpRequest& req);
HttpResponse handle_tokenizer_info(const HttpRequest& req);
HttpResponse handle_server_info(const HttpRequest& req);
HttpResponse handle_diagnostics(const HttpRequest& req);
/* What this deployment can do -- chat, tools, reasoning, grammar, media, logprobs, the
* reasoning efforts it takes -- as /server_info's `capabilities` and the model entry both
* report it, built in one place so the two cannot disagree. */
/* What this deployment can do (chat, tools, reasoning, grammar, media, logprobs, reasoning
* efforts), shared by /server_info's `capabilities` and the model entry so they agree. */
json capabilities() const;
HttpResponse handle_sessions(const HttpRequest& req);
HttpResponse handle_reset_prefix_cache(const HttpRequest& req);
/* ------------------------------------------------------------------ dashboard.cpp */
HttpResponse handle_dashboard(const HttpRequest& req);
HttpResponse handle_stats(const HttpRequest& req);
HttpResponse handle_graph(const HttpRequest& req);
HttpResponse handle_sessions(const HttpRequest& req);
HttpResponse error_response(const ApiError& e, const std::string& peer,
ApiShape shape = ApiShape::OpenAI);
/* THE REQUEST LOG. One line when a request is admitted and one from record() when it ends,
* at the info level, so `docker logs` answers "who asked what, how long, how did it end"
* without the engine's own levels. The debug level adds the last user message's opening. */
/* Request log: one info line at admission and one from record() at the end (who asked what,
* how long, how it ended). The debug level adds the opening of the last user message. */
void log_admitted(const OaiRequest& r) const;
/* Admission. Returns false when the queue is full; the caller answers 429. */
bool admit(int64_t n);
/* Admission: reserves `n` places in the queue, or returns the 429 to answer when it is full.
* More places than the queue has can never be admitted, so that is a 400 under `field` (the
* request field that multiplied them) naming the bound, not a 429 retried forever. Sweeps the
* graveyard first. */
std::optional<HttpResponse> admit(int64_t n, const std::string& peer,
ApiShape shape = ApiShape::OpenAI, const char* field = "n");
void release(int64_t n);
void sweep_abandoned();
/* Wait, bounded, for the scheduler to finish everything it was told to cancel. */
@@ -262,6 +260,13 @@ private:
/* Turn a parsed request into `n_choices` submitted engine requests. */
int submit_all(const OaiRequest& r, std::vector<Generation>* gens, ApiError* err);
void cancel_all(std::vector<Generation>& gens, bool count_disconnect);
/* While `gens` run: once the client has left (499) or the server is stopping, every
* generation is cancelled and retired, `n` queue places are released, and the answer is
* returned. Nothing otherwise. A generation request (`r`) is recorded as an abort, as a
* dropped stream is. */
std::optional<HttpResponse> abandoned(const HttpRequest& req, std::vector<Generation>& gens,
int64_t n, ApiShape shape = ApiShape::OpenAI,
const OaiRequest* r = nullptr);
void retire(std::vector<Generation>& gens);
/* Drain sinks into decoded text. Returns true if anything new arrived. */
@@ -271,7 +276,10 @@ private:
HttpResponse blocking_completion(const HttpRequest& req, OaiRequest& r);
HttpResponse streaming_completion(const HttpRequest& req, OaiRequest& r);
void record(const OaiRequest& r, const std::vector<Generation>& gens, Finish overall);
/* `quiet` says the request's line at the debug level: one of the many small passes a
* realtime session makes, which its own lines account for. */
void record(const OaiRequest& r, const std::vector<Generation>& gens, Finish overall,
bool quiet = false);
Deps deps_;
ServerOptions opt_;
@@ -283,12 +291,13 @@ private:
std::atomic<int64_t> in_flight_{0};
int64_t queue_depth_ = 0;
std::atomic<int64_t> realtime_sessions_{0};
std::atomic<bool> stopping_{false};
int64_t started_at_ = 0;
/* Sinks whose HTTP side is gone but whose engine side may still be mid-step. Held until the
* scheduler reports the request terminal, because Request::sink is a raw pointer and freeing
* it under a running step is a use-after-free in the one place it is unbisectable. */
* it under a running step is a use-after-free. */
std::mutex grave_m_;
std::vector<std::shared_ptr<Sink>> grave_;
};