minimaxh3+r4d+driver: the prompt's vision pads are modulated as video, not as text

The reference modulates by a per-token TAG: token_tags_from_embeds_info tags
every image embed span (with one flanking token on each side) 0 -- video --
inside the prompt, while audio pads keep tag 1 (parallel PR #236, point 3).
Our port modulated the whole prompt span as text, so every reference photo's
pad tokens read the text ada projection where the reference reads the video
one. The tags arrive in the prompt itself and nothing else carries them, so
the denoiser could not know, and the look drifted with the reference count.

The driver now writes each image item's token span into a tail of ref_tab --
one count, then {start, length} per run, audio items excluded (the reference
tags images only). The tail rides inert through the pack and ref_parts, and
is present exactly when the reference table is, so an i2va request keeps its
old bytes. ref2va_mod_groups grows a runs argument: it cuts the prompt at the
runs' edges and gives the pad pieces the VIDEO cell -- the video projection
on the video-schedule block; the prompt's own timestep row never changes,
only the projection.

Cells stay few however many photos interleave, but groups no longer equal
cells: two prompt pieces separated by a pad share one cell non-adjacently.
So the merged-group output gains a per-group column map, and the modulated-
norm kernels -- libr4d and libref alike -- accept an optional trailing
colmap (slot 9 quant, 7 bf16, past every other arch's last operand) that
redirects sequence -> table column, relaxing the row-count checks it binds.
rad_arch_video_mod_segs exports boundaries then map, the plugin stages both
only for a reference request -- the plain path still stages boundaries alone,
byte-identical -- and the half-split keeps its single video row by taking
the target's column instead of the last one. max_ref_segs now bounds the
DISTINCT CELLS, its old meaning was the group count. ABI 28; no struct's
shape moved, the layout table is re-stamped.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-25 07:29:27 -05:00
1 parent c5483e3241
commit 8a6a1180ce
14 files changed
+548 -139

No files matched your search

+82 -40
View File
@@ -3359,13 +3359,15 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
* consumption all move together behind this one constant; a request with no reference
* table stays on the byte-identical plain path (step_dit's refc gate is `V->ref_tab`). */
d.ref_rows = kRefConsume;
/* The denoiser's modulation table is one cell per modulation GROUP, `kMaxSegs` columns.
* A cell is a pure function of a segment's kind, so a run of consecutive same-cell
* segments -- nine reference photos, say -- shares one cell and the table is pitched by
* the group count, not the reference count; a pack that MERGES to more groups than this
* aborts the step. The driver builds and merges the pack itself (rad_arch_video_mod_segs)
* and reads this cap, refusing an over-wide request at submit -- the model's ceilings
* (max_ref_images & co.) stay the model's, this is the build's table. */
/* The denoiser's modulation table is one column per DISTINCT modulation cell,
* `kMaxSegs` columns. A cell is a pure function of a segment's kind and of a prompt
* vision-pad's tag, so the groups the norm walks -- prompt pieces, pad runs, reference
* blocks, targets -- map onto a handful of columns; the table is pitched by that
* DISTINCT-CELL count, not the group or reference count, and a request whose cells
* exceed it aborts the step. The driver builds and merges the pack itself
* (rad_arch_video_mod_segs) and reads this cap, refusing an over-wide request at submit
* -- the model's ceilings (max_ref_images & co.) stay the model's, this is the build's
* table. */
d.max_ref_segs = kRefConsume ? kMaxSegs : 0;
/* Debug naming of the encoder outputs (R4D_ENC_DEBUG): the driver reads these back and
* logs a digest so the encoder's numbers can be inspected without a step-side d2h the
@@ -3489,6 +3491,24 @@ static minimaxh3::Ref2VAPack ref_pack_of(const RadVideoGeom* g, const int32_t* r
return p;
}
/* The vision-pad tag runs the table's tail carries, after the keyframes: [n, (start, len) x n],
* each run the `vision_start` / tiles / `vision_end` span of one reference photo inside the prompt.
* The reference implementation tags those rows with the VIDEO modality, not text -- the pad run
* keeps the prompt's timestep row but swaps its ada projection -- so the merged modulation groups
* must cut the text segment at these edges. A table without the tail (the counts word absent or
* zero) is the pre-tag-run layout: no runs, groups equal segment kinds. */
static std::vector<minimaxh3::Ref2VATagRun> ref_pads_of(const int32_t* ref_tab) {
std::vector<minimaxh3::Ref2VATagRun> runs;
if (!ref_tab) return runs;
const int32_t nr = ref_tab[0], nk = ref_tab[1];
const int32_t* w = ref_tab + 2 + (int64_t)nr * 6 + (int64_t)nk * 3;
const int32_t np = *w++;
if (np < 0 || np > 4096) return runs; /* a table from before the tail, or corrupt */
for (int32_t i = 0; i < np; ++i, w += 2)
if (w[1] > 0) runs.push_back({ w[0], (int64_t)w[0] + w[1], 0 });
return runs;
}
/* A segment's modulation cell -- its modality's ada projection (0 video, 1 text, 2 audio) and the
* timestep-embedding block it reads over [0,S) video, [S,2S) audio, [2S,3S) video-pinned,
* [3S,4S) audio-pinned -- is a pure function of the segment's kind. That rule lives in one place,
@@ -3658,14 +3678,16 @@ static void step_cond(RadCtx* c, const RadBatch* batch, const Model& m) {
const bool refc = kRefConsume && V->ref_tab;
std::vector<std::pair<int, int64_t>> cell;
if (refc) {
/* One cell per modulation GROUP, not per fine segment. A cell is fixed by a segment's kind
* (its modality's ada projection and its timestep-embedding block), so consecutive
* same-cell segments -- every reference photo, say, all video-pinned -- collapse into one.
* The table is written at the group's column and the norm is handed the group boundaries
* (V->mod_cu), so a wide reference request rides a table pitched by its GROUP count. */
/* One cell per DISTINCT modulation cell -- not per group, and not per fine segment. A cell
* is fixed by a segment's kind (its modality's ada projection and its timestep-embedding
* block), and by the tag of a vision-pad run inside the prompt, so the groups the norm
* walks (prompt, pad, photos, soundtrack, video, ...) address a handful of columns through
* the map staged with the group boundaries. The table is written once per column and the
* norm maps group -> column itself, so a wide reference request rides a table pitched by
* its DISTINCT-CELL count however many groups its pads cut. */
const minimaxh3::Ref2VAPack p = ref_pack_of(&V->geom, V->ref_tab);
minimaxh3::Ref2VAModGroups grp;
minimaxh3::ref2va_mod_groups(p, S, &grp);
minimaxh3::ref2va_mod_groups(p, S, ref_pads_of(V->ref_tab), &grp);
for (size_t i = 0; i < grp.md.size(); ++i) cell.emplace_back(grp.md[i], grp.r0[i]);
} else {
for (int e = 0; e < kSegs; ++e)
@@ -3673,8 +3695,8 @@ static void step_cond(RadCtx* c, const RadBatch* batch, const Model& m) {
}
const int64_t ncell = (int64_t)cell.size();
if (ncell > kMaxSegs) {
rad_step_fail(c, "minimaxh3: the reference conditioning lays out more sequence segments than "
"this plugin's modulation table holds");
rad_step_fail(c, "minimaxh3: the reference conditioning reads more distinct modulation cells "
"than this plugin's modulation table holds");
return;
}
for (int64_t l = 0; l < L; ++l) {
@@ -3721,23 +3743,28 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
* segments and lands every offset exactly as before. */
const bool refc = kRefConsume && V->ref_tab;
minimaxh3::Ref2VAPack pk;
minimaxh3::Ref2VAModGroups grp;
int64_t ng = kSegs; /* modulation groups: the norm table's width */
int64_t vcol = ng - 1; /* the video target's table COLUMN */
int64_t vrows, aseg, vseg;
if (refc) {
pk = ref_pack_of(&V->geom, V->ref_tab);
/* The table is pitched by the merged GROUP count (a cell is fixed by a segment's kind, so
* consecutive same-cell segments collapse), while the attention keeps the fine per-segment
* layout. Checked against the table width is the merged count, not the reference count. */
minimaxh3::Ref2VAModGroups grp;
minimaxh3::ref2va_mod_groups(pk, m.S, &grp);
ng = (int64_t)grp.md.size();
if (ng > kMaxSegs || pk.segs.size() < 2 ||
/* The groups the norm walks (segment kinds merged, the prompt cut at its vision-pad runs)
* address the table through a column map, so the table is pitched by its DISTINCT-CELL
* count while the groups may outnumber it -- and the attention keeps the fine per-segment
* layout. Checked against the table width is the distinct-cell count, not the group or
* reference count. */
minimaxh3::ref2va_mod_groups(pk, m.S, ref_pads_of(V->ref_tab), &grp);
ng = (int64_t)grp.bound.size() - 1;
if (ng < 1 || grp.col.size() != (size_t)ng || (int64_t)grp.md.size() > kMaxSegs ||
pk.segs.size() < 2 ||
pk.segs.back().kind != minimaxh3::kR2VVideo ||
pk.segs[pk.segs.size() - 2].kind != minimaxh3::kR2VAudio) {
rad_step_fail(c, "minimaxh3: the reference conditioning did not merge to a video/audio "
"target pair within the modulation table");
return;
}
vcol = grp.col[(size_t)ng - 1]; /* the video target's own column */
const minimaxh3::Ref2VASeg& vid = pk.segs.back();
vrows = vid.end - vid.start;
aseg = pk.segs[pk.segs.size() - 2].start; /* the audio target, just before the video */
@@ -3840,6 +3867,12 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
* selects its per-reference prefix sinks from the fine `segs`, the norm selects its per-cell
* modulation from `mod_segs`. On the plain path the driver stages identical bytes to both. */
const RadOperand mod_segs = praw(V->mod_cu, RAD_I32, ng + 1);
/* The group->column map: the merged table stages the mod-seg export's combined answer, the
* ng+1 boundaries above followed by the ng columns. The norm maps its group index through it,
* so groups that share a cell read one table column. Half 1 and every plain path need none:
* half 1's slice already starts AT the video target's column, and its two-boundary cu maps to
* the slice's single row. */
const RadOperand mod_col = refc ? praw(V->mod_cu + ng + 1, RAD_I32, ng) : RAD_NONE;
const RadOperand geom = praw(V->geom_d, RAD_I32, RAD_VGEOM_N);
const RadOperand cu = praw(batch->cu_seqlens, RAD_I32, 2);
const RadOperand pos = praw2(V->pos, RAD_F32, 3, R);
@@ -3855,7 +3888,8 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
* run on lane 1 while lane 0 computes the other half; the attention stays whole. The second
* half starts at the video target's middle row -- the video target is the pack's last segment,
* so the half is video alone: the batch's one-sequence cu_seqlens and the video target's
* modulation row (the last cell) stand for the segment table. Lane 0 waits for a half's
* modulation row (its own table column, sliced to one row) stand for the segment table. Lane 0
* waits for a half's
* all-reduce before its first reader, issued before the next all-reduce goes to lane 1 (a join
* orders a lane behind everything issued on the other). */
const bool split = g.world > 1;
@@ -3863,10 +3897,11 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
const int64_t hr0[2] = { 0, cut }, hn[2] = { cut, R - cut };
const int nh = split ? 2 : 1;
const RadOperand segh[2] = { mod_segs, cu };
const RadOperand colh[2] = { mod_col, RAD_NONE };
auto modh = [&](int h, int64_t l, int k, int chunks) {
if (h == 0) return mod(l, k, chunks);
const int64_t r = k / per;
return bcol_at(m.b_modg, r * L * kMaxSegs + l * kMaxSegs + (ng - 1), m.Ws, (k % per) * D,
return bcol_at(m.b_modg, r * L * kMaxSegs + l * kMaxSegs + vcol, m.Ws, (k % per) * D,
chunks * D, 1);
};
/* A half's partial sums across the ranks, kArRows rows a message, on lane 1 when split. */
@@ -3894,7 +3929,7 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
l > 0 ? modh(h, l - 1, 5, 1) : RAD_NONE, modh(h, l, 0, 2),
RAD_W(B.w_n1), segh[h], brow_slice(m.b_h, r0, n, D),
brow_slice(m.a_hm.cq(), r0, n, D), brow_slice(m.a_hm.cs(), r0, n, nD),
RAD_NONE);
RAD_NONE, colh[h]);
/* The dump's per-block window (R4D_DIT_SEL): block l-1's residual STREAM rows
* [0, kDbgL). b_ao is not the stream -- it holds block l-1's raw MLP delta until this
* block's norm folds it -- but op_mq1 writes the folded stream back to b_h, so right
@@ -3937,7 +3972,7 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
RAD_ISSUE_N(c, B.op_mq2, n, brow_slice(m.b_ao, r0, n, D), modh(h, l, 2, 1),
modh(h, l, 3, 2), RAD_W(B.w_n2), segh[h], brow_slice(m.b_h, r0, n, D),
brow_slice(m.a_hm.cq(), r0, n, D), brow_slice(m.a_hm.cs(), r0, n, nD),
RAD_NONE);
RAD_NONE, colh[h]);
B.gate_up.step(c, m.a_hm, m.b_gu, R, r0, n);
B.gq.step(c, m.b_gu, R, r0, n);
B.down.step(c, m.a_ffn, m.b_ao, R, r0, n);
@@ -3952,7 +3987,7 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
(lane * m.S + V->step) * (int64_t)kMaxSegs * 2 * D * (int64_t)sizeof(uint16_t);
RAD_ISSUE_N(c, m.op_nout, R, brows(m.b_ao, R), mod(L - 1, 5, 1),
RAD_P_T2(nout, RAD_BF16, ng, 2 * D), RAD_W(m.w_no_n), mod_segs, brows(m.b_h, R),
brows(m.b_hn, R));
brows(m.b_hn, R), mod_col);
/* Block 49's stream, slot L-1: only op_nout folds the last MLP delta into b_h (the reference
* FinalLayer norms the same post-fold stream), so this follows it. Nothing between here and
* the pass' end writes b_h. */
@@ -4628,17 +4663,22 @@ extern "C" int64_t rad_arch_video_pack(const RadVideoGeom* g, const int32_t* ref
return p.rows;
}
/* The merged modulation-group boundaries: a SUBSET of rad_arch_video_pack's segment boundaries,
* with the boundaries that fall inside a run of consecutive same-cell segments dropped. The
* denoiser's attention reads the fine pack boundaries (each reference needs its own prefix sink),
* but the modulated norm reads these coarser ones -- a modulation cell is fixed by a segment's kind,
* so a run of reference photos shares one cell and one table column, letting nine photos ride the
* fixed `kMaxSegs`-wide table that the twelve fine segments would overrun. The merge is independent
* of the sampler's step count (whether two neighbours share a cell depends only on their kinds), so
* S is passed as 1 here purely to keep the timestep-embedding blocks distinct; the boundaries it
* yields are the ones step_cond/step_dit derive at the real S. A plain geometry collapses to the
* fine table: it is the same pack, and the driver then stages identical bytes to both operands. Call
* with mod = nullptr for the number of int32s needed. */
/* The merged modulation groups, in the combined form the step stages as one operand: the group
* BOUNDARIES followed by the group->table-column MAP. The boundaries are a SUBSET of
* rad_arch_video_pack's segment boundaries, with those falling inside a run of consecutive
* same-cell segments dropped -- and once the reference table carries vision-pad runs, also cut
* inside the prompt wherever the pad tag changes the cell. The denoiser's attention reads the fine
* pack boundaries (each reference needs its own prefix sink), but the modulated norm reads these
* coarser ones. A modulation cell is fixed by a segment's kind (and a pad run's tag), so groups
* REPEAT cells: nine photos share one cell, and the pad groups share the video cell with the target
* -- the map sends every group to one of the handful of distinct cells, letting any group count
* ride the fixed `kMaxSegs`-wide table. The merge is independent of the sampler's step count
* (whether two neighbours share a cell depends only on their kinds and tags), so S is passed as 1
* here purely to keep the timestep-embedding blocks distinct; the boundaries and columns it yields
* are the ones step_cond/step_dit derive at the real S. A plain geometry collapses to the fine
* table with an identity map: it is the same pack, and the norm then reads exactly the pre-map
* bytes. `mod` gets `nb` boundaries then `nb - 1` columns, `2 * nb - 1` int32s total. Call with
* mod = nullptr for the number of int32s needed. */
extern "C" int64_t rad_arch_video_mod_segs(const RadVideoGeom* g, const int32_t* ref_tab,
int32_t* mod, int64_t cap) {
if (!g || g->n_text < 1 || g->n_text > minimaxh3::kMaxText) return RAD_E_INVAL;
@@ -4647,11 +4687,13 @@ extern "C" int64_t rad_arch_video_mod_segs(const RadVideoGeom* g, const int32_t*
return RAD_E_INVAL;
const minimaxh3::Ref2VAPack p = minimaxh3::ref_pack_of(g, ref_tab);
minimaxh3::Ref2VAModGroups grp;
minimaxh3::ref2va_mod_groups(p, 1, &grp);
const int64_t n = (int64_t)grp.bound.size();
minimaxh3::ref2va_mod_groups(p, 1, minimaxh3::ref_pads_of(ref_tab), &grp);
const int64_t nb = (int64_t)grp.bound.size();
const int64_t n = nb + nb - 1;
if (!mod) return n;
if (cap < n) return RAD_E_INVAL;
for (size_t k = 0; k < grp.bound.size(); ++k) mod[k] = (int32_t)grp.bound[k];
for (size_t k = 0; k < grp.col.size(); ++k) mod[nb + k] = (int32_t)grp.col[k];
return n;
}
#endif
+64 -15
View File
@@ -287,24 +287,73 @@ static void cell_of_kind(int kind, int64_t S, int* md, int64_t* r0) {
}
}
void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, Ref2VAModGroups* out) {
out->bound.clear(); out->md.clear(); out->r0.clear();
/* Walk the segments in sequence order, opening a new group whenever the cell changes or a gap
* would otherwise appear. Empty segments carry no rows: they neither extend nor split a group,
* so a run of photos with an empty cond between them still rides one cell. */
int cur_md = 0; int64_t cur_r0 = 0; bool open = false;
int64_t prev_end = 0;
void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, const std::vector<Ref2VATagRun>& runs,
Ref2VAModGroups* out) {
out->bound.clear(); out->col.clear(); out->md.clear(); out->r0.clear();
/* Normalise the tag runs: keep the part of each that falls inside the text segment, drop the
* rest, order by start, and trim a run that would overlap its predecessor -- runs describe
* disjoint token spans, but the driver's view and this one must never disagree by accident. */
std::vector<Ref2VATagRun> norm;
for (const Ref2VATagRun& r : runs) {
Ref2VATagRun c = r;
if (c.end <= c.start) continue;
norm.push_back(c);
}
std::sort(norm.begin(), norm.end(),
[](const Ref2VATagRun& a, const Ref2VATagRun& b) { return a.start < b.start; });
norm.erase(std::unique(norm.begin(), norm.end(),
[](const Ref2VATagRun& a, const Ref2VATagRun& b) {
return a.start == b.start && a.end == b.end && a.tag == b.tag;
}),
norm.end());
/* Lay the row pieces: each non-empty segment contributes its cell, except the text segment,
* which is cut at the (clamped) run edges into prompt pieces (text tag on the text block) and
* pad pieces (the run's tag, still on the video-schedule block -- the reference keeps the pad
* rows on the prompt's timestep row and changes only the ada projection). */
struct Piece { int64_t start, end; int md; int64_t r0; };
std::vector<Piece> pieces;
for (const Ref2VASeg& s : p.segs) {
if (s.end <= s.start) continue;
int md; int64_t r0;
cell_of_kind(s.kind, S, &md, &r0);
if (!open || md != cur_md || r0 != cur_r0 || s.start != prev_end) {
if (open) out->bound.push_back(s.start); /* close the previous group at this start */
else out->bound.push_back(0);
cur_md = md; cur_r0 = r0; open = true;
out->md.push_back(md); out->r0.push_back(r0);
if (s.kind == kR2VText) {
int64_t at = s.start;
for (const Ref2VATagRun& r : norm) {
const int64_t a = std::max(r.start, s.start), b = std::min(r.end, s.end);
if (b <= at) continue; /* fully covered already */
if (a >= s.end) break; /* the rest lies past the prompt */
if (a > at) pieces.push_back({ at, a, 1, 0 });
if (b > at) pieces.push_back({ std::max(a, at), b, r.tag, 0 });
at = std::max(at, b);
}
if (at < s.end) pieces.push_back({ at, s.end, 1, 0 });
continue;
}
prev_end = s.end;
Piece pc; pc.start = s.start; pc.end = s.end;
cell_of_kind(s.kind, S, &pc.md, &pc.r0);
pieces.push_back(pc);
}
/* Merge adjacent pieces that share a cell -- every merge the old segment walk made still
* happens (a photo run is one repeated cell), and the new pad pieces merge back into a
* prompt/neighbour piece exactly when their cells agree. Cells deduplicate into table
* COLUMNS: `md`/`r0` describe the distinct cells, `col` maps each group to its cell. */
int cur_col = -1; bool open = false;
int64_t prev_end = 0;
auto column_of = [&](int md, int64_t r0) {
for (size_t c = 0; c < out->md.size(); ++c)
if (out->md[c] == md && out->r0[c] == r0) return (int)c;
out->md.push_back(md); out->r0.push_back(r0);
return (int)out->md.size() - 1;
};
for (const Piece& pc : pieces) {
const int col = column_of(pc.md, pc.r0);
if (!open || col != cur_col || pc.start != prev_end) {
if (open) out->bound.push_back(pc.start); /* close the previous group at this start */
else out->bound.push_back(0);
cur_col = col; open = true;
out->col.push_back(col);
}
prev_end = pc.end;
}
if (open) out->bound.push_back(p.rows); /* the last group runs to the end of the sequence */
}
+23 -5
View File
@@ -119,15 +119,33 @@ void ref2va_ada_cell(const Ref2VAPack& p, double t_v, double t_a, std::vector<in
* fine per-reference segments. The modulation table is then sized by the group count, not the
* reference count -- which is what lets a wide reference request (up to nine photos) ride a fixed
* table. Groups cover the whole sequence: boundaries start at 0 and end at `rows`. Empty segments
* (end <= start) carry no rows and open no boundary. `md`/`r0` are per group, for the table writer. */
* (end <= start) carry no rows and open no boundary.
*
* The reference implementation modulates by a per-token TAG, not by segment: the prompt span's
* vision-pad rows -- the `vision_start` / tiles / `vision_end` run that wraps every reference
* photo -- carry the video tag (0), not the text tag (1), so they modulate with the video ada
* projection while staying on the text segment's timestep row. `runs` replays that: each run cuts
* the text segment at its edges, and a run's piece reads (md = tag, r0 = 0). The number of GROUPS
* then grows with the media count, but the distinct CELLS never exceed the handful of (md, r0)
* pairs -- text, pad, each reference kind's pinned cell, the two target cells -- so the table is
* sized by DISTINCT CELLS while the groups address it through `col`. */
struct Ref2VATagRun {
int64_t start, end; /* rows [start, end) inside the text segment */
int tag; /* the ada projection the run reads (vision pads: 0) */
};
struct Ref2VAModGroups {
std::vector<int64_t> bound; /* [count + 1]: cumulative row boundaries, [0 .. rows] */
std::vector<int> md; /* [count]: the group's ada projection (0 video, 1 text, 2 audio) */
std::vector<int64_t> r0; /* [count]: the timestep-embedding block the group's cell reads */
std::vector<int> col; /* [count]: which cell (index into md/r0) the group reads */
std::vector<int> md; /* [cells]: the cell's ada projection (0 video, 1 text, 2 audio) */
std::vector<int64_t> r0; /* [cells]: the timestep-embedding block the cell reads */
};
/* `S` is the sampler's step count (the embedding's per-schedule row span); it fixes the pinned
* blocks at [2S,3S) video / [3S,4S) audio, exactly as the arch's ref_cell_of does. */
void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, Ref2VAModGroups* out);
* blocks at [2S,3S) video / [3S,4S) audio, exactly as the arch's ref_cell_of does. `runs` are the
* tag runs inside the text segment -- sorted is not required (they are normalised here), anything
* outside the text span is dropped. An empty `runs` gives exactly the segment-kind merge: cells
* then never repeat, so `col` is the identity and the output matches the pre-tag-run tables. */
void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, const std::vector<Ref2VATagRun>& runs,
Ref2VAModGroups* out);
/* Lay the sequence out. Returns 0, or -1 on a negative dimension (the driver has already bounded
* media against the arch's ceilings; this only refuses nonsense). */