| 35 | |
| 36 | |
| 37 | def make_ddim_sampling_parameters(alphacums, ddim_timesteps, eta, verbose=True): |
| 38 | # select alphas for computing the variance schedule |
| 39 | alphas = alphacums[ddim_timesteps] |
| 40 | alphas_prev = np.asarray([alphacums[0]] + alphacums[ddim_timesteps[:-1]].tolist()) |
| 41 | |
| 42 | # according the the formula provided in https://arxiv.org/abs/2010.02502 |
| 43 | sigmas = eta * np.sqrt((1 - alphas_prev) / (1 - alphas) * (1 - alphas / alphas_prev)) |
| 44 | if verbose: |
| 45 | print(f'Selected alphas for ddim sampler: a_t: {alphas}; a_(t-1): {alphas_prev}') |
| 46 | print(f'For the chosen value of eta, which is {eta}, ' |
| 47 | f'this results in the following sigma_t schedule for ddim sampler {sigmas}') |
| 48 | |
| 49 | return sigmas, alphas, alphas_prev |
| 50 | |
| 51 | |
| 52 | class DDIMSampler: |