ops+minimaxh3+driver: the condition-noise augmentation the reference adds to visual cond rows

The reference's _cond_video_rows runs every visual conditioning latent through
x = aug x + (1 - aug) z at VISUAL_COND_TIMESTEP 0.999, its generator restarted
per item, while audio conditioning is untouched (its aug is 1.0, a no-op). We
staged the clean latent instead, so every image-, keyframe- and reference-
conditioned render started from un-augmented conditioning.

New op cond_aug: x = f32(f32(a x) + f32(oma z)), a the aug parameter and oma
the f32 of the double 1 - aug -- the reference subtracts in double and rounds
once -- with z the (seed, stream) normal stream at element k n + c on stream
2, the reference's noise never sharing the generator that fills x. Seed words
0-1 of the video's seed, per-item restart by per-row offset. Issued once at
the end of step_venc over the conditioning rows: staging once at encode-build
time is equivalent to the reference's per-call restart because each item's
rows are exactly its own, and the driver's build_encode now re-stages the
seed, where a stale lane's words used to ride through.

Reference RNG is MT19937 and ours Philox, so the noise is distributionally
faithful, not bit-exact. ABI unchanged at 28. Device: r4d_selftest 0 failures,
cond_aug rows 1.13e-9/4.42e-8 rel_l2 against libref.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-25 08:45:29 -05:00
1 parent 8c547fe240
commit 47b7aae7a3
16 files changed
+320 -4

No files matched your search

+4
View File
@@ -935,6 +935,10 @@ std::vector<Case> build_cases() {
0, 2.0 * 27 * v.cin * v.cout * 27);
add("flow_renoise", { HI("M", 9), HI("n", 96), HI("stream", 1), HS("dtype", "f32") });
add("flow_renoise", { HI("M", 5), HI("n", 645), HI("stream", 7), HS("dtype", "f32") });
add("cond_aug", { HI("M", 9), HI("n", 96), HI("stream", 2), HF("aug", 0.999),
HS("dtype", "f32") });
add("cond_aug", { HI("M", 5), HI("n", 645), HI("stream", 7), HF("aug", 0.5),
HS("dtype", "f32") });
/* LTX-2: the video's 3-axis rotary (two padded pairs, a rank's second head), the cross
* attentions' 1-axis one, the per-head gate and the guided step. */
+1 -1
View File
@@ -127,7 +127,7 @@ int avx_par_force(int threads);
X(flow_res_multistep) \
X(vtile_gather) X(vtile_stitch) X(grid_pos3) X(vsa_select) \
X(attn_vsa) X(conv3d_ndhwc) X(group_norm) X(tconv_dw) \
X(resize_bilinear) X(patch_fold) X(flow_renoise) \
X(resize_bilinear) X(patch_fold) X(flow_renoise) X(cond_aug) \
/* ---- LTX-2 */ \
X(rope_split) X(head_gate) X(ltx_guide) X(pixel_norm) \
X(d2s3d) X(s2d3d) X(pix_patch) \
+8
View File
@@ -671,6 +671,9 @@ static const RadOperandSpec oResize[] = { OPD("x"), OPD("geom"), OUT("y") };
static const RadParamSpec pFlowRenoise[] = { P_INT("M"), P_INT("n"), P_INT("stream"),
P_STR("dtype") };
static const RadOperandSpec oFlowRenoise[] = { OPD("sigma"), OPD("seed"), INOUT("x") };
static const RadParamSpec pCondAug[] = { P_INT("M"), P_INT("n"), P_INT("stream"), P_F64("aug"),
P_STR("dtype") };
static const RadOperandSpec oCondAug[] = { OPD("seed"), INOUT("x") };
/* ---- LTX-2 (avx_ltx.cpp) */
static const RadParamSpec pRopeSplit[] = { P_INT("M"), P_INT("n_head"), P_INT("head_dim"),
@@ -1212,6 +1215,9 @@ static const RadOpSchema kSchemas[] = {
{ "flow_renoise", ARR(pFlowRenoise), ARR(oFlowRenoise),
"x = f32(f32(1 - s) x) + f32(s z), z the (seed, stream) normal stream at k n + c, bit for bit "
"libref's." },
{ "cond_aug", ARR(pCondAug), ARR(oCondAug),
"x = f32(f32(a x) + f32(oma z)) with a the `aug` parameter and oma the f32 of the f64 1 - aug, "
"z the (seed, stream) normal stream at k n + c, bit for bit libref's." },
{ "rope_split", ARR(pRopeSplit), ARR(oRopeSplit),
"LTX-2's split rotary over fractional coordinates, libref's arithmetic element by element." },
{ "head_gate", ARR(pHeadGate), ARR(oHeadGate),
@@ -1779,6 +1785,8 @@ SIMPLE("avx_patch_fold", "patch_fold", "elem", "voxel rows to normalised patch r
L(patch_fold)),
SIMPLE("avx_flow_renoise", "flow_renoise", "elem", "a clean latent re-noised to a sigma",
DT_FLOAT, L(flow_renoise)),
SIMPLE("avx_cond_aug", "cond_aug", "elem", "condition rows blended with fresh noise at a fixed aug",
DT_FLOAT, L(cond_aug)),
SIMPLE("avx_rope_split", "rope_split", "elem", "LTX-2's split rotary over coordinates", DT_FLOAT,
L(rope_split)),
SIMPLE("avx_head_gate", "head_gate", "elem", "each head times 2 sigmoid of its logit", DT_FLOAT,
+34
View File
@@ -833,3 +833,37 @@ AVX_KERNEL(flow_renoise) {
}
return RAD_OK;
}
/* ------------------------------------------------------------------ cond_aug */
/* x = f32(f32(a x) + f32(oma z)) over x's rows, a the `aug` parameter, oma the f32 of the f64
* 1 - aug, z the (seed, stream) normal stream at k n + c (libref's, bit for bit): a visual
* condition's rows with the reference's condition-noise augmentation. */
AVX_KERNEL(cond_aug) {
if (!rad_args_have(a, 2)) return RAD_E_INVAL;
const RadTensor *SD = &a->t[0], *X = &a->t[1];
const int64_t n = p_int(a, "n", 0), sm = p_int(a, "stream", 0);
const RadParam* ap = p_find(a, "aug");
if (!ap || ap->kind != RAD_P_F64) return RAD_E_SHAPE;
const double aug = ap->dval;
if (n <= 0 || sm < 0 || !(aug >= 0.0 && aug < 1.0) || numel(SD) < 2) return RAD_E_SHAPE;
const int64_t rows = rows_of(X, n);
if (rows <= 0) return RAD_E_SHAPE;
const float av = (float)aug, omv = (float)(1.0 - aug);
const uint64_t sd = (uint64_t)(uint32_t)at(SD, 0) | ((uint64_t)(uint32_t)at(SD, 1) << 32);
AVX_PARALLEL_FOR_IF(rows * n * 8 >= AVX_PAR_MIN)
for (int64_t k = 0; k < rows; ++k) {
float* buf = scratch_f32((size_t)(3 * n + 48));
float *xs = buf, *z = xs + n + 16, *o = z + n + 16;
const float* x = in_row(X, rowoff(X, k, n), n, xs);
philox_normals_s(sd, (uint64_t)sm, (uint64_t)(k * n), n, z);
const vf va = vf_set1(av), vo = vf_set1(omv);
int64_t c = 0;
for (; c + VF_N <= n; c += VF_N)
vf_storeu(o + c, vf_add(keep(vf_mul(va, vf_loadu(x + c))),
keep(vf_mul(vo, vf_loadu(z + c)))));
for (; c < n; ++c) o[c] = keep(av * x[c]) + keep(omv * z[c]);
out_row(X, rowoff(X, k, n), n, o);
}
return RAD_OK;
}