Compute the sample at time `t_end` by DPM-Solver, given the initial `x` at time `t_start`. ===================================================== We support the following algorithms for both noise prediction model and data prediction model: - 'singlestep':
(self, x, steps=20, t_start=None, t_end=None, order=2, skip_type='time_uniform',
method='multistep', lower_order_final=True, denoise_to_zero=False, solver_type='dpmsolver',
atol=0.0078, rtol=0.05, return_intermediate=False,
)
| 1053 | atol=atol, rtol=rtol, return_intermediate=return_intermediate) |
| 1054 | |
| 1055 | def sample(self, x, steps=20, t_start=None, t_end=None, order=2, skip_type='time_uniform', |
| 1056 | method='multistep', lower_order_final=True, denoise_to_zero=False, solver_type='dpmsolver', |
| 1057 | atol=0.0078, rtol=0.05, return_intermediate=False, |
| 1058 | ): |
| 1059 | """ |
| 1060 | Compute the sample at time `t_end` by DPM-Solver, given the initial `x` at time `t_start`. |
| 1061 | |
| 1062 | ===================================================== |
| 1063 | |
| 1064 | We support the following algorithms for both noise prediction model and data prediction model: |
| 1065 | - 'singlestep': |
| 1066 | Singlestep DPM-Solver (i.e. "DPM-Solver-fast" in the paper), which combines different orders of singlestep DPM-Solver. |
| 1067 | We combine all the singlestep solvers with order <= `order` to use up all the function evaluations (steps). |
| 1068 | The total number of function evaluations (NFE) == `steps`. |
| 1069 | Given a fixed NFE == `steps`, the sampling procedure is: |
| 1070 | - If `order` == 1: |
| 1071 | - Denote K = steps. We use K steps of DPM-Solver-1 (i.e. DDIM). |
| 1072 | - If `order` == 2: |
| 1073 | - Denote K = (steps // 2) + (steps % 2). We take K intermediate time steps for sampling. |
| 1074 | - If steps % 2 == 0, we use K steps of singlestep DPM-Solver-2. |
| 1075 | - If steps % 2 == 1, we use (K - 1) steps of singlestep DPM-Solver-2 and 1 step of DPM-Solver-1. |
| 1076 | - If `order` == 3: |
| 1077 | - Denote K = (steps // 3 + 1). We take K intermediate time steps for sampling. |
| 1078 | - If steps % 3 == 0, we use (K - 2) steps of singlestep DPM-Solver-3, and 1 step of singlestep DPM-Solver-2 and 1 step of DPM-Solver-1. |
| 1079 | - If steps % 3 == 1, we use (K - 1) steps of singlestep DPM-Solver-3 and 1 step of DPM-Solver-1. |
| 1080 | - If steps % 3 == 2, we use (K - 1) steps of singlestep DPM-Solver-3 and 1 step of singlestep DPM-Solver-2. |
| 1081 | - 'multistep': |
| 1082 | Multistep DPM-Solver with the order of `order`. The total number of function evaluations (NFE) == `steps`. |
| 1083 | We initialize the first `order` values by lower order multistep solvers. |
| 1084 | Given a fixed NFE == `steps`, the sampling procedure is: |
| 1085 | Denote K = steps. |
| 1086 | - If `order` == 1: |
| 1087 | - We use K steps of DPM-Solver-1 (i.e. DDIM). |
| 1088 | - If `order` == 2: |
| 1089 | - We firstly use 1 step of DPM-Solver-1, then use (K - 1) step of multistep DPM-Solver-2. |
| 1090 | - If `order` == 3: |
| 1091 | - We firstly use 1 step of DPM-Solver-1, then 1 step of multistep DPM-Solver-2, then (K - 2) step of multistep DPM-Solver-3. |
| 1092 | - 'singlestep_fixed': |
| 1093 | Fixed order singlestep DPM-Solver (i.e. DPM-Solver-1 or singlestep DPM-Solver-2 or singlestep DPM-Solver-3). |
| 1094 | We use singlestep DPM-Solver-`order` for `order`=1 or 2 or 3, with total [`steps` // `order`] * `order` NFE. |
| 1095 | - 'adaptive': |
| 1096 | Adaptive step size DPM-Solver (i.e. "DPM-Solver-12" and "DPM-Solver-23" in the paper). |
| 1097 | We ignore `steps` and use adaptive step size DPM-Solver with a higher order of `order`. |
| 1098 | You can adjust the absolute tolerance `atol` and the relative tolerance `rtol` to balance the computatation costs |
| 1099 | (NFE) and the sample quality. |
| 1100 | - If `order` == 2, we use DPM-Solver-12 which combines DPM-Solver-1 and singlestep DPM-Solver-2. |
| 1101 | - If `order` == 3, we use DPM-Solver-23 which combines singlestep DPM-Solver-2 and singlestep DPM-Solver-3. |
| 1102 | |
| 1103 | ===================================================== |
| 1104 | |
| 1105 | Some advices for choosing the algorithm: |
| 1106 | - For **unconditional sampling** or **guided sampling with small guidance scale** by DPMs: |
| 1107 | Use singlestep DPM-Solver or DPM-Solver++ ("DPM-Solver-fast" in the paper) with `order = 3`. |
| 1108 | e.g., DPM-Solver: |
| 1109 | >>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver") |
| 1110 | >>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=3, |
| 1111 | skip_type='time_uniform', method='singlestep') |
| 1112 | e.g., DPM-Solver++: |
no test coverage detected