(betas)
| 27 | return betas.numpy() |
| 28 | |
| 29 | def enforce_zero_terminal_snr(betas): |
| 30 | # Copied from https://openaccess.thecvf.com/content/WACV2024/papers/Lin_Common_Diffusion_Noise_Schedules_and_Sample_Steps_Are_Flawed_WACV_2024_paper.pdf |
| 31 | # Convert betas to alphas_bar_sqrt |
| 32 | if isinstance(betas, np.ndarray): |
| 33 | betas = torch.tensor(betas) |
| 34 | alphas = 1 - betas |
| 35 | alphas_bar = alphas.cumprod(0) |
| 36 | alphas_bar_sqrt = alphas_bar.sqrt() |
| 37 | |
| 38 | # Store old values. |
| 39 | alphas_bar_sqrt_0 = alphas_bar_sqrt[0].clone() |
| 40 | alphas_bar_sqrt_T = alphas_bar_sqrt[-1].clone() |
| 41 | |
| 42 | # Shift so last timestep is zero. |
| 43 | alphas_bar_sqrt -= alphas_bar_sqrt_T |
| 44 | |
| 45 | # Scale so first timestep is back to old value. |
| 46 | alphas_bar_sqrt *= alphas_bar_sqrt_0 / (alphas_bar_sqrt_0 - alphas_bar_sqrt_T) |
| 47 | |
| 48 | # Convert alphas_bar_sqrt to betas |
| 49 | alphas_bar = alphas_bar_sqrt ** 2 |
| 50 | alphas = alphas_bar[1:] / alphas_bar[:-1] |
| 51 | alphas = torch.cat([alphas_bar[0:1], alphas]) |
| 52 | betas = 1 - alphas |
| 53 | return betas.numpy() |
| 54 | |
| 55 | |
| 56 | def extract_into_tensor(a, t, x_shape): |
no outgoing calls
no test coverage detected