Archived
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:
1 parent
8c547fe240
commit
47b7aae7a3
16 files changed
+320
-4
No files matched your search
@@ -184,6 +184,7 @@ int ref_group_norm(const RadArgs*, RadStream);
|
||||
int ref_tconv_dw(const RadArgs*, RadStream);
|
||||
int ref_resize_bilinear(const RadArgs*, RadStream);
|
||||
int ref_flow_renoise(const RadArgs*, RadStream);
|
||||
int ref_cond_aug(const RadArgs*, RadStream);
|
||||
/* ref_ltx.cpp */
|
||||
int ref_rope_split(const RadArgs*, RadStream);
|
||||
int ref_head_gate(const RadArgs*, RadStream);
|
||||
@@ -437,6 +438,7 @@ REF_SHAPE_FN(ref_group_norm);
|
||||
REF_SHAPE_FN(ref_tconv_dw);
|
||||
REF_SHAPE_FN(ref_resize_bilinear);
|
||||
REF_SHAPE_FN(ref_flow_renoise);
|
||||
REF_SHAPE_FN(ref_cond_aug);
|
||||
REF_SHAPE_FN(ref_rope_split);
|
||||
REF_SHAPE_FN(ref_head_gate);
|
||||
REF_SHAPE_FN(ref_ltx_guide);
|
||||
|
||||
@@ -891,6 +891,11 @@ 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") };
|
||||
/* `aug` is the condition's kept fraction (the reference's VISUAL_COND_TIMESTEP, 0.999); unlike
|
||||
* `flow_renoise` the blend weight is a declared recipe constant, not a staged tensor. */
|
||||
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 (ref_ltx.cpp) */
|
||||
static const RadParamSpec pRopeSplit[] = { P_INT("M"), P_INT("n_head"), P_INT("head_dim"),
|
||||
@@ -1807,6 +1812,11 @@ static const RadOpSchema kSchemas[] = {
|
||||
{ "flow_renoise", ARR(pFlowRenoise), ARR(oFlowRenoise),
|
||||
"a clean latent re-noised to sigma s: x = f32(f32(f32(1 - s) x) + f32(s z)), z element "
|
||||
"k n + c of the normal stream (seed, `stream`) (abi/rad_philox.h)." },
|
||||
{ "cond_aug", ARR(pCondAug), ARR(oCondAug),
|
||||
"a visual condition's rows blended with fresh noise, the reference's condition augmentation: "
|
||||
"x = f32(f32(a x) + f32(oma z)) with a = `aug` and oma the f32 of the f64 1 - aug, z element "
|
||||
"k n + c of the normal stream (seed, `stream`); the caller issues one media item's rows so "
|
||||
"every item restarts the same stream, as the reference does." },
|
||||
{ "rope_split", ARR(pRopeSplit), ARR(oRopeSplit),
|
||||
"LTX-2's rotary over fractional coordinates: dim/2 pairs over all heads, the first `pad` "
|
||||
"unrotated, then freq[k] = f32(theta^linspace(0,1,steps)[k] pi/2) with the n_dims coordinates "
|
||||
@@ -2450,6 +2460,8 @@ SIMPLE("ref_patch_fold", "patch_fold", "elem", "voxel rows to normalised patch r
|
||||
ref_patch_fold),
|
||||
SIMPLE("ref_flow_renoise", "flow_renoise", "elem", "a clean latent re-noised to a sigma", DT_FLOAT,
|
||||
ref_flow_renoise),
|
||||
SIMPLE("ref_cond_aug", "cond_aug", "elem", "condition rows blended with fresh noise at a fixed aug",
|
||||
DT_FLOAT, ref_cond_aug),
|
||||
SIMPLE("ref_rope_split", "rope_split", "elem", "LTX-2's split rotary over coordinates", DT_FLOAT,
|
||||
ref_rope_split),
|
||||
SIMPLE("ref_head_gate", "head_gate", "elem", "each head times 2 sigmoid of its logit", DT_FLOAT,
|
||||
|
||||
@@ -3143,6 +3143,17 @@ int ref_flow_renoise_shape(const RadParam* p, int n_p, int operand, RadOpdDesc*
|
||||
return o.finish("flow_renoise", operand, out);
|
||||
}
|
||||
|
||||
/* aug in [0, 1); the condition rows f32. */
|
||||
int ref_cond_aug_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const double aug = rad_param_getf(p, n_p, "aug", -1.0);
|
||||
if (M <= 0 || n <= 0 || !(aug >= 0.0 && aug < 1.0)) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t_idx({ 2 }, (int64_t)1 << 30, -1, 0); /* seed: two words */
|
||||
o.t((uint32_t)RAD_F32, { M, n }); /* x, INOUT */
|
||||
return o.finish("cond_aug", operand, out);
|
||||
}
|
||||
|
||||
/* ================================================================== video sparse attention
|
||||
*
|
||||
* The tiles come from the values of `segs` and `geom`, which a description draws only as
|
||||
|
||||
@@ -656,3 +656,42 @@ int ref_flow_renoise(const RadArgs* a, RadStream) {
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ cond_aug */
|
||||
/* A visual condition's patchified rows with the reference's condition-noise augmentation, its
|
||||
* `_cond_video_rows` (comfy/ldm/minimax/model.py): every condition latent is blended with fresh
|
||||
* noise before it becomes a condition row, and every condition intentionally restarts the same
|
||||
* RNG stream, so element e = k n + c of row k is
|
||||
*
|
||||
* x[k, c] = f32(f32(a x[k, c]) + f32(oma z(k n + c)))
|
||||
*
|
||||
* a = `aug` (the reference's VISUAL_COND_TIMESTEP, 0.999), oma the one cast to f32 of the f64
|
||||
* 1 - aug (the reference subtracts that scalar in python double and casts per tensor op),
|
||||
* z(e) = rad_philox_normal_s(seed, stream, e) (abi/rad_philox.h), `seed` two u32 words low first
|
||||
* -- the request's seed -- and `stream` the parameter. x is f32 [M, n] at its row pitch.
|
||||
* The reference redraws the same seed every forward, so the blend is a fixed function of the
|
||||
* request; the arch applies it once to the encoded condition rows, per media item, which is
|
||||
* exactly the reference's per-item restart. */
|
||||
int ref_cond_aug(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 2)) return RAD_E_INVAL;
|
||||
const RadTensor *seed = &a->t[0], *x = &a->t[1];
|
||||
const int64_t n = p_int(a, "n", 0), stream = 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 || stream < 0 || !(aug >= 0.0 && aug < 1.0) || numel(seed) < 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)ldi(seed, 0) | ((uint64_t)(uint32_t)ldi(seed, 1) << 32);
|
||||
const int64_t xs = laststride(x);
|
||||
REF_PAR_FOR(rows * n * 8)
|
||||
for (int64_t k = 0; k < rows; ++k) {
|
||||
const int64_t xb = rowoff(x, k, n);
|
||||
for (int64_t c = 0; c < n; ++c) {
|
||||
const float z = rad_philox_normal_s(sd, (uint64_t)stream, (uint64_t)(k * n + c));
|
||||
stt(x, xb + c * xs, av * ldt(x, xb + c * xs) + omv * z);
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
Reference in new issue
Block a user