Archived
sampler: res_multistep (DPM++2M data-pred) as a per-request field; ABI 24
Radiance's video denoising had only first-order Euler. The DaSiWa reference
workflow samples MiniMax-H3 with res_multistep + simple, so add it as a second
order option, exposed as a `sampler` field on /v1/videos (default euler).
New op `flow_res_multistep` across all three kernel tiers (device==avx==libref),
closed form reusing the driver's per-step scalars:
x' = r*x + hb1*den + hb2*x0, den = x + sigma*v, r = sigma_next/sigma
order 2: h=ln(sg/sgn), h_last=ln(sg_prev/sg), r_s=h_last/h,
hb1=(1-r)(1+1/(2 r_s)), hb2=-(1-r)/(2 r_s)
hb1+hb2 == 1-r, so it collapses to Euler when x0==den. Order 1 (Euler) is forced
at the first step, the first full-size step after a latent upscale (stale
history), and the last step (sigma_next==0); order 2 otherwise. The previous
denoised estimate persists in new PERSIST buffers b_vx0/b_ax0. Verified equal to
k-diffusion sample_dpmpp_2m to 5.6e-17 on three sigma grids.
- ABI 23->24: trailing int32_t sampler on RadVideoGenBatch; RAD_SAMPLER_EULER=0
/ RAD_SAMPLER_RES_MULTISTEP=1 in rad_runtime.h.
- driver: R_SCHED region widened 6->16 f32 ([0..5] Euler, [6..10] video coeffs,
[11..15] audio); step_dit branches on V->sampler.
- server: `sampler` string field ("euler"/empty, "res_multistep", else
invalid_request_error with the supported list); echoed on the job object;
capabilities advertise video_samplers.
Tests: rad-avx-check 816 + 451 hand-built, 0 fail (left-assoc grouping matches
ref/device at tol 0); r4d_selftest --case flow_res_multistep_f32 f32|bf16 x
order {1,2} exact, both INOUT pitch gaps untouched.
Device-verified (TP2, fp8 container, 256^2/2s/10-step, seed 1234 identical):
both samplers complete clean 73-frame h264; outputs differ (branch genuinely
consumed, not ignored); bad value rejected; field omitted -> euler. res_multistep
renders warmer/higher-contrast than euler -- a tone lever, not an over-exposure
fix. The euler default path is unchanged.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
c8c8f93789
commit
8785774fc0
18 files changed
+391
-12
No files matched your search
@@ -196,6 +196,7 @@ int r4d_rad_rms_mod (const RadArgs*, RadStream);
|
||||
int r4d_rad_rms_mod_quant_fp8 (const RadArgs*, RadStream);
|
||||
int r4d_rad_rms_mod_quant_i8 (const RadArgs*, RadStream);
|
||||
int r4d_rad_flow_x0_step (const RadArgs*, RadStream);
|
||||
int r4d_rad_flow_res_multistep (const RadArgs*, RadStream);
|
||||
int r4d_rad_patch_unfold (const RadArgs*, RadStream);
|
||||
int r4d_rad_vtile_gather (const RadArgs*, RadStream);
|
||||
int r4d_rad_vtile_stitch (const RadArgs*, RadStream);
|
||||
|
||||
@@ -2306,6 +2306,11 @@ static const RadOperandSpec oFlowX0[] = {
|
||||
{ "v", RAD_OPD_IN, 0 }, { "t", RAD_OPD_IN, 0 }, { "sigma", RAD_OPD_IN, 0 },
|
||||
{ "sigma_next", RAD_OPD_IN, 0 }, { "x", RAD_OPD_INOUT, 0 },
|
||||
};
|
||||
static const RadOperandSpec oFlowRM[] = {
|
||||
{ "v", RAD_OPD_IN, 0 }, { "x0", RAD_OPD_INOUT, 0 }, { "sigma", RAD_OPD_IN, 0 },
|
||||
{ "r", RAD_OPD_IN, 0 }, { "hb1", RAD_OPD_IN, 0 }, { "hb2", RAD_OPD_IN, 0 },
|
||||
{ "order", RAD_OPD_IN, 0 }, { "x", RAD_OPD_INOUT, 0 },
|
||||
};
|
||||
static const RadParamSpec pPatchUnfold[] = { P_INT("M"), P_INT("C"), P_INT("pt"), P_INT("ph"),
|
||||
P_INT("pw"), P_STR("mul"), P_STR("add"),
|
||||
P_STR("dtype") };
|
||||
@@ -3047,6 +3052,9 @@ static const RadOpSchema kSchemas[] = {
|
||||
SCHEMA("flow_x0_step", pGenMn, oFlowX0,
|
||||
"x = r x + (1 - r) (x + (1 - t) v), r = sigma_next / sigma, each step one f32 "
|
||||
"rounding."),
|
||||
SCHEMA("flow_res_multistep", pGenMn, oFlowRM,
|
||||
"x = r x + hb1 (x + sigma v) + hb2 x0, r = sigma_next / sigma, x0 the previous estimate; "
|
||||
"order<2 is Euler."),
|
||||
SCHEMA("patch_unfold", pPatchUnfold, oPatchUnfold,
|
||||
"patch rows unfolded to voxel rows and denormalised with f32 lists."),
|
||||
SCHEMA("vtile_gather", pVtileGather, oVtileGather,
|
||||
@@ -7309,6 +7317,13 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
|
||||
ROW(cGenF32), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_flow_x0_step },
|
||||
|
||||
{ "flow_res_multistep_f32", "flow_res_multistep", "elem",
|
||||
"a second-order sampler step on the clean estimate", "any M, row pitches honoured",
|
||||
"f32 state and estimate history, f32 or bf16 velocity",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
|
||||
ROW(cGenF32), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_flow_res_multistep },
|
||||
|
||||
{ "patch_unfold_f32", "patch_unfold", "elem",
|
||||
"patch rows to denormalised voxel rows, the geometry read on the device",
|
||||
"C <= 64, row pitches honoured", "f32",
|
||||
|
||||
@@ -6388,6 +6388,52 @@ void flow_x0_cases(const Plugin& pl) {
|
||||
}
|
||||
}
|
||||
|
||||
/* flow_res_multistep: an f32 and a bf16 velocity, the state AND the estimate history INOUT at wider,
|
||||
* unequal pitches; order=2 leans on the history, order=1 is the Euler limit. Every value exact, and
|
||||
* both INOUT buffers' pitch gaps left untouched -- the two-INOUT path exercised for the first time. */
|
||||
void flow_rm_cases(const Plugin& pl) {
|
||||
const RadKernelInfo* r = find(pl, "flow_res_multistep_f32");
|
||||
if (!r) { ok("flow_res_multistep_f32", false, "row absent"); return; }
|
||||
const int64_t M = 37, n = 96, xld = 100, x0ld = 102;
|
||||
for (const bool bf : { false, true })
|
||||
for (const float order : { 2.0f, 1.0f }) {
|
||||
std::vector<float> x = randv((size_t)(M * xld), 3.0f), x0 = randv((size_t)(M * x0ld), 2.0f),
|
||||
v = randv((size_t)(M * n), 2.0f);
|
||||
const std::vector<float> sg = { 0.5625f }, rr = { 0.625f }, hb1 = { 0.24f },
|
||||
hb2 = { -0.005f }, ord = { order };
|
||||
void* dx = up_f32(x);
|
||||
void* dx0 = up_f32(x0);
|
||||
void* dv = bf ? up_bf16(v) : up_f32(v);
|
||||
RadTensor tx = T(dx, RAD_F32, { M, n }); tx.stride[0] = xld;
|
||||
RadTensor tx0 = T(dx0, RAD_F32, { M, n }); tx0.stride[0] = x0ld;
|
||||
const std::string nm =
|
||||
fmt("flow_res_multistep_f32 %s velocity order %g", bf ? "bf16" : "f32", order);
|
||||
const int rc = launch(r, { T(dv, bf ? RAD_BF16 : RAD_F32, { M, n }), tx0,
|
||||
T(up_f32(sg), RAD_F32, { 1 }), T(up_f32(rr), RAD_F32, { 1 }),
|
||||
T(up_f32(hb1), RAD_F32, { 1 }), T(up_f32(hb2), RAD_F32, { 1 }),
|
||||
T(up_f32(ord), RAD_F32, { 1 }), tx },
|
||||
{ PI("M", M), PI("n", n), PS("dtype", "f32") });
|
||||
if (rc != RAD_OK) { ok(nm.c_str(), false, "rc " + std::to_string(rc)); continue; }
|
||||
const bool two = order >= 1.5f;
|
||||
const float ra = rr[0], b1 = hb1[0], b2 = hb2[0], omr = 1.0f - ra;
|
||||
std::vector<float> wantx = x, wantx0 = x0; /* gaps keep their original bytes */
|
||||
for (int64_t row = 0; row < M; ++row)
|
||||
for (int64_t c = 0; c < n; ++c) {
|
||||
const float xv = x[(size_t)(row * xld + c)];
|
||||
const float h0 = x0[(size_t)(row * x0ld + c)];
|
||||
const float p = sg[0] * v[(size_t)(row * n + c)];
|
||||
const float d = xv + p;
|
||||
const float a = ra * xv;
|
||||
wantx[(size_t)(row * xld + c)] = two ? (a + b1 * d) + b2 * h0 : a + omr * d;
|
||||
wantx0[(size_t)(row * x0ld + c)] = d;
|
||||
}
|
||||
int64_t bad = differ(down_f32(dx, wantx.size()), wantx);
|
||||
bad += differ(down_f32(dx0, wantx0.size()), wantx0);
|
||||
ok((nm + " exact, both INOUT gaps untouched").c_str(), bad == 0,
|
||||
fmt("%lld values differ", (long long)bad));
|
||||
}
|
||||
}
|
||||
|
||||
/* grid_pos3: MiniMax-H3's tile of 7 x 16 x 16 and its registers over two periods, written into a
|
||||
* [3, M] view of a wider plane; exact. */
|
||||
void grid_pos3_cases(const Plugin& pl) {
|
||||
@@ -19448,6 +19494,7 @@ static void device_phase(const Plugin& pl) {
|
||||
if (sel("rms_mod_bf16")) vid::rms_mod_cases(pl, false);
|
||||
if (sel("rms_mod_quant_fp8_bf16")) vid::rms_mod_cases(pl, true);
|
||||
if (sel("flow_x0_step_f32")) vid::flow_x0_cases(pl);
|
||||
if (sel("flow_res_multistep_f32")) vid::flow_rm_cases(pl);
|
||||
if (sel("grid_pos3")) vid::grid_pos3_cases(pl);
|
||||
if (sel("snake_aa_f32")) vid::snake_aa_cases(pl);
|
||||
/* A video latent upscaler's ops, at its source and target sizes. */
|
||||
|
||||
@@ -165,6 +165,35 @@ __global__ __launch_bounds__(kT) void flow_x0_kernel(
|
||||
*xp = ra * xv + omr * d;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------- flow_res_multistep
|
||||
// A second-order sampler step on the clean estimate: d = x + sigma v, then x' = r x + hb1 d + hb2 x0
|
||||
// with r = sigma_next / sigma and x0 the previous step's estimate (read, then d written back for the
|
||||
// next step). order<2 is Euler -- x' = r x + (1 - r) d, the first step, a schedule restart and the
|
||||
// last step -- and on the two-estimate steps hb1 + hb2 == 1 - r, so both share the Euler limit.
|
||||
template <typename TV>
|
||||
__global__ __launch_bounds__(kT) void flow_rm_kernel(
|
||||
const TV* __restrict__ v, float* __restrict__ x0, const float* __restrict__ sg,
|
||||
const float* __restrict__ rr, const float* __restrict__ hb1, const float* __restrict__ hb2,
|
||||
const float* __restrict__ ord, float* __restrict__ x, int n, int v_ld, int x_ld, int x0_ld,
|
||||
int64_t total) {
|
||||
const int64_t id = (int64_t)blockIdx.x * kT + threadIdx.x;
|
||||
if (id >= total) return;
|
||||
const int64_t r = id / n;
|
||||
const int c = (int)(id % n);
|
||||
const float sgv = sg[0];
|
||||
const float ra = rr[0];
|
||||
const float b1 = hb1[0];
|
||||
const float b2 = hb2[0];
|
||||
const bool two = ord[0] >= 1.5f;
|
||||
const float omr = 1.0f - ra;
|
||||
float* xp = x + r * x_ld + c;
|
||||
float* op = x0 + r * x0_ld + c;
|
||||
const float xv = *xp;
|
||||
const float d = xv + sgv * ldv(v, r * v_ld + c);
|
||||
*xp = two ? ra * xv + b1 * d + b2 * (*op) : ra * xv + omr * d;
|
||||
*op = d;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------- patch_unfold
|
||||
// The two parameter lists of the latent's statistics, f32 kernel arguments.
|
||||
constexpr int kMaxChan = 64;
|
||||
@@ -517,6 +546,36 @@ extern "C" int r4d_rad_flow_x0_step(const RadArgs* a, RadStream s) {
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_flow_res_multistep(const RadArgs* a, RadStream s) {
|
||||
const RadTensor *v = r4d_opt(a, 0), *x0 = r4d_opt(a, 1), *sg = r4d_opt(a, 2);
|
||||
const RadTensor *rr = r4d_opt(a, 3), *hb1 = r4d_opt(a, 4), *hb2 = r4d_opt(a, 5);
|
||||
const RadTensor *ord = r4d_opt(a, 6), *x = r4d_opt(a, 7);
|
||||
if (!v || !x0 || !sg || !rr || !hb1 || !hb2 || !ord || !x) return R4D_NO(RAD_E_INVAL);
|
||||
if (!is_f32(x) || !is_f32(x0) || !is_f32(sg) || !is_f32(rr) || !is_f32(hb1) || !is_f32(hb2) ||
|
||||
!is_f32(ord) || (!is_f32(v) && !is_bf16(v)))
|
||||
return R4D_NO(RAD_E_DTYPE);
|
||||
const long long n = r4d_geti_or(a, "n", 0);
|
||||
long long rx = 0, rv = 0, rx0 = 0;
|
||||
const long long xl = n > 0 ? r4d_rows_pitch(x, n, &rx) : -1;
|
||||
const long long vl = n > 0 ? r4d_rows_pitch(v, n, &rv) : -1;
|
||||
const long long x0l = n > 0 ? r4d_rows_pitch(x0, n, &rx0) : -1;
|
||||
if (xl < 0 || vl < 0 || x0l < 0) return R4D_NO(RAD_E_STRIDE);
|
||||
if (rx <= 0 || rv < rx || rx0 < rx || r4d_numel(sg) < 1 || r4d_numel(rr) < 1 ||
|
||||
r4d_numel(hb1) < 1 || r4d_numel(hb2) < 1 || r4d_numel(ord) < 1)
|
||||
return R4D_NO(RAD_E_SHAPE);
|
||||
const int64_t total = (int64_t)rx * n;
|
||||
#define R4D_FRM(TV) \
|
||||
hipLaunchKernelGGL(flow_rm_kernel<TV>, dim3(blocks_for(total)), dim3(kT), 0, (hipStream_t)s, \
|
||||
(const TV*)v->data, (float*)x0->data, (const float*)sg->data, \
|
||||
(const float*)rr->data, (const float*)hb1->data, (const float*)hb2->data, \
|
||||
(const float*)ord->data, (float*)x->data, (int)n, (int)vl, (int)xl, \
|
||||
(int)x0l, total)
|
||||
if (is_f32(v)) R4D_FRM(float);
|
||||
else R4D_FRM(uint16_t);
|
||||
#undef R4D_FRM
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_patch_unfold(const RadArgs* a, RadStream s) {
|
||||
const RadTensor *x = r4d_opt(a, 0), *geom = r4d_opt(a, 1), *y = r4d_opt(a, 2);
|
||||
if (!x || !geom || !y) return R4D_NO(RAD_E_INVAL);
|
||||
|
||||
Reference in new issue
Block a user