
    bi!                         d dl Z d dlZd dlmZ d dlmZ d dlmZ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e      Zg dg dg dg dg ddZe G d de             Z G d de      Zy)    N)	dataclass)Enum)OptionalUnion)validate_hf_hub_args)Self   )
BaseOutputPushToHubMixinzscheduler_config.jsonc                   H    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y)KarrasDiffusionSchedulers   r	                     	   
                  N)__name__
__module____qualname__DDIMSchedulerDDPMSchedulerPNDMSchedulerLMSDiscreteSchedulerEulerDiscreteSchedulerHeunDiscreteSchedulerEulerAncestralDiscreteSchedulerDPMSolverMultistepSchedulerDPMSolverSinglestepSchedulerKDPM2DiscreteSchedulerKDPM2AncestralDiscreteSchedulerDEISMultistepSchedulerUniPCMultistepSchedulerDPMSolverSDESchedulerEDMEulerScheduler     `/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/schedulers/scheduling_utils.pyr   r   "   sY    MMM&'#"##$ &(# r/   r   )
  iR  i  i  i!  i  iW     |      ){G:-@gfffff@gS@g~jt@gV-?gtV?g7A`?gw/?gK7?g~jt?        )
r1   iM  i  iK  i  i6     t   5   r   )r5   g(\B@g^I+@g r@gFx?g/$?g(\?gRQ?gʡE?g!rh?r6   )g     @g     @K@gʡ/@g r@gˡE@g9v?g1Zd?gn?g/$?g rh?r6   )StableDiffusionTimestepsStableDiffusionSigmasStableDiffusionXLTimestepsStableDiffusionXLSigmasStableDiffusionVideoSigmasc                   0    e Zd ZU dZej
                  ed<   y)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/   r0   r@   r@   =   s     r/   r@   c            	           e Zd ZdZeZg ZdZee		 	 	 dde
eeej                  f      de
e   defd              Zddeeej                  f   d	efd
Zed        Zed        Zy)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).
    TNpretrained_model_name_or_path	subfolderreturnc                 b     | 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 (`Union[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.

        </Tip>

        T)rH   rI   return_unused_kwargsreturn_commit_hashrL   r.   )load_configfrom_config)clsrH   rI   rL   kwargsconfigcommit_hashs          r0   from_pretrainedzSchedulerMixin.from_pretrained_   sV    p '6coo '
*G!%#	'

 '
# sv[<P[TZ[[r/   save_directorypush_to_hubc                 .     | j                   d||d| y)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.
        )rU   rV   Nr.   )save_config)selfrU   rV   rQ   s       r0   save_pretrainedzSchedulerMixin.save_pretrained   s     	ZKZSYZr/   c                 "    | j                         S )z
        Returns all schedulers that are compatible with this scheduler

        Returns:
            `List[SchedulerMixin]`: List of compatible schedulers
        )_get_compatibles)rY   s    r0   compatibleszSchedulerMixin.compatibles   s     $$&&r/   c                 
   t        t        | j                  g| j                  z               }t	        j
                  t        j                  d      d         }|D cg c]  }t        ||      st        ||       }}|S c c}w )N.r   )	listsetr   _compatibles	importlibimport_modulesplithasattrgetattr)rP   compatible_classes_strdiffusers_libraryccompatible_classess        r0   r\   zSchedulerMixin._get_compatibles   s}    !%c3<<.3;K;K*K&L!M%33HNN34G4JK3I
./WUfhiMjG%q)
 
 "!
s   B .B )NNF)F)r   r   r   rB   SCHEDULER_CONFIG_NAMEconfig_namerb   has_compatiblesclassmethodr   r   r   strosPathLiker   rT   boolrZ   propertyr]   r\   r.   r/   r0   rG   rG   K   s     (KLO LP#'"	=\'/c2;;6F0G'H=\ C==\ 
=\  =\~[eC4D.E [TX [" ' ' " "r/   rG   )rc   rq   dataclassesr   enumr   typingr   r   rC   huggingface_hub.utilsr   typing_extensionsr   utilsr
   r   rl   r   AysSchedulesr@   rG   r.   r/   r0   <module>r|      sx     	 !  "  6 " . 0  & !Ri"Rk"n 
j 
 
w"^ w"r/   