o
    Gi!                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 ddlmZmZ dZG d	d
 d
eZg dg dg dg dg ddZeG dd deZG dd deZdS )    N)	dataclass)Enum)validate_hf_hub_args)Self   )
BaseOutputPushToHubMixinzscheduler_config.jsonc                   @   sH   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdS )KarrasDiffusionSchedulers   r                     	   
                  N)__name__
__module____qualname__DDIMSchedulerDDPMSchedulerPNDMSchedulerLMSDiscreteSchedulerEulerDiscreteSchedulerHeunDiscreteSchedulerEulerAncestralDiscreteSchedulerDPMSolverMultistepSchedulerDPMSolverSinglestepSchedulerKDPM2DiscreteSchedulerKDPM2AncestralDiscreteSchedulerDEISMultistepSchedulerUniPCMultistepSchedulerDPMSolverSDESchedulerEDMEulerScheduler r*   r*   Y/home/ubuntu/.local/lib/python3.10/site-packages/diffusers/schedulers/scheduling_utils.pyr	   !   s     r	   )
  iR  i  i  i!  i  iW     |      ){G:-@gfffff@gS@g~jt@gV-?gtV?g7A`?gw/?gK7?g~jt?        )
r,   iM  i  iK  i  i6     t   5   r   )r0   g(\B@g^I+@g r@gFx?g/$?g(\?gRQ?gʡE?g!rh?r1   )g     @g     @K@gʡ/@g r@gˡE@g9v?g1Zd?gn?g/$?g rh?r1   )StableDiffusionTimestepsStableDiffusionSigmasStableDiffusionXLTimestepsStableDiffusionXLSigmasStableDiffusionVideoSigmasc                   @   s   e Zd ZU dZejed< dS )SchedulerOutputaH  
    Base class for the output of a 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 as next model input in the
            denoising loop.
    prev_sampleN)r   r   r   __doc__torchTensor__annotations__r*   r*   r*   r+   r:   <   s   
 	r:   c                	   @   s   e Zd ZdZeZg ZdZee				dde
ejB dB de
dB defdd	Zdd
e
ejB defddZedd Zedd ZdS )SchedulerMixina  
    Base class for all schedulers.

    [`SchedulerMixin`] contains common functions shared by all schedulers such as general loading and saving
    functionalities.

    [`ConfigMixin`] takes care of storing the configuration attributes (like `num_train_timesteps`) that are passed to
    the scheduler's `__init__` function, and the attributes can be accessed by `scheduler.config.num_train_timesteps`.

    Class attributes:
        - **_compatibles** (`list[str]`) -- A list of scheduler classes that are compatible with the parent scheduler
          class. Use [`~ConfigMixin.from_config`] to load a different compatible scheduler class (should be overridden
          by parent class).
    TNFpretrained_model_name_or_path	subfolderreturnc                 K   s6   | j d||ddd|\}}}| j|fd|i|S )a(  
        Instantiate a scheduler from a pre-defined JSON configuration file in a local directory or Hub repository.

        Parameters:
            pretrained_model_name_or_path (`str` or `os.PathLike`, *optional*):
                Can be either:

                    - A string, the *model id* (for example `google/ddpm-celebahq-256`) of a pretrained model hosted on
                      the Hub.
                    - A path to a *directory* (for example `./my_model_directory`) containing the scheduler
                      configuration saved with [`~SchedulerMixin.save_pretrained`].
            subfolder (`str`, *optional*):
                The subfolder location of a model file within a larger model repository on the Hub or locally.
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                Whether kwargs that are not consumed by the Python class should be returned or not.
            cache_dir (`str | os.PathLike`, *optional*):
                Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
                is not used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force the (re-)download of the model weights and configuration files, overriding the
                cached versions if they exist.

            proxies (`dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
            output_loading_info(`bool`, *optional*, defaults to `False`):
                Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
            local_files_only(`bool`, *optional*, defaults to `False`):
                Whether to only load local model weights and configuration files or not. If set to `True`, the model
                won't be downloaded from the Hub.
            token (`str` or *bool*, *optional*):
                The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
                `diffusers-cli login` (stored in `~/.huggingface`) is used.
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
                allowed by Git.

        > [!TIP] > To use private or [gated models](https://huggingface.co/docs/hub/models-gated#gated-models), log-in
        with `hf > auth login`. You can also activate the special >
        ["offline-mode"](https://huggingface.co/diffusers/installation.html#offline-mode) to use this method in a >
        firewalled environment.

        T)rA   rB   return_unused_kwargsreturn_commit_hashrD   Nr*   )load_configfrom_config)clsrA   rB   rD   kwargsconfigcommit_hashr*   r*   r+   from_pretrained^   s   4zSchedulerMixin.from_pretrainedsave_directorypush_to_hubc                 K   s   | j d||d| dS )a?  
        Save a scheduler configuration object to a directory so that it can be reloaded using the
        [`~SchedulerMixin.from_pretrained`] class method.

        Args:
            save_directory (`str` or `os.PathLike`):
                Directory where the configuration JSON file will be saved (will be created if it does not exist).
            push_to_hub (`bool`, *optional*, defaults to `False`):
                Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the
                repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
                namespace).
            kwargs (`dict[str, Any]`, *optional*):
                Additional keyword arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
        )rM   rN   Nr*   )save_config)selfrM   rN   rI   r*   r*   r+   save_pretrained   s   zSchedulerMixin.save_pretrainedc                 C   s   |   S )z
        Returns all schedulers that are compatible with this scheduler

        Returns:
            `list[SchedulerMixin]`: list of compatible schedulers
        )_get_compatibles)rP   r*   r*   r+   compatibles   s   zSchedulerMixin.compatiblesc                    s@   t t| jg| j }ttdd   fdd|D }|S )N.r   c                    s    g | ]}t  |rt |qS r*   )hasattrgetattr).0cdiffusers_libraryr*   r+   
<listcomp>   s
    
z3SchedulerMixin._get_compatibles.<locals>.<listcomp>)listsetr   _compatibles	importlibimport_modulesplit)rH   compatible_classes_strcompatible_classesr*   rY   r+   rR      s   
zSchedulerMixin._get_compatibles)NNF)F)r   r   r   r<   SCHEDULER_CONFIG_NAMEconfig_namer^   has_compatiblesclassmethodr   strosPathLiker   rL   boolrQ   propertyrS   rR   r*   r*   r*   r+   r@   J   s,    ;
	r@   )r_   ri   dataclassesr   enumr   r=   huggingface_hub.utilsr   typing_extensionsr   utilsr   r   rd   r	   AysSchedulesr:   r@   r*   r*   r*   r+   <module>   s&   	