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
+29
-2
@@ -268,7 +268,10 @@ int ref_rms_mod_quant_fp8(const RadArgs* a, RadStream) {
|
||||
/* y[m] = [cos(t' f_0) .. cos(t' f_{h-1}) | sin(t' f_0) .. sin(t' f_{h-1})], h = n / 2, where
|
||||
* f_i = exp(-ln(max_period) * i / h) in f32 and t' = scale * t -- or, with `round` 1, the value
|
||||
* diffusers' pipeline hands its transformer: t rounded to bf16 at scale, divided back and rounded
|
||||
* again, then scaled: scale * bf16(bf16(t * scale) / scale). */
|
||||
* again, then scaled: scale * bf16(bf16(t * scale) / scale).
|
||||
* With `curve` = G > 0 and a `table` [G, n] f32 operand instead: y[m] = table sampled at
|
||||
* clamp01(max(t[m], clamp_min)) * (G - 1), lerped between the two rows around that position -- the
|
||||
* precomputed adaln time curve a curve-form checkpoint ships in place of the sinusoid + MLP. */
|
||||
int ref_timestep_embed(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 2)) return RAD_E_INVAL;
|
||||
const RadTensor *t = &a->t[0], *y = &a->t[1];
|
||||
@@ -277,9 +280,33 @@ int ref_timestep_embed(const RadArgs* a, RadStream) {
|
||||
const double mp = p_f32(a, "max_period", 10000.0f);
|
||||
const int round = (int)p_int(a, "round", 0);
|
||||
const float clamp = p_f32(a, "clamp_min", 0.0f);
|
||||
if (n <= 0 || (n & 1)) return RAD_E_SHAPE;
|
||||
if (n <= 0) return RAD_E_SHAPE;
|
||||
const int64_t grid = p_int(a, "curve", 0);
|
||||
if (!grid && (n & 1)) return RAD_E_SHAPE;
|
||||
const int64_t rows = rows_of(y, n);
|
||||
if (rows <= 0 || numel(t) < rows) return RAD_E_SHAPE;
|
||||
if (grid > 0) {
|
||||
/* The precomputed adaln curve: y[m] = table sampled at clamp01(max(t, clamp_min)) *
|
||||
* (grid - 1), lerped between the two rows around that position. */
|
||||
const RadTensor* tab = t_in(a, 2);
|
||||
if (!tab) return RAD_E_INVAL;
|
||||
if (tab->dtype != (uint32_t)RAD_F32 || numel(tab) < grid * n) return RAD_E_SHAPE;
|
||||
for (int64_t m = 0; m < rows; ++m) {
|
||||
const float tv = std::fmax(ldt(t, offlin(t, m)), clamp);
|
||||
const float pos = std::fmin(std::fmax(tv, 0.0f), 1.0f) * (float)(grid - 1);
|
||||
float i0f = std::floor(pos);
|
||||
if (i0f > (float)(grid - 2)) i0f = (float)(grid - 2);
|
||||
const float fr = pos - i0f;
|
||||
const int64_t i0 = (int64_t)i0f;
|
||||
const int64_t yb = rowoff(y, m, n), ys = laststride(y);
|
||||
for (int64_t i = 0; i < n; ++i) {
|
||||
const float a0 = ldt(tab, offlin(tab, i0 * n + i));
|
||||
const float a1 = ldt(tab, offlin(tab, (i0 + 1) * n + i));
|
||||
stt(y, yb + i * ys, a0 + fr * (a1 - a0));
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
const int64_t h = n / 2;
|
||||
const float coef = (float)(-std::log(mp));
|
||||
for (int64_t m = 0; m < rows; ++m) {
|
||||
|
||||
@@ -680,8 +680,9 @@ static const RadOperandSpec oFlowX0[] = { OPD("v"), OPD("t"), OPD("sigma"), OPD(
|
||||
static const RadOperandSpec oFlowRM[] = { OPD("v"), INOUT("x0"), OPD("sigma"), OPD("r"),
|
||||
OPD("hb1"), OPD("hb2"), OPD("order"), INOUT("x") };
|
||||
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[] = { OPD("t"), OUT("y") };
|
||||
P_INTO("round"), P_F64O("clamp_min"), P_INTO("curve"),
|
||||
P_STR("dtype") };
|
||||
static const RadOperandSpec oTimestep[] = { OPD("t"), OUT("y"), WGT_O("table") };
|
||||
static const RadOperandSpec oGather2[] = { OPD("a"), OPD("b"), OPD("idx"), OUT("y") };
|
||||
static const RadParamSpec pLane[] = { P_INT("M"), P_INT("n"), P_INT("stride"), P_STR("dtype") };
|
||||
static const RadOperandSpec oLaneGather[] = { OPD("src"), OPD("lane"), OPD("cu_seqlens"), OUT("y") };
|
||||
@@ -1379,7 +1380,9 @@ static const RadOpSchema kSchemas[] = {
|
||||
{ "timestep_embed", ARR(pTimestep), ARR(oTimestep),
|
||||
"the sinusoidal timestep embedding, [cos | sin] of t' * exp(-ln(max_period) * i / (n/2)) with "
|
||||
"t' = scale * t; `round` 1 takes t through bf16 at scale and back first, as diffusers' "
|
||||
"pipeline hands it to its transformer." },
|
||||
"pipeline hands it to its transformer. With `curve` > 0 and a `table` [curve, n] f32 operand: "
|
||||
"y[m] = table sampled at clamp01(max(t[m], clamp_min)) * (curve - 1), lerped between the two "
|
||||
"rows around that position -- a precomputed adaln time-embedding curve." },
|
||||
{ "gather_rows2", ARR(pMnD), ARR(oGather2),
|
||||
"y[i] = idx[i] >= 0 ? a[idx[i]] : b[-1 - idx[i]]: a sequence assembled from two sources." },
|
||||
{ "lane_gather", ARR(pLane), ARR(oLaneGather),
|
||||
|
||||
@@ -2276,10 +2276,11 @@ int ref_gate_add_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return o.finish("gate_add", operand, out);
|
||||
}
|
||||
int ref_timestep_embed_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 int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0), G = gi(p, n_p, "curve", 0);
|
||||
Opd o;
|
||||
o.t_fill((uint32_t)RAD_F32, { M }, (uint32_t)RAD_FILL_SIGMOID, 0); /* t: a sigma in (0, 1) */
|
||||
o.t(act_dt(p, n_p), { M, n }); /* y */
|
||||
if (G > 0) o.t((uint32_t)RAD_F32, { G, n }); else o.skip(); /* table (curve mode) */
|
||||
return o.finish("timestep_embed", operand, out);
|
||||
}
|
||||
int ref_gather_rows2_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
|
||||
Reference in new issue
Block a user