Diffusers documentation

Linear multistep scheduler for discrete beta schedules

You are viewing v0.14.0 version. A newer version v0.16.0 is available. Join the Hugging Face community

to get started

# Linear multistep scheduler for discrete beta schedules

## Overview

Original implementation can be found here.

## LMSDiscreteScheduler

### class diffusers.LMSDiscreteScheduler

< >

( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: typing.Union[numpy.ndarray, typing.List[float], NoneType] = None prediction_type: str = 'epsilon' )

Parameters

• num_train_timesteps (int) — number of diffusion steps used to train the model.
• beta_start (float) — the starting beta value of inference.
• beta_end (float) — the final beta value.
• beta_schedule (str) — the beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from linear or scaled_linear.
• trained_betas (np.ndarray, optional) — option to pass an array of betas directly to the constructor to bypass beta_start, beta_end etc.
• prediction_type (str, default epsilon, optional) — prediction type of the scheduler function, one of epsilon (predicting the noise of the diffusion process), sample (directly predicting the noisy sample) or v_prediction (see section 2.4 https://imagen.research.google/video/paper.pdf)

Linear Multistep Scheduler for discrete beta schedules. Based on the original k-diffusion implementation by Katherine Crowson: https://github.com/crowsonkb/k-diffusion/blob/481677d114f6ea445aa009cf5bd7a9cdee909e47/k_diffusion/sampling.py#L181

~ConfigMixin takes care of storing all config attributes that are passed in the scheduler’s __init__ function, such as num_train_timesteps. They can be accessed via scheduler.config.num_train_timesteps. SchedulerMixin provides general loading and saving functionality via the SchedulerMixin.save_pretrained() and from_pretrained() functions.

#### get_lms_coefficient

< >

( order t current_order )

Parameters

• order (TODO) —
• t (TODO) —
• current_order (TODO) —

Compute a linear multistep coefficient.

#### scale_model_input

< >

( sample: FloatTensor timestep: typing.Union[float, torch.FloatTensor] ) torch.FloatTensor

Parameters

• sample (torch.FloatTensor) — input sample
• timestep (float or torch.FloatTensor) — the current timestep in the diffusion chain

Returns

torch.FloatTensor

scaled input sample

Scales the denoising model input by (sigma**2 + 1) ** 0.5 to match the K-LMS algorithm.

#### set_timesteps

< >

( num_inference_steps: int device: typing.Union[str, torch.device] = None )

Parameters

• 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.

Sets the timesteps used for the diffusion chain. Supporting function to be run before inference.

#### step

< >

( model_output: FloatTensor timestep: typing.Union[float, torch.FloatTensor] sample: FloatTensor order: int = 4 return_dict: bool = True ) ~schedulers.scheduling_utils.LMSDiscreteSchedulerOutput or tuple

Parameters

• model_output (torch.FloatTensor) — direct output from learned diffusion model.
• timestep (float) — current timestep in the diffusion chain.
• sample (torch.FloatTensor) — current instance of sample being created by diffusion process. order — coefficient for multi-step inference.
• return_dict (bool) — option for returning tuple rather than LMSDiscreteSchedulerOutput class

Returns

~schedulers.scheduling_utils.LMSDiscreteSchedulerOutput or tuple

~schedulers.scheduling_utils.LMSDiscreteSchedulerOutput if return_dict is True, otherwise a tuple`. When returning a tuple, the first element is the sample tensor.

Predict the sample at the previous timestep by reversing the SDE. Core function to propagate the diffusion process from the learned model outputs (most often the predicted noise).
{"ft_lang_label":"__label__en","ft_lang_prob":0.59418124,"math_prob":0.68280184,"size":3297,"snap":"2023-14-2023-23","text_gpt3_token_len":775,"char_repetition_ratio":0.13938658,"word_repetition_ratio":0.0,"special_character_ratio":0.21898696,"punctuation_ratio":0.176,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9763997,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-01T22:53:15Z\",\"WARC-Record-ID\":\"<urn:uuid:b28c3a5c-8c81-423c-9cc4-2ebae04199bd>\",\"Content-Length\":\"143266\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1d717f6e-bd78-4b6d-9097-af46edc3c8ad>\",\"WARC-Concurrent-To\":\"<urn:uuid:27e944b3-b40e-430f-b007-c3fadd3c93cc>\",\"WARC-IP-Address\":\"108.138.64.67\",\"WARC-Target-URI\":\"https://huggingface.co/docs/diffusers/v0.14.0/api/schedulers/lms_discrete\",\"WARC-Payload-Digest\":\"sha1:PLIJYR7ZKXI2XOESZFQ3FOFPVPKCWXAR\",\"WARC-Block-Digest\":\"sha1:MMODIWYTDVR2ZBJHD3XIIFVTHGOVJZCR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224648209.30_warc_CC-MAIN-20230601211701-20230602001701-00617.warc.gz\"}"}