keyframes: feed endpoint keyframes through the vision tower (TE-anchor tokens)

Image-conditioned MiniMax-H3 (I2VA/L2VA/FL2VA = first_frame/last_frame) rendered
over-saturated / posterized while T2VA was clean on the same container. Root cause:
the reference conditions a keyframe TWICE -- a vision-tower anchor (clip.tokenize
images=[kf] -> <Picture N> soft-tokens in the text conditioning) AND a VAE-latent pin --
but Radiance did only the VAE pin for endpoint keyframes. The absent semantic anchor
left the DiT reconstructing the frame from low-level VAE pixels alone -> posterize /
black-outline / oversaturation.

Route endpoint keyframes through the existing vision-tower media path, so they produce
<Picture N> anchor soft-tokens in addition to their VAE pin (the reference's dual
channel). No new kernels, no ABI / arena change: build_cond stages r->media generically
and the arch scatter is the generic op_mm.

  - videos.cpp: keyframe index = <Picture> ordinal (first=1,last=2); stable-sort keys
    by kind before merge; run the prepare+placement loops for FIRST/LAST_FRAME as well
    as IMAGE (area-matched tower form, aspect-kept; the exact-canvas VAE pin is a
    separate, unchanged second encode); budget wording covers keyframes.
  - video_driver.cpp: a towerless container no longer refuses a keyframe request (skip
    FIRST/LAST_FRAME in the "needs a vision tower" scan) -> pin-only path runs; the
    encodes guard still requires the VAE encoder and now labels a keyframe correctly.

Device A/B (uncensored w8a8, TP2, seed 1234, 512^2): prompt tokens i2va 27->291,
fl2va 1560->2088 (the +256 / +2*256 keyframe vision tokens + labels), t2va 27->27.
T2VA output is bit-identical across binaries (text path untouched). Image-conditioned
output diverges (cos 0.77/0.80): the realistic I2VA mid-frame recovers foliage
structure (blobs -> trees), softens outlines and shadow detail toward the clean control;
FL2VA gains semantic adherence (prompted "wings spread" now renders). Endpoint-pin
cosine unchanged (0.971 / 0.988 / 0.980, at/above the 0.985 bar). No budget reject.

Tests: fl2va keyframes now feed the tower and still pin the ends (index 1/2, token
stream with both vision blocks); towerless fl2va pins-only; driver-level keyframe
conditions through the tower and needs no tower. NOTE-REF2VA.md #8 closed.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-21 01:06:26 -05:00
1 parent 8785774fc0
commit cd393a0973
6 files changed
+212 -26

No files matched your search

+75
View File
@@ -985,6 +985,81 @@ TEST(a_keyframe_completes_widen_the_step_and_pin_the_ends) {
CHECK(saw_step);
}
/* The keyframe's SECOND channel: when the container carries a vision tower, a keyframe request that
* also carries processed media runs a conditioning pass that stages the tower's rows (the anchor
* tokens) ALONGSIDE the VAE pin. So a request yields BOTH a VENCODE pass (the pin at image slot 1) and
* a VCOND pass (the tower run), exactly as a reference picture conditions -- the keyframe is not merely
* a pin once a tower is present. */
TEST(a_keyframe_completion_also_conditions_through_the_tower) {
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;
CHECK_OK(f.start_with_pack_encode(fake_pack_ref, fake_encode_geom));
std::string why;
auto r = f.req(2);
r->tokens = { 1, 700, 701, 2, 3 }; /* a <Picture 1> anchor run sits in the prompt */
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);
r->refs.push_back(first);
r->media = picture_media(6, 1); /* the SAME keyframe also feeds the tower */
CHECK_OK(f.drv.submit(std::move(r), &why));
bool saw_cond = false, saw_pin = false;
for (int i = 0; i < 20; ++i) {
const RadBatch* b = f.drv.next(i);
if (!b) break;
if (b->gen == RAD_GEN_PASS_VCOND) {
saw_cond = true;
CHECK_EQ(b->n_mm_rows, (int64_t)2); /* the keyframe's tower run */
CHECK(b->mm_rows != nullptr);
CHECK_EQ(b->enc_n_patch, (int64_t)8); /* its patches staged for the tower */
CHECK(b->enc_pixels != nullptr);
} else if (b->gen == RAD_GEN_PASS_VENCODE) {
saw_pin = true;
CHECK_EQ(b->vgen_b->enc_kind, (int32_t)RAD_ENC_IMAGE);
CHECK_EQ(b->vgen_b->enc_slot, (int32_t)1);
}
f.answer(10 * i);
CHECK_OK(f.drv.done());
}
CHECK(saw_cond); /* the anchor channel ran ... */
CHECK(saw_pin); /* ... alongside the VAE pin */
}
/* A keyframe is a VAE-latent pin, so it conditions through the encoders, NOT the vision tower: a
* container converted WITHOUT its tower still renders it (pin-only). Only reference media -- whose
* identity soft tokens come from the tower -- are refused on such a container. */
TEST(a_keyframe_completion_needs_no_vision_tower) {
VideoFixture f;
f.build(); /* no with_tower: the container carries no vision tower */
RadVideoGenDecl& d = f.prog.video_gen;
d.encodes = 1; /* it does carry the VAE encoders, which the pin needs */
d.enc_ratio = 16;
d.max_enc_frames = 1;
d.max_enc_side = 16;
d.ref_rows = 1;
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 }; /* no tower run: no media placed */
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);
r->refs.push_back(first);
CHECK_OK(f.drv.submit(std::move(r), &why)); /* the pin-only path admits without a tower */
}
/* 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