Archived
radiance 1.11.0
New models: - GLM-5.3-Flash reads pictures: its vision tower and processor (--image-tokens sets the budget), with decode kernels for a few rows and the DSA indexer split over the ranks - Sage-A1.5 (fp8 and MXFP4) with its vision tower and a DFlash2 drafter - Unlimited-OCR (bf16) - Gemma 4 31B with z-lab's DFlash and RedHatAI's DFlash2 drafters; at four cards its all-reduces are fused with the junctions, overlapped with the compute and sent compressed - Ornith-1.5-35B-A3B w4a8 compose files Speed: - Block drafters (DFlash, DFlash2) accept their drafts on the card, and the next step is issued ahead - The four-rank all-reduce is faster for every --tp 4 model - qwen35_w8a8: the norms and SiLU write the int8 linears' operands directly - --attn-prefill-fp8 off|qk|pv|both: fp8 QK and PV legs for the h256 prefill attention (about +20% prefill on a 221K-token prompt for the 27B MXFP4 at TP2); lossy, off by default Features: - Control vectors: --control-vector off|on|disabled (disabled by default), a per-request switch, and the published Qwen3.8-Flash-Next refusal-direction vector (its license is in NOTICE) - Krea 2: the `rebalance` request field, as ComfyUI's ConditioningKrea2Rebalance - Cards with a small PCI BAR run, with kernel arguments kept in host memory - Dashboard: live acceptance figures; statsdump rotates its file at a size cap - KV caches every rank holds whole (GLM-5.3's latent and index caches) take one host-tier slot Fixes: - Long conversations taking turns no longer fall back to an early snapshot: a host-tier restore makes room as memory pressure does and waits a step for the previous turn's release (two conversations of 142K and 147K tokens sent back to back: 31.3 s per turn before, 2.8 s now) - Kernels before Linux 6.16 (amdgpu below 3.64) no longer hang at startup: virtual memory management is turned off there, with a warning - Gemma 4 dense scales its token embeddings as Hugging Face does (bf16), which changes its output - The four-rank all-reduce fences prefill-sized messages, for a rare divergence after a fresh start - GLM-5.3: every refusal names the setting and the reason; its template keeps string content - Several pictures in one request no longer refuse processors that take one image at a time Changes: Plugin ABI 26: out-of-tree plugins must be rebuilt. The environment switches the PRs added are fixed rules or flags now (R4D_ATTN_FP8 is --attn-prefill-fp8).
This commit is contained in:
commit
9eaf10da6e
210 files changed
+14363
-2138
No files matched your search
+16
-4
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
@@ -708,10 +709,21 @@ public:
|
||||
std::shared_ptr<mm::Item>* out, std::string* why) override {
|
||||
if (!accepts(k)) { if (why) *why = "this kind of media is not served"; return RAD_E_UNSUPPORTED; }
|
||||
if (k == MediaKind::Audio) return p_->audio(bytes.data(), bytes.size(), out, why);
|
||||
return k == MediaKind::Image
|
||||
? p_->image(bytes.data(), bytes.size(), opts.image_tokens, out, why,
|
||||
opts.max_pixels)
|
||||
: p_->video(bytes.data(), bytes.size(), out, why);
|
||||
if (k == MediaKind::Video) return p_->video(bytes.data(), bytes.size(), out, why);
|
||||
mm::ImageMode mode;
|
||||
mode.kind = (int32_t)opts.image_mode;
|
||||
mode.base_size = opts.image_base_size;
|
||||
mode.image_size = opts.image_size;
|
||||
mode.several = opts.several_pictures;
|
||||
/* The host share of a picture (decode, resample, patch staging), apart from the tower
|
||||
* pass engine_mm.cpp times. */
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
const int rc = p_->image(bytes.data(), bytes.size(), opts.image_tokens, out, why,
|
||||
opts.max_pixels, mode);
|
||||
RAD_DEBUG("mm: host processor %lld bytes -> %.1f ms (rc %d)", (long long)bytes.size(),
|
||||
std::chrono::duration<double, std::milli>(
|
||||
std::chrono::steady_clock::now() - t0).count(), rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int32_t audio_rate() const override {
|
||||
|
||||
@@ -339,9 +339,13 @@ HttpResponse Server::handle_speech(const HttpRequest& req) {
|
||||
std::string pcm;
|
||||
for (const gen::AudioChunk& c : chunks) append_pcm16(c.samples, &pcm);
|
||||
const double secs = (double)pcm.size() / 2.0 / (double)(info.channels * info.sample_rate);
|
||||
RAD_INFO("audio: %.1f s from %lld frames in %lld windows, %.1f s%s", secs,
|
||||
(long long)ticket->frames, (long long)ticket->windows,
|
||||
(double)(ticket->t_done_ns - ticket->t_submit_ns) * 1e-9,
|
||||
auto sec = [](int64_t a, int64_t b) { return a > 0 && b >= a ? (double)(b - a) * 1e-9 : 0.0; };
|
||||
RAD_INFO("audio: %.1f s from %lld frames in %lld windows, %.1f s: queue and prompt %.1f s, "
|
||||
"first audio %.1f s, frames %.1f s%s", secs, (long long)ticket->frames,
|
||||
(long long)ticket->windows, sec(ticket->t_submit_ns, ticket->t_done_ns),
|
||||
sec(ticket->t_submit_ns, ticket->t_prompt_ns),
|
||||
sec(ticket->t_submit_ns, ticket->t_first_audio_ns),
|
||||
sec(ticket->t_prompt_ns, ticket->t_frames_ns),
|
||||
ticket->model_ended ? "" : " (the request's length)");
|
||||
HttpResponse res;
|
||||
res.status = 200;
|
||||
|
||||
+97
-183
@@ -55,6 +55,18 @@ HttpResponse Server::handle_control_vector(const HttpRequest& req) {
|
||||
}
|
||||
|
||||
if (req.method == "POST") {
|
||||
/* The default applies to every client's requests that name no choice, so a server
|
||||
* started without --api-key takes the change from a loopback client only, as it does a
|
||||
* runtime adapter load. */
|
||||
if (opt_.api_key.empty() && !req.peer_is_loopback()) {
|
||||
ApiError e;
|
||||
e.status = 403;
|
||||
e.type = "permission_error";
|
||||
e.message = "without --api-key, the control-vector default is changed only from a "
|
||||
"loopback client; start the server with --api-key to change it from "
|
||||
"elsewhere";
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
json body;
|
||||
try {
|
||||
body = json::parse(req.body.empty() ? "{}" : req.body);
|
||||
@@ -568,16 +580,10 @@ h1 { margin:0; font-size:13.5px; font-weight:600; letter-spacing:-.005em; }
|
||||
.stack { display:grid; gap:14px; }
|
||||
@media (max-width:1000px) {
|
||||
.body { grid-template-columns:minmax(0,1fr); }
|
||||
/* On a phone the page is one column you drag with your thumb. A nested scroller that
|
||||
* refuses to chain (overscroll-behavior:contain, set for the desktop wheel so a scroll
|
||||
* over the request table does not move the page behind it) traps the drag here: you
|
||||
* scroll the card, it bottoms out, and the page will not follow, so you reach for the
|
||||
* margins where no scroller lives to get the page moving again. On narrow screens let
|
||||
* the scroll chain to the document; the desktop containment stays.
|
||||
* .body .hold, not .hold: the base .hold rule is defined LATER in this file, so a bare
|
||||
* .hold override here would match and still LOSE the cascade (equal specificity, later
|
||||
* wins) -- judge slice 31 caught exactly that dead-code trap, and the operator's thumb
|
||||
* confirmed it on the request table. .body .hold wins on specificity regardless of order. */
|
||||
/* In one column a nested scroller with overscroll-behavior:contain (there so a desktop wheel
|
||||
* over the request table does not move the page) traps a touch drag once it bottoms out, so
|
||||
* narrow screens let the scroll chain to the document. `.body .hold` rather than `.hold`: the
|
||||
* base .hold rule comes later in this sheet and would win at equal specificity. */
|
||||
.body .panel > .pbody, .body .hold { overscroll-behavior:auto; }
|
||||
}
|
||||
|
||||
@@ -1488,66 +1494,31 @@ function setMetric(key, value, text) {
|
||||
spark(key, hist[key]);
|
||||
}
|
||||
|
||||
/* BEST / RECENT / NOW ON THE OTHER FOUR TILES, in the shape the decode step established.
|
||||
*
|
||||
* WHAT THESE ARE NOT: engine figures. The engine publishes a floor and a recent window for the
|
||||
* decode step alone (step_ns_decode_best / _recent); for tok/s, requests in flight and acceptance
|
||||
* it publishes ONE figure per poll and nothing older. So these three figures are page-side, and
|
||||
* they mean:
|
||||
* best / highest - the extreme this page session has seen AT THE CURRENT CONCURRENCY.
|
||||
* Resets on reload, not on restart.
|
||||
* recent - the mean over the last 15 s at that concurrency; 5 s on prefill, whose
|
||||
* events are shorter than the window that would fit them. Shorter
|
||||
* than the sparkline on purpose:
|
||||
* a 60 s mean still read 31 tok/s fifty seconds after the lane went
|
||||
* quiet, which is the lane being remembered rather than measured.
|
||||
/* Best / recent / now on the decode, prefill, in-flight and acceptance tiles. The engine
|
||||
* publishes a floor and a recent window only for the decode step; for these it publishes one
|
||||
* figure per poll, so the three figures are the page's own:
|
||||
* best / highest - the extreme this page has seen at the current concurrency; it resets on
|
||||
* reload, not on a server restart. "highest" where more is not better.
|
||||
* recent - the mean of the last RECENT samples at that concurrency.
|
||||
* now - the current value as a percentage of that extreme.
|
||||
* "highest" rather than "best" on the two tiles where more is not better: a lane at its highest
|
||||
* request count is busy, not good. The word carries a direction the number alone does not.
|
||||
* Figures are kept per concurrency ("@cN" past one), because a batched rate read against the
|
||||
* single-stream best reports a batch arriving as a level change. Requests in flight keeps one
|
||||
* bucket, since its value is the concurrency, and it samples idle polls too. Idle polls record
|
||||
* nothing in a concurrency bucket, and the line keeps the last active concurrency's figures
|
||||
* without a now clause. There is no ~99 cap as on the decode step: the extreme comes from the
|
||||
* same series as `now`, so 100% is exact.
|
||||
*
|
||||
* PER-CONCURRENCY BUCKETS, the decode step's structure: a c8 rate read against the
|
||||
* single-stream best reports the batch arriving as a level change -- the mistake that took
|
||||
* the old drift line out. Every figure on the line describes the current concurrency, and
|
||||
* past c1 the line says so ("@c8"). Requests in flight is the exception: its value IS the
|
||||
* concurrency, so bucketing it by concurrency would pin "highest" to the current number
|
||||
* forever -- it keeps one session-wide bucket. While the lane is idle nothing new is
|
||||
* recorded and the line keeps the last active concurrency's figures: frozen, no now clause,
|
||||
* which is what the Decode Step tile does at idle.
|
||||
*
|
||||
* NO ~99 CAP HERE, unlike the decode step. That cap exists because `now` there is a 500 ms poll
|
||||
* mean measured against a 32-step window mean -- different instruments, so a fast stretch can read
|
||||
* faster than the floor without being one. Here the extreme is computed FROM the same series as
|
||||
* `now`, so exceeding it is arithmetically impossible and 100% is exact: you are at your best.
|
||||
*/
|
||||
/* RECENT'S OWN WINDOW, deliberately shorter than the sparkline's. HIST is 60 s and that is right
|
||||
* for a picture -- a sparkline wants the whole minute to show shape. It is wrong for a number:
|
||||
* measured over real traffic (two 5 s bursts inside a quiet minute), a 60 s mean still read 31.7
|
||||
* tok/s fifty seconds after the lane went quiet, and 30 s only brought that to 26.9. Fifteen
|
||||
* seconds decays to zero within a quarter-minute of silence while still tracking the running mean
|
||||
* mid-burst (52.8 against an actual 53.3). Ten and five overshoot -- 79 and 144 against that same
|
||||
* 53 -- which is the current value wearing a different name, and the big number above already is
|
||||
* that. `best`/`highest` stay full-session: an extreme wants every chance to be broken.
|
||||
* Idle polls do not enter an active bucket -- the lane is not at that concurrency while it
|
||||
* sleeps -- but they DO count in requests in flight's window, whose value is meaningful
|
||||
* while nothing runs.
|
||||
*
|
||||
* PREFILL GETS ITS OWN WINDOW (RECENT_PREFILL, 5 s). Measured: small prompts prefill in 1.5-6 s
|
||||
* above 100 tok/s; the operator's compaction reload -- the big one -- runs 7-15 s by his own
|
||||
* count. A 15 s mean cannot report a 7 s event while it is running: it reaches barely half the
|
||||
* peak by the event's end, then spends a quarter-minute averaging it down. Five seconds is
|
||||
* shorter than the shortest event, so `recent` rides the prefill while it happens instead of
|
||||
* diluting it. The engine's own figure is already a windowed rate (its help text: "over the
|
||||
* scheduler's recent window"), so this window sits on top of the engine's smoothing -- it
|
||||
* decides how long the page remembers, not how sharply the engine measures. */
|
||||
const RECENT = 30; /* 15 s at the 500 ms poll WHILE the quantity keeps updating; a quantity
|
||||
that skips polls (acceptance, which only samples when it drafts) spans
|
||||
30 UPDATES, which under sparse drafting is minutes, not 15 s. */
|
||||
const RECENT_PREFILL = 10; /* 5 s: shorter than the shortest prefill event (see above) */
|
||||
* RECENT is shorter than the sparkline's 60 s: a 60 s mean still shows a burst long after the lane
|
||||
* went quiet, and 15 s decays within a quarter-minute while still tracking the mean mid-burst.
|
||||
* Prefill's window is 5 s, so `recent` follows a prefill of several seconds while it runs instead
|
||||
* of diluting it; the engine's prefill rate is itself already windowed. */
|
||||
const RECENT = 30; /* 15 s at the 500 ms poll for a figure sampled every poll; acceptance is
|
||||
sampled only on polls that drafted, so its 30 samples can span minutes */
|
||||
const RECENT_PREFILL = 10; /* 5 s */
|
||||
const extAt = {}, winAt = {};
|
||||
let lastActiveC = 0;
|
||||
/* `win` false records the extreme only. Acceptance keeps its own pooled ring (accPool) and
|
||||
* reads `highest` from extAt, so a window here would be a second, never-read copy of the
|
||||
* same samples -- dead weight that a reviewer reasonably reads as a second figure. */
|
||||
/* `win` false records the extreme only: acceptance pools its window in accPool and reads only
|
||||
* `highest` from extAt. */
|
||||
function noteSample(key, c, value, cap, win) {
|
||||
if (value == null || !finite(value)) return;
|
||||
const e = extAt[key] || (extAt[key] = {});
|
||||
@@ -1558,12 +1529,11 @@ function noteSample(key, c, value, cap, win) {
|
||||
s.push(value); if (s.length > (cap || RECENT)) s.shift();
|
||||
}
|
||||
function triple(key, c, label, fmt, showNow) {
|
||||
/* RECENT IS A WINDOW MEAN, not a window maximum -- a maximum would sit equal to `best` on
|
||||
* any steady lane, and two figures that always agree read as a broken instrument. */
|
||||
/* `recent` is a window mean: a window maximum would equal `best` on any steady lane. */
|
||||
const e = extAt[key];
|
||||
if (!e || !(c in e)) return "";
|
||||
/* A bucket whose extreme is zero still has a story -- requests in flight has seen nothing yet --
|
||||
* so it renders. Only the `now` clause needs a nonzero extreme to divide by. */
|
||||
/* A bucket whose extreme is zero still renders (requests in flight before the first request);
|
||||
* only the `now` clause needs a nonzero extreme to divide by. */
|
||||
const s = winAt[key][c];
|
||||
let sum = 0;
|
||||
for (const v of s) sum += v;
|
||||
@@ -1571,14 +1541,13 @@ function triple(key, c, label, fmt, showNow) {
|
||||
const now = s[s.length - 1];
|
||||
const tag = typeof c === "number" && c > 1 ? "@c" + c : "";
|
||||
let out = label + " " + fmt(e[c]) + " · recent " + fmt(recent);
|
||||
/* THE SAME GUARD THE DECODE STEP USES: no `now` clause while nothing is running. A rate of
|
||||
* zero is the lane being idle, not the lane being slow, and "now 0% of best" reads as a
|
||||
* fault. The "@cN" tag rides the tail, exactly where the decode step puts it. */
|
||||
/* No `now` clause while nothing runs, as on the decode step: a zero rate is an idle lane, and
|
||||
* "now 0% of best" would read as a fault. */
|
||||
if (showNow !== false && e[c] > 0) out += " · now " + Math.round(100 * now / e[c]) + "% of " + label + tag;
|
||||
return out;
|
||||
}
|
||||
/* The acceptance tile's detail line: highest stays the full-session extreme of window ratios
|
||||
* (an extreme is an extreme), but recent and now are POOLED ratios of sums (see above). */
|
||||
/* The acceptance tile's detail line. `highest` is the session's extreme of per-poll ratios;
|
||||
* `recent` is a pooled ratio of sums over the ring (accWindow) and `now` the newest poll's. */
|
||||
function acceptTriple(c, showNow) {
|
||||
const e = extAt["accept"];
|
||||
const ring = accPool[c];
|
||||
@@ -1594,26 +1563,20 @@ function acceptTriple(c, showNow) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/* WINDOWED ACCEPTANCE. The engine's figure is cumulative and exact -- tot_accepted_/tot_drafted_
|
||||
* over the life of the process -- so a best/recent/now line built on it would print the same
|
||||
* number three times and call it a trend. The per-position counters the acceptance chart already
|
||||
* reads are cumulative too, and the DIFFERENCE between two polls is exact acceptance over that
|
||||
* interval, which is the only figure a detail line can move on. Each sample is one poll's delta
|
||||
* (~500 ms, and only when it drafted); `recent` POOLS the last RECENT such deltas AT THAT
|
||||
* CONCURRENCY and `now` is the newest one -- different windows, free to disagree.
|
||||
* The counters go backwards when the engine restarts; that poll resets the window rather than
|
||||
* reporting a negative draft. */
|
||||
/* Acceptance over a window. The engine's draft_accept is accepted / drafted over the life of
|
||||
* the process, so it barely moves on a long-running server. The per-position counters are
|
||||
* cumulative too, and their difference between two polls is the exact conditional acceptance
|
||||
* (accepted / reached) over that interval. Each ring entry is one poll that drafted; the ring is
|
||||
* kept per concurrency and pooled as sum(accepted) / sum(reached), because polls carry unequal
|
||||
* draft counts and a mean of their ratios would weigh a quiet poll like a busy one. */
|
||||
const accPool = {}; /* per concurrency: ring of {dr, da} for the pooled tile window */
|
||||
let accPrev = null, accUp = -1;
|
||||
function accWindow(s) {
|
||||
let reach = 0, hit = 0;
|
||||
for (const p of (s.draft_positions || [])) { reach += p.reached || 0; hit += p.accepted || 0; }
|
||||
/* RESTART DETECTION (2026-10-20, Turnstone audit). Counters going BACKWARDS catches a restart
|
||||
* the page was watching. uptime_s going backwards catches the one it missed: a backgrounded
|
||||
* tab whose accPrev froze while a new process drafted past the old process's lifetime total,
|
||||
* where the delta is positive and the first guard never fires. Either clears every pooled
|
||||
* ring -- a pre-restart pair must not pool with a post-restart one -- and yields no delta,
|
||||
* so the headline reads the idle 0 rather than a dead process's ratio. */
|
||||
/* A server restart: the counters go backwards, or, for a hidden tab that stopped polling while
|
||||
* a new process drafted past the old totals, uptime_s does. Either clears every ring, so counts
|
||||
* from two processes never pool, and yields no delta for this poll. */
|
||||
const up = s.uptime_s;
|
||||
const restart = accPrev !== null && (reach < accPrev.r || hit < accPrev.a ||
|
||||
(typeof up === "number" && up < accUp));
|
||||
@@ -1674,13 +1637,9 @@ function kvPanel(host, keys) {
|
||||
return out;
|
||||
}
|
||||
const totals = kvPanel($("totals"), ["Requests", "Steps"]);
|
||||
/* "Accepted of drafted" is the LIFETIME MARGINAL ratio -- the engine's figure, unchanged, and
|
||||
* the one this panel used to carry as its headline. A bullet now rather than the big number:
|
||||
* see the note at the accept tile. It divides by every token DRAFTED, so it is not comparable
|
||||
* with the live figure above it, which divides by the positions actually REACHED; the two bases
|
||||
* are worked through in README.md, section "Draft acceptance", and both are derivable from the
|
||||
* log. Each label names its own denominator, which is the whole distinction -- so neither needs
|
||||
* a tooltip, and a tooltip would be invisible on the phone anyway. */
|
||||
/* "Accepted of drafted" is the engine's lifetime draft_accept, accepted / drafted. The panel's
|
||||
* big figure divides by the positions reached instead, so the two are not comparable; each label
|
||||
* names its denominator (docs/GUIDE.md, section 6.1). */
|
||||
const spec = kvPanel($("spec"), ["Drafter", "Depth", "Accepted of drafted"]);
|
||||
|
||||
/* ---------------------------------------------------------------- meters */
|
||||
@@ -1915,7 +1874,7 @@ function renderRequests(list, poolTokens) {
|
||||
|
||||
/* ---------------------------------------------------------------- update */
|
||||
let prev = null, prevAt = 0, bars = [], devs = [], layerBars = [];
|
||||
let lastStepMs = null; /* lastTps retired with the per-step freeze (slice 26) */
|
||||
let lastStepMs = null;
|
||||
|
||||
/* The single-stream floor and the engine's most recent window, shown as two numbers with no
|
||||
* verdict. The engine records the fastest single-sequence decode window it has measured
|
||||
@@ -1937,13 +1896,9 @@ function update(s, dt) {
|
||||
* mixed load the answer is the mean of two populations. `step_ns_decode / steps_decode` is
|
||||
* neither -- it is what a decode step cost.
|
||||
*
|
||||
* A window with no decode steps in it reads 0, not the last reading (operator ruling
|
||||
* 2026-10-20, second pass): every other live figure on this page shows 0 when the lane is idle
|
||||
* -- tps() renders 0 as "0" and the engine publishes 0 rates -- so 0 IS the idle signal here,
|
||||
* and the dash stays reserved for a quantity that has no value at all. A held value was the
|
||||
* original sin (a stale number wearing a current name); a dash was an over-correction that
|
||||
* broke the convention. The floor and the engine's recent window below are the engine's own
|
||||
* figures and stay put. */
|
||||
* A window with no decode steps reads 0, the page's idle figure for every live value; a dash
|
||||
* is kept for a quantity that has no value at all, and a held value would present a stale
|
||||
* reading as current. The engine's floor and recent window below keep their values. */
|
||||
const dSteps = prev ? s.steps_decode - prev.steps_decode : 0;
|
||||
const stepMs = dSteps > 0 ? (s.step_ns_decode - prev.step_ns_decode) / 1e6 / dSteps : null;
|
||||
if (stepMs != null) lastStepMs = stepMs;
|
||||
@@ -1967,10 +1922,8 @@ function update(s, dt) {
|
||||
* ~500 ms poll mean and `best` a 32-step window mean, so a short fast stretch can beat the
|
||||
* floor; the figure is capped at 99 and shown as ~99, "at the best", rather than claiming a
|
||||
* record the window cannot confirm. */
|
||||
/* Gated on this window HAVING decode steps, not on the lane being busy: during a
|
||||
* prefill-only stretch the lane is busy, lastStepMs holds the last DECODE poll, and the
|
||||
* headline correctly reads 0 -- printing "now X% of best" under it would put a stale
|
||||
* value under the word "now", the exact defect the idle-0 ruling exists to kill. */
|
||||
/* Only for a window with decode steps in it: during a prefill-only stretch the headline reads
|
||||
* 0 and lastStepMs is an older poll's, which `now` must not show. */
|
||||
if (stepMs != null && s.running > 0) {
|
||||
const k = s.running;
|
||||
if (!(k in bestAt) || lastStepMs < bestAt[k]) bestAt[k] = lastStepMs;
|
||||
@@ -2022,41 +1975,22 @@ function update(s, dt) {
|
||||
const aw = accWindow(s);
|
||||
const awR = aw ? aw.ratio : null;
|
||||
if (awR != null) noteSample("accept", s.running > 0 ? s.running : lastActiveC, awR, null, false);
|
||||
/* POOLED ACCEPTANCE WINDOW (2026-10-20, math audit before the production roll).
|
||||
* triple()'s `recent` averages the per-poll RATIOS; polls carry unequal draft counts, so a
|
||||
* quiet poll and a 500-draft poll would weigh the same -- a mean of ratios, not a ratio of
|
||||
* sums. Measured on a live c8 burst: avg-of-ratios 65.7% vs pooled 54.7%, a 11-point skew
|
||||
* that grows with burstiness. The honest window figure is sum(accepted)/sum(reached) over
|
||||
* the same span, so the tile keeps its own ring of delta pairs per concurrency. */
|
||||
/* The pooled ring (see accWindow), per concurrency. */
|
||||
if (aw != null && aw.dr > 0) {
|
||||
const c = s.running > 0 ? s.running : lastActiveC;
|
||||
const ring = accPool[c] || (accPool[c] = []);
|
||||
ring.push(aw); if (ring.length > RECENT) ring.shift();
|
||||
}
|
||||
/* THE HEADLINE IS THE LIVE WINDOW, not the cumulative ratio. The engine's figure is exact but
|
||||
* cumulative, so on a process that has been up for hours it cannot move: 559 fresh drafts moved
|
||||
* it one point against a 33,000-draft denominator, and it froze outright the moment the lane
|
||||
* went quiet. Every other tile's big number is the current value, and feeding the cumulative one
|
||||
* here also fed the sparkline a quantity that is flat by construction.
|
||||
* Polls with no new drafts read 0 (operator ruling 2026-10-20, second pass): the page's
|
||||
* convention is that a live figure shows 0 when the lane is doing nothing, and the dash is for
|
||||
* quantities with no value at all. The original freeze was the real defect -- a held value
|
||||
* reads as a live measurement of a lane that drafted nothing. The lifetime ratio stays on
|
||||
* /stats and /metrics; what the tile answers is "what is it accepting now", and now, idle,
|
||||
* it is accepting nothing.
|
||||
* THE SPARKLINE'S SCALE IS THE SAME as the other tiles -- 120 samples at the 500 ms poll, 60 s
|
||||
* -- because setMetric samples every poll, idle polls included (0 is a value; see above). The
|
||||
* one difference is the dash case: with no draft head there is no value to push, so those polls
|
||||
* leave a gap and the line stretches over more wall-clock than 60 s. (Judge slice 4C: this
|
||||
* comment claimed a 10 s window, then a drafting-only window; neither sampling scheme exists.) */
|
||||
/* The headline is this poll's conditional acceptance, as every other tile's big number is the
|
||||
* current value; the lifetime ratio stays in the Speculation panel, on /stats and on /metrics.
|
||||
* A poll that drafted nothing reads 0, the page's idle figure, and the dash means there is no
|
||||
* draft head. The sparkline takes a sample every poll, idle ones included, like the other
|
||||
* tiles; without a draft head it takes none. */
|
||||
if (!(s.draft_positions && s.draft_positions.length)) setMetric("accept", null, DASH);
|
||||
else if (awR != null) setMetric("accept", 100 * awR, pctn(awR, 0));
|
||||
else setMetric("accept", 0, pctn(0, 0)); /* drafted nothing this poll -> 0, the idle figure */
|
||||
/* `now` is shown only when THIS poll drafted. The guard inside acceptTriple (last.dr > 0)
|
||||
* cannot ever be false -- the ring only stores deltas with dr > 0 -- so the freshness test
|
||||
* belongs here, where the poll's own delta is known. Otherwise a busy lane that drafted
|
||||
* nothing this poll shows 0 in the headline and "now Z% of highest" one line below it,
|
||||
* computed from the last drafted delta. highest/recent are session statistics and stay. */
|
||||
/* `now` only when this poll drafted: the ring holds only polls that did, so its newest entry
|
||||
* may be older than this poll, whose headline then reads 0. */
|
||||
$("m-acceptdet").textContent = acceptTriple(cNow, busy && awR != null);
|
||||
M.flight.u.textContent = "/ " + s.queue_cap;
|
||||
|
||||
@@ -2084,11 +2018,9 @@ function update(s, dt) {
|
||||
const kvLive = Math.max(0, (s.kv_tokens_used || 0) - kvCached);
|
||||
mKv.v.textContent = hbOf(s.kv_bytes_used, s.kv_bytes_total, " / ") + " · " + pct(kvFrac);
|
||||
setSplit(mKv, kvLive, kvCached, s.kv_tokens_total || 0);
|
||||
/* WHAT THE SEGMENTS ARE, IN THE WORDS OF WHAT THEY WOULD COST TO RECLAIM, because a dimmer bar
|
||||
is not self-explanatory and the phrase this line used to carry -- "in flight" against "held
|
||||
for the next turn" -- named neither thing it was measuring. The split is by who references
|
||||
the blocks: the first part is context a request on the card is reading and cannot be taken
|
||||
from it, the second is context nothing is reading and the next eviction frees. */
|
||||
/* The segments named by what reclaiming them would cost, since a dimmer bar is not
|
||||
self-explanatory. The split is by who references the blocks: the first part is context a
|
||||
request on the card is reading, the second context nothing reads and the next eviction frees. */
|
||||
mKvSub.textContent = s.kv_tokens_used > 0
|
||||
? cnt3(kvLive) + " tok read by running requests · " + cnt3(kvCached) + " kept for reuse"
|
||||
: "";
|
||||
@@ -2141,34 +2073,17 @@ function update(s, dt) {
|
||||
* gives tokens a step for the whole batch -- which grows with concurrency and says nothing
|
||||
* about the drafter. What speculation buys is tokens a step for ONE sequence. */
|
||||
const perStep = sps > 0 && s.decode_tps > 0 ? s.decode_tps / sps / seqs : null;
|
||||
/* Reads 0 when this window took no decode steps -- the page's idle figure, same law as
|
||||
* the step tile above it, which this figure is derived from. It used to hold the last
|
||||
* value, so a lane that stopped decoding kept reporting what its steps used to cost.
|
||||
* (Extension of the operator's idle-0 ruling by one figure: same defect, one line down,
|
||||
* flagged by judge slice 26 as "pre-existing, now more visible".) */
|
||||
/* 0 for a window with no decode steps, as on the step tile it derives from. */
|
||||
$("tps_n").firstChild.nodeValue = perStep == null ? "0" : sig3(perStep);
|
||||
/* ACCEPTED IS THE LIVE FIGURE, matching the tile above it. `aw` is the same pooled drafting
|
||||
* window the tile's headline reads, computed earlier in this function -- one derivation, two
|
||||
* readers, so the panel and the tile cannot disagree.
|
||||
* DESIGN DECISION, 10-19, at the Operator's direction: this section shows the REAL-TIME
|
||||
* accepted percentage and the lifetime average sits in the bullets below it. The reasoning is
|
||||
* on the tile; the short form is that a cumulative ratio on a process that has been up for
|
||||
* hours is a number that cannot move, and a headline that cannot move reads as a dead page.
|
||||
* PINNED, NOT PRICED: the Operator may prefer the average back in the big seat, and the swap
|
||||
* is these two lines. What must not happen is the average returning as the headline with no
|
||||
* bullet left behind, because then the live figure is the thing nobody can see.
|
||||
* Nothing drafted this poll reads 0 -- the page's idle figure, same law as the accept tile
|
||||
* (op ruling 2026-10-20, second pass). The defect being fixed is the FREEZE: a held value
|
||||
* reads as a live measurement of a lane that drafted nothing. */
|
||||
/* The same per-poll conditional acceptance as the accept tile's headline (accWindow), so the
|
||||
* two cannot disagree; 0 when this poll drafted nothing. The lifetime ratio is the
|
||||
* "Accepted of drafted" bullet below. */
|
||||
if (awR != null) $("acc_n").firstChild.nodeValue = pctn(awR, 0);
|
||||
else $("acc_n").firstChild.nodeValue = pctn(0, 0); /* idle: 0, the page's idle figure */
|
||||
$("specaside").textContent = "depth " + dp.length;
|
||||
spec["Drafter"].textContent = drafterName;
|
||||
spec["Depth"].textContent = dp.length;
|
||||
/* The lifetime marginal, always shown. Judge 22: guarding on >0 conflated "no drafts yet"
|
||||
* with "drafts made, all rejected" -- a drafter that accepts nothing is exactly the case a
|
||||
* reader needs to see, and a dash hid it. 0 is the honest figure for both, and the README's
|
||||
* "Draft acceptance" section says which question this bullet answers. */
|
||||
/* Always shown: 0% is also what a drafter that accepts nothing reads, which a dash would hide. */
|
||||
spec["Accepted of drafted"].textContent = pct(s.draft_accept, 0);
|
||||
}
|
||||
|
||||
@@ -3312,32 +3227,24 @@ async function identify() {
|
||||
} catch (err) { /* the header simply keeps its placeholder */ }
|
||||
}
|
||||
|
||||
/* THE CONTROL VECTOR, asked when the Model view opens. It is not a polled value: it changes only
|
||||
* when this page (or an admin call) flips it, and a control that silently reverted under the
|
||||
* reader would be worse than one that is a second old. A deployment without a control vector
|
||||
* answers 404 and the panel stays hidden. */
|
||||
/* The control vector, read when the Model view opens rather than polled: only this page or an
|
||||
* admin call changes it. 404 means the deployment has none and hides the panel; any other failure
|
||||
* keeps the panel and says why, so a page without the API key does not look like a build without
|
||||
* the feature. */
|
||||
async function loadControlVector() {
|
||||
/* THREE OUTCOMES, and only one of them hides the panel:
|
||||
* 404 this deployment has no control vector -- there is no such control, so it is omitted;
|
||||
* 200 the vector is loaded -- show the switch and its state;
|
||||
* anything else (most often 401, the page has no API key yet) -- the feature may well be
|
||||
* there, so SAY that instead of hiding the control. A control that silently disappears
|
||||
* because the page has not signed in reads exactly like a build without the feature. */
|
||||
try {
|
||||
const r = await api("admin/control-vector");
|
||||
if (r.status === 404) { $("cvpanel").hidden = true; return; }
|
||||
if (!r.ok) throw new Error(String(r.status));
|
||||
if (!r.ok) { const err = new Error(String(r.status)); err.status = r.status; throw err; }
|
||||
const p = await r.json();
|
||||
$("cvpanel").hidden = false;
|
||||
$("cvbox").disabled = false;
|
||||
$("cvbox").checked = !!p.default;
|
||||
/* The family leads: it is the one term that says whether this file belongs to the model on the
|
||||
* card at all, and it is the loader's own answer, not a label the page invents. */
|
||||
/* The family the loader validated the file against, then its range and scale. */
|
||||
$("cvsum").textContent = (p.arch ? p.arch + " \u00b7 " : "") + "layers " + p.first +
|
||||
"\u2013" + p.last + " \u00b7 " + p.mode + " \u00b7 scale " + p.scale;
|
||||
/* New requests only, because a running request keeps the choice it was admitted with; and a
|
||||
* session whose context already holds a refusal can repeat it, since the refusal is in the
|
||||
* prompt the next turn reads. */
|
||||
/* A running request keeps the choice it was admitted with, and a refusal already in a
|
||||
* session's context is in the prompt the next turn reads. */
|
||||
$("cvnote").textContent = "New requests only. A session with a refusal already in its " +
|
||||
"context may repeat it.";
|
||||
} catch (e) {
|
||||
@@ -3345,9 +3252,10 @@ async function loadControlVector() {
|
||||
$("cvbox").disabled = true;
|
||||
$("cvbox").checked = false;
|
||||
$("cvsum").textContent = "";
|
||||
$("cvnote").textContent =
|
||||
"Sign in with the API key (the field in the header) to read or change this: the vector " +
|
||||
"is present on this deployment, but its state needs the key.";
|
||||
$("cvnote").textContent = e.status === 401
|
||||
? "Sign in with the API key (the field in the header) to read or change this: the vector " +
|
||||
"is present on this deployment, but its state needs the key."
|
||||
: "The server did not report the control vector's state (" + (e.status || e.message) + ").";
|
||||
}
|
||||
}
|
||||
$("cvbox").addEventListener("change", async (e) => {
|
||||
@@ -3360,11 +3268,17 @@ $("cvbox").addEventListener("change", async (e) => {
|
||||
apiKey ? { Authorization: "Bearer " + apiKey } : {}),
|
||||
body: JSON.stringify({ enabled: want }),
|
||||
});
|
||||
if (!r.ok) throw new Error(String(r.status));
|
||||
if (!r.ok) {
|
||||
let msg = String(r.status);
|
||||
try { const j = await r.json(); if (j && j.error && j.error.message) msg = j.error.message; }
|
||||
catch (_) { /* the status alone */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
const p = await r.json();
|
||||
$("cvbox").checked = !!p.default;
|
||||
} catch (err) {
|
||||
e.target.checked = !want; // the server kept the old value
|
||||
$("cvnote").textContent = "Not changed: " + err.message;
|
||||
} finally {
|
||||
e.target.disabled = false;
|
||||
}
|
||||
|
||||
@@ -527,6 +527,14 @@ struct MediaOpts {
|
||||
/* A picture over this many pixels is first scaled down to that area (PIL's bicubic, sides
|
||||
* truncated), as a model's own pipeline may do before its processor; 0 leaves it as sent. */
|
||||
int64_t max_pixels = 0;
|
||||
/* Which of the checkpoint's picture modes, for one that has two (Unlimited-OCR): 0 is the
|
||||
* processor's choice (mm::ImageMode::Default), 1 gundam, 2 base. */
|
||||
int32_t image_mode = 0;
|
||||
/* The mode's sizes, when the request states them; 0 keeps the mode's own. */
|
||||
int32_t image_base_size = 0, image_size = 0;
|
||||
/* The request carries more than one picture (mm::ImageMode::several): a processor with a
|
||||
* multi-page mode uses it for a picture whose mode the request did not name. */
|
||||
bool several_pictures = false;
|
||||
};
|
||||
|
||||
class IMultimodal {
|
||||
@@ -618,6 +626,8 @@ struct ImageGenInfo {
|
||||
/* The prompt in windows (RadGeneratorDecl::chunk_tokens): tokens a window, its markers and
|
||||
* its padding token; 0 for a prompt read whole. */
|
||||
int32_t chunk_tokens = 0, chunk_bos = 0, chunk_eos = 0, chunk_pad = 0;
|
||||
/* The conditioning options a request may ask for (RadGeneratorDecl::cond_opts, RAD_GEN_COND_*). */
|
||||
uint32_t cond_opts = 0;
|
||||
};
|
||||
|
||||
class IImageGen {
|
||||
|
||||
@@ -397,12 +397,15 @@ HttpResponse Server::handle_images(const HttpRequest& req, bool edit) {
|
||||
r.seed = (uint64_t)body["seed"].get<int64_t>();
|
||||
r.seed_given = body["seed"].is_number_unsigned() || body["seed"].get<int64_t>() != -1;
|
||||
}
|
||||
/* Krea 2's fixed tap gains (ConditioningKrea2Rebalance's defaults, arch/krea2); other models
|
||||
* ignore it. */
|
||||
/* The conditioning at the plugin's fixed rebalance gains (Krea 2: its text taps at
|
||||
* ConditioningKrea2Rebalance's defaults). `false` is accepted everywhere. */
|
||||
if (body.contains("rebalance") && !body["rebalance"].is_null()) {
|
||||
if (!body["rebalance"].is_boolean())
|
||||
return error_response(err_bad("rebalance", "expected true or false"), req.peer);
|
||||
r.rebalance = body["rebalance"].get<bool>();
|
||||
if (r.rebalance && !(info.cond_opts & RAD_GEN_COND_REBALANCE))
|
||||
return error_response(err_unsupported("rebalance", "this model has no rebalance"),
|
||||
req.peer);
|
||||
}
|
||||
if (str("negative_prompt", &r.negative) < 0)
|
||||
return error_response(err_bad("negative_prompt", "expected a string"), req.peer);
|
||||
|
||||
+11
-19
@@ -140,8 +140,7 @@ void Metrics::sample(const SchedMetrics& m) {
|
||||
g_prefill_tps_.set(m.prefill_tps);
|
||||
g_decode_tps_.set(m.decode_tps);
|
||||
g_draft_accept_.set(m.draft_acceptance);
|
||||
/* Nanoseconds in the scheduler, seconds on the wire: the base unit Prometheus expects, and
|
||||
* what radiance:engine_step_seconds_* already use. */
|
||||
/* Nanoseconds in the scheduler, seconds on the wire, as engine_step_seconds_* use. */
|
||||
g_step_best_.set((double)m.step_ns_decode_best / 1e9);
|
||||
g_step_recent_.set((double)m.step_ns_decode_recent / 1e9);
|
||||
const int seen = std::max(0, std::min(m.draft_depth_seen, (int)MAX_DRAFT_POS));
|
||||
@@ -330,25 +329,17 @@ std::string Metrics::render() const {
|
||||
"Prefill throughput over the scheduler's recent window.", L, g_prefill_tps_.get());
|
||||
w.gauge("radiance:decode_tokens_per_second",
|
||||
"Decode throughput over the scheduler's recent window.", L, g_decode_tps_.get());
|
||||
/* THE DECODE FLOOR, the two figures the dashboard's Decode Step tile shows. They were on
|
||||
* /stats only, and /stats is documented as not a stable API -- so the one figure worth
|
||||
* comparing across restarts was reachable only from the surface automation is told not to
|
||||
* use. Omitted until measured: a floor of 0 seconds is not an unmeasured floor, it is an
|
||||
* infinitely fast one, and a scrape would plot it as a record. Both reset on restart, so a
|
||||
* freshly started server simply has no floor to report yet. */
|
||||
/* The decode floor the dashboard's step tile shows. Each series is omitted until its window
|
||||
* has been measured, because a 0-second step would plot as the fastest ever. */
|
||||
if (g_step_best_.get() > 0)
|
||||
w.gauge("radiance:decode_step_seconds_best",
|
||||
"Fastest single-sequence decode step window this process has run, in seconds "
|
||||
"PER STEP. A mean over 32 consecutive single-stream steps, not a stopwatch "
|
||||
"reading. Not seconds per token: with speculation a step can emit several "
|
||||
"tokens, so per-token time is this divided by (1 + accepted per step), "
|
||||
"not by the accepted figure alone. Resets on restart.", L, g_step_best_.get());
|
||||
"Fastest single-sequence decode window this process has run, in seconds per "
|
||||
"step: the mean of 32 consecutive single-stream steps. With speculation a step "
|
||||
"emits 1 + accepted tokens. Resets on restart.", L, g_step_best_.get());
|
||||
if (g_step_recent_.get() > 0)
|
||||
w.gauge("radiance:decode_step_seconds_recent",
|
||||
"Most recent single-sequence decode step window, in seconds PER STEP (see "
|
||||
"_best: not a token rate). The gap "
|
||||
"to _best tracks what else the machine is doing, not wear; see docs/GUIDE.md. "
|
||||
"Freezes while the lane is idle, because no window is completing.",
|
||||
"Most recent single-sequence decode window, in seconds per step (see _best). "
|
||||
"Holds its value while no single-stream window completes.",
|
||||
L, g_step_recent_.get());
|
||||
w.counter("radiance:engine_steps_total",
|
||||
"Scheduler steps executed. One forward pass of the model, plus whatever draft "
|
||||
@@ -463,8 +454,9 @@ std::string Metrics::render() const {
|
||||
c_cut_resumed_below_.get());
|
||||
w.counter("radiance:prefix_restore_cuts_total",
|
||||
"Restores from the host tier the pool could not hold whole, even after giving "
|
||||
"up the VRAM copies of other stored conversations; each came back to a "
|
||||
"snapshot short of its end.", L, c_restore_cuts_.get());
|
||||
"up the VRAM copies of other stored conversations; each came back only in "
|
||||
"part, on a model with recurrent state up to the deepest snapshot the room "
|
||||
"reaches.", L, c_restore_cuts_.get());
|
||||
w.counter("radiance:prefix_hit_cut_tokens_total",
|
||||
"Prompt tokens the attention cache held and admission computed again, because "
|
||||
"the hit resumed at a snapshot below it or reused nothing.", L,
|
||||
|
||||
@@ -113,9 +113,8 @@ private:
|
||||
Gauge g_running_, g_waiting_, g_kv_util_, g_prefix_hit_;
|
||||
Gauge g_kv_max_tokens_, g_kv_max_bytes_;
|
||||
Gauge g_prefill_tps_, g_decode_tps_, g_draft_accept_, g_preempted_;
|
||||
/* The decode floor, in seconds: the fastest single-sequence window this process has run,
|
||||
* and the most recent one. Both stay 0 until a window of 32 single-stream steps completes,
|
||||
* and both reset on restart -- the render omits them rather than expose an unmeasured 0. */
|
||||
/* The decode floor in seconds: the fastest and the most recent single-sequence window. 0
|
||||
* until a window completes, and render() omits a 0. */
|
||||
Gauge g_step_best_, g_step_recent_;
|
||||
Gauge queue_depth_;
|
||||
/* Per-position conditional draft acceptance (see render() and core/sched/draft.h). */
|
||||
|
||||
+129
-16
@@ -240,7 +240,8 @@ const char* kAcceptedCommon[] = {
|
||||
"dry_sequence_breakers", "samplers",
|
||||
"grammar", "json_schema", "priority", "logprobs", "ignore_eos",
|
||||
"timings_per_token", "return_progress", "session_id", "n_probs",
|
||||
"control_vector", "experimental_speed_projection",
|
||||
"control_vector",
|
||||
"ngram_ban_n", "ngram_window", "ngram_whitelist", "no_repeat_ngram_whitelist",
|
||||
};
|
||||
|
||||
const char* kAcceptedChat[] = {
|
||||
@@ -250,6 +251,8 @@ const char* kAcceptedChat[] = {
|
||||
"thinking_token_budget", "thinking_budget", "thinking_budget_tokens",
|
||||
"reasoning_budget_tokens", "reasoning_format", "continue_final_message",
|
||||
"functions", "function_call",
|
||||
/* Unlimited-OCR's picture modes: which of the checkpoint's two a request's pictures get. */
|
||||
"images_config",
|
||||
};
|
||||
|
||||
/* `preserved_tokens` is llama-server's: control tokens a raw completion's text keeps. On chat the
|
||||
@@ -843,19 +846,12 @@ static int parse_sampling(const json& b, const OaiLimits& lim, OaiRequest* r, Ap
|
||||
/* ignore_eos: generate to max_tokens whatever the model emits. See Request::ignore_eos. */
|
||||
if (!get_bool(b, "ignore_eos", &r->ignore_eos, err)) return RAD_E_INVAL;
|
||||
|
||||
/* The control vector (core/cvec.h): an opt-in per request, and the only place an API client
|
||||
* turns it on when the deployment's default is off. `control_vector` is the field's name;
|
||||
* `experimental_speed_projection` is Strata's spelling of the same switch, kept as an alias so
|
||||
* a client written against that reports what it means -- and read only when the request did not
|
||||
* send the field itself, so the field wins when a body carries both. A JSON null is "not sent",
|
||||
* as everywhere else in this parser. */
|
||||
for (const char* key : { "control_vector", "experimental_speed_projection" }) {
|
||||
const auto it = b.find(key);
|
||||
if (it == b.end() || it->is_null()) continue;
|
||||
/* The control vector (core/cvec.h), per request: absent or null takes the deployment's
|
||||
* default. */
|
||||
if (const auto it = b.find("control_vector"); it != b.end() && !it->is_null()) {
|
||||
bool on = false;
|
||||
if (!get_bool(b, key, &on, err)) return RAD_E_INVAL;
|
||||
if (!get_bool(b, "control_vector", &on, err)) return RAD_E_INVAL;
|
||||
r->control_vector = on ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
/* stop: a string or an array of strings. Bounded in count and length because every stop
|
||||
@@ -907,6 +903,95 @@ static int parse_sampling(const json& b, const OaiLimits& lim, OaiRequest* r, Ap
|
||||
auto sid = b.find("session_id");
|
||||
if (sid != b.end() && sid->is_string()) r->session_label = session_label_of(sid->get<std::string>());
|
||||
|
||||
/* The windowed no-repeat-ngram ban (core/sample/sampler.h): `ngram_ban_n` is the banned
|
||||
* n-gram's length and `ngram_window` how far back it looks; the checkpoint's own generation
|
||||
* config asks for 35 and 128 (Unlimited-OCR). The reference spells them
|
||||
* no_repeat_ngram_size and no_repeat_ngram_window_size; both are taken. */
|
||||
i64 = r->sp.ngram_ban_n;
|
||||
if (!get_any(b, { "ngram_ban_n", "no_repeat_ngram_size" }, &i64, nullptr, err))
|
||||
return RAD_E_INVAL;
|
||||
if (i64 < 0 || i64 > 256) {
|
||||
*err = err_bad("ngram_ban_n", "must be in [0, 256]");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
r->sp.ngram_ban_n = (int)i64;
|
||||
i64 = r->sp.ngram_window;
|
||||
if (!get_any(b, { "ngram_window", "no_repeat_ngram_window_size" }, &i64, nullptr, err))
|
||||
return RAD_E_INVAL;
|
||||
if (i64 < 0 || i64 > 131072) {
|
||||
/* The reference's negative window spelling belongs to generation_config, where it is
|
||||
* normalized to 0; a request states the whole-sequence form as 0, matching the sampler's
|
||||
* admission check (check_request refuses a negative window). */
|
||||
*err = err_bad("ngram_window", "must be 0 (search the whole sequence) or a count of at "
|
||||
"most 131072 history tokens");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
r->sp.ngram_window = (int)i64;
|
||||
|
||||
/* The ban's whitelist (the reference's `whitelist_token_ids`, which is removed from the
|
||||
* banned set before the -inf writes): token ids the ban must never touch. An array of
|
||||
* non-negative integers; absent, empty or null is off, the reference's empty whitelist and
|
||||
* the form the model's generation_config ships. */
|
||||
auto nwl = b.find("ngram_whitelist");
|
||||
if (nwl == b.end()) nwl = b.find("no_repeat_ngram_whitelist");
|
||||
if (nwl != b.end() && !nwl->is_null()) {
|
||||
if (!nwl->is_array()) {
|
||||
*err = err_bad("ngram_whitelist", "expected an array of integer token ids");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
std::vector<int32_t> wl;
|
||||
for (const auto& v : *nwl) {
|
||||
int32_t id = 0;
|
||||
if (!token_id(v, &id)) {
|
||||
*err = err_bad("ngram_whitelist",
|
||||
"expected token ids in [0, " + std::to_string(INT32_MAX) + "]");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (wl.size() >= (size_t)1 << 20) {
|
||||
*err = err_bad("ngram_whitelist", "at most 1048576 ids");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
wl.push_back(id);
|
||||
}
|
||||
r->sp.ngram_whitelist = std::move(wl);
|
||||
}
|
||||
|
||||
/* `images_config`: Unlimited-OCR's two picture modes. A string names one ("gundam" for a
|
||||
* single picture -- the global view plus crops --, "base" for a page of a multi-page
|
||||
* document); an object carries the reference runner's own dict. */
|
||||
auto ic = b.find("images_config");
|
||||
if (ic != b.end() && !ic->is_null()) {
|
||||
if (ic->is_string()) {
|
||||
const std::string m = ic->get<std::string>();
|
||||
if (m == "gundam") r->image_mode = 1;
|
||||
else if (m == "base") r->image_mode = 2;
|
||||
else if (!m.empty()) {
|
||||
*err = err_bad("images_config", "expected \"gundam\" or \"base\", got \"" + m +
|
||||
"\"");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
} else if (ic->is_object()) {
|
||||
const json& o = *ic;
|
||||
int64_t bs = 0, is = 0;
|
||||
if (!get_int(o, "base_size", &bs, err)) return RAD_E_INVAL;
|
||||
if (!get_int(o, "image_size", &is, err)) return RAD_E_INVAL;
|
||||
bool crop = true;
|
||||
if (!get_bool(o, "crop_mode", &crop, err)) return RAD_E_INVAL;
|
||||
if (bs < 0 || bs > 65536 || is < 0 || is > 65536) {
|
||||
*err = err_bad("images_config", "base_size and image_size must be in [0, 65536]");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
r->image_mode = crop ? 1 : 2;
|
||||
r->image_base_size = (int32_t)bs;
|
||||
r->image_size = (int32_t)is;
|
||||
} else {
|
||||
*err = err_bad("images_config",
|
||||
"expected \"gundam\", \"base\", or an object with base_size, "
|
||||
"image_size and crop_mode");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
}
|
||||
|
||||
RAD_TRY(apply_sampler_order(b, &r->sp, err));
|
||||
|
||||
auto so = b.find("stream_options");
|
||||
@@ -1488,6 +1573,15 @@ int tokenize_with_media(const std::string& rendered, const OaiDeps& d,
|
||||
out->text = rendered;
|
||||
auto pm = std::make_shared<mm::PromptMedia>();
|
||||
const std::string marker = RAD_MEDIA_MARKER;
|
||||
/* Whether the request carries several pictures: a processor with a multi-page mode picks it
|
||||
* for a picture whose mode the request did not name (mm::ImageMode::several). */
|
||||
size_t n_images = 0;
|
||||
for (const auto& m : media) n_images += m.first == MediaKind::Image ? 1 : 0;
|
||||
auto opts_for = [&](MediaKind k) {
|
||||
MediaOpts mo = opts;
|
||||
if (k == MediaKind::Image) mo.several_pictures = n_images > 1;
|
||||
return mo;
|
||||
};
|
||||
size_t pos = 0, mi = 0;
|
||||
for (;;) {
|
||||
size_t at = rendered.find(marker, pos);
|
||||
@@ -1507,7 +1601,8 @@ int tokenize_with_media(const std::string& rendered, const OaiDeps& d,
|
||||
}
|
||||
std::shared_ptr<mm::Item> item;
|
||||
std::string why;
|
||||
const int s = d.mm->prepare(media[mi].first, media[mi].second, opts, &item, &why);
|
||||
const int s = d.mm->prepare(media[mi].first, media[mi].second, opts_for(media[mi].first),
|
||||
&item, &why);
|
||||
if (s < 0 || !item) {
|
||||
*err = err_bad("messages[].content[]", "the media could not be used: " +
|
||||
(why.empty() ? std::string(rad_strerror(s))
|
||||
@@ -2069,12 +2164,30 @@ int parse_chat_request(const std::string& body, const OaiDeps& d, const OaiLimit
|
||||
|
||||
PromptInput p;
|
||||
if (media.empty()) {
|
||||
/* add_special is false: the template renders the model's special tokens, BOS included;
|
||||
* another would shift every position. */
|
||||
/* add_special is false: the template renders the model's special tokens; BOS is placed
|
||||
* below. */
|
||||
p.tokens = d.tok->encode(rendered, false, /*parse_special=*/true);
|
||||
p.text = rendered;
|
||||
} else {
|
||||
RAD_TRY(tokenize_with_media(rendered, d, media, MediaOpts{}, &p, err));
|
||||
MediaOpts mo;
|
||||
mo.image_mode = out->image_mode;
|
||||
mo.image_base_size = out->image_base_size;
|
||||
mo.image_size = out->image_size;
|
||||
RAD_TRY(tokenize_with_media(rendered, d, media, mo, &p, err));
|
||||
}
|
||||
/* A tokenizer that states add_bos gets exactly one BOS in front. The render drops a BOS the
|
||||
* template writes when add_bos is set (ChatTemplate, as llama.cpp's chat does, which leaves it
|
||||
* to the tokenizer), and some templates never write one, so it is added here unless the
|
||||
* prompt already starts with it. A media run's placeholders shift by one with it. */
|
||||
{
|
||||
const ITokenizer::VocabInfo vi = d.tok->vocab_info();
|
||||
if (vi.add_bos && vi.bos >= 0 && (p.tokens.empty() || p.tokens.front() != vi.bos)) {
|
||||
p.tokens.insert(p.tokens.begin(), vi.bos);
|
||||
if (p.media) {
|
||||
for (auto& pl : p.media->items) pl.tok += 1;
|
||||
p.media->layout();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.tokens.empty()) {
|
||||
*err = err_bad("messages", "the rendered prompt tokenised to nothing");
|
||||
|
||||
+7
-4
@@ -94,10 +94,8 @@ struct OaiRequest {
|
||||
|
||||
int n = 1;
|
||||
SamplingParams sp;
|
||||
/* The control vector, tri-state: -1 the request named no choice (the deployment's
|
||||
* runtime default applies), 0 it asked for the stock model, 1 for the loaded control vector.
|
||||
* Parsed from `control_vector` (or Strata's `experimental_speed_projection`); a deployment
|
||||
* with no vector refuses 1 rather than silently serving the stock model. */
|
||||
/* `control_vector`, tri-state: -1 not sent (the deployment's runtime default applies), 0 the
|
||||
* stock model, 1 the loaded control vector. A deployment with no vector refuses 1. */
|
||||
int control_vector = -1;
|
||||
int32_t max_tokens = 0;
|
||||
std::vector<std::string> stop;
|
||||
@@ -163,6 +161,11 @@ struct OaiRequest {
|
||||
/* /v1/embeddings: a soft-token budget for the request's images, 0 the server's. */
|
||||
int32_t image_tokens = 0;
|
||||
|
||||
/* `images_config`: which of the checkpoint's picture modes a request's pictures get, and the
|
||||
* sizes it states (Unlimited-OCR's gundam and base modes). 0 keeps the processor's choice
|
||||
* (mm::ImageMode::Default). */
|
||||
int32_t image_mode = 0, image_base_size = 0, image_size = 0;
|
||||
|
||||
int n_choices() const { return (int)prompts.size() * n; }
|
||||
};
|
||||
|
||||
|
||||
@@ -98,10 +98,6 @@ int unsettled_for(const std::string& delay) {
|
||||
return 6; /* medium */
|
||||
}
|
||||
|
||||
bool starts_with(const std::string& s, const std::string& p) {
|
||||
return s.size() >= p.size() && s.compare(0, p.size(), p) == 0;
|
||||
}
|
||||
|
||||
std::string rtrim(std::string s) {
|
||||
while (!s.empty() && std::isspace((unsigned char)s.back())) s.pop_back();
|
||||
return s;
|
||||
@@ -858,7 +854,7 @@ bool Server::realtime_loop(RealtimeSession& s, WsConn& ws) {
|
||||
const std::string text = detok(ids, /*flush=*/true);
|
||||
const size_t at = speech_transcript_start(f, text, forced, /*closed=*/true);
|
||||
const std::string transcript = rtrim(text.substr(std::min(at, text.size())));
|
||||
if (starts_with(transcript, t->sent)) delta(*t, transcript.substr(t->sent.size()));
|
||||
if (transcript.starts_with(t->sent)) delta(*t, transcript.substr(t->sent.size()));
|
||||
ojson o = event("conversation.item.input_audio_transcription.completed");
|
||||
o["item_id"] = t->id;
|
||||
o["content_index"] = 0;
|
||||
@@ -886,13 +882,13 @@ bool Server::realtime_loop(RealtimeSession& s, WsConn& ws) {
|
||||
const size_t a = speech_transcript_start(f, settled_text, forced, /*closed=*/false);
|
||||
const std::string settled = a == std::string::npos ? std::string()
|
||||
: rtrim(settled_text.substr(a));
|
||||
if (settled.size() > t->sent.size() && starts_with(settled, t->sent))
|
||||
if (settled.size() > t->sent.size() && settled.starts_with(t->sent))
|
||||
delta(*t, settled.substr(t->sent.size()));
|
||||
const std::string all_text = detok(ids, /*flush=*/false);
|
||||
const size_t b = speech_transcript_start(f, all_text, forced, /*closed=*/false);
|
||||
const std::string all = b == std::string::npos ? std::string()
|
||||
: rtrim(all_text.substr(b));
|
||||
const std::string tentative = starts_with(all, t->sent) ? all.substr(t->sent.size())
|
||||
const std::string tentative = all.starts_with(t->sent) ? all.substr(t->sent.size())
|
||||
: std::string();
|
||||
if (tentative != t->tentative) {
|
||||
ojson o = event("radiance.input_audio_transcription.tentative");
|
||||
|
||||
@@ -297,8 +297,8 @@ std::vector<std::string> Server::probe_reasoning_efforts() {
|
||||
if (text == plain) same.push_back(w);
|
||||
}
|
||||
/* The level a request naming none gets: the one level whose render is the same. A template may
|
||||
* spend it in a system prompt the client never sees (#113: Qwen3.8's is xhigh). Several, or
|
||||
* none, say nothing. */
|
||||
* spend it in a system prompt the client never sees (Qwen3.8's is xhigh). Several, or none,
|
||||
* say nothing. */
|
||||
if (same.size() == 1) template_default_effort_ = same[0];
|
||||
lim_.reasoning_efforts = set;
|
||||
return set;
|
||||
@@ -467,9 +467,7 @@ int Server::submit_all(const OaiRequest& r, std::vector<Generation>* gens, ApiEr
|
||||
}
|
||||
|
||||
/* The control vector: the request's own choice, else the deployment's runtime default. A
|
||||
* deployment with no vector refuses the on state by name -- serving the stock model while the
|
||||
* client believes it asked for the vector would be a silent lie about what produced the text.
|
||||
* (Naming: `control_vector` is the field, `experimental_speed_projection` its alias.) */
|
||||
* deployment with no vector refuses the on state by name rather than serve the stock model. */
|
||||
bool projection_on = false;
|
||||
{
|
||||
const bool named = r.control_vector >= 0;
|
||||
|
||||
@@ -327,7 +327,8 @@ private:
|
||||
HttpResponse handle_sessions(const HttpRequest& req);
|
||||
/* The control vector's runtime switch (dashboard.cpp): GET reports the state, POST
|
||||
* {"enabled": bool} sets the default for requests that name no choice. Guarded by the API key
|
||||
* like every other route but the health probes and the page. */
|
||||
* 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 error_response(const ApiError& e, const std::string& peer,
|
||||
|
||||
Reference in new issue
Block a user