
    bi                     r   d dl mZ d dlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddl m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZCmDZD ddlEmFZF ddlGmHZH ddlImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZX ddlYmZZZm[Z[ ddl\m]Z] ddl^m_Z_m`Z` ddlambZbmcZcmdZd ddlemfZfmgZgmhZh ddlimjZjmkZkmlZl ddlmmnZnmoZo  eg dedfd elfd!ehfd"eNfd#e#fd$e0fd%eJfd&e2fd'e9fd(eAfd)efd*efd+efd,efd-enfd.e_fd/eDfd0eZfd1e[fd2e]fd3eLfd4eSfd5ePfd6eXfd7eUfd8eKfd9efd:e.fd;e*fd<e)fd=e-fd>eFfd?eHfd@efdAefdBefdCef      Zp edebfd ejfd!effd"eMfd#e!fd&e3fd'e:fd(e@fd)efd4eQfd*efd+efd6eVfd7eTfd/eCfd:e+fd<e'fd;e%fd=e-fg      Zq edecfd ekfd!egfd#e"fd&e5fd'e<fd)efd5eOfd*efd+efd,efd6eWfd:e,fd<e(fd;e&fd4eRfg      Zr ed&e7fd'e>fd-eofd.e`fg      Zs ed&e4fd'e;fg      Zt ed&e6fd'e=fg      Zu e	       rddDlvmwZwmxZx ddElImyZy exepdF<   eyepdG<   eweqdF<   epeqereseteugZzdH Z{dI Z|dSdJe}fdKZ~ G dL dMe      Z G dN dOe      Z G dP dQe      ZyR)T    )OrderedDict)validate_hf_hub_args   )ConfigMixin)ControlNetUnionModel)is_sentencepiece_available   )AuraFlowPipeline)ChromaPipeline)CogView3PlusPipeline)CogView4ControlPipelineCogView4Pipeline)	(StableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetInpaintPipeline!StableDiffusionControlNetPipeline*StableDiffusionXLControlNetImg2ImgPipeline*StableDiffusionXLControlNetInpaintPipeline#StableDiffusionXLControlNetPipeline/StableDiffusionXLControlNetUnionImg2ImgPipeline/StableDiffusionXLControlNetUnionInpaintPipeline(StableDiffusionXLControlNetUnionPipeline),StableDiffusion3ControlNetInpaintingPipeline"StableDiffusion3ControlNetPipeline)IFImg2ImgPipelineIFInpaintingPipeline
IFPipeline)
FluxControlImg2ImgPipelineFluxControlInpaintPipelineFluxControlNetImg2ImgPipelineFluxControlNetInpaintPipelineFluxControlNetPipelineFluxControlPipelineFluxImg2ImgPipelineFluxInpaintPipelineFluxKontextPipelineFluxPipeline)HunyuanDiTPipeline)KandinskyCombinedPipeline KandinskyImg2ImgCombinedPipelineKandinskyImg2ImgPipeline KandinskyInpaintCombinedPipelineKandinskyInpaintPipelineKandinskyPipeline)KandinskyV22CombinedPipeline#KandinskyV22Img2ImgCombinedPipelineKandinskyV22Img2ImgPipeline#KandinskyV22InpaintCombinedPipelineKandinskyV22InpaintPipelineKandinskyV22Pipeline)Kandinsky3Img2ImgPipelineKandinsky3Pipeline)%LatentConsistencyModelImg2ImgPipelineLatentConsistencyModelPipeline)LuminaPipeline)Lumina2Pipeline)HunyuanDiTPAGPipelinePixArtSigmaPAGPipelineSanaPAGPipeline"StableDiffusion3PAGImg2ImgPipelineStableDiffusion3PAGPipeline+StableDiffusionControlNetPAGInpaintPipeline$StableDiffusionControlNetPAGPipeline!StableDiffusionPAGImg2ImgPipeline!StableDiffusionPAGInpaintPipelineStableDiffusionPAGPipeline-StableDiffusionXLControlNetPAGImg2ImgPipeline&StableDiffusionXLControlNetPAGPipeline#StableDiffusionXLPAGImg2ImgPipeline#StableDiffusionXLPAGInpaintPipelineStableDiffusionXLPAGPipeline)PixArtAlphaPipelinePixArtSigmaPipeline)SanaPipeline)StableCascadeCombinedPipelineStableCascadeDecoderPipeline)StableDiffusionImg2ImgPipelineStableDiffusionInpaintPipelineStableDiffusionPipeline)StableDiffusion3Img2ImgPipelineStableDiffusion3InpaintPipelineStableDiffusion3Pipeline) StableDiffusionXLImg2ImgPipeline StableDiffusionXLInpaintPipelineStableDiffusionXLPipeline)WuerstchenCombinedPipelineWuerstchenDecoderPipelinezstable-diffusionzstable-diffusion-xlzstable-diffusion-3zstable-diffusion-3-pagifhunyuanzhunyuan-pag	kandinskykandinsky22
kandinsky3zstable-diffusion-controlnetzstable-diffusion-xl-controlnetz$stable-diffusion-xl-controlnet-unionzstable-diffusion-3-controlnet
wuerstchencascadelcmzpixart-alphazpixart-sigmasanazsana-pagzstable-diffusion-pagzstable-diffusion-controlnet-pagzstable-diffusion-xl-pagz"stable-diffusion-xl-controlnet-pagzpixart-sigma-pagauraflowfluxzflux-controlzflux-controlnetzflux-kontextluminalumina2chromacogview3cogview4zcogview4-control)KolorsImg2ImgPipelineKolorsPipeline)KolorsPAGPipelinekolorsz
kolors-pagc                 0   | t         j                         v rt        t        | j                  d      S | t
        j                         v rt        t        | j                  d      S | t        j                         v rt        t        | j                  d      S y )NF)throw_error_if_not_exist)	*_AUTO_TEXT2IMAGE_DECODER_PIPELINES_MAPPINGvalues_get_task_class!AUTO_TEXT2IMAGE_PIPELINES_MAPPING__name__+_AUTO_IMAGE2IMAGE_DECODER_PIPELINES_MAPPING"AUTO_IMAGE2IMAGE_PIPELINES_MAPPING'_AUTO_INPAINT_DECODER_PIPELINES_MAPPINGAUTO_INPAINT_PIPELINES_MAPPING)pipeline_clss    \/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/pipelines/auto_pipeline.py_get_connected_pipelinerz      s    AHHJJ-|/D/D_d
 	
 BIIKK.0E0E`e
 	
 >EEGG=|?T?Totuu H    c                 t    t         D ]/  }|j                         D ]  \  }}|j                  | k(  s|c c S  1 y )N)SUPPORTED_TASKS_MAPPINGSitemsrs   )pipeline_class_nametask_mapping
model_namepipelines       ry   
_get_modelr      sC    0 "$0$6$6$8 	" J  $77!!	""r{   rn   c                 p    t        |      }|| j                  |d       }||S |rt        d| d|       y )Nz-AutoPipeline can't find a pipeline linked to z for )r   get
ValueError)mappingr   rn   r   
task_classs        ry   rq   rq     sU    /0J[[T2
!HI\H]]bcmbnopp  r{   c                   D    e Zd ZdZdZd Zeed               Zed        Z	y)AutoPipelineForText2Imagea6  

    [`AutoPipelineForText2Image`] is a generic pipeline class that instantiates a text-to-image pipeline class. The
    specific underlying pipeline class is automatically selected from either the
    [`~AutoPipelineForText2Image.from_pretrained`] or [`~AutoPipelineForText2Image.from_pipe`] methods.

    This class cannot be instantiated using `__init__()` (throws an error).

    Class attributes:

        - **config_name** (`str`) -- The configuration filename that stores the class and module names of all the
          diffusion pipeline's components.

    model_index.jsonc                     t        | j                  j                   d| j                  j                   d| j                  j                   d      Nz+ is designed to be instantiated using the `z5.from_pretrained(pretrained_model_name_or_path)` or `z.from_pipe(pipeline)` methods.EnvironmentError	__class__rs   selfargskwargss      ry   __init__z"AutoPipelineForText2Image.__init__#  R    ~~&&' (..112 3''((FH
 	
r{   c                 V   |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }||||||d	}	 | j                  |fi |	}
|
d
   }d|v rd}nd}d|v r>t        |d   t              r|
d
   j	                  |d      }n|
d
   j	                  |d      }d|v r%|j                  d      }|r|j	                  |d      }t        t        |      }i |	|} |j                  |fi |S )u(  
        Instantiates a text-to-image Pytorch diffusion pipeline from pretrained pipeline weight.

        The from_pretrained() method takes care of returning the correct pipeline class instance by:
            1. Detect the pipeline class of the pretrained_model_or_path based on the _class_name property of its
               config object
            2. Find the text-to-image pipeline linked to the pipeline class using pattern matching on pipeline class
               name.

        If a `controlnet` argument is passed, it will instantiate a [`StableDiffusionControlNetPipeline`] object.

        The pipeline is set in evaluation mode (`model.eval()`) by default.

        If you get the error message below, you need to finetune the weights for your downstream task:

        ```
        Some weights of UNet2DConditionModel were not initialized from the model checkpoint at stable-diffusion-v1-5/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
        - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
        You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
        ```

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

                    - A string, the *repo id* (for example `CompVis/ldm-text2im-large-256`) of a pretrained pipeline
                      hosted on the Hub.
                    - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
                      saved using
                    [`~DiffusionPipeline.save_pretrained`].
            torch_dtype (`torch.dtype`, *optional*):
                Override the default `torch.dtype` and load the model with another dtype.
            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.
            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.

            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.
            custom_revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id similar to
                `revision` when loading a custom pipeline from the Hub. It can be a 🤗 Diffusers version when loading a
                custom pipeline from GitHub, otherwise it defaults to `"main"` when loading from the Hub.
            mirror (`str`, *optional*):
                Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
                guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
                information.
            device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
                A map that specifies where each submodule should go. It doesn’t need to be defined for each
                parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
                same device.

                Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
                more information about each option see [designing a device
                map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
            max_memory (`Dict`, *optional*):
                A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
                each GPU and the available CPU RAM if unset.
            offload_folder (`str` or `os.PathLike`, *optional*):
                The path to offload weights if device_map contains the value `"disk"`.
            offload_state_dict (`bool`, *optional*):
                If `True`, temporarily offloads the CPU state dict to the hard drive to avoid running out of CPU RAM if
                the weight of the CPU state dict + the biggest shard of the checkpoint does not fit. Defaults to `True`
                when there is some disk offload.
            low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
                Speed up model loading only loading the pretrained weights and not initializing the weights. This also
                tries to not use more than 1x model size in CPU memory (including peak memory) while loading the model.
                Only supported for PyTorch >= 1.9.0. If you are using an older version of PyTorch, setting this
                argument to `True` will raise an error.
            use_safetensors (`bool`, *optional*, defaults to `None`):
                If set to `None`, the safetensors weights are downloaded if they're available **and** if the
                safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
                weights. If set to `False`, safetensors weights are not loaded.
            kwargs (remaining dictionary of keyword arguments, *optional*):
                Can be used to overwrite load and saveable variables (the pipeline components of the specific pipeline
                class). The overwritten components are passed directly to the pipelines `__init__` method. See example
                below for more information.
            variant (`str`, *optional*):
                Load weights from a specified variant filename such as `"fp16"` or `"ema"`. This is ignored when
                loading `from_flax`.

        <Tip>

        To use private or [gated](https://huggingface.co/docs/hub/models-gated#gated-models) models, log-in with `hf
        auth login`.

        </Tip>

        Examples:

        ```py
        >>> from diffusers import AutoPipelineForText2Image

        >>> pipeline = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
        >>> image = pipeline(prompt).images[0]
        ```
        	cache_dirNforce_downloadFproxiestokenlocal_files_onlyrevisionr   r   r   r   r   r   _class_nameControlPipelinePipeline
controlnetControlNetUnionPipelineControlNetPipeline
enable_pagPAGPipeline)popload_config
isinstancer   replacerq   rr   from_pretrained)clspretrained_model_or_pathr   r   r   r   r   r   r   load_config_kwargsconfigorig_class_name
to_replacer   text_2_image_clss                  ry   r   z)AutoPipelineForText2Image.from_pretrained*  sd   d JJ{D1	$4e<**Y-

7D)!::&8%@::j$/ #, 0 
 !!9P=OP //*J#J6!&.0DE"("7"?"?
Le"f"("7"?"?
L`"a6!L1J"1"9"9*m"T*+Lo^1&1&1///0HSFSSr{   c                 P   t        |j                        }|j                  j                  }t	        t
        |      }d|v r|d   Pd|j                  v rdnd}t	        t
        |j                  j                  dd      j                  |d|z               }n*t	        t
        |j                  j                  dd            }d|v rx|j                  d      }|r;t	        t
        |j                  j                  dd      j                  dd            }n*t	        t
        |j                  j                  dd            }|j                  |      \  }}	|j                  d	d      }
|D ci c]  }||v s||j                  |       }}|j                  j                         D ci c]  \  }}||v r||vr||j                  |    }}}|	D ci c]  }||v s||j                  |       }}|j                         D ci c]  \  }}||	v r
||vr|||    }}}|j                         D cg c]&  }|j                  d
      r|dd |	v r|dd |vr|dd ( }}|D ]  }|j                  d
|       ||<    i ||||}|j                         D ci c]&  \  }}||vr|j                  d
      rdnd
 | ||   ( }}}t        |      t        |j                        z
  t        |j                               z
  }t        |      dkD  rOt!        d| d| dt        t#        |j                               t#        |j                               z          d       |di |}|j%                  |
        |j$                  di | |S c c}w c c}}w c c}w c c}}w c c}w c c}}w )a>  
        Instantiates a text-to-image Pytorch diffusion pipeline from another instantiated diffusion pipeline class.

        The from_pipe() method takes care of returning the correct pipeline class instance by finding the text-to-image
        pipeline linked to the pipeline class using pattern matching on pipeline class name.

        All the modules the pipeline contains will be used to initialize the new pipeline without reallocating
        additional memory.

        The pipeline is set in evaluation mode (`model.eval()`) by default.

        Parameters:
            pipeline (`DiffusionPipeline`):
                an instantiated `DiffusionPipeline` object

        ```py
        >>> from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image

        >>> pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
        ...     "stable-diffusion-v1-5/stable-diffusion-v1-5", requires_safety_checker=False
        ... )

        >>> pipe_t2i = AutoPipelineForText2Image.from_pipe(pipe_i2i)
        >>> image = pipe_t2i(prompt).images[0]
        ```
        r   NPAGr   r   
ControlNet r   _name_or_path_r	   r   	Pipeline 
 expected , but only  were passedr    )dictr   r   rs   rq   rr   r   r   _get_signature_keys
componentsr~   keys
startswithset_optional_componentslenr   listregister_to_config)r   r   r   original_configoriginal_cls_namer   r   r   expected_modulesoptional_kwargspretrained_model_name_or_pathkpassed_class_objvoriginal_class_objpassed_pipe_kwargsoriginal_pipe_kwargsadditional_pipe_kwargstext_2_image_kwargsunused_original_configmissing_modulesmodels                         ry   	from_pipez#AutoPipelineForText2Image.from_pipe  sg   : x/$..77 ++LN_`6!l#/.37G7P7P.P]V`
#25$--55lBGOOPZ\hku\uv$ 
 $35$--55lBG$ 
 6!L1J#25$--55eR@HHUbc$ 
 $35$--55eR@$  -=,P,PQa,b)/(7(;(;OT(R% 7GV!v+Avzz!},VV !++113
1$$2B)B x""1%%
 
 9HW11PV;aA.WW (--/ 
1O#1C(C q!! 
  
 %))+"
||C QqrUo%=!AB%OaBa abE"
 "

 ( 	CA&5&9&9AaS'&B #	C w!1v5GvK]vauv
 (--/"
1++ \\#&rC04oa6HH"
 "
  !C(8(M(M$NNQTUhUmUmUoQpp 	 !#,-Z8H7IUXY]^n^s^s^uYvy}  Q  V  V  X  zY  ZY  VZ  U[  [g  h  !7#67  /L M   :#9:_ W
 X 
"
"
s0   %	N/N""N	NN>N++N+N"N
rs   
__module____qualname____doc__config_namer   classmethodr   r   r   r   r{   ry   r   r     sJ     %K
 TT  TTl q qr{   r   c                   D    e Zd ZdZdZd Zeed               Zed        Z	y)AutoPipelineForImage2Imagea;  

    [`AutoPipelineForImage2Image`] is a generic pipeline class that instantiates an image-to-image pipeline class. The
    specific underlying pipeline class is automatically selected from either the
    [`~AutoPipelineForImage2Image.from_pretrained`] or [`~AutoPipelineForImage2Image.from_pipe`] methods.

    This class cannot be instantiated using `__init__()` (throws an error).

    Class attributes:

        - **config_name** (`str`) -- The configuration filename that stores the class and module names of all the
          diffusion pipeline's components.

    r   c                     t        | j                  j                   d| j                  j                   d| j                  j                   d      r   r   r   s      ry   r   z#AutoPipelineForImage2Image.__init__I  r   r{   c                    |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }||||||d	}	 | j                  |fi |	}
|
d
   }d|v rd}n	d|v rd}nd}d|v r>t        |d   t              r|j	                  |d|z         }n|j	                  |d|z         }d|v r(|j                  d      }|r|j	                  |d|z         }|dk(  r|j	                  |d      }t        t        |      }i |	|} |j                  |fi |S )uK  
        Instantiates a image-to-image Pytorch diffusion pipeline from pretrained pipeline weight.

        The from_pretrained() method takes care of returning the correct pipeline class instance by:
            1. Detect the pipeline class of the pretrained_model_or_path based on the _class_name property of its
               config object
            2. Find the image-to-image pipeline linked to the pipeline class using pattern matching on pipeline class
               name.

        If a `controlnet` argument is passed, it will instantiate a [`StableDiffusionControlNetImg2ImgPipeline`]
        object.

        The pipeline is set in evaluation mode (`model.eval()`) by default.

        If you get the error message below, you need to finetune the weights for your downstream task:

        ```
        Some weights of UNet2DConditionModel were not initialized from the model checkpoint at stable-diffusion-v1-5/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
        - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
        You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
        ```

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

                    - A string, the *repo id* (for example `CompVis/ldm-text2im-large-256`) of a pretrained pipeline
                      hosted on the Hub.
                    - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
                      saved using
                    [`~DiffusionPipeline.save_pretrained`].
            torch_dtype (`str` or `torch.dtype`, *optional*):
                Override the default `torch.dtype` and load the model with another dtype.
            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.
            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.

            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.
            custom_revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id similar to
                `revision` when loading a custom pipeline from the Hub. It can be a 🤗 Diffusers version when loading a
                custom pipeline from GitHub, otherwise it defaults to `"main"` when loading from the Hub.
            mirror (`str`, *optional*):
                Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
                guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
                information.
            device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
                A map that specifies where each submodule should go. It doesn’t need to be defined for each
                parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
                same device.

                Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
                more information about each option see [designing a device
                map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
            max_memory (`Dict`, *optional*):
                A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
                each GPU and the available CPU RAM if unset.
            offload_folder (`str` or `os.PathLike`, *optional*):
                The path to offload weights if device_map contains the value `"disk"`.
            offload_state_dict (`bool`, *optional*):
                If `True`, temporarily offloads the CPU state dict to the hard drive to avoid running out of CPU RAM if
                the weight of the CPU state dict + the biggest shard of the checkpoint does not fit. Defaults to `True`
                when there is some disk offload.
            low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
                Speed up model loading only loading the pretrained weights and not initializing the weights. This also
                tries to not use more than 1x model size in CPU memory (including peak memory) while loading the model.
                Only supported for PyTorch >= 1.9.0. If you are using an older version of PyTorch, setting this
                argument to `True` will raise an error.
            use_safetensors (`bool`, *optional*, defaults to `None`):
                If set to `None`, the safetensors weights are downloaded if they're available **and** if the
                safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
                weights. If set to `False`, safetensors weights are not loaded.
            kwargs (remaining dictionary of keyword arguments, *optional*):
                Can be used to overwrite load and saveable variables (the pipeline components of the specific pipeline
                class). The overwritten components are passed directly to the pipelines `__init__` method. See example
                below for more information.
            variant (`str`, *optional*):
                Load weights from a specified variant filename such as `"fp16"` or `"ema"`. This is ignored when
                loading `from_flax`.

        <Tip>

        To use private or [gated](https://huggingface.co/docs/hub/models-gated#gated-models) models, log-in with `hf
        auth login`.

        </Tip>

        Examples:

        ```py
        >>> from diffusers import AutoPipelineForImage2Image

        >>> pipeline = AutoPipelineForImage2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
        >>> image = pipeline(prompt, image).images[0]
        ```
        r   Nr   Fr   r   r   r   r   r   Img2ImgImg2ImgPipeliner   r   r   ControlNetUnionr   r   r   ControlImg2ImgPipeline)r   r   r   r   r   rq   ru   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   image_2_image_clss                  ry   r   z*AutoPipelineForImage2Image.from_pretrainedP  s   f JJ{D1	$4e<**Y-

7D)!::&8%@::j$/ #, 0 
 !!9P=OP / '*J/1*J#J6!&.0DE"1"9"9*FWZdFd"e"1"9"9*lU_F_"`6!L1J"1"9"9*ejFX"Y**-55jBZ[O+,NP_`1&1&10 001ITVTTr{   c                 V   t        |j                        }|j                  j                  }t	        t
        |      }d|v r|d   Sd}d|j                  v rd|z   }t	        t
        |j                  j                  dd      j                  |d|z               }n*t	        t
        |j                  j                  dd            }d|v rx|j                  d      }|r;t	        t
        |j                  j                  dd      j                  dd            }n*t	        t
        |j                  j                  dd            }|j                  |      \  }}	|j                  d	d      }
|D ci c]  }||v s||j                  |       }}|j                  j                         D ci c]  \  }}||v r||vr||j                  |    }}}|	D ci c]  }||v s||j                  |       }}|j                         D ci c]  \  }}||	v r
||vr|||    }}}|j                         D cg c]&  }|j                  d
      r|dd |	v r|dd |vr|dd ( }}|D ]  }|j                  d
|       ||<    i ||||}|j                         D ci c]&  \  }}||vr|j                  d
      rdnd
 | ||   ( }}}t        |      t        |j                        z
  t        |j                               z
  }t        |      dkD  rOt!        d| d| dt        t#        |j                               t#        |j                               z          d       |di |}|j%                  |
        |j$                  di | |S c c}w c c}}w c c}w c c}}w c c}w c c}}w )aZ  
        Instantiates a image-to-image Pytorch diffusion pipeline from another instantiated diffusion pipeline class.

        The from_pipe() method takes care of returning the correct pipeline class instance by finding the
        image-to-image pipeline linked to the pipeline class using pattern matching on pipeline class name.

        All the modules the pipeline contains will be used to initialize the new pipeline without reallocating
        additional memory.

        The pipeline is set in evaluation mode (`model.eval()`) by default.

        Parameters:
            pipeline (`DiffusionPipeline`):
                an instantiated `DiffusionPipeline` object

        Examples:

        ```py
        >>> from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image

        >>> pipe_t2i = AutoPipelineForText2Image.from_pretrained(
        ...     "stable-diffusion-v1-5/stable-diffusion-v1-5", requires_safety_checker=False
        ... )

        >>> pipe_i2i = AutoPipelineForImage2Image.from_pipe(pipe_t2i)
        >>> image = pipe_i2i(prompt, image).images[0]
        ```
        r   Nr   r   r   r   r   PAGImg2ImgPipeliner   r   r	   r   r   r   r   r   r   r   )r   r   r   rs   rq   ru   r   r   r   r   r~   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   image_2_image_kwargsr   r   r   s                         ry   r   z$AutoPipelineForImage2Image.from_pipe  sp   > x/$..77 ,,NPab6!l#/.
-666!&!3J$36%..66|RHPP"L:$=%! %46%..66|RH%!
 6!L1J$36%..66ubAIIJ[]qr%!
 %46%..66ubA%! ->,Q,QRc,d)/(7(;(;OT(R% 7GV!v+Avzz!},VV !++113
1$$2B)B x""1%%
 
 9HW11PV;aA.WW (--/ 
1O#1C(C q!! 
  
 %))+"
||C QqrUo%=!AB%OaBa abE"
 "

 ( 	CA&5&9&9AaS'&B #	C  x"2w6HwL^wbvw
 (--/"
1,, \\#&rC04oa6HH"
 "
  !C(9(N(N$OORUVjVoVoVqRrr 	 !#-.j9I8J+VYZ^_o_t_t_vZwz~  @R  @W  @W  @Y  {Z  [Z  W[  V\  \h  i  "9$89  /L M   :#9:_ W
 X 
"
"
s0   (	N
2N
%"N	NNN.+N +N%Nr   r   r{   ry   r   r   7  sJ     %K
 _U  _UB w wr{   r   c                   D    e Zd ZdZdZd Zeed               Zed        Z	y)AutoPipelineForInpaintinga4  

    [`AutoPipelineForInpainting`] is a generic pipeline class that instantiates an inpainting pipeline class. The
    specific underlying pipeline class is automatically selected from either the
    [`~AutoPipelineForInpainting.from_pretrained`] or [`~AutoPipelineForInpainting.from_pipe`] methods.

    This class cannot be instantiated using `__init__()` (throws an error).

    Class attributes:

        - **config_name** (`str`) -- The configuration filename that stores the class and module names of all the
          diffusion pipeline's components.

    r   c                     t        | j                  j                   d| j                  j                   d| j                  j                   d      r   r   r   s      ry   r   z"AutoPipelineForInpainting.__init__  r   r{   c                    |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }||||||d	}	 | j                  |fi |	}
|
d
   }d|v rd}n	d|v rd}nd}d|v r>t        |d   t              r|j	                  |d|z         }n|j	                  |d|z         }d|v r(|j                  d      }|r|j	                  |d|z         }|dk(  r|j	                  |d      }t        t        |      }i |	|} |j                  |fi |S )uT  
        Instantiates a inpainting Pytorch diffusion pipeline from pretrained pipeline weight.

        The from_pretrained() method takes care of returning the correct pipeline class instance by:
            1. Detect the pipeline class of the pretrained_model_or_path based on the _class_name property of its
               config object
            2. Find the inpainting pipeline linked to the pipeline class using pattern matching on pipeline class name.

        If a `controlnet` argument is passed, it will instantiate a [`StableDiffusionControlNetInpaintPipeline`]
        object.

        The pipeline is set in evaluation mode (`model.eval()`) by default.

        If you get the error message below, you need to finetune the weights for your downstream task:

        ```
        Some weights of UNet2DConditionModel were not initialized from the model checkpoint at stable-diffusion-v1-5/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
        - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
        You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
        ```

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

                    - A string, the *repo id* (for example `CompVis/ldm-text2im-large-256`) of a pretrained pipeline
                      hosted on the Hub.
                    - A path to a *directory* (for example `./my_pipeline_directory/`) containing pipeline weights
                      saved using
                    [`~DiffusionPipeline.save_pretrained`].
            torch_dtype (`str` or `torch.dtype`, *optional*):
                Override the default `torch.dtype` and load the model with another dtype.
            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.
            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.

            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.
            custom_revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id similar to
                `revision` when loading a custom pipeline from the Hub. It can be a 🤗 Diffusers version when loading a
                custom pipeline from GitHub, otherwise it defaults to `"main"` when loading from the Hub.
            mirror (`str`, *optional*):
                Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
                guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
                information.
            device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
                A map that specifies where each submodule should go. It doesn’t need to be defined for each
                parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
                same device.

                Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
                more information about each option see [designing a device
                map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
            max_memory (`Dict`, *optional*):
                A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
                each GPU and the available CPU RAM if unset.
            offload_folder (`str` or `os.PathLike`, *optional*):
                The path to offload weights if device_map contains the value `"disk"`.
            offload_state_dict (`bool`, *optional*):
                If `True`, temporarily offloads the CPU state dict to the hard drive to avoid running out of CPU RAM if
                the weight of the CPU state dict + the biggest shard of the checkpoint does not fit. Defaults to `True`
                when there is some disk offload.
            low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
                Speed up model loading only loading the pretrained weights and not initializing the weights. This also
                tries to not use more than 1x model size in CPU memory (including peak memory) while loading the model.
                Only supported for PyTorch >= 1.9.0. If you are using an older version of PyTorch, setting this
                argument to `True` will raise an error.
            use_safetensors (`bool`, *optional*, defaults to `None`):
                If set to `None`, the safetensors weights are downloaded if they're available **and** if the
                safetensors library is installed. If set to `True`, the model is forcibly loaded from safetensors
                weights. If set to `False`, safetensors weights are not loaded.
            kwargs (remaining dictionary of keyword arguments, *optional*):
                Can be used to overwrite load and saveable variables (the pipeline components of the specific pipeline
                class). The overwritten components are passed directly to the pipelines `__init__` method. See example
                below for more information.
            variant (`str`, *optional*):
                Load weights from a specified variant filename such as `"fp16"` or `"ema"`. This is ignored when
                loading `from_flax`.

        <Tip>

        To use private or [gated](https://huggingface.co/docs/hub/models-gated#gated-models) models, log-in with `hf
        auth login`.

        </Tip>

        Examples:

        ```py
        >>> from diffusers import AutoPipelineForInpainting

        >>> pipeline = AutoPipelineForInpainting.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
        >>> image = pipeline(prompt, image=init_image, mask_image=mask_image).images[0]
        ```
        r   Nr   Fr   r   r   r   r   r   InpaintInpaintPipeliner   r   r   r   r   r   r   ControlInpaintPipeline)r   r   r   r   r   rq   rw   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   inpainting_clss                  ry   r   z)AutoPipelineForInpainting.from_pretrained  s   d JJ{D1	$4e<**Y-

7D)!::&8%@::j$/ #, 0 
 !!9P=OP / '*J/1*J#J6!&.0DE"1"9"9*FWZdFd"e"1"9"9*lU_F_"`6!L1J"1"9"9*ejFX"Y**-55jBZ[O()GY1&1&1-~--.FQ&QQr{   c                 &   t        |j                        }|j                  j                  }t	        t
        |      }d|v rj|d   ;t	        t
        |j                  j                  dd      j                  dd            }n*t	        t
        |j                  j                  dd            }d|v rx|j                  d      }|r;t	        t
        |j                  j                  dd      j                  dd	            }n*t	        t
        |j                  j                  d	d            }|j                  |      \  }}|j                  d
d      }	|D 
ci c]  }
|
|v s|
|j                  |
       }}
|j                  j                         D 
ci c]  \  }
}|
|v r|
|vr|
|j                  |
    }}
}|D 
ci c]  }
|
|v s|
|j                  |
       }}
|j                         D 
ci c]  \  }
}|
|v r
|
|vr|
||
    }}
}|j                         D 
cg c]&  }
|
j                  d      r|
dd |v r|
dd |vr|
dd ( }}
|D ]  }
|j                  d|
       ||
<    i ||||}|j                         D 
ci c]&  \  }
}|
|vr|
j                  d      rdnd |
 ||
   ( }}
}t        |      t        |j                        z
  t        |j                               z
  }t        |      dkD  rOt!        d| d| dt        t#        |j                               t#        |j                               z          d       |di |}|j%                  |	        |j$                  di | |S c c}
w c c}}
w c c}
w c c}}
w c c}
w c c}}
w )aj  
        Instantiates a inpainting Pytorch diffusion pipeline from another instantiated diffusion pipeline class.

        The from_pipe() method takes care of returning the correct pipeline class instance by finding the inpainting
        pipeline linked to the pipeline class using pattern matching on pipeline class name.

        All the modules the pipeline class contain will be used to initialize the new pipeline without reallocating
        additional memory.

        The pipeline is set in evaluation mode (`model.eval()`) by default.

        Parameters:
            pipeline (`DiffusionPipeline`):
                an instantiated `DiffusionPipeline` object

        Examples:

        ```py
        >>> from diffusers import AutoPipelineForText2Image, AutoPipelineForInpainting

        >>> pipe_t2i = AutoPipelineForText2Image.from_pretrained(
        ...     "DeepFloyd/IF-I-XL-v1.0", requires_safety_checker=False
        ... )

        >>> pipe_inpaint = AutoPipelineForInpainting.from_pipe(pipe_t2i)
        >>> image = pipe_inpaint(prompt, image=init_image, mask_image=mask_image).images[0]
        ```
        r   Nr   r   r   ControlNetInpaintPipeliner   r   PAGInpaintPipeliner   r   r	   r   r   r   r   r   r   r   )r   r   r   rs   rq   rw   r   r   r   r   r~   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   inpainting_kwargsr   r   r   s                        ry   r   z#AutoPipelineForInpainting.from_pipe'  sI   < x/$..77 ))GIZ[6!l#/!02"++33L"EMM)+F" "12"++334OQbc"
 6!L1J!02"++33E2>FFGXZno"
 "12"++334HJ[\" -;,N,N~,^)/(7(;(;OT(R% 7GV!v+Avzz!},VV !++113
1$$2B)B x""1%%
 
 9HW11PV;aA.WW (--/ 
1O#1C(C q!! 
  
 %))+"
||C QqrUo%=!AB%OaBa abE"
 "

 ( 	CA&5&9&9AaS'&B #	C u/t3EtI[t_st
 (--/"
1)) \\#&rC04oa6HH"
 "
  !C(K(K$LLsSdSiSiSkOll 	 !#N+:6F5G{SVW[\l\q\q\sWtw{  }O  }T  }T  }V  xW  XW  TX  SY  Ye  f  3!23  /L M   :#9:_ W
 X 
"
"
s0   	M2M2"M76	M= M=)N+N>+NNr   r   r{   ry   r   r   n  sJ     %K
 \R  \R| s sr{   r   N)T)collectionsr   huggingface_hub.utilsr   configuration_utilsr   models.controlnetsr   utilsr   	aura_flowr
   rf   r   rg   r   rh   r   r   r   r   r   r   r   r   r   r   r   r   controlnet_sd3r   r   deepfloyd_ifr   r   r   rc   r   r   r   r    r!   r"   r#   r$   r%   r&   
hunyuanditr'   r[   r(   r)   r*   r+   r,   r-   kandinsky2_2r.   r/   r0   r1   r2   r3   r]   r4   r5   latent_consistency_modelsr6   r7   rd   r8   re   r9   pagr:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   pixart_alpharI   rJ   ra   rK   stable_cascaderL   rM   stable_diffusionrN   rO   rP   stable_diffusion_3rQ   rR   rS   stable_diffusion_xlrT   rU   rV   r^   rW   rX   rr   ru   rw   ro   rt   rv   rl   ri   rj   rk   r}   rz   r   boolrq   r   r   r   r   r{   ry   <module>r
     s    $ 6 - 5 . ' " * ?
 
 
 N M   +   F l " $    " C  W 
 
 
 N %0&	45&	 9:& 
78& 
"#>?	&
 
z& 
&'& 
-.& 
/0& 
45& 
)*& 
'(IJ& 
*+NO& 
01YZ& 
)*LM& 
12&  
12!&" 
./#&$ 
,-%&& 
,-'&( 
)&* 
_%+&, 
 !;<-&. 
+,PQ/&0 
#$@A1&2 
./UV3&4 
345&6 
%&7&8 
9&: 
,-;&< 
23=&> 
,-?&@ 
>"A&B 
O$C&D 
>"E&F 
)*G&H 
%&I&J 
45K&(% !T &1	;<	 @A	>?	!#EF	 !	67	;<	01	&(PQ	!BC	)+UV	/1`a	"$GH	-/\]	56	$%	9:	34	,-'& "0 "-	;<	 @A	>?	#$	67	;<	&(PQ	*,WX	)+UV	/1`a	(*VW	"$GH	$%	9:	34	!BC!" * .9	'(	,-	01	01	. * /:	./	34/ + +6	./	34+ ' =&2@%h/6G%l33H&x0 &&"./+ v"	qD 	qc cL	t tn	m mr{   