minimaxh3+ops: a picture too big for one volume encodes tile-by-tile, as the reference does

vae.py's tiled_encode cuts a picture bigger than tile_size (256 px, 16
latents) into overlapping tiles, encodes each tile alone, and blends every
tile's RAW moments with its raw top and left neighbours -- top first, then
left, never an already-blended neighbour -- into the whole latent canvas.
GroupNorm normalises inside the volume it sees, so the tile seams are
observable: our port ran the whole canvas through the trunk at once, and a
photo or keyframe over 256 px a side drifted from the reference's look.

Three ops, libref/avx/r4d alike. vtile_plan lays each tile's geometry rows
the way vae.py splits -- round-robin slack, and one short tile on an axis
no longer than a tile. vtile_crop cuts the picture's pixels tile-major.
vtile_join blends the tile-major moments into the plain pass's b_eq2 with
vae.py's weights, every product and sum rounding through x's dtype. The
split carries one structural gift: with the slack fully distributed,
start[last] = len - tile, so every band is exactly a tile, and a short
band exists only in the single-band branch -- whose axis has no neighbour
to blend against. The join can therefore fetch the left neighbour always
at the full tile width while own and top fetch at the owner's own column
width, and vae.py's min() clamp inside blend is provably dead code.

step_venc_tiled runs the plain trunk once a tile: pixels from b_vtile,
moments out to one slice of b_eqt, the tile's six level geometries read
back off b_tplan (PERSIST) through raw pointers, exactly as every clip's
geometries come off enc_geom_d. The arena packs by declared lifetime, so
op_ve_q moved ahead of the trunk and the tiled ops sit last: b_vtile must
span op_ve_pix's first read to op_vt_crop at the tail and b_eqt must span
op_ve_q to op_vt_join, bracketing every trunk op the tiled pass re-runs.
b_vtile and b_eqt size tile-major at the declared tile cap; a picture
splitting past the cap step-fails by name. Clips never tile -- their
volume forces each side back to kEncMaxSide. OPS.md documents all three.

Verified: ref_test 264 cases (plan pins the round-robin overlaps {6,5,5}
and a short lone row with column neighbours; crop walks a short band at
ratio 4; join checks a 6x9 canvas with uneven round-robin splits point by
point, and a 32x32 eighths-exact f32 blend that must land bit-identical);
rad-avx-check scalar/avx/avx2 on all three ops; device r4d_selftest plan
4 / crop 8 (f32+bf16) / join 5 cases ok. Full ctest 123/123. ABI
unchanged at 28.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-25 09:52:15 -05:00
1 parent 47b7aae7a3
commit 69087ce773
15 files changed
+1407 -14

No files matched your search

+60
View File
@@ -2991,6 +2991,22 @@ static int64_t tile_count(int64_t len, int64_t tile, int64_t overlap) {
return nt;
}
/* The encoder's split (ref_video.cpp split_tiles_axis) over one axis: the tile count and the
* tiles' extent sum along it, a lone tile short of `tile` if the axis is. -1 where the split
* refuses. The drawn encode planes are `axis_len` long, so the shape fns can size the tile
* operands exactly. */
static int64_t axis_split(int64_t len, int64_t tile, int64_t overlap, int64_t* ext) {
if (len <= 0 || tile <= 0 || overlap < 0 || overlap >= tile) return -1;
if (tile >= len) {
*ext = len;
return 1;
}
const int64_t nt = tile_count(len, tile, overlap);
/* The extents telescope: sum of the tiles = len + sum of the overlaps = `tile` nt. */
*ext = tile * nt;
return nt;
}
/* A 2 x 2 x 2 grid of patches. */
int ref_patch_unfold_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
const int64_t M = gi(p, n_p, "M", 0), C = gi(p, n_p, "C", 0);
@@ -3154,6 +3170,50 @@ int ref_cond_aug_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
return o.finish("cond_aug", operand, out);
}
/* ---- the tiled encoder. The drawn frame is 20 latent units a side; with the sweep's tile of
* 16 and overlap of 4 the split lays 2 x 2 full tiles over it, so the crops, the plan's level
* triples and the blends all draw non-trivial. The kernels size by the geom; these only draw a
* plane that one gives them. */
int ref_vtile_plan_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
const int64_t M = gi(p, n_p, "M", 0), tile = gi(p, n_p, "tile", 0);
const int64_t ov = gi(p, n_p, "overlap", 0), ratio = gi(p, n_p, "ratio", 0);
int64_t e = 0;
const int64_t nt = axis_split(20, tile, ov, &e);
if (M <= 0 || nt < 0 || ratio <= 0) return RAD_E_UNSUPPORTED;
Opd o;
o.t_idx({ 3 }, 0, 20 * ratio, 0); /* geom: (_, H, W) pixels */
o.t((uint32_t)RAD_I32, { M, 22 }); /* y: one row a tile */
return o.finish("vtile_plan", operand, out);
}
int ref_vtile_crop_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
const int64_t M = gi(p, n_p, "M", 0), tile = gi(p, n_p, "tile", 0);
const int64_t ov = gi(p, n_p, "overlap", 0), ratio = gi(p, n_p, "ratio", 0);
int64_t e = 0;
const int64_t nt = axis_split(20, tile, ov, &e);
if (M <= 0 || nt < 0 || ratio <= 0) return RAD_E_UNSUPPORTED;
const uint32_t D = act_dt(p, n_p);
Opd o;
o.t(D, { 20 * ratio * (20 * ratio), 3 }); /* x: the pixel plane */
o.t_idx({ 3 }, 0, 20 * ratio, 0); /* geom: (_, H, W) pixels */
o.t(D, { M, 3 }); /* y: the tiles' pixels */
return o.finish("vtile_crop", operand, out);
}
int ref_vtile_join_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
const int64_t M = gi(p, n_p, "M", 0), tile = gi(p, n_p, "tile", 0);
const int64_t ov = gi(p, n_p, "overlap", 0), n = gi(p, n_p, "n", 0);
int64_t e = 0;
const int64_t nt = axis_split(20, tile, ov, &e);
if (M <= 0 || nt < 0 || n <= 0) return RAD_E_UNSUPPORTED;
const uint32_t D = act_dt(p, n_p);
Opd o;
o.t(D, { e * e, n }); /* x: the tiles' moments */
o.t_idx({ 3 }, 0, 20, 0); /* geom: (_, lat_h, lat_w) */
o.t(D, { M, n }); /* y: the canvas */
return o.finish("vtile_join", operand, out);
}
/* ================================================================== video sparse attention
*
* The tiles come from the values of `segs` and `geom`, which a description draws only as