text
stringlengths
1
1.02k
class_index
int64
0
1.38k
source
stringclasses
431 values
timestep_list = args[0] if len(args) > 0 else kwargs.pop("timestep_list", None) prev_timestep = args[1] if len(args) > 1 else kwargs.pop("prev_timestep", None) if sample is None: if len(args) > 2: sample = args[2] else: raise ValueError(" missing`s...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
sigma_t, sigma_s0, sigma_s1, sigma_s2 = ( self.sigmas[self.step_index + 1], self.sigmas[self.step_index], self.sigmas[self.step_index - 1], self.sigmas[self.step_index - 2], ) alpha_t, sigma_t = self._sigma_to_alpha_sigma_t(sigma_t) alpha_s0, sigm...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
h, h_0, h_1 = lambda_t - lambda_s0, lambda_s0 - lambda_s1, lambda_s1 - lambda_s2 r0, r1 = h_0 / h, h_1 / h D0 = m0 D1_0, D1_1 = (1.0 / r0) * (m0 - m1), (1.0 / r1) * (m1 - m2) D1 = D1_0 + (r0 / (r0 + r1)) * (D1_0 - D1_1) D2 = (1.0 / (r0 + r1)) * (D1_0 - D1_1) if self.confi...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
- (sigma_t * ((torch.exp(h) - 1.0) / h - 1.0)) * D1 - (sigma_t * ((torch.exp(h) - 1.0 - h) / h**2 - 0.5)) * D2 ) elif self.config.algorithm_type == "sde-dpmsolver++": assert noise is not None x_t = ( (sigma_t / sigma_s0 * torch.exp(-h)) * sampl...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
def index_for_timestep(self, timestep, schedule_timesteps=None): if schedule_timesteps is None: schedule_timesteps = self.timesteps index_candidates = (schedule_timesteps == timestep).nonzero() if len(index_candidates) == 0: step_index = len(self.timesteps) - 1 ...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
if self.begin_index is None: if isinstance(timestep, torch.Tensor): timestep = timestep.to(self.timesteps.device) self._step_index = self.index_for_timestep(timestep) else: self._step_index = self._begin_index def step( self, model_output:...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
Args: model_output (`torch.Tensor`): The direct output from learned diffusion model. timestep (`int`): The current discrete timestep in the diffusion chain. sample (`torch.Tensor`): A current instance of a sample created by the diffusio...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
Returns: [`~schedulers.scheduling_utils.SchedulerOutput`] or `tuple`: If return_dict is `True`, [`~schedulers.scheduling_utils.SchedulerOutput`] is returned, otherwise a tuple is returned where the first element is the sample tensor. """ if self.num_inference...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
# Improve numerical stability for small number of steps lower_order_final = (self.step_index == len(self.timesteps) - 1) and ( self.config.euler_at_final or (self.config.lower_order_final and len(self.timesteps) < 15) or self.config.final_sigmas_type == "zero" ) ...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
# Upcast to avoid precision issues when computing prev_sample sample = sample.to(torch.float32) if self.config.algorithm_type in ["sde-dpmsolver", "sde-dpmsolver++"] and variance_noise is None: noise = randn_tensor( model_output.shape, generator=generator, device=model_output...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
if self.config.solver_order == 1 or self.lower_order_nums < 1 or lower_order_final: prev_sample = self.dpm_solver_first_order_update(model_output, sample=sample, noise=noise) elif self.config.solver_order == 2 or self.lower_order_nums < 2 or lower_order_second: prev_sample = self.multist...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
def scale_model_input(self, sample: torch.Tensor, *args, **kwargs) -> torch.Tensor: """ Ensures interchangeability with schedulers that need to scale the denoising model input depending on the current timestep. Args: sample (`torch.Tensor`): The input sample....
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
def add_noise( self, original_samples: torch.Tensor, noise: torch.Tensor, timesteps: torch.IntTensor, ) -> torch.Tensor: # Make sure sigmas and timesteps have the same device and dtype as original_samples sigmas = self.sigmas.to(device=original_samples.device, dtype=o...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
# begin_index is None when the scheduler is used for training or pipeline does not implement set_begin_index if self.begin_index is None: step_indices = [self.index_for_timestep(t, schedule_timesteps) for t in timesteps] elif self.step_index is not None: # add_noise is called aft...
1,373
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin): """ `UniPCMultistepScheduler` is a training-free framework designed for the fast sampling of diffusion models. This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic methods the libr...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Args: num_train_timesteps (`int`, defaults to 1000): The number of diffusion steps to train the model. beta_start (`float`, defaults to 0.0001): The starting `beta` value of inference. beta_end (`float`, defaults to 0.02): The final `beta` value. beta_...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
prediction_type (`str`, defaults to `epsilon`, *optional*): Prediction type of the scheduler function; can be `epsilon` (predicts the noise of the diffusion process), `sample` (directly predicts the noisy sample`) or `v_prediction` (see section 2.4 of [Imagen Video](https://imagen.re...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
solver_type (`str`, default `bh2`): Solver type for UniPC. It is recommended to use `bh1` for unconditional sampling when steps < 10, and `bh2` otherwise. lower_order_final (`bool`, default `True`): Whether to use lower-order solvers in the final steps. Only valid for < 15 in...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If `True`, the sigmas are determined according to a sequence of noise levels {σi}. use_exponential_sigmas (`bool`, *optional*, defaults to `False`): Whether to use exponential sigmas for step s...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
An offset added to the inference steps, as required by some model families. final_sigmas_type (`str`, defaults to `"zero"`): The final `sigma` value for the noise schedule during the sampling process. If `"sigma_min"`, the final sigma is the same as the last sigma in the training schedul...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
_compatibles = [e.name for e in KarrasDiffusionSchedulers] order = 1
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
@register_to_config def __init__( self, num_train_timesteps: int = 1000, beta_start: float = 0.0001, beta_end: float = 0.02, beta_schedule: str = "linear", trained_betas: Optional[Union[np.ndarray, List[float]]] = None, solver_order: int = 2, predictio...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
final_sigmas_type: Optional[str] = "zero", # "zero", "sigma_min" rescale_betas_zero_snr: bool = False, ): if self.config.use_beta_sigmas and not is_scipy_available(): raise ImportError("Make sure to install scipy if you want to use beta sigmas.") if sum([self.config.use_beta_sig...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
self.betas = torch.linspace(beta_start**0.5, beta_end**0.5, num_train_timesteps, dtype=torch.float32) ** 2 elif beta_schedule == "squaredcos_cap_v2": # Glide cosine schedule self.betas = betas_for_alpha_bar(num_train_timesteps) else: raise NotImplementedError(f"{beta_...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if rescale_betas_zero_snr: self.betas = rescale_zero_terminal_snr(self.betas) self.alphas = 1.0 - self.betas self.alphas_cumprod = torch.cumprod(self.alphas, dim=0) if rescale_betas_zero_snr: # Close to 0 without being 0 so first sigma is not inf # FP16 smal...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if solver_type not in ["bh1", "bh2"]: if solver_type in ["midpoint", "heun", "logrho"]: self.register_to_config(solver_type="bh2") else: raise NotImplementedError(f"{solver_type} is not implemented for {self.__class__}") self.predict_x0 = predict_x0 ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
@property def step_index(self): """ The index counter for current timestep. It will increase 1 after each scheduler step. """ return self._step_index @property def begin_index(self): """ The index for the first timestep. It should be set from pipeline with `s...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device] = None): """ Sets the discrete timesteps used for the diffusion chain (to be run before inference).
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Args: num_inference_steps (`int`): The number of diffusion steps used when generating samples with a pre-trained model. device (`str` or `torch.device`, *optional*): The device to which the timesteps should be moved to. If `None`, the timesteps are not moved. ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# casting to int to avoid issues when num_inference_step is power of 3 timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int64) timesteps += self.config.steps_offset elif self.config.timestep_spacing == "trailing": step_ratio...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
sigmas = np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5) if self.config.use_karras_sigmas: log_sigmas = np.log(sigmas) sigmas = np.flip(sigmas).copy() sigmas = self._convert_to_karras(in_sigmas=sigmas, num_inference_steps=num_inference_steps) ti...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
sigmas = self._convert_to_exponential(in_sigmas=sigmas, num_inference_steps=num_inference_steps) timesteps = np.array([self._sigma_to_t(sigma, log_sigmas) for sigma in sigmas]) if self.config.final_sigmas_type == "sigma_min": sigma_last = sigmas[-1] elif self.config.f...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if self.config.final_sigmas_type == "sigma_min": sigma_last = sigmas[-1] elif self.config.final_sigmas_type == "zero": sigma_last = 0 else: raise ValueError( f"`final_sigmas_type` must be one of 'zero', or 'sigma_min', but got {...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
else: raise ValueError( f"`final_sigmas_type` must be one of 'zero', or 'sigma_min', but got {self.config.final_sigmas_type}" ) sigmas = np.concatenate([sigmas, [sigma_last]]).astype(np.float32) else: sigmas = np.interp(timesteps, np.ar...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
self.sigmas = torch.from_numpy(sigmas) self.timesteps = torch.from_numpy(timesteps).to(device=device, dtype=torch.int64) self.num_inference_steps = len(timesteps) self.model_outputs = [ None, ] * self.config.solver_order self.lower_order_nums = 0 self.last_s...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMScheduler._threshold_sample def _threshold_sample(self, sample: torch.Tensor) -> torch.Tensor: """ "Dynamic thresholding: At each sampling step we set s to a certain percentile absolute pixel value in xt0 (the prediction of x_0 at timest...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if dtype not in (torch.float32, torch.float64): sample = sample.float() # upcast for quantile calculation, and clamp not implemented for cpu half # Flatten sample for doing quantile calculation along each image sample = sample.reshape(batch_size, channels * np.prod(remaining_dims)) ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._sigma_to_t def _sigma_to_t(self, sigma, log_sigmas): # get log sigma log_sigma = np.log(np.maximum(sigma, 1e-10)) # get distribution dists = log_sigma - log_sigmas[:, np.newaxis] # get sigm...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler._sigma_to_alpha_sigma_t def _sigma_to_alpha_sigma_t(self, sigma): if self.config.use_flow_sigmas: alpha_t = 1 - sigma sigma_t = sigma else: alpha_t = 1 / ((sigma**2 + 1) ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if hasattr(self.config, "sigma_max"): sigma_max = self.config.sigma_max else: sigma_max = None sigma_min = sigma_min if sigma_min is not None else in_sigmas[-1].item() sigma_max = sigma_max if sigma_max is not None else in_sigmas[0].item() rho = 7.0 # 7.0 is th...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Hack to make sure that other schedulers which copy this function don't break # TODO: Add this logic to the other schedulers if hasattr(self.config, "sigma_min"): sigma_min = self.config.sigma_min else: sigma_min = None if hasattr(self.config, "sigma_max"): ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._convert_to_beta def _convert_to_beta( self, in_sigmas: torch.Tensor, num_inference_steps: int, alpha: float = 0.6, beta: float = 0.6 ) -> torch.Tensor: """From "Beta Sampling is All You Need" [arXiv:2407.12173] ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
sigmas = np.array( [ sigma_min + (ppf * (sigma_max - sigma_min)) for ppf in [ scipy.stats.beta.ppf(timestep, alpha, beta) for timestep in 1 - np.linspace(0, 1, num_inference_steps) ] ] ) retur...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Returns: `torch.Tensor`: The converted model output. """ timestep = args[0] if len(args) > 0 else kwargs.pop("timestep", None) if sample is None: if len(args) > 1: sample = args[1] else: raise ValueError("missing...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if self.predict_x0: if self.config.prediction_type == "epsilon": x0_pred = (sample - sigma_t * model_output) / alpha_t elif self.config.prediction_type == "sample": x0_pred = model_output elif self.config.prediction_type == "v_prediction": ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
return x0_pred else: if self.config.prediction_type == "epsilon": return model_output elif self.config.prediction_type == "sample": epsilon = (sample - alpha_t * model_output) / sigma_t return epsilon elif self.config.prediction...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
def multistep_uni_p_bh_update( self, model_output: torch.Tensor, *args, sample: torch.Tensor = None, order: int = None, **kwargs, ) -> torch.Tensor: """ One step for the UniP (B(h) version). Alternatively, `self.solver_p` is used if is specified. ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Returns: `torch.Tensor`: The sample tensor at the previous timestep. """ prev_timestep = args[0] if len(args) > 0 else kwargs.pop("prev_timestep", None) if sample is None: if len(args) > 1: sample = args[1] else: ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if self.solver_p: x_t = self.solver_p.step(model_output, s0, x).prev_sample return x_t sigma_t, sigma_s0 = self.sigmas[self.step_index + 1], self.sigmas[self.step_index] alpha_t, sigma_t = self._sigma_to_alpha_sigma_t(sigma_t) alpha_s0, sigma_s0 = self._sigma_to_alpha_si...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
R = [] b = [] hh = -h if self.predict_x0 else h h_phi_1 = torch.expm1(hh) # h\phi_1(h) = e^h - 1 h_phi_k = h_phi_1 / hh - 1 factorial_i = 1 if self.config.solver_type == "bh1": B_h = hh elif self.config.solver_type == "bh2": B_h = torch...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if len(D1s) > 0: D1s = torch.stack(D1s, dim=1) # (B, K) # for order 2, we use a simplified version if order == 2: rhos_p = torch.tensor([0.5], dtype=x.dtype, device=device) else: rhos_p = torch.linalg.solve(R[:-1, :-1], b[:-1]).to(device)....
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
def multistep_uni_c_bh_update( self, this_model_output: torch.Tensor, *args, last_sample: torch.Tensor = None, this_sample: torch.Tensor = None, order: int = None, **kwargs, ) -> torch.Tensor: """ One step for the UniC (B(h) version). ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Returns: `torch.Tensor`: The corrected sample tensor at the current timestep. """ this_timestep = args[0] if len(args) > 0 else kwargs.pop("this_timestep", None) if last_sample is None: if len(args) > 1: last_sample = args[1] el...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
"Passing `this_timestep` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`", )
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
model_output_list = self.model_outputs m0 = model_output_list[-1] x = last_sample x_t = this_sample model_t = this_model_output sigma_t, sigma_s0 = self.sigmas[self.step_index], self.sigmas[self.step_index - 1] alpha_t, sigma_t = self._sigma_to_alpha_sigma_t(sigma_t) ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
rks.append(1.0) rks = torch.tensor(rks, device=device) R = [] b = [] hh = -h if self.predict_x0 else h h_phi_1 = torch.expm1(hh) # h\phi_1(h) = e^h - 1 h_phi_k = h_phi_1 / hh - 1 factorial_i = 1 if self.config.solver_type == "bh1": B_h = h...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# for order 1, we use a simplified version if order == 1: rhos_c = torch.tensor([0.5], dtype=x.dtype, device=device) else: rhos_c = torch.linalg.solve(R, b).to(device).to(x.dtype) if self.predict_x0: x_t_ = sigma_t / sigma_s0 * x - alpha_t * h_phi_1 * m0 ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler.index_for_timestep def index_for_timestep(self, timestep, schedule_timesteps=None): if schedule_timesteps is None: schedule_timesteps = self.timesteps index_candidates = (schedule_timesteps == ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler._init_step_index def _init_step_index(self, timestep): """ Initialize the step_index counter for the scheduler. """ if self.begin_index is None: if isinstance(timestep, torch.Te...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
Args: model_output (`torch.Tensor`): The direct output from learned diffusion model. timestep (`int`): The current discrete timestep in the diffusion chain. sample (`torch.Tensor`): A current instance of a sample created by the diffusio...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if self.step_index is None: self._init_step_index(timestep) use_corrector = ( self.step_index > 0 and self.step_index - 1 not in self.disable_corrector and self.last_sample is not None ) model_output_convert = self.convert_model_output(model_output, sample=sample) ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
if self.config.lower_order_final: this_order = min(self.config.solver_order, len(self.timesteps) - self.step_index) else: this_order = self.config.solver_order self.this_order = min(this_order, self.lower_order_nums + 1) # warmup for multistep assert self.this_order > 0...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
def scale_model_input(self, sample: torch.Tensor, *args, **kwargs) -> torch.Tensor: """ Ensures interchangeability with schedulers that need to scale the denoising model input depending on the current timestep. Args: sample (`torch.Tensor`): The input sample....
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# Copied from diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler.add_noise def add_noise( self, original_samples: torch.Tensor, noise: torch.Tensor, timesteps: torch.IntTensor, ) -> torch.Tensor: # Make sure sigmas and timesteps have the same ...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
# begin_index is None when the scheduler is used for training or pipeline does not implement set_begin_index if self.begin_index is None: step_indices = [self.index_for_timestep(t, schedule_timesteps) for t in timesteps] elif self.step_index is not None: # add_noise is called aft...
1,374
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unipc_multistep.py
class ScoreSdeVpScheduler(SchedulerMixin, ConfigMixin): """ `ScoreSdeVpScheduler` is a variance preserving stochastic differential equation (SDE) scheduler. This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic methods the library implements...
1,375
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_sde_vp.py
def set_timesteps(self, num_inference_steps, device: Union[str, torch.device] = None): """ Sets the continuous timesteps used for the diffusion chain (to be run before inference). Args: num_inference_steps (`int`): The number of diffusion steps used when generating s...
1,375
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_sde_vp.py
Args: score (): x (): t (): generator (`torch.Generator`, *optional*): A random number generator. """ if self.timesteps is None: raise ValueError( "`self.timesteps` is not set, you need to run 'set_timesteps' aft...
1,375
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_sde_vp.py
beta_t = self.config.beta_min + t * (self.config.beta_max - self.config.beta_min) beta_t = beta_t.flatten() while len(beta_t.shape) < len(x.shape): beta_t = beta_t.unsqueeze(-1) drift = -0.5 * beta_t * x diffusion = torch.sqrt(beta_t) drift = drift - diffusion**2 * s...
1,375
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_sde_vp.py
class KarrasVeOutput(BaseOutput): """ Output class for the scheduler's step function output. Args: prev_sample (`torch.Tensor` of shape `(batch_size, num_channels, height, width)` for images): Computed sample (x_{t-1}) of previous timestep. `prev_sample` should be used as next model inp...
1,376
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
class KarrasVeScheduler(SchedulerMixin, ConfigMixin): """ A stochastic scheduler tailored to variance-expanding models. This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic methods the library implements for all schedulers such as loading a...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
Args: sigma_min (`float`, defaults to 0.02): The minimum noise magnitude. sigma_max (`float`, defaults to 100): The maximum noise magnitude. s_noise (`float`, defaults to 1.007): The amount of additional noise to counteract loss of detail during sampling. A re...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
@register_to_config def __init__( self, sigma_min: float = 0.02, sigma_max: float = 100, s_noise: float = 1.007, s_churn: float = 80, s_min: float = 0.05, s_max: float = 50, ): # standard deviation of the initial noise distribution self.ini...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
Returns: `torch.Tensor`: A scaled input sample. """ return sample def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.device] = None): """ Sets the discrete timesteps used for the diffusion chain (to be run before inference).
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
Args: num_inference_steps (`int`): The number of diffusion steps used when generating samples with a pre-trained model. device (`str` or `torch.device`, *optional*): The device to which the timesteps should be moved to. If `None`, the timesteps are not moved. ...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
def add_noise_to_input( self, sample: torch.Tensor, sigma: float, generator: Optional[torch.Generator] = None ) -> Tuple[torch.Tensor, float]: """ Explicit Langevin-like "churn" step of adding noise to the sample according to a `gamma_i ≥ 0` to reach a higher noise level `sigma_hat =...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
return sample_hat, sigma_hat def step( self, model_output: torch.Tensor, sigma_hat: float, sigma_prev: float, sample_hat: torch.Tensor, return_dict: bool = True, ) -> Union[KarrasVeOutput, Tuple]: """ Predict the sample from the previous timestep ...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
Returns: [`~schedulers.scheduling_karras_ve.KarrasVESchedulerOutput`] or `tuple`: If return_dict is `True`, [`~schedulers.scheduling_karras_ve.KarrasVESchedulerOutput`] is returned, otherwise a tuple is returned where the first element is the sample tensor. """ ...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
def step_correct( self, model_output: torch.Tensor, sigma_hat: float, sigma_prev: float, sample_hat: torch.Tensor, sample_prev: torch.Tensor, derivative: torch.Tensor, return_dict: bool = True, ) -> Union[KarrasVeOutput, Tuple]: """ Cor...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py
""" pred_original_sample = sample_prev + sigma_prev * model_output derivative_corr = (sample_prev - pred_original_sample) / sigma_prev sample_prev = sample_hat + (sigma_prev - sigma_hat) * (0.5 * derivative + 0.5 * derivative_corr) if not return_dict: return (sample_prev, de...
1,377
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/deprecated/scheduling_karras_ve.py