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
@@ -46,6 +46,11 @@ struct FakeVideoGen : IVideoGen {
|
||||
inf.default_steps = 50;
|
||||
inf.max_steps = 65;
|
||||
inf.max_lanes = 2;
|
||||
inf.max_ref_images = 9;
|
||||
inf.max_ref_videos = 3;
|
||||
inf.max_ref_audios = 3;
|
||||
inf.shift_video = 12.0;
|
||||
inf.shift_audio = 3.0;
|
||||
}
|
||||
const VideoGenInfo& info() const override { return inf; }
|
||||
int submit(std::unique_ptr<gen::VideoRequest> r, std::string*) override {
|
||||
@@ -159,9 +164,21 @@ TEST(a_video_request_that_cannot_be_served_names_its_field) {
|
||||
std::string("num_inference_steps"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "input_reference", "file-1" } })),
|
||||
std::string("input_reference"));
|
||||
/* The output is always an MP4: `format` is not a field, so it is refused as an unknown one,
|
||||
* by name. */
|
||||
CHECK_EQ(v.refused(Videos::body({ { "format", "avi" } })), std::string("format"));
|
||||
/* The keyframe tasks belong to a model with a video encoder; this one has none, so the name
|
||||
* is refused as a task. A model with the encoder takes the task and refuses a missing frame by
|
||||
* its field instead (a_keyframe_task_refuses_a_missing_frame). */
|
||||
CHECK_EQ(v.refused(Videos::body({ { "task", "fl2va" } })), std::string("task"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "conditions", json::array({ json::object() }) } })),
|
||||
std::string("conditions"));
|
||||
/* The shift: (0, 100], a number; 0 / negative / over the cap / non-numeric are refused. */
|
||||
CHECK_EQ(v.refused(Videos::body({ { "shift", 0 } })), std::string("shift"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "shift", -1 } })), std::string("shift"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "shift", 200 } })), std::string("shift"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "shift", "hot" } })), std::string("shift"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "audio_shift", 0 } })), std::string("audio_shift"));
|
||||
CHECK_EQ(v.refused({ { "prompt", "p" }, { "target", { { "aspect_ratio", "wide" } } } }),
|
||||
std::string("target"));
|
||||
CHECK_EQ(v.refused(Videos::body({ { "target", { { "aspect_ratio", "16:9" } } } })),
|
||||
@@ -217,6 +234,30 @@ TEST(the_generator_gets_the_size_the_chunks_and_the_steps) {
|
||||
v.wait(str_at(json::parse(r.body, nullptr, false), "id"));
|
||||
}
|
||||
|
||||
/* `shift`/`audio_shift` thread to the request and echo back; omitted, the request carries 0 (the
|
||||
* driver keeps the model's trained shift) and the echo adds neither field. */
|
||||
TEST(the_shift_threads_to_the_request_and_echoes) {
|
||||
Videos v;
|
||||
HttpResponse r = v.create(Videos::body({ { "shift", 6 }, { "audio_shift", 2 } }));
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
CHECK_EQ(v.gen.last().shift_video, 6.0);
|
||||
CHECK_EQ(v.gen.last().shift_audio, 2.0);
|
||||
json o = json::parse(r.body, nullptr, false);
|
||||
CHECK(o.contains("shift"));
|
||||
CHECK_EQ(o["shift"].get<double>(), 6.0);
|
||||
CHECK_EQ(o["audio_shift"].get<double>(), 2.0);
|
||||
v.wait(str_at(o, "id"));
|
||||
|
||||
r = v.create(Videos::body());
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
CHECK_EQ(v.gen.last().shift_video, 0.0);
|
||||
CHECK_EQ(v.gen.last().shift_audio, 0.0);
|
||||
o = json::parse(r.body, nullptr, false);
|
||||
CHECK(!o.contains("shift"));
|
||||
CHECK(!o.contains("audio_shift"));
|
||||
v.wait(str_at(o, "id"));
|
||||
}
|
||||
|
||||
/* A model with a length head chooses the length of a request that names none or says "auto": the
|
||||
* generator gets 0 chunks, the video object says "auto" until the model has chosen and then the
|
||||
* length chosen. A length named is as for any model; without a head, none named is the default. */
|
||||
@@ -339,6 +380,10 @@ TEST(a_video_job_completes_and_serves_its_file) {
|
||||
SKIP("this build has no libavcodec to write the MP4 with");
|
||||
REQUIRE_EQ(str_at(o, "status"), std::string("completed"));
|
||||
CHECK_EQ(o["progress"].get<int>(), 100);
|
||||
/* The step tally rides in the object (the fake generator lands 2 steps): a waiting client
|
||||
* reads steps_done/steps_total while in_progress, and they survive into the finished object. */
|
||||
CHECK_EQ(o["steps_done"].get<int>(), 2);
|
||||
CHECK_EQ(o["steps_total"].get<int>(), 2);
|
||||
CHECK(o["completed_at"].is_number());
|
||||
CHECK(o["expires_at"].get<int64_t>() > o["completed_at"].get<int64_t>());
|
||||
CHECK(o["error"].is_null());
|
||||
@@ -387,6 +432,11 @@ TEST(a_failed_generation_is_a_failed_job_with_its_reason) {
|
||||
HttpResponse r = v.create(Videos::body());
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
json o = v.wait(str_at(json::parse(r.body, nullptr, false), "id"));
|
||||
/* The job's thread opens the MP4 writer before it draws a step, so without a codec it fails
|
||||
* the write before the generator is asked to fail -- the reason under test is unreachable.
|
||||
* Same guard as the completion case above. */
|
||||
if (str_at(o, "status") == "failed" && has(str_at(o["error"], "message"), "no libavcodec"))
|
||||
SKIP("this build has no libavcodec to reach the generator with");
|
||||
CHECK_EQ(str_at(o, "status"), std::string("failed"));
|
||||
CHECK_EQ(str_at(o["error"], "code"), std::string("generation_failed"));
|
||||
CHECK(has(str_at(o["error"], "message"), "the engine stopped"));
|
||||
@@ -399,6 +449,490 @@ TEST(the_video_routes_are_501_without_a_video_model) {
|
||||
CHECK_EQ(f.get("/v1/videos").status, 501);
|
||||
}
|
||||
|
||||
/* ref2va: the reference file parts are read from the form, and the generator gets them bounded,
|
||||
* numbered and paired — sorted by (kind, number), images first, a soundtrack after its video. */
|
||||
TEST(ref2va_reference_media_reach_the_generator) {
|
||||
Videos v;
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a fox in the snow" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "ref2va" },
|
||||
FormPart{ "ref_video_audio_1", "tail.wav", "audio/wav", "RIFF" },
|
||||
FormPart{ "ref_image_2", "b.jpg", "image/jpeg", "JPEG" },
|
||||
FormPart{ "ref_audio_1", "song.mp3", "audio/mpeg", "ID3" },
|
||||
FormPart{ "ref_video_1", "tail.mp4", "video/mp4", "ftyp" },
|
||||
FormPart{ "ref_image_1", "a.png", "image/png", "png" } };
|
||||
HttpResponse r = v.f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
const gen::VideoRequest& g = v.gen.last();
|
||||
REQUIRE_EQ(g.refs.size(), (size_t)5);
|
||||
CHECK_EQ((int)g.refs[0].kind, (int)gen::VideoRefMedia::IMAGE);
|
||||
CHECK_EQ(g.refs[0].index, 1);
|
||||
CHECK_EQ(g.refs[0].name, std::string("ref_image_1"));
|
||||
CHECK_EQ(g.refs[0].data, std::string("png"));
|
||||
CHECK_EQ((int)g.refs[1].kind, (int)gen::VideoRefMedia::IMAGE);
|
||||
CHECK_EQ(g.refs[1].index, 2);
|
||||
CHECK_EQ((int)g.refs[2].kind, (int)gen::VideoRefMedia::VIDEO);
|
||||
CHECK_EQ(g.refs[2].filename, std::string("tail.mp4"));
|
||||
CHECK_EQ(g.refs[2].data, std::string("ftyp"));
|
||||
CHECK_EQ((int)g.refs[3].kind, (int)gen::VideoRefMedia::VIDEO_AUDIO);
|
||||
CHECK_EQ(g.refs[3].index, 1);
|
||||
CHECK_EQ((int)g.refs[4].kind, (int)gen::VideoRefMedia::AUDIO);
|
||||
CHECK_EQ(g.refs[4].filename, std::string("song.mp3"));
|
||||
json o = json::parse(r.body, nullptr, false);
|
||||
CHECK_EQ(str_at(o, "task"), std::string("ref2va"));
|
||||
REQUIRE(o["refs"].is_array());
|
||||
REQUIRE_EQ(o["refs"].size(), (size_t)5);
|
||||
CHECK_EQ(o["refs"][0].get<std::string>(), std::string("ref_image_1"));
|
||||
CHECK_EQ(o["refs"][4].get<std::string>(), std::string("ref_audio_1"));
|
||||
v.wait(str_at(o, "id"));
|
||||
}
|
||||
|
||||
/* ref2va with a vision encoder loaded: the pictures are decoded and processed, then presented
|
||||
* between the template's head and the prompt, each `<Picture k>: ` label (its own tokenised
|
||||
* string) followed by the picture's token run, in part order; the placed media go with the
|
||||
* request to the generator. */
|
||||
TEST(ref2va_pictures_are_presented_before_the_prompt) {
|
||||
FakeMultimodal mm;
|
||||
mm.expand = { 900, 901, 902 };
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a fox" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "ref2va" },
|
||||
FormPart{ "ref_image_2", "b.png", "image/png", "PB" },
|
||||
FormPart{ "ref_image_1", "a.png", "image/png", "PA" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
/* Both parts were decoded as images, in presentation order. */
|
||||
REQUIRE_EQ(mm.got.size(), (size_t)2);
|
||||
CHECK(mm.got[0].first == MediaKind::Image);
|
||||
CHECK(mm.got[0].second == std::vector<uint8_t>({ 'P', 'A' }));
|
||||
CHECK(mm.got[1].second == std::vector<uint8_t>({ 'P', 'B' }));
|
||||
const gen::VideoRequest& g = gen.last();
|
||||
REQUIRE(g.media != nullptr);
|
||||
REQUIRE_EQ(g.media->items.size(), (size_t)2);
|
||||
CHECK_EQ(g.media->items[0].tok, 16); /* "<v>" + "<Picture 1>: " */
|
||||
CHECK_EQ(g.media->items[1].tok, 32); /* + the first run + "<Picture 2>: " */
|
||||
/* The token stream exactly: head, label and run per picture in part order, the prompt last.
|
||||
* The fake tokenizer turns a character into its code and leaves other ids as sent. */
|
||||
std::vector<int32_t> want;
|
||||
auto chars = [&](const std::string& s) {
|
||||
for (unsigned char c : s) want.push_back((int32_t)c);
|
||||
};
|
||||
chars("<v>");
|
||||
chars("<Picture 1>: ");
|
||||
want.insert(want.end(), mm.expand.begin(), mm.expand.end());
|
||||
chars("<Picture 2>: ");
|
||||
want.insert(want.end(), mm.expand.begin(), mm.expand.end());
|
||||
chars("a fox");
|
||||
CHECK(g.tokens == want);
|
||||
}
|
||||
|
||||
/* A generator with the VAE encoders: the picture, the video and both audios are decoded into the
|
||||
* encoders' form, each audio's mono tone spread across the encoder's channels, and every reference
|
||||
* is named before the prompt in the reference's order: the picture's label and run, a soundtrack's
|
||||
* `<Audio j>` right before its video's `<Video k>`, then the standalone `<Audio j>`. This is the
|
||||
* server half; the driver half (padding, slots, the pack table) is tests/video_gen_test.cpp. */
|
||||
TEST(ref2va_videos_and_audios_are_encoded_and_spoken) {
|
||||
FakeMultimodal mm;
|
||||
mm.expand = { 900, 901 };
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 256;
|
||||
gen.inf.max_enc_frames = 289;
|
||||
gen.inf.max_enc_samples = 500000;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "ref2va" },
|
||||
FormPart{ "ref_image_1", "a.png", "image/png", "PA" },
|
||||
FormPart{ "ref_video_1", "v.mp4", "video/mp4", "ftyp" },
|
||||
FormPart{ "ref_video_audio_1", "s.wav", "audio/wav", "RIFF" },
|
||||
FormPart{ "ref_audio_1", "b.mp3", "audio/mpeg", "ID3" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
|
||||
/* One image, one video and two audios (the video's soundtrack plus the standalone) reached the
|
||||
* encoder each belongs to. */
|
||||
CHECK_EQ(mm.n_ienc, 1);
|
||||
CHECK_EQ(mm.n_venc, 1);
|
||||
CHECK_EQ(mm.n_aenc, 2);
|
||||
|
||||
const gen::VideoRequest& g = gen.last();
|
||||
REQUIRE_EQ(g.refs.size(), (size_t)4); /* sorted (kind, index): image, video, video_audio, audio */
|
||||
/* The picture: one frame at the encoder grid, its pixels filled for the video VAE. */
|
||||
CHECK_EQ((int)g.refs[0].kind, (int)gen::VideoRefMedia::IMAGE);
|
||||
CHECK_EQ(g.refs[0].enc_frames, 1);
|
||||
CHECK_EQ(g.refs[0].enc_h, 16);
|
||||
CHECK_EQ(g.refs[0].enc_w, 16);
|
||||
CHECK_EQ(g.refs[0].enc_pixels.size(), (size_t)16 * 16 * 3);
|
||||
/* The video: the trimmed natural frame count, concatenated over the grid (the driver pads). */
|
||||
CHECK_EQ((int)g.refs[1].kind, (int)gen::VideoRefMedia::VIDEO);
|
||||
CHECK_EQ(g.refs[1].enc_frames, 5);
|
||||
CHECK_EQ(g.refs[1].enc_pixels.size(), (size_t)5 * 16 * 16 * 3);
|
||||
/* The soundtrack and the standalone audio: the mono tone spread across the generator's two
|
||||
* channels, enc_n the natural (unpadded) count. */
|
||||
CHECK_EQ((int)g.refs[2].kind, (int)gen::VideoRefMedia::VIDEO_AUDIO);
|
||||
CHECK_EQ(g.refs[2].enc_channels, 2);
|
||||
CHECK_EQ(g.refs[2].enc_n, (int64_t)850);
|
||||
CHECK_EQ(g.refs[2].enc_samples.size(), (size_t)2 * 850);
|
||||
CHECK_EQ(g.refs[2].enc_samples[0], g.refs[2].enc_samples[850]); /* both channels the same tone */
|
||||
CHECK_EQ((int)g.refs[3].kind, (int)gen::VideoRefMedia::AUDIO);
|
||||
CHECK_EQ(g.refs[3].enc_n, (int64_t)850);
|
||||
|
||||
/* The prompt speaks every reference before the words, in the reference's order. */
|
||||
std::vector<int32_t> want;
|
||||
auto chars = [&](const std::string& s) { for (unsigned char c : s) want.push_back((int32_t)c); };
|
||||
chars("<v>");
|
||||
chars("<Picture 1>: ");
|
||||
want.insert(want.end(), mm.expand.begin(), mm.expand.end());
|
||||
chars("<Audio 1>: ");
|
||||
chars("<Video 1>: ");
|
||||
chars("<Audio 2>: ");
|
||||
chars("fox");
|
||||
CHECK(g.tokens == want);
|
||||
}
|
||||
|
||||
/* Keyframes (task fl2va): a first and a last frame reach the generator as FIRST_FRAME and
|
||||
* LAST_FRAME references, each resized to the output canvas exactly. A keyframe pins frames of the
|
||||
* output, so its latent grid is the target's, not one snapped to its own aspect as a reference's
|
||||
* is. As in the reference (clip.tokenize and vae.encode), a keyframe reaches the transformer twice:
|
||||
* as the VAE's latents and, when the container has a vision tower, as a <Picture k> block in the
|
||||
* prompt. This is the server half; the keyframe rows are tests/video_gen_test.cpp's. */
|
||||
TEST(fl2va_keyframes_feed_the_tower_and_pin_the_output_ends) {
|
||||
FakeMultimodal mm;
|
||||
mm.expand = { 900, 901 };
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 512;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "fl2va" },
|
||||
FormPart{ "first_frame", "f.png", "image/png", "PF" },
|
||||
FormPart{ "last_frame", "l.png", "image/png", "PL" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
/* Both keyframes reach the vision tower as their canvas frames, the pixels the VAE is handed,
|
||||
* not as the files: one canvas resize a frame serves both. */
|
||||
CHECK(mm.got.empty());
|
||||
REQUIRE_EQ(mm.n_pframe, 2);
|
||||
REQUIRE_EQ(mm.pframe_wh.size(), (size_t)2);
|
||||
CHECK(mm.pframe_wh[0] == std::make_pair((int32_t)256, (int32_t)256));
|
||||
CHECK(mm.pframe_wh[1] == std::make_pair((int32_t)256, (int32_t)256));
|
||||
CHECK_EQ(mm.n_cenc, 2);
|
||||
CHECK_EQ(mm.n_ienc, 0); /* a keyframe is never snapped like a reference */
|
||||
CHECK_EQ(mm.cenc_w, 256);
|
||||
CHECK_EQ(mm.cenc_h, 256);
|
||||
CHECK(mm.cenc_cover); /* the last call was the last frame's centre crop */
|
||||
REQUIRE_EQ(mm.cenc_covers.size(), (size_t)2);
|
||||
CHECK(!mm.cenc_covers[0]); /* default first frame: the reference's stretch */
|
||||
CHECK(mm.cenc_covers[1]); /* the last frame: always the centre crop */
|
||||
const gen::VideoRequest& g = gen.last();
|
||||
REQUIRE_EQ(g.refs.size(), (size_t)2);
|
||||
CHECK_EQ((int)g.refs[0].kind, (int)gen::VideoRefMedia::FIRST_FRAME);
|
||||
CHECK_EQ(g.refs[0].index, 1); /* <Picture 1> = first */
|
||||
CHECK_EQ((int)g.refs[1].kind, (int)gen::VideoRefMedia::LAST_FRAME);
|
||||
CHECK_EQ(g.refs[1].index, 2); /* <Picture 2> = last */
|
||||
CHECK_EQ(g.refs[0].enc_frames, 1);
|
||||
CHECK_EQ(g.refs[0].enc_h, 256); /* the target canvas, exactly */
|
||||
CHECK_EQ(g.refs[0].enc_w, 256);
|
||||
CHECK_EQ(g.refs[0].enc_pixels.size(), (size_t)256 * 256 * 3);
|
||||
/* The keyframes reach the text encoder too: a <Picture 1> and a <Picture 2> block before the
|
||||
* prompt. */
|
||||
REQUIRE(g.media != nullptr);
|
||||
REQUIRE_EQ(g.media->items.size(), (size_t)2);
|
||||
CHECK(g.media->items[0].tok < g.media->items[1].tok);
|
||||
std::vector<int32_t> want;
|
||||
auto chars = [&](const std::string& s) { for (unsigned char c : s) want.push_back((int32_t)c); };
|
||||
chars("<v>");
|
||||
chars("<Picture 1>: ");
|
||||
want.insert(want.end(), mm.expand.begin(), mm.expand.end());
|
||||
chars("<Picture 2>: ");
|
||||
want.insert(want.end(), mm.expand.begin(), mm.expand.end());
|
||||
chars("fox");
|
||||
CHECK(g.tokens == want);
|
||||
}
|
||||
|
||||
/* A last frame alone is <Picture 1>: the number counts the pictures present, as ComfyUI's does.
|
||||
* fl2va (both ends) keeps first = 1, last = 2. */
|
||||
TEST(l2va_presents_its_sole_frame_as_picture_1) {
|
||||
FakeMultimodal mm;
|
||||
mm.expand = { 900, 901 };
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 512;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "l2va" },
|
||||
FormPart{ "last_frame", "l.png", "image/png", "PL" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
REQUIRE_EQ(gen.last().refs.size(), (size_t)1);
|
||||
CHECK_EQ((int)gen.last().refs[0].kind, (int)gen::VideoRefMedia::LAST_FRAME);
|
||||
CHECK_EQ(gen.last().refs[0].index, 1); /* the sole picture: <Picture 1>, not the role's 2 */
|
||||
CHECK(mm.cenc_cover); /* it still takes the last frame's centre crop */
|
||||
CHECK(mm.got.empty()); /* the tower reads the canvas frame, not the file */
|
||||
CHECK_EQ(mm.n_pframe, 1);
|
||||
REQUIRE(gen.last().media != nullptr);
|
||||
REQUIRE_EQ(gen.last().media->items.size(), (size_t)1);
|
||||
std::vector<int32_t> want;
|
||||
auto chars = [&](const std::string& s) { for (unsigned char c : s) want.push_back((int32_t)c); };
|
||||
chars("<v>");
|
||||
chars("<Picture 1>: ");
|
||||
want.insert(want.end(), mm.expand.begin(), mm.expand.end());
|
||||
chars("fox");
|
||||
CHECK(gen.last().tokens == want);
|
||||
}
|
||||
|
||||
/* first_frame_mode=center: the first keyframe is scaled to cover the canvas and centre-cropped
|
||||
* instead of stretched, so a portrait photo pinned into a landscape output is not distorted. The
|
||||
* flag reaches encoder_image_canvas on the first call; the last frame is centre-cropped either way. */
|
||||
TEST(first_frame_mode_center_cover_crops_the_first_anchor) {
|
||||
FakeMultimodal mm;
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 512;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "fl2va" },
|
||||
FormPart{ "first_frame", "f.png", "image/png", "PF" },
|
||||
FormPart{ "last_frame", "l.png", "image/png", "PL" },
|
||||
FormPart{ "first_frame_mode", "", "", "center" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
REQUIRE_EQ(mm.cenc_covers.size(), (size_t)2);
|
||||
CHECK(mm.cenc_covers[0]); /* the first keyframe: centre crop, not stretch */
|
||||
CHECK(mm.cenc_covers[1]); /* the last: unchanged */
|
||||
CHECK_EQ(mm.cenc_w, 256);
|
||||
CHECK_EQ(mm.cenc_h, 256); /* still the canvas exactly: a pin needs its grid */
|
||||
}
|
||||
|
||||
/* first_frame_mode takes two values; anything else is refused naming the field, and an explicit
|
||||
* "stretch" (or empty form field) keeps the reference's default. */
|
||||
TEST(first_frame_mode_refuses_a_mode_it_does_not_know) {
|
||||
FakeMultimodal mm;
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 512;
|
||||
} }));
|
||||
auto post = [&](const char* mode) {
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" }, FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "first_frame", "f.png", "image/png", "PF" } };
|
||||
if (mode) q.form.push_back(FormPart{ "first_frame_mode", "", "", mode });
|
||||
return f->srv->router().dispatch(q);
|
||||
};
|
||||
{
|
||||
HttpResponse r = post("warp");
|
||||
CHECK(r.status >= 400);
|
||||
CHECK(r.body.find("first_frame_mode") != std::string::npos);
|
||||
}
|
||||
mm.cenc_covers.clear();
|
||||
{
|
||||
HttpResponse r = post("stretch");
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
REQUIRE_EQ(mm.cenc_covers.size(), (size_t)1);
|
||||
CHECK(!mm.cenc_covers[0]);
|
||||
}
|
||||
mm.cenc_covers.clear();
|
||||
{
|
||||
HttpResponse r = post(""); /* an empty form field is "not set" */
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
REQUIRE_EQ(mm.cenc_covers.size(), (size_t)1);
|
||||
CHECK(!mm.cenc_covers[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Without a vision tower a keyframe request still renders: the keyframes keep their VAE latents and
|
||||
* add no prompt media. */
|
||||
TEST(fl2va_without_a_tower_pins_only) {
|
||||
FakeMultimodal mm;
|
||||
mm.accept_image = false; /* a container converted without its vision tower */
|
||||
mm.enc_frames = 5; mm.enc_side = 16; mm.enc_n = 850;
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
d.mm = &mm;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 512;
|
||||
} }));
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" },
|
||||
FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "fl2va" },
|
||||
FormPart{ "first_frame", "f.png", "image/png", "PF" },
|
||||
FormPart{ "last_frame", "l.png", "image/png", "PL" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
REQUIRE_EQ(r.status, 200);
|
||||
CHECK_EQ(mm.got.size(), (size_t)0); /* nothing reached the absent tower */
|
||||
CHECK_EQ(mm.n_cenc, 2); /* both keyframes still resized for the VAE */
|
||||
const gen::VideoRequest& g = gen.last();
|
||||
CHECK(g.media == nullptr); /* no prompt media */
|
||||
CHECK_EQ(g.refs[0].enc_pixels.size(), (size_t)256 * 256 * 3);
|
||||
CHECK_EQ(g.refs[1].enc_pixels.size(), (size_t)256 * 256 * 3);
|
||||
}
|
||||
|
||||
/* A named keyframe task must carry its frame: fl2va wants both ends. */
|
||||
TEST(a_keyframe_task_refuses_a_missing_frame) {
|
||||
FakeVideoGen gen;
|
||||
std::unique_ptr<Fixture> f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) {
|
||||
d.videos = &gen;
|
||||
o.video_model = true;
|
||||
gen.inf.enc_ratio = 16;
|
||||
gen.inf.max_enc_side = 256;
|
||||
} }));
|
||||
/* fl2va with a first but no last -> names last_frame. */
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "fox" }, FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "fl2va" },
|
||||
FormPart{ "first_frame", "f.png", "image/png", "PF" } };
|
||||
HttpResponse r = f->srv->router().dispatch(q);
|
||||
CHECK(r.status >= 400);
|
||||
CHECK(r.body.find("last_frame") != std::string::npos);
|
||||
}
|
||||
|
||||
/* Everything about the parts that cannot be right is refused naming the part (or `task` when
|
||||
* the media themselves are the question), before anything is queued. */
|
||||
TEST(ref2va_requests_are_refused_naming_the_part) {
|
||||
Videos v;
|
||||
auto refused = [&](const std::vector<FormPart>& media, const std::string& param) {
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a fox" }, FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "ref2va" } };
|
||||
for (const FormPart& m : media) q.form.push_back(m);
|
||||
HttpResponse r = v.f->srv->router().dispatch(q);
|
||||
CHECK_EQ(r.status, 400);
|
||||
CHECK_EQ(str_at(json::parse(r.body, nullptr, false)["error"], "param"), param);
|
||||
};
|
||||
/* The task without any media (and JSON alone cannot carry the bytes). */
|
||||
refused({}, "task");
|
||||
CHECK_EQ(v.refused(Videos::body({ { "task", "ref2va" } })), std::string("task"));
|
||||
/* Empty bytes. */
|
||||
refused({ FormPart{ "ref_image_1", "a.png", "image/png", "" } }, "ref_image_1");
|
||||
/* Numbering with a gap or a repeat. */
|
||||
refused({ FormPart{ "ref_image_1", "a.png", "image/png", "x" },
|
||||
FormPart{ "ref_image_3", "b.png", "image/png", "x" } }, "ref_image_2");
|
||||
refused({ FormPart{ "ref_image_1", "a.png", "image/png", "x" },
|
||||
FormPart{ "ref_image_1", "b.png", "image/png", "y" } }, "ref_image_1");
|
||||
/* A soundtrack with no video of its number; ten images over the API's nine. */
|
||||
refused({ FormPart{ "ref_video_audio_1", "s.wav", "audio/wav", "x" } }, "ref_video_audio_1");
|
||||
{
|
||||
std::vector<FormPart> ten;
|
||||
for (int i = 1; i <= 10; ++i)
|
||||
ten.push_back(FormPart{ "ref_image_" + std::to_string(i), "p.png", "image/png", "x" });
|
||||
refused(ten, "ref_image_10");
|
||||
}
|
||||
/* Reference files with no task, and with t2va: the task is the mistake. */
|
||||
for (const char* task : { (const char*)nullptr, "t2va" }) {
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a fox" }, FormPart{ "size", "", "", "256x256" } };
|
||||
if (task) q.form.push_back(FormPart{ "task", "", "", task });
|
||||
q.form.push_back(FormPart{ "ref_image_1", "a.png", "image/png", "x" });
|
||||
HttpResponse r = v.f->srv->router().dispatch(q);
|
||||
CHECK_EQ(r.status, 400);
|
||||
CHECK_EQ(str_at(json::parse(r.body, nullptr, false)["error"], "param"),
|
||||
std::string("task"));
|
||||
}
|
||||
/* The caps ride the capability block /v1/models and /server_info share, so a client can
|
||||
* gate on them without probing a refusal. This fake declares 9/3/3 and a 64-token prompt,
|
||||
* all at or under the API's caps, so the declaration shows through. */
|
||||
auto caps = [&](json* out) {
|
||||
HttpRequest mq;
|
||||
mq.method = "GET";
|
||||
mq.path = "/v1/models";
|
||||
HttpResponse mr = v.f->srv->router().dispatch(mq);
|
||||
CHECK_EQ(mr.status, 200);
|
||||
*out = json::parse(mr.body, nullptr, false)["data"][0]["capabilities"];
|
||||
};
|
||||
json c;
|
||||
caps(&c);
|
||||
CHECK_EQ(c["video_generation"], true);
|
||||
CHECK_EQ(c["video_max_text"], 64);
|
||||
CHECK_EQ(c["video_max_ref_images"], 9);
|
||||
CHECK_EQ(c["video_max_ref_videos"], 3);
|
||||
CHECK_EQ(c["video_max_ref_audios"], 3);
|
||||
/* A model that declares no reference media does not take the task at all. */
|
||||
v.gen.inf.max_ref_images = v.gen.inf.max_ref_videos = v.gen.inf.max_ref_audios = 0;
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a fox" }, FormPart{ "size", "", "", "256x256" },
|
||||
FormPart{ "task", "", "", "ref2va" },
|
||||
FormPart{ "ref_image_1", "a.png", "image/png", "x" } };
|
||||
HttpResponse r = v.f->srv->router().dispatch(q);
|
||||
CHECK_EQ(r.status, 400);
|
||||
CHECK_EQ(str_at(json::parse(r.body, nullptr, false)["error"], "param"), std::string("task"));
|
||||
CHECK_EQ(v.gen.got.size(), (size_t)0); /* nothing was ever queued */
|
||||
/* And the caps the model reports match what it refuses: the zero counts say what the refusal
|
||||
* does, before a client spends a request on it. */
|
||||
caps(&c);
|
||||
CHECK_EQ(c["video_max_ref_images"], 0);
|
||||
CHECK_EQ(c["video_max_ref_videos"], 0);
|
||||
CHECK_EQ(c["video_max_ref_audios"], 0);
|
||||
CHECK_EQ(c["video_max_text"], 64);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/* A PNG of w x h, every pixel (r, g, b). */
|
||||
|
||||
Reference in new issue
Block a user