mstar.model.wan22.components.unipc#
Inline UniPC (bh2, order 2, flow prediction) for the Wan2.2 denoise loop.
Exact port of diffusers 0.39.0 UniPCMultistepScheduler, restricted to this
checkpoint’s scheduler config. Any deviation from the reference is a bug, not a
choice; the port is asserted in lockstep against it per step.
The reference scheduler keeps state across step() calls, but the denoise loop
is stateless per iteration, so that state is split in two: per-request tables
(make_unipc_tables), derivable from the step count and recomputed each
iteration, and loop-carried tensors (UniPCState), routed through the graph’s
loop-back edges. All solver math runs float32 on the sample’s device, as the
reference does.
Functions
|
Per-request sigma and timestep tables. |
|
Flow-prediction x0 conversion. |
|
UniC correction of x_k using step k's converted output (source |
|
Predictor order at step k. |
|
UniP update x_k -> x_{k+1}. |
Classes
|
Loop-carried UniPC solver state for one request. |
- class mstar.model.wan22.components.unipc.UniPCState(model_outputs, last_sample)[source]#
Bases:
objectLoop-carried UniPC solver state for one request.
model_outputsis the order-2 ring buffer of converted outputs (slot 1 is the previous step, slot 0 the one before).last_sampleis the sample the previous predictor was given, consumed by this step’s corrector. Both are zero before they are written, and the order ramp guarantees they are not read then.
- mstar.model.wan22.components.unipc.make_unipc_tables(num_inference_steps, flow_shift)[source]#
Per-request sigma and timestep tables.
Returns sigmas float32
[N+1]with the terminal zero appended, and timesteps int64[N]. Sigmas are computed float64 and cast at the end, and the timesteps are truncated by the int64 cast — both as the reference does, and both load-bearing for bit-exactness.
- mstar.model.wan22.components.unipc.unipc_convert_model_output(model_output, sample, sigmas, step_index)[source]#
Flow-prediction x0 conversion.
sigma_tstays a CPU 0-dim tensor on purpose, as the reference leaves it. A CPU scalar takes the CUDA kernel’s full-precision Scalar path; a device 0-dim tensor would instead be type-promoted to the bf16 operand’s dtype before the multiply. That is a bitwise difference, and it breaks lockstep with the reference. (It is also why this node cannot be compiled — seeWan22DitSubmodule.)
- mstar.model.wan22.components.unipc.unipc_corrector_step(state, this_model_output, this_sample, sigmas, step_index, order)[source]#
UniC correction of x_k using step k’s converted output (source
multistep_uni_c_bh_update). Runs before the ring shift, sostate.model_outputs[1]is step k-1’s output and[0]step k-2’s;state.last_sampleis the sample step k-1’s predictor started from.
- mstar.model.wan22.components.unipc.unipc_effective_order(step_index, num_inference_steps)[source]#
Predictor order at step k.
Capped both by the steps remaining (so the last step is order 1) and by the warmup ramp. Step k’s corrector reuses step k-1’s value.