text
stringlengths
1
1.02k
class_index
int64
0
1.38k
source
stringclasses
431 values
if self.step_index is None: self._init_step_index(timestep) lower_order_final = ( (self.step_index == len(self.timesteps) - 1) and self.config.lower_order_final and len(self.timesteps) < 15 ) lower_order_second = ( (self.step_index == len(self.timesteps) - 2)...
1,357
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_deis_multistep.py
if self.config.solver_order == 1 or self.lower_order_nums < 1 or lower_order_final: prev_sample = self.deis_first_order_update(model_output, sample=sample) elif self.config.solver_order == 2 or self.lower_order_nums < 2 or lower_order_second: prev_sample = self.multistep_deis_second_orde...
1,357
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_deis_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,357
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_deis_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,357
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_deis_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,357
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_deis_multistep.py
class UnCLIPSchedulerOutput(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 nex...
1,358
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
class UnCLIPScheduler(SchedulerMixin, ConfigMixin): """ NOTE: do not use this scheduler. The DDPM scheduler has been updated to support the changes made here. This scheduler will be removed and replaced with DDPM. This is a modified DDPM Scheduler specifically for the karlo unCLIP model. This sche...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
Args: num_train_timesteps (`int`): number of diffusion steps used to train the model. variance_type (`str`): options to clip the variance used when adding noise to the denoised sample. Choose from `fixed_small_log` or `learned_range`. clip_sample (`bool`, default `True`):...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
@register_to_config def __init__( self, num_train_timesteps: int = 1000, variance_type: str = "fixed_small_log", clip_sample: bool = True, clip_sample_range: Optional[float] = 1.0, prediction_type: str = "epsilon", beta_schedule: str = "squaredcos_cap_v2", ...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
def scale_model_input(self, sample: torch.Tensor, timestep: Optional[int] = None) -> torch.Tensor: """ Ensures interchangeability with schedulers that need to scale the denoising model input depending on the current timestep. Args: sample (`torch.Tensor`): input sample ...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
Args: num_inference_steps (`int`): the number of diffusion steps used when generating samples with a pre-trained model. """ self.num_inference_steps = num_inference_steps step_ratio = (self.config.num_train_timesteps - 1) / (self.num_inference_steps - 1) times...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
if prev_timestep == t - 1: beta = self.betas[t] else: beta = 1 - alpha_prod_t / alpha_prod_t_prev # For t > 0, compute predicted variance βt (see formula (6) and (7) from https://arxiv.org/pdf/2006.11239.pdf) # and sample from it to get previous sample # x_{t-1} ...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
frac = (predicted_variance + 1) / 2 variance = frac * max_log + (1 - frac) * min_log return variance def step( self, model_output: torch.Tensor, timestep: int, sample: torch.Tensor, prev_timestep: Optional[int] = None, generator=None, ret...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
Args: model_output (`torch.Tensor`): direct output from learned diffusion model. timestep (`int`): current discrete timestep in the diffusion chain. sample (`torch.Tensor`): current instance of sample being created by diffusion process. prev_timestep (`int...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
if model_output.shape[1] == sample.shape[1] * 2 and self.variance_type == "learned_range": model_output, predicted_variance = torch.split(model_output, sample.shape[1], dim=1) else: predicted_variance = None # 1. compute alphas, betas if prev_timestep is None: ...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
# 2. compute predicted original sample from predicted noise also called # "predicted x_0" of formula (15) from https://arxiv.org/pdf/2006.11239.pdf if self.config.prediction_type == "epsilon": pred_original_sample = (sample - beta_prod_t ** (0.5) * model_output) / alpha_prod_t ** (0.5) ...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
# 4. Compute coefficients for pred_original_sample x_0 and current sample x_t # See formula (7) from https://arxiv.org/pdf/2006.11239.pdf pred_original_sample_coeff = (alpha_prod_t_prev ** (0.5) * beta) / beta_prod_t current_sample_coeff = alpha ** (0.5) * beta_prod_t_prev / beta_prod_t ...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
if self.variance_type == "fixed_small_log": variance = variance elif self.variance_type == "learned_range": variance = (0.5 * variance).exp() else: raise ValueError( f"variance_type given as {self.variance_type} must be one of `...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMScheduler.add_noise def add_noise( self, original_samples: torch.Tensor, noise: torch.Tensor, timesteps: torch.IntTensor, ) -> torch.Tensor: # Make sure alphas_cumprod and timestep have same device and dtype as origin...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
sqrt_one_minus_alpha_prod = (1 - alphas_cumprod[timesteps]) ** 0.5 sqrt_one_minus_alpha_prod = sqrt_one_minus_alpha_prod.flatten() while len(sqrt_one_minus_alpha_prod.shape) < len(original_samples.shape): sqrt_one_minus_alpha_prod = sqrt_one_minus_alpha_prod.unsqueeze(-1) noisy_samp...
1,359
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_unclip.py
class AmusedSchedulerOutput(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 nex...
1,360
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
class AmusedScheduler(SchedulerMixin, ConfigMixin): order = 1 temperatures: torch.Tensor @register_to_config def __init__( self, mask_token_id: int, masking_schedule: str = "cosine", ): self.temperatures = None self.timesteps = None def set_timesteps( ...
1,361
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
def step( self, model_output: torch.Tensor, timestep: torch.long, sample: torch.LongTensor, starting_mask_ratio: int = 1, generator: Optional[torch.Generator] = None, return_dict: bool = True, ) -> Union[AmusedSchedulerOutput, Tuple]: two_dim_input = s...
1,361
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
device = probs.device probs_ = probs.to(generator.device) if generator is not None else probs # handles when generator is on CPU if probs_.device.type == "cpu" and probs_.dtype != torch.float32: probs_ = probs_.float() # multinomial is not implemented for cpu half precision probs_ ...
1,361
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
if self.config.masking_schedule == "cosine": mask_ratio = torch.cos(ratio * math.pi / 2) elif self.config.masking_schedule == "linear": mask_ratio = 1 - ratio else: raise ValueError(f"unknown masking schedule {self.config.masking_schedule}") ...
1,361
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
masking = mask_by_random_topk(mask_len, selected_probs, self.temperatures[step_idx], generator) # Masks tokens with lower confidence. prev_sample = torch.where(masking, self.config.mask_token_id, pred_original_sample) if two_dim_input: prev_sample = prev_sample.reshape(batc...
1,361
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
if self.config.masking_schedule == "cosine": mask_ratio = torch.cos(ratio * math.pi / 2) elif self.config.masking_schedule == "linear": mask_ratio = 1 - ratio else: raise ValueError(f"unknown masking schedule {self.config.masking_schedule}") mask_indices = ( ...
1,361
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_amused.py
class ConsistencyDecoderSchedulerOutput(BaseOutput): """ Output class for the scheduler's `step` function. 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 a...
1,362
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
class ConsistencyDecoderScheduler(SchedulerMixin, ConfigMixin): order = 1 @register_to_config def __init__( self, num_train_timesteps: int = 1024, sigma_data: float = 0.5, ): betas = betas_for_alpha_bar(num_train_timesteps) alphas = 1.0 - betas alphas_cu...
1,363
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
def set_timesteps( self, num_inference_steps: Optional[int] = None, device: Union[str, torch.device] = None, ): if num_inference_steps != 2: raise ValueError("Currently more than 2 inference steps are not supported.") self.timesteps = torch.tensor([1008, 512], dt...
1,363
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
Args: sample (`torch.Tensor`): The input sample. timestep (`int`, *optional*): The current timestep in the diffusion chain. Returns: `torch.Tensor`: A scaled input sample. """ return sample * self.c_in[timestep]...
1,363
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
Args: model_output (`torch.Tensor`): The direct output from the learned diffusion model. timestep (`float`): The current timestep in the diffusion chain. sample (`torch.Tensor`): A current instance of a sample created by the diffusion p...
1,363
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
Returns: [`~schedulers.scheduling_consistency_models.ConsistencyDecoderSchedulerOutput`] or `tuple`: If return_dict is `True`, [`~schedulers.scheduling_consistency_models.ConsistencyDecoderSchedulerOutput`] is returned, otherwise a tuple is returned where the ...
1,363
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
if not return_dict: return (prev_sample,) return ConsistencyDecoderSchedulerOutput(prev_sample=prev_sample)
1,363
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_consistency_decoder.py
class VQDiffusionSchedulerOutput(BaseOutput): """ Output class for the scheduler's step function output. Args: prev_sample (`torch.LongTensor` of shape `(batch size, num latent pixels)`): Computed sample x_{t-1} of previous timestep. `prev_sample` should be used as next model input in t...
1,364
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
class VQDiffusionScheduler(SchedulerMixin, ConfigMixin): """ A scheduler for vector quantized diffusion. This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic methods the library implements for all schedulers such as loading and saving.
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
Args: num_vec_classes (`int`): The number of classes of the vector embeddings of the latent pixels. Includes the class for the masked latent pixel. num_train_timesteps (`int`, defaults to 100): The number of diffusion steps to train the model. alpha_cum_start ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
@register_to_config def __init__( self, num_vec_classes: int, num_train_timesteps: int = 100, alpha_cum_start: float = 0.99999, alpha_cum_end: float = 0.000009, gamma_cum_start: float = 0.000009, gamma_cum_end: float = 0.99999, ): self.num_embed = ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
at = torch.tensor(at.astype("float64")) bt = torch.tensor(bt.astype("float64")) ct = torch.tensor(ct.astype("float64")) log_at = torch.log(at) log_bt = torch.log(bt) log_ct = torch.log(ct) att = torch.tensor(att.astype("float64")) btt = torch.tensor(btt.astype("f...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.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). Args: num_inference_steps (`int`): The number of diffusion steps used when generatin...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
self.log_at = self.log_at.to(device) self.log_bt = self.log_bt.to(device) self.log_ct = self.log_ct.to(device) self.log_cumprod_at = self.log_cumprod_at.to(device) self.log_cumprod_bt = self.log_cumprod_bt.to(device) self.log_cumprod_ct = self.log_cumprod_ct.to(device) def s...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
Args: log_p_x_0: (`torch.Tensor` of shape `(batch size, num classes - 1, num latent pixels)`): The log probabilities for the predicted classes of the initial latent pixels. Does not include a prediction for the masked class as the initial unnoised image cannot be masked. ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
Returns: [`~schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput`] or `tuple`: If return_dict is `True`, [`~schedulers.scheduling_vq_diffusion.VQDiffusionSchedulerOutput`] is returned, otherwise a tuple is returned where the first element is the sample tensor. ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
Args: log_p_x_0 (`torch.Tensor` of shape `(batch size, num classes - 1, num latent pixels)`): The log probabilities for the predicted classes of the initial latent pixels. Does not include a prediction for the masked class as the initial unnoised image cannot be masked. ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
log_q_t_given_x_t_min_1 = self.log_Q_t_transitioning_to_known_class( t=t, x_t=x_t, log_onehot_x_t=log_onehot_x_t, cumulative=False ) # p_0(x_0=C_0 | x_t) / q(x_t | x_0=C_0) ... p_n(x_0=C_0 | x_t) / q(x_t | x_0=C_0) # . . ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# p_0(x_0=C_0 | x_t) / q(x_t | x_0=C_0) / sum_0 ... p_n(x_0=C_0 | x_t) / q(x_t | x_0=C_0) / sum_n # . . . # . . . ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# (p_0(x_0=C_0 | x_t) / q(x_t | x_0=C_0) / sum_0) * a_cumulative_{t-1} + b_cumulative_{t-1} ... (p_n(x_0=C_0 | x_t) / q(x_t | x_0=C_0) / sum_n) * a_cumulative_{t-1} + b_cumulative_{t-1} # . . ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
q = self.apply_cumulative_transitions(q, t - 1)
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# ((p_0(x_0=C_0 | x_t) / q(x_t | x_0=C_0) / sum_0) * a_cumulative_{t-1} + b_cumulative_{t-1}) * q(x_t | x_{t-1}=C_0) * sum_0 ... ((p_n(x_0=C_0 | x_t) / q(x_t | x_0=C_0) / sum_n) * a_cumulative_{t-1} + b_cumulative_{t-1}) * q(x_t | x_{t-1}=C_0) * sum_n # ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# ((p_0(x_0=C_{k-1} | x_t) / q(x_t | x_0=C_{k-1}) / sum_0) * a_cumulative_{t-1} + b_cumulative_{t-1}) * q(x_t | x_{t-1}=C_{k-1}) * sum_0 ... ((p_n(x_0=C_{k-1} | x_t) / q(x_t | x_0=C_{k-1}) / sum_n) * a_cumulative_{t-1} + b_cumulative_{t-1}) * q(x_t | x_{t-1}=C_{k-1}) * sum_n # c_cumulative_{t-1} * q(x_t |...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# For each column, there are two possible cases. # # Where: # - sum(p_n(x_0))) is summing over all classes for x_0 # - C_i is the class transitioning from (not to be confused with c_t and c_cumulative_t being used for gamma's) # - C_j is the class transitioning to # ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# From equation (11) stated in terms of forward probabilities, the last row is trivially verified. # # For the other rows, we can state the equation as ... # # (c_t / c_cumulative_t) * [b_cumulative_{t-1} * p(x_0=c_0) + ... + (a_cumulative_{t-1} + b_cumulative_{t-1}) * p(x_0=C_i) + ... +...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# C_j != C_i: b_t * ((b_cumulative_{t-1} / b_cumulative_t) * p_n(x_0 = c_0) + ... + ((a_cumulative_{t-1} + b_cumulative_{t-1}) / b_cumulative_t) * p_n(x_0 = C_i) + ... + (b_cumulative_{t-1} / (a_cumulative_t + b_cumulative_t)) * p_n(c_0=C_j) + ... + (b_cumulative_{t-1} / b_cumulative_t) * p_n(x_0 = c_{k-1})) ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# The last row is trivially verified. The other rows can be verified by directly expanding equation (11) stated in terms of forward probabilities. return log_p_x_t_min_1
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
def log_Q_t_transitioning_to_known_class( self, *, t: torch.int, x_t: torch.LongTensor, log_onehot_x_t: torch.Tensor, cumulative: bool ): """ Calculates the log probabilities of the rows from the (cumulative or non-cumulative) transition matrix for each latent pixel in `x_t`. ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
Returns: `torch.Tensor` of shape `(batch size, num classes - 1, num latent pixels)`: Each _column_ of the returned matrix is a _row_ of log probabilities of the complete probability transition matrix. When non cumulative, returns `self.num_classes - 1` rows b...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
non-cumulative result (omitting logarithms): ``` q_0(x_t | x_{t-1} = C_0) ... q_n(x_t | x_{t-1} = C_0) . . . . . . . . . ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
cumulative result (omitting logarithms): ``` q_0_cumulative(x_t | x_0 = C_0) ... q_n_cumulative(x_t | x_0 = C_0) . . . . . . . ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
if not cumulative: # The values in the onehot vector can also be used as the logprobs for transitioning # from masked latent pixels. If we are not calculating the cumulative transitions, # we need to save these vectors to be re-appended to the final matrix so the values #...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# `index_to_log_onehot` will add onehot vectors for masked pixels, # so the default one hot matrix has one too many rows. See the doc string # for an explanation of the dimensionality of the returned matrix. log_onehot_x_t = log_onehot_x_t[:, :-1, :] # this is a cheeky trick to produce ...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
# The whole column of each masked pixel is `c` mask_class_mask = x_t == self.mask_class mask_class_mask = mask_class_mask.unsqueeze(1).expand(-1, self.num_embed - 1, -1) log_Q_t[mask_class_mask] = c if not cumulative: log_Q_t = torch.cat((log_Q_t, log_onehot_x_t_transitionin...
1,365
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_vq_diffusion.py
class RePaintSchedulerOutput(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 m...
1,366
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
class RePaintScheduler(SchedulerMixin, ConfigMixin): """ `RePaintScheduler` is a scheduler for DDPM inpainting inside a given mask. This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic methods the library implements for all schedulers such ...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.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,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
Clip the predicted sample between -1 and 1 for numerical stability.
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
""" order = 1
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.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", eta: float = 0.0, trained_betas: Optional[np.ndarray] = None, clip_sample: bool = True, ): ...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
# GeoDiff sigmoid schedule betas = torch.linspace(-6, 6, num_train_timesteps) self.betas = torch.sigmoid(betas) * (beta_end - beta_start) + beta_start else: raise NotImplementedError(f"{beta_schedule} is not implemented for {self.__class__}")
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
self.alphas = 1.0 - self.betas self.alphas_cumprod = torch.cumprod(self.alphas, dim=0) self.one = torch.tensor(1.0) self.final_alpha_cumprod = torch.tensor(1.0) # standard deviation of the initial noise distribution self.init_noise_sigma = 1.0 # setable values ...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
Returns: `torch.Tensor`: A scaled input sample. """ return sample def set_timesteps( self, num_inference_steps: int, jump_length: int = 10, jump_n_sample: int = 10, device: Union[str, torch.device] = None, ): """ ...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
Args: num_inference_steps (`int`): The number of diffusion steps used when generating samples with a pre-trained model. If used, `timesteps` must be `None`. jump_length (`int`, defaults to 10): The number of steps taken forward in time before going...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
jumps = {} for j in range(0, num_inference_steps - jump_length, jump_length): jumps[j] = jump_n_sample - 1 t = num_inference_steps while t >= 1: t = t - 1 timesteps.append(t) if jumps.get(t, 0) > 0: jumps[t] = jumps[t] - 1 ...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
# For t > 0, compute predicted variance βt (see formula (6) and (7) from # https://arxiv.org/pdf/2006.11239.pdf) and sample from it to get # previous sample x_{t-1} ~ N(pred_prev_sample, variance) == add # variance to pred_sample # Is equivalent to formula (16) in https://arxiv.org/pdf/2...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
def step( self, model_output: torch.Tensor, timestep: int, sample: torch.Tensor, original_image: torch.Tensor, mask: torch.Tensor, generator: Optional[torch.Generator] = None, return_dict: bool = True, ) -> Union[RePaintSchedulerOutput, Tuple]: ...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.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,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
Returns: [`~schedulers.scheduling_repaint.RePaintSchedulerOutput`] or `tuple`: If return_dict is `True`, [`~schedulers.scheduling_repaint.RePaintSchedulerOutput`] is returned, otherwise a tuple is returned where the first element is the sample tensor. """ t =...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
# 3. Clip "predicted x_0" if self.config.clip_sample: pred_original_sample = torch.clamp(pred_original_sample, -1, 1) # We choose to follow RePaint Algorithm 1 to get x_{t-1}, however we # substitute formula (7) in the algorithm coming from DDPM paper # (formula (4) Algorith...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
# 6. compute "direction pointing to x_t" of formula (12) # from https://arxiv.org/pdf/2010.02502.pdf pred_sample_direction = (1 - alpha_prod_t_prev - std_dev_t**2) ** 0.5 * model_output # 7. compute x_{t-1} of formula (12) from https://arxiv.org/pdf/2010.02502.pdf prev_unknown_part = al...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
def undo_step(self, sample, timestep, generator=None): n = self.config.num_train_timesteps // self.num_inference_steps for i in range(n): beta = self.betas[timestep + i] if sample.device.type == "mps": # randn does not work reproducibly on mps noi...
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
def __len__(self): return self.config.num_train_timesteps
1,367
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_repaint.py
class DDIMSchedulerOutput(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 ...
1,368
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
class DDIMScheduler(SchedulerMixin, ConfigMixin): """ `DDIMScheduler` extends the denoising procedure introduced in denoising diffusion probabilistic models (DDPMs) with non-Markovian guidance. This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the g...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.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,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
Each diffusion step uses the alphas product value at that step and at the previous one. For the final step there is no previous alpha. When this option is `True` the previous alpha product is fixed to `1`, otherwise it uses the alpha value at step 0. steps_offset (`int`, defaults to 0): ...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
dynamic_thresholding_ratio (`float`, defaults to 0.995): The ratio for the dynamic thresholding method. Valid only when `thresholding=True`. sample_max_value (`float`, defaults to 1.0): The threshold value for dynamic thresholding. Valid only when `thresholding=True`. timestep_sp...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
[`--offset_noise`](https://github.com/huggingface/diffusers/blob/74fd735eb073eb1d774b1ab4154a0876eb82f055/examples/dreambooth/train_dreambooth.py#L506). """
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
_compatibles = [e.name for e in KarrasDiffusionSchedulers] order = 1
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.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, clip_sample: bool = True, set_al...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
# this schedule is very specific to the latent diffusion model. 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_t...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
# Rescale for zero SNR 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) # At every step in ddim, we are looking into the previous alphas_cumprod # For...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
def scale_model_input(self, sample: torch.Tensor, timestep: Optional[int] = None) -> torch.Tensor: """ Ensures interchangeability with schedulers that need to scale the denoising model input depending on the current timestep. Args: sample (`torch.Tensor`): Th...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.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,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.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,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.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). Args: num_inference_steps (`int`): The number of diffusion steps used when generatin...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891 if self.config.timestep_spacing == "linspace": timesteps = ( np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps) .round()[::-1] ...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
# creates integer timesteps by multiplying by ratio # casting to int to avoid issues when num_inference_step is power of 3 timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64) timesteps -= 1 else: raise ValueError( ...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
self.timesteps = torch.from_numpy(timesteps).to(device) def step( self, model_output: torch.Tensor, timestep: int, sample: torch.Tensor, eta: float = 0.0, use_clipped_model_output: bool = False, generator=None, variance_noise: Optional[torch.Tensor] =...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
Args: model_output (`torch.Tensor`): The direct output from learned diffusion model. timestep (`float`): The current discrete timestep in the diffusion chain. sample (`torch.Tensor`): A current instance of a sample created by the diffus...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
variance_noise (`torch.Tensor`): Alternative to generating noise with `generator` by directly providing the noise for the variance itself. Useful for methods such as [`CycleDiffusion`]. return_dict (`bool`, *optional*, defaults to `True`): Whether or not to re...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py
Returns: [`~schedulers.scheduling_ddim.DDIMSchedulerOutput`] or `tuple`: If return_dict is `True`, [`~schedulers.scheduling_ddim.DDIMSchedulerOutput`] is returned, otherwise a tuple is returned where the first element is the sample tensor. """ if self.num_inf...
1,369
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/schedulers/scheduling_ddim.py