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
@@ -433,6 +433,8 @@ struct Model {
|
||||
rad_buf b_nout = 0; /* [lanes * S, 3 * 2D] bf16: norm_out's, by segment */
|
||||
rad_buf b_vstate = 0; /* [lanes * maxV, 96] f32 */
|
||||
rad_buf b_astate = 0; /* [lanes * maxA, 32] f32 */
|
||||
rad_buf b_vx0 = 0; /* [lanes * maxV, 96] f32: res_multistep's previous video estimate */
|
||||
rad_buf b_ax0 = 0; /* [lanes * maxA, 32] f32: the soundtrack's */
|
||||
rad_buf b_prev = 0; /* [lanes * 5 * area, 3] bf16: the decoder's frames across chunks */
|
||||
|
||||
/* ---- the DiT */
|
||||
@@ -460,6 +462,7 @@ struct Model {
|
||||
std::vector<DitBlock> dit;
|
||||
rad_weight w_no_n = 0, w_vout = 0, b_vout = 0, w_aout = 0, b_aout = 0;
|
||||
rad_op op_nout = 0, op_hcast = 0, op_vout = 0, op_aout = 0, op_ev = 0, op_ea = 0;
|
||||
rad_op op_rmv = 0, op_rma = 0; /* the res_multistep step, video and soundtrack */
|
||||
|
||||
/* ---- the audio decoder */
|
||||
std::string a_mean, a_std;
|
||||
@@ -1107,6 +1110,8 @@ static int declare_dit(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
/* ---- the lanes' latents, and the first step's noise */
|
||||
m.b_vstate = decl_b(b, nm.f("lane.video"), RAD_F32, { La * m.maxV, kPatchVals }, RAD_BUF_PERSIST);
|
||||
m.b_astate = decl_b(b, nm.f("lane.audio"), RAD_F32, { La * m.maxA, kAudioC }, RAD_BUF_PERSIST);
|
||||
m.b_vx0 = decl_b(b, nm.f("lane.video.x0"), RAD_F32, { La * m.maxV, kPatchVals }, RAD_BUF_PERSIST);
|
||||
m.b_ax0 = decl_b(b, nm.f("lane.audio.x0"), RAD_F32, { La * m.maxA, kAudioC }, RAD_BUF_PERSIST);
|
||||
m.op_rnd_v = rw(b, RAD_OP(b, "randn_lanes",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, m.maxV), RAD_INT("n", kPatchVals),
|
||||
RAD_INT("stride", m.maxV), RAD_STR("dtype", "f32")),
|
||||
@@ -1382,7 +1387,21 @@ static int declare_dit(RadBuilder* b, const RadModelMeta* meta, Model& m) {
|
||||
RAD_STR("dtype", "f32")),
|
||||
RAD_NOWEIGHTS),
|
||||
{ m.b_avel, m.b_astate }, { m.b_astate });
|
||||
return m.op_hcast && m.op_vout && m.op_aout && m.op_ev && m.op_ea ? RAD_OK : RAD_E_INVAL;
|
||||
/* The second-order step's two INOUT buffers: the estimate history is both read (previous d) and
|
||||
* written (this d), and the latent x as before; the velocity is read-only. Issued instead of the
|
||||
* Euler pair when the batch's sampler is RES_MULTISTEP. */
|
||||
m.op_rmv = rw(b, RAD_OP(b, "flow_res_multistep",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, m.maxV), RAD_INT("n", kPatchVals),
|
||||
RAD_STR("dtype", "f32")),
|
||||
RAD_NOWEIGHTS),
|
||||
{ m.b_vel, m.b_vx0, m.b_vstate }, { m.b_vx0, m.b_vstate });
|
||||
m.op_rma = rw(b, RAD_OP(b, "flow_res_multistep",
|
||||
RAD_PARAMS(RAD_RANGE("M", 1, m.maxA), RAD_INT("n", kAudioC),
|
||||
RAD_STR("dtype", "f32")),
|
||||
RAD_NOWEIGHTS),
|
||||
{ m.b_avel, m.b_ax0, m.b_astate }, { m.b_ax0, m.b_astate });
|
||||
return m.op_hcast && m.op_vout && m.op_aout && m.op_ev && m.op_ea && m.op_rmv && m.op_rma
|
||||
? RAD_OK : RAD_E_INVAL;
|
||||
}
|
||||
|
||||
/* ================================================================== the audio decoder */
|
||||
@@ -3524,12 +3543,31 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) {
|
||||
};
|
||||
heads(m.op_aout, m.w_aout, m.b_aout, aseg, arows, kAudioC, m.b_avel);
|
||||
heads(m.op_vout, m.w_vout, m.b_vout, vseg, vrows, kPatchVals, m.b_vel);
|
||||
RAD_ISSUE_N(c, m.op_ev, vrows, brows(m.b_vel, vrows), praw(V->sched, RAD_F32, 1),
|
||||
praw(V->sched + 1, RAD_F32, 1), praw(V->sched + 2, RAD_F32, 1),
|
||||
brow_slice(m.b_vstate, lane * m.maxV, vrows, kPatchVals));
|
||||
RAD_ISSUE_N(c, m.op_ea, arows, brows(m.b_avel, arows), praw(V->sched + 3, RAD_F32, 1),
|
||||
praw(V->sched + 4, RAD_F32, 1), praw(V->sched + 5, RAD_F32, 1),
|
||||
brow_slice(m.b_astate, lane * m.maxA, arows, kAudioC));
|
||||
/* The step: Euler (the clean estimate alone, the lane's latent only) or the second-order
|
||||
* res_multistep, which also reads and rotates the previous estimate kept in the lane's x0 buffer.
|
||||
* The driver stages the scalars for whichever runs: sched[0..5] the Euler t/sigmas, sched[6..10]
|
||||
* the video's sigma/r/hb1/hb2/order and sched[11..15] the soundtrack's. */
|
||||
if (V->sampler == RAD_SAMPLER_RES_MULTISTEP) {
|
||||
RAD_ISSUE_N(c, m.op_rmv, vrows, brows(m.b_vel, vrows),
|
||||
brow_slice(m.b_vx0, lane * m.maxV, vrows, kPatchVals),
|
||||
praw(V->sched + 6, RAD_F32, 1), praw(V->sched + 7, RAD_F32, 1),
|
||||
praw(V->sched + 8, RAD_F32, 1), praw(V->sched + 9, RAD_F32, 1),
|
||||
praw(V->sched + 10, RAD_F32, 1),
|
||||
brow_slice(m.b_vstate, lane * m.maxV, vrows, kPatchVals));
|
||||
RAD_ISSUE_N(c, m.op_rma, arows, brows(m.b_avel, arows),
|
||||
brow_slice(m.b_ax0, lane * m.maxA, arows, kAudioC),
|
||||
praw(V->sched + 11, RAD_F32, 1), praw(V->sched + 12, RAD_F32, 1),
|
||||
praw(V->sched + 13, RAD_F32, 1), praw(V->sched + 14, RAD_F32, 1),
|
||||
praw(V->sched + 15, RAD_F32, 1),
|
||||
brow_slice(m.b_astate, lane * m.maxA, arows, kAudioC));
|
||||
} else {
|
||||
RAD_ISSUE_N(c, m.op_ev, vrows, brows(m.b_vel, vrows), praw(V->sched, RAD_F32, 1),
|
||||
praw(V->sched + 1, RAD_F32, 1), praw(V->sched + 2, RAD_F32, 1),
|
||||
brow_slice(m.b_vstate, lane * m.maxV, vrows, kPatchVals));
|
||||
RAD_ISSUE_N(c, m.op_ea, arows, brows(m.b_avel, arows), praw(V->sched + 3, RAD_F32, 1),
|
||||
praw(V->sched + 4, RAD_F32, 1), praw(V->sched + 5, RAD_F32, 1),
|
||||
brow_slice(m.b_astate, lane * m.maxA, arows, kAudioC));
|
||||
}
|
||||
}
|
||||
|
||||
/* The soundtrack: both channels, each a sequence, through the audio decoder, then interleaved. */
|
||||
|
||||
Reference in new issue
Block a user