+
     °³jY  ã                   óL  € ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RI Ht ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHt ^R	IHt ^R
IHt ^RIHt ^RIHt ^RIHt ^RI H!t!H"t"H#t#H$t$H%t% ^RI&H't' ^RI(H)t) ^RI*H+t+ ]! ],4      t-]$! 4       '       d
   ^ RI.H/u H0t1 R R lt2R R lt3R R lt4R R lt5R R lt6R R lt7R R lt8R  R! lt9R" R# lt:R:R$ R% llt;R& t<R' R( lt=R;R) R* llt>]"! R+4      '       d   ]P~                  M]P^                  t@]@P‚                  P„                  ]P†                  ]]Pˆ                  .tE]"! R,4      '       d&   ]EP�                  ]PŽ                  P�                  4       R<R- ltIR. tJR/ tKR<R0 R1 lltLR2 R3 ltMR4 tNR5 tOR6 R7 ltPR=R8 R9 lltQR# )>é    N)Úencode)ÚOrderedDict)ÚpartialÚreduce)Ú
MethodType)ÚOptional)ÚVersion)Ú	save_file)Úwrite_basic_config)Ú
get_logger)ÚPartialState)ÚFSDP_PYTORCH_VERSION)ÚDistributedType)Úis_deepspeed_availableÚis_numpy_availableÚis_torch_distributed_availableÚis_torch_xla_availableÚis_weights_only_available)Úid_tensor_storage)Úconvert_model)Úis_torch_versionc                óX   € V ^8„  d   QhR\         P                  P                  R\        /# ©é   ÚmoduleÚreturn©ÚtorchÚnnÚModuleÚbool)Úformats   "ÚW/home/luca/screen-checking/.venv/lib/python3.14/site-packages/accelerate/utils/other.pyÚ__annotate__r$   6   s&   € ÷ Hñ HœuŸx™xŸ™ð H´4ñ Hó    c                óŽ   € \        \        R4      '       g   R# \        V \        P                  P                  P
                  4      # )z<
Check whether the module was compiled with torch.compile()
Ú_dynamoF)Úhasattrr   Ú
isinstancer'   Ú
eval_frameÚOptimizedModule©r   s   &r#   Úis_compiled_moduler-   6   s1   € ô ”5˜)×$Ò$Ùä�fœeŸm™m×6Ñ6×FÑFÓGÐGr%   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# r   r   )r"   s   "r#   r$   r$   @   s"   € ÷ ñ ¤§¡§¡ð ´Tñ r%   c                óö   € \        \        R4      '       g   R# V P                  '       dO   V P                  4        F:  p\	        V\        P
                  P                  P                  4      '       g   K9   R# 	  R# )zT
Check whether the module has submodules that were compiled with `torch.compile()`.
r'   FT)r(   r   Ú_modulesÚmodulesr)   r'   r*   r+   ©r   Ú	submodules   & r#   Úhas_compiled_regionsr4   @   sS   € ô ”5˜)×$Ò$Ùà‡‡€ØŸ™Ö)ˆIÜ˜)¤U§]¡]×%=Ñ%=×%MÑ%M×NÔNÚñ *ñ r%   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# r   r   )r"   s   "r#   r$   r$   O   s"   € ÷ 
ñ 
œuŸx™xŸ™ð 
´4ñ 
r%   c                óü   a € \        S \        P                  P                  4      ;'       dQ    \	        S 4      ^ 8„  ;'       d;    \
        ;QJ d    V 3R lS  4       F  '       d   K   R# 	  R# ! V 3R lS  4       4      # )zÇ
Check whether the module is a repeated block, i.e. `torch.nn.ModuleList` with all children of the same class. This
is useful to determine whether we should apply regional compilation to the module.
c              3   ó^   <"  € T F"  p\        VS^ ,          P                  4      x € K$  	  R# 5i)r   N)r)   Ú	__class__)Ú.0Úmr   s   & €r#   Ú	<genexpr>Ú%is_repeated_blocks.<locals>.<genexpr>X   s%   øé € ÐC¹F°q”
˜1˜f Q�i×1Ñ1×2Ð2»Fùs   ƒ*-FT)r)   r   r   Ú
ModuleListÚlenÚallr,   s   fr#   Úis_repeated_blocksr@   O   sq   ø€ ô 	�6œ5Ÿ8™8×.Ñ.Ó/÷ 	Dð 	DÜ�‹K˜!‰O÷	Dð 	Dç‹CÔC¹FÓC�CŒCðò ðð ÔC¹FÓCÓCðr%   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# r   r   )r"   s   "r#   r$   r$   \   s"   € ÷ ñ ¤§¡§¡ð ´Dñ r%   c                ó€   € V P                   '       d,   V P                  4        F  p\        V4      '       g   K   R# 	  R# )zí
Check whether the module has repeated blocks, i.e. `torch.nn.ModuleList` with all children of the same class, at
any level of the module hierarchy. This is useful to determine whether we should apply regional compilation to the
module.
TF)r0   r1   r@   r2   s   & r#   Úhas_repeated_blocksrC   \   s1   € ð ‡‡€ØŸ™Ö)ˆIÜ! )×,Ô,Úñ *ñ r%   c                ó€   € V ^8„  d   QhR\         P                  P                  R\         P                  P                  /# r   ©r   r   r    )r"   s   "r#   r$   r$   j   s.   € ÷ Hñ HœEŸH™HŸO™Oð HÄ%Ç(Á(Ç/Á/ñ Hr%   c                ój   a€ R V3R lloS! V 3/ VB pRVP                   9  d   WP                   R&   V# )aÃ  
Performs regional compilation where we target repeated blocks of the same class and compile them sequentially to
hit the compiler's cache. For example, in `GPT2LMHeadModel`, the repeated block/class is `GPT2Block`, and can be
accessed as `model.transformer.h[0]`. The rest of the model (e.g. model.lm_head) is compiled separately.

This allows us to speed up the compilation overhead / cold start of models like LLMs and Transformers in general.
See https://pytorch.org/tutorials/recipes/regional_compilation.html for more details.

Args:
    module (`torch.nn.Module`):
        The model to compile.
    **compile_kwargs:
        Additional keyword arguments to pass to `torch.compile()`.

Returns:
    `torch.nn.Module`: A new instance of the model with some compiled regions.

Example:
```python
>>> from accelerate.utils import compile_regions
>>> from transformers import AutoModelForCausalLM

>>> model = AutoModelForCausalLM.from_pretrained("gpt2")
>>> compiled_model = compile_regions(model, mode="reduce-overhead")
>>> compiled_model.transformer.h[0]
OptimizedModule(
    (_orig_mod): GPT2Block(
            (ln_1): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
            (attn): GPT2Attention(
            (c_attn): Conv1D(nf=2304, nx=768)
            (c_proj): Conv1D(nf=768, nx=768)
            (attn_dropout): Dropout(p=0.1, inplace=False)
            (resid_dropout): Dropout(p=0.1, inplace=False)
        )
        (ln_2): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
        (mlp): GPT2MLP(
            (c_fc): Conv1D(nf=3072, nx=768)
            (c_proj): Conv1D(nf=768, nx=3072)
            (act): NewGELUActivation()
            (dropout): Dropout(p=0.1, inplace=False)
        )
    )
)
```
c                ó€   € V ^8„  d   QhR\         P                  P                  R\         P                  P                  /# r   rE   )r"   s   "r#   r$   Ú%compile_regions.<locals>.__annotate__™   s*   € ÷ ñ ¤§¡§¡ð ÄuÇxÁxÇÁñ r%   c           	      ó  <€ \        V 4      '       dP   \        P                  P                  4       pV  F)  pVP	                  \        P
                  ! V3/ VB 4       K+  	  V# \        V 4      '       dü   V P                  P                  V P                  4      pVP                  P                  V P                  4       \        VP                  P                  4       4       FO  w  rE\        VR 4      '       g   K  \        VRR4      V J g   K,  \        VP                   V4      VP                  V&   KQ  	  / Vn        V P%                  4        F  w  rCVP'                  VS! V3/ VB 4       K   	  V# \        P
                  ! V 3/ VB pV# )Ú__func__Ú__self__N)r@   r   r   r=   ÚappendÚcompilerC   r8   Ú__new__Ú__dict__ÚupdateÚlistÚitemsr(   Úgetattrr   rJ   r0   Únamed_childrenÚ
add_module)r   Úcompile_kwargsÚ
new_moduler3   ÚnameÚvalueÚ_compile_regionss   &,    €r#   rZ   Ú)compile_regions.<locals>._compile_regions™   sF  ø€ Ü˜f×%Ò%ÜŸ™×,Ñ,Ó.ˆJÛ#�	Ø×!Ñ!¤%§-¢-°	Ñ"L¸^Ñ"LÖMñ $ð Ðô ! ×(Ò(Ø×)Ñ)×1Ñ1°&×2BÑ2BÓCˆJØ×Ñ×&Ñ& v§¡Ô7Ü# J×$7Ñ$7×$=Ñ$=Ó$?Ö@‘�Ü˜5 *×-Ô-´'¸%ÀÈTÓ2RÐV\Õ2\Ü0:¸5¿>¹>È:Ó0V�J×'Ñ'¨Ó-ñ  Að #%ˆJÔØ#)×#8Ñ#8Ö#:‘�Ø×%Ñ% dÑ,<¸YÑ,YÈ.Ñ,YÖZñ $;ð
 Ðô Ÿš vÑ@°Ñ@ˆJàÐr%   Ú	_orig_mod)rO   )r   rV   rW   rZ   s   &, @r#   Úcompile_regionsr]   j   sA   ø€ ÷^ð ñ& " &Ñ;¨NÑ;€Jà˜*×-Ñ-Ô-à+1×Ñ˜KÑ(àÐr%   c                óL   € V ^8„  d   QhR\         P                  P                  /# )r   r   rE   )r"   s   "r#   r$   r$   µ   s   € ÷ )ñ )¤e§h¡h§o¡oñ )r%   c                óò   € \        V 4      '       d   V  F  pVP                  ! R/ VB  K  	  R# \        V 4      '       d&   V P                  4        F  p\	        V3/ VB  K  	  R# V P                  ! R/ VB  R# )aõ  
Performs regional compilation the same way as `compile_regions`, but specifically for `DeepSpeedEngine.module`.
Since the model is wrapped in a `DeepSpeedEngine` and has many added hooks, offloaded parameters, etc that
`torch.compile(...)` interferes with, version of trgional compilation uses the inplace `module.compile()` method
instead.

Args:
    module (`torch.nn.Module`):
        The model to compile.
    **compile_kwargs:
        Additional keyword arguments to pass to `module.compile()`.
N© )r@   rM   rC   ÚchildrenÚcompile_regions_deepspeed©r   rV   r3   Úchilds   &,  r#   rb   rb   µ   sd   € ô ˜&×!Ò!ÛˆIØ×ÒÑ/ Ô/ó  ä	˜V×	$Ò	$Ø—_‘_Ö&ˆEÜ% eÑ>¨~Ô>ó 'ð 	�ŠÑ(˜Ô(r%   c                ó€   € V ^8„  d   QhR\         P                  P                  R\         P                  P                  /# r   rE   )r"   s   "r#   r$   r$   Í   s*   € ÷ ñ ¤%§(¡(§/¡/ð ÌÏÉÏÉñ r%   c                óò   € \        V 4      '       d   V  F  pVP                  ! R/ VB  K  	  V # \        V 4      '       d&   V P                  4        F  p\	        V3/ VB  K  	  V # V P                  ! R/ VB  V # )a‡  
Like `compile_regions`, but uses the in-place `module.compile()` instead of `torch.compile(module)`.

Needed for the FSDP2 prepare path: `torch.compile(module)` returns an `OptimizedModule` whose `__call__`
bypasses `nn.Module._call_impl`, so forward/pre hooks added later by `fully_shard` never fire and per-layer
all-gather/reshard is lost. The in-place `module.compile()` keeps `_call_impl` (and its runtime hook check)
on the call path, so FSDP hooks installed afterwards still run.

Args:
    module (`torch.nn.Module`):
        The model to compile.
    **compile_kwargs:
        Additional keyword arguments to pass to `module.compile()`.
r`   )r@   rM   rC   ra   Úcompile_regions_fsdp2rc   s   &,  r#   rg   rg   Í   sy   € ô ˜&×!Ò!ÛˆIØ×ÒÑ/ Ô/ñ  ð €Mô 
˜V×	$Ò	$Ø—_‘_Ö&ˆEÜ! %Ñ:¨>Ô:ñ 'ð €Mð 	�ŠÑ(˜Ò(Ø€Mr%   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# ©r   Úmodelr   r   )r"   s   "r#   r$   r$   ç   s&   € ÷ Cñ CœUŸX™XŸ_™_ð C´ñ Cr%   c                óî   a€ \        RR4      '       d   ^ RIHo M^ RIHo \        ;QJ d-    V3R lV P                  4        4       F  '       g   K   R# 	  R# ! V3R lV P                  4        4       4      # )z®
Check if the model has DTensor parameters.

Args:
    model (`torch.nn.Module`):
        The model to check.

Returns:
    `bool`: Whether the model has DTensor parameters.
ú>=z2.5.0)ÚDTensorc              3   ó<   <"  € T F  p\        VS4      x € K  	  R # 5i©N)r)   )r9   Úprm   s   & €r#   r;   Ú$model_has_dtensor.<locals>.<genexpr>ø   s   øé € ÐBÑ/A¨!Œz˜!˜W×%Ð%Ó/Aùs   ƒTF)r   Útorch.distributed.tensorrm   Útorch.distributed._tensorÚanyÚ
parameters)rj   rm   s   &@r#   Úmodel_has_dtensorrv   ç   sU   ø€ ô ˜˜g×&Ò&Þ4õ 	6ç‹3ÔB¨u×/?Ñ/?Ô/AÓB�3Œ3ÐBŠ3ÐBˆ3ÔB¨u×/?Ñ/?Ô/AÓBÓBÐBr%   c                ón   € V ^8„  d   QhR\         P                  P                  R\        \        ,          /# ri   )r   r   r    r   Úint)r"   s   "r#   r$   r$   û   s&   € ÷ 8ñ 8œUŸX™XŸ_™_ð 8´¼#µñ 8r%   c                óÀ   € \        V RR4      pVe   V# \        \        V RR4      RR4      p\        V\        4      '       d   VP                  R4      # \        VRR4      # )zï
Get the tensor parallel degree a `transformers` model was sharded with, or `None` if it was not sharded.

Args:
    model (`torch.nn.Module`):
        The model to inspect.

Returns:
    `Optional[int]`: The model's tensor parallel size.
Útp_sizeNÚconfigÚdistributed_config)rS   r)   ÚdictÚget)rj   rz   r|   s   &  r#   Úget_model_tp_sizer   û   sf   € ô �e˜Y¨Ó-€GØÒØˆä ¤¨°¸$Ó!?ÐAUÐW[Ó\ÐÜÐ$¤d×+Ò+Ø!×%Ñ% iÓ0Ð0ÜÐ% y°$Ó7Ð7r%   c                ó<   € V ^8„  d   QhR\         R\         R\         /# )r   Úkeep_fp32_wrapperÚkeep_torch_compileÚ	recursive©r!   )r"   s   "r#   r$   r$     s)   € ÷ Uñ UÜ"ðUÜ?CðUÜW[ñUr%   c                óÒ  a€ \         P                  P                  P                  \         P                  P                  3p\        V 4      p\        V 4      pRpV'       d   T pV P                  p M.V'       d'   RV P                  9   d   T pV P                  R,          p \        4       '       d   ^ RI
Hp WH3,          p\        R\        4      '       d    \        4       '       d   ^ RIHp	 WI3,          p\#        W4      '       d   V P$                  p K  V'       d   V3R loS! V 4      p V'       g„   V P&                  p
V P                  P)                  RR4      pVe8   \+        V
R4      '       d   V
P,                  p
W«8X  g   K&   \/        W 4      V n        \1        V R	R
4      '       d   \3        V R
R7       V'       d/   Ve+   V'       d   Wn        Tp V # V'       d   WP                  R&   Tp V # )a_  
Extract a model from its distributed containers.

Args:
    model (`torch.nn.Module`):
        The model to extract.
    keep_fp32_wrapper (`bool`, *optional*):
        Whether to remove mixed precision hooks from the model.
    keep_torch_compile (`bool`, *optional*):
        Whether to unwrap compiled model.
    recursive (`bool`, *optional*, defaults to `False`):
        Whether to recursively extract all cases of `module.module` from `model` as well as unwrap child sublayers
        recursively, not just the top-level distributed containers.

Returns:
    `torch.nn.Module`: The extracted model.
Nr\   )ÚDeepSpeedEnginerl   )ÚFullyShardedDataParallelc                 ó¬   <€ \        V R 4      '       d   S! V P                  4      pMT pVP                  4        F  w  r#\        WS! V4      4       K  	  V# r,   )r(   r   rT   Úsetattr)r   Úunwrapped_modulerX   rd   Ú_recursive_unwraps   &   €r#   r‹   Ú6extract_model_from_parallel.<locals>._recursive_unwrapD  sT   ø€ ô �v˜x×(Ò(Ù#4°V·]±]Ó#CÑ à#)Ð à/×>Ñ>Ö@‘�ÜÐ(Ñ0AÀ%Ó0HÖIñ  Aà#Ð#r%   Ú_original_forwardÚ__wrapped__Ú _converted_to_transformer_engineF)Úto_transformer_engine)r   r   ÚparallelÚDistributedDataParallelÚDataParallelr-   r4   r\   rO   r   Ú	deepspeedr†   r   r   r   Ú2torch.distributed.fsdp.fully_sharded_data_parallelr‡   r)   r   ÚforwardÚpopr(   rŽ   r   rS   r   )rj   r�   r‚   rƒ   ÚoptionsÚis_compiledÚhas_compiledÚcompiled_modelr†   ÚFSDPr–   Úoriginal_forwardr‹   s   &&&&        @r#   Úextract_model_from_parallelrž     sƒ  ø€ ô( �x‰x× Ñ ×8Ñ8¼%¿(¹(×:OÑ:OÐP€Gä$ UÓ+€KÜ'¨Ó.€Là€NßØˆØ—‘‰ß	à˜%Ÿ.™.Ô(Ø"ˆNØ—N‘N ;Õ/ˆEä×ÒÝ-àÐ%Õ%ˆä˜Ô2×3Ò3Ô8V×8XÒ8XÝgà�7Õˆä
�U×
$Ò
$Ø—‘Šçõ
	$ñ " %Ó(ˆçØ—-‘-ˆØ Ÿ>™>×-Ñ-Ð.AÀ4ÓHÐØÒ'Ü˜' =×1Ò1Ø!×-Ñ-�ØÖ.ØÜ& wÓ6ˆEŒMÜ�5Ð<¸e×DÒDÜ˜%°uÕ=ç˜nÒ8ßØ',Ô$Ø"ˆEð
 €L÷	 Ø38×#Ñ# KÑ0Ø"ˆEà€Lr%   c                 ó6   € \        4       P                  4        R# )z÷
Introduces a blocking point in the script, making sure all processes have reached this point before continuing.

<Tip warning={true}>

Make sure all processes will reach this instruction otherwise one of your processes will hang forever.

</Tip>
N)r   Úwait_for_everyoner`   r%   r#   r    r    j  s   € ô ƒN×$Ñ$Ö&r%   c                ó$   € V ^8„  d   QhR\         /# )r   Ú
state_dict)r}   )r"   s   "r#   r$   r$   w  s   € ÷  ñ  ´ñ  r%   c           	     ó,  € \         P                  ! \        4      pV P                  4        F>  w  r#\	        V\
        4      '       d   K  V\        V4      ,          P                  V4       K@  	  VP                  4        UUu/ uF  w  rE\        V4      ^8”  g   K  WEbK  	  ppp\        4       pVP                  4        FF  pV Uu. uF  q"V 9   g   K  VNK  	  ppVP                  VR,          4       VR,           F  pW K  	  KH  	  \        V4      ^ 8”  d   \        P                  RV R24       V P                  4        U	U
u/ uF8  w  ršT	\	        V
\        P                  4      '       d   V
P!                  4       MT
bK:  	  p p	p
V # u uppi u upi u up
p	i )zœ
Cleans the state dictionary from a model and removes tensor aliasing if present.

Args:
    state_dict (`dict`):
        The state dictionary from a model
:é   NNzRemoved shared tensor zk while saving. This should be OK, but check by verifying that you don't receive any warning while reloading)ÚcollectionsÚdefaultdictrQ   rR   r)   Ústrr   rL   r>   ÚsetÚvaluesrP   ÚloggerÚwarningr   ÚTensorÚ
contiguous)r¢   ÚptrsrX   ÚtensorÚptrÚnamesÚshared_ptrsÚ
warn_namesÚfound_namesÚkÚvs   &          r#   Ú clean_state_dict_for_safetensorsr·   w  sa  € ô ×"Ò"¤4Ó(€Dà"×(Ñ(Ö*‰ˆÜ˜&¤#×&Ô&ØÔ" 6Ó*Õ+×2Ñ2°4Ö8ñ +ð
 15·
±
´ÔO±¡* #ÄÀEÃ
ÈQÁ”:�3’:±€KÑOÜ“€JØ×#Ñ#Ö%ˆñ ).ÓD© ¸Ñ1C—t�t©ˆÐDØ×Ñ˜+ b�/Ô*Ø —O�OˆDØÒ ó $ñ &ô ˆ:ƒ˜ÔÜ�‰Ø$ Z Lð  1\ð  ]ô	
ð Wa×VfÑVfÔVhÔiÑVhÉdÈa�!¤z°!´U·\±\×'BÒ'B�Q—\‘\”^ÈÒIÑVh€JÑiØÐùó# Pùò Eùó js   Â FÂFÃFÃFÅ>Fc                ó0   € V ^8„  d   QhR\         R\         /# )r   Úsave_on_each_nodeÚsafe_serializationr„   )r"   s   "r#   r$   r$   š  s   € ÷ ñ ¤Dð Ädñ r%   c                óÎ  € \        4       P                  \        P                  8X  d   \        P
                  ! V 4      p V'       d6   \        \        RR/R7      p\        V \        4      '       d   \        V 4      p M\        P                  p\        4       P                  '       d   V'       g   V! W4       R# \        4       P                  '       d   V'       d   V! W4       R# R# R# )aÉ  
Save the data to disk. Use in place of `torch.save()`.

Args:
    obj:
        The data to save
    f:
        The file (or file-like object) to use to save the data
    save_on_each_node (`bool`, *optional*, defaults to `False`):
        Whether to only save on the global main process
    safe_serialization (`bool`, *optional*, defaults to `False`):
        Whether to save `obj` using `safetensors` or the traditional PyTorch way (that uses `pickle`).
r"   Úpt)ÚmetadataN)r   Údistributed_typer   ÚXLAÚxmÚ_maybe_convert_to_cpur   Úsafe_save_filer)   r   r·   r   ÚsaveÚis_main_processÚis_local_main_process)ÚobjÚfr¹   rº   Ú	save_funcs   &&&& r#   rÃ   rÃ   š  sš   € ô$ ƒ~×&Ñ&¬/×*=Ñ*=Ô=Ü×&Ò& sÓ+ˆçÜœN°hÀÐ5EÔFˆ	Ü�cœ;×'Ò'Ü2°3Ó7ˆCøä—J‘Jˆ	äƒ~×%×%Ð%×.?Ù�#ÖÜ	‹×	-×	-Ð	-×2CÙ�#Öñ 3DÑ	-r%   z2.0.0z1.25.0c                ó|  €  \        4       '       dO   \        P                  P                  4       pRV9  d   RVR&   \        P                  P	                  \
        4       MVP                  RR4       \        P                  ! V 3RV/VB p\        4       '       dF   \        P                  P                  4        X'       d    \        P                  P	                  V4       V#   \        4       '       dH   \        P                  P                  4        X'       d!   \        P                  P	                  T4       i i i ; i)að  
Compatible drop-in replacement of `torch.load()` which allows for `weights_only` to be used if `torch` version is
2.4.0 or higher. Otherwise will ignore the kwarg.

Will also add (and then remove) an exception for numpy arrays

Args:
    f:
        The file (or file-like object) to use to load the data
    map_location:
        a function, `torch.device`, string or a dict specifying how to remap storage locations
    **kwargs:
        Additional keyword arguments to pass to `torch.load()`.
Úweights_onlyTNÚmap_location)	r   r   ÚserializationÚget_safe_globalsÚadd_safe_globalsÚTORCH_SAFE_GLOBALSr—   ÚloadÚclear_safe_globals)rÇ   rË   ÚkwargsÚold_safe_globalsÚ
loaded_objs   &&,  r#   rÐ   rÐ   Ì  sí   € ðGÜ$×&Ò&Ü$×2Ñ2×CÑCÓEÐØ VÔ+Ø)-��~Ñ&Ü×Ñ×0Ñ0Ô1CÕDà�J‰J�~ tÔ,Ü—Z’Z ÑG°ÐGÀÑGˆ
ä$×&Ò&Ü×Ñ×2Ñ2Ô4ßÜ×#Ñ#×4Ñ4Ð5EÔFØÐøô	 %×&Ò&Ü×Ñ×2Ñ2Ô4ßÜ×#Ñ#×4Ñ4Ð5EÕFð  ð 'ús   ‚B	C" Ã"6D;Ä"D;c                óò   € \        V R4      '       g    \        V R4      '       g   \        V RV 4      p \        V R4      '       d   V P                  # \        V R4      '       d   V P                  # \	        V 4      # )z 
Gets a pretty name from `obj`.
Ú__qualname__Ú__name__r8   )r(   rS   rÖ   r×   r§   )rÆ   s   &r#   Úget_pretty_namerØ   ì  sd   € ô �3˜×'Ò'´¸¸Z×0HÒ0HÜ�c˜;¨Ó,ˆÜˆs�N×#Ò#Ø×ÑÐÜˆs�J×ÒØ�|‰|ÐÜˆs‹8€Or%   c                óª   € V P                  4        F>  w  r#\        V\        4      '       d    VP                  V/ 4      p\	        W44       K:  W1V&   K@  	  V# )z¯
Recursively merges two dictionaries.

Args:
    source (`dict`): The dictionary to merge into `destination`.
    destination (`dict`): The dictionary to merge `source` into.
)rR   r)   r}   Ú
setdefaultÚmerge_dicts)ÚsourceÚdestinationÚkeyrY   Únodes   &&   r#   rÛ   rÛ   ù  sM   € ð —l‘l–n‰
ˆÜ�eœT×"Ò"Ø×)Ñ)¨#¨rÓ2ˆDÜ˜Ö$à$˜Óñ %ð Ðr%   c                óF   € V ^8„  d   QhR\         \        ,          R\        /# )r   Úportr   )r   rx   r!   )r"   s   "r#   r$   r$     s   € ÷ 6ñ 6œ¤#�ð 6´$ñ 6r%   c                óî   € V f   Rp \         P                   ! \         P                  \         P                  4      ;_uu_ 4       pVP                  RV 34      ^ 8H  uuRRR4       #   + '       g   i     R# ; i)z¦
Checks if a port is in use on `localhost`. Useful for checking if multiple `accelerate launch` commands have been
run and need to see if the port is already in use.
Ni<s  Ú	localhost)ÚsocketÚAF_INETÚSOCK_STREAMÚ
connect_ex)rá   Úss   & r#   Úis_port_in_useré     sP   € ð
 ‚|ØˆÜ	�Š”v—~‘~¤v×'9Ñ'9×	:Ô	:¸aØ�|‰|˜[¨$Ð/Ó0°AÑ5÷ 
;×	:×	:Ó	:ús   ÁA#Á#A4	c                ó$   € V ^8„  d   QhR\         /# )r   r   )rx   )r"   s   "r#   r$   r$     s   € ÷ 
"ñ 
"”sñ 
"r%   c                 ó  € \         P                   ! \         P                  \         P                  4      ;_uu_ 4       p V P                  R4       V P	                  4       ^,          uuRRR4       #   + '       g   i     R# ; i)z®
Gets a free port on `localhost`. Useful for automatic port selection when port 0 is specified in distributed
training scenarios.

Returns:
    int: An available port number
N)Ú r   )rä   rå   ræ   ÚbindÚgetsockname)rè   s    r#   Úget_free_portrï     sI   € ô 
�Š”v—~‘~¤v×'9Ñ'9×	:Ô	:¸aØ	�‰ˆwŒØ�}‰}‹˜qÕ!÷ 
;×	:×	:Ó	:ús   ¼(A/Á/B 	c                óx   € R F&  pV R8  d   \        V ^4       RV 2u # V R,          p K(  	  \        V ^4       R2# )z7Converts `size` from bytes to the largest possible unitg      �@Ú z PB)ÚbytesÚKBÚMBÚGBÚTB)Úround)ÚsizeÚxs   & r#   Úconvert_bytesrú   #  sJ   € ã.ˆØ�&Œ=Ü˜D !“nÐ% Q q cÐ*Ò*Ø��Šñ /ô
 �D˜!‹nÐ˜SÐ!Ð!r%   c                 ó  € \         P                  ! 4       p V P                  pVR8w  d   R# \        P                  ! RV P
                  4      vr#pRp\        V4      \        V4      8  d#   RV RV R2p\        P                  VRR	7       R# R# )
zFWarns if the kernel version is below the recommended minimum on Linux.ÚLinuxNz(\d+\.\d+\.\d+)z5.5.0zDetected kernel version z,, which is below the recommended minimum of zo; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.T)Úmain_process_only)	ÚplatformÚunameÚsystemÚreÚsplitÚreleaser	   rª   r«   )Úinfor   Ú_ÚversionÚmin_versionÚmsgs         r#   Úcheck_os_kernelr	  -  s�   € ô �>Š>Ó€DØ�[‰[€FØ�ÔÙä—X’XÐ0°$·,±,Ó?€N€A�Ø€KÜˆwÓœ' +Ó.Ô.à& w iÐ/[Ð\gÐ[hð isð sð 	ô 	�‰�s¨dˆÖ3ñ /r%   c                ó$   € V ^8„  d   QhR\         /# )r   Úattr)r§   )r"   s   "r#   r$   r$   ?  s   € ÷ 5ñ 5¤ñ 5r%   c                óL   € R p\        W .VP                  R4      ,           4      # )zµ
Recursive `getattr`.

Args:
    obj:
        A class instance holding the attribute.
    attr (`str`):
        The attribute that is to be retrieved, e.g. 'attribute1.attribute2'.
c                 ó   € \        W4      # ro   )rS   )rÆ   r  s   &&r#   Ú_getattrÚ#recursive_getattr.<locals>._getattrJ  s   € Ü�sÓ!Ð!r%   Ú.)r   r  )rÆ   r  r  s   && r#   Úrecursive_getattrr  ?  s#   € ò"ô �(˜E D§J¡J¨s£OÕ3Ó4Ð4r%   c                ó¢   € V ^8„  d   QhR\         P                  P                  R\        R\        \         P                  P                  ,          /# )r   rj   Úreturn_fqnsr   )r   r   r    r!   rQ   )r"   s   "r#   r$   r$   P  s<   € ÷ !ñ !¬¯©¯©ð !Ätð !ÔX\Ô]b×]eÑ]e×]lÑ]lÕXmñ !r%   c                ó   € V'       g   T MRV 3pV.p. pV'       dÙ   VP                  4       pV'       d   Vw  reVP                  4        Fx  w  rx\        V\        P                  P
                  4      '       g   K1  V'       d/   X'       d   VR,           V,           MTp	VP                  W˜34       Kg  VP                  V4       Kz  	  V'       d   VP                  XV34       KÍ  VP                  V4       Kà  VRRR1,          # )a)  Traverse the model in bottom-up order and return the children modules in that order.

Args:
    model (`torch.nn.Module`): the model to get the children of

Returns:
    `list[torch.nn.Module]`: a list of children modules of `model` in bottom-up order. The last element is the
    `model` itself.
rì   r  Néÿÿÿÿ)r—   rT   r)   r   r   r    rL   )
rj   r  ÚtopÚstackÚordered_modulesÚcurrent_moduleÚcurrent_module_namerX   r  Ú
child_names
   &&        r#   Úget_module_children_bottom_upr  P  sÊ   € ÷ #‰%¨¨U¨€CØˆE€EØ€Oß
ØŸ™›ˆßØ2@Ñ/ÐØ(×7Ñ7Ö9‰JˆDÜ˜$¤§¡§¡×0Ô0ßßEXÐ!4°sÕ!:¸TÖ!AÐ^b�JØ—L‘L *Ð!3Ö4à—L‘L Ö&ñ :÷ Ø×"Ñ"Ð$7¸Ð#HÖIà×"Ñ" >Ö2Ø™4˜R˜4Õ Ð r%   )TTF)FFro   )F)Rr¥   rþ   r  rä   Úcodecsr   r   Ú	functoolsr   r   Útypesr   Útypingr   ÚnumpyÚnpr   Úpackaging.versionr	   Úsafetensors.torchr
   rÂ   Úcommands.config.defaultr   Úloggingr   Ústater   Ú	constantsr   Údataclassesr   Úimportsr   r   r   r   r   Úmodelingr   Útransformer_enginer   Úversionsr   r×   rª   Útorch_xla.core.xla_modelÚcoreÚ	xla_modelrÀ   r-   r4   r@   rC   r]   rb   rg   rv   r   rž   r    r·   rÃ   Ú_coreÚnp_coreÚ
multiarrayÚ_reconstructÚndarrayÚdtyperÏ   rL   ÚdtypesÚUInt32DTyperÐ   rØ   rÛ   ré   rï   rú   r	  r  r  r`   r%   r#   Ú<module>r9     sU  ðó Û Û 	Û Ý Ý #ß %Ý Ý ã Û Ý %Ý 9å 8Ý  Ý  Ý +Ý (÷õ õ (Ý -Ý &ñ 
�HÓ	€ñ ×Òß)Ð)õHõõ
õõHõV)õ0õ4Cõ(8÷.Uòp
'õ ÷FñH )¨×1Ò1ˆ"�(Š(°r·w±w€ð ×Ñ×#Ñ#Ø‡J�Jà
Ø‡H�HðÐ ñ �h×ÒØ×Ñ˜bŸi™i×3Ñ3Ô4ôò@
ò÷$6õ
"ò"ò4õ$5÷"!ñ !r%   