Archived
ref2va: merged-cell modulation lifts the reference-photo ceiling from five to nine
A modulation cell is a pure function of a segment's kind -- (modality ada, timestep block) -- so all reference photos share one cell. Runs of consecutive same-cell segments collapse to a group; group boundaries are a subset of the fine segment boundaries and the merge is sequence-length independent (the key is kind alone). The modulated norm now reads COARSER group boundaries via a new trailing RadVideoGenBatch::mod_cu while attention keeps the fine seg_cu, and the fixed-width table is pitched by GROUP count. Nine photos therefore occupy four groups (prompt / all-photos / soundtrack / video); buffer sizes and the arena are unchanged (kMaxSegs stays 8, no kernel change, no re-convert). No regression for <=5 photos: each photo cell already filled its own column from the same input rows and weights, so it was bit-identical to the others; merging issues it once instead of N times and yields the same per-row value. Only the previously-rejected sixth through ninth photos change, by being allowed. Driver: rad_arch_video_mod_segs (trailing plugin export) computes the merged groups host-side; the driver stages them into R_MOD, guards the GROUP count against max_ref_segs at submit (a clean refusal beats a step-loop fault), and the plain path stages the fine table into both operands. Device-verified on dual gfx1201 / TP2 with a CONTROLLED same-seed battery (task=ref2va, seed fixed on every job, so neither the seed nor the token count is a confounder): same prompt, same seed, same ref-count, DIFFERENT image content give DIFFERENT outputs -- the reference is genuinely consumed. Nine photos complete (the case the pinned build refused at submit), whole-run fault scan clean. Adds docs/NOTE-REF2VA.md: what this port reproduces of the DaSiWa workflow and what it does not -- the residual 8-group ceiling under heavy interleaved mixed refs, the reference-token / row budget, continuity tail (unimplemented), the video/audio reference paths (plumbed, not yet device-verified), references x latent-upscale exclusion, and open conditioned-step parity. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
490d4c604a
commit
72624973ad
15 files changed
+454
-59
No files matched your search
@@ -294,6 +294,11 @@ VideoPackFn rad_tools_video_pack(const LoadedPlugins& lp) {
|
||||
return ap ? ap->arch_video_pack : nullptr;
|
||||
}
|
||||
|
||||
VideoModSegsFn rad_tools_video_mod_segs(const LoadedPlugins& lp) {
|
||||
const Plugin* ap = rad_tools_registry().plugin(lp.arch_plugin);
|
||||
return ap ? ap->arch_video_mod_segs : nullptr;
|
||||
}
|
||||
|
||||
EncodeGeomFn rad_tools_encode_geom(const LoadedPlugins& lp) {
|
||||
const Plugin* ap = rad_tools_registry().plugin(lp.arch_plugin);
|
||||
return ap ? ap->arch_encode_geom : nullptr;
|
||||
|
||||
@@ -110,6 +110,12 @@ using VideoPackFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, i
|
||||
int64_t);
|
||||
VideoPackFn rad_tools_video_pack(const LoadedPlugins& plugins);
|
||||
|
||||
/* The architecture plugin's merged modulation-group boundaries (rad_arch_video_mod_segs), or null
|
||||
* when it exports none -- the driver then stages the fine segment table into the norm operand, which
|
||||
* is correct for any pack that merges nothing (plain or single-reference). */
|
||||
using VideoModSegsFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t);
|
||||
VideoModSegsFn rad_tools_video_mod_segs(const LoadedPlugins& plugins);
|
||||
|
||||
/* The architecture plugin's encode-pass geometry (rad_arch_encode_geom), or null when it
|
||||
* exports none -- the driver then runs no encode pass. */
|
||||
using EncodeGeomFn = int64_t (*)(int32_t, const int64_t*, int32_t*, int64_t);
|
||||
|
||||
+1
-1
@@ -1518,7 +1518,7 @@ int Engine::serve(std::unique_ptr<StallWatch> watch) {
|
||||
auto d = std::make_unique<gen::VideoDriver>();
|
||||
RAD_TRY(d->init(ranks_[0]->program, rad_tools_video_positions(plugins_), gio,
|
||||
rad_tools_video_segs(plugins_), rad_tools_video_pack(plugins_),
|
||||
rad_tools_encode_geom(plugins_)));
|
||||
rad_tools_video_mod_segs(plugins_), rad_tools_encode_geom(plugins_)));
|
||||
vid_gen_ = d.get();
|
||||
gen_ = std::move(d);
|
||||
RAD_TRY(rad_dev_set(ranks_[0]->device));
|
||||
|
||||
+41
-12
@@ -181,6 +181,7 @@ int64_t carve(const RadVideoGenDecl& d, int64_t max_tok, int64_t ep, int64_t pd,
|
||||
d.max_enc_frames * d.max_enc_side * d.max_enc_side * 3 * 4, /* R_ENCPX: [f,h,w,3] f32 */
|
||||
d.max_enc_samples * d.audio_channels * 4, /* R_ENCSM: [ch,n] f32 */
|
||||
25 * 4, /* R_ENCG: rad_arch_encode_geom's 25 i32 (the video geom) */
|
||||
kSegCap * 4, /* R_MOD: the merged modulation-group boundaries (<= R_SEG) */
|
||||
};
|
||||
int64_t off = 0;
|
||||
for (int r = 0; r < n; ++r) {
|
||||
@@ -223,7 +224,7 @@ int64_t VideoDriver::device_bytes(const Program& prog) {
|
||||
|
||||
int VideoDriver::init(const Program& prog, PositionsFn positions,
|
||||
const std::vector<RankIO>& ranks, SegsFn segs, PackFn pack,
|
||||
EncodeGeomFn enc_geom) {
|
||||
ModSegsFn mod_segs, EncodeGeomFn enc_geom) {
|
||||
fini();
|
||||
if (!prog.is_video_generator()) return RAD_E_STATE;
|
||||
decl_ = prog.video_gen;
|
||||
@@ -234,6 +235,7 @@ int VideoDriver::init(const Program& prog, PositionsFn positions,
|
||||
positions_ = positions;
|
||||
segs_ = segs;
|
||||
pack_ = pack;
|
||||
mod_segs_ = mod_segs;
|
||||
enc_geom_ = enc_geom;
|
||||
max_tok_ = prog.ctx.max_tok;
|
||||
encoder_bounds(prog, &max_enc_, &patch_dim_);
|
||||
@@ -430,18 +432,32 @@ int VideoDriver::submit(std::unique_ptr<VideoRequest> r, std::string* why) {
|
||||
return no("the reference conditioning layout has no closing segment boundary");
|
||||
j->seg.resize((size_t)nseg);
|
||||
j->nseg = nseg;
|
||||
/* The denoiser lays out one modulation cell per segment and its table is a fixed width the
|
||||
* arch declares; a pack wider than it would abort the step mid-generation and take the
|
||||
* engine with it. Refuse here, at submit, where a clean answer is still possible. */
|
||||
const int nsegs = nseg - 1; /* `seg` is boundaries: one more than the segments */
|
||||
if (d.max_ref_segs > 0 && nsegs > d.max_ref_segs) {
|
||||
const int nrefs = j->ref_tab.empty() ? 0 : j->ref_tab[0];
|
||||
const int64_t fit = (int64_t)d.max_ref_segs - (nsegs - nrefs); /* the fixed non-ref cells */
|
||||
return no("these references lay the conditioning out in " + std::to_string(nsegs) +
|
||||
" sequence segments but this deployment's conditioning table holds " +
|
||||
std::to_string(d.max_ref_segs) + ", so at most " +
|
||||
std::to_string(fit < 0 ? 0 : (int)fit) + " fit -- ask for fewer references");
|
||||
/* The modulation groups. A modulation cell is fixed by a segment's kind, so the denoiser
|
||||
* merges runs of consecutive same-cell segments and pitches its fixed-width table by the
|
||||
* GROUP count, not the reference count -- which is how nine reference photos (four groups:
|
||||
* prompt, all-photos, soundtrack, video) ride a table the fine layout (twelve segments)
|
||||
* would overrun. The plugin merges for us (rad_arch_video_mod_segs); one that exports none
|
||||
* merges nothing, so the group table is the fine one and the older per-segment ceiling
|
||||
* applies. Refuse over-wide merges here, at submit, where a clean answer is still possible. */
|
||||
int nmod = -1;
|
||||
if (mod_segs_) {
|
||||
j->mod_seg.assign((size_t)kSegCap, 0);
|
||||
nmod = (int)mod_segs_(&j->geom, j->ref_tab.data(), j->mod_seg.data(), kSegCap);
|
||||
if (nmod < 0 || nmod > kSegCap)
|
||||
return no("the model could not merge the reference conditioning into its "
|
||||
"modulation groups");
|
||||
j->mod_seg.resize((size_t)nmod);
|
||||
} else {
|
||||
nmod = nseg; /* nothing merges: the groups are the fine segments */
|
||||
j->mod_seg = j->seg;
|
||||
}
|
||||
j->nmod = nmod;
|
||||
const int ngroups = nmod - 1; /* `mod_seg` is boundaries: one more than the groups */
|
||||
if (d.max_ref_segs > 0 && ngroups > d.max_ref_segs)
|
||||
return no("these references change the conditioning's modulation cell " +
|
||||
std::to_string(ngroups) + " times, but this deployment's modulation table holds " +
|
||||
std::to_string(d.max_ref_segs) + " cells -- ask for references that share their "
|
||||
"modalities and target, or fewer of them");
|
||||
/* `rows` stays the plain text+audio+video count: every non-step pass (encode, decode,
|
||||
* audio, upscale) stages its own segment table and target counts from it and must see the
|
||||
* bytes it sees today. Only build_step runs at the widened `step_rows`. */
|
||||
@@ -677,6 +693,18 @@ void VideoDriver::stage_geom(const Job& j, const RadVideoGeom& g0, int64_t rows,
|
||||
}
|
||||
reg_[R_SEG].used = 4 * 4;
|
||||
}
|
||||
/* The norm's merged boundaries. On a widened step that is the plugin's merged group table (a
|
||||
* subset of the fine one just staged into R_SEG); on the plain path and every non-step pass it
|
||||
* is the fine table verbatim -- nothing merges there, so the norm reads the same bytes as the
|
||||
* attention and the generated output is exactly what it was before this operand split. */
|
||||
int32_t* mod = hptr<int32_t>(R_MOD);
|
||||
if (wide && j.nmod > 0) {
|
||||
std::memcpy(mod, j.mod_seg.data(), j.mod_seg.size() * sizeof(int32_t));
|
||||
reg_[R_MOD].used = (int64_t)j.mod_seg.size() * 4;
|
||||
} else {
|
||||
std::memcpy(mod, seg, reg_[R_SEG].used);
|
||||
reg_[R_MOD].used = reg_[R_SEG].used;
|
||||
}
|
||||
int32_t* lat = hptr<int32_t>(R_LAT);
|
||||
lat[0] = 0;
|
||||
lat[1] = (int32_t)video_rows;
|
||||
@@ -710,6 +738,7 @@ void VideoDriver::base_batches(const Job& j, const RadVideoGeom& g, int64_t n_to
|
||||
V.lane_d = dptr<int32_t>(ri, R_LANE);
|
||||
V.first_d = dptr<int32_t>(ri, R_FIRST);
|
||||
V.seg_cu = dptr<int32_t>(ri, R_SEG);
|
||||
V.mod_cu = dptr<int32_t>(ri, R_MOD);
|
||||
V.lat_cu = dptr<int32_t>(ri, R_LAT);
|
||||
V.n_steps = j.sched.steps;
|
||||
V.t_video = dptr<float>(ri, R_TV);
|
||||
|
||||
+19
-3
@@ -39,15 +39,19 @@ public:
|
||||
using SegsFn = int64_t (*)(const RadVideoGeom*, int32_t*, int64_t);
|
||||
using PackFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t,
|
||||
float*, int64_t);
|
||||
using ModSegsFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t);
|
||||
using EncodeGeomFn = int64_t (*)(int32_t, const int64_t*, int32_t*, int64_t);
|
||||
|
||||
/* `positions` is the plugin's rad_arch_video_positions; `segs`, optional, is its
|
||||
* rad_arch_video_segs (null = the driver stages the plain segment table itself); `pack`,
|
||||
* optional, is its rad_arch_video_pack (null = reference-conditioned sequences cannot be
|
||||
* laid out and such requests are refused); `enc_geom`, optional, is its
|
||||
* laid out and such requests are refused); `mod_segs`, optional, is its
|
||||
* rad_arch_video_mod_segs (null = the driver stages the fine segment table into the norm's
|
||||
* operand too, correct for any pack that merges nothing); `enc_geom`, optional, is its
|
||||
* rad_arch_encode_geom (null = no encode pass runs). */
|
||||
int init(const Program& prog, PositionsFn positions, const std::vector<RankIO>& ranks,
|
||||
SegsFn segs = nullptr, PackFn pack = nullptr, EncodeGeomFn enc_geom = nullptr);
|
||||
SegsFn segs = nullptr, PackFn pack = nullptr, ModSegsFn mod_segs = nullptr,
|
||||
EncodeGeomFn enc_geom = nullptr);
|
||||
void fini();
|
||||
~VideoDriver() override { fini(); }
|
||||
|
||||
@@ -94,6 +98,13 @@ private:
|
||||
bool ref_wide = false;
|
||||
int32_t nseg = 0;
|
||||
std::vector<int32_t> seg;
|
||||
/* The same layout merged to modulation groups: consecutive segments sharing a cell collapse,
|
||||
* so `mod_seg` holds a SUBSET of `seg`'s boundaries and `nmod` (its count) is what the
|
||||
* modulation table -- `nmod - 1` cells -- is pitched by. The attention still runs on the fine
|
||||
* `seg`; only the norm reads `mod_seg`. Empty on the plain path (there the driver stages the
|
||||
* plain table into both operands). */
|
||||
std::vector<int32_t> mod_seg;
|
||||
int32_t nmod = 0;
|
||||
int64_t lat_v = 0, lat_a = 0;
|
||||
/* The denoising step's row count: the widened total once references ride, otherwise equal
|
||||
* to `rows`. Only build_step uses it -- the encode, decode, audio and upscale passes keep
|
||||
@@ -144,9 +155,13 @@ private:
|
||||
/* R_ENCPX/R_ENCSM/R_ENCG stage one media item for a Vencode/Aencode pass: the encoder-ready
|
||||
* pixels ([frames,h,w,3] f32) or samples ([ch,n] f32) and the encode geometry the plugin's
|
||||
* rad_arch_encode_geom returned, staged verbatim as device i32 for the kernels to read. */
|
||||
/* R_MOD is the norm's segment boundaries: the merged modulation-group table (a subset of
|
||||
* R_SEG's), which the modulated norm reads for its per-cell modulation while the attention
|
||||
* reads the fine R_SEG. The step stages the merged table; every other pass, and the plain
|
||||
* path, stages R_SEG's bytes into it as well. */
|
||||
enum { R_TOK, R_POS, R_CU, R_ROPE, R_GEOM, R_SCHED, R_TV, R_TA, R_SEED, R_LANE, R_FIRST,
|
||||
R_SEG, R_LAT, R_UP, R_MMROW, R_ENCPIX, R_ENCCRD, R_ENCCU,
|
||||
R_ENCPX, R_ENCSM, R_ENCG, R_N };
|
||||
R_ENCPX, R_ENCSM, R_ENCG, R_MOD, R_N };
|
||||
|
||||
template <class T> T* hptr(int r) const { return reinterpret_cast<T*>(host_ + reg_[r].off); }
|
||||
template <class T> T* dptr(int rank, int r) const {
|
||||
@@ -182,6 +197,7 @@ private:
|
||||
PositionsFn positions_ = nullptr;
|
||||
SegsFn segs_ = nullptr;
|
||||
PackFn pack_ = nullptr;
|
||||
ModSegsFn mod_segs_ = nullptr;
|
||||
EncodeGeomFn enc_geom_ = nullptr;
|
||||
int64_t max_tok_ = 0;
|
||||
/* The conditioning's encoder view: the tower's per-patch width and the patches one pass
|
||||
|
||||
@@ -234,6 +234,12 @@ int Registry::commit_(Staged& s, int order) {
|
||||
p.arch_video_pack =
|
||||
dl_fn<int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t, float*,
|
||||
int64_t)>(s.handle, "rad_arch_video_pack");
|
||||
/* Optional: the merged modulation-group boundaries the norm reads (a subset of the pack's
|
||||
* fine segment boundaries). Absent, the driver stages the fine table into the norm operand
|
||||
* -- fine whenever nothing merges. */
|
||||
p.arch_video_mod_segs =
|
||||
dl_fn<int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t)>(
|
||||
s.handle, "rad_arch_video_mod_segs");
|
||||
/* Optional: the encode passes' geometry; absent means the driver runs no encode pass. */
|
||||
p.arch_encode_geom =
|
||||
dl_fn<int64_t (*)(int32_t, const int64_t*, int32_t*, int64_t)>(
|
||||
|
||||
@@ -101,6 +101,12 @@ struct Plugin {
|
||||
* out and refuses requests that carry VAE references. */
|
||||
int64_t (*arch_video_pack)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t, float*,
|
||||
int64_t) = nullptr;
|
||||
/* Optional (rad_builder.h); the merged modulation-group boundaries a conditioned pack collapses
|
||||
* to (rad_arch_video_mod_segs). Null with arch_video_pack present means the driver stages the
|
||||
* fine table into the norm operand too -- correct whenever nothing merges (a plain or a
|
||||
* single-reference sequence), and refused at submit only when a wide pack would need it. */
|
||||
int64_t (*arch_video_mod_segs)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t) =
|
||||
nullptr;
|
||||
/* Optional (rad_builder.h); null means the driver runs no encode pass. */
|
||||
int64_t (*arch_encode_geom)(int32_t, const int64_t*, int32_t*, int64_t) = nullptr;
|
||||
|
||||
|
||||
Reference in new issue
Block a user