PIN ref2va: verified device differential + ref-count gate (revert anchor)

Ref2VA ref-image conditioning verified on-device: ref step runs all steps no
fault; output differs ref-present vs ref-absent (by log). 6-9 images rejected
cleanly at submit (no engine crash). Merged-cell modulation (<=9) tracked next.
NOTE: placeholder author -- re-author before any push. Do NOT push this branch.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-19 12:04:47 -05:00
1 parent 816e24bd46
commit 490d4c604a
73 files changed
+16484 -432

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ extern "C" {
* kind of plugin reports it, and a plugin that does not report exactly this version is refused at
* load with both versions printed. A new optional export (e.g. rad_plugin_reference) is not a
* change of shape: a plugin without it gets the default. */
#define RAD_ABI_VERSION 22u
#define RAD_ABI_VERSION 23u
/* ================================================================== plugin identity */
/* One value per plugin, not flags (QUANT is 3). RAD_PLUGIN_QUANT is a quantiser plugin:
+99 -1
View File
@@ -853,9 +853,29 @@ int rad_declare_audio_generator(RadBuilder* b, const RadAudioGenDecl* d);
* pass carries the geometry its latent has at that point: a step before the VUPSCALE pass is at
* W' x H'. The schedule is the request's own, whatever size each evaluation runs at.
*
* Reference conditioning (ref2va), for a program whose container carries the VAE encoders
* (`encodes`, below): before the prompt pass the driver encodes the request's reference media,
* one media a pass. Nothing the passes make is read back — each latent lands in the lane, and the
* step's packed sequence carries it:
*
* RAD_GEN_PASS_VENCODE one reference video's frames, staged in `enc_pixels` (RadVideoGenBatch),
* to the lane's video latents.
* RAD_GEN_PASS_AENCODE one reference audio's samples, staged in `enc_samples`, to the lane's
* soundtrack latents.
*
* `enc_kind` names the media (RAD_ENC_*, rad_runtime.h) and `enc_slot` is its 1-based number
* within that kind; RAD_ENC_TAIL — slot 0 — is the request's continuity tail, the frames of the
* clip it continues, which rides Vencode. The media an encoder takes is bounded by the model:
* reference pictures are one frame, reference video and the tail up to 289 frames, every frame
* at most 256 x 256 with both sides multiples of 16, and a reference audio up to 500 000
* samples; `rad_arch_encode_geom` (below) is the authority and refuses what it cannot encode. A
* program without the encoders declares neither pass and `encodes` stays 0, so the server
* refuses a request that carries references.
*
* A program declares exactly one of this, the other generators, logits or pooled vectors. */
enum { RAD_GEN_PASS_VCOND = 8, RAD_GEN_PASS_VSTEP = 9, RAD_GEN_PASS_ADECODE = 10,
RAD_GEN_PASS_VDECODE = 11, RAD_GEN_PASS_VUPSCALE = 12 };
RAD_GEN_PASS_VDECODE = 11, RAD_GEN_PASS_VUPSCALE = 12,
RAD_GEN_PASS_VENCODE = 13, RAD_GEN_PASS_AENCODE = 14 };
typedef struct RadVideoGenDecl {
const char* name; /* "minimax-h3" -- the served model id and messages */
@@ -902,6 +922,49 @@ typedef struct RadVideoGenDecl {
* and fewer than the default schedule's. */
double upscale_max;
int32_t upscale_refine;
/* Reference media a request may carry (ref2va): the ceilings the server enforces and
* `/v1/models` reports. All 0 — the zero default — on a generator that conditions on no
* reference media, which is how the server refuses the task outright; a generator declares
* them only once it can actually consume the bytes. Trailing since ABI 22: an older plugin's
* declaration reads none and keeps the 0 default. */
int64_t max_ref_images, max_ref_videos, max_ref_audios;
/* Nonzero when the container carries the video and audio VAE encoders, so the driver may
* stage Vencode and Aencode passes (above). Trailing since ABI 23: an older plugin declares
* none and keeps the 0 default. */
int32_t encodes;
/* The ceilings one encode pass may carry, so the driver can size its staging slab: a video's
* clip-padded frame count, the encoder's side (square, a multiple of its downsample), and an
* audio's sample count. Only meaningful with `encodes`; 0 otherwise. The driver stages at most
* one media item per pass, so the slab is these bounds, not a per-request sum. Trailing since
* ABI 23 (the encoder's own pass enums and batch fields): an older plugin declares none. */
int64_t max_enc_frames, max_enc_side, max_enc_samples;
/* The encoder's spatial downsample, so the server can snap a reference's sides to a multiple
* of it before handing them over (the geom refuses any other). Distinct from `size_multiple`,
* which bounds the *generated* video's size and is a further multiple of this. Only meaningful
* with `encodes`; 0 otherwise. Trailing since ABI 23. */
int32_t enc_ratio;
/* Nonzero when this generator's denoiser *consumes* the reference table the driver stages in
* `RadVideoGenBatch::ref_tab` — i.e. its per-step packed sequence already interleaves the
* reference blocks between the text and the audio/video targets, so the driver must size and
* stage those rows (via `rad_arch_video_pack`) rather than the plain `[text|audio|video]`
* layout. Trailing since ABI 23: an older plugin declares none and keeps the 0 default, which
* is exactly the plain path — the driver then never widens rows or segment boundaries and the
* generated bytes are unchanged. It is the arch, not the driver, that knows whether its own
* denoiser reads `ref_tab`, so this flag is what makes staging and consumption flip together. */
int32_t ref_rows;
/* The largest segment count this generator's modulation table holds: its denoiser lays out one
* modulation cell per pack segment, and the table is sized `kMaxSegs` columns. A conditioned
* pack whose segments exceed this cannot be built -- the step would abort the engine. The driver
* refuses such a request at submit (it lays the pack out itself, so it knows the count before
* dispatch) rather than letting the arch fail mid-generation. 0 = no reference consumption, so
* no such limit. Trailing since ABI 23: an older plugin declares none and keeps the 0 default. */
int32_t max_ref_segs;
} RadVideoGenDecl;
int rad_declare_video_generator(RadBuilder* b, const RadVideoGenDecl* d);
@@ -1184,6 +1247,41 @@ typedef struct RadVideoGeom {
enum { RAD_VPOS_STEP = 1, RAD_VPOS_DECODE = 2 };
int64_t rad_arch_video_positions(int which, const RadVideoGeom* g, float* pos, int64_t cap);
/* The packed sequence's segment boundaries for a video generator: cu[k] is the first row of
* segment k (modulation, attention sinks -- whatever segmentation the model lays out), and
* cu[n-1] the sequence's total rows -- the same rows RAD_VPOS_STEP positions. With `cu` null
* it returns the number of int32s needed; with `cap` too small, a negative status. Additive
* export; RAD_ABI_VERSION does not move -- a driver without it stages its own segmentation,
* which for a plain [text | audio | video] request is this table. Called on any thread. */
int64_t rad_arch_video_segs(const RadVideoGeom* g, int32_t* cu, int64_t cap);
/* The geometry of a video generator's encode passes (RAD_GEN_PASS_VENCODE, RAD_GEN_PASS_AENCODE;
* rad_builder.h, "Reference conditioning"): the i32 vector the driver stages into the pass's
* `enc_geom_d` device buffer, derived from the media's own shape, because what the network's
* strided convolutions and causal attention run at — the padded sample length, the latent frame
* count — is only the model's to know. `kind` is the pass value; `in` is four i64s
* {frames_or_samples, height, width, channels}, each unused entry 0. With `out` null it returns
* the number of int32s needed, or a negative status for media the model cannot take; with `out`
* it fills `out[cap]`. The driver stages the samples right-padded with zeros to the length this
* reports (entry 0), and copies these bytes to the device verbatim: it interprets nothing.
* Additive export; RAD_ABI_VERSION does not move — a driver without it drives no encode pass and
* the server refuses references. Called on any thread. */
int64_t rad_arch_encode_geom(int32_t kind, const int64_t* in, int32_t* out, int64_t cap);
/* The whole packed-sequence layout of a reference-conditioned video request: the general form
* of rad_arch_video_segs. `g` is the target's geometry and `ref_tab` the request's keyframes
* and VAE references -- RadVideoGenBatch::ref_tab, its int32 table verbatim -- or null when the
* request conditions on no VAE media, which lays out the plain [text | soundtrack | video]
* sequence. Returns the packed sequence's total rows -- the rows RAD_VPOS_STEP positions -- or
* a negative status for counts the model cannot present or caps too small to write into. With
* `seg` non-null it writes the segment boundaries (seg[k] the first row of segment k, of the n
* it needs) when `cap_seg` int32s hold them; with `pos` non-null the rotary positions (f32
* [3, rows]) when `cap_pos` rows hold them. A null `seg` and `pos` answer with the rows alone,
* which is all a submit needs to size the request. Additive export; RAD_ABI_VERSION does not
* move -- a driver without it refuses reference requests. Called on any thread. */
int64_t rad_arch_video_pack(const RadVideoGeom* g, const int32_t* ref_tab, int32_t* seg,
int64_t cap_seg, float* pos, int64_t cap_pos);
int rad_arch_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx);
/* Forward declaration; the signature is in rad_runtime.h. */
struct RadCtx;
+49
View File
@@ -424,6 +424,8 @@ enum {
* ADECODE no rows of the pass's own.
* VDECODE `dec_rows` rows of the decoder's own (rad_arch_video_positions, RAD_VPOS_DECODE).
* VUPSCALE no rows of the pass's own: the lane's video latent from `geom_from` to `geom`.
* VENCODE no rows of the pass's own: a reference video's pixels in `enc_pixels`.
* AENCODE no rows of the pass's own: a reference audio's samples in `enc_samples`.
*
* Every pointer is device memory unless the name ends in _h. */
typedef struct RadVideoGenBatch {
@@ -468,8 +470,55 @@ typedef struct RadVideoGenBatch {
* soundtrack's) the latents are re-noised to; `seed` is a step's. */
RadVideoGeom geom_from;
const float* upscale; /* f32 [1]: the factor the network is told */
/* ---- VENCODE / AENCODE (rad_builder.h, "Reference conditioning"). `enc_pixels` is a
* Vencode pass's f32 [enc_frames, enc_height, enc_width, 3] row-major RGB, values 0..255 —
* un-normalised: the encoder applies its own pixel normalisation first. `enc_frames` is the
* clip-padded frame count the export reports (entry 23): 1 for a still, else a whole number
* of clips with a short last clip pre-padded by repeating its final frame. `enc_samples` is
* an Aencode pass's f32 [enc_channels, enc_n_samples] channel-major — each channel a
* contiguous sequence the encoder's convolutions read in place — right-padded with zeros to
* the length `rad_arch_encode_geom` reports (its entry 0). `enc_geom_d` is that length and
* the pass's other plugin-defined geometry, device i32, the driver staging verbatim what the
* export returned (the encoder's kernels read the padded lengths from here, as a cu does).
* `enc_kind` names the media the pass carries and `enc_slot` is its 1-based number within
* that kind; RAD_ENC_TAIL is the request's continuity tail — its slot 0 — which rides
* Vencode. A pass writes nothing the core reads back: the latents live in the lane. Trailing
* since ABI 23: a batch an older engine built carries none. */
const float* enc_pixels;
int32_t enc_frames, enc_height, enc_width;
const float* enc_samples;
int64_t enc_n_samples;
int32_t enc_channels;
int32_t enc_slot;
const int32_t* enc_geom_d;
int32_t enc_kind;
/* ---- Reference rows of a VSTEP pass (rad_builder.h, rad_arch_video_pack). `ref_tab` is the
* request's keyframes and VAE references as a host int32 table -- the driver holds it, and
* the step reads it host-side as it reads `geom`. Null when the request conditions on no
* VAE media; otherwise self-describing: [0] the number of references, [1] the number of
* keyframes, then 6 words per reference {kind, slot, height, width, frames, audio} and 3
* words per keyframe {frame, video, audio}, in the order the references are presented. A
* reference's `kind` is 0 a picture, 1 a standalone audio, 2 a video, 3 a video's
* soundtrack; `slot` is its 1-based number within its kind -- the slot its encode pass
* wrote. The counts are latent units: a reference's own latent grid (height, width), its
* latent frames and its audio latents, 0 where the kind carries neither. A batch without
* the field laid out is one an older engine built: no references. Trailing since ABI 23. */
const int32_t* ref_tab;
} RadVideoGenBatch;
/* RadVideoGenBatch::enc_kind: which reference media an encode pass carries. A plugin's latent
* buffer is indexed by the kind and the slot together: two kinds both number their media from
* 1, so the kind is what keeps image 1 and video 1 apart. */
enum {
RAD_ENC_TAIL = 0, /* the request's continuity tail: the frames of the clip it continues */
RAD_ENC_IMAGE = 1, /* a reference picture; rides Vencode */
RAD_ENC_VIDEO = 2, /* a reference video; rides Vencode */
RAD_ENC_VAUDIO = 3, /* the soundtrack of reference video `enc_slot`; rides Aencode */
RAD_ENC_AUDIO = 4 /* a standalone reference audio; rides Aencode */
};
/* RadVideoGenBatch::geom_d. The request's latent geometry, then a VDECODE pass's chunk: the latent
* frames it reads (from latent frame `chunk_lat0`), its latent grid again so that (frames, h, w,
* first, last) is one run, and the same chunk in patches. */