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

+43
View File
@@ -774,6 +774,24 @@ __global__ __launch_bounds__(kT) void flow_renoise_kernel(
*p = a + bz;
}
// ---------------------------------------------------------------------------- cond_aug
// x = a x + oma z, a the aug parameter, oma the f32 of the f64 1 - a, z element k n + c of the
// (seed, stream) normal stream: a thread a value, each product and the sum one f32 rounding.
__global__ __launch_bounds__(kT) void cond_aug_kernel(
const uint32_t* __restrict__ seed, float* __restrict__ x, float a, float oma,
int n, int ldx, long long total, unsigned long long stream) {
const long long id = (long long)blockIdx.x * kT + threadIdx.x;
if (id >= total) return;
const long long k = id / n;
const int c = (int)(id % n);
const uint64_t sd = (uint64_t)seed[0] | ((uint64_t)seed[1] << 32);
const float z = rad_philox_normal_s(sd, stream, (uint64_t)id);
float* p = x + k * ldx + c;
const float av = a * *p;
const float bz = oma * z;
*p = av + bz;
}
inline bool is_bf16(const RadTensor* t) { return t && t->dtype == RAD_BF16; }
inline bool is_f32(const RadTensor* t) { return t && t->dtype == RAD_F32; }
inline bool is_i32(const RadTensor* t) { return t && t->dtype == RAD_I32; }
@@ -1088,3 +1106,28 @@ extern "C" int r4d_rad_flow_renoise(const RadArgs* a, RadStream stream) {
0, (const float*)r4d_p(sg), (const uint32_t*)r4d_p(seed), (float*)r4d_wp(x),
(int)n, (int)ldx, total, (unsigned long long)sm);
}
/* ------------------------------------------------------------------ cond_aug */
enum { CA_SEED = 0, CA_X };
extern "C" int r4d_rad_cond_aug(const RadArgs* a, RadStream stream) {
const RadTensor *seed = r4d_opt(a, CA_SEED), *x = r4d_opt(a, CA_X);
if (!seed || !x) return R4D_NO(RAD_E_INVAL);
if (!is_f32(x) || (seed->dtype != RAD_U32 && seed->dtype != RAD_I32))
return R4D_NO(RAD_E_DTYPE);
const long long n = r4d_geti_or(a, "n", 0), sm = r4d_geti_or(a, "stream", 0);
const double aug = r4d_getf(a, "aug", -1.0);
if (n <= 0 || sm < 0 || !(aug >= 0.0 && aug < 1.0) || r4d_numel(seed) < 2)
return R4D_NO(RAD_E_SHAPE);
long long rx = 0;
const long long ldx = r4d_rows_pitch(x, n, &rx);
if (ldx < 0 || !r4d_contig(seed)) return R4D_NO(RAD_E_STRIDE);
/* Every row of x, as libref's; M is not read. */
const long long M = rx;
if (M <= 0) return R4D_NO(RAD_E_SHAPE);
const long long total = M * n;
const float av = (float)aug, omv = (float)(1.0 - aug);
return R4D_EMIT(stream, cond_aug_kernel, dim3((unsigned)((total + kT - 1) / kT)), dim3(kT),
0, (const uint32_t*)r4d_p(seed), (float*)r4d_wp(x), av, omv,
(int)n, (int)ldx, total, (unsigned long long)sm);
}