
    +hi              0       R   S SK r S SKrS SKrS SKrS SKJr  S SKJrJrJ	r	J
r
JrJr  S SKrS SKrS SKJrJrJrJr  S SKJrJr  S SKJr  S SKJr  SS	KJr  SS
KJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)  SSK*J+r+  SSK,J-r-J.r.  \'" 5       (       a,  S SK/r/S SK/J0r0J1r1  S SK2J3r4  S SK2J"r5  \(" SS5      (       a  S SK2Jr6  \%" 5       (       a  S SK7r7S SK7J8r8  S SK9J:r:  S SK;J<r<J=r=  Sr>Sr?Sr@SrAS/rB\)R                  " \D5      rESS/SS/SS/SS/S.SS/SS/SS/SS/SS/SS/S.S SS/0S!.rF0 rG\F H  rH\GR                  \F\H   5        M     SpS"\J4S# jjrKS$ rLS% rMSqS"\\
\R                     \O4   4S& jjrP\S' 5       rQS( rRS) rSS* rT SqS+ jrU     SrS, jrV        SsS- jrWS.\OS/\OS0\
\   S1\S2\JS3\OS4\\O\R                  4   S5\\O\R                  4   4S6 jrY StS7\	\O\Z4   S8\	\O\Z4   S9\O4S: jjr[S; r\ SuS.\OS/\OS0\
\   S1\S2\JS<\S4\R                  S=\S>\S?\\\	\O\R                  4   \O4      S@\\	\\^\O4   \\^\O4   4      SA\\\O\R                  4      SB\JSC\	\O\O4   S3\OSD\JSE\OSF\JS5\\O\R                  4   SG\JSH\\	\O\4      SI\SJ\\   4.SK jjr_SL\`SM\OSN\JS"\4SO jraSP rbSQ\OSE\OSR\cS"\c4SS jrdST reSU\OSR\c4SV jrfSW\cSX\cSY\cSQ\OS"\c4
SZ jrg   SpS[\OS\\	\O\4   S]\\
\O      S^\\
\O      SE\\O   4
S_ jjrh SuS`\
\O   Sa\
\O   SG\JSD\JSb\JSc\JSd\JSE\\O   S"\
\O   4Se jjriS[\OSf\OSg\OSh\OSi\OSj\JSk\OSl\O4Sm jrjSn rkSo rlg)v    N)Path)AnyCallableDictListOptionalUnion)	DDUFEntry	ModelCard
model_infosnapshot_download)OfflineModeIsEnabledvalidate_hf_hub_args)version)	HTTPError   )__version__)FLAX_WEIGHTS_NAMEONNX_EXTERNAL_WEIGHTS_NAMEONNX_WEIGHTS_NAMESAFETENSORS_WEIGHTS_NAMEWEIGHTS_NAME	deprecateget_class_from_dynamic_moduleis_accelerate_availableis_peft_availableis_transformers_availableis_transformers_versionlogging)is_compiled_module   )_load_tokenizer_from_dduf"_load_transformers_model_from_dduf)PreTrainedModelPreTrainedTokenizerBase)SAFE_WEIGHTS_NAME)r   <=4.56.2)r   )dispatch_model)remove_hook_from_module)compute_module_sizesget_max_memoryzdiffusion_pytorch_model.binzpipeline.pyzdiffusers.utilsztransformers.utilspriorsave_pretrainedfrom_pretrained)
ModelMixinSchedulerMixinDiffusionPipelineOnnxRuntimeModel)PreTrainedTokenizerPreTrainedTokenizerFastr$   FeatureExtractionMixinProcessorMixinImageProcessingMixin	ORTModule)	diffuserstransformerszonnxruntime.trainingreturnc                    [         [        [        [        [        /n[        5       (       a*  U[        [        /-  n[        SS5      (       a
  U[        /-  nU Vs/ s H  oUR                  S5      S   PM     nnU Vs/ s H  oUR                  S5      S   PM     nnSn[        R                  " SSR                  U5       S	U SU S
U S	SR                  U5       S35      n	[        R                  " SSR                  U5       SU SSR                  U5       S35      n
U=(       d    / nU(       a:  U  Vs1 s H-  n[        R                  R                  U5      S   U;   d  M+  UiM/     n n0 nU  Hb  n[!        UR                  S5      5      S:X  d  M#  UR                  S5      u  pX;   a  M=  UR#                  U/ 5        X   R%                  U5        Md     ['        5       nU(       d2  Ub  [)        X	5      nU(       d  [)        X
5      n[+        S U 5       5      $ UR-                  5        H  u  nn/ n['        5       nUb  [)        UU	5      nU(       d  [)        UU
5      nU H;  n[        R                  R/                  U5      u  nnUS:H  nUR%                  U5        M=     [+        U5      (       a  M    g   gs  snf s  snf s  snf )a  
Checking for safetensors compatibility:
- The model is safetensors compatible only if there is a safetensors file for each model component present in
  filenames.

Converting default pytorch serialized filenames to safetensors serialized filenames:
- For models from the diffusers library, just replace the ".bin" extension with ".safetensors"
- For models from the transformers library, the filename changes from "pytorch_model" to "model", and the ".bin"
  extension is replaced with ".safetensors"
r'   r(   .r   \d{5}-of-\d{5}(|)\.(-)$)(-)?\.(/r   c              3   ,   #    U  H
  nS U;   v   M     g7f).safetensorsN ).0filenames     d/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/pipeline_loading_utils.py	<genexpr>,is_safetensors_compatible.<locals>.<genexpr>   s     Q>P(>X->Ps   rJ   FT)r   r   r   r   r   r   TRANSFORMERS_WEIGHTS_NAMETRANSFORMERS_SAFE_WEIGHTS_NAMEr   TRANSFORMERS_FLAX_WEIGHTS_NAMEsplitrecompilejoinospathlen
setdefaultappendsetfilter_with_regexanyitemssplitext)	filenamespassed_componentsfolder_namesvariantweight_nameswweight_prefixesweight_suffixstransformers_index_formatvariant_file_renon_variant_file_ref
componentsrM   	componentcomponent_filenamefiltered_filenamescomponent_filenamesmatchesfiltered_component_filenames	extensionmatch_existss                         rN   is_safetensors_compatiblerw   a   s    	 "L !""24RSS"422;<<L 1==1wws|AO=0<=1ggcl2&N= 1jjSXXo&'tG9AgYa@Y?ZZ^_b_g_ghv_w^xxz{O **SXXo&'s+D*EU388TbKcJddfg */R )Q	1RWW]]1-=a-@L-PQ		Q J8>>#&'1,(0s(;%	)i,$$%78  !29!N "!29!RQ>PQQQ +5*:*:*<&	&'*u$+<=PRa+b( ,+<=PRe+f(">"$''"2"23E"FHi$6LNN<(	 #? 7||# +=& } >= Rs   J4<J95*J>#J>c                 f  ^ [         [        [        [        [        /n[        5       (       a*  U[        [        /-  n[        SS5      (       a
  U[        /-  nU Vs/ s H  o"R                  S5      S   PM     nnU  V^s/ s H!  m[        U4S jU 5       5      (       d  M  TPM#     sn$ s  snf s  snf )zIFilter model repo files for just files/folders that contain model weightsr'   r(   r>   r?   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fN)endswith)rL   ru   rm   s     rN   rO   %filter_model_files.<locals>.<genexpr>   s     'bOa)

9(=(=Oas   !)r   r   r   r   r   r   rQ   rR   r   rS   rT   r_   )rb   rf   wnallowed_extensionsrm   s       `rN   filter_model_filesr      s     	 "L !""24RSS"422;<<L6BCl((3-+lC cy!C'bOa'b$bAycc Dcs   B)>B. B.c                 |    U  Vs1 s H*  o!R                  UR                  S5      S   5      c  M(  UiM,     sn$ s  snf )NrH   r?   )matchrT   )rb   
pattern_rerm   s      rN   r^   r^      s2     Sy!$4$4QWWS\"5E$FAySSSs   '99c                    [         [        [        [        [        /n[        5       (       a*  U[        [        /-  n[        SS5      (       a
  U[        /-  nU Vs/ s H  oDR                  S5      S   PM     nnU Vs/ s H  oDR                  S5      S   PM     nnSnUb  [        R                  " SSR                  U5       S	U SU S
U S	SR                  U5       S35      n[        R                  " SSR                  U5       S	SR                  U5       SU S35      n	[        R                  " SU SU S35      n
[        R                  " SSR                  U5       S	SR                  U5       SU S35      n[        R                  " SSR                  U5       SU SSR                  U5       S35      n[        R                  " SSR                  U5       S	SR                  U5       S35      nS$S jn0 nU  Hy  n[        UR                  S5      5      S:X  d#  UR                  S/ 5      R!                  U5        MD  UR                  S5      u  nnUR                  U/ 5      R!                  U5        M{     [#        5       n[#        5       nUR%                  5        H  u  nnU" UUS9n[#        5       n[#        5       n[#        5       nUb0  ['        UW5      n['        UW	5      n['        UW
5      n['        UW5      nU(       d  U(       a"  UR)                  U(       a  UW-  OUW-  5        M  ['        UU5      n['        UU5      nUR)                  UU-  5        M     UR)                  U5        [        U5      S:X  a  Ub  SU S3n[+        U5      e[        U5      S:  aO  UU:w  aI  [,        R/                  SU SU SU S S!R                  U5       S"U S S!R                  UU-
  5       S#35        UU4$ s  snf s  snf )%Nr'   r(   r>   r   r?   r@   rA   rB   rC   rD   rE   z
)\.index\.z\.json$z.*-z\.z	\.[a-z]+$z)\.z\.index\.json$rF   rG   z)\.index\.jsonc                    ^ U(       d  U $ U  V^s1 s H!  m[        U4S jU 5       5      (       a  M  TiM#     sn$ s  snf )Nc              3   d   >#    U  H%  nTR                  UR                  S 5      5      v   M'     g7f)z*.N)r{   lstrip)rL   patrm   s     rN   rO   Xvariant_compatible_siblings.<locals>.filter_for_compatible_extensions.<locals>.<genexpr>  s)     /hXgQT

3::d;K0L0LXgs   -0)r_   )rb   ignore_patternsrm   s     `rN    filter_for_compatible_extensionsEvariant_compatible_siblings.<locals>.filter_for_compatible_extensions   s4     %i9aC/hXg/h,h9iiis   ;;rH   r    )r   z3You are trying to load model files of the `variant=z-`, but no such modeling files are available. z
A mixture of z	 and non-z" filenames will be loaded.
Loaded z filenames:
[, z]
Loaded non-zF
If this behavior is not expected, please check your folder structure.rz   )r   r   r   r   r   r   rQ   rR   r   rS   rT   rU   rV   rW   rZ   r[   r\   r]   r`   r^   update
ValueErrorloggerwarning)rb   re   r   rf   rg   rh   ri   rj   rk   variant_index_relegacy_variant_file_relegacy_variant_index_rerl   non_variant_index_rer   rn   rM   ro   _usable_filenamesvariant_filenamesrr   component_variantscomponent_legacy_variantscomponent_non_variantscomponent_variant_index_files$component_legacy_variant_index_fileserror_messages                               rN   variant_compatible_siblingsr      sB    "L !""24RSS"422;<<L 1==1wws|AO=0<=1ggcl2&N= 1**/*+4y'!D]C^^bcfckcklzc{b||~
 ::/*+40H/IT[S\\cd
 "$s3L2MRPWyXa,b!c"$**/*+40H/IWIUcd#

 **SXXo&'s+D*EU388TbKcJddfg ::388O+D*ET#((SaJbIccq&rsj J8>>#&'1,!!"b)00:~~c*	1i,33H=  u*4*:*:*<&	&>?Rdst U$'E!!$!23F!X,=>QSc,d)(9:MOe(f%3DEXZq3r0!:$$% #%BB.1UU &77JL_%`",=>QSg,h)##$:=Z$Z[1 +=4 -.
"w':MgY  WD  E''
!&6:K&KgYiy8[\c[d e		+,-^G9 E		*->>?@ A<=	
 ...o >=s   O4<O9c                 .   [        U US S9nUR                   Vs1 s H  ofR                  iM     nn[        XsS9u  pU V
s/ s H;  n
SR	                  U
R                  S5      S S U
R                  S5      SS  -   5      PM=     nn
[        U5      R                  [        U5      5      (       a/  [        R                  " SU SU  SU S	U S
U SU S3[        5        g [        R                  " SU SU  SU SU SU  SU  SU S3[        5        g s  snf s  sn
f )Ntokenrevision)re   r>   r!   r   zYou are loading the variant z from z via `revision='z-'` even though you can load it via `variant=`z)`. Loading model variants via `revision='zK'` is deprecated and will be removed in diffusers v1. Please use `variant='z'` instead.z^'`. This behavior is deprecated and will be removed in diffusers v1. One should use `variant='z%'` instead. However, it appears that z currently does not have the required variant filenames in the 'main' branch. 
 The Diffusers team and community would be very grateful if you could open an issue: https://github.com/huggingface/diffusers/issues/new with the title 'z is missing z6 files' so that the correct variant file can be added.)r   siblings	rfilenamer   rW   rT   r]   issubsetwarningswarnFutureWarning)pretrained_model_name_or_pathr   re   r   model_filenamesinfosiblingrb   comp_model_filenamesr   rm   s              rN   warn_deprecated_model_variantr   <  s   %D
 37--@-w""-I@9)VSghSgaCHHQWWS\"1%5QR8H%HISgh
?$$S)=%>??*8*F;X:YYijris  ta  bj  ak  kT  U]  T^  ^i  jr  is  s~  	

 	*8*F;X:YYijris  tR  S[  R\  \A  B_  A`  `I  Jg  Ih  ht  u}  t~  ~t	  u		
 Ahs   D ADc                     [        U 5      (       a  U R                  n [        5       (       a,  SSKJn  [        X5      (       a  U R                  R                  n U $ )zUnwraps a model.r   )	PeftModel)r    	_orig_modr   peftr   
isinstance
base_modelmodel)r   r   s     rN   _unwrap_modelr   S  sC    %  "e''$$**EL    c           	         U(       d  [         R                  " U 5      n[        X5      nUR                  5        Vs0 s H  o[        XS5      _M     n	nSn
U	R	                  5        H  u  p+Uc  M
  [        X{5      (       d  M  Un
M      XE   n[        U5      nUR                  n[        X5      (       d  [        XE    SU SU
 35      eg[        R                  SXE    S35        gs  snf )zNSimple helper method to raise or warn in case incorrect module has been passedNz is of type: z, but should be z&You have passed a non-standard module z2. We cannot verify whether it has the correct type)	importlibimport_modulegetattrkeysr`   
issubclassr   	__class__r   r   r   )library_namelibrary
class_nameimportable_classespassed_class_objnameis_pipeline_module	class_objcclass_candidatesexpected_class_objclass_candidate	sub_modelunwrapped_sub_model	model_clss                  rN   maybe_raise_or_warnr   a  s     )),7G0	BTBYBYB[\B[Qww488B[\!+;+A+A+C'J*z)/U/U%4" ,D %*	+I6'11	)88 0 67}YKO_`r_stuu 9 	45E5K4L M$ $	
! ]s   C$c                     SSK Jn  [        X 5      nU(       a  [        X 5      n[        XA5      nU$ [        R
                  " U 5      n[        Xa5      nU$ )Nr   	pipelines)r:   r   hasattrr   r   r   )r   r   r   r   pipeline_moduler   r   s          rN   simple_get_class_objr     sQ    # 9!):O8	
  )),7G0	r   c           	         U(       a&  U(       a  [         R                  R                  Xe5      OSnU(       a=  [        X05      n[        X5      n	[        R                  UR                  5       U	5      n
X4$ U(       ax  [         R                  R                  [         R                  R                  XpS-   5      5      (       a4  [        XpS-   US9n	[        R                  UR                  5       U	5      n
X4$ [        R                  " U 5      n[        X5      n	UR                  5        Vs0 s H  o[        XS5      _M     n
nX4$ s  snf )zaSimple helper method to retrieve class object of module as well as potential parent class objectsN.py)module_filer   )rX   rY   rW   r   dictfromkeysr   isfiler   r   r   )r   r   r   r   r   component_name	cache_dircomponent_folderr   r   r   r   r   s                rN   get_class_obj_and_candidatesr     s    CQU^rww||I>dh!):O8	==);)@)@)BIN && 
bggnnRWW\\:J[`L`-abb1*>:
	  ==);)@)@)BIN && )),7G0	BTBYBYB[\B[Qww488B[\&& ]s   &Ec                     U R                  S5      (       a2  [        U 5      nUR                  nUR                  R	                  5       n OUb  U  S3nUn O[
        nUb  Ub  Un[        U UUUUS9$ )Nr   )r   r   r   r   )r{   r   r   parentabsoluteCUSTOM_PIPELINE_FILE_NAMEr   )custom_pipelinerepo_idhub_revisionr   r   r   rY   	file_names           rN   _get_custom_pipeline_classr     s     &&O$II	++..0		&'s+	!-	|7  ( r   c	           	      f   Ub  [        UUUUUUS9$ U R                  S:w  a  U R                  S:w  a  U $ [        R                  " U R                  R                  S5      S   5      n	U=(       d    US   nU(       d  [        S5      eUR                  S5      (       a  US	S  OUn[        X5      n
U(       a|  S
SK	J
n  U" U
5      nUb1  [        R                  SUR                   SU
R                   S35        O/[        R                  U
R                   SU
R                   S35        U=(       d    U
n
U
$ )N)r   r   r   r   r   r2   ModularPipeliner>   r   _class_namezoThe class name could not be found in the configuration file. Please make sure to pass the correct `class_name`.Flax   r!   )_get_connected_pipelinezLoading connected pipeline z instead of z0 as specified via `load_connected_pipeline=True`z* has no connected pipeline class. Loading )r   __name__r   r   
__module__rT   r   
startswithr   auto_pipeliner   r   r   )r   configload_connected_pipeliner   r   r   r   r   r   diffusers_modulepipeline_clsr   connected_pipeline_clss                rN   _get_pipeline_classr     sJ    ")%!
 	
 00Y5G5GK\5\ ..y/C/C/I/I#/Nq/QR4vm4J}
 	
 $.#8#8#@#@ABjJ+8L:!8!F!-KK-.D.M.M-Nl[g[p[pZq  rb  c KK<0011[\h\q\q[rrstu-=r   r   r   r   r   r   r   torch_dtypecached_folderc                 \   [        U UUUUUUS9u  p[        5       (       aC  [        R                  " [        R                  " [        R
                  5      R                  5      nOSn[        5       =(       a0    [        U	[        5      =(       a    U[        R                  " S5      :  n[        R                  " [        R                  S5      S   5      n[        XR                  5      nS nUn[
        SSS.nU(       a  U	R                  [        R                   R#                  UU5      US	S	UR%                  S
S5      UR%                  SS 5      UR%                  SS5      UR%                  SS 5      UR%                  SS 5      UR%                  SS 5      US9u  nnn[&        R(                  " 5          U	R*                  " U40 UD6nS S S 5        OU(       a  [-        U	SS 5      nUc  [/        S5      eUR1                  UUUR%                  S
S5      UR%                  SS 5      UR%                  SS5      UR%                  SS 5      UR%                  SS 5      US9n[&        R(                  " 5          U	" U5      nS S S 5        Ub  UR3                  US9nU$ ! , (       d  f       N"= f! , (       d  f       N3= f)Nr   r   N/A4.20.0r>   r   r   pytorch)r:   	file_type	frameworkTforce_downloadFproxieslocal_files_onlyr   r   	subfolder)
r   return_unused_kwargsreturn_commit_hashr  r  r  r   r   r  
user_agentconfig_classz=`config_class` cannot be None. Please double-check the model.)r  r  r  r  r   r   r  dtype)r   r   r   parser;   r   base_versionr   r$   r   r   r   rT   r0   load_configrX   rY   rW   pop
accelerateinit_empty_weightsfrom_configr   r   r/   to)r   r   r   r   r   r   r   r   kwargsr   r   transformers_versionis_transformers_modelr   is_diffusers_modelr   config_pathr  r   unused_kwargscommit_hashr	  s                         rN   _load_empty_modelr    sn    0LI !""&}}W]]<;S;S-T-a-ab$ 	"# 	<y/2	< GMM($;; 
 !..x~~c/B1/EF#I/J/JKEK J -6-B-BGGLLd+#!%#!::&6>JJy$/#ZZ(:EB**Wd+ZZ
D1jjd3! .C .
*{ **,))&BMBE -,	y.$?\]]--!::&6>JJy$/#ZZ(:EB**Wd+ZZ
D1! . 	
 **,f%E - {+L- -," -,s   -J'	J
J
J+module_sizesdevice_memorydevice_mapping_strategyc                 .   [        UR                  5       5      nX3S S S2   -   nUR                  5       n0 nSnU  HW  nXF[        U5      -     nX   n	X   n
X:  a  U/US'   M(  X;  a  U/XX'   OXX   R	                  U5        X==   U	-  ss'   US-  nMY     U$ )Nr?   r   cpur!   )listr   copyrZ   r\   )r  r  r  
device_idsdevice_cycledevice_id_component_mappingcurrent_device_indexro   	device_idcomponent_memorycurr_device_memorys              rN   _assign_components_to_devicesr*  Q  s     m((*+J4R4 00L!&&(M"$!	 L8I!IJ	'2*5 02;'.;:C+6+6==iH $(88$ A% ! "$ '&r   c                    U S:w  a  U $ SSK Jn  UR                  S[        R                  5      n0 n	UR                  5        GH<  u  n
u  pUR                  S5      (       a  [        S5      e[        X{5      n[        nS nX;   a4  [        UUUUUU
U5        [        R                  " 5          X*   nS S S 5        O[        U[        5      (       a/  UR                  XR                  S[        R                  5      5      OUn[        UUUUUUU
UUR                  SS 5      UR                  S	S 5      UR                  S
S 5      UR                  SS 5      UR                  SS 5      UR                  SS 5      S9nUc  GM8  XU
'   GM?     U	R                  5        VVs0 s H  u  nn[        U[        R                   R"                  5      (       d  M1  U[%        U[        U[        5      (       a0  UR                  UUR                  S[        R                  5      5      OUS9S   _M     nnn[        ['        UR                  5       S SS95      n[)        U5      n[        ['        UR                  5       S SS95      nUR                  5        VVs0 s H  u  nnUS:w  d  M  UU_M     nnnS n[+        U5      S:  a4  [-        UXPS9n0 nUR                  5        H  u  nnU H  nUUU'   M
     M     U$ ! , (       d  f       GN= fs  snnf s  snnf )Nbalancedr   r   r   r   z3Flax pipelines are not supported with `device_map`.defaultr   r  r  r  r   r   )r   r   r   r   r   pipeline_classr   r   r   r  r  r  r   r   r
  r   c                     U S   $ Nr!   rK   items    rN   <lambda>'_get_final_device_map.<locals>.<lambda>  s    d1gr   T)keyreversec                     U S   $ r0  rK   r1  s    rN   r3  r4    s    $q'r   r   )r  )r:   r   gettorchfloat32r`   r   r   r   ALL_IMPORTABLE_CLASSESr   r  r  r   r   r  nnModuler+   sortedr,   rZ   r*  )
device_mapr.  r   	init_dictr   
max_memoryr  r   r   init_empty_modulesr   r   r   r   r   loaded_sub_modelsub_model_dtypemodule_namemoduler  kvfinal_device_mapr%  r'  rn   ro   s                              rN   _get_final_device_maprJ  o  s   Z#**]EMM:K ,5OO,=((|  ((RSS %Y=3 #  " " ..0#3#9  10 k400 ooi&OP  
  1)%#5##5-+$jj$?%zz*:DA

9d3!',>!Ejj$/J5 " ''7t$c ->z $6#;#;#=	 $>Kfehhoo.	)+t,, //+{y%--/XY	

  	 $>  	 |1139MW[\]L  
+JfZ--/5ISWXYJ#-#3#3#5D#541ae$!Q$#5JD 
:&C*'
#
 %@%F%F%H!Iz'	.7 + ( &I  10@	 Es%   )K)0K;	AK;LL)
K8	r.  providersess_optionsr?  rA  offload_folderoffload_state_dictmodel_variants	from_flaxre   low_cpu_mem_usageuse_safetensorsdduf_entriesprovider_optionsquantization_configc           
      x   SSK Jn  [        U UUUUUUS9u  nnSnUR                  5        H%  u  nnUc  M  [	        UU5      (       d  M  X!   S   nM'     Ucj  UR
                  nUR                  [        5      =(       d    UR                  [        5      nU(       a  SU;   a  U" 5         [        SU SU S	[         S
35      e[        UUUSLS9n[        R                  " [        R                  S
5      S   5      n0 n [	        U[         R"                  R$                  5      (       a  UU S'   [	        UUR&                  5      (       a  UU S'   UU S'   UU S'   [	        UUR(                  5      n![+        5       (       aC  [,        R.                  " [,        R.                  " [0        R2                  5      R4                  5      n"OSn"[+        5       =(       a0    [	        U[6        5      =(       a    U"[,        R.                  " S5      :  n#U!(       d  U#(       a  U	U S'   U
U S'   UU S'   UU S'   UR9                  US5      U S'   UU S'   U(       a  SU S'   U#(       a/  U S   b)  U"[,        R.                  " S5      :  a  [;        SU S35      eU#(       a  U S   c  U R9                  S5        U(       a  U#(       d  UU S'   OSU S'   U#(       a"  [=        S S!5      (       a  U R9                  S5        UbR  [?        UU5      (       aA  [	        U[         R"                  R$                  5      (       a  URA                  U!US"9n$U$b  U$U S#'   U(       a  UU S$'   U" U40 U D6n%Os[B        RD                  RG                  [B        RD                  RI                  UU5      5      (       a(  U" [B        RD                  RI                  UU5      40 U D6n%O	U" U40 U D6n%[?        U%[         R"                  R$                  5      (       aV  [?        U	[J        5      (       aA  [M        U%SS%9  U	S&   S':H  n&U&(       a  [O        U%U%RQ                  5       U	SSS(9  U%$ [O        U%U	SS)9  U%$ )*zLHelper method to load the module `name` from `library_name` and `class_name`r   )PipelineQuantizationConfigr   Nr!   dummyzThe component z of zT cannot be loaded as it does not seem to have any of the loading methods defined in r>   )is_ddufr   r   rK  rL  rT  r   r   r?  rA  rM  rN  re   rR  TrP  z4.27.0zWhen passing `variant='zS'`, please make sure to upgrade your `transformers` version to at least 4.27.0.dev0rQ  Fz>=z4.57.0)is_diffusersrE  rU  rS  )recurser   r   )
state_dictr?  force_hooksmain_device)r?  r]  ))
quantizersrW  r   r`   r   r   r   DUMMY_MODULES_FOLDER!TRANSFORMERS_DUMMY_MODULES_FOLDERr   r;  _get_load_methodr   r   r   rT   r9  r<  r=  r3   r0   r   r   r  r;   r   r  r$   r  ImportErrorr   r   _resolve_quant_configrX   rY   isdirrW   r   r*   r)   r\  )'r   r   r   r   r   r.  r   rK  rL  r?  rA  rM  rN  rO  r   rP  re   rQ  r   rR  rS  rT  rU  rW  r   r   load_method_namer   none_moduleis_dummy_pathload_methodr   loading_kwargsr  r  r  model_quant_configrC  needs_offloading_to_cpus'                                          rN   load_sub_modelrm    s7   4 8 #?#I '7'='='?#
O&:i+Q+Q1=a@ (@
 **#../CD 
H^H^-I
 W3KYKtN+; <66L5MQP
 	

 #9.>\`H`aK !..x~~c/B1/EFN)UXX__--(3}%)->>??%-z")5~&-=)*#I/?/J/JK ""&}}W]]<;S;S-T-a-ab$ 	"# 	<y/2	< GMM($;;  2'1|$'1|$+9'(/A+,$2$6$6tT$By!,;()*.N;'
 "y)5$w}}X'>>)'  3F  G  #~i'@'Hy) 32CN./27N./!8x!H!H/0 	'*,FGGy%((//220FF+ G 
 )4FN01 )5~&&t>~>	rww||M48	9	9&rww||M4'H[N[ '}GG"EHHOO44JPT9U9U 0$?",R.E"9" +668%   +
PTUr   r   rf  rY  c                    ^  U(       a6  [        T [        5      (       a  U 4S j$ [        T [        5      (       a  U 4S j$ [        T U5      $ )a*  
Return the method to load the sub model.

In practice, this method will return the `"from_pretrained"` (or `load_method_name`) method of the class object
except if loading from a DDUF checkpoint. In that case, transformers models and tokenizers have a specific loading
method that we need to use.
c                  "   > [        T/U Q70 UD6$ rz   )r"   argsr  r   s     rN   r3  "_get_load_method.<locals>.<lambda>~  s    +DY+`QU+`Y_+`r   c                  "   > [        T/U Q70 UD6$ rz   )r#   rp  s     rN   r3  rr    s    +Mi+iZ^+ibh+ir   )r   r%   r$   r   )r   rf  rY  s   `  rN   rb  rb  t  s=     i!899``i11ii9.//r   c                 B   [         R                  " [        R                  S5      S   5      n[	        US5      n[        U 5      nUR                  R                  S5      S   nUR                  R                  S5      n[        U5      S:  a  US   OS nUR                  R                  S5      nXg;   =(       a    [        X&5      nU(       a  UnOU[        ;  a  UR                  n[        U[        5      (       a  UR                  n	XI4$ UR                  R                  n	XI4$ )Nr>   r   r   r   )r   r   r   rT   r   r   r   rZ   r   LOADABLE_CLASSESr   typer   )
rF  r   r   not_compiled_moduler   module_path_itemspipeline_dirrY   r   r   s
             rN   _fetch_class_library_tupler{    s    ..x~~c/B1/EF(+6I (/!,,2237:G ,66<<SA,/0A,BQ,F$R(DL))//4D%-R')2R
 	(	(%00 %t,,(11
    )22;;
  r   folderr   c                 \  ^ 0 nTb  [         R                  " U 5       H  n[         R                  R                  X5      n[         R                  R	                  U5      =(       a    XB;   nU=(       a)    [        U4S j[         R                  " U5       5       5      nU(       d  M  TX4'   M     U$ )Nc              3   h   >#    U  H'  oR                  S 5      S   R                  T5      v   M)     g7f)r>   r!   N)rT   r   )rL   pre   s     rN   rO   +_identify_model_variants.<locals>.<genexpr>  s,     .t\sWXwws|A/I/I'/R/R\ss   /2)rX   listdirrY   rW   re  r_   )r|  re   r   rO  
sub_folderfolder_path	is_foldervariant_existss    `      rN   _identify_model_variantsr    s    N**V,J'',,v:Kk2Kz7KI&t3.t\^\f\fgr\s.t+tN~-4* - r   c                    S n[         R                  R                  [         R                  R                  X S35      5      (       a%  [         R                  R                  X S35      nX#4$ [	        US   [
        [        45      (       az  [         R                  R                  [         R                  R                  XS   S    S35      5      (       a0  [         R                  R                  XS   S    S35      nUS   S   nX#4$ )Nr   r   r   r!   )rX   rY   r   rW   r   r!  tuple)r|  r   r   custom_class_names       rN    _resolve_custom_pipeline_and_clsr    s    	ww~~bggll6->c+BCDD'',,v1B#/FG -- 
F=)D%=	9	9bggnn
V} 5a 89=>? ? '',,v2G2J1K3/OP"=1!4--r   r   c                 
   U R                   S:X  as  [        R                  " [        R                  " US   5      R                  5      [        R                  " S5      ::  a#  SSKJnJn  Un SU SU SU S	3n[        S
SUSS9  g g g )NStableDiffusionInpaintPipeline_diffusers_versionz0.5.1r   )r  $StableDiffusionInpaintPipelineLegacyzeYou are using a legacy checkpoint for inpainting with Stable Diffusion, therefore we are loading the z class instead of z. For better inpainting results, we strongly suggest using Stable Diffusion's official inpainting checkpoint: https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting instead or adapting your checkpoint z to the format of https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting. Note that we do not actively maintain the {StableDiffusionInpaintPipelineLegacy} class and will likely remove it in version 1.0.0.r  z1.0.0F)standard_warn)r   r   r  r  r:   r  r  r   )r.  r   r   r  r  deprecation_messages         rN   #_maybe_raise_warning_for_inpaintingr    s    "BBw}}f123@@H	w	H  	c=455GHfGg h 99 :l	l 	 	8'CVfkl!H Br   init_kwargspassed_pipe_kwargspassed_class_objsc                   ^^ SSK Jn  [        R                  " [        R
                  R                  US5      5      n[         Vs0 s H  ow[        UR                  US /5      S   _M      nnUR                  5       n	U	b1  [        U	5      S:  a"  U H  n
SU
;   d  M  U	R                  U
5      nM     UU4S jnUR                  5        VVs0 s H%  u  p}Uc  M
  XuR                  " U40 U	DU" U5      D6_M'     nnnUR                  5        HU  u  p~U R                  UR                   R                  5        VVs0 s H  u  nnSR                  X/5      U_M     snn5        MW     U $ s  snf s  snnf s  snnf )Nr!   )r2   z	README.mdr   	schedulerc                 t  > TR                  5        VVs0 s H5  u  pUR                  S5      S   U :X  d  M  UR                  U  S3S5      U_M7     nnnTR                  5        VVs0 s H5  u  pUR                  S5      S   U :X  d  M  UR                  U  S3S5      U_M7     nnn0 UEUEnU$ s  snnf s  snnf )Nr   r   r   )r`   rT   replace)prefixrG  rg   connected_passed_class_objconnected_passed_pipe_kwargsconnected_passed_kwargsr  r  s         rN   get_connected_passed_kwargsP_update_init_kwargs_with_connected_pipeline.<locals>.get_connected_passed_kwargs  s    7H7N7N7P&
7PtqTUT[T[\_T`abTcgmTm*AIIlB'*7P 	# &
 8J7O7O7Q(
7QtqUVU\U\]`UabcUdhnUn*AIIlB'*7Q 	% (
 #a%?"`C_"`&&&
(
s   B.B.'B4	B4r   )pipeline_utilsr2   r   loadrX   rY   rW   CONNECTED_PIPES_KEYSr   datar"  rZ   r  r`   r/   r   rn   )r  r  r  r|  pipeline_loading_kwargsr2   	modelcardr  connected_pipespipeline_loading_kwargs_cprG  r   r  r   connected_piper   ro   s    ``              rN   +_update_init_kwargs_with_connected_pipeliner    st    2rww||FK@AIXlmXlfwy~~vvFqIIXlOm "9!=!=!?!-#6P2QUV2V(Aa.2215 )	'  /446	  7OF		
11
1
5PQW5X
 	
  7	   #2"7"7"9HVHaHaHgHgHijHi_T9SXXvn%y0Hij	
 #: G n* ks   %E$
	E)E)6 E/pretrained_model_nameconfig_dictrb   r   c                    UR                  5       nUR                  5        VVs/ s H&  u  pV[        U[        5      (       d  M  US:w  d  M$  UPM(     nnn[        R
                  " [        R                  S5      S   5      n[        US5      n	0 n
U Hd  nX   S   nUb  [        U[        5      (       d  M$  U SU S3nX;   a  XU'   M7  U[        ;  d  MC  [        X5      (       a  MU  [        U SU  S35      e   X4$ s  snnf )	Nr   r>   r   r   rH   r   z4 as defined in `model_index.json` does not exist in z. and is not a module in 'diffusers/pipelines'.)r"  r`   r   r!  r   r   r   rT   r   strrv  r   r   )r  r  rb   r   re   rG  rH  rd   r   r   custom_componentsro   module_candidatecandidate_files                 rN   "_get_custom_components_and_foldersr    s    ""$K #."3"3"5d"5$!At9LAQRVcQcA"5Ld ..x~~c/B1/EF(+6I !	&1!4#:6F+L+L &;a(8'9=&+;i(%55gi>b>b!""VWlVm  n\  ]  "  **/ es   C;C;C;model_folder_namesr   allow_pickleuse_onnxis_onnxc	                    U(       a(  U(       d!  [        X XS9(       d  [        SU SU S35      eU(       a  / SQn	U	$ U(       a*  [        X XS9(       a  SS/n	Ub  UOUnU(       d  U	SS	/-  n	U	$ S
S/n	Ub  UOUnU(       d  U	SS	/-  n	U	$ )N)rc   rd   re   z6Could not find the necessary `safetensors` weights in z
 (variant=))*.bin*.safetensors*.onnx*.pbr  z	*.msgpackr  r  r  )rw   EnvironmentError)
rc   r  r   rR  rP  r  r  r  re   r   s
             rN   _get_ignore_patternsr  "  s     	)Oa
 D_DUU_`g_hhij
 	
 F$ ! 
6K] #K0'38&11O  +K8'38&11Or   	dduf_filepipeline_class_namer   r  r  r   r   c                    S nU(       d   [        XUS9n	U(       d,  Ub)  US W	R                   5       ;  a  [        SU SU  S35      e USS	.n[        U UUUUUU/US
9nU$ ! [        [        [        R                  4 a'  n
[
        R                  SU
 S35        SnU
n S n
A
NS n
A
ff = f! [         a    Uc  e [        SU  S35      Uef = f)Nr   zCouldn't connect to the Hub: z$.
Will try to load from local cache.Tc              3   8   #    U  H  oR                   v   M     g 7frz   )r   )rL   r   s     rN   rO   &_download_dduf_file.<locals>.<genexpr>d  s     M}G//}s   z
Requested z file is not available in r>   )r.  dduf)r   r  r  r   r   allow_patternsr  zCannot load model z: model is not cached locally and an error occurred while trying to fetch metadata from the Hub. Please check out the root cause in the stacktrace above.)r   r   r   requestsConnectionErrorr   r   r   r   r   FileNotFoundErrorr  )r  r  r  r   r  r  r   r   model_info_call_errorr   er  r   s                rN   _download_dduf_filer  N  s    !	&38TD !Mt}}MM:i[0JK`Jaabcdd)(;TJ
)!-%;!	
 1 /1I1IJ 	&NN:1#=bcd#$%!	&2  )
 !( #$%:$; <  )	))s#   
A! 	B* !B' B""B'*C	c                     SnU  H/  n[        X   [        5      (       d  M  X   S   S:H  nU(       d  M/    O   U(       a  [        SS5      (       d  [        S5      eg g )NFr   r;   >z4.47.1zRPlease upgrade your `transformers` installation to the latest version to use DDUF.)r   r!  r   r   )r  has_transformers_componentrG  s      rN   -_maybe_raise_error_for_incorrect_transformersr    sc    !&knd++)4):n)L&))	 
 "*A#x*P*Pmnn +Q!r   c                    Uc  g [        U R                  5       5      nSnS n[        USS 5      b  [        UR                  5      nOP[        USS 5      bB  [	        UR
                  [        5      (       a#  [        UR
                  R                  5       5      nU(       a  UR                  U5      (       d  XB-
  nU(       a,  [        R                  SU SSR                  U5       S35        g g )Nr   components_to_quantizequant_mappingz4The following components in the quantization config zv will be ignored as they do not belong to the underlying pipeline. Acceptable values for the pipeline components are: r   r>   )r]   r   r   r  r   r  r   r   r   r   rW   )pipe_init_dictquant_configactual_pipe_componentsmissingquant_componentss        rN   /_maybe_warn_for_wrong_component_in_quant_configr    s     !4!4!67G|5t<H|BBC		5	AjQ]QkQkmqFrFr|99>>@A 0 9 9:P Q Q";B7) L#yy)?@AD	
 r   )NNN)NN)NNNNN)NFNNNNNN)r,  rz   )mr   rX   rU   r   pathlibr   typingr   r   r   r   r   r	   r  r9  huggingface_hubr
   r   r   r   huggingface_hub.utilsr   r   	packagingr   requests.exceptionsr   r   r   utilsr   r   r   r   r   r   r   r   r   r   r   r   utils.torch_utilsr    transformers_loading_utilsr"   r#   r;   r$   r%   transformers.utilsr&   rR   rQ   rS   r  r)   accelerate.hooksr*   accelerate.utilsr+   r,   
INDEX_FILEr   r`  ra  r  
get_loggerr   r   rv  r;  r   r   boolrw   r   r^   PathLiker  r   r   r   r   r   r   r   r   r  r  floatr*  rJ  deviceintrm  objectrb  r{  r   r  r  r  r  r  r  r  r  r  rK   r   rN   <module>r     s    	 	   = =   O O L  )     3 e EVLtX..Z)8E +
) ( $8 !y 			H	% )*;<,.?@/1BC.0AB	 !23DE$57H#I-/@A#46G"H,.?@!24E F 	'):; (  G!!"27";<  Wei Wtd(Tf/RWX\]_]h]hXiknXnRo f/R 
 
,
<  qu': F !0fQQQ S	Q 	Q
 Q Q sEKK'(Q bkk)*Qj eo'sEz"'37U
3C'^a'<`t *./___ S	_ 	_
 _ _ _ _ _ tC$56;<=_ eCHouS#X>?@_ U3#345_ _ cN_ _  !_" #_$ %_& bkk)*'_( )_* 4Y/0+_, -_. "#/_D0 0# 0 0QY 0 !B	S 	3 	 	 	
.mWZ mdh m())+/)DH)RU)	)^ &*-1!!+!+c3h!+ S	"!+  S	*	!+
 c]!+Z ")S	) #Y) 	)
 ) ) ) ) c]) 
#Y)X5)5)5) 5) 	5)
 5) 5) 5) 5)po
r   