Archived
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:
1 parent
8ddcbbf01f
commit
60e920cd4d
11 files changed
+410
-37
No files matched your search
+12
-1
@@ -406,7 +406,10 @@ struct FakeMultimodal : IMultimodal {
|
||||
* clip, a sample count that is not a whole hop) — padding is the driver's, not the server's. */
|
||||
int32_t enc_frames = 5, enc_side = 16;
|
||||
int64_t enc_n = 850;
|
||||
int n_ienc = 0, n_venc = 0, n_aenc = 0;
|
||||
int n_ienc = 0, n_venc = 0, n_aenc = 0, n_cenc = 0;
|
||||
/* The canvas an anchor was resized to, and whether the last frame's cover-crop was asked for. */
|
||||
int32_t cenc_w = 0, cenc_h = 0;
|
||||
bool cenc_cover = false;
|
||||
int encoder_image(const uint8_t*, size_t, int32_t, int32_t, mm::Frame* out,
|
||||
std::string*) override {
|
||||
++n_ienc;
|
||||
@@ -414,6 +417,14 @@ struct FakeMultimodal : IMultimodal {
|
||||
out->rgb.assign((size_t)enc_side * enc_side * 3, 128);
|
||||
return RAD_OK;
|
||||
}
|
||||
int encoder_image_canvas(const uint8_t*, size_t, int32_t w, int32_t h, bool cover,
|
||||
mm::Frame* out, std::string*) override {
|
||||
++n_cenc;
|
||||
cenc_w = w; cenc_h = h; cenc_cover = cover;
|
||||
out->w = w; out->h = h;
|
||||
out->rgb.assign((size_t)w * h * 3, 100);
|
||||
return RAD_OK;
|
||||
}
|
||||
int encoder_video(const uint8_t*, size_t, int32_t, int32_t, int32_t, std::vector<mm::Frame>* out,
|
||||
std::string*) override {
|
||||
++n_venc;
|
||||
|
||||
+106
-13
@@ -140,11 +140,13 @@ int64_t fake_pack_more(const RadVideoGeom* g, const int32_t* ref_tab, int32_t* s
|
||||
}
|
||||
|
||||
/* The reference-aware layout: when a reference table rides, lay out
|
||||
* [text | one block per reference | audio target | video target] -- boundaries are segment starts
|
||||
* with the total rows last, so the video target runs [seg[nseg-2], seg[nseg-1]). Each picture
|
||||
* contributes a fixed 4 rows: this fake lays out the structure the driver stages, not the
|
||||
* reference's real visual-token arithmetic. With no table it lays the plain sequence, so the
|
||||
* encode/decode passes that call the pack without references get their plain table. */
|
||||
* [text | one block per keyframe | one block per reference | audio target | video target] --
|
||||
* boundaries are segment starts with the total rows last, so the video target runs
|
||||
* [seg[nseg-2], seg[nseg-1]). Keyframes precede references, matching the real pack. Each keyframe
|
||||
* contributes a fixed 2 rows and each picture a fixed 4: this fake lays out the structure the
|
||||
* driver stages, not the reference's real visual-token arithmetic. With no table it lays the plain
|
||||
* sequence, so the encode/decode passes that call the pack without references get their plain
|
||||
* table. With nk = 0 the layout is exactly the reference-only one the older tests assert. */
|
||||
int64_t fake_pack_ref(const RadVideoGeom* g, const int32_t* ref_tab, int32_t* seg, int64_t cap_seg,
|
||||
float* pos, int64_t cap_pos) {
|
||||
const int64_t audio = 2 * (int64_t)g->n_audio;
|
||||
@@ -164,16 +166,18 @@ int64_t fake_pack_ref(const RadVideoGeom* g, const int32_t* ref_tab, int32_t* se
|
||||
return rows;
|
||||
}
|
||||
const int32_t nr = ref_tab[0], nk = ref_tab[1];
|
||||
const int64_t rper = 4;
|
||||
const int64_t rows = g->n_text + (int64_t)nr * rper + audio + vtarget;
|
||||
const int64_t nseg = (int64_t)nr + 4;
|
||||
const int64_t rper = 4, kper = 2;
|
||||
const int64_t rows = g->n_text + (int64_t)nk * kper + (int64_t)nr * rper + audio + vtarget;
|
||||
const int64_t nseg = (int64_t)nk + (int64_t)nr + 4;
|
||||
if (!seg) return rows;
|
||||
if (cap_seg < nseg || nk != 0) return RAD_E_INVAL;
|
||||
if (cap_seg < nseg) return RAD_E_INVAL;
|
||||
seg[0] = 0;
|
||||
for (int32_t r = 0; r < nr; ++r) seg[1 + r] = (int32_t)(g->n_text + (int64_t)r * rper);
|
||||
seg[1 + nr] = (int32_t)(g->n_text + (int64_t)nr * rper); /* audio target start */
|
||||
seg[2 + nr] = (int32_t)(seg[1 + nr] + audio); /* video target start */
|
||||
seg[3 + nr] = (int32_t)(seg[2 + nr] + vtarget); /* total rows */
|
||||
int64_t cur = g->n_text;
|
||||
for (int32_t k = 0; k < nk; ++k) { seg[1 + k] = (int32_t)cur; cur += kper; }
|
||||
for (int32_t r = 0; r < nr; ++r) { seg[1 + nk + r] = (int32_t)cur; cur += rper; }
|
||||
seg[1 + nk + nr] = (int32_t)cur; /* audio target start */
|
||||
seg[2 + nk + nr] = (int32_t)(cur + audio); /* video target start */
|
||||
seg[3 + nk + nr] = (int32_t)(cur + audio + vtarget); /* total rows */
|
||||
if (pos) {
|
||||
if (cap_pos < 3 * rows) return RAD_E_INVAL;
|
||||
for (int64_t c = 0; c < 3; ++c)
|
||||
@@ -892,6 +896,95 @@ TEST(a_reference_conditioned_step_widens_to_the_pack_layout) {
|
||||
CHECK(saw_encode);
|
||||
}
|
||||
|
||||
/* An endpoint-keyframe completion (I2VA/L2VA/FL2VA) rides the same machinery a reference does, but
|
||||
* fills the pack's KEYFRAME table instead of its reference rows. Each first/last anchor the server
|
||||
* resized to the target canvas folds into a Vencode pass at the IMAGE slot its keyframe ORDER names
|
||||
* (1, then 2 -- free, since a keyframe request carries no references), and the step widens to
|
||||
* [text | keyframe block | keyframe block | audio target | video target]. The table is {0 references,
|
||||
* 2 keys} then the two key triples {pixel frame, video_t, audio_t}: the first pins pixel frame 0,
|
||||
* the last the final frame, each one latent frame of video and no soundtrack -- the resolved frame
|
||||
* index the reference's MiniMaxH3ImageToVideo assigns. The sampler still owns only the two target
|
||||
* streams; the pinned rows are never sampled. */
|
||||
TEST(a_keyframe_completes_widen_the_step_and_pin_the_ends) {
|
||||
VideoFixture f;
|
||||
f.build();
|
||||
with_tower(f, 16);
|
||||
RadVideoGenDecl& d = f.prog.video_gen;
|
||||
d.encodes = 1;
|
||||
d.enc_ratio = 16;
|
||||
d.max_enc_frames = 1;
|
||||
d.max_enc_side = 16;
|
||||
d.ref_rows = 1; // the denoiser consumes the table: turn the widening on
|
||||
CHECK_OK(f.start_with_pack_encode(fake_pack_ref, fake_encode_geom));
|
||||
std::string why;
|
||||
auto r = f.req(2);
|
||||
r->tokens = { 1, 2, 3 }; /* 3 text tokens: pins are not references, so no tower run */
|
||||
gen::VideoRefMedia first = ref_part(gen::VideoRefMedia::FIRST_FRAME, "first_frame", 1);
|
||||
first.enc_frames = 1;
|
||||
first.enc_h = 16;
|
||||
first.enc_w = 16;
|
||||
first.enc_pixels.assign(16 * 16 * 3, 1.0f);
|
||||
gen::VideoRefMedia last = ref_part(gen::VideoRefMedia::LAST_FRAME, "last_frame", 2);
|
||||
last.enc_frames = 1;
|
||||
last.enc_h = 16;
|
||||
last.enc_w = 16;
|
||||
last.enc_pixels.assign(16 * 16 * 3, 2.0f);
|
||||
r->refs.push_back(first);
|
||||
r->refs.push_back(last);
|
||||
CHECK_OK(f.drv.submit(std::move(r), &why));
|
||||
|
||||
const gen::VideoShape s = gen::video_shape(d, 64, 32, 2);
|
||||
const int64_t n_text = 3, audio = 2 * s.n_audio, vtarget = s.video_rows, kper = 2;
|
||||
const int64_t widened = n_text + 2 * kper + audio + vtarget;
|
||||
|
||||
int enc_seen = 0;
|
||||
bool saw_first = false, saw_last = false, saw_step = false;
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
const RadBatch* b = f.drv.next(i);
|
||||
if (!b) break;
|
||||
if (b->gen == RAD_GEN_PASS_VENCODE) {
|
||||
const RadVideoGenBatch* V = b->vgen_b;
|
||||
REQUIRE(V != nullptr);
|
||||
CHECK(V->ref_tab != nullptr); /* the keyframe table rides the encode too */
|
||||
CHECK_EQ(V->enc_kind, (int32_t)RAD_ENC_IMAGE); /* a picture anchor at an image slot */
|
||||
CHECK_EQ(V->enc_slot, (int32_t)(++enc_seen)); /* order 1, then 2 */
|
||||
if (enc_seen == 1) saw_first = true;
|
||||
else if (enc_seen == 2) saw_last = true;
|
||||
} else if (b->gen == RAD_GEN_PASS_VSTEP) {
|
||||
const RadVideoGenBatch* V = b->vgen_b;
|
||||
REQUIRE(V != nullptr);
|
||||
saw_step = true;
|
||||
CHECK_EQ(b->n_tok, widened); /* widened by the two key blocks */
|
||||
CHECK_EQ(V->seg_cu[0], 0);
|
||||
CHECK_EQ(V->seg_cu[1], (int32_t)n_text); /* text | key 0 */
|
||||
CHECK_EQ(V->seg_cu[2], (int32_t)(n_text + kper)); /* key 0 | key 1 */
|
||||
CHECK_EQ(V->seg_cu[3], (int32_t)(n_text + 2 * kper)); /* key 1 | audio target */
|
||||
CHECK_EQ(V->seg_cu[4], (int32_t)(n_text + 2 * kper + audio)); /* audio | video target */
|
||||
CHECK_EQ(V->seg_cu[5], (int32_t)widened); /* video grid ends the row */
|
||||
CHECK_EQ(V->lat_cu[1], (int32_t)vtarget); /* sampler owns the target streams */
|
||||
CHECK_EQ(V->lat_cu[3], (int32_t)audio); /* only, never the pinned rows */
|
||||
/* The keyframe table: {n_refs = 0, n_keys = 2}, then two 3-word key triples. Checked
|
||||
* while the step's job is still alive -- the driver retires a finished job (freeing this
|
||||
* table) on the next() that follows its last pass. */
|
||||
const int32_t* tab = V->ref_tab;
|
||||
REQUIRE(tab != nullptr);
|
||||
CHECK_EQ(tab[0], 0); /* no references */
|
||||
CHECK_EQ(tab[1], 2); /* two endpoint keys */
|
||||
CHECK_EQ(tab[2], 0); /* first pins output frame 0 */
|
||||
CHECK_EQ(tab[3], 1); /* one latent frame of video */
|
||||
CHECK_EQ(tab[4], 0); /* no soundtrack */
|
||||
CHECK_EQ(tab[5], s.frames - 1); /* last pins the final frame */
|
||||
CHECK_EQ(tab[6], 1);
|
||||
CHECK_EQ(tab[7], 0);
|
||||
}
|
||||
f.answer(10 * i);
|
||||
CHECK_OK(f.drv.done());
|
||||
}
|
||||
CHECK(saw_first);
|
||||
CHECK(saw_last);
|
||||
CHECK(saw_step);
|
||||
}
|
||||
|
||||
/* What the container cannot consume is refused at submit, naming the part or the budget it breaks —
|
||||
* never silently dropped into a weaker video. A reference video, soundtrack or audio needs the VAE
|
||||
* encoders; on a container converted without them (encodes 0) they are refused by name here, and on
|
||||
|
||||
+67
-1
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user