diff --git a/arch/minimaxh3/minimaxh3.cpp b/arch/minimaxh3/minimaxh3.cpp index c6641e78..2de406bc 100644 --- a/arch/minimaxh3/minimaxh3.cpp +++ b/arch/minimaxh3/minimaxh3.cpp @@ -122,7 +122,7 @@ enum { kMaxSteps = 64, kDefSteps = 50 }; /* Time: 24 frames a second; a video of n chunks is 17 n + 5 frames over 5 n + 2 latent frames, * and a decode pass reads 7 latent frames from 5 c. 5 to 15 seconds: 7 to 20 chunks. */ enum { kFps = 24, kFpc = 17, kFtail = 5, kLpc = 5, kLtail = 2, kDecLat = 7 }; -enum { kMinChunks = 4, kMaxChunks = 20, kDefChunks = 7 }; /* EXPERIMENT: short-chunk test */ +enum { kMinChunks = 7, kMaxChunks = 20, kDefChunks = 7 }; /* Space: 16 pixels a latent, 2 x 2 latents a patch; sides multiples of 32 from 256, at most the * 1344 x 768 canvas's area, 4:1 at most. */ enum { kScale = 16, kPatch = 2, kMult = 32, kMinSide = 256, kMaxAspect = 4 }; diff --git a/core/server/videos.cpp b/core/server/videos.cpp index dc905151..7bdd784b 100644 --- a/core/server/videos.cpp +++ b/core/server/videos.cpp @@ -335,10 +335,10 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) { gen::VideoRefMedia m; m.kind = p.name == "first_frame" ? gen::VideoRefMedia::FIRST_FRAME : gen::VideoRefMedia::LAST_FRAME; - /* The keyframe's ordinal, so its vision-anchor block is labelled the way - * the source workflow names it (first = , last = ). A keyframe - * request carries no reference media (checked below), so these numbers cannot collide - * with a reference's own . */ + /* The keyframe's ordinal, provisionally by role; the presence rule in + * the count check below settles it once every part has parsed (parts may arrive in + * either order). A keyframe request carries no reference media (checked there), so + * these numbers cannot collide with a reference's own . */ m.index = m.kind == gen::VideoRefMedia::FIRST_FRAME ? 1 : 2; m.name = p.name; m.filename = p.filename; @@ -502,6 +502,12 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) { 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"); + /* The ordinal counts the images the request PRESENTS, not the keyframe's role: + * the reference numbers its presentation by presence (a last-frame-only request is its + * picture ONE), exactly as ref2va numbers reference photos 1..n. With both ends the roles + * and the positions agree, so fl2va keeps first = 1, last = 2. */ + for (gen::VideoRefMedia& m : keys) + if (m.kind == gen::VideoRefMedia::LAST_FRAME) m.index = n_first ? 2 : 1; if (!keys.empty()) { if (!info.encodes) return bad("first_frame", "this model has no video encoder, so it cannot pin a " @@ -762,7 +768,8 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) { * always AFTER every reference: the driver lays the reference rows down first, then folds each * FIRST_FRAME/LAST_FRAME into the pack's keyframe table. Sort first before last (a client may send * the file parts in either order) so they keyframe-order 0 and 1, take image slots 1 and 2, and - * present as then . */ + * present as then -- or alone when only one end is given + * (the presence ordinal was settled by the count check). */ std::stable_sort(keys.begin(), keys.end(), [](const gen::VideoRefMedia& a, const gen::VideoRefMedia& b) { return a.kind < b.kind; /* FIRST_FRAME (4) before LAST_FRAME (5) */ diff --git a/tests/videos_test.cpp b/tests/videos_test.cpp index 6727f178..787a97dc 100644 --- a/tests/videos_test.cpp +++ b/tests/videos_test.cpp @@ -682,6 +682,46 @@ TEST(fl2va_keyframes_feed_the_tower_and_pin_the_output_ends) { CHECK(g.tokens == want); } +/* A last frame ALONE is presented as : the ordinal counts the images the request + * carries, not the keyframe's role -- the reference numbers its presentation by presence, and so + * does ref2va's own photo numbering. 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 f(new Fixture(Fixture::Tweak{ [&](ServerOptions& o, Deps& d) { + d.videos = &gen; + d.mm = &mm; + o.video_model = true; + gen.inf.encodes = 1; + 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: , not the role's 2 */ + CHECK(mm.cenc_cover); /* it still takes the last frame's centre crop */ + REQUIRE(gen.last().media != nullptr); + REQUIRE_EQ(gen.last().media->items.size(), (size_t)1); + std::vector want; + auto chars = [&](const std::string& s) { for (unsigned char c : s) want.push_back((int32_t)c); }; + chars(""); + chars(": "); + want.insert(want.end(), mm.expand.begin(), mm.expand.end()); + chars("fox"); + CHECK(gen.last().tokens == want); +} + /* first_frame_mode=center: the FIRST anchor is cover-cropped to the canvas instead of stretched -- * the no-distortion answer for a portrait photo pinned into a landscape output. The flag reaches * encoder_image_canvas on the first call; the last frame keeps its centre crop either way. */