utils
Small tensor helpers shared across the fastgen subpackage.
Functions
Combine conditional and unconditional predictions via classifier-free guidance. |
|
Pad |
- classifier_free_guidance(cond_pred, uncond_pred, guidance_scale)
Combine conditional and unconditional predictions via classifier-free guidance.
Uses the DMD2 convention
cond + (scale - 1) * (cond - uncond), which is mathematically equivalent to the standard CFG formulauncond + scale * (cond - uncond).- Parameters:
cond_pred (Tensor)
uncond_pred (Tensor)
guidance_scale (float)
- Return type:
Tensor
- expand_like(x, target)
Pad
xwith trailing singleton dims until it has the same ndim astarget.Used to broadcast per-sample scalars like
alpha_t/sigma_tacross the spatial / temporal axes of a video latent.Example:
x = torch.ones(5) # shape (5,) target = torch.ones(5, 4, 16, 16) expand_like(x, target).shape # (5, 1, 1, 1)
- Parameters:
x (Tensor)
target (Tensor)
- Return type:
Tensor