ó
    oM‡j¼� ã                   óæ  • S SK r S SKrS SKrS SKrS SK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  S SKJr  S SKJr  S SKJrJr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  S SKJr  S S	KJrJ r   S S
K!J"r"  SSK#J$r$  SSK%J&r&J'r'  SSK(J)r)  SSK*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<  SSK=J>r>  SSK?J@r@JArAJBrB  SSKCJDrD  SSKEJFrFJGrGJHrHJIrI  SSKJJKrKJLrLJMrMJNrNJOrOJPrPJQrQJRrR   " S S5      rS\<R¨                  " \U5      rV\R®                  " S5      rXSrY\ 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Ð                  S.ri\;" SS5      (       a  SrjOSrj\6" 5       (       a  S SKkrkS SKkJlrl  S S KmJnrnJoro  S!\R@                  Rà                  S"\Râ                  4S# jrrS!\R@                  Rà                  S"\Ræ                  4S$ jrt\S% 5       ru " S& S'\R@                  Rà                  \@5      rv " S( S)\v5      rwg)*é    N)ÚOrderedDict)Ú	ExitStackÚcontextmanager)Úwraps)ÚPath)ÚAnyÚCallableÚContextManagerÚType)Ú	DDUFEntryÚcreate_repoÚ"split_torch_state_dict_into_shards)Úvalidate_hf_hub_args)ÚTensorÚnn)ÚSelfé   )Ú__version__)ÚDiffusersAutoQuantizerÚDiffusersQuantizer)ÚQuantizationMethod)ÚCONFIG_NAMEÚFLASHPACK_WEIGHTS_NAMEÚHF_ENABLE_PARALLEL_LOADINGÚSAFE_WEIGHTS_INDEX_NAMEÚSAFETENSORS_WEIGHTS_NAMEÚWEIGHTS_INDEX_NAMEÚWEIGHTS_NAMEÚ_add_variantÚ_get_checkpoint_shard_filesÚ_get_model_fileÚ	deprecateÚis_accelerate_availableÚis_bitsandbytes_availableÚis_bitsandbytes_versionÚis_flashpack_availableÚis_peft_availableÚis_torch_versionÚlogging)Úis_torch_dist_rank_zero)ÚPushToHubMixinÚload_or_create_model_cardÚpopulate_model_card)Úempty_device_cacheé   )ÚContextParallelConfigÚContextParallelModelPlanÚParallelConfigÚTensorParallelConfig)Ú_caching_allocator_warmupÚ_determine_device_mapÚ_expand_device_mapÚ_fetch_index_fileÚ_fetch_index_file_legacyÚ_load_shard_fileÚ!_load_shard_files_with_threadpoolÚload_state_dictc                   ó8   • \ rS rSrSrS\\   4S jrS rS r	Sr
g)	ÚContextManagerséT   zŽ
Wrapper for `contextlib.ExitStack` which enters a collection of context managers. Adaptation of `ContextManagers`
in the `fastcore` library.
Úcontext_managersc                 ó.   • Xl         [        5       U l        g ©N)r?   r   Ústack)Úselfr?   s     Ú­C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\diffusers/models/modeling_utils.pyÚ__init__ÚContextManagers.__init__Z   s   € Ø 0ÔÜ“[ˆ�
ó    c                 ó`   • U R                    H  nU R                  R                  U5        M      g rA   )r?   rB   Úenter_context)rC   Úcontext_managers     rD   Ú	__enter__ÚContextManagers.__enter__^   s$   € Ø#×4Ô4ˆOØ�J‰J×$Ñ$ _Ö5ò  5rG   c                 ó<   • U R                   R                  " U0 UD6  g rA   )rB   Ú__exit__)rC   ÚargsÚkwargss      rD   rN   ÚContextManagers.__exit__b   s   € Ø�
‰
×Ò˜TÐ, VÓ,rG   )r?   rB   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úlistr
   rE   rK   rN   Ú__static_attributes__© rG   rD   r=   r=   T   s"   † ñð
!¨¨nÑ)=ô !ò6õ-rG   r=   z(.*?)-\d{5}-of-\d{5}i   )Úuniform_Únormal_Útrunc_normal_Ú	constant_Úxavier_uniform_Úxavier_normal_Úkaiming_uniform_Úkaiming_normal_ÚuniformÚnormalÚxavier_uniformÚxavier_normalÚkaiming_uniformÚkaiming_normalú>=ú1.9.0TF)Údispatch_model)Úload_offloaded_weightsÚsave_offload_indexÚ	parameterÚreturnc                 ó¶  • SSK Jn   U" U 5      $ ! [         a     Of = f [        R                  " U R                  5       U R                  5       5      n[        U5      R                  $ ! [         ae    S[        R                  R                  S[        [        [        [         4      4S jnU R#                  US9n[        U5      nUS   R                  s $ f = f)Nr   )Ú_get_group_onload_deviceÚmodulern   c                 óª   • U R                   R                  5        VVs/ s H%  u  p[        R                  " U5      (       d  M"  X4PM'     nnnU$ s  snnf rA   ©Ú__dict__ÚitemsÚtorchÚ	is_tensor©rq   ÚkÚvÚtupless       rD   Úfind_tensor_attributesÚ4get_parameter_device.<locals>.find_tensor_attributes�   sB   € Ø)/¯©×)>Ñ)>Ô)@ÔWÒ)@¡ ÄEÇOÂOÐTU×DV“f�q“fÑ)@ˆFÑWØˆMùó Xó   ž!AÁA©Úget_members_fnr/   )Úhooks.group_offloadingrp   Ú
ValueErrorÚ	itertoolsÚchainÚ
parametersÚbuffersÚnextÚdeviceÚStopIterationrv   r   ÚModulerW   ÚtupleÚstrr   Ú_named_members)rm   rp   Úparameters_and_buffersr|   ÚgenÚfirst_tuples         rD   Úget_parameter_devicer‘   Œ   sÊ   € ÝAðá'¨	Ó2Ð2øÜó Ùðúð%ô "+§¢°×1EÑ1EÓ1GÈ×IZÑIZÓI\Ó!]ÐÜÐ*Ó+×2Ñ2Ð2øÜó 	%ð	¬5¯8©8¯?©?ð 	¼tÄEÌ#ÌvÈ+ÑDVÑ?Wô 	ð ×&Ñ&Ð6LÐ&ÐMˆÜ˜3“iˆØ˜1‰~×$Ñ$Ò$ð	%ús   ˆ �
œ¡AA) Á)A,CÃCc                 óº  ^• [        U [        R                  5      (       a[  U R                  5        HG  u  mn[	        US5      (       d  M  UR
                  nUR                  S5      nUc  M;  UR                  s  $    SnU R                  5        H}  u  mnUR                  n[	        U S5      (       a7  U R                  (       a&  [        U4S jU R                   5       5      (       a  MZ  UR                  5       (       d  Mq  UR                  s  $    U R                  5        H2  nUR                  nUR                  5       (       d  M&  UR                  s  $    Ub  U$ S[        R                  S[        W[        [         4      4S jnU R#                  US	9n	Sn
U	 H.  nUn
US
   R                  5       (       d  M  US
   R                  s  $    U
b  U
S
   R                  $ g)zr
Returns the first found floating dtype in parameters if there is one, otherwise returns the last dtype it found.
Ú_diffusers_hookÚlayerwise_castingNÚ_keep_in_fp32_modulesc              3   ó,   >#   • U  H	  oT;   v •  M     g 7frA   rY   )Ú.0ÚmÚnames     €rD   Ú	<genexpr>Ú&get_parameter_dtype.<locals>.<genexpr>¼   s   øé € ÐGÒ'F !˜–IÒ'Fùs   ƒrq   rn   c                 óª   • U R                   R                  5        VVs/ s H%  u  p[        R                  " U5      (       d  M"  X4PM'     nnnU$ s  snnf rA   rs   rx   s       rD   r|   Ú3get_parameter_dtype.<locals>.find_tensor_attributesÍ   sB   € Ø%+§_¡_×%:Ñ%:Ô%<ÔSÒ%<™T˜QÄÇÂÐPQ×@R“&�1“&Ñ%<ˆÑSØˆùó Tr~   r   r/   )Ú
isinstancer   rŠ   Únamed_modulesÚhasattrr“   Úget_hookÚcompute_dtypeÚnamed_parametersÚdtyper•   ÚanyÚis_floating_pointr†   rW   rŒ   r   r�   )rm   Ú	submoduleÚregistryÚhookÚ
last_dtypeÚparamÚbufferr‹   r|   r�   Ú
last_tupler™   s              @rD   Úget_parameter_dtyper®   ¦   s¯  ø€ ô
 �)œRŸY™Y×'Ñ'Ø(×6Ñ6Ö8‰OˆD�)Ü˜9Ð&7×8Ñ8ÙØ ×0Ñ0ˆHØ×$Ñ$Ð%8Ó9ˆDØÓØ×)Ñ)Ò)ñ  9ð €Jà ×1Ñ1Ö3‰ˆˆeØ—[‘[ˆ
ä�IÐ6×7Ñ7Ø×/×/ÜÔG y×'FÒ'FÓG×GÑGáà×"Ñ"×$Ó$Ø—;‘;Òñ 4ð ×#Ñ#Ö%ˆØ—\‘\ˆ
Ø×#Ñ#×%Ó%Ø—<‘<Òñ &ð
 ÑàÐð¤r§y¡yð ´T¸%ÄÄVÀÑ:LÑ5Mô ð ×
"Ñ
"Ð2HÐ
"Ð
I€CØ€JÛˆØˆ
Ø�‰8×%Ñ%×'Ó'Ø˜‘8—>‘>Ò!ñ ð
 Ñà˜!‰}×"Ñ"Ð"ð rG   c               #   ó¬  #   • S n [         R                  5        H)  u  p[        [        R                  R
                  X5        M+      Sv •  [         R                  5        H)  u  p[        [        R                  R
                  X5        M+     g! [         R                  5        H)  u  p[        [        R                  R
                  X5        M+     f = f7f)z¤
Context manager to globally disable weight initialization to speed up loading large models. To do that, all the
torch.nn.init function are all replaced with skip.
c                  ó   • g rA   rY   )rO   rP   s     rD   Ú
_skip_initÚ#no_init_weights.<locals>._skip_initä   s   € ØrG   N)ÚTORCH_INIT_FUNCTIONSru   Úsetattrrv   r   Úinit)r±   r™   Ú	init_funcs      rD   Úno_init_weightsr·   Ý   sŒ   é € òô 0×5Ñ5Ö7‰ˆÜ”—‘—‘˜tÖ0ñ 8ð4Ûô  4×9Ñ9Ö;‰OˆDÜ”E—H‘H—M‘M 4Ö3ò  <øÔ3×9Ñ9Ö;‰OˆDÜ”E—H‘H—M‘M 4Ö3ò  <üs    ‚ACÁB ÁACÂACÃCc            "       óR  ^ • \ rS rSrSr\r/ SQrSrSr	Sr
SrSrSr/ rSrSrSrSrU 4S jrS\S	\4U 4S
 jjr\S	\4S j5       rSdS\S-  S	S4S jjrSeS jrS\S	S4S jrSeS jrSeS jr SdS\S\S-  S	S4S jjr SdS\S-  4S jjr!S r"SdS\S\S-  S	S4S jjr#SdS\S-  S	S4S jjr$SeS jr%\&RN                  SSSS4S\&RP                  S\&RP                  S-  S\)\S4   S-  S \)\*\&RV                  RX                     S4   S-  S!\S	S4S" jjr-\&R\                  " S#5      S$SSSSSSSS4
S%\&R\                  S&\&R\                  S'\S(\/S-  S!\S)\S*\S+\S-  S,\S-  S-\S-  S	S4S. jjr0S/\S	S4S0 jr1SeS1 jr2       SfS2\\3Rh                  -  S3\S4\S-  S5\S6\S-  S7\/\-  S8\S9\4S: jjr5S; r6\7\8S<\\3Rh                  -  S-  S	\94S= j5       5       r:\;" \&RV                  RX                  Rx                  5      U 4S> j5       r<\;" \&RV                  RX                  Rz                  5      U 4S? j5       r=U 4S@ jr>U 4SA jr?SB r@SSC.SD\A\B-  \C-  SE\D\\E4   S-  4SF jjrF\7            SgSG\GSH\H\   S<\\3Rh                  -  SI\H\   SJ\SK\SL\IS-  SM\SN\\&RP                  -  S-  SO\H\   S-  SP\\/-  \&R\                  -  \D\\\/-  \&R\                  -  4   -  SQ\S-  SR\\3Rh                  -  S-  SS\D\\J4   S-  ST\S-  SU\4 SV jj5       rK\7SW 5       rLSP\4SX jrM\7SN\&RP                  S	\&RP                  4SY j5       rN\S	\&R\                  4SZ j5       r.\S	\&RP                  4S[ j5       r(ShS\\S]\S	\/4S^ jjrOSiS_ jrPS\&R¢                  R¤                  R¤                  4S`\S\S	S4Sa jjrSSG\GS	S4Sb jrTScrUU =rV$ )jÚ
ModelMixinéñ   a  
Base class for all models.

[`ModelMixin`] takes care of storing the model configuration and provides methods for loading, downloading and
saving models.

    - **config_name** ([`str`]) -- Filename to save a model to when calling [`~models.ModelMixin.save_pretrained`].
)Ú_diffusers_versionÚ_class_nameÚ_name_or_pathFNTc                 ó0   >• [         TU ]  5         S U l        g rA   )ÚsuperrE   Ú_gradient_checkpointing_func)rC   Ú	__class__s    €rD   rE   ÚModelMixin.__init__	  s   ø€ Ü‰ÑÔà,0ˆÕ)rG   r™   rn   c                 ó`  >• SU R                   ;   =(       a    [        U R                   S   U5      nXR                   ;   nU(       a[  U(       dT  SU S[        U 5      R                   SU S[        U 5      R                   SU S3n[	        SS	US
SS9  U R
                  U   $ [        TU ]  U5      $ )a^  The only reason we overwrite `getattr` here is to gracefully deprecate accessing
config attributes directly. See https://github.com/huggingface/diffusers/pull/3129 We need to overwrite
__getattr__ here in addition so that we don't trigger `torch.nn.Module`'s __getattr__':
https://pytorch.org/docs/stable/_modules/torch/nn/modules/module.html#Module
Ú_internal_dictzAccessing config attribute `z` directly via 'z1' object attribute is deprecated. Please access 'z' over 'z,'s config object instead, e.g. 'unet.config.z'.zdirect config name accessz1.0.0Fé   )Ústandard_warnÚ
stacklevel)rt   r    ÚtyperR   r"   rÄ   r¿   Ú__getattr__)rC   r™   Úis_in_configÚis_attributeÚdeprecation_messagerÁ   s        €rD   rÉ   ÚModelMixin.__getattr__  sù   ø€ ð (¨4¯=©=Ñ8×k¼WÀTÇ]Á]ÐScÑEdÐfjÓ=kˆØŸ}™}Ñ,ˆæ¦Ø$@ÀÀÐFVÔW[Ð\`ÓWa×WjÑWjÐVkð  l]ð  ^bð  ]cð  ckô  lpð  quó  lv÷  lñ  lð  k@ð  @lð  mqð  lrð  rtð  #uÐÜÐ1°7Ð<OÐ_dÐqrÒsØ×&Ñ& tÑ,Ð,ô ‰wÑ" 4Ó(Ð(rG   c                 óB   • [        S U R                  5        5       5      $ )zD
Whether gradient checkpointing is activated for this model or not.
c              3   ó`   #   • U  H$  n[        US 5      =(       a    UR                  v •  M&     g7f)Úgradient_checkpointingN)r    rÐ   )r—   r˜   s     rD   rš   Ú7ModelMixin.is_gradient_checkpointing.<locals>.<genexpr>%  s)   é € ÐmÒ^lÐYZ”7˜1Ð6Ó7×T¸A×<TÑ<TÔTÒ^lùs   ‚,.)r¥   Úmodules©rC   s    rD   Úis_gradient_checkpointingÚ$ModelMixin.is_gradient_checkpointing   s   € ô
 ÑmÐ^b×^jÑ^jÔ^lÓmÓmÐmrG   Úgradient_checkpointing_funcc                 óš   • U R                   (       d"  [        U R                  R                   S35      eUc  S nUnU R	                  SUS9  g)a‚  
Activates gradient checkpointing for the current model (may be referred to as *activation checkpointing* or
*checkpoint activations* in other frameworks).

Args:
    gradient_checkpointing_func (`Callable`, *optional*):
        The function to use for gradient checkpointing. If `None`, the default PyTorch checkpointing function
        is used (`torch.utils.checkpoint.checkpoint`).
z� does not support gradient checkpointing. Please make sure to set the boolean attribute `_supports_gradient_checkpointing` to `True` in the class definition.Nc                 ó    • [        SS5      (       a  SS0O0 n[        R                  R                  R                  " U R                  /UQ70 UD6$ )Nrh   z1.11.0Úuse_reentrantF)r(   rv   ÚutilsÚ
checkpointÚ__call__)rq   rO   Úckpt_kwargss      rD   rÀ   ÚNModelMixin.enable_gradient_checkpointing.<locals>._gradient_checkpointing_func9  sR   € Ü:JÈ4ÐQY×:ZÑ:Z˜°Ñ6Ð`b�Ü—{‘{×-Ñ-×8Ò8Ø—O‘Oðàòð "ñð rG   T)ÚenablerÖ   )Ú _supports_gradient_checkpointingr‚   rÁ   rR   Ú_set_gradient_checkpointing)rC   rÖ   rÀ   s      rD   Úenable_gradient_checkpointingÚ(ModelMixin.enable_gradient_checkpointing'  s`   € ð ×4×4ÜØ—>‘>×*Ñ*Ð+ð ,Xð Yóð ð
 'Ñ.òð +GÐ'à×(Ñ(°ÐRmÐ(ÒnrG   c                 óF   • U R                   (       a  U R                  SS9  gg)zž
Deactivates gradient checkpointing for the current model (may be referred to as *activation checkpointing* or
*checkpoint activations* in other frameworks).
F)rß   N)rà   rá   rÓ   s    rD   Údisable_gradient_checkpointingÚ)ModelMixin.disable_gradient_checkpointingE  s#   € ð
 ×0×0Ø×,Ñ,°EÐ,Ò:ð 1rG   Úvalidc                 óâ   ^^• S[         R                  R                  4UU4S jjmU R                  5        H6  n[	        U[         R                  R                  5      (       d  M.  T" U5        M8     g)z-
Set the switch for the npu flash attention.
rq   c                 óˆ   >• [        U S5      (       a  U R                  T5        U R                  5        H  nT" U5        M     g )NÚset_use_npu_flash_attention)r    rê   Úchildren)rq   ÚchildÚ$fn_recursive_set_npu_flash_attentionrç   s     €€rD   rí   ÚTModelMixin.set_use_npu_flash_attention.<locals>.fn_recursive_set_npu_flash_attentionR  s8   ø€ Ü�vÐ<×=Ñ=Ø×2Ñ2°5Ô9àŸ™Ö*�Ù4°UÖ;ò +rG   N©rv   r   rŠ   rë   rž   )rC   rç   rq   rí   s    ` @rD   rê   Ú&ModelMixin.set_use_npu_flash_attentionM  sK   ù€ ð
	<¼¿¹¿¹÷ 	<ð 	<ð —m‘m–oˆFÜ˜&¤%§(¡(§/¡/×2Ó2Ù4°VÖ<ò &rG   c                 ó&   • U R                  S5        g)z,
Enable npu flash attention from torch_npu

TN©rê   rÓ   s    rD   Úenable_npu_flash_attentionÚ%ModelMixin.enable_npu_flash_attention]  s   € ð
 	×(Ñ(¨Õ.rG   c                 ó&   • U R                  S5        g)z-
disable npu flash attention from torch_npu

FNrò   rÓ   s    rD   Údisable_npu_flash_attentionÚ&ModelMixin.disable_npu_flash_attentiond  s   € ð
 	×(Ñ(¨Õ/rG   Úuse_xla_flash_attentionÚpartition_specc                 óê   ^^^^• S[         R                  R                  4UUUU4S jjmU R                  5        H6  n[	        U[         R                  R                  5      (       d  M.  T" U5        M8     g )Nrq   c                 óŽ   >• [        U S5      (       a  U R                  " TT40 TD6  U R                  5        H  nT" U5        M     g )NÚset_use_xla_flash_attention)r    rü   rë   )rq   rì   Ú fn_recursive_set_flash_attentionrP   rù   rø   s     €€€€rD   rý   ÚPModelMixin.set_use_xla_flash_attention.<locals>.fn_recursive_set_flash_attentionq  sA   ø€ Ü�vÐ<×=Ñ=Ø×2Ò2Ð3JÈNÑeÐ^dÒeàŸ™Ö*�Ù0°Ö7ò +rG   rï   )rC   rø   rù   rP   rq   rý   s    ``` @rD   rü   Ú&ModelMixin.set_use_xla_flash_attentionk  sK   û€ ð	8´U·X±X·_±_÷ 	8ò 	8ð —m‘m–oˆFÜ˜&¤%§(¡(§/¡/×2Ó2Ù0°Ö8ò &rG   c                 ó,   • U R                   " SU40 UD6  g)z:
Enable the flash attention pallals kernel for torch_xla.
TN©rü   )rC   rù   rP   s      rD   Úenable_xla_flash_attentionÚ%ModelMixin.enable_xla_flash_attention|  s   € ð 	×(Ò(¨¨~ÑHÀÓHrG   c                 ó&   • U R                  S5        g)z;
Disable the flash attention pallals kernel for torch_xla.
FNr  rÓ   s    rD   Údisable_xla_flash_attentionÚ&ModelMixin.disable_xla_flash_attention‚  s   € ð 	×(Ñ(¨Õ/rG   Úattention_opc                 óæ   ^^^• S[         R                  R                  4UUU4S jjmU R                  5        H6  n[	        U[         R                  R                  5      (       d  M.  T" U5        M8     g )Nrq   c                 óŠ   >• [        U S5      (       a  U R                  TT5        U R                  5        H  nT" U5        M     g )NÚ+set_use_memory_efficient_attention_xformers)r    r
  rë   )rq   rì   r  Úfn_recursive_set_mem_effrç   s     €€€rD   r  ÚXModelMixin.set_use_memory_efficient_attention_xformers.<locals>.fn_recursive_set_mem_effŒ  s:   ø€ Ü�vÐL×MÑMØ×BÑBÀ5È,ÔWàŸ™Ö*�Ù(¨Ö/ò +rG   rï   )rC   rç   r  rq   r  s    `` @rD   r
  Ú6ModelMixin.set_use_memory_efficient_attention_xformersˆ  sK   ú€ ð	0¬U¯X©X¯_©_÷ 	0ñ 	0ð —m‘m–oˆFÜ˜&¤%§(¡(§/¡/×2Ó2Ù(¨Ö0ò &rG   c                 ó(   • U R                  SU5        g)ux  
Enable memory efficient attention from [xFormers](https://facebookresearch.github.io/xformers/).

When this option is enabled, you should observe lower GPU memory usage and a potential speed up during
inference. Speed up during training is not guaranteed.

> [!WARNING] > âš ï¸� When memory efficient attention and sliced attention are both enabled, memory efficient
attention takes > precedent.

Parameters:
    attention_op (`Callable`, *optional*):
        Override the default `None` operator for use as `op` argument to the
        [`memory_efficient_attention()`](https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.memory_efficient_attention)
        function of xFormers.

Examples:

```py
>>> import torch
>>> from diffusers import UNet2DConditionModel
>>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp

>>> model = UNet2DConditionModel.from_pretrained(
...     "stabilityai/stable-diffusion-2-1", subfolder="unet", torch_dtype=torch.float16
... )
>>> model = model.to("cuda")
>>> model.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
```
TN©r
  )rC   r  s     rD   Ú*enable_xformers_memory_efficient_attentionÚ5ModelMixin.enable_xformers_memory_efficient_attention—  s   € ð< 	×8Ñ8¸¸|ÕLrG   c                 ó&   • U R                  S5        g)zc
Disable memory efficient attention from [xFormers](https://facebookresearch.github.io/xformers/).
FNr  rÓ   s    rD   Ú+disable_xformers_memory_efficient_attentionÚ6ModelMixin.disable_xformers_memory_efficient_attention·  s   € ð 	×8Ñ8¸Õ?rG   Ústorage_dtyper¢   Úskip_modules_pattern.Úskip_modules_classesÚnon_blockingc                 óÜ  • SSK Jn  SnUc
  SSKJn  UnSnU R                  b  U[        U R                  5      -  nU R                  b  U[        U R                  5      -  n[        [        U5      5      n[        5       (       a<  U(       d5  SSK	J
n	  SS	KJn
  SS
KJn  XšU4 H  nU[        UR                  5      -  nM     Uc!  [         R#                  S5        U R$                  nU" XX#XE5        g)a±  
Activates layerwise casting for the current model.

Layerwise casting is a technique that casts the model weights to a lower precision dtype for storage but
upcasts them on-the-fly to a higher precision dtype for computation. This process can significantly reduce the
memory footprint from model weights, but may lead to some quality degradation in the outputs. Most degradations
are negligible, mostly stemming from weight casting in normalization and modulation layers.

By default, most models in diffusers set the `_skip_layerwise_casting_patterns` attribute to ignore patch
embedding, positional embedding and normalization layers. This is because these layers are most likely
precision-critical for quality. If you wish to change this behavior, you can set the
`_skip_layerwise_casting_patterns` attribute to `None`, or call
[`~hooks.layerwise_casting.apply_layerwise_casting`] with custom arguments.

Example:
    Using [`~models.ModelMixin.enable_layerwise_casting`]:

    ```python
    >>> from diffusers import CogVideoXTransformer3DModel

    >>> transformer = CogVideoXTransformer3DModel.from_pretrained(
    ...     "THUDM/CogVideoX-5b", subfolder="transformer", torch_dtype=torch.bfloat16
    ... )

    >>> # Enable layerwise casting via the model, which ignores certain modules by default
    >>> transformer.enable_layerwise_casting(storage_dtype=torch.float8_e4m3fn, compute_dtype=torch.bfloat16)
    ```

Args:
    storage_dtype (`torch.dtype`):
        The dtype to which the model should be cast for storage.
    compute_dtype (`torch.dtype`):
        The dtype to which the model weights should be cast during the forward pass.
    skip_modules_pattern (`tuple[str, ...]`, *optional*):
        A list of patterns to match the names of the modules to skip during the layerwise casting process. If
        set to `None`, default skip patterns are used to ignore certain internal layers of modules and PEFT
        layers.
    skip_modules_classes (`tuple[Type[torch.nn.Module], ...]`, *optional*):
        A list of module classes to skip during the layerwise casting process.
    non_blocking (`bool`, *optional*, defaults to `False`):
        If `True`, the weight casting operations are non-blocking.
r   )Úapply_layerwise_castingTN)ÚDEFAULT_SKIP_MODULES_PATTERNFr   )Ú	LoHaLayer)Ú	LoKrLayer)Ú	LoraLayerzW`compute_dtype` not provided when enabling layerwise casting. Using dtype of the model.)Úhooksr  Úhooks.layerwise_castingr  r•   r‹   Ú _skip_layerwise_casting_patternsÚsetr'   Úpeft.tuners.loha.layerr  Úpeft.tuners.lokr.layerr  Úpeft.tuners.lora.layerr  Úadapter_layer_namesÚloggerÚinfor¤   )rC   r  r¢   r  r  r  r  Úuser_provided_patternsr  r  r  r  Úlayers                rD   Úenable_layerwise_castingÚ#ModelMixin.enable_layerwise_casting½  sâ   € õd 	4à!%ÐØÑ'ÝNà#?Ð Ø%*Ð"Ø×%Ñ%Ñ1Ø ¤E¨$×*DÑ*DÓ$EÑEÐ Ø×0Ñ0Ñ<Ø ¤E¨$×*OÑ*OÓ$PÑPÐ Ü$¤SÐ)=Ó%>Ó?Ðä×ÑÖ'=õ 9Ý8Ý8à#°	Ó:�Ø$¬¨e×.GÑ.GÓ(HÑHÒ$ñ ;ð Ñ Ü�K‰KÐqÔrØ ŸJ™JˆMáØ ÐFZõ	
rG   ÚcpuÚblock_levelÚonload_deviceÚoffload_deviceÚoffload_typeÚnum_blocks_per_groupÚ
use_streamÚrecord_streamÚoffload_to_disk_pathÚblock_modulesÚexclude_kwargsc                 ó  • SSK Jn  [        U SS5      b0  [        U SS5      (       a  U(       a  Sn[        R	                  U5        U R
                  (       d"  [        U R                  R                   S35      eU" U UUUUUUUUU	U
US	9  g)
aY  
Activates group offloading for the current model.

See [`~hooks.group_offloading.apply_group_offloading`] for more information.

Example:

    ```python
    >>> from diffusers import CogVideoXTransformer3DModel

    >>> transformer = CogVideoXTransformer3DModel.from_pretrained(
    ...     "THUDM/CogVideoX-5b", subfolder="transformer", torch_dtype=torch.bfloat16
    ... )

    >>> transformer.enable_group_offload(
    ...     onload_device=torch.device("cuda"),
    ...     offload_device=torch.device("cpu"),
    ...     offload_type="leaf_level",
    ...     use_stream=True,
    ... )
    ```
r   )Úapply_group_offloadingÚenable_tilingNÚ
use_tilingFa/  Applying group offloading on autoencoders, with CUDA streams, may not work as expected if the first forward pass is executed with tiling enabled. Please make sure to either:
1. Run a forward pass with small input shapes.
2. Or, run a forward pass with tiling disabled (can still use small dummy inputs).zü does not support group offloading. Please make sure to set the boolean attribute `_supports_group_offloading` to `True` in the class definition. If you believe this is a mistake, please open an issue at https://github.com/huggingface/diffusers/issues.)rq   r/  r0  r1  r2  r  r3  r4  Úlow_cpu_mem_usager5  r6  r7  )	r  r9  Úgetattrr'  ÚwarningÚ_supports_group_offloadingr‚   rÁ   rR   )rC   r/  r0  r1  r2  r  r3  r4  r<  r5  r6  r7  r9  Úmsgs                 rD   Úenable_group_offloadÚModelMixin.enable_group_offload  s¢   € õH 	3ä�4˜¨$Ó/Ñ;ÄÈÈlÐ\a×@bÑ@bÖgqðeð ô �N‰N˜3ÔØ×.×.ÜØ—>‘>×*Ñ*Ð+ð ,Tð Uóð ñ 	ØØ'Ø)Ø%Ø!5Ø%Ø!Ø'Ø/Ø!5Ø'Ø)ó	
rG   Úbackendc                 ój  • SSK Jn  SSKJnJnJnJn  SSKJnJ	n  [        R                  S5        XxU4n	Sn
U R                  5        H3  n[        X¹5      (       d  M  UR                  n[        USS5      c  M1  S	n
  O   UR!                  5       nUR"                  R%                  5        Vs1 s H  oÝR&                  iM     nnX;  a"  [)        S
U< S3SR+                  U5      -   5      eU" U5      nU
(       aG  UR-                  U5      (       d1  [/        UR0                  5      n[)        SUR&                   SU S35      eU" U5        U" U5        U R                  5        H=  n[        X¹5      (       d  M  UR                  nUb  [3        US5      (       d  M7  Xl        M?     UR7                  U5        gs  snf )ai  
Set the attention backend for the model.

Args:
    backend (`str`):
        The name of the backend to set. Must be one of the available backends defined in
        `AttentionBackendName`. Available backends can be found in
        `diffusers.attention_dispatch.AttentionBackendName`. Defaults to torch native scaled dot product
        attention as backend.
r/   ©ÚAttentionModuleMixin)ÚAttentionBackendNameÚ_AttentionBackendRegistryÚ%_check_attention_backend_requirementsÚ"_maybe_download_kernel_for_backend©Ú	AttentionÚMochiAttentionúTAttention backends are an experimental feature and the API may be subject to change.FÚ_parallel_configNTz	`backend=z ` must be one of the following: ú, z>Context parallelism is enabled but current attention backend 'zS' does not support context parallelism. Please set a compatible attention backend: z' using `model.set_attention_backend()`.Ú_attention_backend)Ú	attentionrF  Úattention_dispatchrG  rH  rI  rJ  Úattention_processorrL  rM  r'  r>  rÒ   rž   Ú	processorr=  ÚlowerÚ__members__ÚvaluesÚvaluer‚   ÚjoinÚ_is_context_parallel_availableÚsortedÚ_supports_context_parallelr    rQ  Úset_active_backend)rC   rC  rF  rG  rH  rI  rJ  rL  rM  Úattention_classesÚparallel_config_setrq   rU  ÚxÚavailable_backendsÚcompatible_backendss                   rD   Úset_attention_backendÚ ModelMixin.set_attention_backendV  s¦  € õ 	4÷	
ó 	
÷ 	Cä�‰ÐmÔnØ&Ð8LÐMÐà#ÐØ—l‘l–nˆFÜ˜f×8Ñ8ÙØ×(Ñ(ˆIÜ�yÐ"4°dÓ;ÓGØ&*Ð#Ùñ %ð —-‘-“/ˆØ/C×/OÑ/O×/VÑ/VÔ/XÓYÒ/X¨!ŸgœgÑ/XÐÐYØÓ,Ü˜z ¡
Ð*JÐKÈdÏiÉiÐXjÓNkÑkÓlÐlá& wÓ/ˆÞÐ'@×'_Ñ'_Ð`g×'hÑ'hÜ"(Ð)B×)]Ñ)]Ó"^ÐÜØPÐQX×Q^ÑQ^ÐP_ð `>à>QÐ=RÐRyð{óð ñ 	.¨gÔ6Ù*¨7Ô3à—l‘l–nˆFÜ˜f×8Ñ8ÙØ×(Ñ(ˆIØÑ ¬°	Ð;O×(PÑ(PÙØ+2Ö(ñ %ð 	"×4Ñ4°WÕ=ùò3 Zs   Â)F0c                 óö   • SSK Jn  SSKJnJn  [
        R                  S5        X#U4nU R                  5        H>  n[        XT5      (       d  M  UR                  nUb  [        US5      (       d  M7  SUl        M@     g)z¦
Resets the attention backend for the model. Following calls to `forward` will use the environment default, if
set, or the torch native scaled dot product attention.
r/   rE  rK  rN  NrQ  )rR  rF  rT  rL  rM  r'  r>  rÒ   rž   rU  r    rQ  )rC   rF  rL  rM  r_  rq   rU  s          rD   Úreset_attention_backendÚ"ModelMixin.reset_attention_backend”  sj   € õ
 	4ßBä�‰ÐmÔnà&Ð8LÐMÐØ—l‘l–nˆFÜ˜f×8Ñ8ÙØ×(Ñ(ˆIØÑ ¬°	Ð;O×(PÑ(PÙØ+/ˆIÖ(ò %rG   Úsave_directoryÚis_main_processÚsave_functionÚsafe_serializationÚvariantÚmax_shard_sizeÚpush_to_hubÚuse_flashpackc	           
      óæ  • [         R                  R                  U5      (       a  [        R	                  SU S35        g[        U SS5      n
U
b{  U
SL=(       a#    [        U
[        5      =(       a    U
R                  nU(       a  U(       a  U=(       a    U
R                  nU(       d#  [        SU
R                  R                   S35      e[        nU(       a  [        nOU(       a  [        n[!        XÅ5      nUR#                  SS5      R#                  S	S
5      n[         R$                  " USS9  U(       aš  U	R'                  SS5      nU	R'                  SS5      nU	R'                  SS5      nU	R'                  SS5      nU	R'                  SUR)                  [         R                  R*                  5      S   5      n[-        USUUS9R.                  nU nU(       a  UR1                  U5        UR3                  5       n0 nU
b  U
R5                  UUS9u  nnU(       ax  [7        5       (       a  SSKnO [        R	                  S5        [;        S5      eUR<                  R?                  U[         R                  RA                  X5      U RB                  S9  GOn[E        UXmS9nU(       Ga!  [         RF                  " U5       GH  nUURH                  RK                  5       ;   a  M$  [         R                  RA                  UU5      n[         R                  R                  U5      (       d  Mj  UR#                  SS5      R#                  S	S5      nUR#                  SS5      nUR#                  SS5      R#                  S	S5      nURM                  U5      (       d  MØ  [N        RQ                  U5      c  Mð  [         RR                  " U5        GM	     URH                  RU                  5        Hë  u  nnU Vs0 s H  nUUU   RW                  5       _M     nn[         R                  RA                  UU5      nU(       aƒ  SS0n U(       a  U RY                  U5        U RU                  5        V!V"s0 s H)  u  n!n"U![        U"[Z        5      (       d  [[        U"5      OU"_M+     n n!n"[\        R^                  Ra                  UUU S9  MÔ  [^        Rb                  " UU5        Mí     URd                  (       aê  [g        URh                  5      n U(       a  U RY                  U5        U URj                  S .n#U(       a  [l        O[n        n$[         R                  RA                  U[!        U$U5      5      n$[q        U$S!S"S#9 n%[r        Rt                  " U#S$SS%9S&-   n&U%Rw                  U&5        SSS5        [        Ry                  S'U S([{        URH                  5       S)U$ S*35        O7[         R                  RA                  X5      n'[        Ry                  S+U' 35        U(       aR  [}        WWS,9n([        U(5      n(U(Rc                  [�        US-5      Rƒ                  5       5        U R…                  UUUWWS.9  ggs  snf s  sn"n!f ! , (       d  f       NÝ= f)/a 	  
Save a model and its configuration file to a directory so that it can be reloaded using the
[`~models.ModelMixin.from_pretrained`] class method.

Arguments:
    save_directory (`str` or `os.PathLike`):
        Directory to save a model and its configuration file to. Will be created if it doesn't exist.
    is_main_process (`bool`, *optional*, defaults to `True`):
        Whether the process calling this is the main process or not. Useful during distributed training and you
        need to call this function on all processes. In this case, set `is_main_process=True` only on the main
        process to avoid race conditions.
    save_function (`Callable`):
        The function to use to save the state dictionary. Useful during distributed training when you need to
        replace `torch.save` with another method. Can be configured with the environment variable
        `DIFFUSERS_SAVE_MODE`.
    safe_serialization (`bool`, *optional*, defaults to `True`):
        Whether to save the model using `safetensors` or the traditional PyTorch way with `pickle`.
    variant (`str`, *optional*):
        If specified, weights are saved in the format `pytorch_model.<variant>.bin`.
    max_shard_size (`int` or `str`, defaults to `"10GB"`):
        The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size
        lower than this size. If expressed as a string, needs to be digits followed by a unit (like `"5GB"`).
        If expressed as an integer, the unit is bytes. Note that this limit will be decreased after a certain
        period of time (starting from Oct 2024) to allow users to upgrade to the latest version of `diffusers`.
        This is to establish a common default size for this argument across different libraries in the Hugging
        Face ecosystem (`transformers`, and `accelerate`, for example).
    push_to_hub (`bool`, *optional*, defaults to `False`):
        Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the
        repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
        namespace).
    kwargs (`dict[str, Any]`, *optional*):
        Additional keyword arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
zProvided path (z#) should be a directory, not a fileNÚhf_quantizerzThe model is quantized with z˜ and is not serializable - check out the warnings from the logger on the traceback to understand the reason why the quantized model is not serializable.z.binz{suffix}.binz.safetensorsz{suffix}.safetensorsT©Úexist_okÚcommit_messageÚprivateÚ	create_prFÚtokenÚrepo_idéÿÿÿÿ)rt  rv  rx  )rl  r   zÅSaving a FlashPack checkpoint in PyTorch, requires both PyTorch and flashpack to be installed. Please see https://pytorch.org/ and https://github.com/fal-ai/flashpack for installation instructions.zMPlease install torch and flashpack to save a FlashPack checkpoint in PyTorch.)Ústate_dict_or_modelÚdestination_pathÚtarget_dtype)rn  Úfilename_patternÚ z{suffix}ÚformatÚpt)Úmetadata)r‚  Ú
weight_mapÚwzutf-8)Úencodingr   )ÚindentÚ	sort_keysÚ
z:The model is bigger than the maximum size per checkpoint (z) and is going to be split in z^ checkpoint shards. You can find where each parameters has been saved in the index located at Ú.zModel weights saved in )rx  z	README.md)rx  ru  rw  )CÚosÚpathÚisfiler'  Úerrorr=  rž   r   Úis_serializableÚ"supports_safetensors_serializationr‚   Úquantization_configÚquant_methodr   r   r   r   ÚreplaceÚmakedirsÚpopÚsplitÚsepr   ry  Úsave_configÚ
state_dictÚget_state_dict_and_metadatar&   Ú	flashpackÚImportErrorÚserializationÚpack_to_filerZ  r¤   r   ÚlistdirÚfilename_to_tensorsÚkeysÚ
startswithÚ_REGEX_SHARDÚ	fullmatchÚremoveru   Ú
contiguousÚupdaterŒ   Úsafetensorsrv   Ú	save_fileÚsaveÚ
is_shardedÚdictr‚  Útensor_to_filenamer   r   ÚopenÚjsonÚdumpsÚwriter(  Úlenr,   r-   r   Úas_posixÚ_upload_folder))rC   ri  rj  rk  rl  rm  rn  ro  rp  rP   rr  Úquantization_serializableÚweights_nameÚweights_name_patternru  rv  rw  rx  ry  Úmodel_to_saver˜  Úquantization_metadatarš  Ústate_dict_splitÚfilenameÚfull_filenameÚweights_without_extÚfilename_without_extÚtensorsÚtensorÚshardÚfilepathr‚  ry   rz   ÚindexÚsave_index_fileÚfÚcontentÚpath_to_weightsÚ
model_cards)                                            rD   Úsave_pretrainedÚModelMixin.save_pretrained§  sª  € ôZ �7‰7�>‰>˜.×)Ñ)Ü�L‰L˜?¨>Ð*:Ð:]Ð^Ô_Øä˜t ^°TÓ:ˆØÑ#à DÐ(÷ 1Ü˜|Ô-?Ó@÷1à ×0Ñ0ð &ö
 "Ö&?à-×a°,×2aÑ2að *ö -Ü Ø2°<×3SÑ3S×3`Ñ3`Ð2að byð yóð ô
 $ˆÞÜ1‰LÞÜ3ˆLä# LÓ:ˆØ+×3Ñ3°F¸NÓK×SÑSØÐ2ó 
Ðô 	�Š�N¨TÒ2æØ#ŸZ™ZÐ(8¸$Ó?ˆNØ—j‘j ¨DÓ1ˆGØŸ
™
 ;°Ó6ˆIØ—J‘J˜w¨Ó-ˆEØ—j‘j ¨N×,@Ñ,@ÄÇÁÇÁÓ,MÈbÑ,QÓRˆGÜ! '°DÀ'ÐQVÑW×_Ñ_ˆGð ˆö Ø×%Ñ% nÔ5ð #×-Ñ-Ó/ˆ
Ø "ÐØÑ#Ø0<×0XÑ0XØÐ/Að 1Yð 1Ñ-ˆJÐ-ö Ü%×'Ñ'Ü ä—‘ðrôô "Ð"qÓrÐrà×#Ñ#×0Ñ0Ø$.Ü!#§¡§¡¨nÓ!KØ!ŸZ™Zð 1ó ô  BØ¨>ñ Ð÷
 Ü "§
¢
¨>× :�HØÐ#3×#GÑ#G×#LÑ#LÓ#NÓNÙ Ü$&§G¡G§L¡L°ÀÓ$J�MÜŸ7™7Ÿ>™>¨-×8Ñ8Ù Ø*>×*FÑ*FÀvÈrÓ*R×*ZÑ*ZÐ[iÐkmÓ*nÐ'Ø*=×*EÑ*EÀjÐRTÓ*UÐ'Ø+3×+;Ñ+;¸FÀBÓ+G×+OÑ+OÐP^Ð`bÓ+cÐ(ð !×+Ñ+Ð,?×@Ó@Ü(×2Ñ2Ð3GÓHÓTäŸ	š	 -×0ñ !;ð  &6×%IÑ%I×%OÑ%OÖ%QÑ!�˜'ÙOVÓWÊwÀV˜ ¨FÑ!3×!>Ñ!>Ó!@Ò@Éw�ÐWÜŸ7™7Ÿ<™<¨¸ÓA�Þ%Ø (¨$Ð/�HÞ,Ø Ÿ™Ð(=Ô>ØW_×WeÑWeÔWgÔhÒWgÉtÈqÐRS ´¸A¼s×1CÑ1C¤3 q¤6ÈÒ JÑWg�HÑhô  ×%Ñ%×/Ñ/°°xÈ(Ð/ÓSä—J’J˜u hÖ/ñ &Rð  ×*×*ÜÐ 0× 9Ñ 9Ó:�Þ(Ø—O‘OÐ$9Ô:à (Ø"2×"EÑ"Eñ�ö >PÕ"9ÔUg�Ü"$§'¡'§,¡,¨~¼|ÈOÐ]dÓ?eÓ"f�ä˜/¨3¸ÒAÀQÜ"Ÿjšj¨°qÀDÑIÈDÑP�GØ—G‘G˜GÔ$÷ Bô —‘ØPÐQ_ÐP`ð a Ü #Ð$4×$HÑ$HÓ IÐJð K(Ø(7Ð'8¸ð;õô #%§'¡'§,¡,¨~Ó"L�Ü—‘Ð5°oÐ5FÐGÔHæä2°7À%ÑHˆJÜ,¨ZÓ8ˆJØ�O‰OœD °Ó=×FÑFÓHÔIà×ÑØØØØ-Ø#ð  ò ð ùòI Xùó  i÷$ BÕAús   Ï&YÑ0YÕ +Y"Ù"
Y0c                 óZ   • [        U SS5      nUc  [        S5      eUR                  U 5      $ )zv
Potentially dequantize the model in case it has been quantized by a quantization method that support
dequantization.
rr  Nz?You need to first quantize your model in order to dequantize it)r=  r‚   Ú
dequantize)rC   rr  s     rD   rË  ÚModelMixin.dequantizeh  s5   € ô
 ˜t ^°TÓ:ˆàÑÜÐ^Ó_Ð_à×&Ñ& tÓ,Ð,rG   Úpretrained_model_name_or_pathc                 ó  • UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	S5      n	UR                  S
S5      n
UR                  SS5      nUR                  SS5      nUb  UOUnUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S[        5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S0 5      n[        nU(       a  U(       d  [        S5      eUbH  [	        U[
        R                  5      (       d)  [
        R                  n[        R                  SU S35        SnUc  SnSnU(       a&  [        5       (       d  Sn[        R                  S5        Ub  [        5       (       d  [        S 5      eUb  [        S!S"5      (       d  [        S#5      eUSL a  [        S!S"5      (       d  [        S$5      eUSL a  Ub  [        S%U S&35      e[	        U[
        R                  5      (       a  S'U0nO_[	        U[        5      (       a   US(;  a   S'[
        R                  " U5      0nO*[	        U[         5      (       a  US+:  a  [        S,5      eS'U0nUb  Uc  SnOU(       d  [        S-5      eU(       a  Ub  [        S!S.5      (       d  [        S/5      e["        S0S1[        U R$                  5      S2.n0 nUnU R&                  " U4USSUUUU	U
UUUS3.UD6u  n nn![(        R*                  " U 5      n SU ;   =(       a    U S   SLn"U"(       d  UbC  U"(       a  [,        R.                  " U S   U5      U S'   OUU S'   [,        R0                  " U S   U"S49n#OSn#U#bÆ  U#R3                  X¾S59  U#R5                  U5      nU#R7                  U5      nU#R8                  R:                  R<                  US6'   [>        R@                  " U#R8                  RC                  5       SS79n$[E        U$5      [F        ::  a  U$US8'   Uc  Sn[        RI                  S95        OU(       d  [        S:5      eU RJ                  SL=(       a    U#SL =(       d    [M        U#S;S5      n%U%(       aR  U RJ                  n&[	        U&[N        5      (       d  U&/n&Uc  Sn[        RI                  S<5        OU(       d  [        S=5      eO/ n&Sn'Sn(Sn)Sn*[P        RR                  RU                  U5      n+U+UU=(       d    S'UUUUUUU	U
UU!US>.n,[W        SW0 U,D6n*Ub2  U*b$  [P        RR                  RY                  U*5      (       d  [[        SW0 U,D6n*U*b  U(       d  U*R]                  5       (       a  Sn'U'(       a  [_        UU*UUUU	UU
U=(       d    S'US?9
u  n(n)O@U(       a  [`        n-OU(       a  [c        [d        U5      n-OSn-U-b   [g        UU-UUUUU	U
UUU!US@9n(U(c)  U'(       d"  [g        U[c        [l        U5      UUUUU	U
UUU!US@9n([	        U([N        5      (       d  U(/n(Sn/Ub_  U[M        [
        SDS5      :X  dJ  [	        U[
        R                  5      (       d  [        U SE[o        U5       S*35      eU Rq                  U5      n/[s        5       /n0U(       a$  U0Ru                  [v        Rx                  " 5       5        [{        U05         U R0                  " U 40 UD6n1SSS5        U(       Ga#  [}        5       (       a  S+SK?n2O [        Rk                  SF5        [�        SG5      eUc,  [        R                  SH5        [
        R                  " SI5      n3ObUS'   n4[	        U4[        5      (       a  U4S(;   a  [        SJ5      e[	        U4[
        R                  5      (       d  [
        R                  " U45      OU4n3U2R‚                  R„                  " SWW1U(S+   U3SK.UD6  U/b  [
        R†                  " U/5        U(       a  [        R                  SL5        U10 4$ U1$ U/b  [
        R†                  " U/5        Sn5U'(       d  [‰        U(S+   UUSM9n5W1R‹                  U55        U'(       a  U)SN   n6O[O        U5R�                  5       5      n6U(n7U#b  U#R�                  U6U75      n6U#b  U#R‘                  W1UU&SO9  U#b  U#R’                  (       d  Sn[•        W1XïUU&U#5      nU#b  U#R3                  USP9  U R—                  U1U5U(UU6UUUUUUU#U&UUUSQ9u  n1n8n9n:n;n<U8U9U:U<SR.n=Ub  UUU;SS.n>[™        U140 U>D6  U#b  U#R›                  U15        U#U1lN        Ub0  U[M        [
        SDS5      :X  a  U#c  U%(       d  U1RŸ                  U5      n1U#b  U1R¡                  XST9  OU1R¡                  USU9  U1R£                  5         Ub  U1R¥                  USV9  U(       a  U1U=4$ U1$ ! [         a    [        S)U S*35      ef = f! [h         aC  n.[        Rk                  SAU SBU. 35        U(       d  e [        R                  SC5         Sn.A.GN>Sn.A.ff = f! , (       d  f       GNP= f)Xu¨  
Instantiate a pretrained PyTorch model from a pretrained model configuration.

The model is set in evaluation mode - `model.eval()` - by default, and dropout modules are deactivated. To
train the model, set it back in training mode with `model.train()`.

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

            - A string, the *model id* (for example `google/ddpm-celebahq-256`) of a pretrained model hosted on
              the Hub.
            - A path to a *directory* (for example `./my_model_directory`) containing the model weights saved
              with [`~ModelMixin.save_pretrained`].

    cache_dir (`str | os.PathLike`, *optional*):
        Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
        is not used.
    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.
    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.
    subfolder (`str`, *optional*, defaults to `""`):
        The subfolder location of a model file within a larger model repository on the Hub or locally.
    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 (`int | str | torch.device` or `dict[str, 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. Defaults to `None`, meaning that the model will be loaded on CPU.

        Examples:

        ```py
        >>> from diffusers import AutoModel
        >>> import torch

        >>> # This works.
        >>> model = AutoModel.from_pretrained(
        ...     "stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", device_map="cuda"
        ... )
        >>> # This also works (integer accelerator device ID).
        >>> model = AutoModel.from_pretrained(
        ...     "stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", device_map=0
        ... )
        >>> # Specifying a supported offloading strategy like "auto" also works.
        >>> model = AutoModel.from_pretrained(
        ...     "stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", device_map="auto"
        ... )
        >>> # Specifying a dictionary as `device_map` also works.
        >>> model = AutoModel.from_pretrained(
        ...     "stabilityai/stable-diffusion-xl-base-1.0",
        ...     subfolder="unet",
        ...     device_map={"": torch.device("cuda")},
        ... )
        ```

        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://huggingface.co/docs/accelerate/en/concept_guides/big_model_inference#the-devicemap). You
        can also refer to the [Diffusers-specific
        documentation](https://huggingface.co/docs/diffusers/main/en/training/distributed_inference#model-sharding)
        for more concrete examples.
    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.
    variant (`str`, *optional*):
        Load weights from a specified `variant` filename such as `"fp16"` or `"ema"`.
    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.
    disable_mmap ('bool', *optional*, defaults to 'False'):
        Whether to disable mmap when loading a Safetensors model. This option can perform better when the model
        is on a network mount or hard drive, which may not handle the seeky-ness of mmap very well.
    use_flashpack (`bool`, *optional*, defaults to `False`):
        If set to `True`, the model is loaded from `flashpack` weights.
    flashpack_kwargs(`dict[str, Any]`, *optional*, defaults to `{}`):
        Kwargs passed to
        [`flashpack.deserialization.assign_from_file`](https://github.com/fal-ai/flashpack/blob/f1aa91c5cd9532a3dbf5bcc707ab9b01c274b76c/src/flashpack/deserialization.py#L408-L422)


> [!TIP] > To use private or [gated models](https://huggingface.co/docs/hub/models-gated#gated-models), log-in
with `hf > auth login`. You can also activate the special >
["offline-mode"](https://huggingface.co/diffusers/installation.html#offline-mode) to use this method in a >
firewalled environment.

Example:

```py
from diffusers import UNet2DConditionModel

unet = UNet2DConditionModel.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="unet")
```

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

```bash
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.
```
Ú	cache_dirNÚignore_mismatched_sizesFÚforce_downloadÚproxiesÚoutput_loading_infoÚlocal_files_onlyrx  ÚrevisionÚtorch_dtyper¤   Ú	subfolderÚ
device_mapÚ
max_memoryÚoffload_folderÚoffload_state_dictr<  rm  Úuse_safetensorsr�  Údduf_entriesÚdisable_mmapÚparallel_configrp  Úflashpack_kwargszEParallel loading is not supported when not using `low_cpu_mem_usage`.zPassed `torch_dtype` z7 is not a `torch.dtype`. Defaulting to `torch.float32`.Ta,  Cannot initialize model with low cpu memory usage because `accelerate` was not found in the environment. Defaulting to `low_cpu_mem_usage=False`. It is strongly recommended to install `accelerate` for faster and less memory-intense model loading. You can do so with: 
```
pip install accelerate
```
.z©Loading and dispatching requires `accelerate`. Please make sure to install accelerate or set `device_map=None`. You can install accelerate with `pip install accelerate`.rh   ri   ztLoading and dispatching requires torch >= 1.9.0. Please either update your PyTorch version or set `device_map=None`.z~Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set `low_cpu_mem_usage=False`.zEYou cannot set `low_cpu_mem_usage` to `False` while using device_map=zO for loading and dispatching. Please make sure to set `low_cpu_mem_usage=True`.r  )ÚautoÚbalancedÚbalanced_low_0Ú
sequentialzœWhen passing device_map as a string, the value needs to be a device name (e.g. cpu, cuda:0) or 'auto', 'balanced', 'balanced_low_0', 'sequential' but found r‰  r   znYou can't pass device_map as a negative int. If you want to put the model on the cpu, pass device_map = 'cpu' z>Passing along a `device_map` requires `low_cpu_mem_usage=True`z1.10z=`low_cpu_mem_usage` and `device_map` require PyTorch >= 1.10.ÚmodelÚpytorch)Ú	diffusersÚ	file_typeÚ	frameworkÚmodel_class)rÏ  Úreturn_unused_kwargsÚreturn_commit_hashrÑ  rÒ  rÔ  rx  rÕ  r×  Ú
user_agentrÝ  )Úpre_quantized)rÖ  rØ  Úquant)r‡  Úquant_configz>Set `low_cpu_mem_usage` to True as `hf_quantizer` is not None.zD`low_cpu_mem_usage` cannot be False or None when using quantization.Úuse_keep_in_fp32_moduleszGSet `low_cpu_mem_usage` to True as `_keep_in_fp32_modules` is not None.zH`low_cpu_mem_usage` cannot be False when `keep_in_fp32_modules` is True.)Úis_localrÍ  r×  rÜ  rÏ  rm  rÑ  rÒ  rÔ  rx  rÕ  rí  Úcommit_hashrÝ  )rÏ  rÒ  rÔ  rx  rí  rÕ  r×  rÝ  )rµ  rÏ  rÑ  rÒ  rÔ  rx  rÕ  r×  rí  ró  rÝ  z(An error occurred while trying to fetch z: zXDefaulting to unsafe serialization. Pass `allow_pickle=False` to raise an error instead.Úfloat8_e4m3fnzA needs to be of type `torch.dtype`, e.g. `torch.float16`, but is zÆLoading a FlashPack checkpoint in PyTorch, requires both PyTorch and flashpack to be installed. Please see https://pytorch.org/ and https://github.com/fal-ai/flashpack for installation instructions.zMPlease install torch and flashpack to load a FlashPack checkpoint in PyTorch.zŠ`device_map` has not been provided for FlashPack, model will be on `cpu` - provide `device_map` to fully utilize the benefit of FlashPack.r-  z°FlashPack `device_map` should not be one of `auto`, `balanced`, `balanced_low_0`, `sequential`. Use a specific device instead, e.g., `device_map='cuda'` or `device_map='cuda:0')rå  r‹  rˆ   z6`output_loading_info` is not supported with FlashPack.)rÞ  rÝ  Úall_checkpoint_keys)rå  rØ  Úkeep_in_fp32_modules)rØ  )rÐ  r<  rØ  rÚ  rÛ  r¤   rr  rö  rÝ  Úis_parallel_loading_enabledrÞ  )Úmissing_keysÚunexpected_keysÚmismatched_keysÚ
error_msgs)rØ  Úoffload_dirÚoffload_index)r½   Ú_pre_quantization_dtype)r½   )ÚconfigrY   )Sr”  Ú_LOW_CPU_MEM_USAGE_DEFAULTr   ÚNotImplementedErrorrž   rv   r¤   Úfloat32r'  r>  r#   r(   r‚   rˆ   rŒ   ÚRuntimeErrorÚintr   rR   Úload_configÚcopyÚdeepcopyr   Úmerge_quantization_configsÚfrom_configÚvalidate_environmentÚupdate_torch_dtypeÚupdate_device_mapr�  r‘  rY  r®  r¯  Úto_dictr±  Ú"_MAX_QUANT_CONFIG_USER_AGENT_CHARSr(  r•   r=  rW   rŠ  r‹  Úisdirr7   Úexistsr8   Úis_filer    r   r   r   r!   ÚIOErrorr�  r   rÈ   Ú_set_default_torch_dtyper·   ÚappendÚ
accelerateÚinit_empty_weightsr=   r&   rš  r›  ÚmixinÚassign_from_fileÚset_default_dtyper;   Ú_fix_state_dict_keys_on_loadr   Úmaybe_update_loaded_keysÚpreprocess_modelÚsupports_parallel_loadingr5   Ú_load_pretrained_modelrj   Úpostprocess_modelrr  ÚtoÚregister_to_configÚevalÚenable_parallelism)?ÚclsrÍ  rP   rÏ  rÐ  rÑ  rÒ  rÓ  rÔ  rx  rÕ  rÖ  r¤   r×  rØ  rÙ  rÚ  rÛ  r<  rm  rÜ  r�  rÝ  rÞ  rß  rp  rà  r÷  Úallow_picklerí  Úunused_kwargsÚconfig_pathrÿ  ró  rî  rr  Úserialized_quant_configrñ  rö  rª  Úresolved_model_fileÚsharded_metadataÚ
index_filerò  Úindex_file_kwargsrµ  ÚeÚ
dtype_origÚinit_contextsrå  rš  Úflashpack_devicerˆ   r˜  Úloaded_keysÚcheckpoint_filesrø  rù  rú  rý  rû  Úloading_infoÚdevice_map_kwargss?                                                                  rD   Úfrom_pretrainedÚModelMixin.from_pretrainedt  sÿ  € ðL —J‘J˜{¨DÓ1ˆ	Ø"(§*¡*Ð-FÈÓ"NÐØŸ™Ð$4°eÓ<ˆØ—*‘*˜Y¨Ó-ˆØ$Ÿj™jÐ)>ÀÓFÐØ!Ÿ:™:Ð&8¸$Ó?ÐØ—
‘
˜7 DÓ)ˆØ—:‘:˜j¨$Ó/ˆØ—j‘j °Ó5ˆØ—
‘
˜7 DÓ)ˆØ$Ñ0‘e°kˆØ—J‘J˜{¨DÓ1ˆ	Ø—Z‘Z ¨dÓ3ˆ
Ø—Z‘Z ¨dÓ3ˆ
ØŸ™Ð$4°dÓ;ˆØ#ŸZ™ZÐ(<¸dÓCÐØ"ŸJ™JÐ':Ô<VÓWÐØ—*‘*˜Y¨Ó-ˆØ Ÿ*™*Ð%6¸Ó=ˆØ$Ÿj™jÐ)>ÀÓEÐØ4:·J±J¸~ÈtÓ4TˆØ—z‘z .°%Ó8ˆØIOÏÉÐTeÐgkÓIlˆØŸ
™
 ?°EÓ:ˆØ!Ÿ:™:Ð&8¸"Ó=Ðä&@Ð#Þ&Ö/@Ü%Ð&mÓnÐnàÑ"¬:°kÄ5Ç;Á;×+OÑ+OÜŸ-™-ˆKÜ�N‰NØ'¨ }Ð4kÐlôð ˆØÑ"Ø"ˆOØˆLæÔ%<×%>Ñ%>Ø %ÐÜ�N‰Nð.ôð Ñ!Ô*A×*CÑ*CÜ%ð`óð ð Ñ!Ô*:¸4À×*IÑ*IÜ%ð&óð ð
  Ò$Ô-=¸dÀG×-LÑ-LÜ%ð.óð ð
  Ò%¨*Ñ*@ÜØWÐXbÐWcð dRð Róð ô �j¤%§,¡,×/Ñ/Ø˜jÐ)‰JÜ˜
¤C×(Ñ(¨ZÐ?sÓ-sðØ ¤%§,¢,¨zÓ":Ð;‘
ô ˜
¤C×(Ñ(Ø˜A‹~Ü ð Eóð ð ! *Ð-�
àÑ!Ø Ñ(Ø$(Ñ!Þ&Ü Ð!aÓbÐbæØÑ%Ô.>¸tÀV×.LÑ.Lä Ð!`ÓaÐaô %Ø Ø"Ü˜sŸ|™|Ó,ñ	
ˆ
ð ˆð 4ˆð .1¯_ª_Øð.
àØ!%Ø#Ø)ØØ-ØØØØ!Ø%ñ.
ð ñ.
Ñ*ˆ�˜{ô  —’˜vÓ&ˆð .°Ñ7×e¸FÐCXÑ<YÐaeÐ<eˆÞÐ/Ñ;ÞÜ0F×0aÒ0aØÐ0Ñ1Ð3Fó1�Ð,Ò-ð 1D�Ð,Ñ-Ü1×=Ò=ØÐ,Ñ-¸]ñ‰Lð  ˆLàÑ#Ø×-Ñ-¸+Ð-Ñ]Ø&×9Ñ9¸+ÓFˆKØ%×7Ñ7¸
ÓCˆJð #/×"BÑ"B×"OÑ"O×"UÑ"UˆJ�wÑô '+§j¢j°×1QÑ1Q×1YÑ1YÓ1[ÐgkÑ&lÐ#ÜÐ*Ó+Ô/QÓQØ-D�
˜>Ñ*ð !Ñ(Ø$(Ð!Ü—‘Ð\Õ]Þ&Ü Ð!gÓhÐhð $'×#<Ñ#<ÀDÐ#H÷ $
Ø˜DÐ ×\¤G¨LÐ:TÐV[Ó$\ð 	!ö $Ø#&×#<Ñ#<Ð ÜÐ2´D×9Ñ9Ø(<Ð'=Ð$à Ñ(Ø$(Ð!Ü—‘ÐeÕfÞ&Ü Ð!kÓlÐlð 'ð $&Ð àˆ
Ø"Ðð  ÐØˆ
Ü—7‘7—=‘=Ð!>Ó?ˆà Ø-JØ"Ÿ bØ.Ø"ØØ,ØØ 0ØØ Ø$Ø&Ø(ñ
Ðô  'Ñ;Ð):Ñ;ˆ
ð Ñ JÑ$6¼b¿g¹g¿n¹nÈZ×>XÑ>XÜ1ÑFÐ4EÑFˆJØÑ!¦|°z×7IÑ7I×7KÑ7KØˆJö Ü4OØ-ØØ#ØØ!1ØØ%Ø!Ø#Ÿ/ rØ)ñ5Ñ1ÐÑ!1ö Ü5‘Þ Ü+Ô,DÀgÓN‘à#�ØÑ'ðÜ*9Ø5Ø%1Ø"+Ø'5Ø 'Ø)9Ø#Ø!)Ø"+Ø#-Ø$/Ø%1ñ+Ð'ð. Ñ&®zÜ"1Ø-Ü)¬,¸Ó@Ø#Ø-ØØ!1ØØ!Ø#Ø%Ø'Ø)ñ#Ðô Ð-¬t×4Ñ4Ø#6Ð"7Ðð
 ˆ
ØÑ"¨;¼'Ä%ÈÐZ^Ó:_Ó+_Ü˜k¬5¯;©;×7Ñ7Ü Ø"�mÐ#dÔeiÐjuÓevÐdwÐwxÐyóð ð ×5Ñ5°kÓBˆJä(Ó*Ð+ˆæØ× Ñ ¤×!>Ò!>Ó!@ÔAä˜]Õ+Ø—O’O FÑ<¨mÑ<ˆE÷ ,÷ Ü%×'Ñ'Ü ä—‘ðrôô "Ð"qÓrÐràÑ!Ü—‘ð0ôô $)§<¢<°Ó#6Ñ à# B™�Ü˜f¤c×*Ñ*¨vÐ9mÓ/mÜ$ð Kóð ô @JÈ&ÔRW×R^ÑR^×?_Ñ?_¤5§<¢<°Ô#7ÐekÐ à�O‰O×,Ò,ð ØØ(¨Ñ+Ø'ñð #ò	ð Ñ%Ü×'Ò'¨
Ô3Þ"Ü—‘ÐWÔXØ˜b�yÐ àˆLàÑ!Ü×#Ò# JÔ/àˆ
Þä(Ð)<¸QÑ)?ÈlÐiuÑvˆJà×.Ñ.¨zÔ:æØ*Ð+@ÑA‰Kä˜zŸ™Ó0Ó1ˆKà.ÐØÑ#Ø&×?Ñ?ÀÐM]Ó^ˆKàÑ#Ø×)Ñ)ØØ%Ø%9ð *ñ ð Ñ#¨L×,R×,RØ*/Ð'ô +Ø�:¨;Ð8LÈló
ˆ
ð Ñ#Ø×-Ñ-¸Ð-ÑDð ×&Ñ&ØØØØ)ØØ$;Ø/Ø!Ø)Ø1ØØ%Ø!5Ø%Ø(CØ%ð! 'ð 
ñ	
ØØØØØØð( )Ø.Ø.Ø$ñ	
ˆð Ñ!à(Ø-Ø!.ñ!Ðô
 ˜5Ñ6Ð$5Ò6àÑ#Ø×*Ñ*¨5Ô1Ø!-ˆEÔð Ñ#Øœw¤u¨o¸tÓDÓDØÑ$Þ,à—H‘H˜[Ó)ˆEàÑ#ð ×$Ñ$Ð3PÐ$Òvà×$Ñ$Ð3PÐ$ÑQð 	�
‰
ŒàÑ&Ø×$Ñ$¨OÐ$Ñ<æØ˜,Ð&Ð&àˆøô_  ó Ü ðTØT^ÐS_Ð_`ðbóð ðûôd ó Ü—L‘LÐ#KÐLiÐKjÐjlÐmnÐloÐ!pÔqÞ'ØÜ—N‘NØr÷ò ûð	ú÷V ,Ö+ús0   Ìj Új  Þk0êjê 
k-ê*8k(ë(k-ë0
k?c                 óÖ  >• SSK Jn  [        U SS 5      [        R                  :X  ax  [        U SS5      (       a*  [        SS5      (       a  [        SU R                   S	35      e[        U S
S5      (       a*  [        SS5      (       a  [        SU R                   S35      eU" U 5      (       a/  [        R                  SU R                  R                   S35        U $ [        TU ]4  " U0 UD6$ )Nr   ©Ú_is_group_offload_enabledÚquantization_methodÚis_loaded_in_8bitFÚ<ú0.48.0z‚Calling `cuda()` is not supported for `8-bit` quantized models with the installed version of bitsandbytes. The current device is `úL`. If you intended to move the model, please install bitsandbytes >= 0.48.0.Úis_loaded_in_4bitú0.43.2z‚Calling `cuda()` is not supported for `4-bit` quantized models with the installed version of bitsandbytes. The current device is `úL`. If you intended to move the model, please install bitsandbytes >= 0.43.2.úThe module 'zD' is group offloaded and moving it using `.cuda()` is not supported.)r�   r9  r=  r   ÚBITS_AND_BYTESr%   r‚   rˆ   r'  r>  rÁ   rR   r¿   Úcuda)rC   rO   rP   r9  rÁ   s       €rD   rD  ÚModelMixin.cuda½  sû   ø€ åFô �4Ð.°Ó5Ô9K×9ZÑ9ZÓZÜ�tÐ0°%×8Ñ8Ô=TÐUXÐZb×=cÑ=cÜ ð.Ø.2¯k©k¨]ð  ;GðHóð ô ˜Ð2°E×:Ñ:Ô?VÐWZÐ\d×?eÑ?eÜ ð.Ø.2¯k©k¨]ð  ;GðHóð ñ % T×*Ñ*Ü�N‰NØ˜tŸ~™~×6Ñ6Ð7Ð7{Ð|ôð ˆKä‰wŠ|˜TÐ, VÑ,Ð,rG   c                 ó  >• SSK Jn  U R                  =(       d    / n[        S U 5       5      =(       d    SU;   nSU;   nU H3  n[	        U[
        5      (       d  M   [        R                  " U5        SnM5     U(       d,  U H&  n[	        U[        R                  5      (       d  M$  Sn  O   U(       a3  Ub0  [        R                  SU R                  R                   SU S	35        [        U S
S5      (       a  U(       a  [        S5      e[        U SS 5      [         R"                  :X  ax  [        U SS5      (       a*  [%        SS5      (       a  [        SU R                   S35      e[        U SS5      (       a*  [%        SS5      (       a  [        SU R                   S35      eU" U 5      (       a6  U(       a/  [        R                  SU R                  R                   S35        U $ [&        TU ]P  " U0 UD6$ ! [         a     GMÀ  f = f)Nr   r8  c              3   óV   #   • U  H  n[        U[        R                  5      v •  M!     g 7frA   )rž   rv   rˆ   )r—   Úargs     rD   rš   Ú ModelMixin.to.<locals>.<genexpr>Þ  s    é € Ð)XÒSWÈC¬*°S¼%¿,¹,×*GÐ*GÒSWùs   ‚')rˆ   r¤   TzThere are modules in z! that should be kept in float32: z“. Casting directly with `to()` can lead to inconsistent results; set `torch_dtype` in `from_pretrained()` instead to keep these modules in float32.Úis_quantizedFzÍCasting a quantized model to a new `dtype` is unsupported. To set the dtype of unquantized layers, please use the `torch_dtype` argument when loading the model using `from_pretrained` or `from_single_file`r:  r;  r<  r=  z€Calling `to()` is not supported for `8-bit` quantized models with the installed version of bitsandbytes. The current device is `r>  r?  r@  z€Calling `to()` is not supported for `4-bit` quantized models with the installed version of bitsandbytes. The current device is `rA  rB  zB' is group offloaded and moving it using `.to()` is not supported.)r�   r9  r•   r¥   rž   rŒ   rv   rˆ   r  r¤   r'  r>  rÁ   rR   r=  r‚   r   rC  r%   r¿   r   )	rC   rO   rP   r9  Úfp32_modulesÚdevice_arg_or_kwarg_presentÚdtype_present_in_argsrH  rÁ   s	           €rD   r   ÚModelMixin.toØ  s  ø€ åFà×1Ñ1×7°Rˆä&)Ñ)XÑSWÓ)XÓ&X×&nÐ\dÐhnÑ\nÐ#Ø '¨6Ñ 1Ðó ˆCÜ˜c¤3×'Ñ'ÙðÜ—’˜SÔ!Ø.2Ò+ñ ö %Û�Ü˜c¤5§;¡;×/Ó/Ø,0Ð)Ùñ ö
 ! \Ñ%=Ü�N‰NØ'¨¯©×(?Ñ(?Ð'@Ð@aÐbnÐaoð  pCð  Dôô �4˜¨×/Ñ/Þ$Ü ðzóð ô
 �4Ð.°Ó5Ô9K×9ZÑ9ZÓZÜ�tÐ0°%×8Ñ8Ô=TÐUXÐZb×=cÑ=cÜ ð.Ø.2¯k©k¨]ð  ;GðHóð ô ˜Ð2°E×:Ñ:Ô?VÐWZÐ\d×?eÑ?eÜ ð.Ø.2¯k©k¨]ð  ;GðHóð ñ % T×*Ñ*Ö/JÜ�N‰NØ˜tŸ~™~×6Ñ6Ð7Ð7yÐzôð ˆKä‰wŠz˜4Ð* 6Ñ*Ð*øôM  ó Ûðús   ÁG4Ç4
HÈHc                 óX   >• [        U SS5      (       a  [        S5      e[        TU ]  " U6 $ )NrJ  FzŒ`.half()` is not supported for quantized model. Please use the model as it is, since the model has already been cast to the correct `dtype`.)r=  r‚   r¿   Úhalf©rC   rO   rÁ   s     €rD   rP  ÚModelMixin.half  s6   ø€ ä�4˜¨×/Ñ/ÜðGóð ô
 ‘7’< Ð&Ð&rG   c                 óX   >• [        U SS5      (       a  [        S5      e[        TU ]  " U6 $ )NrJ  Fz�`.float()` is not supported for quantized model. Please use the model as it is, since the model has already been cast to the correct `dtype`.)r=  r‚   r¿   ÚfloatrQ  s     €rD   rT  ÚModelMixin.float  s6   ø€ ä�4˜¨×/Ñ/ÜðGóð ô
 ‘7’= $Ð'Ð'rG   c                 ó0  • [        U SS5      nU(       d#  [        SU R                  R                   S35      eSnU R	                  5        H3  nUR                  R                  U;   d  M  UR
                  " U0 UD6  SnM5     U(       d  [        SU S35      eg)	u�  
Compiles *only* the frequently repeated sub-modules of a model (e.g. the Transformer layers) instead of
compiling the entire model. This techniqueâ€”often called **regional compilation** (see the PyTorch recipe
https://docs.pytorch.org/tutorials/recipes/regional_compilation.html) can reduce end-to-end compile time
substantially, while preserving the runtime speed-ups you would expect from a full `torch.compile`.

The set of sub-modules to compile is discovered by the presence of **`_repeated_blocks`** attribute in the
model definition. Define this attribute on your model subclass as a list/tuple of class names (strings). Every
module whose class name matches will be compiled.

Once discovered, each matching sub-module is compiled by calling `submodule.compile(*args, **kwargs)`. Any
positional or keyword arguments you supply to `compile_repeated_blocks` are forwarded verbatim to
`torch.compile`.
Ú_repeated_blocksNzM`_repeated_blocks` attribute is empty. Set `_repeated_blocks` for the class `z&` to benefit from faster compilation. FTz$Regional compilation failed because z% classes are not found in the model. )r=  r‚   rÁ   rR   rÒ   Úcompile)rC   rO   rP   Úrepeated_blocksÚhas_compiled_regionÚsubmods         rD   Úcompile_repeated_blocksÚ"ModelMixin.compile_repeated_blocks&  s©   € ô " $Ð(:¸DÓAˆæÜð9Ø9=¿¹×9PÑ9PÐ8QÐQwðyóð ð $ÐØ—l‘l–nˆFØ×Ñ×(Ñ(¨OÕ;Ø—’ Ð/¨Ò/Ø&*Ò#ñ %ö
 #ÜØ6°Ð6GÐGlÐmóð ð #rG   )Úcp_planrÿ  r^  c          
      óè  • [         R                  S5        [        R                  R	                  5       (       d.  [        R                  R                  5       (       d  [        S5      eSSKJn  SSK	J
n  SSKJnJn  SSKJnJn  [#        U[$        5      (       a
  ['        US	9nO[#        U[(        5      (       a	  ['        US
9n[        R                  R+                  5       n	[        R                  R-                  5       n
[        R.                  R1                  5       R2                  n[        R4                  " U5      n[        R6                  " X¹UR9                  5       -  5      nXxU4nUR:                  bÔ  U R=                  5        HÀ  n[#        Xþ5      (       d  M  UR>                  nUb  [A        US5      (       d  M7  URB                  nUc  URE                  5       u  nnOU" U5      nURG                  U5      (       dH  [I        URJ                  5      n[M        SURN                  RP                   SURR                   SU S35      e  O   S nUR:                  b]  UR:                  nURT                  =(       d=    [        R                  RV                  RY                  UURZ                  UR\                  S9nO`UR^                  bS  UR^                  nURT                  =(       d4    [        R                  RV                  RY                  UUR`                  4SS9nURc                  XšUUS9  Xl2        UR:                  b‘  U R=                  5        H>  n[#        Xþ5      (       d  M  UR>                  nUb  [A        US5      (       d  M7  UUl2        M@     Uc  U Rf                  c  [M        S5      eUb  UOU Rf                  nU" XR:                  U5        UR^                  bŸ  U Rh                  c#  [M        SU RN                  RP                   S35      eUR^                  Rj                  n[m        U Rn                  SS 5      nUb  UU-  S:w  a  [M        SU SU S35      eSSK8J9n  U" XR^                  U Rh                  5        g g )Nz•`enable_parallelism` is an experimental feature. The API may change in the future and breaking changes may be introduced at any time without warning.zXtorch.distributed must be available and initialized before calling `enable_parallelism`.r   )Úapply_context_parallelr/   rE  )rG  rH  rK  )Úcontext_parallel_config)Útensor_parallel_configrQ  z<Context parallelism is enabled but the attention processor 'z' is using backend 'zY' which does not support context parallelism. Please set a compatible attention backend: zS using `model.set_attention_backend()` before calling `model.enable_parallelism()`.)Údevice_typeÚ
mesh_shapeÚmesh_dim_names)Útp)ÚmeshrO  z\`cp_plan` must be provided either as an argument or set in the model's `_cp_plan` attribute.zF`_tp_plan` must be set on the model class to use tensor parallelism. 'z' does not define one.Únum_attention_headsr   z`tp_degree` (z-) must divide the number of attention heads (z).)Úapply_tensor_parallel):r'  r>  rv   ÚdistributedÚis_availableÚis_initializedr  Úhooks.context_parallelr`  rR  rF  rS  rG  rH  rT  rL  rM  rž   r0   r2   r3   Úget_rankÚget_world_sizeÚ_CÚ_get_acceleratorrÈ   Úget_device_modulerˆ   Údevice_countra  rÒ   rU  r    rQ  Úget_active_backendr[  r\  r]  r‚   rÁ   rR   rY  rg  Údevice_meshÚinit_device_meshrd  re  rb  Ú	tp_degreeÚsetuprO  Ú_cp_planÚ_tp_planÚ
_tp_degreer=  rÿ  Úhooks.tensor_parallelri  )rC   rÿ  r^  r`  rF  rG  rH  rL  rM  ÚrankÚ
world_sizerc  Údevice_modulerˆ   r_  rq   rU  Úattention_backendÚ_rc  rg  Ú	cp_configÚ	tp_configrw  Ú	num_headsri  s                             rD   r#  ÚModelMixin.enable_parallelismG  s  € ô 	�‰ð dô	
ô × Ñ ×-Ñ-×/Ñ/¼×8IÑ8I×8XÑ8X×8ZÑ8ZÜØjóð õ 	DÝ3ßWßBä�fÔ3×4Ñ4Ü#¸FÑC‰FÜ˜Ô 4×5Ñ5Ü#¸6ÑBˆFä× Ñ ×)Ñ)Ó+ˆÜ×&Ñ&×5Ñ5Ó7ˆ
Ü—h‘h×/Ñ/Ó1×6Ñ6ˆÜ×/Ò/°Ó<ˆÜ—’˜k°-×2LÑ2LÓ2NÑ+NÓOˆà&Ð8LÐMÐà×)Ñ)Ñ5ØŸ,™,ž.�Ü! &×<Ñ<Ùà"×,Ñ,�	ØÑ$¬G°IÐ?S×,TÑ,TÙà$-×$@Ñ$@Ð!Ø$Ñ,Ø+D×+WÑ+WÓ+YÑ(Ð%¡qá(<Ð=NÓ(OÐ%à0×OÑOÐPa×bÑbÜ*0Ð1J×1eÑ1eÓ*fÐ'Ü$ØVÐW`×WjÑWj×WsÑWsÐVtð u-Ø->×-DÑ-DÐ,Eð FFØFYÐEZð [@ðAóð ñ ñ3 )ð6 ˆØ×)Ñ)Ñ5Ø×6Ñ6ˆIØ—>‘>÷ ¤U×%6Ñ%6×%BÑ%B×%SÑ%SØ'Ø$×/Ñ/Ø(×7Ñ7ð &Tð &‰Dð
 ×*Ñ*Ñ6Ø×5Ñ5ˆIØ—>‘>÷ ¤U×%6Ñ%6×%BÑ%B×%SÑ%SØ'Ø%×/Ñ/Ð1Ø&ð &Tð &ˆDð 	�‰�T v°DˆÑ9Ø &Ôð
 ×)Ñ)Ñ5ØŸ,™,ž.�Ü! &×<Ñ<ÙØ"×,Ñ,�	ØÑ$¬G°IÐ?Q×,RÑ,RÙØ-3�	Ö*ñ )ð ‰ 4§=¡=Ñ#8Ü Øróð ð ")Ñ!4‘g¸$¿-¹-ˆGÙ" 4×)GÑ)GÈÔQà×(Ñ(Ñ4Ø�}‰}Ñ$Ü ðØŸ™×/Ñ/Ð0Ð0FðHóð ð ×5Ñ5×@Ñ@ˆIÜ §¡Ð-BÀDÓIˆIØÑ$¨°YÑ)>À!Ó)CÜ  =°°Ð;hÐirÐhsÐsuÐ!vÓwÐwåEá! $×(EÑ(EÀtÇ}Á}ÕUð 5rG   r˜  r)  r1  rÐ  Úassign_to_params_buffersrr  r<  r¤   rö  rØ  rÛ  rÚ  rÝ  r÷  rÞ  c                 óü  • UR                  5       n[        UR                  5       5      n[        [        U5      [        U5      -
  5      nUb  UR	                  UUSS9n[        [        U5      [        U5      -
  5      nU R
                  b?  U R
                   H/  nU Vs/ s H  n[        R                  " UU5      b  M  UPM!     nnM1     / n/ nUb<  SUR                  5       ;   a(  Uc  [        S5      e[        R                  " USS9  Uc  SnUb  [        UU5      n[        UUX¨5        Ub  SUR                  5       ;   a  0 OS nSu  nnU(       a  [        R                  " 5       n0 nUb  U/n[         R"                  " U(       a  [$        O[&        40 SU_S	U_S
U_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU	_SU_6nU(       a  U" U5      u  nnnn UU -  nUU-  nO`Un![)        U5      S:”  a/  SS0n"[+        5       (       d  SU"S'   [,        R.                  " U40 U"D6n!U! H  n#U" U#5      u  nnnn UU -  nUU-  nM     [1        5         UbG  [)        U5      S:”  a8  [3        UU5        S nU(       a#  [5        UUU5        [6        R8                  " U5        [)        U5      S:”  aA  SR;                  U5      n$SU$;   a  U$S-  n$[=        S UR>                  R@                   S!U$ 35      e[)        U5      S:”  a9  [B        RE                  S"U S#U R@                   S$S%R;                  U5      / 35        O-[B        RG                  S&UR>                  R@                   S'35        [)        U5      S:”  a4  [B        RE                  S(UR>                  R@                   S)U S*U S+35        OV[)        U5      S:X  aG  [B        RG                  S,UR>                  R@                   S-U S.UR>                  R@                   S/35        [)        U5      S:”  ag  S0R;                  U V%V&V's/ s H  u  n%n&n'S1U% S2U& S3U' S43PM     sn'n&n%5      n([B        RE                  S(UR>                  R@                   S)U S5U( S+35        UUUUUU4$ s  snf s  sn'n&n%f )6Nr  )ÚprefixÚdiskzàThe current `device_map` had weights offloaded to the disk. Please provide an `offload_folder` for them. Alternatively, make sure you have `safetensors` installed if the model you are using offers the weights in this format.Trs  )NNrå  Úmodel_state_dictrØ  r¤   rr  rö  rÝ  r1  rù  rý  rÚ  Ústate_dict_indexÚstate_dict_folderrÐ  r<  rÞ  r/   ÚdesczLoading checkpoint shardsÚdisabler   z
	zsize mismatchz_
	You may consider adding `ignore_mismatched_sizes=True` in the model `from_pretrained` method.z#Error(s) in loading state_dict for z:
	z(Some weights of the model checkpoint at z! were not used when initializing z: 
 rP  z9All model checkpoint weights were used when initializing z.
zSome weights of z3 were not initialized from the model checkpoint at z and are newly initialized: zo
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.zAll the weights of z/ were initialized from the model checkpoint at zf.
If your task is similar to the task the model of the checkpoint was trained on, you can already use z* for predictions without further training.rˆ  z- z: found shape z in the checkpoint and z in the model instantiatedz= and are newly initialized because the shapes did not match:
)$r˜  rW   r   r"  Úupdate_missing_keysÚ"_keys_to_ignore_on_load_unexpectedÚreÚsearchrX  r‚   rŠ  r“  r6   r4   ÚtempfileÚmkdtempÚ	functoolsÚpartialr:   r9   r±  r*   r)   Útqdmr.   rl   rk   ÚshutilÚrmtreerZ  r  rÁ   rR   r'  r>  r(  ))r$  rå  r˜  r)  rÍ  r1  rÐ  r†  rr  r<  r¤   rö  rØ  rÛ  rÚ  rÝ  r÷  rÞ  rŠ  Úexpected_keysrø  rù  Úpatry   rú  rû  Úexpanded_device_maprý  rŒ  r‹  Úload_fnÚ_mismatched_keysÚ_error_msgsÚshard_filesÚshard_tqdm_kwargsÚ
shard_fileÚ	error_msgÚkeyÚshape1Úshape2Úmismatched_warnings)                                            rD   r  Ú!ModelMixin._load_pretrained_modelº  s�  € ð* !×+Ñ+Ó-ÐÜÐ-×2Ñ2Ó4Ó5ˆÜœC Ó.´°[Ó1AÑAÓBˆØÑ#Ø'×;Ñ;¸EÀ<ÐXZÐ;Ð[ˆLÜœs ;Ó/´#°mÓ2DÑDÓEˆð ×1Ñ1Ñ=Ø×=Ô=�Ù.=Ó"[ªo¨ÄÇÂÈ3ÐPQÓAR§1©o�Ð"[‘ñ >ð ˆØˆ
ð Ñ! f°
×0AÑ0AÓ0CÓ&CØÑ%Ü ð:óð ô —’˜N°TÒ:Ø!Ñ)Ø%)Ð"ð Ñ!Ü"4°ZÀÓ"OÐÜ% eÐ-@À%ÔVà(Ñ4¸À:×CTÑCTÓCVÓ9V™Ð\`ˆØ.8Ñ+ÐÐ+ÞÜ (× 0Ò 0Ó 2ÐØ!ÐàÑ!ð $. ,Ðô ×#Ò#Þ1LÕ-ÔRbò
áð
ñ .ð
ñ "ð	
ñ
 ð
ñ &ð
ñ "6ð
ñ &ð
ñ $ð
ñ ,ð
ñ (ð
ñ *ð
ñ .ð
ñ 0ð
ñ %<ð
ñ  0ð!
ñ" &ð#
ˆö( 'ÙMTÐUhÓMiÑJˆMÐ+Ð-=¸{Ø˜+Ñ%ˆJØÐ/Ñ/‰Oà-ˆKÜÐ&Ó'¨!Ó+Ø%+Ð-HÐ$IÐ!Ü.×0Ñ0Ø37Ð% iÑ0Ü%ŸlšlÐ+>ÑTÐBSÑT�ã)�
ÙQXÐYcÓQdÑN�Ð/Ð1AÀ;Ø˜kÑ)�
ØÐ#3Ñ3’ñ *ô
 	ÔàÑ$¬¨]Ó);¸aÓ)?Ü˜}¨nÔ=Ø ˆMæ!Ü& uÐ.>Ð@QÔRÜ—’Ð/Ô0äˆz‹?˜QÓØŸ™ JÓ/ˆIØ )Ó+ØØwñ�	ô Ð!DÀUÇ_Á_×E]ÑE]ÐD^Ð^cÐdmÐcnÐoÓpÐpäˆÓ !Ó#Ü�N‰NØ:Ð;XÐ:YÐYzÐ{~÷  |Hñ  |Hð  {Ið  INð  PT÷  PYñ  PYð  Zió  Pjð  Okð  Nlð  mõô �K‰KÐSÐTY×TcÑTc×TlÑTlÐSmÐmpÐqÔräˆ|Ó˜qÓ Ü�N‰NØ" 5§?¡?×#;Ñ#;Ð"<ð =Ø1Ð2Ð2NÈ|Ènð ]nðnõô
 �Ó! QÓ&Ü�K‰KØ% e§o¡o×&>Ñ&>Ð%?ð @Ø1Ð2ð 3CØCHÇ?Á?×C[ÑC[ÐB\ð ]-ð-ôô ˆÓ !Ó#Ø!%§¡ñ 0?õâ/>Ñ+˜˜V Vð ˜˜˜^¨F¨8Ð3JÈ6È(ÐRlÓmÙ/>óó"Ðô �N‰NØ" 5§?¡?×#;Ñ#;Ð"<ð =Ø1Ð2ð 3Ø.Ð/ð 0AðAôð �l O°_ÀmÐU_Ð_Ð_ùòC #\ùôjs   ÂQ2Â>Q2ÐQ7c                 óÒ  • [         R                  " UR                  5      R                  nUR	                  5        VVs0 s H'  u  p4UR
                  [         R                  :X  d  M%  X4_M)     nnn[        UR	                  5        VVs1 s H'  u  p4UR
                  [         R                  :w  d  M%  UiM)     snn5      n[        UR                  5       5      S1-
  nXv4$ s  snnf s  snnf )NrC   )	ÚinspectÚ	signaturerE   r…   ru   ÚdefaultÚ_emptyr"  r   )r$  Úobjr…   ry   rz   Úrequired_parametersÚoptional_parametersÚexpected_moduless           rD   Ú_get_signature_keysÚModelMixin._get_signature_keys\  s»   € ä×&Ò& s§|¡|Ó4×?Ñ?ˆ
Ø0:×0@Ñ0@Ô0BÔbÒ0B©¨ÀaÇiÁiÔSZ×SaÑSaÑFa›t˜qštÑ0BÐÑbÜ!°×1AÑ1AÔ1CÔ"cÒ1C©¨ÀqÇyÁyÔT[×TbÑTbÑGb§1Ñ1CÒ"cÓdÐÜÐ2×7Ñ7Ó9Ó:¸f¸XÑEÐàÐ4Ð4ùó	 cùÛ"cs   ¾$CÁ&CÂ$C#
Â/C#
c                 ó¾  • [        5       nU /n[        U5      S:”  a·  UR                  S5      nUR                  R                  U;  a{  [        U[        5      (       aJ  UR                  c%  [        UR                  R                   SU S35      eU[        UR                  5      -  nU[        UR                  5       5      -  n[        U5      S:”  a  M·  [        U5      $ )aZ  
Get the modules of the model that should not be split when using device_map. We iterate through the modules to
get the underlying `_no_split_modules`.

Args:
    device_map (`str`):
        The device map value. Options are ["auto", "balanced", "balanced_low_0", "sequential"]

Returns:
    `list[str]`: list of modules that should not be split
r   rz  z does not support `device_map='z_'`. To implement support, the model class needs to implement the `_no_split_modules` attribute.)r"  r±  r”  rÁ   rR   rž   r¹   Ú_no_split_modulesr‚   rW   rë   )rC   rØ  rµ  Úmodules_to_checkrq   s        rD   Ú_get_no_split_modulesÚ ModelMixin._get_no_split_modulesf  sâ   € ô  ›EÐØ ˜6ÐÜÐ"Ó# aÓ'Ø%×)Ñ)¨"Ó-ˆFà×Ñ×(Ñ(Ð0AÓAÜ˜f¤j×1Ñ1Ø×/Ñ/Ñ7Ü(Ø%×/Ñ/×8Ñ8Ð9Ð9XÐYcÐXdð eZð Zóð ð
 ->ÄÀF×D\ÑD\Ó@]Ñ,]Ð)Ø ¤D¨¯©Ó):Ó$;Ñ;Ð ô Ð"Ó# aÕ'ô Ð%Ó&Ð&rG   c                 ó  • UR                   (       d  [        SU R                   SU S35      e[        R	                  SU R                   SU S35        [
        R                  " 5       n[
        R                  " U5        U$ )a7  
Change the default dtype and return the previous one. This is needed when wanting to instantiate the model
under specific dtype.

Args:
    dtype (`torch.dtype`):
        a floating dtype to set to.

Returns:
    `torch.dtype`: the original `dtype` that can be used to restore `torch.set_default_dtype(dtype)` if it was
    modified. If it wasn't, returns `None`.

Note `set_default_dtype` currently only works with floating-point types and asserts if for example,
`torch.int64` is passed. So if a non-float `dtype` is passed this functions will throw an exception.
zCan't instantiate z model under dtype=z' since it is not a floating point dtypezInstantiating z model under default dtype r‰  )r¦   r‚   rR   r'  r(  rv   Úget_default_dtyper  )r$  r¤   r.  s      rD   r  Ú#ModelMixin._set_default_torch_dtypeƒ  sw   € ð" ×&×&ÜØ$ S§\¡\ NÐ2EÀeÀWÐLsÐtóð ô 	�‰�n S§\¡\ NÐ2MÈeÈWÐTUÐVÔWÜ×,Ò,Ó.ˆ
Ü×Ò Ô&ØÐrG   c                 ó   • [        U 5      $ )zu
`torch.device`: The device on which the module is (assuming that all the module parameters are on the same
device).
)r‘   rÓ   s    rD   rˆ   ÚModelMixin.devicež  s   € ô $ DÓ)Ð)rG   c                 ó   • [        U 5      $ )zg
`torch.dtype`: The dtype of the module (assuming that all the module parameters have the same dtype).
)r®   rÓ   s    rD   r¤   ÚModelMixin.dtype¦  s   € ô
 # 4Ó(Ð(rG   Úonly_trainableÚexclude_embeddingsc                 ó„  • [        U SS5      nU(       a  [        5       (       a  SSKnO[        S5      eU(       at  U R	                  5        VVs/ s H+  u  pV[        U[        R                  5      (       d  M&  U S3PM-     nnnU R                  5        VVs/ s H  u  pXXW;  d  M  UPM     n	nnO[        U R                  5       5      n	/ n
U	 HÛ  nUR                  (       d	  U(       a  M  U(       a˜  [        UWR                  R                  5      (       as  [        US5      (       a  UR                  5       nO*[        US5      (       a  UR                  R                   nOS	nU
R#                  UR%                  5       S
-  U-  5        M¼  U
R#                  UR%                  5       5        MÝ     ['        U
5      $ s  snnf s  snnf )a‰  
Get number of (trainable or non-embedding) parameters in the module.

Args:
    only_trainable (`bool`, *optional*, defaults to `False`):
        Whether or not to return only the number of trainable parameters.
    exclude_embeddings (`bool`, *optional*, defaults to `False`):
        Whether or not to return only the number of non-embedding parameters.

Returns:
    `int`: The number of parameters.

Example:

```py
from diffusers import UNet2DConditionModel

model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
unet = UNet2DConditionModel.from_pretrained(model_id, subfolder="unet")
unet.num_parameters(only_trainable=True)
859520964
```
r?  Fr   NzÊbitsandbytes is not installed but it seems that the model has been loaded in 4bit precision, something went wrong make sure to install bitsandbytes with `pip install bitsandbytes`. You also need a GPU. z.weightÚelement_sizeÚquant_storager/   r   )r=  r$   Úbitsandbytesr‚   rŸ   rž   r   Ú	Embeddingr£   rW   r…   Úrequires_gradÚ
Params4bitr    rÃ  rÄ  Úitemsizer  ÚnumelÚsum)rC   rÀ  rÁ  r?  Úbnbr™   Úmodule_typeÚembedding_param_namesrm   Útotal_parametersÚtotal_numelr«   Ú	num_bytess                rD   Únum_parametersÚModelMixin.num_parameters­  s„  € ô0 $ DÐ*=¸uÓEÐæÜ(×*Ñ*Ü*ä ðpóð ö
 à:>×:LÑ:LÔ:Nô%Ú:NÑ%6 TÔR\Ð]hÔjl×jvÑjv×RwÓ �4�&˜Ó Ñ:Nð "ñ %ð 26×1FÑ1FÔ1Hô Ú1H™o˜dÈDÑLm—	Ñ1Hð ñ  Ðô  $ D§O¡OÓ$5Ó6Ðàˆã%ˆEØ×"×"¯.¨.ö %¬°E¸3¿6¹6×;LÑ;L×)MÑ)MÜ˜u n×5Ñ5Ø$)×$6Ñ$6Ó$8™	Ü  ¨×8Ñ8Ø$)×$7Ñ$7×$@Ñ$@™	à$%˜	Ø×&Ñ& u§{¡{£}°qÑ'8¸9Ñ'DÖEà×&Ñ& u§{¡{£}Ö5ñ &ô �;ÓÐùó5%ùó s   Á%F6Á7	F6ÂF<Â%F<c                 óP  • [        U R                  5        Vs/ s H#  o"R                  5       UR                  5       -  PM%     sn5      nU(       aL  [        U R	                  5        Vs/ s H#  oDR                  5       UR                  5       -  PM%     sn5      nX5-   nU$ s  snf s  snf )a¼  
Get the memory footprint of a model. This will return the memory footprint of the current model in bytes.
Useful to benchmark the memory footprint of the current model and design some tests. Solution inspired from the
PyTorch discussions: https://discuss.pytorch.org/t/gpu-memory-that-model-uses/56822/2

Arguments:
    return_buffers (`bool`, *optional*, defaults to `True`):
        Whether to return the size of the buffer tensors in the computation of the memory footprint. Buffers
        are tensors that do not require gradients and not registered as parameters. E.g. mean and std in batch
        norm layers. Please see: https://discuss.pytorch.org/t/what-pytorch-means-by-buffers/120266/2
)rË  r…   ÚnelementrÃ  r†   )rC   Úreturn_buffersr«   ÚmemÚbufÚmem_bufss         rD   Úget_memory_footprintÚModelMixin.get_memory_footprintí  s‚   € ô ÈÏÉÔHYÓZÒHY¸u—>‘>Ó# e×&8Ñ&8Ó&:Ô:ÑHYÑZÓ[ˆÞÜÈ4Ï<É<Ì>ÓZÊ>ÀCŸL™L›N¨S×-=Ñ-=Ó-?Ô?É>ÑZÓ[ˆHØ‘.ˆCØˆ
ùò	 [ùâZs   ˜*BÁ'*B#rß   c                 ó  • SnU R                  5        HB  u  pE[        US5      (       d  M  [        R                  SU SU S35        X%l        Xl        SnMD     U(       d#  [        SU R                  R                   S35      eg )	NFrÐ   z Setting `gradient_checkpointing=z` for 'Ú'TzThe module z© does not support gradient checkpointing. Please make sure to use a module that supports gradient checkpointing by creating a boolean attribute `gradient_checkpointing`.)	rŸ   r    r'  ÚdebugrÀ   rÐ   r‚   rÁ   rR   )rC   rß   rÖ   Úis_gradient_checkpointing_setr™   rq   s         rD   rá   Ú&ModelMixin._set_gradient_checkpointingÿ  s‘   € ð ).Ð%à ×.Ñ.Ö0‰LˆDÜ�vÐ7×8Ó8Ü—‘Ð?À¸xÀwÈtÈfÐTUÐVÔWØ6QÔ3Ø06Ô-Ø04Ò-ñ 1ö -ÜØ˜dŸn™n×5Ñ5Ð6ð 7~ð óð ð -rG   c                 óh  ^^• / mUU4S jmT" SU 5        T GH  nU S3U;   a  UR                  U S35      X S3'   U S3U;   a  UR                  U S35      X S3'   U S3U;   a  UR                  U S35      X S3'   U S	3U;   a  UR                  U S	35      X S
3'   U S3U;   a  UR                  U S35      X S3'   U S3U;   a  UR                  U S35      X S3'   U S3U;   a  UR                  U S35      X S3'   U S3U;   d  Mý  UR                  U S35      X S3'   GM     U$ )a#  
This function fix the state dict of the model to take into account some changes that were made in the model
architecture:
- deprecated attention blocks (happened before we introduced sharded checkpoint,
so this is why we apply this method only when loading non sharded checkpoints for now)
c                 óÌ   >• [        US5      (       a"  UR                  (       a  TR                  U 5        UR                  5        H  u  p#U S:X  a  UOU  SU 3nT" X#5        M     g )NÚ_from_deprecated_attn_blockr  r‰  )r    rã  r  Únamed_children)r™   rq   Úsub_nameÚ
sub_moduleÚ deprecated_attention_block_pathsÚrecursive_find_attn_blocks       €€rD   rè  ÚJModelMixin._fix_state_dict_keys_on_load.<locals>.recursive_find_attn_block  s^   ø€ Ü�vÐ<×=Ñ=À&×Bd×BdØ0×7Ñ7¸Ô=à(.×(=Ñ(=Ö(?Ñ$�Ø'+¨r£z™8¸$¸¸qÀÀ
Ð7K�Ù)¨(Ö?ò )@rG   r  z.query.weightz.to_q.weightz.query.biasz
.to_q.biasz.key.weightz.to_k.weightz	.key.biasz
.to_k.biasz.value.weightz.to_v.weightz.value.biasz
.to_v.biasz.proj_attn.weightz.to_out.0.weightz.proj_attn.biasz.to_out.0.bias)r”  )rC   r˜  r‹  rç  rè  s      @@rD   r  Ú'ModelMixin._fix_state_dict_keys_on_load  s¬  ù€ ð ,.Ð(ö	@ñ 	" " dÔ+ô 5ˆDð ��}Ð%¨Ó3Ø4>·N±NÀdÀVÈ=ÐCYÓ4Z�
˜V <Ð0Ñ1Ø��{Ð# zÓ1Ø2<·.±.ÀDÀ6ÈÐAUÓ2V�
˜V :Ð.Ñ/ð ��{Ð# zÓ1Ø4>·N±NÀdÀVÈ;ÐCWÓ4X�
˜V <Ð0Ñ1Ø��yÐ! ZÓ/Ø2<·.±.ÀDÀ6ÈÐASÓ2T�
˜V :Ð.Ñ/ð ��}Ð%¨Ó3Ø4>·N±NÀdÀVÈ=ÐCYÓ4Z�
˜V <Ð0Ñ1Ø��{Ð# zÓ1Ø2<·.±.ÀDÀ6ÈÐAUÓ2V�
˜V :Ð.Ñ/ð �Ð(Ð)¨ZÓ7Ø8B¿¹È$ÈÐO`ÐGaÓ8b�
˜VÐ#3Ð4Ñ5Ø��Ð'¨:Õ5Ø6@·n±nÈÀvÈ_ÐE]Ó6^�
˜V >Ð2Ô3ñ3 5ð4 ÐrG   )rÀ   rO  rA   )rn   N)TNTNÚ10GBFF)FFNTNNNNNNFF)FF)T)WrR   rS   rT   rU   rV   r   Úconfig_nameÚ_automatically_saved_argsrà   r�  rµ  r•   r!  r?  rW  rO  ry  rz  Ú
_skip_keysrE   rŒ   r   rÉ   ÚpropertyÚboolrÔ   r	   râ   rå   rê   ró   rö   rü   r  r  r
  r  r  rv   rô  r¤   r‹   r   r   rŠ   r+  rˆ   r  rA  rd  rg  rŠ  ÚPathLikerÈ  rË  Úclassmethodr   r   r5  r   rD  r   rP  rT  r\  r2   r0   r3   r«  r1   r#  r   rW   r   r   r  r²  r·  r  rÒ  rÚ  rÚ   rÛ   rá   r  rX   Ú__classcell__©rÁ   s   @rD   r¹   r¹   ñ   s”  ø† ñð €KÚ VÐØ',Ð$Ø)-Ð&ØÐØ ÐØ'+Ð$Ø!%ÐØÐØÐØ€HØ€HØ€Jõ1ð
) ð )¨÷ )ð$ ðn¨4ó nó ðnñoÈÐTXÉð oÐdhõ oô<;ð=°ð =¸$ô =ô /ô0ð PTñ9Ø'+ð9Ø=EÈ¹_ð9à	õ9ñ"I¸ÀD¹õ Iò0ñ1Àð 1ÐU]Ð`dÑUdð 1Ðptõ 1ñMÀxÐRVÁð MÐbfõ Mô@@ð &+×%8Ñ%8Ø,0Ø7;ØIMØ"ñS
à—{‘{ðS
ð —{‘{ TÑ)ðS
ð $ C¨ H™o°Ñ4ð	S
ð
 $ D¨¯©¯©Ñ$9¸3Ð$>Ñ?À$ÑFðS
ð ðS
ð 
õS
ðp (-§|¢|°EÓ':Ø)Ø+/Ø"Ø Ø#ØØ+/Ø$(Ø%)ñB
à—|‘|ðB
ð Ÿ™ðB
ð ð	B
ð
 " D™jðB
ð ðB
ð ðB
ð ðB
ð " D™jðB
ð ˜T‘zðB
ð ˜d™
ðB
ð 
õB
ðH<>¨Sð <>°Tô <>ô|0ð, !%Ø)-Ø#'Ø"Ø$*Ø!Ø#ñà˜bŸk™kÑ)ðð ðð   $‘ð	ð
 !ðð �t‘ðð ˜c™	ðð ðð õòB
-ð ØðD	¸CÀ"Ç+Á+Ñ<MÐPTÑ<Tð D	Ðcgó D	ó ó ðD	ñN ˆ5�8‰8�?‰?×ÑÓ ô-ó !ð-ñ4 ˆ5�8‰8�?‰?×ÑÓô5+ó ð5+õp'õ(òðJ ?Cò	qVð Ð!6Ñ6Ð9MÑMðqVð �cÐ3Ð3Ñ4°tÑ;õ	qVðf ð ).Ø).Ø26Ø"&Ø*.Ø15ØUYØ*.Ø37Ø48Ø38Ø"ñ%_`ð  ð_`ð " #™Yð	_`ð
 (+¨R¯[©[Ñ'8ð_`ð ˜#‘Yð_`ð "&ð_`ð #'ð_`ð )¨4Ñ/ð_`ð  ð_`ð �U—[‘[Ñ  4Ñ'ð_`ð # 3™i¨$Ñ.ð_`ð ˜#‘I §¡Ñ,¨t°C¸¸s¹ÀUÇ\Á\Ñ9QÐ4QÑ/RÑRð_`ð ! 4™Kð_`ð ˜bŸk™kÑ)¨DÑ0ð_`ð  ˜3 	˜>Ñ*¨TÑ1ð!_`ð" &*¨D¡[ð#_`ð$ ô%_`ó ð_`ðB ñ5ó ð5ð'°ô 'ð: ð¨U¯[©[ð ¸U¿[¹[ó ó ðð4 ð*˜Ÿ™ó *ó ð*ð ð)�u—{‘{ó )ó ð)ñ> ¨Tð > Ètð > Ð`cõ > ô@ð& "È5Ï;É;×KaÑKa×KlÑKlñØðØ@Hðà	õð$1°{ð 1Àt÷ 1ò 1rG   r¹   c                   óh   ^ • \ rS rSrSr\\S\\R                  -  S-  4U 4S jj5       5       r
SrU =r$ )ÚLegacyModelMixiniE  z§
A subclass of `ModelMixin` to resolve class mapping from legacy classes (like `Transformer2DModel`) to more
pipeline-specific classes (like `DiTTransformer2DModel`).
rÍ  Nc                 óò  >• SSK Jn  UR                  5       nUR                  SS 5      nUR                  SS5      nUR                  SS 5      nUR                  SS 5      nUR                  SS 5      n	UR                  S	S 5      n
UR                  S
S 5      nUn[        SSS.nU R
                  " U4USSUUUU	U
UUS.
UD6u  n  nU" Xà5      nUU L a  [        [        U]"  " U40 UD6$ UR                  " U40 UD6$ )Nr/   )Ú_fetch_remapped_cls_from_configrÏ  rÑ  FrÒ  rÔ  rx  rÕ  r×  rå  ræ  )rç  rè  ré  T)
rÏ  rë  rì  rÑ  rÒ  rÔ  rx  rÕ  r×  rí  )	Úmodel_loading_utilsrø  r  r”  r   r  r¿   rö  r5  )r$  rÍ  rP   rø  Úkwargs_copyrÏ  rÑ  rÒ  rÔ  rx  rÕ  r×  r'  rí  rÿ  r�  Úremapped_classrÁ   s                    €rD   r5  Ú LegacyModelMixin.from_pretrainedK  s6  ø€ õ 	Ið —k‘k“mˆà—J‘J˜{¨DÓ1ˆ	ØŸ™Ð$4°eÓ<ˆØ—*‘*˜Y¨Ó-ˆØ!Ÿ:™:Ð&8¸$Ó?ÐØ—
‘
˜7 DÓ)ˆØ—:‘:˜j¨$Ó/ˆØ—J‘J˜{¨DÓ1ˆ	ð 4ˆô %Ø Ø"ñ
ˆ
ð —’Øð
àØ!%Ø#Ø)ØØ-ØØØØ!ñ
ð ñ
‰ˆ��1ñ 9¸ÓEˆà˜SÒ ÜÔ)¨>ÒJØ-ñØ1<ñð ð "×1Ò1Ð2OÑ_ÐS^Ñ_Ð_rG   rY   )rR   rS   rT   rU   rV   rò  r   rŒ   rŠ  rñ  r5  rX   ró  rô  s   @rD   rö  rö  E  s=   ø† ñð
 Øð/`¸CÀ"Ç+Á+Ñ<MÐPTÑ<Tö /`ó ó ö/`rG   rö  )xr  r•  rª  rƒ   r®  rŠ  r‘  r˜  r“  Úcollectionsr   Ú
contextlibr   r   r   Úpathlibr   Útypingr   r	   r
   r   r§  rv   Útorch.utils.checkpointÚhuggingface_hubr   r   r   Úhuggingface_hub.utilsr   r   r   Útyping_extensionsr   r  r   Ú
quantizersr   r   Úquantizers.quantization_configr   rÚ   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   Úutils.distributed_utilsr*   Úutils.hub_utilsr+   r,   r-   Úutils.torch_utilsr.   Ú_modeling_parallelr0   r1   r2   r3   rù  r4   r5   r6   r7   r8   r9   r:   r;   r=   Ú
get_loggerrR   r'  rX  r¢  r  rµ   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   r³   r   r  rj   Úaccelerate.utilsrk   rl   rŠ   rˆ   r‘   r¤   r®   r·   r¹   rö  rY   rG   rD   Ú<module>r     s+  ðó" Û Û Û Û Û 	Û 	Û Û Ý #ß 0Ý Ý ß 6Ó 6ã Û Û ß VÑ VÝ 6ß Ý "å ß CÝ ?÷÷ ÷ ÷ ÷ õ( >ß \Ñ \Ý 2÷ó ÷	÷ 	ó 	÷-ñ -ð$ 
×	Ò	˜HÓ	%€à�zŠzÐ1Ó2€ð
 &*Ð "ð —‘× Ñ Ø�w‰w�‰Ø—W‘W×*Ñ*Ø—‘×"Ñ"Ø—w‘w×.Ñ.Ø—g‘g×,Ñ,ØŸ™×0Ñ0Ø—w‘w×.Ñ.Ø�w‰w�‰Ø�g‰g�n‰nØ—g‘g×,Ñ,Ø—W‘W×*Ñ*Ø—w‘w×.Ñ.Ø—g‘g×,Ñ,ñÐ ñ" �D˜'×"Ñ"Ø!%Ñà!&Ðñ ×ÑÛÝ)ßKð% E§H¡H§O¡Oð %¸¿¹ô %ð44# 5§8¡8§?¡?ð 4#°u·{±{ô 4#ðn ñ4ó ð4ô&Q�—‘—‘ .ô Qôh:7`�zõ 7`rG   