
    wi"                         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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dS )    N)	dataclass)Enum)OptionalUnion)validate_hf_hub_args   )
BaseOutputPushToHubMixinzscheduler_config.jsonc                   J    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     u/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/diffusers/schedulers/scheduling_utils.pyr   r   !   sg        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?        )
r0   iM  i  iK  i  i6     t   5   r   )r4   g(\B@g^I+@g r@gFx?g/$?g(\?gRQ?gʡE?g!rh?r5   )g     @g     @K@gʡ/@g r@gˡE@g9v?g1Zd?gn?g/$?g rh?r5   )StableDiffusionTimestepsStableDiffusionSigmasStableDiffusionXLTimestepsStableDiffusionXLSigmasStableDiffusionVideoSigmasc                   (    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.   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         fd                        Zddeeej        f         d	efd
Zed             Ze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	subfolderc                 N     | 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.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible. Will be removed in v1
                of Diffusers.
            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
        `huggingface-cli 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)rG   rH   return_unused_kwargsreturn_commit_hashrJ   r-   )load_configfrom_config)clsrG   rH   rJ   kwargsconfigcommit_hashs          r/   from_pretrainedzSchedulerMixin.from_pretrained^   sb    t '6co '
*G!%#	'
 '

 '
 '
# sv[[<P[TZ[[[r.   save_directorypush_to_hubc                 &     | 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.
        )rS   rT   Nr-   )save_config)selfrS   rT   rO   s       r/   save_pretrainedzSchedulerMixin.save_pretrained   s+     	ZKZZSYZZZZZr.   c                 *    |                                  S )z
        Returns all schedulers that are compatible with this scheduler

        Returns:
            `List[SchedulerMixin]`: List of compatible schedulers
        )_get_compatibles)rW   s    r/   compatibleszSchedulerMixin.compatibles   s     $$&&&r.   c                     t          t          | j        g| j        z                       }t	          j        t                              d          d                   fd|D             }|S )N.r   c                 P    g | ]"}t          |          t          |          #S r-   )hasattrgetattr).0cdiffusers_librarys     r/   
<listcomp>z3SchedulerMixin._get_compatibles.<locals>.<listcomp>   sE     
 
 
./WUfhiMjMj
%q))
 
 
r.   )listsetr   _compatibles	importlibimport_modulesplit)rN   compatible_classes_strcompatible_classesrc   s      @r/   rZ   zSchedulerMixin._get_compatibles   sx    !%c3<.3;K*K&L&L!M!M%3HNN34G4G4JKK
 
 
 
3I
 
 
 "!r.   )NNF)F)r   r   r   rA   SCHEDULER_CONFIG_NAMEconfig_namerg   has_compatiblesclassmethodr   r   r   strosPathLikerR   boolrX   propertyr[   rZ   r-   r.   r/   rF   rF   J   s
         (KLO LP#'"	?\ ?\'/c2;6F0G'H?\ C=?\ ?\ ?\  [?\B[ [eC4D.E [TX [ [ [ [" ' ' X' " " [" " "r.   rF   )rh   rr   dataclassesr   enumr   typingr   r   rB   huggingface_hub.utilsr   utilsr	   r
   rm   r   AysSchedulesr?   rF   r-   r.   r/   <module>r|      sm       				 ! ! ! ! ! !       " " " " " " " "  6 6 6 6 6 6 . . . . . . . . 0        & !R Q Qiii"R"R"Rkkk"n"n"n  
 
 
 
 
j 
 
 
y" y" y" y" y"^ y" y" y" y" y"r.   