
    
3j              5       d   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  S SK	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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%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-J.r.J/r/  S SK0J1r2  S SK0Jr3  \&" SS5      (       a  S SK0Jr4  \#" 5       (       a  S SK5r5S SK5J6r6  S SK7J8r8  S SK9J:r:J;r;  Sr<Sr=Sr>Sr?S/r@\'R                  " \B5      rCSS/S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 .rD0 rE\D H  rF\ER                  \D\F   5        M     SrS!\H4S" jjrIS# rJS$ rKSsS!\L\R                     \N-  4S% jjrO\S& 5       rPS' rQS( rRS) rS   StS*\H4S+ jjrT      SuS*\H4S, jjrU         SvS*\H4S- jjrVS.\NS/\NS0\L\   S1\S2\HS3\NS4\N\R                  -  S5\N\R                  -  4S6 jrX SwS7\Y\N\Z4   S8\Y\N\Z4   S9\N4S: jjr[S; r\   SxS.\NS/\NS0\L\   S1\S2\HS<\S4\R                  S=\S>\S?\Y\N\R                  4   \N-  S-  S@\Y\^\N-  \^\N-  4   S-  SA\N\R                  -  S-  SB\HSC\Y\N\N4   S3\NSD\HSE\NSF\HS5\N\R                  -  SG\HSH\Y\N\4   S-  SI\SJ\HSK\S-  SL\HS*\H44SM jjr_SN\`SO\NSP\HS!\4SQ jraSR rbSS\NSE\NST\YS!\Y4SU jrcSV rdSW\NST\Y4SX jreSY\YSZ\YS[\YSS\NS!\Y4
S\ jrf   SrS]\NS^\Y\N\4   S_\L\N   S-  S`\L\N   S-  SE\NS-  4
Sa jjrg SySb\L\N   Sc\L\N   SG\HSD\HSd\HSe\HSf\HSL\HSE\NS-  S!\L\N   4Sg jjrhS]\NSh\NSi\NSj\NSk\NSl\HSm\NSn\N4So jriSp rjSq rkg)z    N)Path)AnyCallable)	DDUFEntry	ModelCard
model_infosnapshot_download)HfHubHTTPErrorOfflineModeIsEnabledvalidate_hf_hub_args)version   )__version__)FLASHPACK_WEIGHTS_NAMEFLAX_WEIGHTS_NAMEONNX_EXTERNAL_WEIGHTS_NAMEONNX_WEIGHTS_NAMESAFETENSORS_WEIGHTS_NAMEWEIGHTS_NAME_maybe_remap_transformers_class	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BaseGuidance)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/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/pipelines/pipeline_loading_utils.py	<genexpr>,is_safetensors_compatible.<locals>.<genexpr>   s     Q>P(>X->Ps   rI   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
componentsrL   	componentcomponent_filenamefiltered_filenamescomponent_filenamesmatchesfiltered_component_filenames	extensionmatch_existss                         rM   is_safetensors_compatiblerv   d   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                 p  ^ [         [        [        [        [        [
        /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)rK   rt   rl   s     rM   rN   %filter_model_files.<locals>.<genexpr>   s     'bOa)

9(=(=Oas   !)r   r   r   r   r   r   r   rP   rQ   r   rR   rS   r^   )ra   re   wnallowed_extensionsrl   s       `rM   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.B3%B3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 )NrG   r>   )matchrS   )ra   
pattern_rerl   s      rM   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?   r@   rA   rB   rC   rD   z
)\.index\.z\.json$z.*-z\.z	\.[a-z]+$z)\.z\.index\.json$rE   rF   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)rz   lstrip)rK   patrl   s     rM   rN   Xvariant_compatible_siblings.<locals>.filter_for_compatible_extensions.<locals>.<genexpr>  s)     /hXgQT

3::d;K0L0LXgs   -0)r^   )ra   ignore_patternsrl   s     `rM    filter_for_compatible_extensionsEvariant_compatible_siblings.<locals>.filter_for_compatible_extensions  s4     %i9aC/hXg/h,h9iiis   ;;rG   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.ry   )r   r   r   r   r   r   rP   rQ   r   rR   rS   rT   rU   rV   rY   rZ   r[   r\   r_   r]   update
ValueErrorloggerwarning)ra   rd   r   re   rf   rg   rh   ri   rj   variant_index_relegacy_variant_file_relegacy_variant_index_rerk   non_variant_index_rer   rm   rL   rn   _usable_filenamesvariant_filenamesrq   component_variantscomponent_legacy_variantscomponent_non_variantscomponent_variant_index_files$component_legacy_variant_index_fileserror_messages                               rM   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)rd   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   rV   rS   r\   issubsetwarningswarnFutureWarning)pretrained_model_name_or_pathr   rd   r   model_filenamesinfosiblingra   comp_model_filenamesr   rl   s              rM   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     rM   _unwrap_modelr   W  sC    %  "e''$$**EL    c           	         U(       d  [         R                  " U 5      nU S:X  a  [        U5      =(       d    U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 passedr:   Nz 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_moduler   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                  rM   maybe_raise_or_warnr   e  s    )),7 >)8DR
J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U S:X  a  [        U5      =(       d    Un[        Xa5      nU$ )Nr   	pipelinesr:   )r9   r   hasattrr   r   r   r   )r   r   r   r   pipeline_moduler   r   s          rM   simple_get_class_objr     sj    # 9!):O8	  )),7 >)8DR
JG0	r   trust_remote_codec           	         U(       a&  U(       a  [         R                  R                  Xe5      OSnUR                  S5      (       a  UR	                  S5      nU(       a=  [        X05      n	[        X5      n
[        R                  UR                  5       U
5      nX4$ U(       az  [         R                  R                  [         R                  R                  XS-   5      5      (       a6  [        UU S-   UUS9n
[        R                  UR                  5       U
5      nX4$ [        R                  " U 5      nU S:X  a  [        U5      =(       d    U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	FlashPack.py)module_filer   r   r:   )rW   rX   rV   
startswithremoveprefixr   dictfromkeysr   isfiler   r   r   r   )r   r   r   r   r   component_name	cache_dirr   component_folderr   r   r   r   r   s                 rM   get_class_obj_and_candidatesr     s[    CQU^rww||I>dh[)),,[9
!):O8	==);)@)@)BIN* &&) 
bggnnRWW\\:J[`L`-abb1$u,!/	
	  ==);)@)@)BIN && )),7 >)8DR
JG0	BTBYBYB[\B[Qww488B[\&& ]s   )F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US9$ )Nr   )r   r   r   r   r   )rz   r   r   parentabsoluteCUSTOM_PIPELINE_FILE_NAMEr   )	custom_pipelinerepo_idhub_revisionr   r   r   r   rX   	file_names	            rM   _get_custom_pipeline_classr     s     &&O$II	++..0		&'s+	!-	|7  (+ r   c
           
      h   Ub  [        U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   r   r0   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__rS   r   r   r   auto_pipeliner   r   r   )r   configload_connected_pipeliner   r   r   r   r   r   r   diffusers_modulepipeline_clsr   connected_pipeline_clss                 rM   _get_pipeline_classr     sM    ")%!/
 	
 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)r9   	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   rS   r.   load_configrW   rX   rV   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                         rM   _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   copyrY   r[   )r  r  r  
device_idsdevice_cycledevice_id_component_mappingcurrent_device_indexrn   	device_idcomponent_memorycurr_device_memorys              rM   _assign_components_to_devicesr+  t  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   rJ   items    rM   <lambda>'_get_final_device_map.<locals>.<lambda>  s    d1gr   T)keyreversec                     U S   $ r1  rJ   r2  s    rM   r4  r5    s    $q'r   r!  )r  )r9   r   gettorchfloat32r_   r   r   r   ALL_IMPORTABLE_CLASSESr   r  r  r   r   r  nnModuler)   sortedr*   rY   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(  rm   rn   s                              rM   _get_final_device_maprK    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@  rB  offload_folderoffload_state_dictmodel_variants	from_flaxrd   low_cpu_mem_usageuse_safetensorsdduf_entriesprovider_optionsdisable_mmapquantization_configuse_flashpackc                 b	   SSK Jn  [        U 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U"R                   5      n$[#        5       (       aC  [$        R&                  " [$        R&                  " [(        R*                  5      R,                  5      n%OSn%[#        5       =(       a0    [	        U[.        5      =(       a    U%[$        R&                  " S5      :  n&[	        U[0        R2                  R4                  5      (       a,  U&(       a   U%[$        R&                  " S5      :  a  UU#S'   OUU#S'   [	        UU"R6                  5      (       a  UU#S'   UU#S'   UU#S'   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  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  UU#S#'   U&(       a"  [=        S$S%5      (       a  U#R9                  S5        UbR  [?        UU5      (       aA  [	        U[0        R2                  R4                  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([0        R2                  R4                  5      (       a  [?        U	[J        5      (       av  U(       do  [M        U(SS)9  U	S*   S+:H  n)Sn*[O        U(S,5      (       a  U(RP                  b  U(RP                  n*U)(       a  [S        U(U(RU                  5       U	SSU*S-9  U($ [S        U(U	SU*S.9  U($ )/zLHelper method to load the module `name` from `library_name` and `class_name`r   )PipelineQuantizationConfig)r   r   r   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   r   z4.56.0r  r   rL  rM  rU  r@  rB  rN  rO  rd   rS  rX  TrQ  z4.27.0zWhen passing `variant='zS'`, please make sure to upgrade your `transformers` version to at least 4.27.0.dev0rR  FrV  z>=z4.57.0)is_diffusersrF  rW  rT  )recurser   r!  
_skip_keys)
state_dictr@  force_hooksmain_device	skip_keys)r@  ra  rc  )+
quantizersrZ  r   r_   r   r   r   DUMMY_MODULES_FOLDER!TRANSFORMERS_DUMMY_MODULES_FOLDERr   r<  _get_load_methodr   r   r   rS   r.   r   r   r  r:   r   r  r"   r:  r=  r>  r1   r  ImportErrorr   r   _resolve_quant_configrW   rX   isdirrV   r   r(   r   r_  r'   r`  )+r   r   r   r   r   r/  r   rL  rM  r@  rB  rN  rO  rP  r   rQ  rd   rR  r   rS  rT  rU  rV  rW  rX  r   rZ  r   r   load_method_namer   none_moduleis_dummy_pathload_methodr   loading_kwargsr  r  r  model_quant_configrD  needs_offloading_to_cpurc  s+                                              rM   load_sub_modelrr    s   : 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#I/?/J/JK ""&}}W]]<;S;S-T-a-ab$ 	"# 	<y/2	< GMM($;;  )UXX__-- %9W]]8=T%T&1N7#,7N=))->>??%-z")5~&-=)*
 2'1|$'1|$+9'(/A+,$2$6$6tT$By!,;().;N?+*.N;'
 "y)5$w}}X'>>)'  3F  G  #~i'@'Hy) 32CN./27N./)5~&!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^k 0$?",R.E"9	#\227G7R7R7^(33I" +668% #  +
PT`ijr   r   rk  r\  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$ ry   )r    argsr  r   s     rM   r4  "_get_load_method.<locals>.<lambda>  s    +DY+`QU+`Y_+`r   c                  "   > [        T/U Q70 UD6$ ry   )r!   ru  s     rM   r4  rw    s    +Mi+iZ^+ibh+ir   )r   r#   r"   r   )r   rk  r\  s   `  rM   rg  rg    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   rS   r   r   r   rY   r   LOADABLE_CLASSESr   typer   )
rG  r   r   not_compiled_moduler   module_path_itemspipeline_dirrX   r   r   s
             rM   _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)rS   r   )rK   prd   s     rM   rN   +_identify_model_variants.<locals>.<genexpr>  s,     .t\sWXwws|A/I/I'/R/R\ss   /2)rW   listdirrX   rV   rj  r^   )r  rd   r   rP  
sub_folderfolder_path	is_foldervariant_existss    `      rM   _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   )rW   rX   r   rV   r   r"  tuple)r  r   r   custom_class_names       rM    _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  r9   r  r  r   )r/  r   r   r  r  deprecation_messages         rM   #_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   )r0   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_   rS   replace)prefixrH  rf   connected_passed_class_objconnected_passed_pipe_kwargsconnected_passed_kwargsr  r  s         rM   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_utilsr0   r   loadrW   rX   rV   CONNECTED_PIPES_KEYSr   datar#  rY   r  r_   r-   r   rm   )r  r  r  r  pipeline_loading_kwargsr0   	modelcardr  connected_pipespipeline_loading_kwargs_cprH  r   r  r   connected_piper   rn   s    ``              rM   +_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_dictra   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   rG   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   rS   r   strr{  r   r   )r  r  ra   r   rd   rH  rI  rc   r   r   custom_componentsrn   module_candidatecandidate_files                 rM   "_get_custom_components_and_foldersr  4  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
$ U(       a  / S
Qn
U
$ SS/n
Ub  UOUnU(       d  U
SS	/-  n
U
$ )N)rb   rc   rd   z6Could not find the necessary `safetensors` weights in z
 (variant=))*.bin*.safetensors*.onnx*.pbr  	*.msgpackr  r  )r  r  r  r  r  r  )rv   EnvironmentError)rb   r  r   rS  rQ  r  r  r  rX  rd   r   s              rM   _get_ignore_patternsr  X  s     	)Oa
 D_DUU_`g_hhij
 	
 F* ' 
6K] #K0'38&11O  
S  +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                  [
        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ry   )r   )rK   r   s     rM   rN   &_download_dduf_file.<locals>.<genexpr>  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ConnectionErrorhttpxNetworkErrorr   r   r   r   r	   FileNotFoundErrorr  )r  r  r  r   r  r  r   r   model_info_call_errorr   er	  r   s                rM   _download_dduf_filer    s#    !	&38TD !Mt}}MM:i[0JK`Jaabcdd)(;TJ
)!-%;!	
 1  4h6N6NPUPbPbc 	&NN:1#=bcd#$%!	&2  )
 !( #$%:$; <  )	))s#   
A! 	B9 !.B6B11B69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_componentrH  s      rM   -_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   rV   )pipe_init_dictquant_configactual_pipe_componentsmissingquant_componentss        rM   /_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)NNF)NNNNNF)	NFNNNNNNF)r-  )NFFry   )lr   rW   rT   r   pathlibr   typingr   r   r  r  r:  huggingface_hubr   r   r   r	   huggingface_hub.utilsr
   r   r   	packagingr   r   r   utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   utils.torch_utilsr   transformers_loading_utilsr    r!   r:   r"   r#   transformers.utilsr$   rQ   rP   rR   r  r'   accelerate.hooksr(   accelerate.utilsr)   r*   
INDEX_FILEr   re  rf  r  
get_loggerr   r   r{  r<  r   r   boolrv   r~   r]   r"  PathLiker  r   r   r   r   r   r   r   r   r  r  r   floatr+  rK  deviceintrr  objectrg  r  r  r  r  r  r  r  r  r  r  rJ   r   rM   <module>r     sJ    	 	        O O \ \       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/RVWYWbWbRcfiRi f/R 
 
,
F4 #)' )'\ #   J !#2 2jQQQ S	Q 	Q
 Q Q u{{"Q $Qj eo'sEz"'37U
3C'^a'<`v '+#5rrr S	r 	r
 r r r r r S%,,&'#-4r S3Yc	)*T1r "++%,r r cNr r  !r" #r$ %r& $'r( )r* sI~&-+r, -r. /r0 t1r2 3r4 5rj0 0# 0 0QY 0 !B	S 	3 	 	 	
.mWZ mdh m())+/)DH)RU)	)^ #'*.!+!+c3h!+ Cy4!+ Cy4'	!+
 4Z!+\ -S	- #Y- 	-
 - - - - - 4Z- 
#Y-`5)5)5) 5) 	5)
 5) 5) 5) 5)po
r   