(
self,
num_train_timesteps: int = 1000,
solver_order: int = 2,
prediction_type: str = "flow_prediction",
shift: Optional[float] = 1.0,
use_dynamic_shifting=False,
thresholding: bool = False,
dynamic_thresholding_ratio: float = 0.995,
sample_max_value: float = 1.0,
algorithm_type: str = "dpmsolver++",
solver_type: str = "midpoint",
lower_order_final: bool = True,
euler_at_final: bool = False,
final_sigmas_type: Optional[str] = "zero", # "zero", "sigma_min"
lambda_min_clipped: float = -float("inf"),
variance_type: Optional[str] = None,
invert_sigmas: bool = False,
)
| 129 | |
| 130 | @register_to_config |
| 131 | def __init__( |
| 132 | self, |
| 133 | num_train_timesteps: int = 1000, |
| 134 | solver_order: int = 2, |
| 135 | prediction_type: str = "flow_prediction", |
| 136 | shift: Optional[float] = 1.0, |
| 137 | use_dynamic_shifting=False, |
| 138 | thresholding: bool = False, |
| 139 | dynamic_thresholding_ratio: float = 0.995, |
| 140 | sample_max_value: float = 1.0, |
| 141 | algorithm_type: str = "dpmsolver++", |
| 142 | solver_type: str = "midpoint", |
| 143 | lower_order_final: bool = True, |
| 144 | euler_at_final: bool = False, |
| 145 | final_sigmas_type: Optional[str] = "zero", # "zero", "sigma_min" |
| 146 | lambda_min_clipped: float = -float("inf"), |
| 147 | variance_type: Optional[str] = None, |
| 148 | invert_sigmas: bool = False, |
| 149 | ): |
| 150 | if algorithm_type in ["dpmsolver", "sde-dpmsolver"]: |
| 151 | deprecation_message = f"algorithm_type {algorithm_type} is deprecated and will be removed in a future version. Choose from `dpmsolver++` or `sde-dpmsolver++` instead" |
| 152 | deprecate("algorithm_types dpmsolver and sde-dpmsolver", "1.0.0", |
| 153 | deprecation_message) |
| 154 | |
| 155 | # settings for DPM-Solver |
| 156 | if algorithm_type not in [ |
| 157 | "dpmsolver", "dpmsolver++", "sde-dpmsolver", "sde-dpmsolver++" |
| 158 | ]: |
| 159 | if algorithm_type == "deis": |
| 160 | self.register_to_config(algorithm_type="dpmsolver++") |
| 161 | else: |
| 162 | raise NotImplementedError( |
| 163 | f"{algorithm_type} is not implemented for {self.__class__}") |
| 164 | |
| 165 | if solver_type not in ["midpoint", "heun"]: |
| 166 | if solver_type in ["logrho", "bh1", "bh2"]: |
| 167 | self.register_to_config(solver_type="midpoint") |
| 168 | else: |
| 169 | raise NotImplementedError( |
| 170 | f"{solver_type} is not implemented for {self.__class__}") |
| 171 | |
| 172 | if algorithm_type not in ["dpmsolver++", "sde-dpmsolver++" |
| 173 | ] and final_sigmas_type == "zero": |
| 174 | raise ValueError( |
| 175 | f"`final_sigmas_type` {final_sigmas_type} is not supported for `algorithm_type` {algorithm_type}. Please choose `sigma_min` instead." |
| 176 | ) |
| 177 | |
| 178 | # setable values |
| 179 | self.num_inference_steps = None |
| 180 | alphas = np.linspace(1, 1 / num_train_timesteps, |
| 181 | num_train_timesteps)[::-1].copy() |
| 182 | sigmas = 1.0 - alphas |
| 183 | sigmas = torch.from_numpy(sigmas).to(dtype=torch.float32) |
| 184 | |
| 185 | if not use_dynamic_shifting: |
| 186 | # when use_dynamic_shifting is True, we apply the timestep shifting on the fly based on the image resolution |
| 187 | sigmas = shift * sigmas / (1 + |
| 188 | (shift - 1) * sigmas) # pyright: ignore |
nothing calls this directly
no outgoing calls
no test coverage detected