video: endpoint keyframe completion (I2VA / L2VA / FL2VA)

One keyframe path serves three DaSiWa modes: first_frame pins output frame 0,
last_frame pins the last frame, and the gap is diffused. A keyframe is pure
attention conditioning -- its VAE latent rides as a pinned (update=0) cond row
at its frame's time position, faithful to comfy/ldm/minimax/model.py where
keyframe latents are img_update==False rows. The sampler is untouched; the step
merely widens to carry the extra cond rows.

- server (videos.cpp/iface.h/adapters.h): first_frame/last_frame form parts ->
  VideoRefMedia::FIRST_FRAME/LAST_FRAME; kf_task validation (i2va/fl2va need
  first, l2va/fl2va need last); keyframes are mutually exclusive with refs;
  encoder_image_canvas(cover=LAST) sizes the anchor.
- driver (video_driver.cpp): keyframe pass issues a RAD_ENC_IMAGE Vencode per
  anchor (slot = ++ref_tab[1], ordered), appends ref_tab key triples
  {frame(0|frames-1), video_t=1, audio_t=0}.
- arch (minimaxh3.cpp): ref_parts emits keyframe cond parts FIRST; the step
  scatter admits kR2VCond/kR2VCondAudio rows.
- tests: video_gen_test keyframe-completes-widens-the-step-and-pins-the-ends
  (2x Vencode at slot 1,2; widened step; seg_cu/lat_cu/ref_tab pinned); fake_pack_ref
  lays keyframe rows (nk=0 byte-identical to before); videos_test keyframe API.

Device-verified (TP2, seed 9999): FL2VA completes a valid 73-frame MP4+AAC; pins
are consumed (fl2va != same-seed t2va) and force the endpoints (frame0 vs anchor
0.687 pinned vs 0.460 un-pinned; last 0.719 vs 0.521). Fidelity follow-up (not
function): anchors ride as pins only; the reference also feeds them through the
TE as vision tokens, so a prompt that contradicts the anchor lets text win --
full endpoint parity vs a golden needs TE-anchor tokens (#10/P6 bucket).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-19 22:19:16 -05:00
1 parent 8ddcbbf01f
commit 60e920cd4d
11 files changed
+410 -37

No files matched your search

+67 -1
View File
@@ -154,7 +154,9 @@ 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"));
CHECK_EQ(v.refused(Videos::body({ { "task", "fl2va" } })), std::string("task"));
/* fl2va is a valid task, but one that promises a first frame -- refused naming the missing
* part, not the task. */
CHECK_EQ(v.refused(Videos::body({ { "task", "fl2va" } })), std::string("first_frame"));
CHECK_EQ(v.refused(Videos::body({ { "conditions", json::array({ json::object() }) } })),
std::string("conditions"));
CHECK_EQ(v.refused({ { "prompt", "p" }, { "target", { { "aspect_ratio", "wide" } } } }),
@@ -512,6 +514,70 @@ TEST(ref2va_videos_and_audios_are_encoded_and_spoken) {
CHECK(g.tokens == want);
}
/* Endpoint keyframes (task fl2va): a first and a last frame reach the generator as FIRST_FRAME and
* LAST_FRAME references, each resized to the EXACT output canvas -- a keyframe is a PIN, so its
* latent grid must be the target's, not an aspect-kept snap like a reference's. The pins-only path
* does not show them to the language model, so no media is built. The driver's fold into the pack's
* keyframe rows and the device scatter are the engine/device tests; this is the server half. */
TEST(fl2va_keyframes_pin_the_output_ends) {
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.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", "", "", "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.n_cenc, 2); /* both anchors canvas-resized ... */
CHECK_EQ(mm.n_ienc, 0); /* ... none 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 */
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((int)g.refs[1].kind, (int)gen::VideoRefMedia::LAST_FRAME);
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);
CHECK(g.media == nullptr); /* pins-only: the anchors never reach the text encoder */
}
/* 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.encodes = 1;
gen.inf.enc_ratio = 16;
} }));
/* 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) {