Archived
minimaxh3: adaln_t_table curve-form checkpoints + an R4D_DIT_SEL step dump
The DaSiWa overlay ships its modulation curve as a precomputed table (adaln_t_table [1025,8]): timestep_embed gains a curve mode -- y[m] = the table linearly sampled at the timestep, no sinusoid, no MLP -- in the HIP, AVX and ref tiers, and the arch drives the four timestep rows (video, audio, and each re-embedded with its reference pin) through it with the ada projections as plain bf16 K=8 lines. The dasiwa-w8a8 recipe carries the overlay. Device-verified at 512: T2VA, I2VA and FL2VA complete clean and the T2VA re-run is bit-identical; the fried look PERSISTS on the exact finetune the reference clips rendered from, which kills the checkpoint-style theory and pins the fork to Radiance's forward. For the value-parity localisation: R4D_DIT_SEL (env, driver and plugin) declares f32 PERSIST shadows of the stream entering block 0, the timestep table and the step-0 modulation, and the driver reads those plus the velocity head back on a plain request's step 0 into R4D_ENC_DUMPDIR, for the CPU reference DiT replay to diff against. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
3a7a79fb47
commit
cfbccb46dc
16 files changed
+631
-92
No files matched your search
+41
-2
@@ -216,6 +216,27 @@ __global__ __launch_bounds__(kT) void timestep_kernel(
|
||||
}
|
||||
}
|
||||
|
||||
// The curve form: y[m] = table sampled at clamp01(max(t[m], clamp_min)) * (grid - 1), lerped
|
||||
// between the two rows around that position -- the precomputed adaln curve a curve-form
|
||||
// checkpoint ships in place of the sinusoid + MLP. `table` is contiguous [grid, n] f32.
|
||||
template <typename TY>
|
||||
__global__ __launch_bounds__(kT) void timestep_curve_kernel(
|
||||
const float* __restrict__ t, const float* __restrict__ table, TY* __restrict__ y,
|
||||
int grid, int n, float clamp_min, int y_ld) {
|
||||
const int m = blockIdx.x;
|
||||
const float tv = fmaxf(t[m], clamp_min);
|
||||
const float pos = fminf(fmaxf(tv, 0.0f), 1.0f) * (float)(grid - 1);
|
||||
float i0f = floorf(pos);
|
||||
if (i0f > (float)(grid - 2)) i0f = (float)(grid - 2); /* torch lerp's clamp(max=G-2) */
|
||||
const float fr = pos - i0f;
|
||||
const int i0 = (int)i0f;
|
||||
for (int i = threadIdx.x; i < n; i += kT) {
|
||||
const float a0 = table[(size_t)i0 * n + i];
|
||||
const float a1 = table[(size_t)(i0 + 1) * n + i];
|
||||
st1(y + (size_t)m * y_ld + i, a0 + fr * (a1 - a0));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------- row moves
|
||||
__global__ __launch_bounds__(kT) void gather2_kernel(
|
||||
const uint16_t* __restrict__ a, const uint16_t* __restrict__ b, const int* __restrict__ idx,
|
||||
@@ -753,18 +774,36 @@ extern "C" int r4d_rad_gate_add(const RadArgs* a, RadStream s) {
|
||||
}
|
||||
|
||||
/* Both rows: a bf16 embedding (timestep_embed_bf16) or an f32 one (timestep_embed_f32, a timestep
|
||||
* MLP kept in f32). */
|
||||
* MLP kept in f32). With `curve` = G > 0 and a `table` [G, n] f32 operand the sinusoid is replaced
|
||||
* by a lerp over that precomputed adaln curve. */
|
||||
extern "C" int r4d_rad_timestep_embed(const RadArgs* a, RadStream s) {
|
||||
const RadTensor *t = r4d_opt(a, 0), *y = r4d_opt(a, 1);
|
||||
if (!t || !y) return R4D_NO(RAD_E_INVAL);
|
||||
if (t->dtype != RAD_F32 || !r4d_contig(t) || (!is_bf16(y) && y->dtype != RAD_F32))
|
||||
return R4D_NO(RAD_E_DTYPE);
|
||||
const long long n = r4d_geti_or(a, "n", 0);
|
||||
if (n <= 0 || (n & 1)) return R4D_NO(RAD_E_SHAPE);
|
||||
const long long grid = r4d_geti_or(a, "curve", 0);
|
||||
if (n <= 0 || (!grid && (n & 1))) return R4D_NO(RAD_E_SHAPE);
|
||||
long long ry = 0;
|
||||
const long long yl = r4d_rows_pitch(y, n, &ry);
|
||||
if (yl < 0) return R4D_NO(RAD_E_STRIDE);
|
||||
if (ry <= 0 || r4d_numel(t) < ry) return R4D_NO(RAD_E_SHAPE);
|
||||
if (grid > 0) {
|
||||
const RadTensor* tab = r4d_opt(a, 2);
|
||||
if (!tab) return R4D_NO(RAD_E_INVAL);
|
||||
if (tab->dtype != RAD_F32 || !r4d_contig(tab) || r4d_numel(tab) < grid * n)
|
||||
return R4D_NO(RAD_E_SHAPE);
|
||||
const float clamp = (float)r4d_getf(a, "clamp_min", 0.0);
|
||||
if (y->dtype == RAD_F32)
|
||||
hipLaunchKernelGGL(timestep_curve_kernel<float>, dim3((unsigned)ry), dim3(kT), 0,
|
||||
(hipStream_t)s, (const float*)t->data, (const float*)tab->data,
|
||||
(float*)y->data, (int)grid, (int)n, clamp, (int)yl);
|
||||
else
|
||||
hipLaunchKernelGGL(timestep_curve_kernel<uint16_t>, dim3((unsigned)ry), dim3(kT), 0,
|
||||
(hipStream_t)s, (const float*)t->data, (const float*)tab->data,
|
||||
(uint16_t*)y->data, (int)grid, (int)n, clamp, (int)yl);
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
const float mp = (float)r4d_getf(a, "max_period", 10000.0);
|
||||
const float coef = (float)(-std::log((double)mp));
|
||||
const float scale = (float)r4d_getf(a, "scale", 1000.0);
|
||||
|
||||
+14
-5
@@ -2133,8 +2133,10 @@ static const RadOperandSpec oGateAdd[] = {
|
||||
{ "x", RAD_OPD_INOUT, 0 },
|
||||
};
|
||||
static const RadParamSpec pTimestep[] = { P_INT("M"), P_INT("n"), P_F64("scale"), P_F64("max_period"),
|
||||
P_INTO("round"), P_F64O("clamp_min"), P_STR("dtype") };
|
||||
static const RadOperandSpec oTimestep[] = { { "t", RAD_OPD_IN, 0 }, { "y", RAD_OPD_OUT, 0 } };
|
||||
P_INTO("round"), P_F64O("clamp_min"), P_INTO("curve"),
|
||||
P_STR("dtype") };
|
||||
static const RadOperandSpec oTimestep[] = { { "t", RAD_OPD_IN, 0 }, { "y", RAD_OPD_OUT, 0 },
|
||||
{ "table", RAD_OPD_WEIGHT, 1 } };
|
||||
static const RadOperandSpec oGather2[] = {
|
||||
{ "a", RAD_OPD_IN, 0 }, { "b", RAD_OPD_IN, 0 }, { "idx", RAD_OPD_IN, 0 }, { "y", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
@@ -2969,7 +2971,10 @@ static const RadOpSchema kSchemas[] = {
|
||||
"x = bf16(x + bf16(bf16(tanh(g[seq])) * y)): a residual through its sequence's gate; "
|
||||
"with `act` none the gate is g itself, x = bf16(x + bf16(g[seq] * y))."),
|
||||
SCHEMA("timestep_embed", pTimestep, oTimestep,
|
||||
"the sinusoidal timestep embedding, [cos | sin] of t' * exp(-ln(max_period) * i / (n/2))."),
|
||||
"the sinusoidal timestep embedding, [cos | sin] of t' * exp(-ln(max_period) * i / (n/2)). "
|
||||
"With `curve` > 0 and a `table` [curve, n] f32 operand instead: y[m] is `table` sampled at "
|
||||
"pos = clamp01(max(t[m], clamp_min)) * (curve - 1), linearly between the two rows around "
|
||||
"pos -- an adaln time-embedding curve precomputed at convert."),
|
||||
SCHEMA("gather_rows2", pGenMn, oGather2,
|
||||
"y[i] = idx[i] >= 0 ? a[idx[i]] : b[-1 - idx[i]]."),
|
||||
SCHEMA("lane_gather", pLane, oLaneGather, "y[cu[e] + k] = src[lane[e] * stride + k]."),
|
||||
@@ -4295,8 +4300,12 @@ static const RadConstraint cGenLanes[] = { C_IN("dtype", "bf16 f32") };
|
||||
/* The two lists are kernel arguments, 64 floats each at most (r4d_gen.hip). */
|
||||
static const RadConstraint cGenAffine[] = { C_IN("dtype", "bf16"), C_LE("n", 64) };
|
||||
static const RadConstraint cGenAffineF32[] = { C_IN("dtype", "f32"), C_LE("n", 64) };
|
||||
static const RadConstraint cGenTimestep[] = { C_IN("dtype", "bf16"), C_DIV("n", 2) };
|
||||
static const RadConstraint cGenTimestepF32[] = { C_IN("dtype", "f32"), C_DIV("n", 2) };
|
||||
/* No parity clause on `n` on either timestep row: a row's constraints are unconditional, and the
|
||||
* sinusoid's parity floor (n is its angle pair count) would exclude a curve table, whose n is just
|
||||
* the embedding's column count and can be odd. r4d_rad_timestep_embed checks parity itself when
|
||||
* curve is 0, and returns RAD_E_SHAPE at issue for a sinusoid with odd n. */
|
||||
static const RadConstraint cGenTimestep[] = { C_IN("dtype", "bf16") };
|
||||
static const RadConstraint cGenTimestepF32[] = { C_IN("dtype", "f32") };
|
||||
/* The paged prefix at libr4d's block of 16, both caches bf16, up to eight query heads a KV head
|
||||
* (the shim takes 1, 2, 4 and 8). */
|
||||
static const RadConstraint cAttnPrefixSelf[] = {
|
||||
|
||||
+30
-1
@@ -7638,6 +7638,35 @@ void timestep_f32_case(const Plugin& pl) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The curve form: y[m] lerps the [G, n] f32 table at clamp01(max(t[m], clamp_min)) * (G - 1),
|
||||
* clamping the lower row index to G - 2 -- the device mirror of comfy's adaln curve sampling. */
|
||||
void timestep_curve_case(const Plugin& pl) {
|
||||
const RadKernelInfo* r = find(pl, "timestep_embed_f32");
|
||||
if (!r) { ok("timestep_embed_f32 curve", false, "row absent"); return; }
|
||||
const int64_t M = 33, n = 8, G = 1025;
|
||||
std::vector<float> t((size_t)M), tab = randv((size_t)(G * n), 1.0f);
|
||||
for (int64_t m = 0; m < M; ++m) t[(size_t)m] = (float)m / (float)(M - 1); /* spans [0, 1] */
|
||||
void* dt = up_f32(t);
|
||||
void* dtab = up_f32(tab);
|
||||
void* dy = dalloc((size_t)(M * n) * 4);
|
||||
const int rc = launch(r, { T(dt, RAD_F32, { M }), T(dy, RAD_F32, { M, n }),
|
||||
T(dtab, RAD_F32, { G, n }) },
|
||||
{ PI("M", M), PI("n", n), PI("curve", G), PS("dtype", "f32") });
|
||||
if (rc != RAD_OK) { ok("timestep_embed_f32 curve", false, "rc " + std::to_string(rc)); return; }
|
||||
std::vector<float> want((size_t)(M * n));
|
||||
for (int64_t m = 0; m < M; ++m) {
|
||||
const float pos = std::fmin(std::fmax(t[(size_t)m], 0.0f), 1.0f) * (float)(G - 1);
|
||||
int64_t i0 = (int64_t)std::floor(pos);
|
||||
if (i0 > G - 2) i0 = G - 2;
|
||||
const float fr = pos - (float)i0;
|
||||
for (int64_t i = 0; i < n; ++i) {
|
||||
const float a0 = tab[(size_t)(i0 * n + i)], a1 = tab[(size_t)((i0 + 1) * n + i)];
|
||||
want[(size_t)(m * n + i)] = a0 + fr * (a1 - a0);
|
||||
}
|
||||
}
|
||||
check_f32("timestep_embed_f32 curve numerics", down_f32(dy, want.size()), want, 1e-6);
|
||||
}
|
||||
|
||||
void randn_f32_case(const Plugin& pl) {
|
||||
const RadKernelInfo* r = find(pl, "randn_lanes_f32");
|
||||
if (!r) { ok("randn_lanes_f32", false, "row absent"); return; }
|
||||
@@ -19520,7 +19549,7 @@ static void device_phase(const Plugin& pl) {
|
||||
if (sel("silu_f32")) vg::silu_f32_cases(pl);
|
||||
if (sel("rmsnorm_bf16")) vg::norm_f32_rows_cases(pl, false);
|
||||
if (sel("layernorm_bf16")) vg::norm_f32_rows_cases(pl, true);
|
||||
if (sel("timestep_embed_f32")) vg::timestep_f32_case(pl);
|
||||
if (sel("timestep_embed_f32")) { vg::timestep_f32_case(pl); vg::timestep_curve_case(pl); }
|
||||
if (sel("randn_lanes_f32")) vg::randn_f32_case(pl);
|
||||
if (sel("interleave2_bf16")) vg::interleave2_f32_case(pl);
|
||||
if (sel("chan_affine_f32")) vg::chan_affine_cases(pl, "chan_affine_f32");
|
||||
|
||||
Reference in new issue
Block a user