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

+17 -5
View File
@@ -85,10 +85,14 @@ __global__ __launch_bounds__(kT) void rms_mod_kernel(
const uint16_t* __restrict__ w, const int* __restrict__ cu, uint16_t* __restrict__ x,
uint8_t* __restrict__ q, float* __restrict__ qs, uint16_t* __restrict__ z, int n, int n_seq,
float eps, int y_ld, int g_ld, int s_ld, int x_ld, int q_ld, int qs_ld, int z_ld, float wadd,
int once, int layer, int none) {
int once, int layer, int none, const int* __restrict__ colmap) {
__shared__ float sh[kT / 32];
const int r = blockIdx.x;
const int e = seq_of(cu, n_seq, r);
int e = seq_of(cu, n_seq, r);
// Optional column indirection: `cu` may bound MORE groups than the modulation table has
// columns (groups that share a cell map to one column), so a group index is translated to its
// table column here -- null leaves the segment index itself, exactly as before.
if (colmap) e = colmap[e];
uint16_t* xr = x + (size_t)r * x_ld;
float v[kRmChunks][8];
float ss = 0.0f;
@@ -489,6 +493,10 @@ static int rms_mod_launch(const RadArgs* a, RadStream st, int qmode) {
const RadTensor* q = qmode ? r4d_opt(a, 6) : nullptr;
const RadTensor* qs = qmode ? r4d_opt(a, 7) : nullptr;
const RadTensor* z = r4d_opt(a, qmode ? 8 : 6);
// Optional group->column map, issued after the last operand of either mode (slot 9 with the
// quantising chain, slot 7 with the plain one). Absent for every other issuer: the segment
// index remains the column.
const RadTensor* cm = r4d_opt(a, qmode ? 9 : 7);
if (!sc || !cu || !x || (qmode ? (!q || !qs) : !z)) return R4D_NO(RAD_E_INVAL);
const bool gated = r4d_geti_or(a, "gated", 0) != 0;
if (gated && (!y || !g)) return R4D_NO(RAD_E_INVAL);
@@ -513,8 +521,12 @@ static int rms_mod_launch(const RadArgs* a, RadStream st, int qmode) {
if (ql < 0 || (ql & 7) || ((uintptr_t)q->data & 7) || qsl < 0) return R4D_NO(RAD_E_STRIDE);
}
const long long n_seq = r4d_numel(cu) - 1, rows = qmode ? rq : rz;
if (rows <= 0 || n_seq <= 0 || rx < rows || rs < n_seq || (w && r4d_numel(w) < n) ||
(qmode && rqs < rows) || (gated && (ry < rows || rg < n_seq)) || (z && rz < rows))
if (cm && (!is_i32(cm) || !r4d_contig(cm) || r4d_numel(cm) < n_seq))
return R4D_NO(RAD_E_SHAPE);
// With the map the table rows index the COLUMNS, not the groups, so its row count need not
// reach n_seq; the issuer (the only one who passes a map) guarantees mapped columns < rows.
if (rows <= 0 || n_seq <= 0 || rx < rows || (!cm && rs < n_seq) || (w && r4d_numel(w) < n) ||
(qmode && rqs < rows) || (gated && (ry < rows || (!cm && rg < n_seq))) || (z && rz < rows))
return R4D_NO(RAD_E_SHAPE);
const float eps = (float)r4d_getf(a, "eps", 1e-6);
const float wadd = (float)r4d_getf(a, "wadd", 0.0);
@@ -532,7 +544,7 @@ static int rms_mod_launch(const RadArgs* a, RadStream st, int qmode) {
Q ? (uint8_t*)q->data : nullptr, Q ? (float*)qs->data : nullptr, \
z ? (uint16_t*)z->data : nullptr, (int)n, (int)n_seq, eps, (int)yl, \
(int)gl, (int)sl, (int)xl, (int)ql, (int)qsl, (int)zl, wadd, once, layer, \
none)
none, cm ? (const int*)cm->data : nullptr)
if (qmode == 2) {
if (gated) R4D_RMQ(true, 2);
else R4D_RMQ(false, 2);