radiance 1.8.1

- MiniMax-H3 and FastH3 no longer stop the server on a prompt longer than 16 tokens (FastH3) or
  128 tokens (MiniMax-H3)
- latent upscaling for the MiniMax-H3 containers: with LBH-123-AI's latent upscaler in the
  container, `latent_upscale` runs the first steps at a smaller size and refines the latent at the
  full size; `upscale_refine_steps` sets how many steps refine, and the video object reports both
- rad-convert --in-place extends a container whose weights the plugin has regrouped since
- plugin ABI 22: out-of-tree plugins must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-18 15:41:44 +02:00
1 parent 7a7707a955
commit 816e24bd46
43 files changed
+4458 -81

No files matched your search

+11
View File
@@ -1484,6 +1484,17 @@ int Builder::declare_video_generator(const RadVideoGenDecl* d) {
"below the one before it", nm, i, d->rungs[i]);
return RAD_E_INVAL;
}
/* An upscaler needs a schedule it can split: one evaluation at the small size at least, and
* `upscale_refine` of them after it by default. */
const int64_t def_evals = d->n_rungs > 0 ? d->n_rungs : d->default_steps - 1;
if (d->upscale_max != 0.0 &&
(!(d->upscale_max > 1.0) || d->upscale_refine < 1 || d->upscale_refine >= def_evals)) {
err(RAD_E_INVAL, "declare_video_generator '%s': a latent upscaler of factor %g at most, "
"refining %d evaluations of %lld by default; the factor must be above 1 "
"and the refinement 1 to %lld", nm, d->upscale_max, (int)d->upscale_refine,
(long long)def_evals, (long long)(def_evals - 1));
return RAD_E_INVAL;
}
auto buf_ok = [&](rad_buf h, uint32_t dtype, int64_t numel, const char* what) {
if (h == RAD_NULL_HANDLE || (size_t)h >= prog_.buffers.size()) {
err(RAD_E_INVAL, "declare_video_generator '%s': %s %u is not a declared buffer", nm,
+5
View File
@@ -2495,6 +2495,8 @@ int Engine::run_server() {
in.default_steps = vd.default_steps;
in.max_steps = vd.max_steps;
in.fixed_steps = vd.n_rungs > 0;
in.upscale_max = vd.upscale_max;
in.upscale_refine = vd.upscale_refine;
in.max_lanes = vd.max_lanes;
video_bridge.drv = vid_gen_;
d.videos = &video_bridge;
@@ -2510,6 +2512,9 @@ int Engine::run_server() {
(double)(in.frames_per_chunk * in.min_chunks + in.frames_tail) / fps,
(double)(in.frames_per_chunk * in.max_chunks + in.frames_tail) / fps, fps,
(long long)in.sample_rate, (long long)in.channels, (long long)in.default_steps);
if (in.upscale_max > 0.0)
RAD_INFO("video: latent upscaling up to %gx, the last %lld evaluations at the full size "
"by default", in.upscale_max, (long long)in.upscale_refine);
}
if (encd.modalities == 0 && aend.modalities == 0 && cfg_.media_flags_set())
+1
View File
@@ -28,6 +28,7 @@ static const char* pass_name(int gen) {
case RAD_GEN_PASS_VSTEP: return "vstep";
case RAD_GEN_PASS_ADECODE: return "adecode";
case RAD_GEN_PASS_VDECODE: return "vdecode";
case RAD_GEN_PASS_VUPSCALE: return "vupscale";
default: return "";
}
}
+16 -2
View File
@@ -53,10 +53,14 @@ public:
int32_t frames = 0, width = 0, height = 0, steps = 0;
int64_t sample_rate = 0, channels = 0;
double fps = 0.0;
/* With latent upscaling, the size the first evaluations run at and the evaluations after the
* upscale; zero without. */
int32_t small_width = 0, small_height = 0, refine = 0;
/* Usage, written by the driver before finish(): prompt tokens, rows a step and per-phase
* times. */
* times (t_small_ns the last small step done, t_upscaled_ns the upscale; zero without). */
int64_t in_tokens = 0, rows = 0;
int64_t t_submit_ns = 0, t_cond_ns = 0, t_denoised_ns = 0, t_done_ns = 0;
int64_t t_submit_ns = 0, t_cond_ns = 0, t_small_ns = 0, t_upscaled_ns = 0, t_denoised_ns = 0,
t_done_ns = 0;
private:
mutable std::mutex mu_;
@@ -72,6 +76,10 @@ struct VideoRequest {
int32_t width = 0, height = 0; /* pixels, within the declaration's limits */
int32_t chunks = 0; /* the length in chunks (RadVideoGenDecl) */
int32_t steps = 0; /* sigma grid points; 0: the model's default */
/* Latent upscaling (abi/rad_builder.h, RadVideoGenDecl): the factor, 0 for none, and the
* evaluations at the full size after it, 0 for the model's default. */
double upscale = 0.0;
int32_t refine = 0;
uint64_t seed = 0;
std::shared_ptr<VideoTicket> ticket;
};
@@ -84,6 +92,12 @@ struct VideoShape {
};
VideoShape video_shape(const RadVideoGenDecl& d, int32_t width, int32_t height, int32_t chunks);
/* The small size a request's first evaluations run at under latent upscaling by `factor`: each
* side divided by it and rounded to the nearest multiple of the size multiple, at least one
* multiple and at most the side. */
void video_small_size(const RadVideoGenDecl& d, int32_t width, int32_t height, double factor,
int32_t* small_w, int32_t* small_h);
/* The two schedules a request of `steps` grid points runs (RadVideoGenDecl, "The sampler"): each
* the f32 sigmas, last 0, and the model evaluations it takes, the shorter of the two. With a
* trained schedule any other step count than n_rungs + 1 gives no steps. */
+141 -40
View File
@@ -1,9 +1,11 @@
/* video_driver.cpp -- the video generator's pass driver (video_driver.h), the ticket a caller
* waits on, and a request's shape and schedule (video.h). */
#include "video_driver.h"
#include "rad_internal.h"
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
namespace rad {
@@ -77,6 +79,17 @@ VideoShape video_shape(const RadVideoGenDecl& d, int32_t width, int32_t height,
return s;
}
void video_small_size(const RadVideoGenDecl& d, int32_t width, int32_t height, double factor,
int32_t* small_w, int32_t* small_h) {
const int64_t m = d.size_multiple;
auto side = [&](int32_t full) {
const int64_t k = (int64_t)std::floor((double)full / factor / (double)m + 0.5);
return (int32_t)(std::min<int64_t>(std::max<int64_t>(k, 1), full / m) * m);
};
*small_w = side(width);
*small_h = side(height);
}
/* The shift of one base time, in f32 as the reference's tensor arithmetic. */
static float shift_sigma(double shift, float b) {
const float sh = (float)shift, sh1 = (float)(shift - 1.0);
@@ -147,6 +160,7 @@ int64_t carve(const RadVideoGenDecl& d, int64_t max_tok, int64_t (*bytes)[2], in
4, /* R_FIRST */
4 * 4, /* R_SEG */
4 * 4, /* R_LAT */
4, /* R_UP */
};
int64_t off = 0;
for (int r = 0; r < n; ++r) {
@@ -304,6 +318,43 @@ int VideoDriver::submit(std::unique_ptr<VideoRequest> r, std::string* why) {
return no("the model could not lay this video out");
j->sched = video_schedule(d, steps);
if (j->sched.steps < 1) return no("the schedule has no steps");
if (r->upscale > 1.0) {
if (!(d.upscale_max > 1.0)) return no("this model has no latent upscaler");
if (r->upscale > d.upscale_max)
return no("latent_upscale is at most " + fmt("%g", d.upscale_max) + " for this model");
int32_t sw = 0, sh = 0;
video_small_size(d, r->width, r->height, r->upscale, &sw, &sh);
if (sw == r->width && sh == r->height)
return no("latent_upscale " + fmt("%g", r->upscale) + " leaves " +
std::to_string(r->width) + "x" + std::to_string(r->height) + " as it is: "
"the small size is each side over the factor, rounded to a multiple of " +
std::to_string(d.size_multiple));
const int32_t evals = j->sched.steps;
int32_t refine = r->refine;
if (refine == 0) refine = std::min<int32_t>(d.upscale_refine, evals - 1);
if (refine < 1 || refine >= evals)
return no("upscale_refine_steps must be 1.." + std::to_string(evals - 1) + ": the "
"schedule takes " + std::to_string(evals) + " evaluations and the small "
"size at least one of them");
const VideoShape ss = video_shape(d, sw, sh, r->chunks);
j->geom_small = j->geom;
j->geom_small.lat_h = ss.lat_h;
j->geom_small.lat_w = ss.lat_w;
j->rows_small = T + ss.audio_rows + ss.video_rows;
const int64_t ns = positions_(RAD_VPOS_STEP, &j->geom_small, nullptr, 0);
if (ns != j->rows_small)
return no("the model lays the small size " + std::to_string(sw) + "x" +
std::to_string(sh) + " out in " + std::to_string(ns) + " step rows, which "
"this server cannot run");
j->pos_small.assign((size_t)(3 * ns), 0.0f);
if (positions_(RAD_VPOS_STEP, &j->geom_small, j->pos_small.data(), ns) != ns)
return no("the model could not lay the small size out");
j->split = evals - refine;
j->factor = (float)(((double)r->width / sw + (double)r->height / sh) / 2.0);
r->ticket->small_width = sw;
r->ticket->small_height = sh;
r->ticket->refine = refine;
}
j->n_chunks = r->chunks;
j->n_samples = (int64_t)s.n_audio * (d.sample_rate / d.audio_rate);
@@ -391,35 +442,46 @@ int VideoDriver::upload() {
return RAD_OK;
}
/* The geometry a pass's ops read off the device (RAD_VGEOM_*), with chunk `chunk`'s span when it
* is a decode's. */
void VideoDriver::stage_geom(const Job& j, int32_t chunk) {
/* The geometry a pass's ops read off the device (RAD_VGEOM_*) for a pass at geometry `g` of
* `rows` step rows, with chunk `chunk`'s span when it is a decode's and both grids when the job
* upscales. */
void VideoDriver::stage_geom(const Job& j, const RadVideoGeom& g0, int64_t rows, int32_t chunk) {
int32_t* g = hptr<int32_t>(R_GEOM);
std::memset(g, 0, RAD_VGEOM_N * 4);
g[RAD_VGEOM_LAT_FRAMES] = j.geom.lat_frames;
g[RAD_VGEOM_LAT_H] = j.geom.lat_h;
g[RAD_VGEOM_LAT_W] = j.geom.lat_w;
g[RAD_VGEOM_N_TEXT] = j.geom.n_text;
g[RAD_VGEOM_N_AUDIO] = j.geom.n_audio;
g[RAD_VGEOM_LAT_FRAMES] = g0.lat_frames;
g[RAD_VGEOM_LAT_H] = g0.lat_h;
g[RAD_VGEOM_LAT_W] = g0.lat_w;
g[RAD_VGEOM_N_TEXT] = g0.n_text;
g[RAD_VGEOM_N_AUDIO] = g0.n_audio;
g[RAD_VGEOM_CHUNK_LAT0] = (int32_t)(decl_.latents_per_chunk * chunk);
g[RAD_VGEOM_CHUNK_FRAMES] = (int32_t)decl_.dec_latents;
g[RAD_VGEOM_CHUNK_H] = j.geom.lat_h;
g[RAD_VGEOM_CHUNK_W] = j.geom.lat_w;
g[RAD_VGEOM_CHUNK_H] = g0.lat_h;
g[RAD_VGEOM_CHUNK_W] = g0.lat_w;
g[RAD_VGEOM_CHUNK_FIRST] = chunk == 0;
g[RAD_VGEOM_CHUNK_LAST] = chunk == j.n_chunks - 1;
g[RAD_VGEOM_PATCH_FRAMES] = (int32_t)decl_.dec_latents;
g[RAD_VGEOM_PATCH_H] = (int32_t)(j.geom.lat_h / decl_.patch);
g[RAD_VGEOM_PATCH_W] = (int32_t)(j.geom.lat_w / decl_.patch);
g[RAD_VGEOM_PATCH_H] = (int32_t)(g0.lat_h / decl_.patch);
g[RAD_VGEOM_PATCH_W] = (int32_t)(g0.lat_w / decl_.patch);
if (j.split > 0) {
const RadVideoGeom& a = j.geom_small;
const RadVideoGeom& b = j.geom;
const int32_t p = (int32_t)decl_.patch;
const int32_t up[] = { a.lat_frames, a.lat_h, a.lat_w, b.lat_h, b.lat_w,
b.lat_frames, b.lat_h, b.lat_w,
a.lat_frames, a.lat_h / p, a.lat_w / p,
b.lat_frames, b.lat_h / p, b.lat_w / p };
std::memcpy(g + RAD_VGEOM_UP_SRC, up, sizeof up);
}
reg_[R_GEOM].used = RAD_VGEOM_N * 4;
const int64_t audio_rows = decl_.audio_channels * (int64_t)j.geom.n_audio;
const int64_t video_rows = j.rows - j.geom.n_text - audio_rows;
const int64_t audio_rows = decl_.audio_channels * (int64_t)g0.n_audio;
const int64_t video_rows = rows - g0.n_text - audio_rows;
*hptr<int32_t>(R_LANE) = j.lane;
*hptr<int32_t>(R_FIRST) = j.step == 0;
int32_t* seg = hptr<int32_t>(R_SEG);
seg[0] = 0;
seg[1] = j.geom.n_text;
seg[2] = (int32_t)(j.geom.n_text + audio_rows);
seg[3] = (int32_t)j.rows;
seg[1] = g0.n_text;
seg[2] = (int32_t)(g0.n_text + audio_rows);
seg[3] = (int32_t)rows;
int32_t* lat = hptr<int32_t>(R_LAT);
lat[0] = 0;
lat[1] = (int32_t)video_rows;
@@ -431,7 +493,7 @@ void VideoDriver::stage_geom(const Job& j, int32_t chunk) {
reg_[R_LAT].used = 4 * 4;
}
void VideoDriver::base_batches(const Job& j, int64_t n_tok, int step) {
void VideoDriver::base_batches(const Job& j, const RadVideoGeom& g, int64_t n_tok, int step) {
for (size_t r = 0; r < ranks_.size(); ++r) {
RadBatch& B = out_[r];
RadVideoGenBatch& V = vout_[r];
@@ -448,7 +510,8 @@ void VideoDriver::base_batches(const Job& j, int64_t n_tok, int step) {
B.cu_seqlens = dptr<int32_t>(ri, R_CU);
V = RadVideoGenBatch{};
V.lane = j.lane;
V.geom = j.geom;
V.geom = g;
V.geom_from = j.geom_small;
V.geom_d = dptr<int32_t>(ri, R_GEOM);
V.lane_d = dptr<int32_t>(ri, R_LANE);
V.first_d = dptr<int32_t>(ri, R_FIRST);
@@ -465,6 +528,7 @@ void VideoDriver::base_batches(const Job& j, int64_t n_tok, int step) {
V.n_chunks = j.n_chunks;
V.dec_rows = j.dec_rows;
V.n_samples = j.n_samples;
V.upscale = dptr<float>(ri, R_UP);
B.vgen_b = &V;
}
}
@@ -500,11 +564,12 @@ const RadBatch* VideoDriver::next(int step) {
Job& j = *jp;
if (j.admitted && !j.failed && !j.cond_done) return build_cond(j, step);
}
/* 3. The oldest lane's next step. */
/* 3. The oldest lane's next step, or its upscale once its small steps are done. */
for (auto& jp : jobs_) {
Job& j = *jp;
if (j.admitted && !j.failed && j.cond_done && j.step < j.sched.steps)
return build_step(j, step);
if (!j.admitted || j.failed || !j.cond_done || j.step >= j.sched.steps) continue;
if (small_now(j) && j.step == j.split) return build_upscale(j, step);
return build_step(j, step);
}
return nullptr;
}
@@ -535,30 +600,32 @@ const RadBatch* VideoDriver::build_cond(Job& j, int step) {
reg_[R_CU].used = 2 * 4;
reg_[R_TV].used = j.sched.steps * 4;
reg_[R_TA].used = j.sched.steps * 4;
stage_geom(j, 0);
const RadVideoGeom& g = small_now(j) ? j.geom_small : j.geom;
stage_geom(j, g, small_now(j) ? j.rows_small : j.rows, 0);
if (upload() < 0) return nullptr;
base_batches(j, T, step);
base_batches(j, g, T, step);
for (auto& B : out_) B.gen = RAD_GEN_PASS_VCOND;
pass_.kind = RAD_GEN_PASS_VCOND;
pass_.job = j.id;
return &out_[0];
}
const RadBatch* VideoDriver::build_step(Job& j, int step) {
for (int g = 0; g < R_N; ++g) reg_[g].used = 0;
const int32_t i = j.step;
/* Step i's timesteps and sigmas, the video's then the soundtrack's (RadVideoGenBatch::sched);
* with `to_clean` the next sigmas are 0, so the step lands on its clean estimate. */
void VideoDriver::stage_sched(const Job& j, int32_t i, bool to_clean) {
float* s = hptr<float>(R_SCHED);
s[0] = 1.0f - j.sched.sig_v[(size_t)i];
s[1] = j.sched.sig_v[(size_t)i];
s[2] = j.sched.sig_v[(size_t)i + 1];
s[2] = to_clean ? 0.0f : j.sched.sig_v[(size_t)i + 1];
s[3] = 1.0f - j.sched.sig_a[(size_t)i];
s[4] = j.sched.sig_a[(size_t)i];
s[5] = j.sched.sig_a[(size_t)i + 1];
s[5] = to_clean ? 0.0f : j.sched.sig_a[(size_t)i + 1];
reg_[R_SCHED].used = 6 * 4;
std::memcpy(hptr<float>(R_ROPE), j.pos.data(), j.pos.size() * 4);
reg_[R_ROPE].used = (int64_t)j.pos.size() * 4;
/* The video's noise seed is the request's; the soundtrack's the same with its top bit flipped,
* so the two streams never coincide. */
}
/* The video's noise seed is the request's; the soundtrack's the same with its top bit flipped, so
* the two streams never coincide. */
void VideoDriver::stage_seed(const Job& j) {
uint32_t* sd = hptr<uint32_t>(R_SEED);
const uint64_t seed = j.req->seed;
sd[0] = (uint32_t)seed;
@@ -566,25 +633,54 @@ const RadBatch* VideoDriver::build_step(Job& j, int step) {
sd[2] = (uint32_t)seed;
sd[3] = (uint32_t)(seed >> 32) ^ 0x80000000u;
reg_[R_SEED].used = 4 * 4;
}
const RadBatch* VideoDriver::build_step(Job& j, int step) {
for (int g = 0; g < R_N; ++g) reg_[g].used = 0;
const bool small = small_now(j);
const RadVideoGeom& g = small ? j.geom_small : j.geom;
const int64_t rows = small ? j.rows_small : j.rows;
const std::vector<float>& pos = small ? j.pos_small : j.pos;
stage_sched(j, j.step, small && j.step == j.split - 1);
std::memcpy(hptr<float>(R_ROPE), pos.data(), pos.size() * 4);
reg_[R_ROPE].used = (int64_t)pos.size() * 4;
stage_seed(j);
/* The packed sequence is one attention document. */
int32_t* cu = hptr<int32_t>(R_CU);
cu[0] = 0;
cu[1] = (int32_t)j.rows;
cu[1] = (int32_t)rows;
reg_[R_CU].used = 2 * 4;
stage_geom(j, 0);
stage_geom(j, g, rows, 0);
if (upload() < 0) return nullptr;
base_batches(j, j.rows, step);
base_batches(j, g, rows, step);
for (auto& B : out_) B.gen = RAD_GEN_PASS_VSTEP;
pass_.kind = RAD_GEN_PASS_VSTEP;
pass_.job = j.id;
return &out_[0];
}
/* The small latent to the full size, both latents re-noised to the first full-size step's
* sigmas. */
const RadBatch* VideoDriver::build_upscale(Job& j, int step) {
for (int g = 0; g < R_N; ++g) reg_[g].used = 0;
stage_sched(j, j.split, false);
stage_seed(j);
*hptr<float>(R_UP) = j.factor;
reg_[R_UP].used = 4;
stage_geom(j, j.geom, j.rows, 0);
if (upload() < 0) return nullptr;
base_batches(j, j.geom, 0, step);
for (auto& B : out_) B.gen = RAD_GEN_PASS_VUPSCALE;
pass_.kind = RAD_GEN_PASS_VUPSCALE;
pass_.job = j.id;
return &out_[0];
}
const RadBatch* VideoDriver::build_audio(Job& j, int step) {
for (int g = 0; g < R_N; ++g) reg_[g].used = 0;
stage_geom(j, 0);
stage_geom(j, j.geom, j.rows, 0);
if (upload() < 0) return nullptr;
base_batches(j, 0, step);
base_batches(j, j.geom, 0, step);
for (auto& B : out_) B.gen = RAD_GEN_PASS_ADECODE;
rb_.assign(1, Readback{ decl_.audio_out, j.n_samples * decl_.audio_channels * 4, audio_host_ });
pass_.kind = RAD_GEN_PASS_ADECODE;
@@ -594,9 +690,9 @@ const RadBatch* VideoDriver::build_audio(Job& j, int step) {
const RadBatch* VideoDriver::build_chunk(Job& j, int step) {
for (int g = 0; g < R_N; ++g) reg_[g].used = 0;
stage_geom(j, j.chunk);
stage_geom(j, j.geom, j.rows, j.chunk);
if (upload() < 0) return nullptr;
base_batches(j, j.dec_rows, step);
base_batches(j, j.geom, j.dec_rows, step);
const bool last = j.chunk == j.n_chunks - 1;
const int32_t n = (int32_t)(decl_.frames_per_chunk + (last ? decl_.frames_tail : 0));
for (size_t r = 0; r < out_.size(); ++r) {
@@ -626,9 +722,14 @@ int VideoDriver::done() {
e.kind = VideoEvent::STEP;
e.steps_done = j->step;
j->req->ticket->push(std::move(e));
if (j->split > 0 && j->step == j->split) j->req->ticket->t_small_ns = now;
if (j->step >= j->sched.steps) j->req->ticket->t_denoised_ns = now;
break;
}
case RAD_GEN_PASS_VUPSCALE:
j->upscaled = true;
j->req->ticket->t_upscaled_ns = now;
break;
case RAD_GEN_PASS_ADECODE: {
VideoEvent e;
e.kind = VideoEvent::AUDIO;
+19 -5
View File
@@ -13,8 +13,9 @@
* 1. ADECODE, then each VDECODE chunk in order, of a lane whose denoising is done: they finish
* a request and free its lane.
* 2. VCOND of an admitted request, so its steps can follow the current request's without a gap.
* 3. VSTEP of the oldest lane with steps left. Requests are denoised one after another, not in
* turns: a pass is one request's whole sequence, so taking turns would only delay the first.
* 3. VSTEP of the oldest lane with steps left, or its VUPSCALE once its small steps are done.
* Requests are denoised one after another, not in turns: a pass is one request's whole
* sequence, so taking turns would only delay the first.
*/
#pragma once
#include "video.h"
@@ -67,6 +68,14 @@ private:
int64_t n_samples = 0; /* the soundtrack's samples a channel */
VideoSchedule sched;
std::vector<float> pos; /* [3, rows] */
/* Latent upscaling: the evaluations at the small size (0: none), its geometry, rows and
* positions, the factor the network is told, and whether the upscale has run. */
int32_t split = 0;
RadVideoGeom geom_small{};
int64_t rows_small = 0;
std::vector<float> pos_small;
float factor = 0.0f;
bool upscaled = false;
int32_t lane = -1;
bool admitted = false;
bool cond_done = false;
@@ -87,15 +96,19 @@ private:
/* Staging regions: their offsets in the host span and every rank's slab. */
struct Region { int64_t off = 0, bytes = 0, used = 0; };
enum { R_TOK, R_POS, R_CU, R_ROPE, R_GEOM, R_SCHED, R_TV, R_TA, R_SEED, R_LANE, R_FIRST,
R_SEG, R_LAT, R_N };
R_SEG, R_LAT, R_UP, R_N };
template <class T> T* hptr(int r) const { return reinterpret_cast<T*>(host_ + reg_[r].off); }
template <class T> T* dptr(int rank, int r) const {
return reinterpret_cast<T*>((char*)dev_[(size_t)rank] + reg_[r].off);
}
int upload();
void base_batches(const Job& j, int64_t n_tok, int step);
void stage_geom(const Job& j, int32_t chunk);
/* The geometry and rows of the job's next step: the small ones before its upscale. */
bool small_now(const Job& j) const { return j.split > 0 && !j.upscaled; }
void base_batches(const Job& j, const RadVideoGeom& g, int64_t n_tok, int step);
void stage_geom(const Job& j, const RadVideoGeom& g, int64_t rows, int32_t chunk);
void stage_sched(const Job& j, int32_t i, bool to_clean);
void stage_seed(const Job& j);
void admit_locked();
void release_locked(Job& j);
@@ -104,6 +117,7 @@ private:
const RadBatch* build_cond(Job& j, int step);
const RadBatch* build_step(Job& j, int step);
const RadBatch* build_upscale(Job& j, int step);
const RadBatch* build_audio(Job& j, int step);
const RadBatch* build_chunk(Job& j, int step);
+3
View File
@@ -641,6 +641,9 @@ 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 */
/* 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;
};
class IVideoGen {
+59 -6
View File
@@ -18,6 +18,12 @@
* Nothing that conditions on media is served: `input_reference` and non-empty `conditions` are
* refused.
*
* A model with a latent upscaler also takes `latent_upscale`, a factor from 1 to its largest: the
* first steps run at `size` divided by it and the latent is enlarged to `size` for the last
* `upscale_refine_steps` (the model's default when absent; abi/rad_builder.h, RadVideoGenDecl).
* The video object of an upscaled video says how it was made: the factor, the refine steps and the
* small size (`upscale_from`).
*
* The prompt is the model's template with `{prompt}` filled; the template is tokenised with its
* special tokens and the prompt without, so a caller cannot write control tokens into it.
*/
@@ -55,6 +61,11 @@ struct Server::VideoJob {
std::string err_code, err_message;
std::string mp4;
std::vector<uint8_t> first; /* the first frame, RGB, for the thumbnail */
/* 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;
int32_t refine = 0;
std::string upscale_from;
int32_t w = 0, h = 0;
bool worker_done = false; /* its thread has nothing left to do but return */
};
@@ -142,7 +153,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",
"task", "target", "conditions", "user", "latent_upscale", "upscale_refine_steps",
};
for (auto it = body.begin(); it != body.end(); ++it) {
bool known = false;
@@ -272,6 +283,25 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
" (sigma grid points, the last one 0)");
r->steps = (int32_t)v;
}
if (has(body, "latent_upscale")) {
double v = 0;
if (!(info.upscale_max > 0.0))
return error_response(err_unsupported("latent_upscale", "this model has no latent "
"upscaler"), req.peer);
if (!number(body["latent_upscale"], &v) || !(v >= 1.0) || v > info.upscale_max)
return bad("latent_upscale", "expected a factor from 1 to " +
rad::fmt("%g", info.upscale_max));
r->upscale = v > 1.0 ? v : 0.0;
}
if (has(body, "upscale_refine_steps")) {
double v = 0;
if (r->upscale <= 1.0)
return bad("upscale_refine_steps", "counts the steps after a latent upscale; give "
"latent_upscale above 1 with it");
if (!number(body["upscale_refine_steps"], &v) || v != std::floor(v) || v < 1 || v > 1e6)
return bad("upscale_refine_steps", "expected a positive integer");
r->refine = (int32_t)v;
}
bool seed_given = false;
if (has(body, "seed")) {
double v = 0;
@@ -318,6 +348,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
r->ticket = j->ticket;
const int64_t n_tok = (int64_t)r->tokens.size();
const int32_t steps = r->steps;
const double upscale = r->upscale;
{
std::string w;
const int s = deps_.videos->submit(std::move(r), &w);
@@ -328,9 +359,19 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
return error_response(e, req.peer);
}
}
RAD_INFO("video %s: %s, %lld frames (%s s), %lld prompt tokens, %d steps, seed=%llu",
const gen::VideoTicket& tk = *j->ticket;
if (tk.refine > 0) {
j->upscale = upscale;
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, %lld frames (%s s), %lld prompt tokens, %d steps%s, seed=%llu",
j->id.c_str(), j->size.c_str(), (long long)frames, j->seconds.c_str(),
(long long)n_tok, steps > 0 ? steps : (int)j->ticket->steps,
(long long)n_tok, steps > 0 ? steps : (int)tk.steps,
tk.refine > 0 ? rad::fmt(" (the first %d at %dx%d, upscaled for the last %d)",
(int)(tk.steps - tk.refine), (int)tk.small_width,
(int)tk.small_height, (int)tk.refine).c_str()
: "",
(unsigned long long)j->seed);
std::lock_guard<std::mutex> lk(videos_m_);
sweep_videos_locked(unix_now());
@@ -395,9 +436,16 @@ void Server::video_work(std::shared_ptr<VideoJob> j) {
j->completed_at = now;
j->expires_at = now + opt_.video_ttl_s;
j->mp4 = std::move(file);
RAD_INFO("video %s: completed, %.1f MB (%s), %.1f s", j->id.c_str(),
(double)j->mp4.size() / 1e6, mp4.video_encoder().c_str(),
(double)(t.t_done_ns - t.t_submit_ns) / 1e9);
auto sec = [](int64_t a, int64_t b) { return (double)(b - a) / 1e9; };
const std::string steps = t.t_upscaled_ns > 0
? rad::fmt("small steps %.1f s, upscale %.2f s, full steps %.1f s",
sec(t.t_cond_ns, t.t_small_ns), sec(t.t_small_ns, t.t_upscaled_ns),
sec(t.t_upscaled_ns, t.t_denoised_ns))
: rad::fmt("steps %.1f s", sec(t.t_cond_ns, t.t_denoised_ns));
RAD_INFO("video %s: completed, %.1f MB (%s), %.1f s: queue and prompt %.1f s, %s, "
"decode %.1f s", j->id.c_str(), (double)j->mp4.size() / 1e6,
mp4.video_encoder().c_str(), sec(t.t_submit_ns, t.t_done_ns),
sec(t.t_submit_ns, t.t_cond_ns), steps.c_str(), sec(t.t_denoised_ns, t.t_done_ns));
} else {
j->status = "failed";
j->failed = true;
@@ -477,6 +525,11 @@ json Server::video_json(const VideoJob& j) {
o["seconds"] = j.seconds;
o["size"] = j.size;
o["seed"] = j.seed;
if (j.refine > 0) {
o["latent_upscale"] = j.upscale;
o["upscale_refine_steps"] = j.refine;
o["upscale_from"] = j.upscale_from;
}
o["remixed_from_video_id"] = nullptr;
if (j.failed) {
json e;