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

+25 -9
View File
@@ -3080,15 +3080,27 @@ static minimaxh3::Ref2VAPack ref_pack_of(const RadVideoGeom* g, const int32_t* r
/* Which encoder slot each reference part's latents sit in, in the order ref2va_build lays the
* reference segments down -- a standalone soundtrack alone; a clip its soundtrack (when it carries
* one) then its video; a picture its video alone. The encode pass wrote these into b_evc / b_enca at
* the same slot it names here (the driver's queue uses the ref's own index). Keyframe (cond) rows
* ride the continuation tail, not an encode, so they are absent -- and get no scatter until the tail
* path lands. `audio` picks the buffer (1 = b_enca, 0 = b_evc); `row` is that buffer's base for the
* the same slot it names here (the driver's queue uses the ref's own index). A keyframe (cond) row is
* encoded the same way a reference is -- a picture anchor rides the image slot its index names, a
* clip anchor's soundtrack the audio slot -- so it takes a part ahead of the references, whose
* segments ref2va_build lays after the keyframes'. `audio` picks the buffer (1 = b_enca, 0 = b_evc); `row` is that buffer's base for the
* part. A row < 0 means the slot is unknown -- a table the encode queue never filled. */
struct RefPart { int audio; int64_t row; };
static void ref_parts(const int32_t* ref_tab, std::vector<RefPart>* out) {
if (!ref_tab) return;
const int32_t nr = ref_tab[0];
const int32_t nr = ref_tab[0], nk = ref_tab[1];
const int32_t* w = ref_tab + 2;
/* Keyframe parts FIRST: ref2va_build lays the sequence [text | keyframes | refs | targets], and
* the scatter consumes parts in segment order, so a keyframe's part precedes every reference's.
* A keyframe's video latent rides the image slot the key's own index names -- a keyframe request
* carries no references, so the image slots are free for it -- and a picture anchor's soundtrack
* (absent for FL2VA's stills, present for a clip keyframe) the standalone-audio slot. `w` stays
* where the reference loop below needs it; the keys trail the references in the table. */
const int32_t* kw = ref_tab + 2 + (int64_t)nr * 6;
for (int32_t i = 0; i < nk; ++i, kw += 3) {
if (kw[1] > 0) out->push_back({ 0, venc_slot_row(RAD_ENC_IMAGE, i + 1) });
if (kw[2] > 0) out->push_back({ 1, aenc_slot_row(RAD_ENC_AUDIO, i + 1) });
}
for (int32_t i = 0; i < nr; ++i, w += 6) {
const int32_t kind = w[0], slot = w[1], aframes = w[5];
if (kind == minimaxh3::kR2VRefAudioOnly) {
@@ -3313,10 +3325,11 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
RAD_W(m.w_ain), RAD_W(m.b_ain), RAD_NONE, brow_slice(m.b_h, aseg, arows, D));
RAD_ISSUE_N(c, m.op_vin, vrows, brow_slice(m.b_vstate, lane * m.maxV, vrows, kPatchVals),
RAD_W(m.w_vin), RAD_W(m.b_vin), RAD_NONE, brow_slice(m.b_h, vseg, vrows, D));
/* Then each reference block: the same input projection, but its latents read from the encoder's
* slot (b_evc / b_enca), scattered into the rows the pack placed between the prompt and the
* targets. Every ref part -- a picture, a clip's video, a clip's or a standalone's soundtrack --
* is one issue, its part list consumed in the order ref2va_build laid the segments down. */
/* Then each conditioning block -- a keyframe's pinned rows, then every reference: the same input
* projection, but its latents read from the encoder's slot (b_evc / b_enca), scattered into the
* rows the pack placed between the prompt and the targets. Every part -- a keyframe's picture
* anchor, a picture, a clip's video, a clip's or a standalone's soundtrack -- is one issue, its
* part list consumed in the order ref2va_build laid the segments down (keyframes first). */
if (refc) {
std::vector<RefPart> parts;
ref_parts(V->ref_tab, &parts);
@@ -3324,7 +3337,10 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
for (const minimaxh3::Ref2VASeg& s : pk.segs) {
const bool img = minimaxh3::ref2va_is_img(s.kind), aud = minimaxh3::ref2va_is_audio(s.kind);
if (!img && !aud) continue; /* text, and the targets above */
if (s.kind != minimaxh3::kR2VRefImg && s.kind != minimaxh3::kR2VRefAudio) continue;
/* A keyframe's pinned rows (kR2VCond / kR2VCondAudio) scatter exactly as a reference's
* do -- same projection, same encoder slot -- so they join the references here. */
if (s.kind != minimaxh3::kR2VRefImg && s.kind != minimaxh3::kR2VRefAudio &&
s.kind != minimaxh3::kR2VCond && s.kind != minimaxh3::kR2VCondAudio) continue;
if (pi >= parts.size()) {
rad_step_fail(c, "minimaxh3: the reference conditioning has more reference blocks "
"than its table describes");