Archived
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:
1 parent
8785774fc0
commit
cd393a0973
6 files changed
+212
-26
No files matched your search
+9
-1
@@ -85,7 +85,15 @@ struct VideoRefMedia {
|
||||
* each into the pack's keyframe table and encodes it into an image slot (a keyframe request
|
||||
* carries no references, so those slots are free). The server resizes each to the target canvas
|
||||
* (first a plain stretch, last a centre crop) and sets enc_pixels to one frame at that size, so
|
||||
* its latent grid is the target's exactly and its pinned rows are frame_rows wide. */
|
||||
* its latent grid is the target's exactly and its pinned rows are frame_rows wide.
|
||||
* A keyframe is fed to the DiT on TWO channels, matching the reference (clip.tokenize +
|
||||
* vae.encode): the VAE-latent pin above, AND -- when the container carries a vision tower -- a
|
||||
* <Picture k> anchor block through the tower (its `data` bytes are prepared as media and its
|
||||
* soft tokens interleaved into the text conditioning). That anchor is the semantic counterpart
|
||||
* to the low-level VAE pin; without it the DiT reconstructs the frame from pixels alone and
|
||||
* over-saturates. `index` is the keyframe's <Picture> ordinal (first = 1, last = 2), not a
|
||||
* per-kind count, so the block is labelled the way the source workflow names it. On a towerless
|
||||
* container the anchor channel is absent and the pin-only path runs unchanged. */
|
||||
enum Kind : int32_t { IMAGE = 0, VIDEO = 1, VIDEO_AUDIO = 2, AUDIO = 3, FIRST_FRAME = 4, LAST_FRAME = 5 };
|
||||
Kind kind = IMAGE;
|
||||
int32_t index = 0;
|
||||
|
||||
@@ -345,7 +345,15 @@ int VideoDriver::submit(std::unique_ptr<VideoRequest> r, std::string* why) {
|
||||
* pack lays those slots between the text and the target streams (RadVideoGenBatch::ref_tab).
|
||||
* Every kind the declaration allows is consumed; the guard below is only about a container
|
||||
* lacking its vision tower, which could encode nothing. */
|
||||
if (!r->refs.empty() && max_enc_ == 0)
|
||||
/* Reference media need the vision tower (their identity soft tokens). Endpoint keyframes do not:
|
||||
* they condition through the VAE-latent pin, so a container converted without its tower can still
|
||||
* render them -- the server simply lays no `media` for them and the pin-only path runs. (Keyframes
|
||||
* still need the VAE encoders, checked just below.) */
|
||||
bool has_ref_media = false;
|
||||
for (const VideoRefMedia& m : r->refs)
|
||||
if (m.kind != VideoRefMedia::FIRST_FRAME && m.kind != VideoRefMedia::LAST_FRAME)
|
||||
has_ref_media = true;
|
||||
if (has_ref_media && max_enc_ == 0)
|
||||
return no("this container was converted without its vision tower, so no request can "
|
||||
"carry reference media");
|
||||
/* A reference video, soundtrack or standalone audio reaches the model only through the VAE
|
||||
@@ -358,12 +366,16 @@ int VideoDriver::submit(std::unique_ptr<VideoRequest> r, std::string* why) {
|
||||
if (m.kind != VideoRefMedia::IMAGE)
|
||||
return no("'" + m.name + "' is a reference " +
|
||||
(m.kind == VideoRefMedia::VIDEO ? "video"
|
||||
: m.kind == VideoRefMedia::VIDEO_AUDIO ? "soundtrack" : "audio") +
|
||||
: m.kind == VideoRefMedia::VIDEO_AUDIO ? "soundtrack"
|
||||
: m.kind == VideoRefMedia::FIRST_FRAME ||
|
||||
m.kind == VideoRefMedia::LAST_FRAME ? "keyframe" : "audio") +
|
||||
", but this container was converted without its VAE encoders, so nothing "
|
||||
"can condition on it");
|
||||
/* Only reference images add language-model soft-token rows, so only they need processed media.
|
||||
* A reference video or audio reaches the model purely through the VAE encode rows the pack lays
|
||||
* from the reference table, so a request of those alone carries no `media` and needs none. */
|
||||
/* Only pictures (reference images and endpoint keyframes) add language-model soft-token rows, so
|
||||
* only they need processed media. A reference video or audio reaches the model purely through the
|
||||
* VAE encode rows the pack lays from the reference table, so a request of those alone carries no
|
||||
* `media` and needs none. A keyframe with no tower also carries no `media` — that is the deliberate
|
||||
* pin-only fallback, not a silent weakening (its VAE pin still conditions the DiT). */
|
||||
bool has_image = false;
|
||||
for (const VideoRefMedia& m : r->refs)
|
||||
if (m.kind == VideoRefMedia::IMAGE) has_image = true;
|
||||
|
||||
+28
-8
@@ -310,7 +310,11 @@ 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;
|
||||
m.index = 1;
|
||||
/* The keyframe's <Picture k> ordinal, so its vision-anchor block is labelled the way
|
||||
* the source workflow names it (first = <Picture 1>, last = <Picture 2>). A keyframe
|
||||
* request carries no reference media (checked below), so these numbers cannot collide
|
||||
* with a reference's own <Picture k>. */
|
||||
m.index = m.kind == gen::VideoRefMedia::FIRST_FRAME ? 1 : 2;
|
||||
m.name = p.name;
|
||||
m.filename = p.filename;
|
||||
m.content_type = p.content_type;
|
||||
@@ -603,9 +607,15 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
r->refs = std::move(refs);
|
||||
/* Keyframes ride the reference vector for the driver's sake (its encode queue indexes it), but
|
||||
* 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. first before last, so they keyframe-order
|
||||
* 0 and 1 and take image slots 1 and 2. */
|
||||
* 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 <Picture 1> then <Picture 2>. */
|
||||
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) */
|
||||
});
|
||||
r->refs.insert(r->refs.end(), keys.begin(), keys.end());
|
||||
const bool has_keys = !keys.empty();
|
||||
|
||||
/* ---- the prompt: the template's text with special tokens, the reference media in its
|
||||
* presentation order, the prompt last (docs/PORT-REF2VA.md §3: images, then videos each
|
||||
@@ -630,7 +640,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
* soundtrack's `<Audio j>` label is emitted right before its video's `<Video k>` label, and
|
||||
* `audio_ord` counts soundtracks and standalone audios together, in the order they are
|
||||
* spoken (docs/PORT-REF2VA.md §3). */
|
||||
if (ref2va && deps_.mm && deps_.mm->accepts(MediaKind::Image)) {
|
||||
if ((ref2va || has_keys) && deps_.mm && deps_.mm->accepts(MediaKind::Image)) {
|
||||
/* Every picture is decoded and processed before any token is laid down. A reference
|
||||
* video or audio needs no vision item here — it reaches the model through the VAEs, so
|
||||
* it contributes only its presentation label to the prompt (the 2 fps timestamped
|
||||
@@ -638,8 +648,18 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
std::vector<std::shared_ptr<mm::Item>> pics;
|
||||
MediaOpts mo;
|
||||
mo.max_pixels = (int64_t)W * (int64_t)H; /* `match`: scaled to the output's area */
|
||||
/* A reference image and an endpoint keyframe are both fed to the vision tower: the keyframe
|
||||
* gets a <Picture k> anchor block here (the soft tokens the reference also feeds) IN
|
||||
* ADDITION to the VAE-latent pin it takes from `enc_pixels` below — the reference's own
|
||||
* split (clip.tokenize + vae.encode). A reference picture and a keyframe never share a
|
||||
* request, so `pics` holds one or the other. */
|
||||
auto anchor = [](const gen::VideoRefMedia& m) {
|
||||
return m.kind == gen::VideoRefMedia::IMAGE ||
|
||||
m.kind == gen::VideoRefMedia::FIRST_FRAME ||
|
||||
m.kind == gen::VideoRefMedia::LAST_FRAME;
|
||||
};
|
||||
for (const gen::VideoRefMedia& m : r->refs) {
|
||||
if (m.kind != gen::VideoRefMedia::IMAGE) continue;
|
||||
if (!anchor(m)) continue;
|
||||
const std::vector<uint8_t> bytes(m.data.begin(), m.data.end());
|
||||
std::shared_ptr<mm::Item> it;
|
||||
std::string why;
|
||||
@@ -662,7 +682,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
if (!pics.empty()) media = std::make_shared<mm::PromptMedia>();
|
||||
size_t i = 0;
|
||||
for (const gen::VideoRefMedia& m : r->refs) { /* sorted by (kind, index): images first */
|
||||
if (m.kind != gen::VideoRefMedia::IMAGE) continue;
|
||||
if (!anchor(m)) continue;
|
||||
put("<Picture " + std::to_string(m.index) + ">: ", false);
|
||||
mm::Placed pl;
|
||||
pl.item = pics[i++];
|
||||
@@ -691,8 +711,8 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) {
|
||||
put(t.substr(p + kSlot.size()), true);
|
||||
}
|
||||
if ((int64_t)r->tokens.size() > info.max_text)
|
||||
return bad("prompt", "the prompt" + std::string(ref2va ? " with its reference media"
|
||||
: "") +
|
||||
return bad("prompt", "the prompt" + std::string((ref2va || has_keys)
|
||||
? " with its media" : "") +
|
||||
" is " + std::to_string(r->tokens.size()) +
|
||||
" tokens; this model takes at most " +
|
||||
std::to_string(info.max_text));
|
||||
|
||||
Reference in new issue
Block a user