§
    “©ºj!  ã                   óœ   — d Z ddlZddlmZ ddlZddlmZ ddlmZ ddeded	efd
„Z	de
d	efd„Zde
d	efd„Zde
d	efd„Zde
d	efd„Zdd„ZdS )zUtilities related to memory.é    N)ÚAny)Úapply_to_collection)ÚTensorFÚin_dictÚto_cpuÚreturnc                 ód   — dt           dt          dt           fd„}t          | t           ||¬¦  «        S )a”  Detach all tensors in `in_dict`.

    May operate recursively if some of the values in `in_dict` are dictionaries
    which contain instances of `Tensor`. Other types in `in_dict` are
    not affected by this utility function.

    Args:
        in_dict: Dictionary with tensors to detach
        to_cpu: Whether to move tensor to cpu

    Return:
        out_dict: Dictionary with detached tensors

    Útr   r   c                 óZ   — |                       ¦   «         } |r|                      ¦   «         } | S ©N)ÚdetachÚcpu)r
   r   s     úr/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/utilities/memory.pyÚdetach_and_movez)recursive_detach.<locals>.detach_and_move(   s)   € Ø�HŠH‰JŒJˆØð 	Ø—’‘”ˆAØˆó    )r   )r   Úboolr   )r   r   r   s      r   Úrecursive_detachr      sD   € ð �6ð ­4ð µFð ð ð ð õ ˜w­°ÈÐOÑOÔOÐOr   Ú	exceptionc                 ó\   — t          | ¦  «        pt          | ¦  «        pt          | ¦  «        S r   )Úis_cuda_out_of_memoryÚis_cudnn_snafuÚis_out_of_cpu_memory©r   s    r   Úis_oom_errorr   1   s,   € Ý  Ñ+Ô+Ðk­~¸iÑ/HÔ/HÐkÕL`ÐajÑLkÔLkÐkr   c                 ó˜   — t          | t          ¦  «        o5t          | j        ¦  «        dk    od| j        d         v od| j        d         v S )Né   ÚCUDAr   zout of memory©Ú
isinstanceÚRuntimeErrorÚlenÚargsr   s    r   r   r   6   sU   € å�9�lÑ+Ô+ð 	1Ý�	”ÑÔ 1Ò$ð	1à�i”n QÔ'Ð'ð	1ð ˜yœ~¨aÔ0Ð0ð	r   c                 óz   — t          | t          ¦  «        o&t          | j        ¦  «        dk    od| j        d         v S )Nr   z(cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.r   r   r   s    r   r   r   @   sC   € õ 	�9�lÑ+Ô+ð 	LÝ�	”ÑÔ 1Ò$ð	Là6¸)¼.ÈÔ:KÐKðr   c                 óz   — t          | t          ¦  «        o&t          | j        ¦  «        dk    od| j        d         v S )Nr   z*DefaultCPUAllocator: can't allocate memoryr   r   r   s    r   r   r   J   sA   € å�9�lÑ+Ô+ð 	NÝ�	”ÑÔ 1Ò$ð	Nà8¸I¼NÈ1Ô<MÐMðr   c                  óº   — t          j        ¦   «          	 t          j                             ¦   «          dS # t
          $ r} t          | ¦  «        s‚ Y d} ~ dS d} ~ ww xY w)z'Garbage collection Torch (CUDA) memory.N)ÚgcÚcollectÚtorchÚcudaÚempty_cacher    r   r   s    r   Úgarbage_collection_cudar+   S   s|   € å„J�L„L€LðåŒ
×ÒÑ Ô Ð Ð Ð øÝð ð ð Ý˜IÑ&Ô&ð 	àð	ð 	ð 	ð 	ð 	ð 	øøøøðøøøs   •5 µ
A¿AÁA)F)r   N)Ú__doc__r&   Útypingr   r(   Ú#lightning_utilities.core.apply_funcr   r   r   r   ÚBaseExceptionr   r   r   r   r+   © r   r   ú<module>r1      s7  ðð #Ð "à 	€	€	€	Ø Ð Ð Ð Ð Ð à €€€Ø CÐ CÐ CÐ CÐ CÐ CØ Ð Ð Ð Ð Ð ðPð P˜cð P¨4ð P¸Cð Pð Pð Pð Pð2l˜Mð l¨dð lð lð lð lð
 ]ð °tð ð ð ð ð˜mð °ð ð ð ð ð Mð °dð ð ð ð ð	ð 	ð 	ð 	ð 	ð 	r   