Archived
radiance 1.12.0
New models: - Fish Audio drama-3: speech with speaker tags and inline direction, voices cloned from reference clips (the `references` field of /v1/audio/speech and the streaming session), two cards - Gemma 4 E2B/E4B (KV-shared layers, per-layer embeddings, clipped vision linears), with NVIDIA-Nemotron-3.5-Bolt-E4B in bf16 with DFlash and vision on one card, and E4B recipes Speed: - MXFP4 GEMMs for one to 64 rows and a tiled prefill GEMM at TN=4 from 1024 rows: the 27B MXFP4 with DFlash2 decodes about 1% faster at c1, 5% at c4 and 14% at c16 - The fp8 and int8 LM heads read their weight once for 65 to 128 rows - A prefill step of one sequence runs in two pieces on a second lane at two ranks (qwen35_fp8, gemma3): a 45K-token prompt on the 27B fp8 in 15.1 s instead of 16.2 s - Gemma 3's fused all-reduce junctions also under a lossy wire - --draft-short-from N: a block drafter runs its shorter block from N decoding sequences on (off by default; with 8 on the 27B MXFP4: c8 +12%, c16 +18%, c64 +32%, c1 unchanged) - --tp-attn-split rows: GLM-5.3-Flash's MLA attention split by rows over the ranks, 18 to 21% faster prefill; lossy, `heads` stays the default - --draft-coupling on: Qwen3.8-Flash-Next's MTP drafter samples its proposals from its reranked top-8 and the target's draw is coupled to it; pays at high temperatures (c1 at T 1.0: 155 -> 178 tok/s), costs at low ones; off by default Features: - Edited prompts on windowed models (Gemma 4) reuse their prefix: periodic window snapshots, and snapshot-backed prefix KV kept across recomputes (an edited tail on Gemma 4 31B: 96 s -> 2.6 s) - DELETE /sessions/<label> and DELETE /sessions?id=<id> forget one stored conversation - --state-cache-dtype f16: the delta-net state cache at half the memory (qwen35 plugins; lossy) Fixes: - A browser's CORS preflight allows DELETE Changes: Plugin ABI 27: out-of-tree plugins must be rebuilt. The environment switches the PRs added are flags now (--tp-attn-split, --draft-coupling, --state-cache-dtype).
This commit is contained in:
10 parents
4bca30369b
b1f4fccc52
d90e19dc15
3aded1bbf8
d912c694f3
824e238996
58142a6638
9322ea0b92
e9d03362f0
4d68a01a08
commit
5a9ce4912b
137 files changed
+12959
-1126
No files matched your search
@@ -108,6 +108,8 @@ inline SchedMetrics bridge_metrics(const rad::SchedMetrics& m) {
|
||||
o.hit_cut_tokens = m.hit_cut_tokens;
|
||||
o.prefix_expired = m.prefix_expired;
|
||||
o.prefix_ckpt_expired = m.prefix_ckpt_expired;
|
||||
o.prefix_released = m.prefix_released;
|
||||
o.prefix_ckpt_released = m.prefix_ckpt_released;
|
||||
|
||||
o.prefill_tps = m.prefill_tps;
|
||||
o.decode_tps = m.decode_tps;
|
||||
@@ -203,6 +205,24 @@ public:
|
||||
|
||||
int64_t reset_prefix_cache() override { return s_->reset_prefix_cache(); }
|
||||
|
||||
int release_session(const std::string& label, uint64_t id, int64_t keep_tokens,
|
||||
SessionReleased* out) override {
|
||||
SessionRelease r;
|
||||
const int rc = s_->release_session(label, id, keep_tokens, &r);
|
||||
if (out) {
|
||||
out->sessions = r.sessions;
|
||||
out->entries = r.entries;
|
||||
out->tokens = r.tokens;
|
||||
out->device_bytes = r.device_bytes;
|
||||
out->host_bytes = r.host_bytes;
|
||||
out->snapshots = r.snapshots;
|
||||
out->kept_tokens = r.kept_tokens;
|
||||
out->kept_shared = r.kept_shared;
|
||||
out->kept_live = r.kept_live;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* The stored conversations. The tiers keep monotonic timestamps; idle and age are converted
|
||||
* to "seconds ago" here, so only the monotonic clock is authoritative. */
|
||||
TierCounters tier_counters() const override {
|
||||
|
||||
+136
-15
@@ -11,11 +11,18 @@
|
||||
* `guidance_scale` (the model's guidance: the denoiser's for a music model, the frame model's for
|
||||
* a speech one) and, for a model with a denoiser, `num_inference_steps`.
|
||||
*
|
||||
* References, for a model that clones a voice (RadAudioGenDecl::tmpl_ref): `references` is an
|
||||
* array of {"audio", "text"}, a clip of the voice (a data: URL or the base64 of an audio file,
|
||||
* decoded to mono at the model's rate and padded to whole frames) and what it says; at most the
|
||||
* model's count of them and seconds together. The prompt is then the references' template, each
|
||||
* reference rendered from the model's item, its transcript and a row a frame of its clip.
|
||||
*
|
||||
* Prompt: the plugin's template with its slots filled, each text first rewritten by the plugin
|
||||
* into the form the model was trained on (rad_arch_text_prepare). The template is tokenised with
|
||||
* its special tokens and the texts without, so a caller cannot write the model's control tokens
|
||||
* into a lyric. A model that declares the unconditional branch's own template gets that one
|
||||
* rendered from the same texts.
|
||||
* into a lyric; a model that declares `input_special` has its input tokenised with them too (its
|
||||
* speaker tags), its prepare() refusing the control tokens. A model that declares the
|
||||
* unconditional branch's own template gets that one rendered from the same texts.
|
||||
*
|
||||
* Response: the whole piece, once it is finished, as `response_format` wav (16-bit PCM, the
|
||||
* model's rate and channels) or pcm (the same samples raw, little-endian). Streamed as the
|
||||
@@ -29,6 +36,7 @@
|
||||
#include "oai.h"
|
||||
|
||||
#include "gen/audio.h"
|
||||
#include "mm/media.h"
|
||||
#include "rad_internal.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -109,6 +117,9 @@ int Server::speech_request(const json& body, const std::string& text,
|
||||
return fail(err_bad("instructions", "this model needs instructions, as a non-empty "
|
||||
"string: for a song its genre, mood, vocals and "
|
||||
"instruments"));
|
||||
if (!inst.empty() && info.tmpl.empty())
|
||||
return fail(err_unsupported("instructions", "this model takes no instructions; its "
|
||||
"direction is written in the input"));
|
||||
if (body.contains("speed") && !body["speed"].is_null() &&
|
||||
!(body["speed"].is_number() && body["speed"].get<double>() == 1.0))
|
||||
return fail(err_unsupported("speed", "this model keeps its own tempo; the instructions "
|
||||
@@ -156,6 +167,8 @@ int Server::speech_request(const json& body, const std::string& text,
|
||||
if (!body["guidance_scale"].is_number() || !(body["guidance_scale"].get<double>() >= 1.0) ||
|
||||
body["guidance_scale"].get<double>() > 30.0)
|
||||
return fail(err_bad("guidance_scale", "expected a number in [1, 30]"));
|
||||
if (info.branches == 1 && body["guidance_scale"].get<double>() != 1.0)
|
||||
return fail(err_unsupported("guidance_scale", "this model runs without guidance"));
|
||||
r->cfg = (float)body["guidance_scale"].get<double>();
|
||||
}
|
||||
bool seed_given = false;
|
||||
@@ -170,33 +183,141 @@ int Server::speech_request(const json& body, const std::string& text,
|
||||
r->seed = (((uint64_t)rd() << 32) ^ rd()) & (((uint64_t)1 << 53) - 1);
|
||||
}
|
||||
|
||||
/* ---- the references: a clip of a voice and what it says, each */
|
||||
struct Ref { std::string text; int64_t frames = 0; };
|
||||
std::vector<Ref> refs;
|
||||
if (body.contains("references") && !body["references"].is_null()) {
|
||||
const json& rs = body["references"];
|
||||
if (!rs.is_array())
|
||||
return fail(err_bad("references", "expected an array of {\"audio\", \"text\"}"));
|
||||
if (!rs.empty() && info.tmpl_ref.empty())
|
||||
return fail(err_unsupported("references", "this model takes no reference audio; its "
|
||||
"voice is described in the input"));
|
||||
if ((int64_t)rs.size() > info.ref_max)
|
||||
return fail(err_bad("references", "at most " + std::to_string(info.ref_max) +
|
||||
" references a request"));
|
||||
const int64_t hop = std::max<int64_t>(1, info.ref_hop);
|
||||
r->ref_cu.assign(1, 0);
|
||||
for (size_t i = 0; i < rs.size(); ++i) {
|
||||
const std::string at = "references[" + std::to_string(i) + "]";
|
||||
const json& e = rs[i];
|
||||
if (!e.is_object())
|
||||
return fail(err_bad(at, "expected an object {\"audio\", \"text\"}"));
|
||||
for (auto it = e.begin(); it != e.end(); ++it)
|
||||
if (it.key() != "audio" && it.key() != "text")
|
||||
return fail(err_bad(at + "." + it.key(), "a reference is its audio and its "
|
||||
"text"));
|
||||
if (!e.contains("audio") || !e["audio"].is_string())
|
||||
return fail(err_bad(at + ".audio", "the clip is required, as a data: URL or "
|
||||
"base64 of an audio file"));
|
||||
if (!e.contains("text") || !e["text"].is_string() || blank(e["text"].get<std::string>()))
|
||||
return fail(err_bad(at + ".text", "the clip's transcript is required, as a "
|
||||
"non-empty string"));
|
||||
/* The file: a data: URL, or its base64 alone (as fish-speech's server takes it). */
|
||||
const std::string& a = e["audio"].get_ref<const std::string&>();
|
||||
std::vector<uint8_t> bytes;
|
||||
if (a.rfind("data:", 0) == 0) {
|
||||
ApiError ue;
|
||||
if (decode_media_url(a, at + ".audio", &bytes, &ue) < 0) return fail(ue);
|
||||
} else if (!base64_decode(a, &bytes)) {
|
||||
return fail(err_bad(at + ".audio", "invalid base64"));
|
||||
}
|
||||
/* Mono at the model's rate; one sample past what is left of the budget is decoded,
|
||||
* so a clip too long is refused rather than cut. */
|
||||
const int64_t left = info.ref_max_samples - (int64_t)r->ref_audio.size();
|
||||
std::vector<float> pcm;
|
||||
std::string dwhy;
|
||||
if (left < hop)
|
||||
return fail(err_bad(at + ".audio", "the references are longer than this model "
|
||||
"takes"));
|
||||
if (mm::decode_audio(bytes.data(), bytes.size(), (int32_t)info.ref_rate, left + 1,
|
||||
&pcm, &dwhy) < 0)
|
||||
return fail(err_bad(at + ".audio", "the clip could not be used: " + dwhy));
|
||||
if (pcm.empty()) return fail(err_bad(at + ".audio", "the clip holds no audio"));
|
||||
const int64_t padded = ((int64_t)pcm.size() + hop - 1) / hop * hop;
|
||||
if (padded > left)
|
||||
return fail(err_bad(at + ".audio", "the references hold more than " +
|
||||
rad::fmt("%g", (double)info.ref_max_samples /
|
||||
(double)info.ref_rate) +
|
||||
" seconds together; this model takes no "
|
||||
"more"));
|
||||
pcm.resize((size_t)padded, 0.0f);
|
||||
r->ref_audio.insert(r->ref_audio.end(), pcm.begin(), pcm.end());
|
||||
r->ref_cu.push_back((int32_t)r->ref_audio.size());
|
||||
Ref ref;
|
||||
std::string why;
|
||||
if (deps_.audio->prepare(RAD_TEXT_REFERENCE, e["text"].get<std::string>(), &ref.text,
|
||||
&why) < 0)
|
||||
return fail(err_bad(at + ".text", why));
|
||||
ref.frames = padded / hop;
|
||||
refs.push_back(std::move(ref));
|
||||
}
|
||||
if (refs.empty()) r->ref_cu.clear();
|
||||
}
|
||||
if (!refs.empty() && !inst.empty())
|
||||
return fail(err_unsupported("instructions", "a request with references takes no "
|
||||
"instructions; the clips set the voice"));
|
||||
|
||||
/* ---- the prompt */
|
||||
std::string i2, t2, why;
|
||||
if (!inst.empty() && deps_.audio->prepare(RAD_TEXT_INSTRUCTIONS, inst, &i2, &why) < 0)
|
||||
return fail(err_bad("instructions", why));
|
||||
if (deps_.audio->prepare(RAD_TEXT_INPUT, text, &t2, &why) < 0)
|
||||
return fail(err_bad("input", why));
|
||||
auto encode = [&](const std::string& t, bool special, std::vector<int32_t>* ids_out) {
|
||||
if (t.empty()) return;
|
||||
const auto ids = deps_.tok->encode(t, false, /*parse_special=*/special);
|
||||
ids_out->insert(ids_out->end(), ids.begin(), ids.end());
|
||||
};
|
||||
auto subst = [](std::string t, const std::string& key, const std::string& v) {
|
||||
for (size_t p = t.find(key); p != std::string::npos; p = t.find(key, p + v.size()))
|
||||
t.replace(p, key.size(), v);
|
||||
return t;
|
||||
};
|
||||
/* One reference (ref_item): its header, the transcript in it, tokenised as one segment with
|
||||
* its special tokens (the speaker tags prepare() allows), a row a frame of its clip, and what
|
||||
* follows the clip as another segment. */
|
||||
int64_t frame0 = 0;
|
||||
auto render_ref = [&](size_t i, std::vector<int32_t>* ids_out) {
|
||||
static const std::string kAudio = "{audio}";
|
||||
const std::string idx = std::to_string(i + 1);
|
||||
const size_t a = info.ref_item.find(kAudio);
|
||||
encode(subst(subst(info.ref_item.substr(0, a), "{index}", idx), "{text}", refs[i].text),
|
||||
true, ids_out);
|
||||
r->ref_frame.resize(ids_out->size(), -1);
|
||||
for (int64_t f = 0; f < refs[i].frames; ++f) {
|
||||
ids_out->push_back(0);
|
||||
r->ref_frame.push_back((int32_t)(frame0 + f));
|
||||
}
|
||||
frame0 += refs[i].frames;
|
||||
encode(subst(info.ref_item.substr(a + kAudio.size()), "{index}", idx), true, ids_out);
|
||||
};
|
||||
/* A template a segment at a time: its own text with special tokens, each slot without. */
|
||||
auto render = [&](const std::string& t, std::vector<int32_t>* ids_out) {
|
||||
static const std::string kInst = "{instructions}", kInput = "{input}";
|
||||
static const std::string kInst = "{instructions}", kInput = "{input}",
|
||||
kRefs = "{references}";
|
||||
size_t at = 0;
|
||||
while (at <= t.size()) {
|
||||
const size_t a = t.find(kInst, at), b = t.find(kInput, at);
|
||||
const size_t p = std::min(a, b);
|
||||
const std::string lit =
|
||||
t.substr(at, p == std::string::npos ? std::string::npos : p - at);
|
||||
if (!lit.empty()) {
|
||||
const auto ids = deps_.tok->encode(lit, false, /*parse_special=*/true);
|
||||
ids_out->insert(ids_out->end(), ids.begin(), ids.end());
|
||||
}
|
||||
const size_t a = t.find(kInst, at), b = t.find(kInput, at), c = t.find(kRefs, at);
|
||||
const size_t p = std::min(a, std::min(b, c));
|
||||
encode(t.substr(at, p == std::string::npos ? std::string::npos : p - at), true,
|
||||
ids_out);
|
||||
if (p == std::string::npos) break;
|
||||
if (p == c) {
|
||||
for (size_t i = 0; i < refs.size(); ++i) render_ref(i, ids_out);
|
||||
at = p + kRefs.size();
|
||||
continue;
|
||||
}
|
||||
const bool is_inst = p == a;
|
||||
const auto ids = deps_.tok->encode(is_inst ? i2 : t2, false, /*parse_special=*/false);
|
||||
ids_out->insert(ids_out->end(), ids.begin(), ids.end());
|
||||
/* The input keeps its special tokens only for a model that asks (its speaker tags);
|
||||
* the plugin's prepare() has refused the ones a caller may not write. */
|
||||
encode(is_inst ? i2 : t2, !is_inst && info.input_special, ids_out);
|
||||
at = p + (is_inst ? kInst : kInput).size();
|
||||
}
|
||||
};
|
||||
render(inst.empty() ? info.tmpl_plain : info.tmpl, &r->tokens);
|
||||
render(!refs.empty() ? info.tmpl_ref : inst.empty() ? info.tmpl_plain : info.tmpl,
|
||||
&r->tokens);
|
||||
if (!refs.empty()) r->ref_frame.resize(r->tokens.size(), -1);
|
||||
if (!info.neg_tmpl.empty()) render(info.neg_tmpl, &r->neg_tokens);
|
||||
const size_t n_prompt = std::max(r->tokens.size(), r->neg_tokens.size());
|
||||
if ((int64_t)n_prompt > info.max_prompt)
|
||||
@@ -225,7 +346,7 @@ HttpResponse Server::handle_speech(const HttpRequest& req) {
|
||||
static const char* kKnown[] = {
|
||||
"model", "input", "instructions", "voice", "response_format", "speed", "stream",
|
||||
"stream_format", "seed", "max_new_tokens", "duration", "num_inference_steps",
|
||||
"guidance_scale", "user",
|
||||
"guidance_scale", "user", "references",
|
||||
};
|
||||
for (auto it = body.begin(); it != body.end(); ++it) {
|
||||
bool known = false;
|
||||
|
||||
@@ -150,6 +150,8 @@ HttpResponse Server::handle_sessions(const HttpRequest&) {
|
||||
o["snapshot_store"] = { { "bytes_each", c.ck_bytes }, { "slots", c.ck_slots } };
|
||||
/* Entries and snapshots removed by --prefix-cache-ttl, from whichever tier held them. */
|
||||
o["expired"] = { { "entries", sm.prefix_expired }, { "snapshots", sm.prefix_ckpt_expired } };
|
||||
/* And the ones a client gave up on purpose (DELETE /sessions). */
|
||||
o["released"] = { { "entries", sm.prefix_released }, { "snapshots", sm.prefix_ckpt_released } };
|
||||
/* Step-thread time spent on tier moves; every request waits through it. */
|
||||
o["stall"] = { { "restores", c.restores }, { "restore_ms", (double)c.restore_ns / 1e6 },
|
||||
{ "flushes", c.flushes }, { "flush_ms", (double)c.flush_ns / 1e6 } };
|
||||
@@ -179,6 +181,83 @@ HttpResponse Server::handle_sessions(const HttpRequest&) {
|
||||
return HttpResponse::json_body(200, json_dump(o));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ DELETE /sessions
|
||||
*
|
||||
* A client that deletes a conversation, or replaces everything past a prefix of it, knows the
|
||||
* rest is dead before the TTL does. Named by the label it sent (`session_id`, or Anthropic's
|
||||
* `metadata.user_id`), or by the engine id `/sessions` shows. `keep_tokens` keeps the chain's
|
||||
* start. Shared blocks and blocks a live request reads stay; a request of the same conversation
|
||||
* in flight is a 409, since its close would publish the chain again. */
|
||||
HttpResponse Server::handle_session_release(const HttpRequest& req) {
|
||||
if (!deps_.sched)
|
||||
return error_response(err_not_implemented("the server has no engine attached"), req.peer);
|
||||
|
||||
const std::string label = req.param("label");
|
||||
uint64_t id = 0;
|
||||
const std::string id_s = req.param("id");
|
||||
if (!id_s.empty()) {
|
||||
if (id_s.find_first_not_of("0123456789") != std::string::npos || id_s.size() > 19)
|
||||
return error_response(err_bad("id", "expected the session's engine id, a decimal "
|
||||
"integer as /sessions reports it"), req.peer);
|
||||
id = std::stoull(id_s);
|
||||
if (id == 0) return error_response(err_bad("id", "0 names no session"), req.peer);
|
||||
}
|
||||
if (label.empty() && id == 0)
|
||||
return error_response(err_bad("label", "name the session: DELETE /sessions/<label>, "
|
||||
"?label=<label> or ?id=<engine id>"), req.peer);
|
||||
int64_t keep_tokens = 0;
|
||||
const std::string keep_s = req.param("keep_tokens");
|
||||
if (!keep_s.empty()) {
|
||||
if (keep_s.find_first_not_of("0123456789") != std::string::npos || keep_s.size() > 12)
|
||||
return error_response(err_bad("keep_tokens", "expected a non-negative integer: the "
|
||||
"prefix to keep, in tokens"), req.peer);
|
||||
keep_tokens = std::stoll(keep_s);
|
||||
}
|
||||
|
||||
SessionReleased r;
|
||||
const int rc = deps_.sched->release_session(label, id, keep_tokens, &r);
|
||||
if (rc == RAD_E_UNSUPPORTED)
|
||||
return error_response(err_not_implemented(
|
||||
"this engine has no prefix cache (started with --no-prefix-cache, or the model "
|
||||
"declares no cacheable KV group)"), req.peer);
|
||||
const std::string who = label.empty() ? "id " + std::to_string(id) : "'" + label + "'";
|
||||
if (rc == RAD_E_NOTFOUND) {
|
||||
ApiError e;
|
||||
e.status = 404;
|
||||
e.type = "not_found_error";
|
||||
e.param = label.empty() ? "id" : "label";
|
||||
e.message = "no stored session " + who + "; GET /sessions lists them";
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
if (rc == RAD_E_STATE) {
|
||||
ApiError e;
|
||||
e.status = 409;
|
||||
e.type = "conflict_error";
|
||||
e.code = "session_in_use";
|
||||
e.message = "a request of session " + who + " is queued or running; cancel it or wait "
|
||||
"for it to finish, then release again";
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
if (rc == RAD_E_INVAL)
|
||||
return error_response(err_bad("keep_tokens", rad_strerror(rc)), req.peer);
|
||||
if (rc < 0) return error_response(err_internal(rad_strerror(rc)), req.peer);
|
||||
|
||||
json o;
|
||||
if (!label.empty()) o["label"] = label;
|
||||
if (id != 0) o["id"] = id;
|
||||
o["keep_tokens"] = keep_tokens;
|
||||
o["sessions"] = r.sessions;
|
||||
o["entries"] = r.entries;
|
||||
o["tokens"] = r.tokens;
|
||||
o["device_bytes"] = r.device_bytes;
|
||||
o["host_bytes"] = r.host_bytes;
|
||||
o["snapshots"] = r.snapshots;
|
||||
o["kept"] = { { "tokens", r.kept_tokens }, { "shared", r.kept_shared },
|
||||
{ "live", r.kept_live } };
|
||||
metrics_.observe_http(200);
|
||||
return HttpResponse::json_body(200, json_dump(o));
|
||||
}
|
||||
|
||||
HttpResponse Server::handle_stats(const HttpRequest&) {
|
||||
json o;
|
||||
o["model"] = opt_.model_id;
|
||||
@@ -234,6 +313,8 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
|
||||
o["ckpt_evictions"] = { { "retention", m.prefix_ckpt_retired },
|
||||
{ "store_full", m.prefix_ckpt_lru } };
|
||||
o["ckpt_refused"] = m.prefix_ckpt_refused;
|
||||
o["released"] = { { "entries", m.prefix_released },
|
||||
{ "snapshots", m.prefix_ckpt_released } };
|
||||
o["hit_cuts"] = { { "no_snapshot", m.hit_cut_no_snapshot },
|
||||
{ "windowed_group", m.hit_cut_window },
|
||||
{ "adopt_failed", m.hit_cut_adopt },
|
||||
|
||||
@@ -506,7 +506,7 @@ int HttpTransport::serve(const Router& router, const TransportOptions& o) {
|
||||
* anthropic-version and anthropic-beta headers of Anthropic's clients, which nothing reads. */
|
||||
static const char* const kCorsHeaders =
|
||||
"Content-Type, Authorization, X-Api-Key, anthropic-version, anthropic-beta";
|
||||
static const char* const kCorsMethods = "GET, POST, OPTIONS";
|
||||
static const char* const kCorsMethods = "GET, POST, DELETE, OPTIONS";
|
||||
|
||||
/* Whether a request carries the API key: `Authorization: Bearer` (OpenAI; the scheme is
|
||||
* case-insensitive, RFC 9110) or `X-Api-Key` (Anthropic, also accepted by llama-server). */
|
||||
|
||||
@@ -78,6 +78,7 @@ struct SchedMetrics {
|
||||
int64_t prefix_restore_cuts = 0;
|
||||
/* Removed by --prefix-cache-ttl, cumulative. Not evictions: nothing wanted the memory. */
|
||||
int64_t prefix_expired = 0, prefix_ckpt_expired = 0;
|
||||
int64_t prefix_released = 0, prefix_ckpt_released = 0;
|
||||
/* Decoupled prefix caching (spec §7.3). `prefix_hit_rate` is the attention hit rate, as in
|
||||
* vLLM. The linear side hits at a different granularity (whole checkpoints, not blocks), so
|
||||
* it is reported separately, with token counts and checkpoints written. */
|
||||
@@ -168,6 +169,17 @@ struct SessionOccupancy {
|
||||
int64_t host_cap_bytes = 0;
|
||||
};
|
||||
|
||||
/* What a release took out of the store and what it left (PrefixCache::release_session). The
|
||||
* kept counts are apart on purpose: `shared` blocks belong to another stored conversation too,
|
||||
* `live` ones to a request still reading them. */
|
||||
struct SessionReleased {
|
||||
int64_t sessions = 0;
|
||||
int64_t entries = 0, tokens = 0;
|
||||
int64_t device_bytes = 0, host_bytes = 0;
|
||||
int64_t snapshots = 0;
|
||||
int64_t kept_tokens = 0, kept_shared = 0, kept_live = 0;
|
||||
};
|
||||
|
||||
/* One in-flight request, for the live request table: shows which request is stuck, e.g. one
|
||||
* waiting on a prompt that will never fit, which no aggregate metric reveals. */
|
||||
struct RequestStat {
|
||||
@@ -225,6 +237,15 @@ public:
|
||||
* allocated), but it takes the scheduler's lock because a step may be inserting into the map. */
|
||||
virtual int64_t reset_prefix_cache() { return RAD_E_UNSUPPORTED; }
|
||||
|
||||
/* Forgets one stored conversation (DELETE /sessions): every row carrying `label`, or with
|
||||
* `id` nonzero the row of that engine id; `keep_tokens` leaves the chain's start standing.
|
||||
* RAD_E_NOTFOUND when nothing matches (404), RAD_E_STATE while a request of that
|
||||
* conversation is queued or running (409), RAD_E_UNSUPPORTED without a prefix cache (501). */
|
||||
virtual int release_session(const std::string& /*label*/, uint64_t /*id*/,
|
||||
int64_t /*keep_tokens*/, SessionReleased* /*out*/) {
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* The live request table, oldest first; returns the count. Default: none kept. */
|
||||
virtual int requests(std::vector<RequestStat>* /*out*/) const { return 0; }
|
||||
|
||||
@@ -662,6 +683,15 @@ struct AudioGenInfo {
|
||||
int64_t sample_rate = 0, channels = 0;
|
||||
int64_t default_steps = 0, max_lanes = 1; /* default_steps 0: no denoiser */
|
||||
double default_cfg = 1.0;
|
||||
/* RadAudioGenDecl::branches (1: no guidance) and ::input_special (the {input} slot is
|
||||
* tokenised with special tokens). */
|
||||
int32_t branches = 2;
|
||||
bool input_special = false;
|
||||
/* RadAudioGenDecl's references: the prompt with them and one reference ("" when the model
|
||||
* takes none), the clips' rate and frame, and the most of them and their samples. */
|
||||
std::string tmpl_ref, ref_item;
|
||||
int64_t ref_rate = 0, ref_hop = 0, ref_max_samples = 0;
|
||||
int32_t ref_max = 0;
|
||||
};
|
||||
|
||||
class IAudioGen {
|
||||
|
||||
@@ -189,6 +189,8 @@ void Metrics::sample(const SchedMetrics& m) {
|
||||
c_prefix_ckpt_evict_.advance_to(m.prefix_ckpt_evictions);
|
||||
c_prefix_expired_.advance_to(m.prefix_expired);
|
||||
c_prefix_ckpt_expired_.advance_to(m.prefix_ckpt_expired);
|
||||
c_prefix_released_.advance_to(m.prefix_released);
|
||||
c_prefix_ckpt_released_.advance_to(m.prefix_ckpt_released);
|
||||
c_ckpt_retired_.advance_to(m.prefix_ckpt_retired);
|
||||
c_ckpt_lru_.advance_to(m.prefix_ckpt_lru);
|
||||
c_ckpt_refused_.advance_to(m.prefix_ckpt_refused);
|
||||
@@ -438,6 +440,13 @@ std::string Metrics::render() const {
|
||||
c_ckpt_retired_.get());
|
||||
labelled("radiance:prefix_cache_ckpt_evictions_by_reason_total", "reason", "store_full",
|
||||
c_ckpt_lru_.get());
|
||||
w.help("radiance:prefix_cache_released_total",
|
||||
"Prefix-cache entries and linear-state snapshots a client released on purpose "
|
||||
"(DELETE /sessions).", "counter");
|
||||
labelled("radiance:prefix_cache_released_total", "what", "entries",
|
||||
c_prefix_released_.get());
|
||||
labelled("radiance:prefix_cache_released_total", "what", "snapshots",
|
||||
c_prefix_ckpt_released_.get());
|
||||
w.counter("radiance:prefix_cache_ckpt_refused_total",
|
||||
"Checkpoints not written because every snapshot slot was in use by a restore "
|
||||
"in the same step.", L, c_ckpt_refused_.get());
|
||||
|
||||
@@ -151,6 +151,7 @@ private:
|
||||
Counter c_attn_cached_, c_linear_cached_, c_checkpoints_;
|
||||
Counter c_prefix_evict_, c_prefix_ckpt_evict_;
|
||||
Counter c_prefix_expired_, c_prefix_ckpt_expired_;
|
||||
Counter c_prefix_released_, c_prefix_ckpt_released_;
|
||||
Counter c_ckpt_retired_, c_ckpt_lru_, c_ckpt_refused_;
|
||||
Counter c_cut_no_snapshot_, c_cut_window_, c_cut_adopt_, c_cut_resumed_below_, c_cut_tokens_;
|
||||
Counter c_restore_cuts_;
|
||||
|
||||
@@ -210,6 +210,12 @@ void Server::register_routes() {
|
||||
[this](const HttpRequest& q) { return handle_control_vector(q); });
|
||||
router_.post("/admin/control-vector",
|
||||
[this](const HttpRequest& q) { return handle_control_vector(q); });
|
||||
/* Forget one stored conversation: by its client label in the path (or `?label=`, for a
|
||||
* label the path cannot carry), or by engine id with `?id=`. */
|
||||
router_.add ("DELETE", "/sessions/:label",
|
||||
[this](const HttpRequest& q) { return handle_session_release(q); });
|
||||
router_.add ("DELETE", "/sessions",
|
||||
[this](const HttpRequest& q) { return handle_session_release(q); });
|
||||
}
|
||||
|
||||
/* Workers beyond the admission ceiling. A generation holds its connection's worker for its whole
|
||||
|
||||
@@ -330,6 +330,7 @@ private:
|
||||
* like every other route but the health probes and the page; without a key, POST answers
|
||||
* loopback clients only. */
|
||||
HttpResponse handle_control_vector(const HttpRequest& req);
|
||||
HttpResponse handle_session_release(const HttpRequest& req);
|
||||
|
||||
HttpResponse error_response(const ApiError& e, const std::string& peer,
|
||||
ApiShape shape = ApiShape::OpenAI);
|
||||
|
||||
@@ -214,7 +214,7 @@ bool Server::speech_stream_loop(SpeechSession& s, WsConn& ws) {
|
||||
static const char* kFields[] = {
|
||||
"type", "model", "instructions", "voice", "response_format", "speed", "seed",
|
||||
"max_new_tokens", "duration", "num_inference_steps", "guidance_scale", "user",
|
||||
"stream_audio", "split_granularity", "text_input_mode",
|
||||
"references", "stream_audio", "split_granularity", "text_input_mode",
|
||||
};
|
||||
json fields = json::object();
|
||||
for (auto it = j.begin(); it != j.end(); ++it) {
|
||||
|
||||
Reference in new issue
Block a user