+
     °³jQ  ã                   óš   € R t ^ RIt^ RIt^ RIt^ RIHt ^ RIt^RIHtH	t	H
t
HtHtHtHtHtHt RR R lltR R ltR R	 ltRR
 R lltR# )z“
A collection of utilities for ensuring that training can always occur. Heavily influenced by the
[toma](https://github.com/BlackHC/toma) library.
N)ÚOptional)	Úis_cuda_availableÚis_hpu_availableÚis_mlu_availableÚis_mps_availableÚis_musa_availableÚis_neuron_availableÚis_npu_availableÚis_sdaa_availableÚis_xpu_availablec                ó(   € V ^8„  d   QhR\         RR/# )é   Úgarbage_collectionÚreturnN)Úbool)Úformats   "ÚX/home/luca/screen-checking/.venv/lib/python3.14/site-packages/accelerate/utils/memory.pyÚ__annotate__r   (   s   € ÷ #ñ #¬4ð #¸Dñ #ó    c                óh  € V '       d   \         P                  ! 4        \        4       '       d!   \        P                  P                  4        R# \        4       '       d!   \        P                  P                  4        R# \        4       '       d!   \        P                  P                  4        R# \        4       '       d!   \        P                  P                  4        R# \        4       '       d!   \        P                  P                  4        R# \        RR7      '       d!   \        P                  P                  4        R# \!        4       '       d!   \        P"                  P                  4        R# \%        4       '       d   R# \'        4       '       d!   \        P(                  P                  4        R# R# )z±
Clears the device cache by calling `torch.{backend}.empty_cache`. Can also run `gc.collect()`, but do note that
this is a *considerable* slowdown and should be used sparingly.
z2.0)Úmin_versionN)ÚgcÚcollectr   ÚtorchÚxpuÚempty_cacher   Úmlur
   Úsdaar   Úmusar	   Únpur   Úmpsr   Úcudar   r   Úneuron©r   s   &r   Úclear_device_cacher$   (   së   € ÷
 Ü
�
Š
Œä×ÒÜ�	‰	×ÑÖÜ	×	Ò	Ü�	‰	×ÑÖÜ	×	Ò	Ü�
‰
×ÑÖ Ü	×	Ò	Ü�
‰
×ÑÖ Ü	×	Ò	Ü�	‰	×ÑÖÜ	 e×	,Ó	,Ü�	‰	×ÑÖÜ	×	Ò	Ü�
‰
×ÑÖ Ü	×	Ò	áÜ	×	Ò	ä�‰× Ñ Ö"ñ 
r   c                ó$   € V ^8„  d   QhR\         /# )r   r   )Úlist)r   s   "r   r   r   F   s   € ÷ ñ ¤ñ r   c                 óž   € \        V \        4      '       g   \        V 4      p \        \        V 4      4       F  pRW&   K	  	  \	        RR7       V # )a  
Releases memory from `objects` by setting them to `None` and calls `gc.collect()` and `torch.cuda.empty_cache()`.
Returned objects should be reassigned to the same variables.

Args:
    objects (`Iterable`):
        An iterable of objects
Returns:
    A list of `None` objects to replace `objects`

Example:

    ```python
    >>> import torch
    >>> from accelerate.utils import release_memory

    >>> a = torch.ones(1000, 1000).cuda()
    >>> b = torch.ones(1000, 1000).cuda()
    >>> a, b = release_memory(a, b)
    ```
NTr#   )Ú
isinstancer&   ÚrangeÚlenr$   )ÚobjectsÚis   * r   Úrelease_memoryr-   F   sA   € ô, �gœt×$Ò$Ü�w“-ˆÜ”3�w“<Ö ˆØˆ‹
ñ !ä¨$Õ/Ø€Nr   c                ó0   € V ^8„  d   QhR\         R\        /# )r   Ú	exceptionr   )Ú	Exceptionr   )r   s   "r   r   r   d   s   € ÷ ñ ¬	ð ´dñ r   c                óä   a € . ROp\        S \        4      '       dU   \        S P                  4      ^8X  d;   \        ;QJ d    V 3R lV 4       F  '       g   K   R# 	  R# ! V 3R lV 4       4      # R# )z—
Checks if `exception` relates to CUDA, XPU, MPS or CPU out-of-memory, or CUDNN not supported

Args:
    exception (`Exception`):
        An exception
c              3   óN   <"  € T F  qSP                   ^ ,          9   x € K  	  R# 5i)é    N)Úargs)Ú.0Úerrr/   s   & €r   Ú	<genexpr>Ú+should_reduce_batch_size.<locals>.<genexpr>t   s   øé € ÐC±{°˜)Ÿ.™.¨Õ+Ö+³{ùs   ƒ"%TF)z out of memory.zMPS backend out of memoryz(cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.z*DefaultCPUAllocator: can't allocate memoryz1FATAL ERROR :: MODULE:PT_DEVMEM Allocation failed)r(   ÚRuntimeErrorr*   r4   Úany)r/   Ú_statementss   f r   Úshould_reduce_batch_sizer<   d   sU   ø€ ò€Kô �)œ\×*Ò*¬s°9·>±>Ó/BÀaÔ/Gß‹sÔC±{ÓC�sŒsÐCŠsÐCˆsÔC±{ÓCÓCÐCÙr   c                óh   € V ^8„  d   QhR\         \        ,          R\        R\         \        ,          /# )r   ÚfunctionÚstarting_batch_sizeÚreduce_batch_size_fn)r   ÚcallableÚint)r   s   "r   r   r   x   s5   € ÷ Iñ IÜ”xÕ ðIäðIô #¤8Õ,ñIr   c                óv   a aa€ S f   \         P                  ! \        VSR7      # VoSf   V3R loVV V3R lpV# )aÂ  
A basic decorator that will try to execute `function`. If it fails from exceptions related to out-of-memory or
CUDNN, the batch size is multiplied by 0.9 and passed to `function`

`function` must take in a `batch_size` parameter as its first argument.

Args:
    function (`callable`, *optional*):
        A function to wrap
    starting_batch_size (`int`, *optional*):
        The batch size to try and fit into memory
    reduce_batch_size_fn (`callable`, *optional*):
        A function to determine the new batch size after an out-of-memory error. If not
        provided, the batch size is multiplied by 0.9 on each failure. The function takes
        no arguments and should return the new (reduced) batch size as an `int`.

Example:

```python
>>> from accelerate.utils import find_executable_batch_size


>>> @find_executable_batch_size(starting_batch_size=128)
... def train(batch_size, model, optimizer):
...     ...


>>> train(model, optimizer)
```
)r?   r@   c                  ó,   <€ \        S R ,          4      o S # )gÍÌÌÌÌÌì?)rB   )Ú
batch_sizes   €r   r@   Ú8find_executable_batch_size.<locals>.reduce_batch_size_fn¥   s   ø€ ä˜Z¨#Õ-Ó.ˆJØÐr   c            	      óh  <€ \        R R7       \        \        P                  ! S4      P                  P                  4       4      p\        V4      \        V 4      ^,           8  dl   RP                  \        VR,          V R,          4       UUu. uF  w  r4V RV 2NK  	  upp4      p\        RSP                   RSP                   RV R24      h S^ 8X  d   \        R	4      h S! S.V O5/ VB # u uppi   \         d1   p\        T4      '       d   \        R R7       S	! 4       o R
p?K[  h R
p?ii ; i)Tr#   z, :é   NNÚ=zBatch size was passed into `zS` as the first argument when called.Remove this as the decorator already does so: `Ú(z)`z-No executable batch size found, reached zero.N)r$   r&   ÚinspectÚ	signatureÚ
parametersÚkeysr*   ÚjoinÚzipÚ	TypeErrorÚ__name__r9   r0   r<   )
r4   ÚkwargsÚparamsÚargÚvalueÚarg_strÚerE   r>   r@   s
   *,     €€€r   Ú	decoratorÚ-find_executable_batch_size.<locals>.decoratorª   s)  ø€ ä¨dÕ3Ü”g×'Ò'¨Ó1×<Ñ<×AÑAÓCÓDˆäˆv‹;œ#˜d›) a�-Ô(Ø—i‘iÄCÈÈrÍ
ÐTXÐY[ÕT\ÔD]Ô ^ÑD]±j°c C 5¨¨%¨Ó!1ÑD]Ò ^Ó_ˆGÜØ.¨x×/@Ñ/@Ð.Að BBØBJ×BSÑBSÐATÐTUÐV]ÐU^Ð^`ðbóð ð Ø˜QŒÜ"Ð#RÓSÐSðÙ 
Ð<¨TÒ<°VÑ<Ð<ùó !_øô ô Ü+¨A×.Ò.Ü&¸$Õ?Ù!5Ó!7–Jàûðús$   ÂC0
Ã$C6 Ã6D1Ä$D,Ä+D,Ä,D1)Ú	functoolsÚpartialÚfind_executable_batch_size)r>   r?   r@   rY   rE   s   f&f @r   r]   r]   x   sG   ú€ ðF ÒÜ× Ò Ü&Ø 3Ø!5ô
ð 	
ð %€JØÒ#õ	÷
ð. Ðr   )F)Né€   N)Ú__doc__r[   r   rK   Útypingr   r   Úimportsr   r   r   r   r   r   r	   r
   r   r$   r-   r<   r]   © r   r   Ú<module>rc      sE   ðñó
 Û 	Û Ý ã ÷
÷ 
õ 
÷#õ<õ<÷(Iñ Ir   