Build the Karras noise schedule
Why it matters The DPM++ and Euler samplers in ComfyUI and diffusers use Karras sigmas by default.
Karras et al. space sampling noise levels so more steps go to low noise.
Write karras_sigmas(n, sigma_min, sigma_max, rho=7.0). For i = 0 .. n - 1 with ramp = i / (n - 1), sigma_i = (sigma_max^(1/rho) + ramp * (sigma_min^(1/rho) - sigma_max^(1/rho)))^rho. Append a final 0. Return the array of length n + 1.
def karras_sigmas(n, sigma_min, sigma_max, rho=7.0)Example
karras_sigmas(2, 1.0, 16.0, 1.0) is [16, 1, 0].
Understand the idea
A diffusion sampler steps from high noise down to zero, and where you place the steps matters. The Karras schedule interpolates evenly in sigma^(1/rho) space and then raises back to the power rho. With rho around 7, this packs many more steps near low noise, where fine detail is decided. Worked example: n = 3, sigma_min 1, sigma_max 81, rho 2. sigma_max^(1/2) = 9 and sigma_min^(1/2) = 1. Ramps 0, 0.5, 1 give 9, 5, 1 in root space. Squaring gives 81, 25, 1, then append 0: [81, 25, 1, 0]. A plain linear schedule would put the middle step at 41, so this one spends more steps at low noise. Rule: ramp_i = i / (n - 1) for i = 0 .. n - 1; sigma_i = (sigma_max^(1/rho) + ramp_i * (sigma_min^(1/rho) - sigma_max^(1/rho)))^rho; append a final 0, so the result has length n + 1. Do not forget the final power rho. Used in: the Karras samplers offered in Stable Diffusion tools and k-diffusion style libraries.