Archived
radiance 1.13.0
New models: - Tencent Hy-Memory (HYV3) from its BF16, FP8 and GGUF checkpoints, with its native tool calls - M2XFP4: metadata-augmented MXFP4 weights for Qwen3.8-27B and its DFlash2 drafter (top-1 89.1% -> 92.4% against plain MXFP4), its quantiser and recipe, and ParoQuant's M2XFP4 checkpoints - Gemma 4 E2B/E4B audio input; NVIDIA-Nemotron-3.5-Bolt-E4B in int8 and 4-bit, on two cards by default; Ornith-1.5-122B compose files Speed: - Weight reads beside the decode all-reduces (qwen35_fp8, gemma3; --weight-prefetch, on by default): the 27B MXFP4 with DFlash2 61.2 -> 67.9 tok/s at c1, TranslateGemma 27B +13% - Head-256 split-KV decode attention at 256 workgroups and without bank conflicts (27B: +3-5% a step at 25-41K context), and the prefill KV split for small launches (a short turn over a long context decodes the other sequences 27% faster in that step) - MXFP4 decode gate_up, activation and fp8 quantiser in one launch (27B, Gemma 3 up to 64 rows: TranslateGemma +2-5% at 2-8 streams) - ParoQuant int4/int5 tiled GEMMs 6-9% faster - Speculation: a step's tokens are sent before the drafter's passes end, no step waits behind one that ends its requests, and the MTP head's first draft no longer collapses after short chats in the prefix cache Features: - --kv-resident N: KV streaming for a context bigger than VRAM (qwen4exp_fp8, GLM-5.3) - MiniMax-H3: reference media and keyframe conditioning with the VAE encoders - Krea 2 rebalance presets balanced, detail and subtle - The dashboard's request history; a stall watch that reports a frozen step's thread and stack - rad-tune at the served configuration, collectives measured as the exchange; Gemma 4 E2B/E4B's per-layer embeddings read ahead off the step path - A GPTQ calibration tap and recipe for Gemma 4 31B's w4a8 container Fixes: - The two-rank all-reduce checks that a peer's push has landed before reducing it - z-lab's DFlash drafter on Gemma 4 31B keeps drafting after a prefix-cache hit - MiniMax-H3's modulation rows Changes: Plugin ABI 31: out-of-tree plugins must be rebuilt. RADIANCE_PREFETCH_BESIDE is --weight-prefetch now; RADIANCE_NO_HUGE_PAGES, RADIANCE_IDS_EARLY, RADIANCE_ATTN_BAND_SPLIT, R4D_PREFILL_SPLITS, RAD_PLE_TIMING and RAD_PLE_CACHE_ROWS are gone.
This commit is contained in:
commit
6645337f69
198 files changed
+20904
-3240
No files matched your search
@@ -87,6 +87,11 @@ inline SchedMetrics bridge_metrics(const rad::SchedMetrics& m) {
|
||||
if (o.kv_tokens_max == 0 || t < o.kv_tokens_max) o.kv_tokens_max = t;
|
||||
}
|
||||
|
||||
/* KV streaming's totals are not per group, so they pass through. */
|
||||
o.kv_resident_blocks = m.kv_resident_blocks;
|
||||
o.kv_stream_misses = m.kv_stream_misses;
|
||||
o.kv_stream_bytes_in = m.kv_stream_bytes_in;
|
||||
|
||||
/* vLLM's gpu_prefix_cache_hit_rate means attention caching. The linear-checkpoint hit
|
||||
* rate has a different granularity (spec §7.3) and is reported separately, not averaged
|
||||
* in. */
|
||||
@@ -746,6 +751,53 @@ public:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* A decoded frame (a keyframe on the output canvas) through the processor's resize and
|
||||
* patching, as a prepared file's would go. */
|
||||
int prepare_frame(const mm::Frame& f, std::shared_ptr<mm::Item>* out,
|
||||
std::string* why) override {
|
||||
if (!accepts(MediaKind::Image)) {
|
||||
if (why) *why = "this model's vision tower serves no pictures";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
return p_->image_from(f, out, why);
|
||||
}
|
||||
|
||||
int encoder_image(const uint8_t* bytes, size_t n, int32_t ratio, int32_t max_side,
|
||||
mm::Frame* out, std::string* why) override {
|
||||
if (!p_ || !mm::decoder_available()) {
|
||||
if (why) *why = "no picture decoder is available";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
return p_->encoder_image(bytes, n, ratio, max_side, out, why);
|
||||
}
|
||||
|
||||
int encoder_image_canvas(const uint8_t* bytes, size_t n, int32_t w, int32_t h, bool cover,
|
||||
mm::Frame* out, std::string* why) override {
|
||||
if (!p_ || !mm::decoder_available()) {
|
||||
if (why) *why = "no picture decoder is available";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
return p_->encoder_image_canvas(bytes, n, w, h, cover, out, why);
|
||||
}
|
||||
|
||||
int encoder_video(const uint8_t* bytes, size_t n, int32_t ratio, int32_t max_side,
|
||||
int32_t max_frames, std::vector<mm::Frame>* out, std::string* why) override {
|
||||
if (!p_ || !mm::decoder_available()) {
|
||||
if (why) *why = "no video decoder is available";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
return p_->encoder_video(bytes, n, ratio, max_side, max_frames, out, why);
|
||||
}
|
||||
|
||||
int encoder_audio(const uint8_t* bytes, size_t n, int32_t rate, int64_t max_samples,
|
||||
std::vector<float>* out, std::string* why) override {
|
||||
if (!p_ || !mm::decoder_available()) {
|
||||
if (why) *why = "no audio decoder is available";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
return p_->encoder_audio(bytes, n, rate, max_samples, out, why);
|
||||
}
|
||||
|
||||
int32_t audio_rate() const override {
|
||||
return accepts(MediaKind::Audio) ? p_->audio_config().rate : 0;
|
||||
}
|
||||
|
||||
@@ -399,6 +399,8 @@ json Server::capabilities() const {
|
||||
caps["image_edit"] = deps_.images != nullptr && deps_.images->info().max_refs > 0;
|
||||
caps["audio_generation"] = deps_.audio != nullptr;
|
||||
caps["video_generation"] = deps_.videos != nullptr;
|
||||
/* What a video request may carry. */
|
||||
if (deps_.videos) video_caps(caps, deps_.videos);
|
||||
/* The efforts a chat request may send, probed from the template at startup; null when it
|
||||
* takes any word. "none" and "minimal" are this server's and turn thinking off. */
|
||||
if (lim_.reasoning_efforts.empty()) {
|
||||
|
||||
+45
-70
@@ -273,6 +273,8 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
|
||||
}
|
||||
}
|
||||
o["uptime_s"] = unix_now() - started_at_;
|
||||
/* The process's start, unix seconds: with a request id, a key unique across restarts. */
|
||||
o["started_at"] = started_at_;
|
||||
/* Seconds this process took to come up, the cost of a restart; 0 before the server listens. */
|
||||
o["startup_s"] = startup_s_;
|
||||
o["in_flight"] = in_flight_.load(std::memory_order_relaxed);
|
||||
@@ -666,7 +668,7 @@ h1 { margin:0; font-size:13.5px; font-weight:600; letter-spacing:-.005em; }
|
||||
* 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; }
|
||||
/* The history table is the card's scroller now, and it is the same trap on a phone. */
|
||||
/* The history table is the card's scroller, and the same trap on a phone. */
|
||||
#hist .hlist { overscroll-behavior:auto; }
|
||||
}
|
||||
|
||||
@@ -704,11 +706,8 @@ th + th, td + td { padding-left:14px; }
|
||||
.hold { scrollbar-width:thin; scrollbar-color:var(--edge) transparent; }
|
||||
|
||||
|
||||
/* HISTORY UNDER THE LIVE TABLE. The requests card holds two tables: what is running now and what
|
||||
has already finished. The live one is short by nature and stays put; only history scrolls, so
|
||||
the card has one scrollbar, and the card is half again the stock height to buy history rows.
|
||||
The age column is the only cell that changes on a poll, and it is rewritten in place rather
|
||||
than redrawing the table -- see histRender. */
|
||||
/* The requests card: the live table, which stays put, over the history, which scrolls. The card
|
||||
is half again the stock height to make room for history rows. */
|
||||
#reqpanel { height:459px; }
|
||||
#reqpanel > .pbody { overflow:hidden; }
|
||||
#reqpanel .hold { flex:0 0 auto; height:auto; overflow:visible; }
|
||||
@@ -1996,28 +1995,17 @@ function renderRequests(list, poolTokens) {
|
||||
|
||||
/* ---------------------------------------------------------------- history
|
||||
*
|
||||
* A REQUEST LIVES IN /STATS ONLY WHILE IT EXISTS. Its finished row is gone from the payload within
|
||||
* roughly 20 ms (a one-token reply) to half a second, so a reader looking at the card after the
|
||||
* fact finds the number they wanted — the average tok/s and the time to first token of that
|
||||
* request — nowhere on the page. This keeps every finished request the poll managed to see, per
|
||||
* browser, and draws the last two hundred under the live table.
|
||||
* A request is in /stats only while it exists: its finished row leaves the payload within about
|
||||
* 20 ms (a one-token reply) to half a second. The history keeps every finished request a poll
|
||||
* saw, per browser in localStorage, and shows the last HMAX under the live table.
|
||||
*
|
||||
* CAPTURE IS BY SIGHTING: a request is recorded the moment its state is "done", or, for the usual
|
||||
* case where the engine drops it before a poll lands on "done", at its last sighting once it is
|
||||
* gone from the payload. What was never seen is COUNTED, not invented: the grey row says how many
|
||||
* requests began and ended between two polls.
|
||||
*
|
||||
* AN ID HERE IS NOT THE ENGINE'S ID. The engine renumbers 1..N and starts over at 1 on every
|
||||
* restart, so rows carry a unique key (k) — the engine id plus a running offset persisted in
|
||||
* storage — and a separate history id (id) that starts at 0 and counts up. Clear sets that counter
|
||||
* back to 0, which is the point of the button: a cleared table begins again at #0.
|
||||
*
|
||||
* Rows are per browser, in localStorage, shared by every dashboard tab: a save UNIONS with what is
|
||||
* stored (two tabs each saw different requests), a row is deduplicated by k, and a clear is a
|
||||
* timestamp every tab honours. */
|
||||
const HK = "radiance.history.v2"; /* rows */
|
||||
* A request is recorded when a poll sees it "done", or, usually, from its last sighting once it
|
||||
* has left the payload. Requests that began and ended between two polls are counted in a grey
|
||||
* row. Rows are keyed by the engine's start and request id, so every tab and reload keys a
|
||||
* request alike; a save unions with what is stored, and a clear is a timestamp every tab
|
||||
* honours. The history id shown starts at 0 again after a clear. */
|
||||
const HK = "radiance.history.v3"; /* rows */
|
||||
const HKN = HK + ".next"; /* next history id: 0 after a clear */
|
||||
const HKO = HK + ".off"; /* engine-id offset, raised across engine restarts */
|
||||
const HKC = HK + ".clear"; /* clear marker: rows older than this stay deleted */
|
||||
const HMAX = 200;
|
||||
|
||||
@@ -2026,7 +2014,6 @@ function lsSet(k, v) { try { localStorage.setItem(k, v); } catch (e) {} }
|
||||
|
||||
let hRows = []; /* oldest first, unique by k */
|
||||
let hNext = 0; /* next history id; the clear button writes 0 here */
|
||||
let hOff = 0; /* engine id -> unique key offset */
|
||||
let hTracked = new Map(); /* engine id -> { last, fin } */
|
||||
let hSeen = new Set(), hBase = null, hBaseSeen = 0;
|
||||
let hDrawn = null;
|
||||
@@ -2038,48 +2025,37 @@ function histStored() {
|
||||
}
|
||||
function histMerge(lists) {
|
||||
const cleared = +lsGet(HKC) || 0, by = new Map();
|
||||
for (const rows of lists) for (const r of rows)
|
||||
if (r && r.k != null && (r.at || 0) > cleared) {
|
||||
const p = by.get(r.k);
|
||||
if (!p || (r.at || 0) > (p.at || 0)) by.set(r.k, r);
|
||||
for (const rows of lists) for (const h of rows)
|
||||
if (h && h.k != null && (h.at || 0) > cleared) {
|
||||
const p = by.get(h.k);
|
||||
if (!p || (h.at || 0) > (p.at || 0)) by.set(h.k, h);
|
||||
}
|
||||
return [...by.values()].sort((a, b) => a.k - b.k).slice(-HMAX);
|
||||
return [...by.values()].sort((a, b) => a.at - b.at).slice(-HMAX);
|
||||
}
|
||||
/* The whole table, on load and on every poll: another tab's rows join this one's. */
|
||||
function histLoad() {
|
||||
hRows = histMerge([histStored(), hRows]);
|
||||
let n = 0;
|
||||
for (const r of hRows) n = Math.max(n, (r.id || 0) + 1);
|
||||
for (const h of hRows) n = Math.max(n, (h.id || 0) + 1);
|
||||
hNext = Math.max(n, +lsGet(HKN) || 0);
|
||||
hOff = Math.max(hOff, +lsGet(HKO) || 0);
|
||||
for (const r of hRows) hOff = Math.max(hOff, r.k);
|
||||
}
|
||||
function histSave() {
|
||||
hRows = histMerge([hRows]);
|
||||
lsSet(HK, JSON.stringify(hRows));
|
||||
lsSet(HKN, String(hNext));
|
||||
lsSet(HKO, String(hOff));
|
||||
}
|
||||
/* A restart renumbers the engine's ids from 1. The offset keeps new rows from overwriting old
|
||||
* ones with the same key. It is not reset by a clear: the clear renumbers HISTORY ids, not the
|
||||
* engine's. */
|
||||
function histBump() {
|
||||
for (const r of hRows) hOff = Math.max(hOff, r.k);
|
||||
lsSet(HKO, String(hOff));
|
||||
}
|
||||
|
||||
/* Prefill rate: the prompt tokens this request actually computed (the rest came out of the
|
||||
* prefix cache) over its time to first token. A fully cached prompt did no prefill work: no
|
||||
* number, rather than 0. */
|
||||
/* Prefill rate: the prompt tokens computed (not from the prefix cache) over the time to first
|
||||
* token; none for a fully cached prompt. */
|
||||
function histPrefill(r) {
|
||||
if (!finite(r.prompt) || !finite(r.ttft_s) || r.ttft_s <= 0) return null;
|
||||
const fresh = r.prompt - (r.cached || 0);
|
||||
return fresh > 0 ? fresh / r.ttft_s : null;
|
||||
}
|
||||
function histFinish(r) {
|
||||
function histFinish(r, run) {
|
||||
if (!r || !r.id) return;
|
||||
hRows.push({
|
||||
k: hOff + r.id, /* unique for the life of this browser */
|
||||
k: run + ":" + r.id,
|
||||
id: hNext++, /* 0 after a clear, then 1, 2, … */
|
||||
prompt: finite(r.prompt) ? r.prompt : null,
|
||||
out: finite(r.output) ? r.output : null,
|
||||
@@ -2095,9 +2071,10 @@ function histFinish(r) {
|
||||
/* Returns the requests that finished unseen between two polls, for the grey row. */
|
||||
function histIngest(s) {
|
||||
const total = s.total_requests || 0;
|
||||
const run = s.started_at || 0;
|
||||
if (hBase === null) { hBase = total; hBaseSeen = hSeen.size; }
|
||||
else if (total < hBase) { /* a new engine run: its ids restart at 1 */
|
||||
hBase = total; hBaseSeen = 0; hSeen.clear(); hTracked.clear(); histBump();
|
||||
hBase = total; hBaseSeen = 0; hSeen.clear(); hTracked.clear();
|
||||
}
|
||||
histLoad();
|
||||
const live = new Set();
|
||||
@@ -2107,23 +2084,23 @@ function histIngest(s) {
|
||||
let t = hTracked.get(r.id);
|
||||
if (!t) { t = {}; hTracked.set(r.id, t); }
|
||||
t.last = r;
|
||||
if (r.state === "done" && !t.fin) { t.fin = true; histFinish(r); }
|
||||
if (r.state === "done" && !t.fin) { t.fin = true; histFinish(r, run); }
|
||||
}
|
||||
/* Gone without a "done" sighting: finalise it from its last sighting, then forget it. */
|
||||
for (const [id, t] of [...hTracked])
|
||||
if (!live.has(id)) { if (!t.fin) histFinish(t.last); hTracked.delete(id); }
|
||||
if (!live.has(id)) { if (!t.fin) histFinish(t.last, run); hTracked.delete(id); }
|
||||
|
||||
return Math.max(0, total - hBase - (hSeen.size - hBaseSeen));
|
||||
}
|
||||
|
||||
const HCOLS = [
|
||||
{ h: "id", f: (r) => "#" + r.id },
|
||||
{ h: "prompt", f: (r) => cnt3(r.prompt) },
|
||||
{ h: "out", f: (r) => cnt3(r.out) },
|
||||
{ h: "ctx", f: (r) => cnt3(r.ctx) },
|
||||
{ h: "ttft", f: (r) => dur(r.ttft) },
|
||||
{ h: "prefill tok/s", f: (r) => cnt3(r.pf) },
|
||||
{ h: "tok/s", f: (r) => tps(r.tps) },
|
||||
{ h: "id", f: (h) => "#" + h.id },
|
||||
{ h: "prompt", f: (h) => cnt3(h.prompt) },
|
||||
{ h: "out", f: (h) => cnt3(h.out) },
|
||||
{ h: "ctx", f: (h) => cnt3(h.ctx) },
|
||||
{ h: "ttft", f: (h) => dur(h.ttft) },
|
||||
{ h: "prefill tok/s", f: (h) => cnt3(h.pf) },
|
||||
{ h: "tok/s", f: (h) => tps(h.tps) },
|
||||
{ h: "age", f: null }, /* rewritten in place every poll */
|
||||
];
|
||||
for (const c of HCOLS) $("hhead").appendChild(el("th", null, c.h));
|
||||
@@ -2137,29 +2114,28 @@ function histRender(missed) {
|
||||
return label + " avg " + fmt(all) +
|
||||
(a20 != null ? " (20: " + fmt(a20) + ", 5: " + fmt(a5) + ")" : "");
|
||||
};
|
||||
const tpsV = hRows.map((r) => r.tps).filter((v) => v != null);
|
||||
const pfV = hRows.map((r) => r.pf).filter((v) => v != null);
|
||||
const tfs = hRows.map((r) => r.ttft).filter((v) => v != null).sort((a, b) => a - b);
|
||||
const tpsV = hRows.map((h) => h.tps).filter((v) => v != null);
|
||||
const pfV = hRows.map((h) => h.pf).filter((v) => v != null);
|
||||
const tfs = hRows.map((h) => h.ttft).filter((v) => v != null).sort((a, b) => a - b);
|
||||
const parts = [hRows.length + " done"];
|
||||
if (tpsV.length) parts.push(group(tpsV, tps, "tok/s"));
|
||||
if (pfV.length) parts.push(group(pfV, cnt3, "prefill"));
|
||||
if (tfs.length) parts.push("ttft " + dur(tfs[Math.floor(tfs.length / 2)]));
|
||||
$("hsum").textContent = parts.join(" · ");
|
||||
|
||||
/* Newest first, and the DOM is rebuilt only when the SET of rows changes: a long request
|
||||
* finishing late never shifts the rows being read, and the per-poll age update is a text write. */
|
||||
/* Newest first. The rows are rebuilt only when the set changes; a poll only rewrites the ages. */
|
||||
const body = $("hbody");
|
||||
const shape = hRows.length + ":" + (hRows.length ? hRows[hRows.length - 1].k : 0) + ":" + missed;
|
||||
const shape = hRows.length + ":" + (hRows.length ? hRows[hRows.length - 1].k : "") + ":" + missed;
|
||||
if (shape !== hDrawn) {
|
||||
hDrawn = shape;
|
||||
body.textContent = "";
|
||||
const frag = document.createDocumentFragment();
|
||||
for (let i = hRows.length - 1; i >= 0; i--) {
|
||||
const r = hRows[i], tr = el("tr");
|
||||
const h = hRows[i], tr = el("tr");
|
||||
for (const c of HCOLS) {
|
||||
const td = tr.appendChild(el("td", c.f === null ? "dim" : null));
|
||||
if (c.f) td.textContent = c.f(r);
|
||||
else td.dataset.at = r.at;
|
||||
if (c.f) td.textContent = c.f(h);
|
||||
else td.dataset.at = h.at;
|
||||
}
|
||||
frag.appendChild(tr);
|
||||
}
|
||||
@@ -3601,9 +3577,8 @@ $("cvbox").addEventListener("change", async (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
/* THE POLL SPEEDS UP WHILE SOMETHING IS RUNNING, for the history: a finished request leaves
|
||||
* /stats within a fraction of a second of its last token, so the idle 500 ms poll would miss most
|
||||
* of them. 100 ms costs the server one small JSON read and buys the finished row. */
|
||||
/* The poll runs every 100 ms while a request is in flight, so the history sees most finished
|
||||
* requests before they leave /stats, and every 500 ms otherwise. */
|
||||
let pollTimer = null;
|
||||
function schedulePoll(ms) { clearTimeout(pollTimer); pollTimer = setTimeout(poll, ms); }
|
||||
async function poll() {
|
||||
|
||||
@@ -60,6 +60,11 @@ struct SchedMetrics {
|
||||
* expert slab (`kv_bytes_carved` in bytes). The smallest over the paged groups, which share
|
||||
* one token axis; windowed groups are excluded, since their carve bounds lookback, not fit. */
|
||||
int64_t kv_tokens_max = 0;
|
||||
/* KV streaming: the rings' depth over every streamed group, and the resolve's cumulative misses
|
||||
* and bytes copied in from the host mirrors. Zero when nothing streams. */
|
||||
int64_t kv_resident_blocks = 0;
|
||||
int64_t kv_stream_misses = 0;
|
||||
int64_t kv_stream_bytes_in = 0;
|
||||
|
||||
double prefix_hit_rate = 0.0; /* 0..1 */
|
||||
/* Cumulative prefix-cache evictions. They rise as reusable prefixes are dropped, while
|
||||
@@ -568,6 +573,46 @@ public:
|
||||
virtual int prepare(MediaKind k, const std::vector<uint8_t>& bytes, const MediaOpts& opts,
|
||||
std::shared_ptr<mm::Item>* out, std::string* why) = 0;
|
||||
|
||||
/* A frame the caller decoded, for the vision tower: a keyframe resized to the output canvas,
|
||||
* so the tower sees the same pixels the video VAE is handed. Unsupported where the tower cannot
|
||||
* read host-built frames. */
|
||||
virtual int prepare_frame(const mm::Frame& f, std::shared_ptr<mm::Item>* out,
|
||||
std::string* why) {
|
||||
(void)f; (void)out;
|
||||
if (why) *why = "this server cannot show a pre-decoded frame to the vision tower";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* Media for a video generator's VAE encoders, as mm::Processor::encoder_image and the rest
|
||||
* make them; unsupported without a processor. */
|
||||
virtual int encoder_image(const uint8_t* bytes, size_t n, int32_t ratio, int32_t max_side,
|
||||
mm::Frame* out, std::string* why) {
|
||||
(void)bytes; (void)n; (void)ratio; (void)max_side; (void)out;
|
||||
if (why) *why = "this server prepares no reference media for a video encoder";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
virtual int encoder_image_canvas(const uint8_t* bytes, size_t n, int32_t w, int32_t h,
|
||||
bool cover, mm::Frame* out, std::string* why) {
|
||||
(void)bytes; (void)n; (void)w; (void)h; (void)cover; (void)out;
|
||||
if (why) *why = "this server prepares no reference media for a video encoder";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
virtual int encoder_video(const uint8_t* bytes, size_t n, int32_t ratio, int32_t max_side,
|
||||
int32_t max_frames, std::vector<mm::Frame>* out, std::string* why) {
|
||||
(void)bytes; (void)n; (void)ratio; (void)max_side; (void)max_frames; (void)out;
|
||||
if (why) *why = "this server prepares no reference media for a video encoder";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
virtual int encoder_audio(const uint8_t* bytes, size_t n, int32_t rate, int64_t max_samples,
|
||||
std::vector<float>* out, std::string* why) {
|
||||
(void)bytes; (void)n; (void)rate; (void)max_samples; (void)out;
|
||||
if (why) *why = "this server prepares no reference media for an audio encoder";
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* Audio in two halves, for a route that cuts a long recording into clips itself
|
||||
* (/v1/audio/transcriptions): the file decoded to mono samples at audio_rate(), at most
|
||||
* `max_samples` of them (RAD_E_INVAL past that, never a silent cut), and a clip of at most
|
||||
@@ -722,9 +767,16 @@ struct VideoGenInfo {
|
||||
int64_t sample_rate = 0, channels = 0;
|
||||
int64_t default_steps = 0, max_steps = 0, max_lanes = 1;
|
||||
bool fixed_steps = false; /* a trained schedule: max_steps grid points and no other */
|
||||
/* The schedule shifts a request that names none runs (RadVideoGenDecl). */
|
||||
double shift_video = 0.0, shift_audio = 0.0;
|
||||
/* A latent upscaler: the largest factor (0: none) and the full-size evaluations by default. */
|
||||
double upscale_max = 0.0;
|
||||
int64_t upscale_refine = 0;
|
||||
/* Reference conditioning (RadVideoGenDecl): the reference pictures, videos and soundtracks a
|
||||
* request may carry (a video's own soundtrack counts with the video), and the encoders' bounds
|
||||
* the server fits media to; `max_enc_side` 0 means no video encoder, so no keyframes either. */
|
||||
int64_t max_ref_images = 0, max_ref_videos = 0, max_ref_audios = 0;
|
||||
int64_t max_enc_frames = 0, max_enc_side = 0, max_enc_samples = 0, enc_ratio = 0;
|
||||
/* `steps` counts model evaluations rather than sigma grid points (RadVideoGenDecl form 1). */
|
||||
bool step_evals = false;
|
||||
/* Guidance (RadVideoGenDecl::guidance): the terms a request may name, their defaults and the
|
||||
|
||||
@@ -136,6 +136,7 @@ void Metrics::sample(const SchedMetrics& m) {
|
||||
g_kv_util_.set(m.kv_util);
|
||||
g_kv_max_tokens_.set((double)m.kv_tokens_max);
|
||||
g_kv_max_bytes_.set((double)m.kv_bytes_carved);
|
||||
g_kv_resident_blocks_.set((double)m.kv_resident_blocks);
|
||||
g_prefix_hit_.set(m.prefix_hit_rate);
|
||||
g_prefill_tps_.set(m.prefill_tps);
|
||||
g_decode_tps_.set(m.decode_tps);
|
||||
@@ -200,6 +201,8 @@ void Metrics::sample(const SchedMetrics& m) {
|
||||
c_cut_resumed_below_.advance_to(m.hit_cut_resumed_below);
|
||||
c_restore_cuts_.advance_to(m.prefix_restore_cuts);
|
||||
c_cut_tokens_.advance_to(m.hit_cut_tokens);
|
||||
c_kv_stream_misses_.advance_to((double)m.kv_stream_misses);
|
||||
c_kv_stream_bytes_.advance_to((double)m.kv_stream_bytes_in);
|
||||
g_linear_hit_.set(m.linear_hit_rate);
|
||||
}
|
||||
|
||||
@@ -281,6 +284,20 @@ std::string Metrics::render() const {
|
||||
w.gauge("radiance:kv_cache_max_bytes",
|
||||
"VRAM the KV cache holds with every block it lends the experts taken back, one card.",
|
||||
L, g_kv_max_bytes_.get());
|
||||
w.gauge("radiance:kv_resident_blocks",
|
||||
"Blocks of every streamed KV group the device ring holds; 0 when no group streams.",
|
||||
L, g_kv_resident_blocks_.get());
|
||||
w.counter("radiance:kv_stream_misses_total",
|
||||
"Blocks copied into a streamed KV group's ring from the host mirror.",
|
||||
L, c_kv_stream_misses_.get());
|
||||
/* Labelled by direction; the resolve only copies in. */
|
||||
w.help("radiance:kv_stream_bytes_total",
|
||||
"Bytes a streamed KV group's resolve moved, by direction.", "counter");
|
||||
w.out += "radiance:kv_stream_bytes_total";
|
||||
w.out += L.substr(0, L.size() - 1);
|
||||
w.out += ",dir=\"in\"} ";
|
||||
w.out += num(c_kv_stream_bytes_.get());
|
||||
w.out += '\n';
|
||||
w.gauge("vllm:gpu_prefix_cache_hit_rate",
|
||||
"GPU prefix cache block hit rate.", L, g_prefix_hit_.get());
|
||||
|
||||
|
||||
@@ -111,7 +111,9 @@ private:
|
||||
std::string labels_; /* {model_name="...",engine="0"} */
|
||||
|
||||
Gauge g_running_, g_waiting_, g_kv_util_, g_prefix_hit_;
|
||||
Gauge g_kv_max_tokens_, g_kv_max_bytes_;
|
||||
Gauge g_kv_max_tokens_, g_kv_max_bytes_, g_kv_resident_blocks_;
|
||||
/* KV streaming: blocks and bytes copied into the rings, cumulative. */
|
||||
Counter c_kv_stream_misses_, c_kv_stream_bytes_;
|
||||
Gauge g_prefill_tps_, g_decode_tps_, g_draft_accept_, g_preempted_;
|
||||
/* The decode floor in seconds: the fastest and the most recent single-sequence window. 0
|
||||
* until a window completes, and render() omits a 0. */
|
||||
|
||||
@@ -318,6 +318,8 @@ private:
|
||||
/* 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;
|
||||
/* A video model's capabilities (videos.cpp). */
|
||||
static void video_caps(json& caps, const IVideoGen* gen);
|
||||
HttpResponse handle_reset_prefix_cache(const HttpRequest& req);
|
||||
|
||||
/* ------------------------------------------------------------------ dashboard.cpp */
|
||||
|
||||
+474
-27
@@ -15,6 +15,11 @@
|
||||
* (`w:h`) instead lays the model's own canvas over that ratio: the short edge (the model's, or
|
||||
* `short_edge`), the area capped at the model's largest, both sides rounded to the multiple.
|
||||
* A video's length is a whole number of the model's chunks: `seconds` is rounded up to the next.
|
||||
* A model with the VAEs' encoders also takes keyframes, form file parts `first_frame` and
|
||||
* `last_frame` (tasks i2va, l2va, fl2va), or reference media (task ref2va): `ref_image_N` (at
|
||||
* most 9), `ref_video_N` (3) with a soundtrack `ref_video_audio_N` and `ref_audio_N` (3), N from 1
|
||||
* without gaps within each kind. The parts carry the bytes: `input_reference` (but for i2va on a
|
||||
* model that starts from a picture) and non-empty `conditions` are refused.
|
||||
* A model with a length head (LTX-2.5's duration head) chooses the length of a request that names
|
||||
* none, or says `"seconds": "auto"`; the video object reports it once chosen. A model with more
|
||||
* than one decoder takes `decoder`, one of their names (LTX-2.5: `vae`, the default, or
|
||||
@@ -53,10 +58,12 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace rad {
|
||||
namespace server {
|
||||
@@ -65,16 +72,25 @@ struct Server::VideoJob {
|
||||
std::string id, model, prompt, seconds, size;
|
||||
int64_t created_at = 0;
|
||||
uint64_t seed = 0;
|
||||
int32_t sampler = 0; /* the request's RAD_SAMPLER_* */
|
||||
double shift_video = 0, shift_audio = 0; /* 0: the model's */
|
||||
std::shared_ptr<gen::VideoTicket> ticket;
|
||||
std::thread worker;
|
||||
/* Under Server::videos_m_ from here on. */
|
||||
std::string status = "queued";
|
||||
int progress = 0;
|
||||
/* The steps done of the total (0 before the first), and the first one's steady-clock time in
|
||||
* ns, which the per-step log line measures its rate from. */
|
||||
int steps_done = 0, steps_total = 0;
|
||||
int64_t step_ns0 = 0;
|
||||
int64_t completed_at = 0, expires_at = 0;
|
||||
bool failed = false;
|
||||
std::string err_code, err_message;
|
||||
std::string mp4;
|
||||
std::vector<uint8_t> first; /* the first frame, RGB, for the thumbnail */
|
||||
/* A job with reference media or keyframes: its task and its parts in conditioning order. */
|
||||
std::string task;
|
||||
std::vector<std::string> refs;
|
||||
/* Latent upscaling, as the generator resolved it: the factor, the evaluations after it and the
|
||||
* small size; refine 0 when the video is not upscaled. */
|
||||
double upscale = 0.0;
|
||||
@@ -144,8 +160,110 @@ void canvas_for(double rw, double rh, int64_t short_edge, int64_t max_area, int6
|
||||
*h = std::max<int64_t>(mult, (int64_t)std::nearbyint(H / mult) * mult);
|
||||
}
|
||||
|
||||
/* The most reference media of each kind a request carries, ComfyUI's ref2va workflow's; a model
|
||||
* may take fewer. */
|
||||
constexpr int32_t kMaxRefImages = 9, kMaxRefVideos = 3, kMaxRefAudios = 3;
|
||||
|
||||
/* A reference part's kind and number from its name; false for any other name. `ref_video_audio_`
|
||||
* is tried before `ref_video_`, which it starts with. */
|
||||
bool parse_ref_name(const std::string& name, gen::VideoRefMedia::Kind* kind, int32_t* index) {
|
||||
static const struct { const char* pfx; gen::VideoRefMedia::Kind kind; } kKinds[] = {
|
||||
{ "ref_image_", gen::VideoRefMedia::IMAGE },
|
||||
{ "ref_video_audio_", gen::VideoRefMedia::VIDEO_AUDIO },
|
||||
{ "ref_video_", gen::VideoRefMedia::VIDEO },
|
||||
{ "ref_audio_", gen::VideoRefMedia::AUDIO },
|
||||
};
|
||||
for (const auto& k : kKinds) {
|
||||
const size_t n = std::strlen(k.pfx);
|
||||
if (name.compare(0, n, k.pfx) != 0 || name.size() == n) continue;
|
||||
char* e = nullptr;
|
||||
const long v = std::strtol(name.c_str() + n, &e, 10);
|
||||
if (*e == '\0' && v >= 1 && v <= 99) { *kind = k.kind; *index = (int32_t)v; return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* A ref2va request's parts, refused naming the part when one is empty, over its kind's count,
|
||||
* numbered with a gap or twice, or a soundtrack with no video of its number. On return `refs` is
|
||||
* sorted by (kind, number), the order of the conditioning. */
|
||||
int validate_refs(std::vector<gen::VideoRefMedia>& refs, const VideoGenInfo& info, ApiError* err) {
|
||||
if (refs.empty()) {
|
||||
*err = err_bad("task", "ref2va takes at least one reference part: ref_image_N, "
|
||||
"ref_video_N, ref_video_audio_N or ref_audio_N");
|
||||
return -1;
|
||||
}
|
||||
const struct {
|
||||
const char* pfx;
|
||||
gen::VideoRefMedia::Kind kind;
|
||||
int32_t cap;
|
||||
} kinds[] = {
|
||||
{ "ref_image", gen::VideoRefMedia::IMAGE,
|
||||
std::min(kMaxRefImages, (int32_t)info.max_ref_images) },
|
||||
{ "ref_video", gen::VideoRefMedia::VIDEO,
|
||||
std::min(kMaxRefVideos, (int32_t)info.max_ref_videos) },
|
||||
{ "ref_video_audio", gen::VideoRefMedia::VIDEO_AUDIO,
|
||||
std::min(kMaxRefVideos, (int32_t)info.max_ref_videos) },
|
||||
{ "ref_audio", gen::VideoRefMedia::AUDIO,
|
||||
std::min(kMaxRefAudios, (int32_t)info.max_ref_audios) },
|
||||
};
|
||||
for (const auto& k : kinds) {
|
||||
std::vector<bool> got(k.cap + 1, false);
|
||||
int n = 0;
|
||||
for (const gen::VideoRefMedia& m : refs) {
|
||||
if (m.kind != k.kind) continue;
|
||||
++n;
|
||||
if (m.data.empty())
|
||||
return *err = err_bad(m.name, "'" + m.name + "' carries an empty file"), -1;
|
||||
if (m.index > k.cap)
|
||||
return *err = err_bad(m.name, k.cap == 0
|
||||
? "this model takes no parts named " +
|
||||
std::string(k.pfx) + "_N"
|
||||
: "this model takes at most " +
|
||||
std::to_string(k.cap) + " parts named " +
|
||||
std::string(k.pfx) + "_N"), -1;
|
||||
if (got[m.index])
|
||||
return *err = err_bad(m.name, "two parts are numbered " + std::string(k.pfx) +
|
||||
"_" + std::to_string(m.index)), -1;
|
||||
got[m.index] = true;
|
||||
}
|
||||
for (int i = 1; i <= n; ++i)
|
||||
if (!got[i])
|
||||
return *err = err_bad(std::string(k.pfx) + "_" + std::to_string(i),
|
||||
"the " + std::string(k.pfx) + "_N parts must be numbered 1 "
|
||||
"to " + std::to_string(n) + " without gaps or repeats"), -1;
|
||||
}
|
||||
for (const gen::VideoRefMedia& m : refs) {
|
||||
if (m.kind != gen::VideoRefMedia::VIDEO_AUDIO) continue;
|
||||
bool paired = false;
|
||||
for (const gen::VideoRefMedia& v : refs)
|
||||
paired = paired || (v.kind == gen::VideoRefMedia::VIDEO && v.index == m.index);
|
||||
if (!paired)
|
||||
return *err = err_bad(m.name, "'" + m.name + "' is the soundtrack of a reference "
|
||||
"video; give ref_video_" + std::to_string(m.index) +
|
||||
" with it"), -1;
|
||||
}
|
||||
std::stable_sort(refs.begin(), refs.end(),
|
||||
[](const gen::VideoRefMedia& a, const gen::VideoRefMedia& b) {
|
||||
return a.kind != b.kind ? a.kind < b.kind : a.index < b.index;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* A video model's capabilities on /v1/models and /server_info: the counts validate_refs applies,
|
||||
* the samplers and the model's shifts. */
|
||||
void Server::video_caps(json& caps, const IVideoGen* gen) {
|
||||
const VideoGenInfo& info = gen->info();
|
||||
caps["video_max_text"] = info.max_text;
|
||||
caps["video_max_ref_images"] = std::min(kMaxRefImages, (int32_t)info.max_ref_images);
|
||||
caps["video_max_ref_videos"] = std::min(kMaxRefVideos, (int32_t)info.max_ref_videos);
|
||||
caps["video_max_ref_audios"] = std::min(kMaxRefAudios, (int32_t)info.max_ref_audios);
|
||||
caps["video_samplers"] = json::array({ "euler", "res_multistep" });
|
||||
caps["video_shift"] = info.shift_video;
|
||||
caps["video_audio_shift"] = info.shift_audio;
|
||||
}
|
||||
|
||||
HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
if (!deps_.videos || !deps_.tok)
|
||||
return error_response(err_not_implemented(
|
||||
@@ -153,8 +271,14 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
req.peer);
|
||||
const VideoGenInfo& info = deps_.videos->info();
|
||||
|
||||
const bool takes_refs = info.max_ref_images > 0 || info.max_ref_videos > 0 ||
|
||||
info.max_ref_audios > 0;
|
||||
/* JSON, or a form whose fields are strings (OpenAI's clients send the create call as a form,
|
||||
* since it may carry a file). */
|
||||
* since it may carry a file). Reference media and keyframes are file parts, collected here and
|
||||
* checked once the task is known. */
|
||||
std::vector<gen::VideoRefMedia> refs;
|
||||
/* The keyframes, `first_frame` and `last_frame`. */
|
||||
std::vector<gen::VideoRefMedia> keys;
|
||||
json body = json::object();
|
||||
std::vector<uint8_t> ref_bytes;
|
||||
bool has_ref = false;
|
||||
@@ -165,9 +289,32 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
has_ref = true;
|
||||
continue;
|
||||
}
|
||||
if (!p.filename.empty())
|
||||
return error_response(err_bad(p.name, "'" + p.name + "' takes text, not a file"),
|
||||
req.peer);
|
||||
if (p.name == "first_frame" || p.name == "last_frame") {
|
||||
if (p.filename.empty())
|
||||
return error_response(err_bad(p.name, "'" + p.name + "' must carry an image "
|
||||
"file"), req.peer);
|
||||
gen::VideoRefMedia m;
|
||||
m.kind = p.name == "first_frame" ? gen::VideoRefMedia::FIRST_FRAME
|
||||
: gen::VideoRefMedia::LAST_FRAME;
|
||||
m.name = p.name;
|
||||
m.filename = p.filename;
|
||||
m.content_type = p.content_type;
|
||||
m.data = p.data;
|
||||
keys.push_back(std::move(m));
|
||||
continue;
|
||||
}
|
||||
if (!p.filename.empty()) {
|
||||
gen::VideoRefMedia m;
|
||||
if (!parse_ref_name(p.name, &m.kind, &m.index))
|
||||
return error_response(err_bad(p.name, "'" + p.name + "' takes text, not a "
|
||||
"file"), req.peer);
|
||||
m.name = p.name;
|
||||
m.filename = p.filename;
|
||||
m.content_type = p.content_type;
|
||||
m.data = p.data;
|
||||
refs.push_back(std::move(m));
|
||||
continue;
|
||||
}
|
||||
json v = p.data;
|
||||
if (p.name == "target" || p.name == "conditions" ||
|
||||
((p.name == "loras" || p.name == "lora") && !p.data.empty() &&
|
||||
@@ -186,6 +333,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
static const char* kKnown[] = {
|
||||
"model", "prompt", "seconds", "size", "input_reference", "seed", "num_inference_steps",
|
||||
"task", "target", "conditions", "user", "latent_upscale", "upscale_refine_steps",
|
||||
"sampler", "shift", "audio_shift", "first_frame_mode",
|
||||
"negative_prompt", "decoder", "loras", "lora",
|
||||
/* RadVideoGenBatch::guidance_h's order */
|
||||
"guidance_scale", "stg_scale", "modality_scale", "guidance_rescale",
|
||||
@@ -243,19 +391,104 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
has_ref = true;
|
||||
}
|
||||
if (has_ref && !info.image_cond)
|
||||
return error_response(err_unsupported("input_reference", "this model makes video from "
|
||||
"text only"), req.peer);
|
||||
const std::string task_want = has_ref ? "i2va" : "t2va";
|
||||
if (has(body, "task") && (!body["task"].is_string() ||
|
||||
body["task"].get<std::string>() != task_want)) {
|
||||
ApiError e = err_unsupported("task", has_ref ? "a video from a picture is i2va"
|
||||
: "this request makes video from text: t2va");
|
||||
e.supported = { task_want };
|
||||
return error_response(err_unsupported("input_reference", takes_refs
|
||||
? "this server reads reference media as ref_image_N "
|
||||
"file parts"
|
||||
: "this model makes video from text only"), req.peer);
|
||||
/* With `input_reference` the task is i2va. */
|
||||
if (has_ref && has(body, "task") && (!body["task"].is_string() ||
|
||||
body["task"].get<std::string>() != "i2va")) {
|
||||
ApiError e = err_unsupported("task", "a video from a picture is i2va");
|
||||
e.supported = { "i2va" };
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
/* Otherwise t2va, or what the model takes: ref2va with reference media, the keyframe tasks
|
||||
* with a video encoder. */
|
||||
bool ref2va = false;
|
||||
std::string kf_task; /* a keyframe task named */
|
||||
if (!has_ref && has(body, "task")) {
|
||||
const std::string task = body["task"].is_string() ? body["task"].get<std::string>() : "";
|
||||
if (task == "ref2va" && takes_refs) ref2va = true;
|
||||
/* The parts say which frames there are; a named task is checked against them below. */
|
||||
else if (info.max_enc_side > 0 && (task == "i2va" || task == "l2va" || task == "fl2va"))
|
||||
kf_task = task;
|
||||
else if (task != "t2va") {
|
||||
std::string what = "this server makes video from text";
|
||||
std::vector<std::string> sup{ "t2va" };
|
||||
if (info.image_cond) { what += ", from a picture"; sup.push_back("i2va"); }
|
||||
if (info.max_enc_side > 0) {
|
||||
what += ", or between keyframes";
|
||||
for (const char* k : { "i2va", "l2va", "fl2va" })
|
||||
if (std::find(sup.begin(), sup.end(), std::string(k)) == sup.end())
|
||||
sup.push_back(k);
|
||||
}
|
||||
if (takes_refs) { what += ", from reference media"; sup.push_back("ref2va"); }
|
||||
what += ": ";
|
||||
for (size_t i = 0; i < sup.size(); ++i) what += (i ? ", " : "") + sup[i];
|
||||
ApiError e = err_unsupported("task", what);
|
||||
e.supported = sup;
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
}
|
||||
if (has(body, "conditions") && (!body["conditions"].is_array() || !body["conditions"].empty()))
|
||||
return error_response(err_unsupported("conditions", "this server makes video from text "
|
||||
"only; conditions must be empty"), req.peer);
|
||||
return error_response(err_unsupported("conditions", takes_refs
|
||||
? "reference media arrive as ref_* file parts; "
|
||||
"conditions must be empty"
|
||||
: "this server makes video from text only; "
|
||||
"conditions must be empty"), req.peer);
|
||||
/* Reference parts without task ref2va are a mistake about the task. */
|
||||
if (!refs.empty() && !ref2va)
|
||||
return bad("task", "reference files are given: send them with task ref2va, or send "
|
||||
"none");
|
||||
if (ref2va) {
|
||||
ApiError e;
|
||||
if (validate_refs(refs, info, &e) < 0) return error_response(e, req.peer);
|
||||
}
|
||||
/* At most one keyframe of each, not with reference media, and only with a video encoder. */
|
||||
{
|
||||
int n_first = 0, n_last = 0;
|
||||
for (const gen::VideoRefMedia& m : keys)
|
||||
if (m.kind == gen::VideoRefMedia::FIRST_FRAME) ++n_first; else ++n_last;
|
||||
if (n_first > 1) return bad("first_frame", "at most one first_frame part");
|
||||
if (n_last > 1) return bad("last_frame", "at most one last_frame part");
|
||||
/* A keyframe's <Picture N> counts the pictures present, as ComfyUI numbers them: a last
|
||||
* frame alone is <Picture 1>. */
|
||||
for (gen::VideoRefMedia& m : keys)
|
||||
m.index = m.kind == gen::VideoRefMedia::LAST_FRAME && n_first ? 2 : 1;
|
||||
if (!keys.empty()) {
|
||||
if (info.max_enc_side <= 0)
|
||||
return bad("first_frame", "this model has no video encoder, so it cannot pin a "
|
||||
"keyframe");
|
||||
if (!refs.empty())
|
||||
return bad("first_frame", "a keyframe completion conditions on its pinned frames, "
|
||||
"not on reference media: give first_frame/last_frame or "
|
||||
"the ref_* parts, not both");
|
||||
}
|
||||
/* A named keyframe task carries its frames. */
|
||||
if (!kf_task.empty()) {
|
||||
if ((kf_task == "i2va" || kf_task == "fl2va") && n_first < 1)
|
||||
return bad("first_frame", "task '" + kf_task + "' pins a first frame: give a "
|
||||
"first_frame part");
|
||||
if ((kf_task == "l2va" || kf_task == "fl2va") && n_last < 1)
|
||||
return bad("last_frame", "task '" + kf_task + "' pins a last frame: give a "
|
||||
"last_frame part");
|
||||
}
|
||||
}
|
||||
/* How the first frame is fitted to the video: stretched, as ComfyUI does, or `center`, scaled
|
||||
* to cover it and cropped. The last frame is always cropped, as ComfyUI does. */
|
||||
bool first_center = false;
|
||||
if (has(body, "first_frame_mode")) {
|
||||
const std::string fm = body["first_frame_mode"].is_string()
|
||||
? body["first_frame_mode"].get<std::string>() : "";
|
||||
if (fm.empty() || fm == "stretch")
|
||||
;
|
||||
else if (fm == "center")
|
||||
first_center = true;
|
||||
else
|
||||
return bad("first_frame_mode", "expected \"stretch\" (the reference's own resize) "
|
||||
"or \"center\" (keep the anchor's aspect, crop the "
|
||||
"canvas)");
|
||||
}
|
||||
json target = json::object();
|
||||
if (has(body, "target")) {
|
||||
if (!body["target"].is_object()) return bad("target", "expected an object");
|
||||
@@ -384,6 +617,34 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
(unit + 1) + ")");
|
||||
r->steps = (int32_t)v;
|
||||
}
|
||||
if (has(body, "sampler")) {
|
||||
const std::string sm = body["sampler"].is_string() ? body["sampler"].get<std::string>() : "";
|
||||
if (sm.empty() || sm == "euler") r->sampler = RAD_SAMPLER_EULER;
|
||||
else if (sm == "res_multistep") r->sampler = RAD_SAMPLER_RES_MULTISTEP;
|
||||
else {
|
||||
ApiError e = err_unsupported("sampler", "the sampler is euler (first order) or "
|
||||
"res_multistep (second order on the clean "
|
||||
"estimate)");
|
||||
e.supported = { "euler", "res_multistep" };
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
}
|
||||
/* Each stream's schedule shift; any positive shift is safe, and (0, 100] refuses typos. */
|
||||
if (has(body, "shift")) {
|
||||
double v = 0;
|
||||
if (!number(body["shift"], &v) || !(v > 0.0) || v > 100.0)
|
||||
return bad("shift", "the video schedule shift: a number in (0, 100], or omit it to run "
|
||||
"the model's trained shift " + rad::fmt("%g", info.shift_video));
|
||||
r->shift_video = v;
|
||||
}
|
||||
if (has(body, "audio_shift")) {
|
||||
double v = 0;
|
||||
if (!number(body["audio_shift"], &v) || !(v > 0.0) || v > 100.0)
|
||||
return bad("audio_shift", "the soundtrack schedule shift: a number in (0, 100], or "
|
||||
"omit it to run the model's trained shift " +
|
||||
rad::fmt("%g", info.shift_audio));
|
||||
r->shift_audio = v;
|
||||
}
|
||||
/* ---- guidance */
|
||||
static const char* kGuide[8] = {
|
||||
"guidance_scale", "stg_scale", "modality_scale", "guidance_rescale",
|
||||
@@ -442,25 +703,139 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
std::random_device rd;
|
||||
r->seed = (((uint64_t)rd() << 32) ^ rd()) & (((uint64_t)1 << 53) - 1);
|
||||
}
|
||||
r->refs = std::move(refs);
|
||||
/* The keyframes after the references, the first before the last. */
|
||||
std::stable_sort(keys.begin(), keys.end(), [](const gen::VideoRefMedia& a,
|
||||
const gen::VideoRefMedia& b) {
|
||||
return a.kind < b.kind;
|
||||
});
|
||||
r->refs.insert(r->refs.end(), keys.begin(), keys.end());
|
||||
const bool has_keys = !keys.empty();
|
||||
|
||||
/* ---- the prompt: the template's text with special tokens, the prompt without */
|
||||
/* Pixels as the VAE encoders take them: RGB in 0..255, frame after frame. */
|
||||
auto pixels = [](gen::VideoRefMedia& m, const std::vector<mm::Frame>& fr) {
|
||||
m.enc_frames = (int32_t)fr.size();
|
||||
m.enc_h = fr.front().h;
|
||||
m.enc_w = fr.front().w;
|
||||
m.enc_pixels.clear();
|
||||
for (const mm::Frame& f : fr) m.enc_pixels.insert(m.enc_pixels.end(), f.rgb.begin(),
|
||||
f.rgb.end());
|
||||
};
|
||||
|
||||
/* A keyframe is decoded once, onto the output canvas, and that frame serves both the VAE pin
|
||||
* and the vision tower, as in ComfyUI: the tower sees the pixels that are pinned, not the file
|
||||
* at its own size. The first frame is stretched unless first_frame_mode=center, the last is
|
||||
* centre-cropped. `canvas` parallels r->refs. */
|
||||
std::vector<mm::Frame> canvas;
|
||||
if (has_keys && deps_.mm) {
|
||||
canvas.resize(r->refs.size());
|
||||
for (size_t i = 0; i < r->refs.size(); ++i) {
|
||||
gen::VideoRefMedia& m = r->refs[i];
|
||||
if (m.kind != gen::VideoRefMedia::FIRST_FRAME &&
|
||||
m.kind != gen::VideoRefMedia::LAST_FRAME)
|
||||
continue;
|
||||
std::string why;
|
||||
if (deps_.mm->encoder_image_canvas((const uint8_t*)m.data.data(), m.data.size(),
|
||||
(int32_t)W, (int32_t)H,
|
||||
m.kind == gen::VideoRefMedia::LAST_FRAME ||
|
||||
first_center,
|
||||
&canvas[i], &why) < 0)
|
||||
return bad(m.name.c_str(), "'" + m.name + "' could not be decoded: " + why);
|
||||
pixels(m, { canvas[i] });
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- the prompt: the template's text with special tokens, the media in ComfyUI's order, the
|
||||
* prompt without. A picture is its `<Picture N>: ` label, encoded on its own, then its
|
||||
* tokens; a video its soundtrack's `<Audio N>: ` label if it has one, then its `<Video N>: `;
|
||||
* a soundtrack its `<Audio N>: `, numbered with the videos' soundtracks. Only the pictures are
|
||||
* shown to the text encoder: videos and soundtracks reach the model through the VAEs. */
|
||||
{
|
||||
static const std::string kSlot = "{prompt}";
|
||||
const std::string& t = info.tmpl;
|
||||
const size_t p = t.find(kSlot);
|
||||
auto render = [&](const std::string& text, std::vector<int32_t>* out) {
|
||||
auto put = [&](const std::string& s, bool special) {
|
||||
if (s.empty()) return;
|
||||
const auto ids = deps_.tok->encode(s, false, special);
|
||||
out->insert(out->end(), ids.begin(), ids.end());
|
||||
};
|
||||
put(t.substr(0, p), true);
|
||||
put(text, false);
|
||||
put(t.substr(p + kSlot.size()), true);
|
||||
auto put = [&](std::vector<int32_t>* out, const std::string& s, bool special) {
|
||||
if (s.empty()) return;
|
||||
const auto ids = deps_.tok->encode(s, false, special);
|
||||
out->insert(out->end(), ids.begin(), ids.end());
|
||||
};
|
||||
render(prompt, &r->tokens);
|
||||
auto render = [&](const std::string& text, std::vector<int32_t>* out) {
|
||||
put(out, t.substr(0, p), true);
|
||||
put(out, text, false);
|
||||
put(out, t.substr(p + kSlot.size()), true);
|
||||
};
|
||||
if ((ref2va || has_keys) && deps_.mm && deps_.mm->accepts(MediaKind::Image)) {
|
||||
/* Every picture is processed before any token is laid down. ComfyUI also shows the text
|
||||
* encoder a video's frames at 2 fps, which this does not. */
|
||||
std::vector<std::shared_ptr<mm::Item>> pics;
|
||||
MediaOpts mo;
|
||||
mo.max_pixels = (int64_t)W * (int64_t)H; /* scaled to the video's area */
|
||||
/* A keyframe is shown to the tower as well as pinned, as its canvas frame. */
|
||||
auto anchor = [](const gen::VideoRefMedia& m) {
|
||||
return m.kind == gen::VideoRefMedia::IMAGE ||
|
||||
m.kind == gen::VideoRefMedia::FIRST_FRAME ||
|
||||
m.kind == gen::VideoRefMedia::LAST_FRAME;
|
||||
};
|
||||
auto keyframe = [](const gen::VideoRefMedia& m) {
|
||||
return m.kind == gen::VideoRefMedia::FIRST_FRAME ||
|
||||
m.kind == gen::VideoRefMedia::LAST_FRAME;
|
||||
};
|
||||
for (size_t i = 0; i < r->refs.size(); ++i) {
|
||||
const gen::VideoRefMedia& m = r->refs[i];
|
||||
if (!anchor(m)) continue;
|
||||
std::shared_ptr<mm::Item> it;
|
||||
std::string why;
|
||||
int rc;
|
||||
if (keyframe(m) && !canvas.empty() && canvas[i].w > 0)
|
||||
rc = deps_.mm->prepare_frame(canvas[i], &it, &why);
|
||||
else {
|
||||
const std::vector<uint8_t> bytes(m.data.begin(), m.data.end());
|
||||
rc = deps_.mm->prepare(MediaKind::Image, bytes, mo, &it, &why);
|
||||
}
|
||||
if (rc < 0 || !it)
|
||||
return bad(m.name.c_str(), "'" + m.name + "' could not be used: " + why);
|
||||
pics.push_back(std::move(it));
|
||||
}
|
||||
auto has_soundtrack = [&](int32_t idx) {
|
||||
for (const gen::VideoRefMedia& m : r->refs)
|
||||
if (m.kind == gen::VideoRefMedia::VIDEO_AUDIO && m.index == idx) return true;
|
||||
return false;
|
||||
};
|
||||
put(&r->tokens, t.substr(0, p), true);
|
||||
std::shared_ptr<mm::PromptMedia> media;
|
||||
if (!pics.empty()) media = std::make_shared<mm::PromptMedia>();
|
||||
size_t i = 0;
|
||||
for (const gen::VideoRefMedia& m : r->refs) {
|
||||
if (!anchor(m)) continue;
|
||||
put(&r->tokens, "<Picture " + std::to_string(m.index) + ">: ", false);
|
||||
mm::Placed pl;
|
||||
pl.item = pics[i++];
|
||||
pl.tok = (int32_t)r->tokens.size();
|
||||
r->tokens.insert(r->tokens.end(), pl.item->expand.begin(),
|
||||
pl.item->expand.end());
|
||||
media->items.push_back(std::move(pl));
|
||||
}
|
||||
int audio_ord = 0;
|
||||
for (const gen::VideoRefMedia& m : r->refs) {
|
||||
if (m.kind != gen::VideoRefMedia::VIDEO) continue;
|
||||
if (has_soundtrack(m.index))
|
||||
put(&r->tokens, "<Audio " + std::to_string(++audio_ord) + ">: ", false);
|
||||
put(&r->tokens, "<Video " + std::to_string(m.index) + ">: ", false);
|
||||
}
|
||||
for (const gen::VideoRefMedia& m : r->refs) {
|
||||
if (m.kind != gen::VideoRefMedia::AUDIO) continue;
|
||||
put(&r->tokens, "<Audio " + std::to_string(++audio_ord) + ">: ", false);
|
||||
}
|
||||
if (media) { media->layout(); r->media = std::move(media); }
|
||||
put(&r->tokens, prompt, false);
|
||||
put(&r->tokens, t.substr(p + kSlot.size()), true);
|
||||
} else {
|
||||
render(prompt, &r->tokens);
|
||||
}
|
||||
if ((int64_t)r->tokens.size() > info.max_text)
|
||||
return bad("prompt", "the prompt is " + std::to_string(r->tokens.size()) +
|
||||
return bad("prompt", "the prompt" + std::string((ref2va || has_keys)
|
||||
? " with its media" : "") +
|
||||
" is " + std::to_string(r->tokens.size()) +
|
||||
" tokens; this model takes at most " +
|
||||
std::to_string(info.max_text));
|
||||
if (info.guidance) {
|
||||
@@ -509,6 +884,43 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
std::memcpy(&r->image[3 * i], &sized.rgba[4 * i], 3);
|
||||
}
|
||||
|
||||
/* ---- every reference as its VAE encoder takes it (the keyframes are done above): pictures and
|
||||
* video frames fitted to the encoder's bounds, soundtracks as mono samples at the model's rate,
|
||||
* one copy a channel. The driver pads both to the encoders' clips and hops. */
|
||||
if ((ref2va || !keys.empty()) && deps_.mm) {
|
||||
for (gen::VideoRefMedia& m : r->refs) {
|
||||
std::string why;
|
||||
const uint8_t* p = (const uint8_t*)m.data.data();
|
||||
const size_t n = m.data.size();
|
||||
std::vector<mm::Frame> fr(1);
|
||||
int st = 0;
|
||||
if (m.kind == gen::VideoRefMedia::FIRST_FRAME || m.kind == gen::VideoRefMedia::LAST_FRAME)
|
||||
continue;
|
||||
if (m.kind == gen::VideoRefMedia::IMAGE)
|
||||
st = deps_.mm->encoder_image(p, n, (int32_t)info.enc_ratio,
|
||||
(int32_t)info.max_enc_side, &fr[0], &why);
|
||||
else if (m.kind == gen::VideoRefMedia::VIDEO)
|
||||
st = deps_.mm->encoder_video(p, n, (int32_t)info.enc_ratio,
|
||||
(int32_t)info.max_enc_side,
|
||||
(int32_t)info.max_enc_frames, &fr, &why);
|
||||
else {
|
||||
std::vector<float> mono;
|
||||
if (deps_.mm->encoder_audio(p, n, (int32_t)info.sample_rate, info.max_enc_samples,
|
||||
&mono, &why) < 0 || mono.empty())
|
||||
return bad(m.name.c_str(), "'" + m.name + "' could not be decoded: " + why);
|
||||
m.enc_channels = (int32_t)info.channels;
|
||||
m.enc_n = (int64_t)mono.size();
|
||||
m.enc_samples.clear();
|
||||
for (int32_t c = 0; c < m.enc_channels; ++c)
|
||||
m.enc_samples.insert(m.enc_samples.end(), mono.begin(), mono.end());
|
||||
continue;
|
||||
}
|
||||
if (st < 0 || fr.empty())
|
||||
return bad(m.name.c_str(), "'" + m.name + "' could not be decoded: " + why);
|
||||
pixels(m, fr);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- admitted and queued: the job holds its place until its file is written */
|
||||
if (!loras.empty()) {
|
||||
std::string why, note;
|
||||
@@ -529,6 +941,14 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
j->size = std::to_string(W) + "x" + std::to_string(H);
|
||||
j->created_at = unix_now();
|
||||
j->seed = r->seed;
|
||||
j->sampler = r->sampler;
|
||||
j->shift_video = r->shift_video;
|
||||
j->shift_audio = r->shift_audio;
|
||||
for (const gen::VideoRefMedia& m : r->refs) j->refs.push_back(m.name);
|
||||
if (ref2va) j->task = "ref2va";
|
||||
else if (keys.size() == 2) j->task = "fl2va";
|
||||
else if (!keys.empty())
|
||||
j->task = keys[0].kind == gen::VideoRefMedia::FIRST_FRAME ? "i2va" : "l2va";
|
||||
j->ticket = std::make_shared<gen::VideoTicket>();
|
||||
r->ticket = j->ticket;
|
||||
const int64_t n_tok = (int64_t)r->tokens.size();
|
||||
@@ -557,7 +977,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
j->refine = tk.refine;
|
||||
j->upscale_from = std::to_string(tk.small_width) + "x" + std::to_string(tk.small_height);
|
||||
}
|
||||
RAD_INFO("video %s: %s, %s, %lld prompt tokens, %d steps%s, seed=%llu",
|
||||
RAD_INFO("video %s: %s, %s, %lld prompt tokens, %d steps%s%s, seed=%llu",
|
||||
j->id.c_str(), j->size.c_str(),
|
||||
auto_len ? "the length the model chooses"
|
||||
: rad::fmt("%lld frames (%s s)", (long long)frames, j->seconds.c_str()).c_str(),
|
||||
@@ -566,6 +986,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
(int)(tk.steps - tk.refine), (int)tk.small_width,
|
||||
(int)tk.small_height, (int)tk.refine).c_str()
|
||||
: "",
|
||||
j->refs.empty() ? "" : rad::fmt(", %zu reference parts", j->refs.size()).c_str(),
|
||||
(unsigned long long)j->seed);
|
||||
std::lock_guard<std::mutex> lk(videos_m_);
|
||||
sweep_videos_locked(unix_now());
|
||||
@@ -597,9 +1018,24 @@ void Server::video_work(std::shared_ptr<VideoJob> j) {
|
||||
continue;
|
||||
}
|
||||
if (e.kind == gen::VideoEvent::STEP) {
|
||||
const int64_t now = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
std::lock_guard<std::mutex> lk(videos_m_);
|
||||
j->status = "in_progress";
|
||||
j->progress = t.steps > 0 ? (int)(90LL * e.steps_done / t.steps) : 0;
|
||||
j->steps_done = e.steps_done;
|
||||
j->steps_total = t.steps;
|
||||
if (!j->step_ns0) j->step_ns0 = now;
|
||||
/* A line a step, its rate the mean since the first step, so the eta of an upscaled
|
||||
* video, whose small steps are faster, is an estimate. */
|
||||
const double el = (double)(now - j->step_ns0) / 1e9;
|
||||
const double per = e.steps_done > 1 ? el / (e.steps_done - 1) : 0.0;
|
||||
if (per > 0)
|
||||
RAD_INFO("video %s: step %d/%d, %.2f s/step, eta %.0f s",
|
||||
j->id.c_str(), e.steps_done, t.steps, per,
|
||||
per * (double)(t.steps - e.steps_done));
|
||||
else
|
||||
RAD_INFO("video %s: step %d/%d", j->id.c_str(), e.steps_done, t.steps);
|
||||
} else if (e.kind == gen::VideoEvent::LENGTH) {
|
||||
std::lock_guard<std::mutex> lk(videos_m_);
|
||||
j->seconds = rad::fmt("%.2f", (double)e.n * info.fps_den / info.fps_num);
|
||||
@@ -715,6 +1151,10 @@ json Server::video_json(const VideoJob& j) {
|
||||
o["model"] = j.model;
|
||||
o["status"] = j.status;
|
||||
o["progress"] = j.progress;
|
||||
if (j.steps_total > 0) {
|
||||
o["steps_done"] = j.steps_done;
|
||||
o["steps_total"] = j.steps_total;
|
||||
}
|
||||
o["created_at"] = j.created_at;
|
||||
o["completed_at"] = j.completed_at ? json(j.completed_at) : json(nullptr);
|
||||
o["expires_at"] = j.expires_at ? json(j.expires_at) : json(nullptr);
|
||||
@@ -722,11 +1162,18 @@ json Server::video_json(const VideoJob& j) {
|
||||
o["seconds"] = j.seconds;
|
||||
o["size"] = j.size;
|
||||
o["seed"] = j.seed;
|
||||
o["sampler"] = j.sampler == RAD_SAMPLER_RES_MULTISTEP ? "res_multistep" : "euler";
|
||||
if (j.shift_video > 0.0) o["shift"] = j.shift_video;
|
||||
if (j.shift_audio > 0.0) o["audio_shift"] = j.shift_audio;
|
||||
if (j.refine > 0) {
|
||||
o["latent_upscale"] = j.upscale;
|
||||
o["upscale_refine_steps"] = j.refine;
|
||||
o["upscale_from"] = j.upscale_from;
|
||||
}
|
||||
if (!j.refs.empty()) {
|
||||
o["task"] = j.task;
|
||||
o["refs"] = j.refs;
|
||||
}
|
||||
if (j.guided) {
|
||||
static const char* kGuide[8] = {
|
||||
"guidance_scale", "stg_scale", "modality_scale", "guidance_rescale",
|
||||
|
||||
Reference in new issue
Block a user