Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of (1-beta) over time from t = [0,1]. :param num_diffusion_timesteps: the number of betas to produce. :param alpha_bar: a lambda that takes an argument t from 0 to 1 and
(num_diffusion_timesteps, alpha_bar, max_beta=0.999)
| 40 | |
| 41 | |
| 42 | def betas_for_alpha_bar(num_diffusion_timesteps, alpha_bar, max_beta=0.999): |
| 43 | """ |
| 44 | Create a beta schedule that discretizes the given alpha_t_bar function, |
| 45 | which defines the cumulative product of (1-beta) over time from t = [0,1]. |
| 46 | :param num_diffusion_timesteps: the number of betas to produce. |
| 47 | :param alpha_bar: a lambda that takes an argument t from 0 to 1 and |
| 48 | produces the cumulative product of (1-beta) up to that |
| 49 | part of the diffusion process. |
| 50 | :param max_beta: the maximum beta to use; use values lower than 1 to |
| 51 | prevent singularities. |
| 52 | """ |
| 53 | betas = [] |
| 54 | for i in range(num_diffusion_timesteps): |
| 55 | t1 = i / num_diffusion_timesteps |
| 56 | t2 = (i + 1) / num_diffusion_timesteps |
| 57 | betas.append(min(1 - alpha_bar(t2) / alpha_bar(t1), max_beta)) |
| 58 | return np.array(betas) |
| 59 | |
| 60 | |
| 61 | def enforce_zero_terminal_snr(betas): |
no outgoing calls
no test coverage detected