| 16 | |
| 17 | |
| 18 | def make_ddim_timesteps(ddim_discr_method, num_ddim_timesteps, num_ddpm_timesteps, verbose=True): |
| 19 | if ddim_discr_method == 'uniform': |
| 20 | c = num_ddpm_timesteps // num_ddim_timesteps |
| 21 | assert c > 1, "Issue, not solved!" |
| 22 | ddim_timesteps = np.asarray(list(range(0, num_ddpm_timesteps, c))) |
| 23 | elif ddim_discr_method == 'quad': |
| 24 | ddim_timesteps = ((np.linspace(0, np.sqrt(num_ddpm_timesteps * .8), num_ddim_timesteps)) ** 2).astype(int) |
| 25 | else: |
| 26 | raise NotImplementedError(f'There is no ddim discretization method called "{ddim_discr_method}"') |
| 27 | |
| 28 | # assert ddim_timesteps.shape[0] == num_ddim_timesteps |
| 29 | # add one to get the final alpha values right (the ones from first scale to data during sampling) |
| 30 | steps_out = ddim_timesteps + 1 |
| 31 | if verbose: |
| 32 | print(f'Selected timesteps for ddim sampler: {steps_out}') |
| 33 | |
| 34 | return steps_out |
| 35 | |
| 36 | |
| 37 | def make_ddim_sampling_parameters(alphacums, ddim_timesteps, eta, verbose=True): |