§
    “©ºjv  ã                   ó¦   — d dl Z d dlZd dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dl
mZ d dlmZ  e j        e¦  «        Z G d„ d	e	¦  «        ZdS )
é    N)ÚAnyÚCallableÚOptional)Úoverride)ÚCheckpointIO)Ú_atomic_saveÚget_filesystem)Ú_load)Ú_PATHc                   óÐ   — e Zd ZdZeddeeef         dede	e         ddfd„¦   «         Z
ed„ dfded	e	e         d
e	e         deeef         fd„¦   «         Zededdfd„¦   «         ZdS )ÚTorchCheckpointIOzíCheckpointIO that utilizes :func:`torch.save` and :func:`torch.load` to save and load checkpoints respectively,
    common for most use cases.

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    NÚ
checkpointÚpathÚstorage_optionsÚreturnc                 óê   — |�t          d| j        j        › d�¦  «        ‚t          |¦  «        }|                     t
          j                             |¦  «        d¬¦  «         t          ||¦  «         dS )a~  Save model/training states as a checkpoint file through state-dump and file-write.

        Args:
            checkpoint: dict containing model and trainer state
            path: write-target path
            storage_options: not used in ``TorchCheckpointIO.save_checkpoint``

        Raises:
            TypeError:
                If ``storage_options`` arg is passed in

        Nze`Trainer.save_checkpoint(..., storage_options=...)` with `storage_options` arg is not supported for `za`. Please implement your custom `CheckpointIO` to define how you'd like to use `storage_options`.T)Úexist_ok)	Ú	TypeErrorÚ	__class__Ú__name__r	   ÚmakedirsÚosr   Údirnamer   )Úselfr   r   r   Úfss        út/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/lightning_fabric/plugins/io/torch_io.pyÚsave_checkpointz!TorchCheckpointIO.save_checkpoint$   s…   € ð Ð&ÝðFØ*.¬.Ô*AðFð Fð Fñô ð õ
 ˜DÑ!Ô!ˆØ
�Š•B”G—O’O DÑ)Ô)°DˆÑ9Ô9Ð9Ý�Z Ñ&Ô&Ð&Ð&Ð&ó    c                 ó   — | S ©N© )ÚstorageÚlocs     r   ú<lambda>zTorchCheckpointIO.<lambda>@   s   € À€ r   Úmap_locationÚweights_onlyc                 ó’   — t          |¦  «        }|                     |¦  «        st          d|› �¦  «        ‚t          |||¬¦  «        S )aÿ  Loads checkpoint using :func:`torch.load`, with additional handling for ``fsspec`` remote loading of files.

        Args:
            path: Path to checkpoint
            map_location: a function, :class:`torch.device`, string or a dict specifying how to remap storage
                locations.
            weights_only: Defaults to ``None``. If ``True``, restricts loading to ``state_dicts`` of plain
                ``torch.Tensor`` and other primitive types. If loading a checkpoint from a trusted source that contains
                an ``nn.Module``, use ``weights_only=False``. If loading checkpoint from an untrusted source, we
                recommend using ``weights_only=True``. For more information, please refer to the
                `PyTorch Developer Notes on Serialization Semantics <https://docs.pytorch.org/docs/main/notes/serialization.html#id3>`_.

        Returns: The loaded checkpoint.

        Raises:
            FileNotFoundError: If ``path`` is not found by the ``fsspec`` filesystem

        zCheckpoint file not found: )r%   r&   )r	   ÚexistsÚFileNotFoundErrorÚpl_load)r   r   r%   r&   r   s        r   Úload_checkpointz!TorchCheckpointIO.load_checkpoint<   sP   € õ6 ˜DÑ!Ô!ˆØ�yŠy˜‰Œð 	JÝ#Ð$HÀ$Ð$HÐ$HÑIÔIÐIå�t¨,À\ÐRÑRÔRÐRr   c                 óº   — t          |¦  «        }|                     |¦  «        r6|                     |d¬¦  «         t                               d|› �¦  «         dS dS )ziRemove checkpoint file from the filesystem.

        Args:
            path: Path to checkpoint

        T)Ú	recursivezRemoved checkpoint: N)r	   r(   ÚrmÚlogÚdebug)r   r   r   s      r   Úremove_checkpointz#TorchCheckpointIO.remove_checkpoint]   sd   € õ ˜DÑ!Ô!ˆØ�9Š9�T‰?Œ?ð 	5Ø�EŠE�$ $ˆEÑ'Ô'Ð'Ý�IŠIÐ3¨TÐ3Ð3Ñ4Ô4Ð4Ð4Ð4ð	5ð 	5r   r    )r   Ú
__module__Ú__qualname__Ú__doc__r   ÚdictÚstrr   r   r   r   r   Úboolr+   r1   r!   r   r   r   r      s  € € € € € ðð ð ð'ð '¨$¨s°C¨x¬.ð 'Àð 'ÐX`ÐadÔXeð 'Ðquð 'ð 'ð 'ñ „Xð'ð. ð ,HÐ+GØ'+ð	Sð SàðSð ˜xÔ(ðSð ˜t”nð	Sð
 
ˆc�3ˆhŒðSð Sð Sñ „XðSð@ ð
5 eð 
5°ð 
5ð 
5ð 
5ñ „Xð
5ð 
5ð 
5r   r   )Úloggingr   Útypingr   r   r   Útyping_extensionsr   Ú)lightning_fabric.plugins.io.checkpoint_ior   Ú#lightning_fabric.utilities.cloud_ior   r	   r
   r*   Ú lightning_fabric.utilities.typesr   Ú	getLoggerr   r/   r   r!   r   r   ú<module>r?      sç   ðð €€€Ø 	€	€	€	Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *à &Ð &Ð &Ð &Ð &Ð &à BÐ BÐ BÐ BÐ BÐ BØ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LØ @Ð @Ð @Ð @Ð @Ð @Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2à€gÔ˜Ñ!Ô!€ðL5ð L5ð L5ð L5ð L5˜ñ L5ô L5ð L5ð L5ð L5r   